public void reset()//resets the level { currentState = State.one; wave1.reset(); wave2.reset(); wave3.reset(); wave4.reset(); wave5.reset(); }
public TowerButton(int x, int y)//constructor { towers = new List<Tower>(); START_POSITION_X = x; START_POSITION_Y = y; setPosition(new Vector2(x, y)); mCurrentState = State.Button; scale = 3.0f; }
public Level1()//constructor { currentState = State.one; wave1 = new waves(); wave2 = new waves(); wave3 = new waves(); wave4 = new waves(); wave5 = new waves(); }
public void Update(GameTime theGameTime)//updates appropriate wave and changes level state { if (wave1.getDone() == true)//changes level state by checking if waves are done { currentState = State.two; if (wave2.getDone() == true) { currentState = State.three; if (wave3.getDone() == true) { currentState = State.four; if (wave4.getDone() == true) { currentState = State.five; if (wave5.getDone() == true) { currentState = State.done; } } } } } switch (currentState)//checking wich wave to update { case State.one: wave1.Update(theGameTime); break; case State.two: wave2.Update(theGameTime); break; case State.three: wave3.Update(theGameTime); break; case State.four: wave4.Update(theGameTime); break; case State.five: wave5.Update(theGameTime); break; case State.done: break; } }
public Climbing(State state) { Console.WriteLine("Climbing"); this.smith = state.smith; }
public Moving(State state) { this.smith = state.smith; }
public OnAntiPlatform(State state) { Console.WriteLine("OnAntiPlatfrom"); this.smith = state.smith; grav = Screen.Bounds.Height / timefromtoptobottom; }
private void StopOhgodwhy() { if (mCurrentState == State.Ohgodwhy) { Source = new Rectangle(200, 0, 200, 200); mCurrentState = State.Walking; } }
public Jumping(State state) { this.smith = state.smith; ystrt = smith.prect.Y; jmpht = (int)(Screen.Bounds.Height * jumphtfractionofscreen) ; jumpspeed = jmpht / timeonjump; }
public bool changeMouse() { if (mCurrentState == State.Click && Stats.getGold() >= 50) { return true; } else { mCurrentState = State.Button; return false; } }
private void UpdateClick(MouseState mousestate, MouseState lastmousestate) { if (mCurrentState == State.Click && mouseState.LeftButton == ButtonState.Pressed && lastMouseState.LeftButton == ButtonState.Released && mousestate.X < 800 && Stats.getGold() >= 50) { // **x2** //showGrid(1); TileX = (int)Math.Floor((float)(mousestate.X / tileWidth)); TileY = (int)Math.Floor((float)(mousestate.Y / tileHeight)); squarePositionX = (TileX * tileWidth) + (tileWidth / 2); squarePositionY = (TileY * tileHeight) + (tileHeight / 2); Tower aTower = new Tower("Tower", squarePositionX - 30, squarePositionY - 30); // *X1* Center tower on mouse. Change to 1/2 texture size. aTower.Scale = 0.5f; aTower.LoadContent(mContentManager); towers.Add(aTower); mCurrentState = State.Button; Stats.setGold(Stats.getGold() - 50); } if (mCurrentState == State.Button && mousestate.X > START_POSITION_X && mousestate.X < (START_POSITION_X + (int)(mSpriteTexture.Width * Scale)) && mousestate.Y > START_POSITION_Y && mousestate.Y < (START_POSITION_Y + (int)(mSpriteTexture.Height * Scale))) { //hover over button here if (mouseState.LeftButton == ButtonState.Pressed && lastMouseState.LeftButton == ButtonState.Released) { mCurrentState = State.Click;//button click here } } }
public void reset() { X = START_POSITION_X; Y = START_POSITION_Y; cranes.Clear(); unitCounter = numberOfUnits; state = State.scroll; setPosition(new Vector2(START_POSITION_X, START_POSITION_Y)); done = false; }
private void UpdateCranes(GameTime theGameTime) { if (cranes.Count == 0 && state == State.spawned) { done = true; } for (int i = 0; i < cranes.Count; i++) { cranes[i].Update(theGameTime); if (cranes[i].dead() == true) { cranes.Remove(cranes[i]); } } --cooldown; if (cooldown <= 0 && state == State.spawn) { Pcrane aCrane = new Pcrane(); aCrane.LoadContent(mContentManager); cranes.Add(aCrane); aCrane.Scale = scale; aCrane.setHp(Hp); cooldown = 25; --unitCounter; if (unitCounter == 0) { state = State.spawned; } } }
private void updateMap()//checks button states on the map screen { if (Keyboard.GetState().IsKeyDown(Keys.Enter) == true || lvl1Button.getClicked() == true)//level 1 { gameState = State.level1; levelStart(); lvl1.reset(); lvl1Button.setClicked(false);//reset the button off clicked state return; } if (lvl2Button.getClicked() == true)//level 2 { gameState = State.level2; levelStart(); lvl2.reset(); lvl2Button.setClicked(false);//reset the button off clicked state return; } }
protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); tower1.LoadContent(this.Content); Back1.LoadContent(this.Content, "Back01"); sidebar.LoadContent(this.Content, "side"); sidebar.setPosition(new Vector2(800,0)); topbar.LoadContent(this.Content, "topbar"); topbar.setPosition(new Vector2(0, 0)); title.LoadContent(this.Content, "title"); map.LoadContent(this.Content, "Map"); gameState = State.title; font = Content.Load<SpriteFont>("SpriteFont1"); lvl1Button.LoadContent(this.Content, "lvl"); lvl1Button.setPosition(new Vector2(30, 500)); start.LoadContent(this.Content, "start"); start.setPosition(new Vector2(350, 475)); lvl2Button.LoadContent(this.Content, "lvl"); lvl2Button.setPosition(new Vector2(120, 320)); lvl1.LoadContent(this.Content); lvl2.LoadContent(this.Content); }
private void updateTitle() { if (start.getClicked() == true || Keyboard.GetState().IsKeyDown(Keys.Space) == true) { gameState = State.map; return; } }
protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); if (gameState == State.title) { updateTitle(); start.Update(Mouse.GetState()); } else if (gameState == State.map) { updateMap(); lvl1Button.Update(Mouse.GetState()); lvl2Button.Update(Mouse.GetState()); } else if (gameState == State.level1) { lvl1.Update(gameTime); updateCollision(gameTime, lvl1.getCranes()); updateTarget(lvl1); if(Stats.getLives() <= 0 || lvl1.getDone() == true) { gameState = State.map; } tower1.Update(gameTime); } else if (gameState == State.level2) { lvl2.Update(gameTime); updateCollision(gameTime, lvl2.getCranes()); updateTarget(lvl2); if (Stats.getLives() <= 0 || lvl2.getDone() == true) { gameState = State.map; } tower1.Update(gameTime); } base.Update(gameTime); }
private void UpdateJump(KeyboardState aCurrentKeyboardState) { if (mCurrentState == State.Walking) { if (aCurrentKeyboardState.IsKeyDown(Keys.Space) == true && mPreviousKeyboardState.IsKeyDown(Keys.Space) == false) { Jump(); } } if (mCurrentState == State.Jumping) { if (mStartingPosition.Y - Position.Y > 150) { mDirection.Y = MOVE_DOWN; } if (Position.Y > mStartingPosition.Y) { Position.Y = mStartingPosition.Y; mCurrentState = State.Walking; mDirection = Vector2.Zero; } if (aCurrentKeyboardState.IsKeyDown(Keys.Space) == true && mPreviousKeyboardState.IsKeyDown(Keys.Space) == false) { Jump(); } } }
public Dead(State state) { this.smith = state.smith; smith.prect.X = Screen.Width / 2; smith.prect.Y = Screen.Height / 2; }
private void Ohgodwhy() { if (mCurrentState == State.Walking || mCurrentState == State.Flying) { mSpeed = Vector2.Zero; mDirection = Vector2.Zero; Source = new Rectangle(0, 0, 200, 200); mCurrentState = State.Ohgodwhy; } }
public Falling(State state) { Console.WriteLine("Falling"); this.smith = state.smith; fallspeed = Screen.Width / timetofall; }
//UpdateMovement will detect inputs, then assign speed and direction //Enemy AI function included private void UpdateMovement() { mSpeed = Vector2.Zero; mDirection = Vector2.Zero; //Keep last moving decision for stucking if (LastDecision.X != 0) StuckedDecision.X = LastDecision.X; if (LastDecision.Y != 0) StuckedDecision.Y = LastDecision.Y; //Indicating no movement, state goes to stationary //Then, use last 2 dimentional move to get out from stuck if (LastPosition2 == pos) { mCurrentState = State.Stationary; mSpeed = new Vector2(CHARACTER_SPEED, CHARACTER_SPEED); mDirection = StuckedDecision; } //Indicating Successful movement if (LastPosition1 == pos) mCurrentState = State.Walking; //Position -999, -999 means no target found, stay on or move to its post if (TargetPosition == new Vector2(-999, -999)) { //On the post, no movement needed if (pos.X <= START_POSITION_X+5 && pos.Y <= START_POSITION_Y +5 && pos.X >= START_POSITION_X - 5 && pos.Y >= START_POSITION_Y - 5) { mSpeed = Vector2.Zero; mDirection = Vector2.Zero; } //Out from post, need to go back to the post //Obtain difference from the first Post, then move close to there else if (mCurrentState != State.Stationary) { //Need some modification +2 or +1 to avoid strange movement if (pos.X > START_POSITION_X+2) { mSpeed.X = CHARACTER_SPEED; mDirection.X = MOVE_LEFT; } else if (pos.X <= START_POSITION_X + 2 && pos.X >= START_POSITION_X - 2) { //DO NOTHING } else { mSpeed.X = CHARACTER_SPEED; mDirection.X = MOVE_RIGHT; } if (pos.Y > START_POSITION_Y +2) { mSpeed.Y = CHARACTER_SPEED; mDirection.Y = MOVE_UP; } else if (pos.Y <= START_POSITION_Y + 2 && pos.Y >= START_POSITION_Y - 2) { //DO NOTHING } else { mSpeed.Y = CHARACTER_SPEED; mDirection.Y = MOVE_DOWN; } } } else //Found target and chase { mCurrentState = State.Chasing; if (pos.X > TargetPos.X +2) { currentRow = 0; mSpeed.X = CHARACTER_SPEED; mDirection.X = MOVE_LEFT; } else if (pos.X <= TargetPos.X +2 && pos.X >=TargetPos.X -2) { //DO NOTHING } else { currentRow = 1; mSpeed.X = CHARACTER_SPEED; mDirection.X = MOVE_RIGHT; } if (pos.Y > TargetPos.Y +2) { mSpeed.Y = CHARACTER_SPEED; mDirection.Y = MOVE_UP; } else if (pos.Y <= TargetPos.Y + 2 && pos.Y >= TargetPos.Y - 2) { //DO NOTHING } else { mSpeed.Y = CHARACTER_SPEED; mDirection.Y = MOVE_DOWN; } } }
private void Jump() { if (mCurrentState != State.Jumping) { mCurrentState = State.Jumping; mStartingPosition = Position; mDirection.Y = MOVE_UP; mSpeed = new Vector2(BEE_SPEED, BEE_SPEED); } }
private void Flight(KeyboardState aCurrentKeyboardState) { if (mCurrentState == State.Walking) { mSpeed = Vector2.Zero; mDirection = Vector2.Zero; mCurrentState = State.Flying; } if(mCurrentState == State.Flying) { mSpeed = Vector2.Zero; mDirection = Vector2.Zero; FlightAnimation(aCurrentKeyboardState); if (aCurrentKeyboardState.IsKeyDown(Keys.Left) == true || aCurrentKeyboardState.IsKeyDown(Keys.A) == true) { mSpeed.X = BEE_SPEED; mDirection.X = MOVE_LEFT; } else if (aCurrentKeyboardState.IsKeyDown(Keys.Right) == true || aCurrentKeyboardState.IsKeyDown(Keys.D) == true) { mSpeed.X = BEE_SPEED; mDirection.X = MOVE_RIGHT; } if (aCurrentKeyboardState.IsKeyDown(Keys.Up) == true || aCurrentKeyboardState.IsKeyDown(Keys.W) == true) { mSpeed.Y = BEE_SPEED; mDirection.Y = MOVE_UP; } else if (aCurrentKeyboardState.IsKeyDown(Keys.Down) == true || aCurrentKeyboardState.IsKeyDown(Keys.S) == true) { mSpeed.Y = BEE_SPEED; mDirection.Y = MOVE_DOWN; } } }
private void UpdateMovement() { if (state == State.scroll) { mSpeed = Vector2.Zero; mDirection = Vector2.Zero; if (X > 270) { mSpeed.X = 100; mDirection.X = MOVE_LEFT; X = X + MOVE_LEFT; } if (X == 270) { state = State.spawn; --X; mSpeed = Vector2.Zero; mDirection = Vector2.Zero; } } }
private void StopFlight() { if (mCurrentState == State.Flying) { if (Position.Y > 450) { Position.Y = 450; mCurrentState = State.Walking; mDirection = Vector2.Zero; } Source = new Rectangle(200, 0, 200, 200); mCurrentState = State.Walking; } if (mCurrentState == State.Walking) { if (Position.Y < 450) { mSpeed.Y = BEE_SPEED; mDirection.Y = MOVE_DOWN; } } }
public void setState(State newState) { switch (state) { case State.STATE_GAMEPLAY: // reset the map and player data player1.reset(); player2.reset(); mapLayer.reset(); mapLayer.setSpeed(2.25); break; case State.STATE_SCORES: score = 0; break; default: break; } state = newState; foreach (RenderTarget2D tex in renderTarget) { //graphics.GraphicsDevice.SetRenderTarget(tex); //GraphicsDevice.Clear(Color.CornflowerBlue); } graphics.GraphicsDevice.SetRenderTarget(null); }
public void Update(GameTime theGameTime, KeyboardState state) { if (MovingUp == 1 || MovingUp == -1) { mCurrentState = State.Moving; } else { mCurrentState = State.Still; } this.UpdateMovement(mMoveUp); mPreviousPosition = Position; base.Update(theGameTime, mSpeed, mDirection); this.CheckWallCollision(); mPreviousState = mCurrentState; }
public void Update(GameTime theGameTime) { this.UpdateMovement(); base.Update(theGameTime, mSpeed, mDirection); if (Hp <= 0 && mCurrentState == State.Walking) { this.Visible = false; Stats.setGold(Stats.getGold() + 10); mCurrentState = State.Dead; } }
//UpdateMovement will detect inputs, then assign speed and direction //Enemy AI function included private void UpdateMovement() { currentRow = 1; mSpeed = Vector2.Zero; mDirection = Vector2.Zero; if (gState == GameState.Escape) { //Keep last moving decision for stucking if (LastDecision.X != 0) StuckedDecision.X = LastDecision.X; if (LastDecision.Y != 0) StuckedDecision.Y = LastDecision.Y; //Position did not change before movement that //indicating stuck on object, state goes to stationary //Then, use last 2 dimentional move to get out from stuck if (LastPosition2 == pos) { mCurrentState = State.Stationary; mSpeed = new Vector2(CHARACTER_SPEED, CHARACTER_SPEED); mDirection = StuckedDecision; } //Position is same as the after move. Successfuly moved. //Indicating got out from stuck, change state to walking if (LastPosition1 == pos) mCurrentState = State.Walking; //Close enought to player if (pos.X <= TargetPos.X + 15 * 1.7f && pos.X >= TargetPos.X - 35 * 1.7f && pos.Y <= TargetPos.Y + 15 * 1.7f && pos.Y >= TargetPos.Y - 45 * 1.7f) { currentRow = 1; mSpeed = Vector2.Zero; mDirection = Vector2.Zero; } else if (mCurrentState != State.Stationary) { if (pos.X > TargetPos.X - 15) { currentRow = 0; mSpeed.X = CHARACTER_SPEED; mDirection.X = MOVE_LEFT; } else if (pos.X <= TargetPos.X -12 && pos.X >= TargetPos.X - 18) { //DO NOTHING } else { currentRow = 4; mSpeed.X = CHARACTER_SPEED; mDirection.X = MOVE_RIGHT; } if (pos.Y > TargetPos.Y - 15) { currentRow = 2; mSpeed.Y = CHARACTER_SPEED; mDirection.Y = MOVE_UP; } else if (pos.Y <= TargetPos.Y -12 && pos.Y >= TargetPos.Y - 18) { //DO NOTHING } else { currentRow = 1; mSpeed.Y = CHARACTER_SPEED; mDirection.Y = MOVE_DOWN; } } if (characterStatus == 4) { currentRow = 3; mSpeed = Vector2.Zero; mDirection = Vector2.Zero; mCurrentState = State.Walking; } if (characterStatus == 5) { currentRow = 1; mSpeed = Vector2.Zero; mDirection = Vector2.Zero; mCurrentState = State.Walking; } } }