Exemplo 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();
            }
        }
Exemplo n.º 2
0
        override public void update()
        {
            // collide everything
            FlxG.collide();

            //player 1 controls
            player1.Acceleration.X = 0;

            if (FlxG.keys.pressed(Keys.Left))
            {
                player1.Acceleration.X = -player1.MaxVelocity.X * 4;
            }
            if (FlxG.keys.pressed(Keys.Right))
            {
                player1.Acceleration.X = player1.MaxVelocity.X * 4;
            }
            if (FlxG.keys.justPressed(Keys.Up) && player1.isTouching(FlxObject.Floor))
            {
                player1.Velocity.Y -= (float)(player1.MaxVelocity.Y / 1.5);
            }

            //player 2 controls
            player2.Acceleration.X = 0;

            if (FlxG.keys.pressed(Keys.A))
            {
                player2.Acceleration.X = -player2.MaxVelocity.X * 4;
            }
            if (FlxG.keys.pressed(Keys.D))
            {
                player2.Acceleration.X = player2.MaxVelocity.X * 4;
            }
            if (FlxG.keys.justPressed(Keys.W) && player2.isTouching(FlxObject.Floor))
            {
                player2.Velocity.Y -= (float)(player2.MaxVelocity.Y / 1.5);
            }
            if (FlxG.keys.justPressed(Keys.Escape))
            {
                onQuit();
            }

            base.update();
        }