public void GetLocationY() { World world = new World(); Socket socket; IPAddress ip; networking.MakeSocket("localhost", out socket, out ip); SocketState ss = new SocketState(socket); ship sh = new ship(1, ss, 5, new Vector2D(8, 8), "JoCee", 0, new Vector2D(9, 9), 7); Assert.AreEqual(sh.GetLocation().GetY(), 8); }
/// <summary> /// Will check to see if the screen has flown off screen. If it has, it will wrap the ship around to the other side of the screen /// </summary> /// <param name="sh"></param> public void checkIfOffScreen(ship sh) { if (sh.GetLocation().GetX() > universeSize / 2 || sh.GetLocation().GetX() < -universeSize / 2) { //we will want it to keep the y position and just rotate to the other side of the screen. double yLocation = sh.GetLocation().GetY(); double oldxLocation = sh.GetLocation().GetX(); Vector2D newLocation = new Vector2D(-(oldxLocation), yLocation); //Set the ship location to the new location sh.setLocation(newLocation); } if (sh.GetLocation().GetY() > universeSize / 2 || sh.GetLocation().GetY() < -universeSize / 2) { //we will want it to keep the y position and just rotate to the other side of the screen. double yLocation = sh.GetLocation().GetY(); double xLocation = sh.GetLocation().GetX(); Vector2D newLocation = new Vector2D(xLocation, -yLocation); sh.setLocation(newLocation); } }
// This method is invoked when the DrawingPanel needs to be re-drawn /// <summary> /// Draws all the players, stars and projectiles each time the form is invalidated. /// The lock is used so cross-threads can't screw it up! /// </summary> /// <param name="e"></param> protected override void OnPaint(PaintEventArgs e) { // Draw the players // Draw the stars // Draw the projectiles. lock (world) { foreach (var shipper in world.playersInWorld.ToList()) { ship p = shipper.Value as ship; if (p.hp > 0) // If the HP is above zero, the ship deserves to be drawn. { DrawObjectWithTransform(e, p, world.worldPanel.Size.Width, p.GetLocation().GetX(), p.GetLocation().GetY(), p.GetDirections().ToAngle(), shipDrawer); } } foreach (var starry in world.starsInWorld.ToList()) { star p = starry.Value as star; DrawObjectWithTransform(e, p, world.worldPanel.Size.Width, p.GetLocation().GetX(), p.GetLocation().GetY(), 0, starDrawer); } foreach (var proj in world.projectilesInWorld.ToList()) { projectile p = proj.Value as projectile; if (p.alive == true) { DrawObjectWithTransform(e, p, world.worldPanel.Size.Width, p.GetLocation().GetX(), p.GetLocation().GetY(), p.GetDirections().ToAngle(), projectileDrawer); } else // If it's dead, can be removed from the projectile list. { world.projectilesInWorld.Remove(p.ID); } } } // Do anything that Panel (from which we inherit) needs to do base.OnPaint(e); }