/// <summary> /// This method is used to move ship/ /// </summary> /// <param name="s"></param> private static void moveShip(Ship s) { //calls the method shipFuntion from world class. s.shipFunctions(); //sets gravity to 0,0. Vector2D g = new Vector2D(0, 0); //calculate g. g = star.getStarLoc() - s.getShipLoc(); g.Normalize(); //gets the mass of the star from xml file. g = g * star.getStarMass(); Vector2D a = new Vector2D(0, 0); //the ship is thrusting. if (s.getShipThrust()) { Vector2D t = new Vector2D(s.getShipDir()); //calculate the thrust and apply to gravity. t = t * 0.08; a = g + t; } else { //else acceleration is equal to gravity. a = g; } //set thr ships velocity and location. s.setShipVelocity(s.getShipVelocity() + a); s.setShipLoc(s.getShipLoc() + s.getShipVelocity()); }
/// <summary> /// this method checks if the ship is going out of the universe. /// </summary> /// <param name="s"></param> private static void shipsPosition(Ship s) { //if ships x is greater than universize by 2. if (s.getShipLoc().GetX() > (UniverseSize / 2)) { //set ship to the opposite location. s.setShipLoc(new Vector2D((-UniverseSize / 2), (s.getShipLoc().GetY()))); } //if ships y os greter than universesize by two if (s.getShipLoc().GetY() > (UniverseSize / 2)) { //set ship to the opposite location. s.setShipLoc(new Vector2D((s.getShipLoc().GetX()), (-(UniverseSize / 2)))); } //if ships x is less than universize by 2. if (s.getShipLoc().GetX() < -(UniverseSize / 2)) { //set ship to the opposite location. s.setShipLoc(new Vector2D(((UniverseSize / 2)), s.getShipLoc().GetY())); } //if ships y os less than universesize by two if (s.getShipLoc().GetY() < -(UniverseSize / 2)) { //set ship to the opposite location. s.setShipLoc(new Vector2D((s.getShipLoc().GetX()), (UniverseSize / 2))); } }
/// <summary> /// This method calculates ship and star collsion. /// </summary> /// <param name="s"></param> private static void ShipStarCollision(Ship s) { foreach (Star star in world.starCollection.Values) { //if star location minus ship location length is less that 35, we set //ships hp to 0. if ((star.getStarLoc() - s.getShipLoc()).Length() < 35) { s.setShipHp(0); } } }
/// <summary> /// This method calculates Projectile and ship collision. /// </summary> /// <param name="s"></param> private static void ProjectileShipCollision(Ship s) { foreach (Projectile p in world.projectileCollection.Values.ToList()) { //if ship hp is not equal to zero. if (s.getShipHp() != 0) { //if projectile location and ship location is less than 25 and projectile is alive. if ((p.getProjectileLoc() - s.getShipLoc()).Length() < 25 && (p.getProjectileOwner() != s.getShipId())) { //get the score and hp for the owner of the projectile. int score = world.shipCollection[p.getProjectileOwner()].getShipScore(); int hp = world.shipCollection[p.getProjectileOwner()].getShipHp(); //decrement ships hp by 1. s.setShipHp(s.getShipHp() - 1); //for extra game mode. if (gameMode == 1) { //if projectile owner hp is less than 5. if (world.shipCollection[p.getProjectileOwner()].getShipHp() < 5) { //icrement the ships hp by 1, if it hits other ship. world.shipCollection[p.getProjectileOwner()].setShipHp((s.getShipHp() + 1)); } } p.setProjectileAlive(false); //id ship hp is zer0. if (s.getShipHp() == 0) { //extra game mode. if (gameMode == 1) { if (hp < 5) { //increments hp by 1. world.shipCollection[p.getProjectileOwner()].setShipHp(hp + 1); } } //increments score by 1. world.shipCollection[p.getProjectileOwner()].setShipScore(score + 1); } } } } }