protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } if (Keyboard.GetState().IsKeyDown(Keys.Enter) && connected == false) { connectToServer(); } if (!player.isLanding()) { if (Keyboard.GetState().IsKeyDown(Keys.W) == true) { player.thrust(); } if (Keyboard.GetState().IsKeyDown(Keys.S) == true) { player.reverse(); } if (Keyboard.GetState().IsKeyDown(Keys.D) == true) { player.rotateRight(); } if (Keyboard.GetState().IsKeyDown(Keys.A) == true) { player.rotateLeft(); } if (Keyboard.GetState().IsKeyDown(Keys.Q) == true) { player.leftThrust(); } if (Keyboard.GetState().IsKeyDown(Keys.E) == true) { player.rightThrust(); } if (Keyboard.GetState().IsKeyDown(Keys.Space) == true) { player.brake(); } if (Keyboard.GetState().IsKeyDown(Keys.H) == true && player.getSpeed() < player.MAX_SPEED_TO_LAND) { List <SpaceObject> spaceObjects = world.getSpaceObjects(); for (int index = 0; index < spaceObjects.Count; index++) { if (Math2.inRadius(player.getPos().X, player.getPos().Y, spaceObjects[index].getXpos(), spaceObjects[index].getYpos(), spaceObjects[index].getRadius())) { player.land(spaceObjects[index]); index = spaceObjects.Count; } } } } if (Keyboard.GetState().IsKeyDown(Keys.G) == true) { player.takeOff(); } if (Mouse.GetState().LeftButton == ButtonState.Pressed) { Laser l = player.fireWeapon(new Vector2(Mouse.GetState().Position.X, Mouse.GetState().Position.Y)); if (l != null) { movingObjects.Add(l); } } bob.nearby(); bob.updatePosition(world); foreach (MovingObject mo in movingObjects) { mo.update(world); } connectToServer(); cam.UpdateCamera(viewport); base.Update(gameTime); }
protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } //bob.travelToTarget(player.getPos(), 1, 4); //bob.rotateToTarget(player.getPos()); player.update(world); if (Keyboard.GetState().IsKeyDown(Keys.Enter) && connected == false) { try { handler.connectToServer(); connected = true; } catch (Exception e) { connected = false; System.Diagnostics.Debug.WriteLine("Could not connect!"); } } if (Keyboard.GetState().IsKeyDown(Keys.T) == true) { player.onMap(); } else { player.offMap(); if (player.isAlive()) { if (!player.isLanding()) { if (!player.isCooling()) { if (Keyboard.GetState().IsKeyDown(Keys.W) == true) { player.thrust(); } } if (/*!player.isBoosting() && !player.isCooling()*/ 1 == 1) { if (Keyboard.GetState().IsKeyDown(Keys.S) == true) { player.reverse(); } if (Keyboard.GetState().IsKeyDown(Keys.D) == true) { player.rotateRight(); } if (Keyboard.GetState().IsKeyDown(Keys.A) == true) { player.rotateLeft(); } if (Keyboard.GetState().IsKeyDown(Keys.Q) == true) { player.leftThrust(); } if (Keyboard.GetState().IsKeyDown(Keys.E) == true) { player.rightThrust(); } if (Keyboard.GetState().IsKeyDown(Keys.Space) == true) { player.brake(); } if (Keyboard.GetState().IsKeyDown(Keys.H) == true && player.getSpeed() < player.MAX_SPEED_TO_LAND) { for (int index = 0; index < objects.Count; index++) { if (objects[index].getType() == ObjectType.ASTEROID || objects[index].getType() == ObjectType.MINING_PLANET) { if (Math2.inRadius(player.getPos(), objects[index].getPos(), ((SpaceObject)objects[index]).getRadius())) { player.land((SpaceObject)objects[index]); index = objects.Count; } } } } if (!player.isCooling()) { if (Mouse.GetState().LeftButton == ButtonState.Pressed) { Laser l = player.fireWeapon(new Vector2(Mouse.GetState().Position.X, Mouse.GetState().Position.Y)); if (l != null) { projectiles.Add(l); } //Console.WriteLine(Mouse.GetState().Position.X.ToString() + ", " + Mouse.GetState().Position.Y.ToString()); } } } if (!player.isCooling()) { if (Keyboard.GetState().IsKeyDown(Keys.LeftShift) == true) { player.boost(); } } if (Keyboard.GetState().IsKeyDown(Keys.LeftShift) == false || player.isCooling()) { player.noBoost(); } } else { if (Keyboard.GetState().IsKeyDown(Keys.M) == true) { if (player.getCapacity() > 0) { player.mine(); } } if (Keyboard.GetState().IsKeyDown(Keys.G) == true) { player.takeOff(); } } } } toBeDestroyed.Clear(); foreach (AI o in ships.ToList()) { if (!o.isAlive()) { ships.Remove(o); } else { o.update(world); /*foreach(Object obj in objects) { * if (obj.getType() == ObjectType.PROJECTILE) { * Projectile p = (Projectile)obj; * //p.update(world); * if (o.isHit(p) && p.getID() != o.getID()) { * p.getHit(0); * o.getHit(p.getPower()); * //Console.WriteLine("Projectile " + o2.getID() + " hit " + o.getID()); * } * } * }*/ } } foreach (Projectile p in projectiles.ToList()) { if (!p.isAlive()) { projectiles.Remove(p); } else { p.update(world); } } foreach (Faction f in world.factions) { f.update(); } foreach (Object o in toBeDestroyed) { objects.Remove(o); } //connectToServer(); cam.UpdateCamera(viewport); base.Update(gameTime); }