예제 #1
0
파일: SuperPj.cs 프로젝트: AlexRex/2DGame
 public virtual void Shoot(int direction)
 {
     if (character.Ammunition > 0)
     {
         Projectile proj = new Projectile();
         proj.Initialize(Position, direction, projectileTexture, character.Strength, con);
         projectiles.Add(proj);
         character.Ammunition--;
     }
 }
예제 #2
0
파일: Player.cs 프로젝트: AlexRex/2DGame
        private void handleInput(GameTime gameTime)
        {
            var kbState = Keyboard.GetState();

            if (kbState.IsKeyDown(Keys.Left))
            {
                this.Position.X -= character.Speed;
                shootDirection = 1;
                con.Update();
            }

            if (kbState.IsKeyDown(Keys.Right))
            {
                this.Position.X += character.Speed;
                shootDirection = 0;
                con.Update();

            }

            if (kbState.IsKeyDown(Keys.Up))
            {
                this.Position.Y -= character.Speed;
                shootDirection = 2;
                con.Update();

            }

            if (kbState.IsKeyDown(Keys.Down))
            {
                this.Position.Y += character.Speed;
                shootDirection = 3;
                con.Update();

            }

            if (kbState.IsKeyDown(Keys.Space) && oldState.IsKeyUp(Keys.Space))
            {
                if (character.Ammunition > 0)
                {
                    Projectile proj = new Projectile();
                    proj.Initialize(Position, shootDirection, projectileTexture, character.Strength, con);
                    projectiles.Add(proj);
                    character.Ammunition--;
                }

                con.Shoot(shootDirection);

            }

            oldState = kbState;

              this.Position.X = MathHelper.Clamp(this.Position.X, character.Width / 2,
                graphicsDevice.Viewport.Width - 32 - (character.Width / 2));
            this.Position.Y = MathHelper.Clamp(this.Position.Y, character.Height / 2,
                graphicsDevice.Viewport.Height - 32 - (character.Height / 2));
        }