//Game state update method //Current order: Gameover?, Input, updates, collision, scrolling protected override void Update(GameTime gameTime) { //Pause-unpause /*if (gamestate == PGameState.Game && PCgamepad.GetState(PlayerIndex.One).Buttons.Start == ButtonState.Pressed) * { * startPressed = true; * } * else if (startPressed) * { * startPressed = false; * if (!paused) * { * paused = true; * } * else * { * paused = false; * } * }*/ if (gamestate == PGameState.Game && !paused) { levelTimeElapsed += gameTime.ElapsedGameTime.TotalSeconds; //Handle player death if (player.Plife <= 0) { paused = true; player.Plife = 100; processDeath(); paused = false; } //Checks controler/key input and respond as needed if (gamepadConnected) { processGamepadInput(); } else { processInput(); } //Update enemy roster //Currently enemies are not dynamically spawned, only removes dead enemies foreach (EnemySprite item in enemylist) { if (item.Life <= 0 || !(item.isAlive())) { if (item.explodes) { Explosion anExp = new Explosion(); anExp.position.X = item.bbox.Center.X - 50; anExp.position.Y = item.bbox.Center.Y - 50; enemylist.Add(anExp); } if (item.islevelboss) { EnemySprite lgoal = currentLevel.getDelayedLevelGoal(this.Content, item.position); enemylist.Add(lgoal); } enemylist.Remove(item); break; } } ArrayList newAttacks = null; foreach (EnemySprite item in enemylist) { newAttacks = item.getAttacks(player.position); if (newAttacks != null) { foreach (EnemySprite attack in newAttacks) { enemylist.Add(attack); } break; } } //Update attacks foreach (Attack item in pAttacks) { item.Update(gameTime, player); } //Update player sprite player.Update(gameTime, pAttacks); //Update enemies foreach (EnemySprite item in enemylist) { item.Update(gameTime, player.position); } //Update ground foreach (GroundSprite item in groundlist) { item.Update(gameTime); } //Checks for collisions and respond as needed processCollision(); //Scroll level processScrolling(); //Debug - position //Console.WriteLine("(" + levelloc.X + "," + levelloc.Y + ")"); base.Update(gameTime); } else if (gamestate == PGameState.Title) { if (gamepadConnected) { processGamepadInput(); } else { processInput(); } } else if (gamestate == PGameState.IntroScrn) { if (gamepadConnected) { processGamepadInput(); } else { processInput(); } } }
public void addEnemy(EnemySprite esprite) { enemies.Add(esprite); }