// Resets the game for another round. public void Reset() { // Reset the state state = boxingstate.roundstart; roundStartTimer = roundStartTime; numberOfPlayers = 0; // Reset the players for (int i = 0; i < 4; i++) { if (players[i] != null) { players[i].Reset(playerStartPositions[i]); numberOfPlayers++; } } Debug.WriteLine("num of players = " + numberOfPlayers); // reset item instances itemInstances.Clear(); deadCount = 0; isRoundOver = false; }
public bool Update(GameTime gameTime) { //camera.UpdateCamera(players.ToList<BoxingPlayer>(), graphicsDevice); switch (state) { // The idle state is just to display the background while the settings are configured. case(boxingstate.idle): // if animated background, update it. break; // Will display the "Round X, Begin!" animation. case(boxingstate.roundstart): if (roundStartTimer > 0) roundStartTimer -= (float)gameTime.ElapsedGameTime.TotalSeconds; else state = boxingstate.box; break; // Will handle all the logic for the boxing; player updates, collision, etc. case(boxingstate.box): foreach (ItemInstance item in itemInstances) { item.Update(gameTime); HandleCollisions(item); } for(int i = 0; i < 4; i++) { BoxingPlayer player = players[i]; if(player != null) { player.Update(gameTime); // keep them from going off the screen player.position.X = MathHelper.Clamp(player.position.X, bounds.Left + player.GetWidth / 2, bounds.Right - player.GetWidth / 2);//- (player.GetWidth / 2 - 15 * player.scale), bounds.Right - player.GetWidth / 2 - (player.GetWidth / 2 - 15 * player.scale)); HandleCollisions(i, gameTime); } } // Handle the winning if (winTimer > 0) winTimer -= (float)gameTime.ElapsedGameTime.TotalSeconds; if (deadCount >= numberOfPlayers - 1) { isRoundOver = true; winTimer = winTime; // Who's the winner? for (int i = 0; i < 4; i++) { if (players[i] != null && !players[i].isDead) { winner = i+1; } } state = boxingstate.roundend; restartTimer = restartTime; } break; case (boxingstate.roundend): if (currentRound == NumRounds) // this was the last round, show stats { Debug.WriteLine("Round {0} Complete!", currentRound); state = boxingstate.stats; } else // reset for next round { if (restartTimer > 0) { restartTimer -= (float)gameTime.ElapsedGameTime.TotalSeconds; } else { Debug.WriteLine("Round {0} Complete!", currentRound); currentRound++; Reset(); } } break; case (boxingstate.stats): Debug.WriteLine("A winner is you!"); return false; break; } return true; /* kb = Keyboard.GetState(); Players.Sort(); HandleCollisions(); foreach (BoxingPlayer player in Players) { //player.handleCollision(Players); if (player.InternalState is StateCharging) { player.handleCollision(Players); } player.update(gameTime); } List<ItemInstance> instancesToRemove = new List<ItemInstance>(); foreach (ItemInstance item in itemInstances) { item.Update(gameTime); if (item.end) instancesToRemove.Add(item); } for (int i = 0; i < instancesToRemove.Count; i++) itemInstances.Remove(instancesToRemove[i]); foreach (PlayerStatDisplay display in displays) { display.Update(); } //Switch to Menu by pressing R if (kb.IsKeyDown(Keys.R)) return true; else return false;*/ }
public Boxing_Manager(ContentManager content, Rectangle ClientBounds, Input_Handler[] inputs, GraphicsDevice gd, Camera camera) { this.graphicsDevice = gd; this.camera = camera; //camera = new Camera(ClientBounds); this.bounds = new Rectangle(0, 0, ClientBounds.Width, ClientBounds.Height); this.inputs = inputs; background = content.Load<Texture2D>("Boxing/AB Background"); font = content.Load<SpriteFont>("Menu/menufont"); blank = content.Load<Texture2D>("White"); #region Add StateNames StateNames.Add(smoving); StateNames.Add(sstopped); StateNames.Add(sjump); StateNames.Add(sattack1); StateNames.Add(sattack3); StateNames.Add(scasting); StateNames.Add(shit); StateNames.Add(sdead); #endregion #region ItemNames ItemNames.Add(cane); #endregion state = boxingstate.idle; level = new Level(this, ClientBounds, blank, background); for (int i = 0; i < 4; i++) playerStartPositions[i] = new Vector2(bounds.X + bounds.Width / 5 * (i + 1), level.platforms[level.platforms.Length - 1].Y); //level.platforms[level.platforms.Length - 1].Y = (int)playerStartPositions[0].Y; NumRounds = 1; itemInstances = new List<ItemInstance>(); healthBarDimensions = new Rectangle(0, 0, ClientBounds.Width / 16, ClientBounds.Height / 80); LoadContent(content); }