Ejemplo n.º 1
0
        public override void update()
        {
            //Player movement and controls
            player.Acceleration.X = 0;

            if (FlxG.keys.pressed(Keys.Left))
            {
                player.Acceleration.X = -player.MaxVelocity.X * 4;
            }
            if (FlxG.keys.pressed(Keys.Right))
            {
                player.Acceleration.X = player.MaxVelocity.X * 4;
            }

            if (FlxG.keys.pressed(Keys.Space) && player.isTouching(FlxObject.Floor))
            {
                player.Velocity.Y = -player.MaxVelocity.Y / 2;
            }

            if (FlxG.keys.justPressed(Keys.Escape))
            {
                onQuit();
            }


            //Updates all the objects appropriately
            base.update();

            //Check if player collected a coin or coins this frame
            FlxG.overlap(coins, player, getCoin);

            //Check to see if the player touched the exit door this frame
            FlxG.overlap(exit, player, win);

            FlxG.collide(level, player);

            //Check for player lose conditions
            if (player.Y > FlxG.height)
            {
                FlxG.score = 1;                 //sets status.text to "Aww, you died!"
                FlxG.resetState();
            }
        }
Ejemplo n.º 2
0
        public override void update()
        {
            //game restart timer
            if (!Alive)
            {
                _restart += FlxG.elapsed;
                if (_restart > 2)
                {
                    FlxG.resetState();
                }
                return;
            }

            //make a little noise if you just touched the floor
            if (justTouched(Floor) && (Velocity.Y > 50))
            {
                _sfxLand.play(true);
            }

            //MOVEMENT
            Acceleration.X = 0;
            if (FlxG.keys.pressed(Keys.Left) /*|| _pad.buttonLeft.status == FlxButton.Pressed*/)
            {
                Facing          = Left;
                Acceleration.X -= Drag.X;
            }
            else if (FlxG.keys.pressed(Keys.Right) /*|| _pad.buttonRight.status == FlxButton.Pressed*/)
            {
                Facing          = Right;
                Acceleration.X += Drag.X;
            }
            if (FlxG.keys.justPressed(Keys.X))
            {
                jump();
            }

            //AIMING
            if (FlxG.keys.pressed(Keys.Up) /*|| _pad.buttonUp.status == FlxButton.Pressed*/)
            {
                _aim = Up;
            }
            else if ((FlxG.keys.pressed(Keys.Down) /*|| _pad.buttonDown.status == FlxButton.Pressed*/) && Velocity.Y != 0)
            {
                _aim = Down;
            }
            else
            {
                _aim = Facing;
            }

            //ANIMATION
            if (Velocity.Y != 0)
            {
                if (_aim == Up)
                {
                    play("jump_up");
                }
                else if (_aim == Down)
                {
                    play("jump_down");
                }
                else
                {
                    play("jump");
                }
            }
            else if (Velocity.X == 0)
            {
                if (_aim == Up)
                {
                    play("idle_up");
                }
                else
                {
                    play("idle");
                }
            }
            else
            {
                if (_aim == Up)
                {
                    play("run_up");
                }
                else
                {
                    play("run");
                }
            }

            //SHOOTING
            if (FlxG.keys.pressed(Keys.C) /*|| _pad.buttonB.status == FlxButton.Pressed*/)
            {
                if (!_justShoot)
                {
                    if (flickering)
                    {
                        _sfxJam.play(true);
                    }
                    else
                    {
                        getMidpoint(_tagPoint);
                        ((Bullet)_bullets.recycle(typeof(Bullet))).shoot(_tagPoint, (int)_aim);
                        if (_aim == Down)
                        {
                            Velocity.Y -= 36;
                        }
                    }
                    _justShoot = true;
                }
            }
            else
            {
                _justShoot = false;
            }
        }