So... I'm working on a game, where the essential gameplay element is that you walk through a maze with a flashlight, and when you reach the end, the game goes to a "story frame" basically just text, and a button to play the next level.
The only problem is... i can't seem to destroy everything at the end of the frame, and then i get all sorts of errors and it wont run, I am trying to do all the code in the .fla so i can set up the game on screen instead of with coordinates and addChild, etc in the code.
can anyone help/have any suggestions
ActionScript Code:
stop();
var player_speed:int=2;
var up,down,left,right:Boolean=false;
var radius:int=8;
addEventListener(Event.ENTER_FRAME,on_enter_frame);
stage.addEventListener(KeyboardEvent.KEY_DOWN, on_key_down);
stage.addEventListener(KeyboardEvent.KEY_UP, on_key_up);
function on_enter_frame(e:Event):void {
if (up) {
player_mc.y-=player_speed;
}
if (down) {
player_mc.y+=player_speed;
}
if (left) {
player_mc.x-=player_speed;
}
if (right) {
player_mc.x+=player_speed;
}
if (player_mc.hitTestObject(next_mc)) {
gotoAndStop(2);
removeEventListener(Event.ENTER_FRAME,on_enter_frame);
stage.removeEventListener(KeyboardEvent.KEY_DOWN, on_key_down);
stage.removeEventListener(KeyboardEvent.KEY_UP, on_key_up);
/*removeChild(player_mc);
removeChild(next_mc);
removeChild(environment_mc);
removeChild(light_mc);*/
}
while (environment_mc.hitTestPoint(player_mc.x, player_mc.y+radius, true)) {
player_mc.y--;
}
while (environment_mc.hitTestPoint(player_mc.x, player_mc.y-radius, true)) {
player_mc.y++;
}
while (environment_mc.hitTestPoint(player_mc.x-radius, player_mc.y, true)) {
player_mc.x++;
}
while (environment_mc.hitTestPoint(player_mc.x+radius, player_mc.y, true)) {
player_mc.x--;
}
var dist_x:Number=player_mc.x-mouseX;
var dist_y:Number=player_mc.y-mouseY;
var angle:Number=- Math.atan2(dist_x,dist_y);
player_mc.rotation=to_degrees(angle);
light_mc.x=player_mc.x;
light_mc.y=player_mc.y;
light_mc.rotation=to_degrees(angle);
}
function on_key_down(e:KeyboardEvent):void {
switch (e.keyCode) {
case 37 :
left=true;
break;
case 38 :
up=true;
break;
case 39 :
right=true;
break;
case 40 :
down=true;
break;
}
}
function on_key_up(e:KeyboardEvent):void {
switch (e.keyCode) {
case 37 :
left=false;
break;
case 38 :
up=false;
break;
case 39 :
right=false;
break;
case 40 :
down=false;
break;
}
}
function to_radians(n:Number):Number {
return (n*0.0174532925);
}
function to_degrees(n:Number):Number {
return (n*57.2957795);
}