package {
import flash.media.Sound;
import flash.display.MovieClip;
import flash.events.Event;
public class Main extends MovieClip {
var score = 0;
var health = 100;
var collectSound : Sound = new CollectSound();
public function Main(){
stage.addEventListener(Event.ENTER_FRAME, gameLoop);
stage.addChild(player);
gameOverScreen.visible = false;
winScreen.visible = false;
}
function gameLoop(evt:Event)
{
player.x = stage.mouseX;
player.y = stage.mouseY;
background.x = background.x - 7;
level.x = level.x - 7;
goal.x = goal.x - 7;
for(var i = 0; i < level.numChildren; i++)
{
if(level.getChildAt(i).name == "collectable" && player.hitTestObject(level.getChildAt(i)) && level.getChildAt(i).visible == true)
{
level.getChildAt(i).visible = false;
score += 10;
collectSound.play();
}
if(level.getChildAt(i).name == "enemy" && player.hitTestObject(level.getChildAt(i)) && level.getChildAt(i).visible == true){
level.getChildAt(i).visible = false;
health -= 20;
}
}
scoreDisplay.text = "Score: " + score;
healthDisplay.text = "Health: " + health;
if(player.x > goal.x && gameOverScreen.visible == false)
{
winScreen.visible = true;
}
if(health <= 0 && winScreen.visible == false)
{
gameOverScreen.visible = true;
}
}
}
}
No comments:
Post a Comment