1 PhysicalObject::PhysicalObject(sf::RenderWindow *pApp, cpSpace *pSpace, 2 std::string ImageName, std::string GlowImageName, 3 cpVect Location, cpFloat Angle, cpFloat Speed, 4 cpFloat Depth, cpFloat RotSpeed) : 5 mpApp(pApp), 6 mpSpace(pSpace), 7 mpImage(NULL), 8 mpGlowImage(NULL), 9 mpSprite(NULL), 10 mpGlowSprite(NULL), 11 mDepth(Depth) 12 { 13 // Load the image 14 mpImage = Utilities::ImageGet(ImageName.c_str()); 15 16 mpSprite = new sf::Sprite(); 17 mpSprite->SetImage(*mpImage); 18 mpSprite->SetOrigin(mpImage->GetWidth()/2, mpImage->GetHeight()/2); 19 20 // Set to middle of screen 21 mpSprite->SetPosition(pApp->GetWidth()/2, pApp->GetHeight()/2); 22 23 if (GlowImageName.size() > 0) 24 { 25 mpGlowImage = Utilities::ImageGet(GlowImageName.c_str()); 26 27 mpGlowSprite = new sf::Sprite(); 28 mpGlowSprite->SetImage(*mpGlowImage); 29 mpGlowSprite->SetOrigin(mpGlowImage->GetWidth()/2, mpGlowImage->GetHeight()/2); 30 31 // Set to middle of screen 32 mpGlowSprite->SetPosition(pApp->GetWidth()/2, pApp->GetHeight()/2); 33 34 // for glow, set to additive blend 35 mpGlowSprite->SetBlendMode(sf::Blend::Add); 36 } 37 38 mpBody = cpBodyNew(1.0f, 1.0f); 39 40 cpBodySetPos(mpBody, Location); 41 42 // Set the Velocity 43 mpBody->v.x=cos( Angle)*Speed; 44 mpBody->v.y=sin( Angle)*Speed; 45 46 cpBodySetAngle(mpBody, Angle); 47 mpBody->w = RotSpeed; 48 49 mpShape = cpCircleShapeNew(mpBody, (mpImage->GetWidth() + mpImage->GetHeight())/4, cpvzero); 50 mpShape->e = 0.0f; // not elatics, no bouncing 51 mpShape->u = 0.0f; // 0.0 is frictionless 52 53 cpSpaceAddBody(mpSpace, mpBody); 54 cpSpaceAddShape(mpSpace, mpShape); 55 56 }