public void createMissile(GameTime gameTime, Player objPlayer, List <missile> myMissiles) { TimeSpan timeScinceLastShot = gameTime.TotalGameTime - objPlayer.lastShot; if (timeScinceLastShot > objPlayer.shotCoolDown) { missile missile = new missile(); missile.playerNum = objPlayer.playerNum; if (left == true) { missile.Position = new Vector2(objPlayer.position.X, objPlayer.position.Y + objPlayer.texture.Height / 2 - 7); } else { missile.Position = new Vector2(objPlayer.position.X + objPlayer.texture.Width, objPlayer.position.Y + objPlayer.texture.Height / 2 - 7); } missile.rectangle = new Rectangle((int)objPlayer.position.X + objPlayer.texture.Width / 2, (int)objPlayer.position.Y + objPlayer.texture.Height / 2 - 10, 16, 16); missile.Rotation = 1.6f; Matrix missleRotationMatrix = Matrix.CreateRotationZ(missile.Rotation); if (left == true) { missile.Velocity = new Vector2(-10, 0); } else { missile.Velocity = new Vector2(10, 0); } missile.MaxLimit = new Vector2(2000, 2000); missile.MinLimit = new Vector2(-50, -50); missile.Size = new Vector2(6, 10); myMissiles.Add(missile); objPlayer.lastShot = gameTime.TotalGameTime; //soundShoot.Play(); } }
public void Input(GameTime gameTime, Keys moveLeft, Keys moveRight, Keys jump, Keys Shoot, Player playernumber, List <missile> myMissiles) { if (Dead == false) { if (Keyboard.GetState().IsKeyDown(moveRight)) { velocity.X = movementSpeed; flip = SpriteEffects.None; left = false; } else if (Keyboard.GetState().IsKeyDown(moveLeft)) { velocity.X = -movementSpeed; flip = SpriteEffects.FlipHorizontally; left = true; } else { velocity.X = 0f; } if (Keyboard.GetState().IsKeyDown(Shoot)) { createMissile(gameTime, playernumber, myMissiles); } if ((playerNum == 1 && Keyboard.GetState().IsKeyDown(jump) && hasJumped == false) || (playerNum == 2 && Keyboard.GetState().IsKeyDown(jump) && hasJumped == false)) { position.Y -= 9f; velocity.Y = -12f; hasJumped = true; timesJumped++; if (timesJumped < maxJumps) { JumpTimer.timer = 0.5f; } } if (JumpTimer.finished == true && timesJumped <= maxJumps) { hasJumped = false; } if ((playerNum == 1 && Keyboard.GetState().IsKeyDown(Keys.Space) && hasJumped == false) || (playerNum == 2 && Keyboard.GetState().IsKeyDown(Keys.NumPad0) && hasJumped == false)) { TimeSpan timeScinceLastShot = gameTime.TotalGameTime - lastShot; missile missile = new missile(); if (Keyboard.GetState().IsKeyDown(Shoot)) { if (timeScinceLastShot > shotCoolDown) { missile.Position = position; missile.Velocity = new Vector2(2, 0); missile.Size = new Vector2(16, 16); missile.Velocity = missile.Velocity + velocity; missile.MaxLimit = new Vector2(graphics.PreferredBackBufferWidth + 500, graphics.PreferredBackBufferHeight + 500); missile.MinLimit = new Vector2(-500, -500); myMissiles.Add(missile); lastShot = gameTime.TotalGameTime; } } } float i = 1; velocity.Y += 0.05f * i; } }