i am making a game where the main charecter is in the middle of the screen and when he moves left or right the animation of him moving plays and the ground moves in the opposite direction
but when you release one of the keys the animation of the charecter moving in that direction continues
this is some code for attacking, moving and moving a game map, it's a zelda type engine.
May come in handy through your moving and attacking troubles. I had a difficult time figuring out mine my first time as well.
I will post this code here as a reference for you to look at while you work on your game. If you need any other code examples like this let me know and I will remove this one and put up the new one.
I use this code to scroll the game in a zelda type way so I dont have to tile base and can have a more detailed game without worrying about TONS and TONS of lag while the screen moves.
Code:
//attack vars
slice = false;
stab = false;
attack = false;
//attack conditions
function stabMethod() {
stab = attack=true;
game.player.gotoAndStop(4);
}
function sliceMethod() {
slice = attack=true;
game.player.gotoAndStop(3);
}
function ruptureMethod() {
rupture = attack=true;
game.player.gotoAndStop(6);
}
function exMethod() {
ex = attack=true;
game.player.gotoAndStop(5);
}
//attack timer
at = 0;
//player move speed
speed = 17;
//game map scroll
gscr = 0;
scrollgame = false;
//game map wall border
topwall = false;
bottomwall = false;
rightwall = false;
leftwall = false;
onEnterFrame = function (){
if (!scrollgame) {
if (Key.isDown(Key.UP)) {
game.player._y -= speed;
game.player._rotation = 0;
if (!attack) {
game.player.gotoAndStop(2);
}
if (Key.isDown(Key.LEFT)) {
game.player._rotation = 315;
game.player._y += 4.25;
game.player._x -= 12.75;
}
if (Key.isDown(Key.RIGHT)) {
game.player._rotation = 45;
game.player._y += 4.25;
game.player._x += 12.75;
}
} else if (Key.isDown(Key.DOWN)) {
game.player._y += speed;
game.player._rotation = 180;
if (!attack) {
game.player.gotoAndStop(2);
}
if (Key.isDown(Key.LEFT)) {
game.player._rotation = 225;
game.player._y -= 4.25;
game.player._x -= 12.75;
}
if (Key.isDown(Key.RIGHT)) {
game.player._rotation = 135;
game.player._y -= 4.25;
game.player._x += 12.75;
}
} else if (Key.isDown(Key.LEFT)) {
game.player._x -= speed;
game.player._rotation = 270;
if (!attack) {
game.player.gotoAndStop(2);
}
} else if (Key.isDown(Key.RIGHT)) {
game.player._x += speed;
game.player._rotation = 90;
if (!attack) {
game.player.gotoAndStop(2);
}
} else {
if (!attack) {
game.player.gotoAndStop(1);
}
}
//player attacking
if (!attack) {
buttons.stab_btn.onPress = stabMethod;
buttons.slice_btn.onPress = sliceMethod;
buttons.rupture_btn.onPress = ruptureMethod;
buttons.execute_btn.onPress = exMethod;
}
}
//attack timers
if (stab) {
at++;
if (at>6) {
at = 0;
stab = attack=false;
if (shadowgoo) {
shad++;
}
}
}
if (slice) {
at++;
if (at>13) {
at = 0;
slice = attack=false;
if (shadowgoo) {
shad++;
}
}
}
if (rupture) {
at++;
if (at>10) {
at = 0;
rupture = attack=false;
if (shadowgoo) {
shad++;
}
}
}
if (ex) {
at++;
if (at>11) {
at = 0;
ex = attack=false;
if (shadowgoo) {
shad++;
}
}
}
//stop player from leaving the map
if (game.player.hitTest(game.floor.top_wall)) {
game.player._y += speed;
}
if (game.player.hitTest(game.floor.bottom_wall)) {
game.player._y -= speed;
}
if (game.player.hitTest(game.floor.left_wall)) {
game.player._x += speed;
}
if (game.player.hitTest(game.floor.right_wall)) {
game.player._x -= speed;
}
//moving game
//top wall
if (!scrollgame) {
if (game.player.hitTest(top_wall)) {
scrollgame = topwall=true;
}
}
if (topwall) {
gscr += 40;
game._y += 40;
if (gscr>539) {
gscr = 0;
scrollgame = topwall=false;
}
}
//bottom wall
if (!scrollgame) {
if (game.player.hitTest(bottom_wall)) {
scrollgame = bottomwall=true;
}
}
if (bottomwall) {
gscr += 40;
game._y -= 40;
if (gscr>539) {
gscr = 0;
scrollgame = bottomwall=false;
}
}
//right wall
if (!scrollgame) {
if (game.player.hitTest(right_wall)) {
scrollgame = rightwall=true;
}
}
if (rightwall) {
gscr += 40;
game._x -= 40;
if (gscr>879) {
gscr = 0;
scrollgame = rightwall=false;
}
}
//left wall
if (!scrollgame) {
if (game.player.hitTest(left_wall)) {
scrollgame = leftwall=true;
}
}
if (leftwall) {
gscr += 40;
game._x += 40;
if (gscr>879) {
gscr = 0;
scrollgame = leftwall=false;
}
}
};
Last edited by everfornever; 10-16-2006 at 12:45 AM.