I am trying to make it so that when my main character collides with the chimney of the house, a new level begins. The new level being the inside of the house. My current working code is:
var vy:Number=0;
var jumped:Boolean=false;
var gv:Number=1;
addEventListener(Event.ENTER_FRAME,ctrl_hero);
stage.addEventListener(MouseEvent.CLICK, jump);
stage.addEventListener(Event.ENTER_FRAME, collide);
function ctrl_hero(e:Event) {
if (hero.x-20<mouseX) {
hero.x+=5;
}
if (hero.x+20>mouseX) {
hero.x-=5;
}
vy+=gv;
if (! level.hitTestPoint(hero.x,hero.y,true)) {
hero.y+=vy;
}
if (vy>10) {
vy=10;
}
for (var i:int = 0; i<10; i++) {
if (level.hitTestPoint(hero.x,hero.y,true)) {
hero.y--;
vy=0;
jumped=false;
}
}
}
function jump(e:Event) {
if (! jumped) {
hero.y-=5;
vy=-18;
jumped=true;
}
}
function collide(event:Event) {
if (hero.hitTestObject(knob)) {
errormsg.text="The Door Is Locked, Try a Different Tactic.";
} else {
errormsg.text="Welcome to your Birthday Game Dad!";
}
}
What I tried was to add a new function that is basically something like this
addEventListener(Event.ENTER_FRAME,chimney);
function chimney(event:Event) {
if (hero.hitTestObject(chimney)) {
gotoAndPlay(2)
} else {
gotoAndPlay(1)
}
}
When I try that I get a duplicate function error, so then I just put the function code with the other function code. So there would be 2 "if" statements, and 2 "else" statements. I am not sure what to do, maybe I am using the wrong code entirely? Any help would be appreciated.

New Topic/Question
Reply



MultiQuote



|