Beispiel #1
0
        public void fireItem(Entity e, DirectionalComponent dir)
        {
            TimedShooterComponent timedShooterComp = ( TimedShooterComponent )e.getComponent(GlobalVars.TIMED_SHOOTER_COMPONENT_NAME);
            PositionComponent     posComp          = (PositionComponent)e.getComponent(GlobalVars.POSITION_COMPONENT_NAME);
            ShooterBullet         bullet           = new ShooterBullet(level, level.rand.Next(Int32.MinValue, Int32.MaxValue), posComp.x, posComp.y, dir.getDir(), timedShooterComp.state);
            VelocityComponent     bulletVel        = ( VelocityComponent )bullet.getComponent(GlobalVars.VELOCITY_COMPONENT_NAME);

            float bulletSpeed = 160.0f;

            if (dir.isUp())
            {
                bulletVel.setVelocity(0, -bulletSpeed);
            }
            else if (dir.isRight())
            {
                bulletVel.setVelocity(bulletSpeed, 0);
            }
            else if (dir.isDown())
            {
                bulletVel.setVelocity(0, bulletSpeed);
            }
            else if (dir.isLeft())
            {
                bulletVel.setVelocity(-bulletSpeed, 0);
            }
            level.addEntity(bullet);
        }