public int CheckDamageCollision(Level level, Player player) { for (int i = 0; i < level.damageRec.Count; i++) { if (player.playerRecBottom.Intersects(level.damageRec[i])) { return i; } } return -1; }
public int CheckObjectCollision(Level level, Player player) { for (int i = 0; i < level.objectRec.Count; i++) { if (player.playerRecRight.Intersects(level.objectRec[i])) { Rectangle r = level.objectRec[i]; r.Y = 5000; level.objectRec[i] = r; return i; } } return -1; }
public string checkEnemyLevelCollision(Enemy enemy, Level level) { string collision = ""; foreach (Rectangle rectangle in level.levelRec) { if (enemy.enemyRecRight.Intersects(rectangle)) { collision += "Right"; } if (enemy.enemyRecLeft.Intersects(rectangle)) { collision += "Left"; } if (enemy.enemyRecBottom.Intersects(rectangle)) { collision += "Bottom"; } } return collision; }
public void updateHeight(Collision collision, Level level) { if (!collision.checkEnemyLevelCollision(this, level).Contains("Bottom")) { if (airVelocity <= 15) { airVelocity += 0.5f; } location = new Vector2(location.X, location.Y + airVelocity); } }
public bool Move(Player player, Collision collision, Level level, GameTime gameTime, PlayerAnimations playerAnimations) { if (!Recoil(player)) { if (location.X + enemyTex[currentFrame].Width < player.location.X) { if (!collision.checkEnemyLevelCollision(this, level).Contains("Right")) { direction = 1; location.X += 5; animateMove(gameTime); lastAttack = gameTime.TotalGameTime - TimeSpan.FromSeconds(0.5); return false; } } if (location.X > player.location.X + playerAnimations.playerTex[playerAnimations.currentframe].Width) { if (!collision.checkEnemyLevelCollision(this, level).Contains("Left")) { direction = 0; location.X -= 5; animateMove(gameTime); lastAttack = gameTime.TotalGameTime -TimeSpan.FromSeconds(0.5); return false; } } return true; } return false; }
public void DrawLoadingScreen(SpriteBatch sprite, Level level) { sprite.Begin(); if (level.currentLevel == 0) { sprite.Draw(achtergrond[2], new Vector2(0, 0), Color.White); } if (level.currentLevel == 1) { sprite.Draw(achtergrond[3], new Vector2(0, 0), Color.White); } if (level.currentLevel == 2) { sprite.Draw(achtergrond[4], new Vector2(0, 0), Color.White); } sprite.End(); }
public string checkPlayerLevelCollision(PlayerAnimations animation, Player player, Level level) { string collision = ""; foreach (Rectangle rectangle in level.levelRec) { if (player.playerRecRight.Intersects(rectangle)) { collision += "Right"; } if (player.playerRecLeft.Intersects(rectangle)) { collision += "Left"; } if (player.playerRecBottom.Intersects(rectangle)) { collision += "Bottom"; } } return collision; }
public void UpdateHeight(PlayerAnimations animation, Level level, Collision collision) { if (jumping && allowJump) { if (grounded) { velocity = 15f; } grounded = false; location = new Vector2(location.X, location.Y - velocity); velocity -= 0.5f; if (velocity <= 0) { jumping = false; allowJump = false; } } else { if (grounded) { velocity = 1f; } if (!collision.checkPlayerLevelCollision(animation, this, level).Contains("Bottom")) { if (velocity <= 15) { velocity += 0.5f; } location = new Vector2(location.X, location.Y + velocity); allowJump = false; grounded = false; } else { grounded = true; allowJump = true; } } }
public bool MoveToCenter(PlayerAnimations animation, Level level) { if (!screenLocked) { int center = GlobalVars.resolutionWidth / 2 - animation.playerTex[animation.currentframe].Width; if (location.X > center) { location -= new Vector2(GlobalVars.playerSpeed, 0); level.MoveLevel(1); } if (location.X < center) { location += new Vector2(GlobalVars.playerSpeed, 0); level.MoveLevel(-1); } if (location.X == center) { return true; } return false; } return true; }
public void MoveRight(PlayerAnimations animation, Level level, GameTime gameTime, Collision collision) { if (!collision.checkPlayerLevelCollision(animation, this, level).Contains("Right")) { animation.BotState = PlayerAnimations.BottomAnimationState.Walking; if (!screenLocked) { level.MoveLevel(1); } else { if (location.X < GlobalVars.resolutionWidth - animation.playerTex[animation.currentframe].Width) { location += new Vector2(GlobalVars.playerSpeed, 0); } } } }
public void MoveLeft(PlayerAnimations animation, Level level, GameTime gameTime, Collision collision) { if (level.location > 0) { if (!collision.checkPlayerLevelCollision(animation, this, level).Contains("Left")) { animation.Moving(gameTime); if (!screenLocked) { level.MoveLevel(-1); } else { if (location.X > 0) { location -= new Vector2(GlobalVars.playerSpeed, 0); } } } } }
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); font = Content.Load<SpriteFont>(@"Arial"); playerAnimations = new PlayerAnimations(Content); playerInterface = new Interface(Content); player = new Player(playerAnimations); keyboardInput = new KeyboardInput(); database = new DatabaseClass(); collision = new Collision(); enemies = new List<Enemy>(); level = new Level(Content); menu = new Menu(Content); text = new Text(); GlobalVars.currentState = GlobalVars.gameState.mainMenu; }