public void Reset() { hasGloves = false; hasBoots = false; hasENVSuit = false; hasSpaceSuit = false; hasJetpack = false; hasUsedJetPack = false; JetPackState = 1; enterPosition.X = 900; enterPosition.Y = 830; oxygen = 1000; oxygenCap = 1000; fuel = 500; fuelCap = 500; lives = 3; numBombs = 10; hasDiedRecently = false; standingOn = null; onWall = true; jumpCounter = 0; }
/// <summary> /// lets ship know to destroy an object (such as bomb or power up) /// </summary> /// <param name="o"></param> public void Destroy(SolitudeObject o) { toKill.Add(o); }
public override void Update() { if (jetpackZero + TimeSpan.FromSeconds(3) < DateTime.Now) { refuelling = true; } if (refuelling && fuel < fuelCap) { if (refuel % 2 == 0) { fuel++; } refuel++; } //update health and fuel bars hpBar.Update(); fBar.Update(); //if moving, make sure not on wall if (!body.LinearVelocity.Equals(Vector2.Zero)) { jumpCounter = 0; onWall = false; standingOn = null; } if (onWall) { //get input vector.X = GameElements.GameWorld.controller.ContainsFloat(Inputs.ActionType.MoveHorizontal); vector.Y = -1 * GameElements.GameWorld.controller.ContainsFloat(Inputs.ActionType.MoveVertical); //if B pressed on door, enter next room if (standingOn is Door && GameElements.GameWorld.controller.ContainsBool(Inputs.ActionType.BButtonFirst)) { (standingOn as Door).Enter(); jumpCounter = 0; } //if the A button is held down if (GameElements.GameWorld.controller.ContainsBool(Inputs.ActionType.AButton)) { //power up jump if (jumpCounter < 125) { jumpCounter++; }else{ jumpCounter = 100; } // Draw arrow vector.Normalize(); int arrowDistance = 50; rotation = (float)Math.Atan(vector.Y / vector.X) - (float)Math.PI / 2; if (vector.X >= 0) rotation += (float)Math.PI; arrowbodyPosition = new Vector2( body.Position.X + arrowDistance * vector.X, body.Position.Y + arrowDistance * vector.Y); arrowheadPosition = new Vector2( arrowbodyPosition.X + vector.X * (jumpCounter + 15), arrowbodyPosition.Y + vector.Y * (jumpCounter + 15)); } else //A is not pressed { if (jumpCounter > 0) { //jump if (!vector.Equals(Vector2.Zero)) { vector.Normalize(); body.ApplyLinearImpulse(2000 * vector * (jumpCounter + 25)); onWall = false; standingOn = null; } } jumpCounter = 0; } } //update jetpack if (hasJetpack && fuel > 0) { vector.X = GameElements.GameWorld.controller.ContainsFloat(Inputs.ActionType.LookHorizontal); vector.Y = -1 * GameElements.GameWorld.controller.ContainsFloat(Inputs.ActionType.LookVertical); if (!vector.Equals(Vector2.Zero)) { jetpackZero = DateTime.Now; refuelling = false; refuel = 0; vector.Normalize(); fuel--; body.ApplyForce(vector * Settings.jetPackForceMult); hasUsedJetPack = true; if (JetPackState < 100) JetPackState++; } } //set a bomb if (GameElements.GameWorld.controller.ContainsBool(Inputs.ActionType.XButtonFirst)) { if (Settings.maxBombs > SolitudeScreen.ship.bombCount && !onWall && numBombs > 0) { vector.X = GameElements.GameWorld.controller.ContainsFloat(Inputs.ActionType.MoveHorizontal); vector.Y = -1 * GameElements.GameWorld.controller.ContainsFloat(Inputs.ActionType.MoveVertical); //if the player is holding a direction if (!vector.Equals(Vector2.Zero)) { vector.Normalize(); //numBombs--; body.ApplyForce(vector * Settings.bombForce); //calculate the bomb's speed Vector2 bombSpeed = new Vector2(); bombSpeed = -1 * vector * body.LinearVelocity.Length(); Bomb b = new Bomb(body.Position - 50 * vector, SolitudeScreen.ship.PhysicalWorld, bombSpeed); SolitudeScreen.ship.contents.Add(b); SolitudeScreen.ship.bombCount++; } } } if (oxygen <= 0 ) { if (lives > 0 /*&& !hasDiedRecently*/) { //die, and place player back at start of room lives--; standingOn = enterDoor; body.Position = enterPosition; onWall = true; body.LinearVelocity = Vector2.Zero; body.AngularVelocity = 0f; oxygen = oxygenCap; hasDiedRecently = true; SolitudeScreen.ship.ResetRoom(); } else { SolitudeScreen.ship.screen.GameOver(); //SolitudeScreen.ship.endGameFlag = true; //gameover } } }
public override void Update() { if (jetpackZero + TimeSpan.FromSeconds(3) < DateTime.Now) { refuelling = true; } if (refuelling && fuel < fuelCap) { if (refuel % 2 == 0) { fuel++; } refuel++; } //update health and fuel bars hpBar.Update(); fBar.Update(); //if moving, make sure not on wall if (!body.LinearVelocity.Equals(Vector2.Zero)) { jumpCounter = 0; onWall = false; standingOn = null; } if (onWall) { //get input vector.X = GameElements.GameWorld.controller.ContainsFloat(Inputs.ActionType.MoveHorizontal); vector.Y = -1 * GameElements.GameWorld.controller.ContainsFloat(Inputs.ActionType.MoveVertical); //if B pressed on door, enter next room if (standingOn is Door && GameElements.GameWorld.controller.ContainsBool(Inputs.ActionType.BButtonFirst)) { (standingOn as Door).Enter(); jumpCounter = 0; } //if the A button is held down if (GameElements.GameWorld.controller.ContainsBool(Inputs.ActionType.AButton)) { //power up jump if (jumpCounter < 125) { jumpCounter++; } else { jumpCounter = 100; } // Draw arrow vector.Normalize(); int arrowDistance = 50; rotation = (float)Math.Atan(vector.Y / vector.X) - (float)Math.PI / 2; if (vector.X >= 0) { rotation += (float)Math.PI; } arrowbodyPosition = new Vector2( body.Position.X + arrowDistance * vector.X, body.Position.Y + arrowDistance * vector.Y); arrowheadPosition = new Vector2( arrowbodyPosition.X + vector.X * (jumpCounter + 15), arrowbodyPosition.Y + vector.Y * (jumpCounter + 15)); } else //A is not pressed { if (jumpCounter > 0) { //jump if (!vector.Equals(Vector2.Zero)) { vector.Normalize(); body.ApplyLinearImpulse(2000 * vector * (jumpCounter + 25)); onWall = false; standingOn = null; } } jumpCounter = 0; } } //update jetpack if (hasJetpack && fuel > 0) { vector.X = GameElements.GameWorld.controller.ContainsFloat(Inputs.ActionType.LookHorizontal); vector.Y = -1 * GameElements.GameWorld.controller.ContainsFloat(Inputs.ActionType.LookVertical); if (!vector.Equals(Vector2.Zero)) { jetpackZero = DateTime.Now; refuelling = false; refuel = 0; vector.Normalize(); fuel--; body.ApplyForce(vector * Settings.jetPackForceMult); hasUsedJetPack = true; if (JetPackState < 100) { JetPackState++; } } } //set a bomb if (GameElements.GameWorld.controller.ContainsBool(Inputs.ActionType.XButtonFirst)) { if (Settings.maxBombs > SolitudeScreen.ship.bombCount && !onWall && numBombs > 0) { vector.X = GameElements.GameWorld.controller.ContainsFloat(Inputs.ActionType.MoveHorizontal); vector.Y = -1 * GameElements.GameWorld.controller.ContainsFloat(Inputs.ActionType.MoveVertical); //if the player is holding a direction if (!vector.Equals(Vector2.Zero)) { vector.Normalize(); //numBombs--; body.ApplyForce(vector * Settings.bombForce); //calculate the bomb's speed Vector2 bombSpeed = new Vector2(); bombSpeed = -1 * vector * body.LinearVelocity.Length(); Bomb b = new Bomb(body.Position - 50 * vector, SolitudeScreen.ship.PhysicalWorld, bombSpeed); SolitudeScreen.ship.contents.Add(b); SolitudeScreen.ship.bombCount++; } } } if (oxygen <= 0) { if (lives > 0 /*&& !hasDiedRecently*/) { //die, and place player back at start of room lives--; standingOn = enterDoor; body.Position = enterPosition; onWall = true; body.LinearVelocity = Vector2.Zero; body.AngularVelocity = 0f; oxygen = oxygenCap; hasDiedRecently = true; SolitudeScreen.ship.ResetRoom(); } else { SolitudeScreen.ship.screen.GameOver(); //SolitudeScreen.ship.endGameFlag = true; //gameover } } }