private void PlayerActionCheck2(User2ControlledSprite Player) { if (Keyboard.GetState().IsKeyDown(Keys.D)) { if (Player.GetOriginalCurrentFrame != playerRunFramePoint) { ChangeState2(Game.Content.Load<Texture2D>(@"Images/user2character"), playerRunFramePoint, playerRunSheetSize, false, Player); } } if (Keyboard.GetState().IsKeyUp(Keys.D) && prevKeyboard.IsKeyUp(Keys.D) == false) { if (Player.GetOriginalCurrentFrame != playerIdleFramePoint) { ChangeState2(Game.Content.Load<Texture2D>(@"Images/user2character"), playerIdleFramePoint, playerIdleSheetSize, false, Player); } } if (Keyboard.GetState().IsKeyDown(Keys.A)) { if (Player.GetOriginalCurrentFrame != playerRunFramePointRight) { ChangeState2(Game.Content.Load<Texture2D>(@"Images/user2character2"), playerRunFramePointRight, playerRunSheetSize, true, Player); } } if (Keyboard.GetState().IsKeyUp(Keys.A) && prevKeyboard.IsKeyUp(Keys.A) == false) { if (Player.GetOriginalCurrentFrame != playerIdleFramePointRight) { ChangeState2(Game.Content.Load<Texture2D>(@"Images/user2character2"), playerIdleFramePointRight, playerIdleSheetSize, true, Player); } } /* if (Keyboard.GetState().IsKeyDown(Keys.Space) && bulletTimeSinceLastSpawnChange > bulletCreateMilliseconds) { bulletTimeSinceLastSpawnChange = 0; BulletsCreate(); prevKeyboard = Keyboard.GetState(); } if (Keyboard.GetState().IsKeyDown(Keys.D1)) { ChangeBullet(Player.Bullet1); } if (Keyboard.GetState().IsKeyDown(Keys.D2) && Player.HadBullet2) { ChangeBullet(Player.Bullet2); } if (Keyboard.GetState().IsKeyDown(Keys.D3) && Player.HadBullet2) { ChangeBullet(Player.Bullet1); player.HadBullet2 = false; player.ResetSpeed(); }*/ }
private void ChangeState2(Texture2D Texture, Point FramePoint, Point sheetSize, Boolean right, User2ControlledSprite Player) { Player.TextImage = Texture; Player.GetOriginalCurrentFrame = FramePoint; Player.SheetSize = sheetSize; Player.IsRightCheck = right; prevKeyboard = Keyboard.GetState(); }
private void CheckCollisionsForBoards2(GameTime gameTime, User2ControlledSprite player) { Boolean hit = false; BroadsSprite b = broadsList[1]; //change the players rectangle to a bigger one Rectangle forPlayer = new Rectangle(player.collisionRect.X - 10, player.collisionRect.Y - 10, player.collisionRect.Width + 20, player.collisionRect.Height + 20); for (int i = 0; i < broadsList.Count; i++) { BroadsSprite b1 = broadsList[i]; if (b1.collisionRect.Intersects(forPlayer)) { if (player.FrameSize.Y >= b1.Position.Y - player.Position.Y && b1.Position.Y > player.Position.Y + 50) { hit = true; b = b1; } } } if (hit) { player.DownSpeed = 0; if (Keyboard.GetState().IsKeyDown(Keys.Up) && GetPlayerPosition().Y == b.Position.Y - player.FrameSize.Y + 1) { player.JumpSpeed = 10; player.JumpState = true; } else if ((player.JumpSpeed < 0 || player.JumpSpeed == 10) && player.FrameSize.Y >= b.Position.Y - player.Position.Y && b.Position.Y > player.Position.Y + 50) { player.Position = new Vector2(player.Position.X, b.Position.Y - player.FrameSize.Y + 1); player.JumpSpeed = 10; player.JumpState = false; } } else { if (!player.JumpState) { if (player.Position.Y < Game.Window.ClientBounds.Height - player.FrameSize.Y) { player.DownSpeed = player.DownSpeed - 0.8f; player.Position = new Vector2(player.Position.X, player.Position.Y - player.DownSpeed); } } } hit = false; }
protected override void LoadContent() { spriteBatch = new SpriteBatch(Game.GraphicsDevice); //load smoke image smokeflakes = Game.Content.Load<Texture2D>(@"images/smoke"); //create initial borads int x = 100, y = 100; for (int i = 1; i < broadCount; i++) { if (i == 5) { x -= 30; } broadsList.Add(new BroadsSprite( Game.Content.Load<Texture2D>(@"Images/broad"), new Vector2(x, y), new Point(100, 30), 0, new Point(0, 0), new Point(1, 1), Vector2.Zero, null, 0, 0.5f)); broadsList.Add(new BroadsSprite( Game.Content.Load<Texture2D>(@"Images/broad"), new Vector2(Game.Window.ClientBounds.Width - x, y), new Point(100, 30), 0, new Point(0, 0), new Point(1, 1), Vector2.Zero, null, 0, 0.5f)); x += 120; y += 80; } //load bullet image TextureForBullet1 = Game.Content.Load<Texture2D>(@"Images/skullball"); //create players player = new UserControlledSprite( Game.Content.Load<Texture2D>(@"Images/character"), new Vector2(Game.Window.ClientBounds.Width / 2, Game.Window.ClientBounds.Height - 64), new Point(64, 64), 10, playerIdleFramePoint, new Point(9, 1), new Vector2(6, 6), 30, false, "", 0); player2 = new User2ControlledSprite( Game.Content.Load<Texture2D>(@"Images/user2character"), new Vector2(20, Game.Window.ClientBounds.Height - 64), new Point(64, 64), 10, playerIdleFramePoint, new Point(9, 1), new Vector2(6, 6), 30, false, "", 0); //Life icon for (int i = 0; i < ((Game1)Game).NumberLivesRemaining; ++i) { int offset = 10 + i * 40; livesList.Add(new AutomatedSprite( Game.Content.Load<Texture2D>(@"images\threerings"), new Vector2(offset, 35), new Point(75, 75), 10, new Point(0, 0), new Point(6, 8), Vector2.Zero, null, 0, .5f)); } for (int i = 0; i < ((Game1)Game).NumberLivesRemaining2; ++i) { int offset = 950 - i * 40; livesList2.Add(new AutomatedSprite( Game.Content.Load<Texture2D>(@"images\threerings"), new Vector2(offset, 35), new Point(75, 75), 10, new Point(0, 0), new Point(6, 8), Vector2.Zero, null, 0, .5f)); } base.LoadContent(); }