private void Jump(WallMap wallMap) { if (velocity.Y > 0) { PlayerState = State.fall; } isJumping = false; if (playerLeft == true) { MoveLeft(); objectAnimated.Effect = SpriteEffects.FlipHorizontally; } if (playerRight == true) { MoveRight(); objectAnimated.Effect = SpriteEffects.None; } //wall jump if (playerJump && CanWallJump(wallMap) != Rectangle.Empty) { wallDir = (int)direction.X; PlayerState = State.wallJump; velocity.Y = 0; } }
public override void Update(List <GameObject> objects, WallMap wallMap, GameTime gametime) { if (HUD.canMove == true) { UpdateMovement(objects, wallMap); } //are we on the ground var testRect = OnGround(wallMap); if (testRect != Rectangle.Empty) { isOnGround = true; } else { isOnGround = false; } //reset jumping bool if (OnGround(wallMap) != Rectangle.Empty) { isJumping = false; } base.Update(objects, wallMap, gametime); pastBoundingBoxBottom = BoundingBox.Bottom; }
private void Attack(List <GameObject> objects, WallMap wallMap) { if (attackTimer > maxTimer * (3 / 4) || attackTimer <= 0) { damageObject.StartTimer(); damageObject.active = true; attackTimer = maxTimer; } damageObject.position = position + (new Vector2(18 + (Math.Abs(velocity.X) * 2), 0) * direction); if (!isOnGround && !isOnStairs && !isWallJumping) { if (playerLeft == true) { MoveLeft(); objectAnimated.Effect = SpriteEffects.FlipHorizontally; } if (playerRight == true) { MoveRight(); objectAnimated.Effect = SpriteEffects.None; } } else if (isOnGround) { velocity.X = TendToZero(velocity.X, friction); } }
private void UpdateMovement(List <GameObject> objects, WallMap wallMap) { if (canCollide == true && (velocity.X != 0) && collision.CheckCollisions(this, wallMap, objects, true) == true) { velocity.X = 0; } position.X += velocity.X; if (canCollide == true && (velocity.Y != 0) && collision.CheckCollisions(this, wallMap, objects, false) == true) { velocity.Y = 0; } position.Y += velocity.Y; //check if should apply gravity if (applyGravity == true) { ApplyGravity(wallMap); } // friction on Y if not using gravity if (applyGravity == false) { velocity.Y = TendToZero(velocity.Y, friction); } }
private void Walk(WallMap wallMap) { //stop moving velocity.X = TendToZero(velocity.X, friction); velocity.Y = TendToZero(velocity.X, friction); if (playerLeft == true) { MoveLeft(); objectAnimated.Effect = SpriteEffects.FlipHorizontally; } if (playerRight == true) { MoveRight(); objectAnimated.Effect = SpriteEffects.None; } if (playerUp == true) { MoveUp(); objectAnimated.Effect = SpriteEffects.None; } if (playerDown == true) { MoveDown(); objectAnimated.Effect = SpriteEffects.None; } if (!playerLeft && !playerRight && !playerUp && !playerDown) { PlayerState = State.idle; } }
private void Idle(WallMap wallMap) { //stop moving velocity.X = TendToZero(velocity.X, friction); velocity.Y = TendToZero(velocity.X, friction); //switch to walk }
private void Walk(WallMap wallMap) { if (playerLeft == true) { MoveLeft(); objectAnimated.Effect = SpriteEffects.FlipHorizontally; } if (playerRight == true) { MoveRight(); objectAnimated.Effect = SpriteEffects.None; } //switch to jump if (playerJump == true && isJumping == false) { velocity.Y -= jumpHeight; PlayerState = State.jump; isJumping = true; } if (isOnGround == false) { PlayerState = State.fall; } //check to see if we are moving if (playerLeft == false && playerRight == false) { PlayerState = State.idle; } if (playerJump == true && isJumping == false) { velocity.Y -= jumpHeight; PlayerState = State.jump; } // climb stairs if contacting if (playerUp == true) { var stairTest = AtBottomOfStairs(wallMap); if (stairTest != Rectangle.Empty) { isOnStairs = true; PlayerState = State.stairs; } } if (playerDown == true) { var stairTest = AtTopOfStairs(wallMap); if ((stairTest != Rectangle.Empty) && (isOnGround)) { isOnStairs = true; PlayerState = State.stairs; } } }
public override void Update(List <GameObject> _objects, WallMap wallMap, GameTime gameTime) { if (rupeeCount >= 100) { rupeeCount -= 100; } RupeeAddition(); //textBox.Update(_objects, wallMap, gameTime); base.Update(_objects, wallMap, gameTime); }
private void Duck(WallMap wallMap) { velocity.X = TendToZero(velocity.X, friction); boundingBoxTopLeft = duckBoundingBox; if (playerDown == false) { boundingBoxTopLeft = standingBoundingBox; PlayerState = State.idle; } }
protected Rectangle OnGround(WallMap wallMap) { Rectangle futureBoundingBox = new Rectangle((int)((BoundingBox.X)), (int)((BoundingBox.Y) + (1)), (int)(BoundingBox.Width), (int)(BoundingBox.Height)); return(wallMap.CheckCollision(futureBoundingBox)); }
protected Rectangle AtTopOfStairs(WallMap wallMap) { Rectangle futureBoundingBox = new Rectangle((int)((BoundingBox.X)), (int)((BoundingBox.Y) + BoundingBox.Height + 1), (int)(BoundingBox.Width), (int)(2)); return(wallMap.StairCollision(futureBoundingBox)); }
private void DuckAttack(List <GameObject> objects, WallMap wallMap) { if (attackTimer <= 0) { damageObject.position = position + new Vector2(0, 6) + (new Vector2(18, 0) * direction); damageObject.StartTimer(); damageObject.active = true; attackTimer = maxTimer; } }
protected Rectangle CanWallJump(WallMap wallMap) { Rectangle futureBoundingBox = new Rectangle((int)(BoundingBox.X + (1 * direction.X)), (int)(BoundingBox.Y + 4), (int)(BoundingBox.Width), (int)(BoundingBox.Height - 14)); return(wallMap.CheckCollision(futureBoundingBox)); }
protected Rectangle InDoor(WallMap wallMap) { Rectangle futureBoundingBox = new Rectangle((int)((BoundingBox.X)), (int)((BoundingBox.Y)), (int)(BoundingBox.Width), (int)(BoundingBox.Height)); return(wallMap.CheckForDoor(futureBoundingBox)); }
protected Rectangle AtBottomOfStairs(WallMap wallMap) { Rectangle futureBoundingBox = new Rectangle((int)((BoundingBox.X)), (int)((BoundingBox.Y + 20)), (int)(BoundingBox.Width), (int)(BoundingBox.Height - 20)); return(wallMap.StairCollision(futureBoundingBox)); }
public void ApplyGravity(WallMap wallMap) { if (isJumping == true || (OnGround(wallMap) == Rectangle.Empty && isJumping == false)) { velocity.Y += gravity; if (velocity.Y > terminalVelocity) { velocity.Y = terminalVelocity; } } }
private void Idle(WallMap wallMap) { //stop moving velocity.X = TendToZero(velocity.X, friction); velocity.Y = TendToZero(velocity.X, friction); //switch to walk if (playerLeft || playerRight || playerUp || playerDown) { PlayerState = State.walk; } }
public override void Update(List <GameObject> objects, WallMap wallMap, GameTime gametime) { if (timer > 0 && active == true) { timer--; CheckCollision(objects, wallMap); } else { active = false; } damageBoundingBox.X = (int)position.X; damageBoundingBox.Y = (int)position.Y; base.Update(objects, wallMap, gametime); }
private void Walk(WallMap wallMap) { //stop moving if (direction.X == 1) { MoveRight(); objectAnimated.Effect = SpriteEffects.None; } else { MoveLeft(); objectAnimated.Effect = SpriteEffects.FlipHorizontally; } velocity.X = TendToZero(velocity.X, friction); }
private void StateMachine(State playerState, List <GameObject> objects, WallMap wallMap) { switch (playerState) { case State.idle: Idle(wallMap); objectAnimated.Play("idle"); break; case State.walk: Walk(wallMap); objectAnimated.Play("walk"); break; default: PlayerState = State.idle; break; } }
protected Rectangle OneEdgeOfGround(WallMap wallMap) { if (direction.X == 1) { Rectangle futureBoundingBox = new Rectangle((int)((BoundingBox.X + BoundingBox.Width)), (int)((BoundingBox.Y + 1)), (int)(BoundingBox.Width), (int)(BoundingBox.Height)); return(wallMap.CheckCollision(futureBoundingBox)); } else { Rectangle futureBoundingBox = new Rectangle((int)((BoundingBox.X - BoundingBox.Width)), (int)((BoundingBox.Y) + (1)), (int)(BoundingBox.Width), (int)(BoundingBox.Height)); return(wallMap.CheckCollision(futureBoundingBox)); } }
private void WallAttack(List <GameObject> objects, WallMap wallMap) { velocity.Y -= 0.28f; if (attackTimer <= 0) { damageObject.position = position + new Vector2(0, 6) + (new Vector2(18, 0) * direction); damageObject.StartTimer(); damageObject.active = true; attackTimer = maxTimer; } damageObject.position = position + (new Vector2(18 + (Math.Abs(velocity.X) * 2), 0) * direction); if (isOnGround) { PlayerState = State.wallJump; isWallJumping = false; } }
private void CheckCollision(List <GameObject> objects, WallMap wallMap) { for (int i = 0; i < objects.Count; i++) { if (objects[i].objectType == "Enemy" && objects[i].CheckCollision(damageBoundingBox) == true) { if (objects[0].position.X > objects[i].BoundingBox.X) { objects[0].knockbackDir.X = 1; } else { objects[0].knockbackDir.X = -1; } active = false; objects[0].velocity.X = 0; objects[0].velocity = objects[i].knockback * objects[0].knockbackDir; objects[i].isHurt = true; } } }
// individual player states: private void Idle(WallMap wallMap) { //switch to walk if (playerLeft == true || playerRight == true) { PlayerState = State.walk; } //switch to jump if (playerJump == true && isJumping == false) { velocity.Y -= jumpHeight; PlayerState = State.jump; isJumping = true; } //switch to duck if (playerDown == true) { PlayerState = State.duck; } // climb stairs if contacting if (playerUp == true) { var stairTest = AtBottomOfStairs(wallMap); if (stairTest != Rectangle.Empty) { isOnStairs = true; PlayerState = State.stairs; } } if (playerDown == true) { var stairTest = AtTopOfStairs(wallMap); if ((stairTest != Rectangle.Empty) && (isOnGround)) { isOnStairs = true; PlayerState = State.stairs; } } }
public override void Update(List <GameObject> objects, WallMap wallMap, GameTime gametime) { if (HUD.canMove) { //Check Input PlayerInput(); //FSM Check StateMachine(PlayerState, objects, wallMap); base.Update(objects, wallMap, gametime); //are we in a door var testRectDoor = InDoor(wallMap); if (testRectDoor != Rectangle.Empty) { applyGravity = false; } } objectSprite.Position = position; objectAnimated.Update(gametime); }
private void Stairs(WallMap wallMap) { StairMaster(wallMap); if (direction.X < 0) { objectAnimated.Effect = SpriteEffects.FlipHorizontally; } else { objectAnimated.Effect = SpriteEffects.None; } //stop animating if not moving if (!playerUp && !playerDown && !playerLeft && !playerRight) { stopAnimating = true; } else { stopAnimating = false; } }
private void WallJump(WallMap wallMap) { //applyGravity = false; isWallJumping = false; velocity.Y -= 0.28f; isJumping = false; if (playerJump) { velocity.Y = 0; velocity.Y -= 5f; velocity.X -= jumpHeight / 4 * direction.X; PlayerState = State.jump; direction = -direction; isJumping = true; } // adjust facing direction if (playerLeft) { direction.X = -1; objectAnimated.Effect = SpriteEffects.FlipHorizontally; } if (playerRight) { direction.X = 1; objectAnimated.Effect = SpriteEffects.None; } if ((!playerRight && !playerLeft) || (CanWallJump(wallMap) == Rectangle.Empty) || (wallDir != (int)direction.X)) { PlayerState = State.fall; } if (isOnGround) { PlayerState = State.idle; } }
private void Fall(WallMap wallMap) { if (isOnGround == true) { isJumping = false; PlayerState = State.idle; } if (playerLeft == true) { MoveLeft(); } if (playerRight == true) { MoveRight(); } //walljump if (CanWallJump(wallMap) != Rectangle.Empty && (playerLeft || playerRight)) { wallDir = (int)direction.X; PlayerState = State.wallJump; velocity.Y = 0; } // climb stairs if contacting if (playerUp == true) { var stairTest = AtBottomOfStairs(wallMap); if (stairTest != Rectangle.Empty) { isOnStairs = true; jumpOnStairs = true; PlayerState = State.stairs; } } }
public override void Update(List <GameObject> objects, WallMap wallMap, GameTime gametime) { if (HUD.canMove) { //FSM Check StateMachine(EnemyState, objects, wallMap); base.Update(objects, wallMap, gametime); if (OneEdgeOfGround(wallMap) == Rectangle.Empty || position.X == previousX) { velocity.X = 0f; direction = -direction; } if (health <= 0) { objects.Remove(this); } } objectSprite.Position = position; objectAnimated.Update(gametime); previousX = position.X; }
public virtual void Update(List <GameObject> objects, WallMap wallMap, GameTime gametime) { }