Followers

Thursday, April 16, 2015

Flash: Mobile Mouse Control Code

This code uses Mouse Control for Player.
The enemy and collectable object will slowly scroll across the screen.




import flash.events.Event;

stage.addEventListener(Event.ENTER_FRAME, gameLoop);
stage.addChild(player);
player.x = stage.mouseX;
player.y = stage.mouseY;
var score = 0;
var health = 10;

function gameLoop(evt:Event)
{
player.x  = stage.mouseX;
player.y  = stage.mouseY;

enemy.x = enemy.x - 1;
collectable.x = collectable.x - 3;


// IF THE PLAYER HITS THE COLLECTABLE

if(player.hitTestObject(collectable) && collectable.visible == true)

{
collectable.visible = false;
score = score + 1;
}

scoreDisplay.text = "Score: " + score;

//IF THE PLAYER HITS THE ENEMY

if(player.hitTestObject(enemy) && enemy.visible == true)

{
enemy.visible = false;
health = health - 1;
}

healthDisplay.text = "Health: " + health;
}

No comments:

Post a Comment