public HealthPickup(Vector2 position, Tank tank) { player = tank; healthSprite.PreLoad(ref PreLoadedTextures.HealthPickupTexture); healthSprite.SetPosition(-healthSprite.Width * 1.5f, -healthSprite.Height / 2); AddChild(healthSprite); SetPosition(position.x, position.y); collider = new BoxCollider(position, healthSprite.Width * 2, healthSprite.Height, 0); }
public static SpriteObject AccelerateObject(SpriteObject obj, float acceleration, float dt) { var x = obj.GetPosition().X; var y = obj.GetPosition().Y; var dx = obj.GetVelocity().X; var dy = obj.GetVelocity().Y; var x2 = x + (dt * dx) + (acceleration * dt * dt * 0.5f); var y2 = y + (dt * y) + (acceleration * dt * dt * 0.5f); var dx2 = dx + (acceleration * dt) * (dx > 0 ? 1 : -1); var dy2 = dy + (acceleration * dt) * (dy > 0 ? 1 : -1); var newObj = new SpriteObject(); newObj.SetPosition(new Vector2(x2 - x, y2 - y)); newObj.SetVelocity(dx2, dy2); newObj.SetStartPosition(new Vector2(x2, y2)); return(newObj); // need to return a position and velocity (not really a whole new sprite object) }
public AmmoPickup(Vector2 position, Tank tank) { player = tank; ammo1.PreLoad(ref PreLoadedTextures.AmmoPickupTexture); ammo2.PreLoad(ref PreLoadedTextures.AmmoPickupTexture); ammo3.PreLoad(ref PreLoadedTextures.AmmoPickupTexture); ammo1.SetPosition(-ammo1.Width * 1.5f, -ammo1.Height / 2); ammo2.SetPosition(-ammo2.Width / 2, -ammo2.Height / 2); ammo3.SetPosition(ammo2.Width / 2, -ammo3.Height / 2); AddChild(ammo1); AddChild(ammo2); AddChild(ammo3); SetPosition(position.x, position.y); collider = new BoxCollider(position, ammo1.Width * 2, ammo1.Height, 0); }