public void getSetMissile() { missile.reset(); missile.active = false; missile.setPos(player.getPosX(), player.getPosY()); exLimSound.playSoundIfOk(); explostionTimer = 0; }
public void UpdateEE(GameTime gameTime) { // is it better to decrement the alpha or the rgb values? ltCol.R--; ltCol.G--; ltCol.B--; ltCol.A--; if (lives == 0 && ltCol.R == 0) { eeSound.playSoundIfOk(); } if (ltCol.R == 0) { state = 0; } showII = false; }
//Adds explosion to particle list public void AddExplosion(int x, int y) { float scale = 0.6f; float xOffset = -10; float yOffset = -5; Sprite3 newExplosion = new Sprite3(true, explosionTex, x + xOffset, y + yOffset); newExplosion.setXframes(7); newExplosion.setYframes(3); newExplosion.setWidthHeight(896 / 7 * scale, 384 / 3 * scale); Vector2[] anim = new Vector2[21]; anim[0].X = 0; anim[0].Y = 0; anim[1].X = 1; anim[1].Y = 0; anim[2].X = 2; anim[2].Y = 0; anim[3].X = 3; anim[3].Y = 0; anim[4].X = 4; anim[4].Y = 0; anim[5].X = 5; anim[5].Y = 0; anim[6].X = 6; anim[6].Y = 0; anim[7].X = 0; anim[7].Y = 1; anim[8].X = 1; anim[8].Y = 1; anim[9].X = 2; anim[9].Y = 1; anim[10].X = 3; anim[10].Y = 1; anim[11].X = 4; anim[11].Y = 1; anim[12].X = 5; anim[12].Y = 1; anim[13].X = 6; anim[13].Y = 1; anim[14].X = 0; anim[14].Y = 2; anim[15].X = 1; anim[15].Y = 2; anim[16].X = 2; anim[16].Y = 2; anim[17].X = 3; anim[17].Y = 2; anim[18].X = 4; anim[18].Y = 2; anim[19].X = 5; anim[19].Y = 2; anim[20].X = 6; anim[20].Y = 2; newExplosion.setAnimationSequence(anim, 0, 20, 2); newExplosion.setAnimFinished(2); // make it inactive and invisible newExplosion.animationStart(); particleList.addSpriteReuse(newExplosion); soundExplosionLimit.playSoundIfOk(); }
public void UpdateL2(GameTime gameTime) { // the crazy dog will be running towards the right and will // appear randomly on the screen crazyDog.visible = true; crazyDog.moveByDeltaXY(); crazyDog.animationTick(gameTime); crazyDog.active = true; doggyVec.X++; crazyDog.setPosX(doggyVec.X); if (crazyDog.getPosX() > 800) { doggyVec.X = 0; } if (doggyVec.X == 20 || doggyVec.X == 400) { barkoSound.playSoundIfOk(); } // check whether the player sprite has clashed with the crazy dog colWBB = playerSprite.collision(crazyDog); // play the sound if this is true if (colWBB == true && doggyVec.X == playerVec.X) { yowlinSound.playSoundIfOk(); lives--; } // play the kaching sound if the player sprite passes over // the dog and also does not colide if (colWBB == false && doggyVec.X == playerVec.X) { kachingSound.playSoundIfOk(); points++; } ks = Keyboard.GetState(); // this is really bad practice to repeat code from another method // but have no time right now to implement something better if (ks.IsKeyDown(Keys.Left)) { playerSprite.moveByDeltaXY(); playerSprite.animationTick(gameTime); successSound.playSoundIfOk(); playerSprite.active = true; background.Update(gameTime); } if (ks.IsKeyDown(Keys.Right)) { // NOTE: the move right functionality does not work currently background.Update(gameTime); } if (ks.IsKeyDown(Keys.B)) { showBB = !showBB; } /// increases the player's jump speed - this is a secret function if (ks.IsKeyDown(Keys.Z)) { playerJumpSpeed++; } // decreases the player's jump speed - this is another secret function if (ks.IsKeyDown(Keys.X)) { playerJumpSpeed--; } // this gives the small kitty cat the ability to jump around the screen if (playerJump) { playerVec.Y += playerJumpSpeed; playerJumpSpeed += 1; playerSprite.setPosY(playerVec.Y); if (playerVec.Y >= prevPos.Y) { playerSprite.setPosY(prevPos.Y); playerJump = false; } } else { if (ks.IsKeyDown(Keys.Up)) { playerJump = true; playerJumpSpeed = -14; jumpoSound.playSoundIfOk(); playerSprite.setPosY(playerVec.Y); } } // transition to end of game if user reaches 5 pts if (points == 5) { state = 6; } if (lives == 0) { state = 7; } }
public void UpdateL1(GameTime gameTime) { ks = Keyboard.GetState(); yarnBalls.moveDeltaXY(); // collision test for (int i = 0; i < yarnBalls.count(); i++) { Sprite3 s = yarnBalls.getSprite(i); bool coll = playerSprite.collision(s); if (coll) { kachingSound.playSoundIfOk(); s.setActive(false); points++; } } // used to move the kitty cat to the left if (ks.IsKeyDown(Keys.Left)) { playerSprite.moveByDeltaXY(); playerSprite.animationTick(gameTime); successSound.playSoundIfOk(); playerSprite.active = true; background.Update(gameTime); } if (ks.IsKeyDown(Keys.Right)) { // NOTE: the move right functionality does not work currently background.Update(gameTime); } if (ks.IsKeyDown(Keys.B)) { showBB = !showBB; } /// increases the player's jump speed - this is a secret function if (ks.IsKeyDown(Keys.Z)) { playerJumpSpeed++; } // decreases the player's jump speed - this is another secret function if (ks.IsKeyDown(Keys.X)) { playerJumpSpeed--; } // this gives the small kitty cat the ability to jump around the screen if (playerJump) { playerVec.Y += playerJumpSpeed; playerJumpSpeed += 1; playerSprite.setPosY(playerVec.Y); if (playerVec.Y >= prevPos.Y) { playerSprite.setPosY(prevPos.Y); playerJump = false; } } else { if (ks.IsKeyDown(Keys.Up)) { playerJump = true; jumpoSound.playSoundIfOk(); playerJumpSpeed = -14; playerSprite.setPosY(playerVec.Y); } } // transition over to level 2 if (points == 5) { state = 3; } }
public override void Update(GameTime gameTime) { //deltaTime is in seconds, so calculations = pixels per second. deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds; //Press enter to start game/level switch (levelState) { case LEVELSTATE.LEVELSTART: if (InputManager.Instance.KeyPressed(Keys.Enter)) { levelState = LEVELSTATE.LEVELPLAY; } return; case LEVELSTATE.LEVELPLAY: timer += deltaTime; //update player player.Update(gameTime); //PAUSE if (InputManager.Instance.KeyPressed(Keys.P)) { gameStateManager.pushLevel(3); } //PLAYER SHOOT if (InputManager.Instance.KeyPressed(Keys.Space)) { AddBullet((int)player.getPosX(), (int)player.getPosY()); soundBulletLimit.playSoundIfOk(); } break; case LEVELSTATE.LEVELFINISH: player.Update(gameTime); if (InputManager.Instance.KeyPressed(Keys.Enter)) { gameStateManager.pushLevel(1); } break; case LEVELSTATE.LEVELGAMEOVER: timer += deltaTime; if (InputManager.Instance.KeyPressed(Keys.Q)) { gameStateManager.setLevel(4); } break; default: throw new Exception("hahaha"); } //Every 2 seconds, spawn an enemy randomly. if (timer > spawnInterval && enemyCounter < enemyToSpawn) { AddEnemy(enemyList); timer = 0; enemyCounter++; } //update backgrounds scrollBack.Update(gameTime); scrollFore.Update(gameTime); scrollBack.setScrollSpeed(player.playerBackgroundSpeed - 2); scrollFore.setScrollSpeed(player.playerBackgroundSpeed); //Update/remove enemies enemyList.Update(gameTime); enemyList.removeIfOutside(new Rectangle(-100, -100, Game1.SCREEN_WIDTH + 200, Game1.SCREEN_HEIGHT + 200)); if (enemyList.countActive() == 0 && enemyCounter >= enemyToSpawn) { levelState = LEVELSTATE.LEVELFINISH; } //update/remove bullets playerBulletList.moveDeltaX(5); playerBulletList.removeIfOutside(new Rectangle(-100, -100, Game1.SCREEN_WIDTH + 200, Game1.SCREEN_HEIGHT + 200)); //If player collides with enemy int collisionIndex = enemyList.collisionAA(player); if (collisionIndex != -1) { Sprite3 temp = enemyList.getSprite(collisionIndex); //player collides with boss if (temp.getName() == "boss") { } else { //enemy dies? temp.active = false; temp.visible = false; AddExplosion((int)temp.getPosX(), (int)temp.getPosY()); score -= 5; textScore.text = "Score : " + score.ToString(); player.TakeDamage(); if (player.hitPoints <= 0) { levelState = LEVELSTATE.LEVELGAMEOVER; AddExplosion((int)player.getPosX(), (int)player.getPosY()); player.setPos(0, -300); // offscreen player.setActive(false); } //TODO: GET HITSOUND soundEnemyHitLimit.playSoundIfOk(); } } //if a bullet collides with enemy for (int i = 0; i < playerBulletList.count(); i++) { Sprite3 currentBullet = playerBulletList.getSprite(i); if (currentBullet == null) { continue; } if (currentBullet.active != true) { continue; } if (currentBullet.visible != true) { continue; } //if collision success int collision = enemyList.collisionAA(currentBullet); if (collision != -1) { Sprite3 currentEnemy = enemyList.getSprite(collision); currentEnemy.hitPoints -= 1; //DEAD ENEMY if (currentEnemy.hitPoints <= 0) { currentEnemy.active = false; currentEnemy.visible = false; //add particle AddExplosion((int)currentEnemy.getPosX(), (int)currentEnemy.getPosY()); //add score score += 10; textScore.text = "Score : " + score.ToString(); } //DAMAGED ENEMY else { currentEnemy.varInt0 = 100; soundEnemyHitLimit.playSoundIfOk(); } //REMOVE BULLET currentBullet.active = false; currentBullet.visible = false; } } //update particles particleList.animationTick(gameTime); base.Update(gameTime); }
public override void Update(GameTime gameTime) { prevKeyState = keyState; keyState = Keyboard.GetState(); timer += 1; explostionTimer += 1; explosionAnimation.animationTick(gameTime); mineExplostionAnimation.animationTick(gameTime); missileSmoke.Update(gameTime); exLimSound.Update(gameTime); previousMouseState = currentMouseState; currentMouseState = Mouse.GetState(); mouse_x = currentMouseState.X; mouse_y = currentMouseState.Y; // Sets up mine if (currentMouseState.LeftButton == ButtonState.Pressed) { minePos.X = mouse_x; minePos.Y = mouse_y; drawMines = true; mine.active = true; mineCount = 1; } // Controls player movements if (keyState.IsKeyDown(Keys.Left)) { if (player.getPosX() > Dir.leftBoundary) { player.setPosX(player.getPosX() - 4); // Moves player 3 units left player.setFlip(SpriteEffects.FlipHorizontally); } } if (keyState.IsKeyDown(Keys.Right)) { if (player.getPosX() < (Dir.rightBoundary - (player.getWidth() - 5))) { player.setPosX(player.getPosX() + 4); // Moves player 3 units right player.setFlip(SpriteEffects.None); } } // Moves enemy sprite enemy1.setPosX(enemy1.getPosX() + Dir.rnd.Next(1, 3)); enemy2.setPosX(enemy2.getPosX() - Dir.rnd.Next(1, 3)); // If enemy runs off screen, reset position to random x postion if (enemy1.getPosX() > Dir.rightBoundary + 60) { enemy1.setPos(Dir.rnd.Next(-400, -250), Dir.rnd.Next(200, 700)); } if (enemy2.getPosX() < Dir.leftBoundary - (enemy2.getWidth() + 50)) { enemy2.setPos(Dir.rnd.Next(Dir.rightBoundary, Dir.rightBoundary + 200), Dir.rnd.Next(200, 700)); } // Shoot missile if (keyState.IsKeyDown(Keys.Space) && prevKeyState.IsKeyUp(Keys.Space)) { missile.setPos(player.getPosX() + player.getWidth() / 2, player.getPosY() - missile.getHeight()); missile.active = true; drawSmoke(); drawMissile = true; if (missileCount > 0) { missileCount--; } } if (missileCount == 0) { missileCount = 5; } if (missile.getPosY() < 185 + missile.getHeight()) { missile.setPos(player.getPos()); drawMissile = false; missileSmoke.deActivate(); } if (timer % 361 == 360) { anchor.setPos(enemy1.getPosX() + enemy1.getWidth() / 2, enemy1.getPosY() + enemy1.getHeight() / 2); anchorDraw = true; } if (anchor.getPosY() > Dir.bottomBoundary + anchor.getHeight()) { anchor.active = false; anchorDraw = false; } // Collision Control enemy1Collision = missile.collision(enemy1); enemy2Collision = missile.collision(enemy2); if (enemy1Collision) { enemy1.hitPoints = enemy1.hitPoints - 10; currXMissile = enemy1.getPosX() + enemy1.getWidth() / 2; currYMissile = enemy1.getPosY() - enemy1.getHeight() / 2; if (enemy1.hitPoints <= 0) { collision1 = true; enemy1.hitPoints = 10; Dir.enemy1Count++; missileSmoke.deActivate(); } getSetMissile(); } if (enemy2Collision) { missileSmoke.deActivate(); enemy2.hitPoints = enemy2.hitPoints - 10; drawMissile = false; if (enemy2.hitPoints <= 0) { currXMissile = enemy2.getPosX() + enemy2.getWidth() / 2; currYMissile = enemy2.getPosY() - enemy2.getHeight() / 2; collision2 = true; Dir.enemy2Count++; enemy2.hitPoints = 20; } getSetMissile(); } // Gain 10 hp if missile hits the anchor preserve bool lifeGain = missile.collision(life); if (lifeGain == true) { if (player.hitPoints < 50) { player.hitPoints = player.hitPoints + 10; } lifeGain = false; drawMissile = false; life.active = false; life.setPos(new Vector2(Dir.rnd.Next(250, 800), Dir.rnd.Next(400, 600))); missile.active = false; missile.setPos(player.getPosX(), player.getPosY()); missileSmoke.deActivate(); } bool anchorCollision = anchor.collision(player); if (anchorCollision) { anchorDraw = false; anchor.setActiveAndVisible(false); anchor.setPos(new Vector2(-100, -100)); player.hitPoints = player.hitPoints - 20; } mineCollission = mine.collision(enemy1); if (mineCollission) { mine.active = false; drawMines = false; mineCurrPos = mine.getPos(); mine.setPos(new Vector2(-100, 0)); enemy1.setPos(Dir.rnd.Next(-400, -250), Dir.rnd.Next(200, 700)); mineCollisionToggle = true; score += 150; mineCount = 0; Dir.enemy1Count += 1; exLimSound.playSoundIfOk(); } mineCollission2 = mine.collision(enemy2); if (mineCollission2) { mine.active = false; drawMines = false; mineCurrPos = mine.getPos(); mine.setPos(new Vector2(-100, 0)); enemy2.setPos(Dir.rnd.Next(-400, -250), Dir.rnd.Next(200, 700)); mineCollisionToggle2 = true; score += 200; mineCount = 0; Dir.enemy2Count += 1; exLimSound.playSoundIfOk(); } // Toggle BB if (keyState.IsKeyDown(Keys.B) && prevKeyState.IsKeyUp(Keys.B)) { showBB = !showBB; } // Pause if (keyState.IsKeyDown(Keys.P) && !prevKeyState.IsKeyDown(Keys.P)) { gameStateManager.pushLevel(3); } // Help State if (keyState.IsKeyDown(Keys.F1) && !prevKeyState.IsKeyDown(Keys.F1)) { gameStateManager.pushLevel(5); } if (player.hitPoints < 0) { player.hitPoints = 0; } // End State if (score >= 1000 || player.hitPoints <= 0) { if (timer % 181 == 180) { gameStateManager.setLevel(4); } } }