public override void Update(Room room, Player player) { Vector2 offset = player.position - position; Vector2 range = Main.instance.Size(); if (Math.Abs(offset.X) > range.X / 2f || Math.Abs(offset.Y) > range.Y / 2f) { shootTimer = 0; } else { shootTimer++; if (shootTimer >= maxShootTimer) { Vector2 direction = offset; if (direction != Vector2.Zero) { direction.Normalize(); } direction *= shootSpeed; PositionalBullet bullet = new PositionalBullet(position, direction, 10f, bulletTexture, bulletTime); room.bullets.Add(bullet); shootTimer = 0; } } }
public override void Update(Room room, Player player) { shootTimer++; if (shootTimer >= maxShootTimer) { PositionalBullet bullet = new PositionalBullet(position, shootVelocity, 10f, bulletTexture, bulletTime); room.bullets.Add(bullet); shootTimer = 0; } }
public override void Update(Room room, Player player) { Vector2 offset = player.position - position; float distance = offset.Length(); float range = Tile.tileSize * 6f; float speed = 2f; if (Math.Abs(distance - range) < speed) { speed = Math.Abs(distance - range); } if (distance != 0f) { offset *= speed / distance; } if (distance < range) { offset *= -1f; } bool collided; TopLeft = Collision.MovePos(TopLeft, size, size, offset, room, out collided); offset = player.position - position; shootTimer++; if (shootTimer >= maxShootTimer) { Vector2 direction = offset; if (direction != Vector2.Zero) { direction.Normalize(); } direction *= shootSpeed; PositionalBullet bullet = new PositionalBullet(position, direction, 10f, fireTexture, fireTime); room.bullets.Add(bullet); shootTimer = 0; } }