SunsetHigh.Hero.shoot C# (CSharp) Method

shoot() public method

Causes the Hero to create a projectile and fire it in the direction he is facing; Hero is then responsible for updating and drawing this projectile
public shoot ( ) : void
return void
        public void shoot()
        {
            if (canShoot)
            {
                int x = 0;
                int y = 0;
                if (this.getDirection().Equals(Direction.North))
                    y = -this.getHeight() / 2;
                if (this.getDirection().Equals(Direction.South))
                    y = this.getHeight() / 2;
                if (this.getDirection().Equals(Direction.East))
                    x = this.getWidth() / 2;
                if (this.getDirection().Equals(Direction.West))
                    x = -this.getWidth() / 2;

                Projectile bullet = new Projectile(this.getX() + x, this.getY() + y, 300.0f, this.getDirection());
                bullet.setImage(Sprite.getCommonImage(PROJECTILE_IMAGE_NAME));
                bullet.addCollideEvent(new ProjectileCollideEvent(heroBulletCollideEvent));
                WorldManager.enqueueObjectToCurrentRoom(bullet);

                canShoot = false;
                shootTimer = 0.0f;
            }
        }

Usage Example

Ejemplo n.º 1
0
 /// <summary>
 /// Handles Hero's "weapon" ability; call this method in the Game's update cycle (AFTER
 /// calling KeyboardManager.update())
 /// </summary>
 /// <param name="character">The main character</param>
 public static void handleShooting(Hero hero)
 {
     if (KeyboardManager.isKeyPressed(keyTypes[(int)KeyInputType.Shoot]))
     {
         hero.shoot();
     }
 }