private void HandleMouseInput() { if (Xin.CheckMouseReleased(MouseButton.Left)) { Point mouse = Xin.MouseAsPoint; if (leftSide.Contains(mouse)) { selectedItem--; if (selectedItem < 0) { selectedItem = this.Items.Count - 1; } OnSelectionChanged(); } if (rightSide.Contains(mouse)) { selectedItem++; if (selectedItem >= items.Count) { selectedItem = 0; } OnSelectionChanged(); } } }
public override void Update(GameTime gameTime) { menu.Update(gameTime); if (menu.MouseOver && Xin.CheckMouseReleased(MouseButton.Left)) { switch (menu.SelectedIndex) { case 0: IGamePlayState gamePlayState = (IGamePlayState)Game.Services.GetService( typeof(IGamePlayState)); gamePlayState.SetupNewGame(); manager.PushState((GameState)gamePlayState); break; case 1: break; case 2: manager.PushState(GameRef.OptionState); break; case 3: break; case 4: GameRef.Exit(); break; } } base.Update(gameTime); }
public override void HandleInput() { if (items.Count == 0) { return; } if (Xin.WasKeyReleased(Keys.Left)) { selectedItem--; if (selectedItem < 0) { selectedItem = this.Items.Count - 1; } OnSelectionChanged(); } if (Xin.WasKeyReleased(Keys.Right)) { selectedItem++; if (selectedItem >= items.Count) { selectedItem = 0; } OnSelectionChanged(); } }
public void Update(GameTime gameTime, TileMap map) { Vector2 motion = Vector2.Zero; if (Xin.IsKeyDown(Keys.Left)) { motion.X = -speed; } else if (Xin.IsKeyDown(Keys.Right)) { motion.X = speed; } if (Xin.IsKeyDown(Keys.Up)) { motion.Y = -speed; } else if (Xin.IsKeyDown(Keys.Down)) { motion.Y = speed; } if (motion != Vector2.Zero && map != null) { motion.Normalize(); position += motion * speed; LockCamera(map); } }
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) { if ((Xin.CheckMouseReleased(MouseButton.Left) && mouseOver) || Xin.CheckKeyRelease(Keys.Enter)) { manager.ChangeState(GameRef.MainMenuState); } 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); }
public Game1() { graphics = new GraphicsDeviceManager(this); graphics.PreferredBackBufferWidth = SCREEN_WIDTH; graphics.PreferredBackBufferHeight = SCREEN_HEIGHT; graphics.IsFullScreen = false; xinComponent = new Xin(this); Components.Add(xinComponent); Content.RootDirectory = "Content"; this.IsMouseVisible = false; //this.Components.Add(new GamerServicesComponent(this)); }
public override void Update(GameTime gameTime) { camera.Update(gameTime, world.CurrentMap); camera.LockCamera(world.CurrentMap); Vector2 motion = Vector2.Zero; if (Xin.IsKeyDown(Keys.S)) { motion.Y = 1; player.Sprite.IsAnimating = true; player.Sprite.CurrentAnimation = AnimationKey.WalkUp; } if (Xin.IsKeyDown(Keys.W)) { motion.Y = -1; player.Sprite.IsAnimating = true; player.Sprite.CurrentAnimation = AnimationKey.WalkDown; } if (Xin.IsKeyDown(Keys.A)) { motion.X = -1; player.Sprite.IsAnimating = true; player.Sprite.CurrentAnimation = AnimationKey.WalkLeft; } if (Xin.IsKeyDown(Keys.D)) { motion.X = 1; player.Sprite.IsAnimating = true; player.Sprite.CurrentAnimation = AnimationKey.WalkRight; } if (motion != Vector2.Zero) { motion.Normalize(); player.Sprite.Position += motion * player.Speed * (float)gameTime.ElapsedGameTime.TotalSeconds; player.Sprite.LockToMap(new Point(world.CurrentMap.WidthInPixels, world.CurrentMap.HeightInPixels)); camera.LockToSprite(player.Sprite, world.CurrentMap); } else { player.Sprite.IsAnimating = false; } 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 void Update(GameTime gameTime) { Vector2 menuPosition = position; Point p = Xin.MouseAsPoint; Vector2 scale = new Vector2( Settings.Resolution.X / 1280, Settings.Resolution.Y / 720); Rectangle buttonRect; mouseOver = false; for (int i = 0; i < menuItems.Count; i++) { buttonRect = new Rectangle( (int)menuPosition.X, (int)menuPosition.Y, texture.Width, texture.Height).Scale(scale); if (buttonRect.Contains(p)) { selectedIndex = i; mouseOver = true; } menuPosition.Y += texture.Height + 50; } if (!mouseOver && Xin.CheckKeyPress(Keys.Up)) { selectedIndex--; if (selectedIndex < 0) { selectedIndex = menuItems.Count - 1; } } else if (!mouseOver && Xin.CheckKeyPress(Keys.Down)) { selectedIndex++; if (selectedIndex > menuItems.Count - 1) { selectedIndex = 0; } } }
public override void HandleInput() { Point position = Xin.MouseAsPoint; Vector2 scale = new Vector2( Settings.Resolution.X / 1280, Settings.Resolution.Y / 720); Rectangle destination = new Rectangle( (int)position.X, (int)position.Y, background.Width, background.Height).Scale(scale); if (destination.Contains(position) && Xin.CheckMouseReleased(MouseButton.Left)) { OnClick(); } }
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 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 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) { 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 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 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 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) { _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 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); }
private void CheckKeys() { string newChar = ""; if (Xin.CheckKeyPress(Keys.A)) { newChar += "a"; } if (Xin.CheckKeyPress(Keys.B)) { newChar += "b"; } if (Xin.CheckKeyPress(Keys.C)) { newChar += "c"; } if (Xin.CheckKeyPress(Keys.D)) { newChar += "d"; } if (Xin.CheckKeyPress(Keys.E)) { newChar += "e"; } if (Xin.CheckKeyPress(Keys.F)) { newChar += "f"; } if (Xin.CheckKeyPress(Keys.G)) { newChar += "g"; } if (Xin.CheckKeyPress(Keys.H)) { newChar += "h"; } if (Xin.CheckKeyPress(Keys.I)) { newChar += "i"; } if (Xin.CheckKeyPress(Keys.J)) { newChar += "j"; } if (Xin.CheckKeyPress(Keys.K)) { newChar += "k"; } if (Xin.CheckKeyPress(Keys.L)) { newChar += "l"; } if (Xin.CheckKeyPress(Keys.M)) { newChar += "m"; } if (Xin.CheckKeyPress(Keys.N)) { newChar += "n"; } if (Xin.CheckKeyPress(Keys.O)) { newChar += "o"; } if (Xin.CheckKeyPress(Keys.P)) { newChar += "p"; } if (Xin.CheckKeyPress(Keys.Q)) { newChar += "q"; } if (Xin.CheckKeyPress(Keys.R)) { newChar += "r"; } if (Xin.CheckKeyPress(Keys.S)) { newChar += "s"; } if (Xin.CheckKeyPress(Keys.T)) { newChar += "t"; } if (Xin.CheckKeyPress(Keys.U)) { newChar += "u"; } if (Xin.CheckKeyPress(Keys.V)) { newChar += "v"; } if (Xin.CheckKeyPress(Keys.W)) { newChar += "w"; } if (Xin.CheckKeyPress(Keys.X)) { newChar += "x"; } if (Xin.CheckKeyPress(Keys.Y)) { newChar += "y"; } if (Xin.CheckKeyPress(Keys.Z)) { newChar += "z"; } if (Xin.CheckKeyPress(Keys.Back)) { if (text.Length != 0) { text = text.Remove(text.Length - 1); } } if (Xin.IsKeyDown(Keys.RightShift) || Xin.IsKeyDown(Keys.LeftShift)) { newChar = newChar.ToUpper(); } if (Xin.CheckKeyPress(Keys.Enter)) { canType = false; } text += newChar; }
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); }