PDA

View Full Version : Help with frogger game


fatbloke
07-18-2003, 05:59 PM
Help ! Please look at the attached code. I want the player mc to move at the same rate as the trans mc's when hitTest is performed. and also be able to move to either end of the trans mc's (walk along length). As you can see it keeps flipping to the middle.
Hope this makes sense! many thanks!

fatbloke
07-18-2003, 06:03 PM
oops!

ebmGameGuy
07-18-2003, 11:27 PM
I didn't actually look at your code, but I did write some of my own. You can modify this to fit your game. As you can see I only had one log in my test file but you should be able to figure out how to get all of the logs to call the same function.


// Keys
Key.addListener(frog);

frog.onKeyDown = function() {
if (this.keyed == 0) {
this.keyed = 1;
currentKey = Key.getCode();
this.getKey(currentKey);
}
};

frog.onKeyUp = function() {
this.keyed = 0;
};

frog.getKey = function(keys) {
if (keys == 37) {
frog.move(1);
}else if (keys == 38) {
frog.move(3);
}else if (keys == 39) {
frog.move(2);
}else if (keys == 40) {
frog.move(4);
}
};

frog.move = function(dir) {
switch(dir) {
case 1:
// Left
this._x -= 25;
break;
case 2:
// right
this._x += 25;
break;
case 3:
// up
this._y -= 50;
break;
case 4:
// down
this._y += 50;
break;
}
};

frog.changeX = function(x) {
// frogs position changed by object
// it is sitting on
this._x += x;
};

log.speed = 5;

log.onEnterFrame = function() {
// move log
this._x += this.speed;
// look for frog
if (this.hitTest(frog)) {
// change frogs x position
frog.changeX(this.speed);
}
};


all of this code is on the main timeline

fatbloke
07-19-2003, 02:57 AM
I've just pasted the code into a new movie and it works cool. Thats just what I needed many thanks ebmGameGuy!