public void Update(PickupManager pickups, PlanetColecction planets) { ship.Update(pickups); pDock = null; foreach (var planet in planets.Planets) { if (Tool.distance2(ship.Locaion, planet.Position) < planet.Size) { pDock = planet; } } }
public void update(PickupManager pickUps, Ship player, PlanetColecction planets) { for (int i = 0; i < roids.Count; i++) { roids[i].Update(); // calculate force of gravity roids[i].setAcceleration(new Vector2(0, 0)); float disPlanet = float.MaxValue; // distance to closest planet; foreach (var planet in planets.Planets) { float disP = Tool.distance(roids[i].Locaion, planet.Position); if (disPlanet > disP) { disPlanet = disP; } if (Tool.magnitude(roids[i].Acceleration) < 10f) { Vector2 planetAcel = Tool.getPlanetGravity(planet, roids[i].Locaion, roids[i].Mass); roids[i].addAcceleration(planetAcel); } } float distancePlayer = Tool.distance(roids[i].Locaion, player.Locaion); // test damage if (distancePlayer < 1000f) { for (int j = 0; j < player.Shot.Count; j++) { float distanceShot = Tool.distance(roids[i].Locaion, player.Shot[j].Location); if (distanceShot < roids[i].Size * roids[i].CellSize * 1.5f) { if (roids[i].testHit(player.Shot[j].Location, player.Shot[j].Damage, pickUps)) { player.removeShot(j); j--; } } } } if (!roids[i].Live || disPlanet > 80000f) { roids.RemoveAt(i); i--; continue; } } }
public bool testHit(Vector2 loc, int damage, PickupManager pickUps) { Cell hit = CellIntercect(loc, 1, .4f); if (hit != null) { if (hit.Live) { PickUp drop = hit.subHealthPickup(damage, (int)(CellSize - 2)); if (drop != null && hit.Type != CellType.Fill) { float offset = (float)Math.Atan2(hit.X, hit.Y); float velx = (float)Math.Cos(rotSpeed + offset); float vely = (float)Math.Sin(rotSpeed + offset); drop.Velocity = new Vector2(velx, vely) + velocity; pickUps.Add(drop); } return(true); } } return(false); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { screenHeight = 800; screenWidth = 1600; graphics.PreferredBackBufferHeight = screenHeight; graphics.PreferredBackBufferWidth = screenWidth; graphics.ApplyChanges(); this.IsMouseVisible = true; station = new Station(new Vector2(0, 0)); planets = new PlanetColecction(); player = new Player(planets.Planets[0], screenWidth, screenHeight, 200); player.startBuild(screenWidth * .5f, screenHeight * .5f); pickups = new PickupManager(); camera = new Camera(screenWidth * 0.5f, screenHeight * .5f, 0.75f, screenWidth, screenHeight); astroroids = new AstroroidManager(); stars = new StarManager(camera); screen = Screen.build; base.Initialize(); }
public void Update(PickupManager pickups) { UpdateMovement(); if (shotCooldown > 0) { shotCooldown--; } for (int i = 0; i < Shot.Count; i++) { Shot[i].Update(); if (Shot[i].Life < 0) { Shot.RemoveAt(i); i--; } } if (usedCargo < cargo) { for (int i = 0; i < pickups.Count; i++) { float distance = Tool.distance(location, pickups.Index(i).Location); if (distance < 50) { addItem(pickups.CollectAt(i)); continue; } if (distance < 400) { pickups.Index(i).MoveTo(Locaion, 10f); } } } }