public override void Update(GameTime gameTime) { menuComponent.Update(gameTime); if (Xin.CheckKeyReleased(Keys.Space) || Xin.CheckKeyReleased(Keys.Enter) || (menuComponent.MouseOver && Xin.CheckMouseReleased(MouseButtons.Left))) { if (menuComponent.SelectedIndex == 0) { Xin.FlushInput(); GameRef.GamePlayState.SetUpNewGame(); GameRef.GamePlayState.StartGame(); manager.PushState((GamePlayState)GameRef.GamePlayState, PlayerIndexInControl); } else if (menuComponent.SelectedIndex == 1) { Xin.FlushInput(); GameRef.GamePlayState.LoadExistingGame(); GameRef.GamePlayState.StartGame(); manager.PushState((GamePlayState)GameRef.GamePlayState, PlayerIndexInControl); } else if (menuComponent.SelectedIndex == 2) { Xin.FlushInput(); } else if (menuComponent.SelectedIndex == 3) { Game.Exit(); } } base.Update(gameTime); }
public override void Update(GameTime gameTime) { PlayerIndex index = PlayerIndex.One; if (Xin.CheckKeyReleased(Keys.P)) { manager.PopState(); } base.Update(gameTime); }
public override void Update(GameTime gameTime) { PlayerIndex?index = null; elapsed += gameTime.ElapsedGameTime; if (Xin.CheckKeyReleased(Keys.Space) || Xin.CheckKeyReleased(Keys.Enter) || Xin.CheckMouseReleased(MouseButtons.Left)) { manager.ChangeState((MainMenuState)GameRef.StartMenuState, index); } base.Update(gameTime); }
public override void Update(GameTime gameTime) { _elapsed += gameTime.ElapsedGameTime; if (Xin.CheckKeyReleased(Keys.Space) || Xin.CheckKeyReleased(Keys.Enter) || Xin.CheckMouseReleased(MouseButtons.Left)) { Manager.ChangeState(GameRef.StartMenuState, null); } base.Update(gameTime); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } // show/hide fps counter if (Xin.CheckKeyReleased(Keys.F1)) { fpsCounter.IsVisible = !fpsCounter.IsVisible; } base.Update(gameTime); }
public override void Update(GameTime gameTime) { PlayerIndex index = PlayerIndex.One; // TODO elapsed += gameTime.ElapsedGameTime; menuComponent.Update(gameTime, index); this.player1pad = GamePad.GetState(PlayerIndex.One); if (Xin.CheckKeyReleased(Keys.Space) || Xin.CheckKeyReleased(Keys.Enter) || (menuComponent.MouseOver && Xin.CheckMouseReleased(MouseButtons.Left)) || this.player1pad.IsButtonDown(Buttons.A)) { buttonSelect.Play(); if (menuComponent.SelectedIndex == 0) // new single player game { Xin.FlushInput(); this.gameOptions.GameType = GameType.SinglePlayer; GameRef.GamePlayState.SetUpNewGame(this.gameOptions); GameRef.GamePlayState.StartGame(); manager.PushState((GamePlayState)GameRef.GamePlayState, PlayerIndexInControl); } else if (menuComponent.SelectedIndex == 1) // new 2 player cooperative game { Xin.FlushInput(); this.gameOptions.GameType = GameType.TwoPlayerCooperative; GameRef.GamePlayState.SetUpNewGame(this.gameOptions); GameRef.GamePlayState.StartGame(); manager.PushState((GamePlayState)GameRef.GamePlayState, PlayerIndexInControl); } else if (menuComponent.SelectedIndex == 2) // new 2 player deathmatch game { Xin.FlushInput(); this.gameOptions.GameType = GameType.TwoPlayerDeathmatch; GameRef.GamePlayState.SetUpNewGame(this.gameOptions); GameRef.GamePlayState.StartGame(); manager.PushState((GamePlayState)GameRef.GamePlayState, PlayerIndexInControl); } else if (menuComponent.SelectedIndex == 3) { Game.Exit(); } } base.Update(gameTime); }
public override void Update(GameTime gameTime) { PlayerIndex index = PlayerIndex.One; if (Xin.CheckKeyReleased(Keys.Space) || Xin.CheckKeyReleased(Keys.Enter)) { if (levelUp) { this.Visible = true; } else { manager.PopState(); manager.PopState(); } } base.Update(gameTime); }
public override void Update(GameTime gameTime) { PlayerIndex?index = null; elapsed += gameTime.ElapsedGameTime; if (Xin.CheckKeyReleased(Keys.Space)) { GameRef.GamePlayState.ResetGame(); manager.ChangeState((GamePlayState)GameRef.GamePlayState, index); } if (Xin.CheckKeyReleased(Keys.Escape)) { Game.Exit(); } base.Update(gameTime); }
public void Update(GameTime gameTime, PlayerIndex index) { if (Xin.CheckKeyReleased(Keys.Down)) { selectedIndex--; if (selectedIndex < 0) { selectedIndex = options.Count - 1; } } else if (Xin.CheckKeyReleased(Keys.Down)) { selectedIndex++; if (selectedIndex > options.Count - 1) { selectedIndex = 0; } } }
public override void Update(GameTime gameTime) { switch (connectionState) { case ConnectionState.SERVER_SELECT: serverSelectionMenuComponent.Update(gameTime); if (Xin.CheckKeyReleased(Keys.Space) || Xin.CheckKeyReleased(Keys.Enter) || (serverSelectionMenuComponent.MouseOver && Xin.CheckMouseReleased(MouseButtons.Left))) { if (serverSelectionMenuComponent.SelectedIndex == 0) { Xin.FlushInput(); ConnectToServer(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 2013)); //GameRef.GamePlayState.SetUpNewGame(); //GameRef.GamePlayState.StartGame(); //manager.PushState((GamePlayState)GameRef.GamePlayState, PlayerIndexInControl); } else if (serverSelectionMenuComponent.SelectedIndex == 1) { Xin.FlushInput(); GameRef.SetWindowResolution(400, 300); //ConnectToServer(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 2014)); //GameRef.GamePlayState.LoadExistingGame(); //GameRef.GamePlayState.StartGame(); //manager.PushState((GamePlayState)GameRef.GamePlayState, PlayerIndexInControl); } else if (serverSelectionMenuComponent.SelectedIndex == 2) { Game.Exit(); } } break; case ConnectionState.LOGIN: loginComponent.Update(gameTime); break; } base.Update(gameTime); }
public override void Update(GameTime gameTime) { PlayerIndex?index = PlayerIndex.One; if (Xin.CheckKeyReleased(Keys.Space) || Xin.CheckKeyReleased(Keys.Enter)) { if (levelUp) { manager.PushState((LevelUpState)GameRef.LevelUpState, PlayerIndexInControl); GameRef.LevelUpState.SetAvatar(player); this.Visible = true; } else { manager.PopState(); manager.PopState(); } } base.Update(gameTime); }
public override void Update(GameTime gameTime) { if (!this.doneOnce) { Song song = GameRef.ContentBank.GetSong(Content.ContentItem.Sounds_Song_Level); MediaPlayer.Volume = 0.8f; MediaPlayer.IsRepeating = false; MediaPlayer.Play(song); this.doneOnce = true; } PlayerIndex?index = null; elapsed += gameTime.ElapsedGameTime; if (Xin.CheckKeyReleased(Keys.Space) || Xin.CheckKeyReleased(Keys.Enter) || Xin.CheckMouseReleased(MouseButtons.Left)) { manager.ChangeState((MainMenuState)GameRef.StartMenuState, index); } base.Update(gameTime); }
public void Update(GameTime gameTime) { Vector2 menuPosition = position; Point p = Xin.MouseState.Position; Rectangle buttonRect; mouseOver = false; for (int i = 0; i < menuItems.Count; i++) { buttonRect = new Rectangle((int)(menuPosition.X * GameRef.ScaleMatrix.Scale.X), (int)(menuPosition.Y * GameRef.ScaleMatrix.Scale.Y), (int)(texture.Width * GameRef.ScaleMatrix.Scale.X), (int)(texture.Height * GameRef.ScaleMatrix.Scale.Y)); if (buttonRect.Contains(p)) { selectedIndex = i; mouseOver = true; } menuPosition.Y += texture.Height + menuSpacing; } if (!mouseOver && (Xin.CheckKeyReleased(Keys.Up))) { selectedIndex--; if (selectedIndex < 0) { selectedIndex = menuItems.Count - 1; } } else if (!mouseOver && (Xin.CheckKeyReleased(Keys.Down))) { selectedIndex++; if (selectedIndex > menuItems.Count - 1) { selectedIndex = 0; } } }
public void Update(GameTime gameTime) { usernameInput.Update(gameTime); passwordInput.Update(gameTime); if (Xin.CheckKeyReleased(Keys.Tab)) { if (!usernameInput.IsFocussed && !passwordInput.IsFocussed) { usernameInput.IsFocussed = true; } else { bool tempUserFocussed = usernameInput.IsFocussed; usernameInput.IsFocussed = passwordInput.IsFocussed; passwordInput.IsFocussed = tempUserFocussed; } } else if (Xin.CheckMouseReleased(MouseButtons.Left) || Xin.CheckKeyReleased(Keys.Enter)) { usernameInput.IsFocussed = false; passwordInput.IsFocussed = false; if (usernameInput.Text.Length == 0 || passwordInput.Text.Length == 0) { errorMessage = "Please fill in your credentials."; } else { errorMessage = ""; GameRef.GameSocketClient.LoginMessageReceived += GameSocketClient_Login; GameRef.GameSocketClient.SendMessage(new ClassLibrary.Packets.Client.cLogin() { Username = usernameInput.Text, Password = passwordInput.Text }); } } }
public override void Update(GameTime gameTime) { if (Xin.CheckKeyReleased(Keys.Space) || Xin.CheckKeyReleased(Keys.Enter)) { switch (conversation.CurrentScene.OptionAction.Action) { case ActionType.Buy: break; case ActionType.Change: speaker.SetConversation(conversation.CurrentScene.OptionScene); manager.PopState(); break; case ActionType.End: manager.PopState(); break; case ActionType.GiveItems: break; case ActionType.GiveKey: break; case ActionType.Quest: break; case ActionType.Sell: break; case ActionType.Talk: conversation.ChangeScene(conversation.CurrentScene.OptionScene); break; } } conversation.Update(gameTime); base.Update(gameTime); }
public override void Update(GameTime gameTime) { PlayerIndex?index = PlayerIndex.One; if (Xin.CheckKeyReleased(Keys.P)) { manager.PopState(); } combatScene.Update(gameTime, index.Value); if (Xin.CheckKeyReleased(Keys.Space) || Xin.CheckKeyReleased(Keys.Enter)) { manager.PushState((DamageState)GameRef.DamageState, index); GameRef.DamageState.SetAvatars(player, enemy); IMove enemyMove = null; do { int move = random.Next(0, enemy.KnownMoves.Count); int i = 0; foreach (string s in enemy.KnownMoves.Keys) { if (move == i) { enemyMove = (IMove)enemy.KnownMoves[s].Clone(); } i++; } } while (!enemyMove.Unlocked); GameRef.DamageState.SetMoves((IMove)player.KnownMoves[combatScene.OptionText].Clone(), enemyMove); GameRef.DamageState.Start(); player.Update(gameTime); enemy.Update(gameTime); } Visible = true; base.Update(gameTime); }
public override void Update(GameTime gameTime) { _menuComponent.Update(gameTime); if (Xin.CheckKeyReleased(Keys.Space) || Xin.CheckKeyReleased(Keys.Enter) || (_menuComponent.MouseOver && Xin.CheckMouseReleased(MouseButtons.Left))) { switch (_menuComponent.SelectedIndex) { case 0: Xin.FlushInput(); GameRef.GamePlayState.SetUpNewGame(); GameRef.GamePlayState.StartGame(); Manager.PushState(GameRef.GamePlayState, PlayerIndexInControl); break; case 1: Xin.FlushInput(); GameRef.GamePlayState.LoadExistingGame(); GameRef.GamePlayState.StartGame(); Manager.PushState(GameRef.GamePlayState, PlayerIndexInControl); break; case 2: Xin.FlushInput(); break; case 3: Game.Exit(); break; } } base.Update(gameTime); }
public void Update(GameTime gameTime) { var menuPos = Position; var p = Xin.MouseState.Position; MouseOver = false; for (var i = 0; i < _menuItems.Count; i++) { var buttonRect = new Rectangle((int)menuPos.X, (int)menuPos.Y, Texture.Width, Texture.Height); if (!buttonRect.Contains(p)) { continue; } _selectedIndex = i; MouseOver = true; } if (!MouseOver && (Xin.CheckKeyReleased(Keys.Up))) { _selectedIndex--; if (_selectedIndex < 0) { _selectedIndex = _menuItems.Count; } } else if (!MouseOver && (Xin.CheckKeyReleased(Keys.Down))) { _selectedIndex++; if (_selectedIndex > _menuItems.Count - 1) { _selectedIndex = 0; } } }
public override void Update(GameTime gameTime) { Vector2 motion = Vector2.Zero; int cp = 8; if (Xin.KeyboardState.IsKeyDown(Keys.W) && Xin.KeyboardState.IsKeyDown(Keys.A)) { motion.X = -1; motion.Y = -1; player.Sprite.CurrentAnimation = AnimationKey.WalkLeft; } else if (Xin.KeyboardState.IsKeyDown(Keys.W) && Xin.KeyboardState.IsKeyDown(Keys.D)) { motion.X = 1; motion.Y = -1; player.Sprite.CurrentAnimation = AnimationKey.WalkRight; } else if (Xin.KeyboardState.IsKeyDown(Keys.S) && Xin.KeyboardState.IsKeyDown(Keys.A)) { motion.X = -1; motion.Y = 1; player.Sprite.CurrentAnimation = AnimationKey.WalkLeft; } else if (Xin.KeyboardState.IsKeyDown(Keys.S) && Xin.KeyboardState.IsKeyDown(Keys.D)) { motion.X = 1; motion.Y = 1; player.Sprite.CurrentAnimation = AnimationKey.WalkRight; } else if (Xin.KeyboardState.IsKeyDown(Keys.W)) { motion.Y = -1; player.Sprite.CurrentAnimation = AnimationKey.WalkUp; } else if (Xin.KeyboardState.IsKeyDown(Keys.S)) { motion.Y = 1; player.Sprite.CurrentAnimation = AnimationKey.WalkDown; } else if (Xin.KeyboardState.IsKeyDown(Keys.A)) { motion.X = -1; player.Sprite.CurrentAnimation = AnimationKey.WalkLeft; } else if (Xin.KeyboardState.IsKeyDown(Keys.D)) { motion.X = 1; player.Sprite.CurrentAnimation = AnimationKey.WalkRight; } if (motion != Vector2.Zero) { motion.Normalize(); motion *= (player.Speed * (float)gameTime.ElapsedGameTime.TotalSeconds); Rectangle pRect = new Rectangle( (int)player.Sprite.Position.X + (int)motion.X + cp, (int)player.Sprite.Position.Y + (int)motion.Y + cp, Engine.TileWidth - cp, Engine.TileHeight - cp); foreach (string s in map.Characters.Keys) { ICharacter c = GameRef.CharacterManager.GetCharacter(s); Rectangle r = new Rectangle( (int)map.Characters[s].X * Engine.TileWidth + cp, (int)map.Characters[s].Y * Engine.TileHeight + cp, Engine.TileWidth - cp, Engine.TileHeight - cp); if (pRect.Intersects(r)) { motion = Vector2.Zero; break; } } Vector2 newPosition = player.Sprite.Position + motion; player.Sprite.Position = newPosition; player.Sprite.IsAnimating = true; player.Sprite.LockToMap(new Point(map.WidthInPixels, map.HeightInPixels)); } else { player.Sprite.IsAnimating = false; } camera.LockToSprite(map, player.Sprite, Game1.ScreenRectangle); player.Sprite.Update(gameTime); if (Xin.CheckKeyReleased(Keys.Space) || Xin.CheckKeyReleased(Keys.Enter)) { foreach (string s in map.Characters.Keys) { ICharacter c = CharacterManager.Instance.GetCharacter(s); float distance = Vector2.Distance(player.Sprite.Center, c.Sprite.Center); if (Math.Abs(distance) < 72f) { IConversationState conversationState = (IConversationState)GameRef.Services.GetService(typeof(IConversationState)); manager.PushState( (ConversationState)conversationState, PlayerIndexInControl); conversationState.SetConversation(player, c); conversationState.StartConversation(); } } } if (Xin.CheckKeyReleased(Keys.B)) { foreach (string s in map.Characters.Keys) { ICharacter c = CharacterManager.Instance.GetCharacter(s); float distance = Vector2.Distance(player.Sprite.Center, c.Sprite.Center); if (Math.Abs(distance) < 72f) { GameRef.BattleState.SetAvatars(player.CurrentAvatar, c.BattleAvatar); manager.PushState( (BattleState)GameRef.BattleState, PlayerIndexInControl); } } } base.Update(gameTime); }
public void Update(GameTime gameTime) { if (isFocussed) { elapsed += gameTime.ElapsedGameTime; if (text.Length > 0 && Xin.CheckKeyReleased(Keys.Back)) { text = text.Substring(0, text.Length - 1); } else if (maxLength == 0 || text.Length < maxLength) { bool upperCase = Xin.KeyboardState.IsKeyDown(Keys.LeftShift) || Xin.KeyboardState.IsKeyDown(Keys.RightShift) || Xin.KeyboardState.CapsLock; for (int keyValue = (int)Keys.A; keyValue <= (int)Keys.Z; keyValue++) { Keys key = (Keys)keyValue; if (Xin.CheckKeyReleased(key)) { string letter = key.ToString(); text += (upperCase ? letter : letter.ToLower()); return; } } if ((upperCase && Xin.CheckKeyReleased(Keys.D0)) || (Xin.KeyboardState.NumLock && Xin.CheckKeyReleased(Keys.NumPad0))) { text += "0"; } else if ((upperCase && Xin.CheckKeyReleased(Keys.D1)) || (Xin.KeyboardState.NumLock && Xin.CheckKeyReleased(Keys.NumPad1))) { text += "1"; } else if ((upperCase && Xin.CheckKeyReleased(Keys.D2)) || (Xin.KeyboardState.NumLock && Xin.CheckKeyReleased(Keys.NumPad2))) { text += "2"; } else if ((upperCase && Xin.CheckKeyReleased(Keys.D3)) || (Xin.KeyboardState.NumLock && Xin.CheckKeyReleased(Keys.NumPad3))) { text += "3"; } else if ((upperCase && Xin.CheckKeyReleased(Keys.D4)) || (Xin.KeyboardState.NumLock && Xin.CheckKeyReleased(Keys.NumPad4))) { text += "4"; } else if ((upperCase && Xin.CheckKeyReleased(Keys.D5)) || (Xin.KeyboardState.NumLock && Xin.CheckKeyReleased(Keys.NumPad5))) { text += "5"; } else if ((upperCase && Xin.CheckKeyReleased(Keys.D6)) || (Xin.KeyboardState.NumLock && Xin.CheckKeyReleased(Keys.NumPad6))) { text += "6"; } else if ((upperCase && Xin.CheckKeyReleased(Keys.D7)) || (Xin.KeyboardState.NumLock && Xin.CheckKeyReleased(Keys.NumPad7))) { text += "7"; } else if ((upperCase && Xin.CheckKeyReleased(Keys.D8)) || (Xin.KeyboardState.NumLock && Xin.CheckKeyReleased(Keys.NumPad8))) { text += "8"; } else if ((upperCase && Xin.CheckKeyReleased(Keys.D9)) || (Xin.KeyboardState.NumLock && Xin.CheckKeyReleased(Keys.NumPad9))) { text += "9"; } } } else { // when tabbing fast between inputboxes this will make sure the caret is visible on entry elapsed = gameTime.ElapsedGameTime; } }
public override void Update(GameTime gameTime) { if (!contentLoaded) { LoadContent(); } if (player1.Status == PlayerStatus.GameOver && (player2.Status == PlayerStatus.GameOver || player2.Status == PlayerStatus.Disabled)) { SetUpNewGame(this.gameOptions); StartGame(); return; } if (enemies.Count == 0) { level++; StartLevel(); return; } this.player1pad = GamePad.GetState(PlayerIndex.One); this.player2pad = GamePad.GetState(PlayerIndex.Two); targets.Clear(); if (Xin.CheckKeyReleased(Keys.M)) // MUTE/MUSIC { if (MediaPlayer.State == MediaState.Playing) { MediaPlayer.Pause(); } else { MediaPlayer.Resume(); } } if (Xin.CheckKeyReleased(Keys.R)) // RESTART { SetUpNewGame(this.gameOptions); } if (player1.Status == PlayerStatus.Resurrecting) { player1.Sprite.Position = arena.GetSafeSpawnPosition(player2, enemies, enemyListController.shots); } if (player2.Status == PlayerStatus.Resurrecting) { player2.Sprite.Position = arena.GetSafeSpawnPosition(player1, enemies, enemyListController.shots); } //--- Player 1 ---// if (player1.Status == PlayerStatus.Active) { player1.Sprite.CurrentAnimation = AnimationKey.Idle; if (player1.shotReloadTimeRemaining > 0) { player1.shotReloadTimeRemaining -= gameTime.ElapsedGameTime.Milliseconds; } if (Xin.KeyboardState.IsKeyDown(Keys.Left) || this.player1pad.ThumbSticks.Left.X < -0.2f) // rotate counterclockwise { player1.Sprite.Rotation -= 0.1f; } else if (Xin.KeyboardState.IsKeyDown(Keys.Right) || this.player1pad.ThumbSticks.Left.X > 0.2f) // rotate clockwise { player1.Sprite.Rotation += 0.1f; } if (Xin.KeyboardState.IsKeyDown(Keys.Up) || this.player1pad.Triggers.Left > 0.2f) // thrust { float xSpeed = player1.Sprite.Velocity.X + (float)Math.Sin(player1.Sprite.Rotation) / 8; float ySpeed = player1.Sprite.Velocity.Y - (float)Math.Cos(player1.Sprite.Rotation) / 8; if (Math.Abs(xSpeed) > player1.MaxSpeed) { xSpeed = player1.MaxSpeed * Math.Sign(xSpeed); } if (Math.Abs(ySpeed) > player1.MaxSpeed) { ySpeed = player1.MaxSpeed * Math.Sign(ySpeed); } player1.Sprite.Velocity = new Vector2(xSpeed, ySpeed); player1.Sprite.CurrentAnimation = AnimationKey.Thrusting; thrustSound.Play(); } if (Xin.KeyboardState.IsKeyDown(Keys.RightShift) || this.player1pad.Triggers.Right > 0.2f) // fire! { if (player1.shotReloadTimeRemaining <= 0) { // determine shot location at the nose of the ship Vector2 position = new Vector2(player1.Sprite.Position.X + (float)Math.Cos(player1.Sprite.Rotation - MathHelper.PiOver2) * 30, player1.Sprite.Position.Y + (float)Math.Sin(player1.Sprite.Rotation - MathHelper.PiOver2) * 30); Vector2 velocity = new Vector2((float)Math.Sin(player1.Sprite.Rotation) * 10, (float)Math.Cos(player1.Sprite.Rotation) * -10); Shot shot = new Shot(Game, position, velocity, 800, shotTexture, shotAnimations); player1shots.Add(shot); shotFireSound.Play(); player1.shotReloadTimeRemaining = player1.shotReloadTime; } } targets.Add(player1.Position); } //--- Player 2 ---// if (player2.Status == PlayerStatus.Active) { player2.Sprite.CurrentAnimation = AnimationKey.Idle; if (player2.shotReloadTimeRemaining > 0) { player2.shotReloadTimeRemaining -= gameTime.ElapsedGameTime.Milliseconds; } if (Xin.KeyboardState.IsKeyDown(Keys.A) || this.player2pad.ThumbSticks.Left.X < -0.2f) // rotate counterclockwise { player2.Sprite.Rotation -= 0.1f; } else if (Xin.KeyboardState.IsKeyDown(Keys.D) || this.player2pad.ThumbSticks.Left.X > 0.2f) // rotate clockwise { player2.Sprite.Rotation += 0.1f; } if (Xin.KeyboardState.IsKeyDown(Keys.W) || this.player2pad.Triggers.Left > 0.2f) // thrust { float xSpeed = player2.Sprite.Velocity.X + (float)Math.Sin(player2.Sprite.Rotation) / 8; float ySpeed = player2.Sprite.Velocity.Y - (float)Math.Cos(player2.Sprite.Rotation) / 8; if (Math.Abs(xSpeed) > player2.MaxSpeed) { xSpeed = player2.MaxSpeed * Math.Sign(xSpeed); } if (Math.Abs(ySpeed) > player2.MaxSpeed) { ySpeed = player2.MaxSpeed * Math.Sign(ySpeed); } player2.Sprite.Velocity = new Vector2(xSpeed, ySpeed); player2.Sprite.CurrentAnimation = AnimationKey.Thrusting; thrustSound.Play(); } if (Xin.KeyboardState.IsKeyDown(Keys.LeftShift) || this.player2pad.Triggers.Right > 0.2f) // fire! { if (player2.shotReloadTimeRemaining <= 0) { // determine shot location at the nose of the ship Vector2 position = new Vector2(player2.Sprite.Position.X + (float)Math.Cos(player2.Sprite.Rotation - MathHelper.PiOver2) * 30, player2.Sprite.Position.Y + (float)Math.Sin(player2.Sprite.Rotation - MathHelper.PiOver2) * 30); Vector2 velocity = new Vector2((float)Math.Sin(player2.Sprite.Rotation) * 10, (float)Math.Cos(player2.Sprite.Rotation) * -10); Shot shot = new Shot(Game, position, velocity, 800, shotTexture, shotAnimations); player2shots.Add(shot); shotFireSound.Play(); player2.shotReloadTimeRemaining = player2.shotReloadTime; } } targets.Add(player2.Position); } // check for collisions with arena walls and obstacles arena.CheckCollision(player1.Sprite, true); if (player2.Status == PlayerStatus.Active) { arena.CheckCollision(player2.Sprite, true); } enemies.ForEach(en => arena.CheckCollision(en.Sprite, true)); // check to see if the enemy got hit foreach (Shot shot in player1shots) { foreach (Enemy enemy in enemies) { if (shot.CheckCollision(enemy)) { player1.AddToScore(enemy.PointValue); } } } foreach (Shot shot in player2shots) { foreach (Enemy enemy in enemies) { if (shot.CheckCollision(enemy)) { player2.AddToScore(enemy.PointValue); } } } // check to see if the player got hit foreach (Shot shot in enemyListController.shots) { if (shot.CheckCollision(player1)) { player1.Status = PlayerStatus.Hit; } if ((player2.Status == PlayerStatus.Active) && (shot.CheckCollision(player2))) { player2.Status = PlayerStatus.Hit; } } if (this.gameOptions.GameType == GameType.TwoPlayerDeathmatch) { // see if the players hit each other foreach (Shot shot in player1shots) { if (shot.CheckCollision(player2)) { player2.Status = PlayerStatus.Hit; } } foreach (Shot shot in player2shots) { if (shot.CheckCollision(player1)) { player1.Status = PlayerStatus.Hit; } } } foreach (Enemy enemy in enemies) { if (player1.Status == PlayerStatus.Active && enemy.CheckCollision(player1.Sprite)) { player1.Status = PlayerStatus.Hit; enemy.Status = EnemyStatus.Hit; } if ((player2.Status == PlayerStatus.Active) && (enemy.CheckCollision(player2.Sprite))) { player2.Status = PlayerStatus.Hit; enemy.Status = EnemyStatus.Hit; } } enemyListController.shots.RemoveAll(shot => arena.CheckCollision(shot.Sprite, false)); enemyListController.shots.RemoveAll(shot => shot.Range <= 0); player1shots.RemoveAll(sh => arena.CheckCollision(sh.Sprite, false)); player1shots.RemoveAll(sh => sh.Range <= 0); player2shots.RemoveAll(sh => arena.CheckCollision(sh.Sprite, false)); player2shots.RemoveAll(sh => sh.Range <= 0); enemies.RemoveAll(en => en.Status == EnemyStatus.Dead); // update the game objects player1shots.ForEach(sh => sh.Update(gameTime)); player2shots.ForEach(sh => sh.Update(gameTime)); enemyListController.shots.ForEach(shot => shot.Update(gameTime)); enemyListController.Update(gameTime, targets); enemies.ForEach(en => en.Update(gameTime)); if ((player1.Status != PlayerStatus.Disabled) && (player1.Status != PlayerStatus.Dead)) { player1.Update(gameTime); } if ((player2.Status != PlayerStatus.Disabled) && (player2.Status != PlayerStatus.Dead)) { player2.Update(gameTime); } arena.Player1Score = player1.Score; arena.Player1Lives = player1.Lives; arena.Player2Lives = player2.Score; arena.Player2Lives = player2.Lives; //base.Update(gameTime); }
public override void Update(GameTime gameTime) { Vector2 motion = Vector2.Zero; int cp = 8; if (Xin.KeyboardState.IsKeyDown(Keys.W) && Xin.KeyboardState.IsKeyDown(Keys.A)) { motion.X = -1; motion.Y = -1; player.Sprite.CurrentAnimation = AnimationKey.WalkLeft; } else if (Xin.KeyboardState.IsKeyDown(Keys.W) && Xin.KeyboardState.IsKeyDown(Keys.D)) { motion.X = 1; motion.Y = -1; player.Sprite.CurrentAnimation = AnimationKey.WalkRight; } else if (Xin.KeyboardState.IsKeyDown(Keys.S) && Xin.KeyboardState.IsKeyDown(Keys.A)) { motion.X = -1; motion.Y = 1; player.Sprite.CurrentAnimation = AnimationKey.WalkLeft; } else if (Xin.KeyboardState.IsKeyDown(Keys.S) && Xin.KeyboardState.IsKeyDown(Keys.D)) { motion.X = 1; motion.Y = 1; player.Sprite.CurrentAnimation = AnimationKey.WalkRight; } else if (Xin.KeyboardState.IsKeyDown(Keys.W)) { motion.Y = -1; player.Sprite.CurrentAnimation = AnimationKey.WalkUp; } else if (Xin.KeyboardState.IsKeyDown(Keys.S)) { motion.Y = 1; player.Sprite.CurrentAnimation = AnimationKey.WalkDown; } else if (Xin.KeyboardState.IsKeyDown(Keys.A)) { motion.X = -1; player.Sprite.CurrentAnimation = AnimationKey.WalkLeft; } else if (Xin.KeyboardState.IsKeyDown(Keys.D)) { motion.X = 1; player.Sprite.CurrentAnimation = AnimationKey.WalkRight; } if (motion != Vector2.Zero) { motion.Normalize(); motion *= (player.Speed * (float)gameTime.ElapsedGameTime.TotalSeconds); Rectangle playerRect = new Rectangle( (int)player.Sprite.Position.X + (int)motion.X + cp, (int)player.Sprite.Position.Y + (int)motion.Y + cp, Engine.TileWidth - cp, Engine.TileHeight - cp); foreach (string characterName in world.CurrentMap.Characters.Keys) { ICharacter character = GameRef.CharacterManager.GetCharacter(characterName); Rectangle characterRect = new Rectangle( (int)world.CurrentMap.Characters[characterName].X * Engine.TileWidth + cp, (int)world.CurrentMap.Characters[characterName].Y * Engine.TileHeight + cp, Engine.TileWidth - cp, Engine.TileHeight - cp); // if player collides with character, stop their movement if (playerRect.Intersects(characterRect)) { motion = Vector2.Zero; break; } } Vector2 newPosition = player.Sprite.Position + motion; player.Sprite.Position = newPosition; player.Sprite.IsAnimating = true; player.Sprite.LockToMap(new Point(world.CurrentMap.WidthInPixels, world.CurrentMap.HeightInPixels)); } else { player.Sprite.IsAnimating = false; } camera.LockToSprite(world.CurrentMap, player.Sprite, Game1.ScreenRectangle); player.Sprite.Update(gameTime); if (Xin.CheckKeyReleased(Keys.Space) || Xin.CheckKeyReleased(Keys.Enter)) { foreach (string characterName in world.CurrentMap.Characters.Keys) { ICharacter character = CharacterManager.Instance.GetCharacter(characterName); float distance = Vector2.Distance(player.Sprite.Center, character.Sprite.Center); // if player is close to character if (Math.Abs(distance) < 72f) { // get the main game conversation state controller. one per game IConversationState conversationState = (IConversationState)GameRef.Services.GetService(typeof(IConversationState)); manager.PushState( (ConversationState)conversationState, PlayerIndexInControl); conversationState.SetConversation(player, character); conversationState.StartConversation(); } } foreach (Rectangle r in world.CurrentMap.PortalLayer.Portals.Keys) { Portal p = world.CurrentMap.PortalLayer.Portals[r]; float distance = Vector2.Distance( player.Sprite.Center, new Vector2( r.X * Engine.TileWidth + Engine.TileWidth / 2, r.Y * Engine.TileHeight + Engine.TileHeight / 2)); if (Math.Abs(distance) < 64f) { world.ChangeMap(p.DestinationLevel, new Rectangle(p.DestinationTile.X, p.DestinationTile.Y, 32, 32)); player.Position = new Vector2( p.DestinationTile.X * Engine.TileWidth, p.DestinationTile.Y * Engine.TileHeight); camera.LockToSprite(world.CurrentMap, player.Sprite, Game1.ScreenRectangle); return; } } } if (Xin.CheckKeyReleased(Keys.B)) { foreach (string s in world.CurrentMap.Characters.Keys) { ICharacter c = CharacterManager.Instance.GetCharacter(s); float distance = Vector2.Distance(player.Sprite.Center, c.Sprite.Center); if (Math.Abs(distance) < 72f && !c.Battled) { GameRef.BattleState.SetAvatars(player.CurrentAvatar, c.BattleAvatar); manager.PushState( (BattleState)GameRef.BattleState, PlayerIndexInControl); c.Battled = true; } } } // TODO: Save game data as json. Create GameSave class that has all necessary objects and serialize it. // F1 = Save Game // Produces: // avatar.sav // level1Lance,teacherone,WalkDown.Water,Water,0,100,1,9,12,10,50,-3,Tackle,Block*Marissa,teachertwo,WalkDown,MarissaHello,0-Wind,Wind,0,100,1,10,10,12,50,50,Tackle,Block.Earth,Earth,0,100,1,10,10,9,60,60,Tackle,Block if (Xin.CheckKeyReleased(Keys.F1)) { FileStream stream = new FileStream("avatars.sav", FileMode.Create, FileAccess.Write); BinaryWriter writer = new BinaryWriter(stream); world.Save(writer); player.Save(writer); writer.Close(); stream.Close(); } base.Update(gameTime); }
public override void Update(GameTime gameTime) { // used to calculate movement according to time passed, so that even when the loops run faster/slower the distance moved is still correct float delta = (float)gameTime.ElapsedGameTime.TotalSeconds; // release the ball to start playing if (!ballMoving && ((player1 is AIPlayer && player2 is AIPlayer) || Xin.CheckKeyReleased(GameRef.Settings.startRound))) { ballMoving = true; } // move the left paddle up and down HandlePlayerState(player1.GetState(ball, paddlePlayer1), paddlePlayer1, delta); HandlePlayerState(player2.GetState(ball, paddlePlayer2), paddlePlayer2, delta); /*if (Xin.KeyboardState.IsKeyDown(Keys.Z)) * { * float newPosition = player1.Position.Y - (delta * player1.Velocity.Y); * player1.Position.Y = (newPosition < 0 ? 0 : newPosition); * } * else if (Xin.KeyboardState.IsKeyDown(Keys.S)) * { * float newPosition = player1.Position.Y + (delta * player1.Velocity.Y); * int maxHeight = Pong.TargetHeight - player1.BoundingBox.Height; * player1.Position.Y = (newPosition > maxHeight ? maxHeight : newPosition); * }*/ /*if (Xin.KeyboardState.IsKeyDown(Keys.Up)) * { * float newPosition = player2.Position.Y - (delta * player2.Velocity.Y); * player2.Position.Y = (newPosition < 0 ? 0 : newPosition); * } * else if (Xin.KeyboardState.IsKeyDown(Keys.Down)) * { * float newPosition = player2.Position.Y + (delta * player2.Velocity.Y); * int maxHeight = Pong.TargetHeight - player2.BoundingBox.Height; * player2.Position.Y = (newPosition > maxHeight ? maxHeight : newPosition); * }*/ if (ballMoving) { particleEngine.EmitterLocation = new Vector2(ball.BoundingBox.Center.X, ball.BoundingBox.Center.Y); particleEngine.Update(delta); ball.Position += ball.Velocity * delta; // all positions are calculated using their position float values instead of the boundingbox rounded int values for accuracy // ball <> player collision if (ball.BoundingBox.Intersects(paddlePlayer1.BoundingBox) && ball.Velocity.X < 0) { ball.Velocity.X *= -1; float collisionDepth = paddlePlayer1.Position.X + paddlePlayer1.BoundingBox.Width - ball.Position.X; ball.Position.X += collisionDepth * 2; } else if (ball.BoundingBox.Intersects(paddlePlayer2.BoundingBox) && ball.Velocity.X > 0) { ball.Velocity.X *= -1; float collisionDepth = ball.Position.X + ball.BoundingBox.Width - paddlePlayer2.Position.X; ball.Position.X -= collisionDepth * 2; } // ball <> top/bottom screen collision if (ball.BoundingBox.Top <= 0 && ball.Velocity.Y < 0) { ball.Velocity.Y *= -1; ball.Position.Y *= -1; } else if (ball.BoundingBox.Bottom >= Pong.TargetHeight && ball.Velocity.Y > 0) { ball.Velocity.Y *= -1; float collisionDepth = ball.Position.Y + ball.BoundingBox.Height - Pong.TargetHeight; ball.Position.Y -= collisionDepth * 2; } // update score if (ball.Position.X <= 0) { ballMoving = false; ball.Position = BallCenterPosition; scoreBoard.Player2Scored(); ResetPaddles(); particleEngine.RemoveAllParticles(); } else if (ball.Position.X >= Pong.TargetWidth) { ballMoving = false; ball.Position = BallCenterPosition; scoreBoard.Player1Scored(); ResetPaddles(); particleEngine.RemoveAllParticles(); } } base.Update(gameTime); }
public override void Update(GameTime gameTime) { PlayerIndex index = PlayerIndex.One; int i = 0; string attribute = ""; if (Xin.CheckKeyReleased(Keys.Down)) { selected++; if (selected >= attributes.Count) { selected = attributes.Count - 1; } } else if (Xin.CheckKeyReleased(Keys.Up)) { selected--; if (selected < 0) { selected = 0; } } if (Xin.CheckKeyReleased(Keys.Space) || Xin.CheckKeyReleased(Keys.Enter)) { if (selected == 4 && points == 0) { foreach (string s in assignedTo.Keys) { player.AssignPoint(s, assignedTo[s]); } manager.PopState(); manager.PopState(); manager.PopState(); return; } } int increment = 1; if (Xin.CheckKeyReleased(Keys.Right) && points > 0) { foreach (string s in assignedTo.Keys) { if (s == "Done") { return; } if (i == selected) { attribute = s; break; } i++; } if (attribute == "Health") { increment *= 5; } points--; assignedTo[attribute] += increment; if (points == 0) { selected = 4; } } else if (Xin.CheckKeyReleased(Keys.Left) && points <= 3) { foreach (string s in assignedTo.Keys) { if (s == "Done") { return; } if (i == selected) { attribute = s; break; } i++; } if (assignedTo[attribute] != attributes[attribute]) { if (attribute == "Health") { increment *= 5; } points++; assignedTo[attribute] -= increment; } } base.Update(gameTime); }