public virtual void Draw(SpriteBatch spriteBatch, GameTime gameTime, Vector2 offset, Camera camera, DebugGeometry debugGeometry) { var tex = GetTexture(); var s = Math.Max(tex.Region.Width, tex.Region.Height); spriteBatch.Draw(tex.Texture, Position + offset, tex.Region, Color * Alpha, Rotation, new Vector2(tex.Region.Width / 2, tex.Region.Height / 2), Size / s, SpriteEffects.None, 0f); // DrawHP if (DrawHP) { Vector2 start = new Vector2(-10f, -Size / 2 - 5f); start = new Vector2(start.X * Maf.Cos(-camera.FollowedObject.Rotation) + start.Y * Maf.Sin(-camera.FollowedObject.Rotation), -start.X * Maf.Sin(-camera.FollowedObject.Rotation) + start.Y * Maf.Cos(-camera.FollowedObject.Rotation)); debugGeometry.DrawLine(Position + start + offset, 20f, camera.FollowedObject.Rotation, Color.Red); debugGeometry.DrawLine(Position + start + offset, 20f * HP / MaxHP, camera.FollowedObject.Rotation, Color.Green); } }
public void Draw(SpriteBatch spriteBatch, Camera camera) { var sourceRectangle = new Rectangle(0, 0, TextureManager.SpaceTexture.Texture.Width * RepeatX, TextureManager.SpaceTexture.Texture.Height * RepeatY); var scale = new Vector2( Game.WorldWidth / TextureManager.SpaceTexture.Texture.Width / ParallaxFactorX / RepeatX, Game.WorldHeight / TextureManager.SpaceTexture.Texture.Height / ParallaxFactorY / RepeatY); float w = Game.WorldWidth / ParallaxFactorX; float h = Game.WorldHeight / ParallaxFactorY; spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.LinearWrap, null, null, null, camera.GetParallaxTransform(ParallaxFactorX, ParallaxFactorY)); spriteBatch.Draw(TextureManager.SpaceTexture.Texture, new Vector2(0, 0), sourceRectangle, Color.White, 0.0f, new Vector2(0, 0), scale, SpriteEffects.None, 0.0f); spriteBatch.Draw(TextureManager.SpaceTexture.Texture, new Vector2(w, 0), sourceRectangle, Color.White, 0.0f, new Vector2(0, 0), scale, SpriteEffects.None, 0.0f); spriteBatch.Draw(TextureManager.SpaceTexture.Texture, new Vector2(w, h), sourceRectangle, Color.White, 0.0f, new Vector2(0, 0), scale, SpriteEffects.None, 0.0f); spriteBatch.Draw(TextureManager.SpaceTexture.Texture, new Vector2(0, h), sourceRectangle, Color.White, 0.0f, new Vector2(0, 0), scale, SpriteEffects.None, 0.0f); spriteBatch.Draw(TextureManager.SpaceTexture.Texture, new Vector2(-w, h), sourceRectangle, Color.White, 0.0f, new Vector2(0, 0), scale, SpriteEffects.None, 0.0f); spriteBatch.Draw(TextureManager.SpaceTexture.Texture, new Vector2(-w, 0), sourceRectangle, Color.White, 0.0f, new Vector2(0, 0), scale, SpriteEffects.None, 0.0f); spriteBatch.Draw(TextureManager.SpaceTexture.Texture, new Vector2(-w, -h), sourceRectangle, Color.White, 0.0f, new Vector2(0, 0), scale, SpriteEffects.None, 0.0f); spriteBatch.Draw(TextureManager.SpaceTexture.Texture, new Vector2(0, -h), sourceRectangle, Color.White, 0.0f, new Vector2(0, 0), scale, SpriteEffects.None, 0.0f); spriteBatch.Draw(TextureManager.SpaceTexture.Texture, new Vector2(w, -h), sourceRectangle, Color.White, 0.0f, new Vector2(0, 0), scale, SpriteEffects.None, 0.0f); spriteBatch.End(); }
protected override void Initialize() { _graphics.IsFullScreen = Config.IsFullScreen; _graphics.ApplyChanges(); InitializeInputManager(); _ship = Game.Objects.CreateShip(new Vector2(WorldWidth / 2, WorldHeight / 2), _world); _enemyShip = Game.Objects.CreateEnemyShip(new Vector2(Chaos.GetFloat(0, WorldWidth), Chaos.GetFloat(0, WorldHeight)), _world, _ship); _ship.HP = 100; _ship.MaxHP = 100; _enemyShip.HP = 100; _enemyShip.MaxHP = 100; _camera = new Camera(_ship); for (int i = 0; i < 100; ++i) { Asteroid asteroid = Game.Objects.CreateAsteroid(); asteroid.Size = Chaos.GetFloat(20f, 80f); asteroid.Mass = asteroid.Size; asteroid.HP = (int)asteroid.Size / 8; asteroid.MaxHP = (int)asteroid.Size / 8; asteroid.Position = Chaos.GetVector2InRectangle(WorldWidth, WorldHeight); asteroid.Speed = Chaos.GetVector2InCenterRectangle(2f, 2f); asteroid.Rotation = Chaos.GetFloat(MathHelper.TwoPi); asteroid.RotationSpeed = Chaos.GetFloat(-.05f, .05f); _world.Add(asteroid); } for (int i = 0; i < 150; ++i) { SpeedBonus bonus = Game.Objects.CreateSpeedBonus(Chaos.GetVector2InRectangle(WorldWidth, WorldHeight)); _world.Add(bonus); } for (int i = 0; i < 150; ++i) { Medkit medkit = Game.Objects.CreateMedkit(Chaos.GetVector2InRectangle(WorldWidth, WorldHeight)); _world.Add(medkit); } _world.Add(_enemyShip); _world.Add(_ship); Components.Add(new FPS(this, Vector2.Zero)); _worldLoopParticles.Clusterize(_particles.ParticlesList); _worldLoop.Clusterize(_world.GameObjects); base.Initialize(); }