public override void Update(GameTime gameTime) { // Check if the projectile has reached the ground. if (position.Z < 0) { var enemies = enemyManager.GetEnemiesInRange(new Vector2(position.X, position.Y), 1.5f); foreach (var enemy in enemies) { enemy.Attack(20); } stopwatch.Stop(); TargetReached?.Invoke(this); } // Calculate the current position from the elapsed time. var time = (float)stopwatch.Elapsed.TotalSeconds; displacement = (initialVelocity * time) + (0.5f * (Acceleration * (float)Math.Pow(time, 2))); position = initialPosition + displacement; // Update the actual position on the screen. sprite.Position = map.MapToScreen(new Vector2(position.X, position.Y)) + new Vector2(0, -position.Z * (map.TiledMap.TileHeight / 2)); }
public override void Draw(GameTime gameTime) { if (map.HoveredTile != null) { var position = map.MapToScreen(map.HoveredTile.Position); var color = map.HoveredTile.IsPlaceable ? Color.White * 0.5f : Color.Red * 0.5f; sprite.Position = position; sprite.Color = color; Scene.SpriteBatch.Draw(sprite); } }