Followers

Monday, March 30, 2015

Flash Mobile: Enemy Scroll and Collect Collectable Code

Below is Actionscript 3 code that once is input into your Actions Frame in Flash will allow your player character to move with the mouse, collect an object and the enemy will scroll from right to left.

(Originally published 2/11/15)


import flash.events.Event;
stage.addEventListener(Event.ENTER_FRAME, gameLoop);
stage.addChild(player);

var score = 0;
var health = 0;

player.x = stage.mouseX;
player.y = stage.mouseY;

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

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

        if(player.hitTestObject(enemy) && enemy.visible == true)
        {
     health = health - 5;
              enemy.visible = false;
        }

if(player.hitTestObject(collectable) && collectable.visible == true)
        {
     score = score +1;
              collectable.visible = false;
        }

        scoreDisplay.text = "Score:" + score;
        healthDisplay.text = "Health:" + health;

}

No comments:

Post a Comment