ForumsProgramming ForumMaze Game

42 12771
Maaron
offline
Maaron
47 posts
Nomad

Hey everyone,

I'm making a maze game but I'm having a bit of trouble. When you hit the walls you are sent to a different frame where it tells you that you have lost, here is the code for that:

if (Wall.hitTest(Player._x, Player._y, true)) {
gotoAndStop(2);
}

That works fine, it's just the restart button I can't get working, I click on it and nothing happens, here is the code:

Retry.onRelease = function() {
gotoAndStop(1);
}

I have no idea why it won't work, please help me.

  • 42 Replies
Maaron
offline
Maaron
47 posts
Nomad

Sorry forgot to post a link, here it is:
[url=http://spamtheweb.com/ul/upload/3308/65512_Maze_Game.swf]

jpx111
offline
jpx111
264 posts
Nomad

its a wild guess, but shouldn't the second gotoAndStop be gotoAndPlay?...

TROJANS
offline
TROJANS
372 posts
Nomad

yup i think jpx111 is right

IQAndreas
offline
IQAndreas
299 posts
Peasant

Perhaps you should try putting the frame that says you have lost on a different layer, and have it revealed by action script instead.

This will most likely solve the problem.

Maaron
offline
Maaron
47 posts
Nomad

I've already tried that, it still doesn't work with gotoAndPlay.

jpx111
offline
jpx111
264 posts
Nomad

ok well, try putting it on a different scene...this way, its foolproof

dank
offline
dank
983 posts
Peasant

try _root.Retry; or put the code directly on the button.

Maaron
offline
Maaron
47 posts
Nomad

OK, I'll try all of these, thanks.

Gfitz07
offline
Gfitz07
203 posts
Nomad

Im making a game like this but the walls you can touch and a guy is chasing you. ther are also traps. I cant think up of a name though.

IQAndreas
offline
IQAndreas
299 posts
Peasant

@Gfitz07:
Perhaps give the main player or the enemy a name, and then name the game after the player.

Or, you could have something unoriginal but easy to remember like "Maze Runner". :-P

Captain_J_Sheridan
offline
Captain_J_Sheridan
313 posts
Nomad

Put a Trace on the code so you can check where the problem is

Retry.onRelease = function() {
gotoAndStop(1);
trace("yay&quot
}
Maaron
offline
Maaron
47 posts
Nomad

I tried the trace thing and none of it worked, the button or the trace, I have absolutely no idea why it isn't working, from what I know of actionscript it should be working.

Maaron
offline
Maaron
47 posts
Nomad

Here is the whole script:

stop();

Player_mc.onEnterFrame = function() {
//Check If It Touches The Wall
if (Wall_mc.hitTest(Player_mc._x, Player_mc._y, true)) {
gotoAndStop(2);
}
if (Finish_mc.hitTest(PLayer)) {
gotoAndStop(3);
}

//Control Player With Keyboard
if (Key.isDown(Key.UP)) {
this._y -= 5;
}
if (Key.isDown(Key.DOWN)) {
this._y += 5;
}
if (Key.isDown(Key.RIGHT)) {
this._x += 5;
}
if (Key.isDown(Key.LEFT)) {
this._x -= 5;
}
}

//Restart Button
Retry_btn.onRelease = function() {
gotoAndStop(1);
trace("hello"
}

Maaron
offline
Maaron
47 posts
Nomad

Sorry about the triple post but could the problem be that when ever I click retry it takes me back to the maze but the player is still touching the wall so it just sends me back to the "you lose" page. If this is the case then I need the player to be reset to a certain set of coordinates when I click retry, how would I go about doing this.

IQAndreas
offline
IQAndreas
299 posts
Peasant

Ah. There is the problem.

You need to reset the player to the beginning of the maze.

I'm not really good at AS2, but this should solve the problem.

onLoad {
Player_mc._x = 0 //Or wherever the player starts out.
Player_mc._y = 0 //Or wherever the player starts out.
}


Or, you could try this:
//Restart Button
Retry_btn.onRelease = function() {
Player_mc._x = 0 //Or wherever the player starts out.
Player_mc._y = 0 //Or wherever the player starts out.
gotoAndStop(1);
}

Showing 1-15 of 42