private void Shoot(Ship entity) { Bullet b = entity.Shoot(); if (b != null) { CurrentLevel.AddEntity(b, CurrentLevel.EntityLayer); } }
public void ResetGame() { Body body = BodyFromTexture(shipTexture, WorldConversions.ShipDensity); CurrentEnemy = new EnemyShip(shipTexture, CurrentLevel.Bounds, CurrentLevel.PhysicsWorld, body); CurrentEnemy.Body.IsStatic = false; CurrentEnemy.Position = new Vector2(0, 200); CurrentEnemy.Color = Color.Blue; CurrentEnemy.Rotation = (float)Math.PI / 2; // CurrentEnemy.AI.Hate(CurrentLevel.Player, 0.1f); CurrentEnemy.RearThruster = new Engine("Thuster MkI", EngineDirection.Rear); CurrentEnemy.Weapon = new Weapon("Uberweapon", Content.Load <SoundEffect>("Samples/laser"), bulletTexture); CurrentLevel.AddEntity(CurrentEnemy, EntityLayer, false); }
private void AddPlanets(BackgroundLayer layer) { List <Texture2D> planets = new List <Texture2D>(); planets.Add(Content.Load <Texture2D>("Images/sun")); planets.Add(Content.Load <Texture2D>("Images/earth")); planets.Add(Content.Load <Texture2D>("Images/jupiter")); Random r = new Random(); Rectangle areaSize = CurrentLevel.Bounds; List <Entity> testList = new List <Entity>(); const float minDistance = 1500; for (int i = 0; i < 20; i++) { Planet planet = new Planet(planets[r.Next(planets.Count)], areaSize, CurrentLevel.PhysicsWorld); bool found = false; while (!found) { planet.Position = Interpolations.GetRandomRectanglePoint(areaSize, r); int tooClose = 0; foreach (Entity e in testList) { if (Vector2.Distance(planet.Position, e.Position) < minDistance) { tooClose++; } } found = (tooClose == 0); } planet.Scale = 2.0f; planet.Rotation = (float)r.NextDouble() * MathHelper.PiOver2; planet.PlanetRotation = (float)r.NextDouble() * 0.0005f; CurrentLevel.AddEntity(planet, layer, true); testList.Add(planet); } }