Example #1
0
        public override void input(RenderWindow _window)
        {
            if (Keyboard.IsKeyPressed(Keyboard.Key.A))
            {
                if (mPosition.X > 0)
                {
                    mBody.ApplyLinearImpulse(new Vector2(-0.3f * Delta.mDelta, 0f));
                }
                else
                {
                    mBody.ApplyLinearImpulse(new Vector2(0.3f * Delta.mDelta, 0f));
                }
            }
            else if (Keyboard.IsKeyPressed(Keyboard.Key.D))
            {
                if (mPosition.Y < 1280)
                {
                    mBody.ApplyLinearImpulse(new Vector2(0.3f * Delta.mDelta, 0f));
                }
                else
                {
                    mBody.ApplyLinearImpulse(new Vector2(-0.3f * Delta.mDelta, 0f));
                }
            }

            if (Keyboard.IsKeyPressed(Keyboard.Key.Return))
            {
                if (!mOnce)
                {
                    invincible();
                }
            }

            if (Keyboard.IsKeyPressed(Keyboard.Key.Space))
            {
                if (mPosition.X > 0 && mPosition.X < 1280)
                {
                    mBody.ApplyLinearImpulse(new Vector2(0f, -0.9f * Delta.mDelta));
                }
            }

            if (Mouse.IsButtonPressed(Mouse.Button.Left))
            {
                if (mShoot.ElapsedMilliseconds > 250)
                {
                    Vector2i mousePos   = Mouse.GetPosition(_window);
                    Vector2f translated = _window.MapPixelToCoords(mousePos, _window.GetView());
                    Vector2f aim        = new Vector2f(translated.X - mPosition.X, translated.Y - mPosition.Y);
                    double   angle      = Math.Atan2(aim.Y, aim.X);

                    mWorld.createBullet(mPosition, this, "resources/bullet.png", angle);
                    mShoot.Restart();
                }
            }
        }
Example #2
0
        public override void update(RenderWindow _window)
        {
            //base.update(_window);
            if (mHealth == 0)
            {
                destroy();
            }

            if (mState == AIState.Chase)
            {
                chase();
            }

            if (mDie.ElapsedMilliseconds > 30000)
            {
                mWorld.createBullet(mPosition, this, "resources/fire.png", 0);
                mWorld.createBullet(mPosition, this, "resources/fire.png", 45);
                mWorld.createBullet(mPosition, this, "resources/fire.png", 90);
                mWorld.createBullet(mPosition, this, "resources/fire.png", 135);
                mWorld.createBullet(mPosition, this, "resources/fire.png", 180);
                mWorld.createBullet(mPosition, this, "resources/fire.png", 225);
                mWorld.createBullet(mPosition, this, "resources/fire.png", 275);
                mWorld.createBullet(mPosition, this, "resources/fire.png", 315);
                mWorld.createBullet(mPosition, this, "resources/fire.png", 0);
                mWorld.createBullet(mPosition, this, "resources/fire.png", 12);
                mWorld.createBullet(mPosition, this, "resources/fire.png", 33);
                mWorld.createBullet(mPosition, this, "resources/fire.png", 135);
                mWorld.createBullet(mPosition, this, "resources/fire.png", 25);
                mWorld.createBullet(mPosition, this, "resources/fire.png", 200);
                mWorld.createBullet(mPosition, this, "resources/fire.png", 128);
                mWorld.createBullet(mPosition, this, "resources/fire.png", 357);
                mWorld.createBullet(mPosition, this, "resources/fire.png", 23);
                mWorld.createBullet(mPosition, this, "resources/fire.png", 368);
                mWorld.createBullet(mPosition, this, "resources/fire.png", 54);
                mWorld.createBullet(mPosition, this, "resources/fire.png", 262);
                mWorld.createBullet(mPosition, this, "resources/fire.png", 231);
                mWorld.createBullet(mPosition, this, "resources/fire.png", 123);
                mWorld.createBullet(mPosition, this, "resources/fire.png", 324);
                destroy();
            }

            if (mTimer.ElapsedMilliseconds > 2000)
            {
                mWorld.createBullet(mPosition, this, "resources/fire.png", 0);
                mWorld.createBullet(mPosition, this, "resources/fire.png", 45);
                mWorld.createBullet(mPosition, this, "resources/fire.png", 90);
                mWorld.createBullet(mPosition, this, "resources/fire.png", 135);
                mWorld.createBullet(mPosition, this, "resources/fire.png", 180);
                mWorld.createBullet(mPosition, this, "resources/fire.png", 225);
                mWorld.createBullet(mPosition, this, "resources/fire.png", 275);
                mWorld.createBullet(mPosition, this, "resources/fire.png", 315);
                mTimer.Restart();
            }

            addPosition(mMovement.X, mMovement.Y);
            mBody.Position = ConvertUnits.ToSimUnits(mPosition.X, mPosition.Y);
        }