PDA

View Full Version : platform game help



Baelberith
March 2nd, 2008, 05:08 PM
hi there, I'm a graphic design student from Belgium and for my final assignement, I'm working on a multimedia project around Greek mythologie
I wanted to include a little game, so I started by following the tutorial here on the forum (http://www.kirupa.com/developer/mx2004/platform_game.htm), and was able to get it working, but now I'd like to make the "labyrinth" more challenging: I tried to make the screen follow the character vertically (like in this game for example: http://www.kirupa.com/forum/showthread.php?t=290115), but as I'm not so experienced with action script or any form of programming, I didn't succeed :(

from what I've learned from the tutorial, this should have something to do with the _root._y that should move in the opposite way of the character
sadly I could make the screen go up and down whilst jumping, but it didn't work if the character fell down by simply walking from the edge and also it made him fall through the ground from time to time, and after a while the screen has moved so far up that the character is placed at the bottom instead of somewhere in the middle

if anyone could help me out with this one, I'd be much obliged :)

this is a link to the (very, very unfinished) game, it's only a test version: http://www.stijnvanelst.be/labyrinth_testversie4.html
(you can't fight until you've got the sword, which is somewhere near the right)

and this is the code on my character (which I got mainly from the tutorial)
I only changed the ctrl release code because it didn't work in the browser, so I changed it a bit, now you stop fighting when you press another button,
and then added _root._y += jump; when jumping



onClipEvent (load) {
jumping = true;
jump = 0
speed = 0;
maxmove = 15;
}


onClipEvent (enterFrame) {

if (!_root.ground.hitTest(this._x, this._y, true) && !jumping) {
this._y += 6;
}

if (_root.dead) {
this.gotoAndStop("dead");

} else {
speed *= .85;
if (speed>0) {
dir = "right";

} else if (speed<0) {
dir = "left";
}


if (dir == "right" && !_root.leftblock.hitTest(this._x+20, this._y, true)) {
this._x += speed;
_root._x -= speed;
}
if (dir == "left" && !_root.rightblock.hitTest(this._x-20, this._y, true)) {
this._x += speed;
_root._x -= speed;
}

if (Key.isDown(Key.LEFT)) {
if (speed>-maxmove) {
speed--;
}

this.gotoAndStop("run");
this._xscale = -100;
attacking = false;

} else if (Key.isDown(Key.RIGHT)) {

if (speed<maxmove) {

speed++;

}
this._xscale = 100;

this.gotoAndStop("run");

attacking = false;

} else if (Key.isDown(Key.CONTROL)) {

if (_root.gotsword == true) {

this.gotoAndStop("attack");

attacking = true;

speed = 0;


}


} else if (speed<1 && speed>-1 && !attacking) {

speed = 0;

this.gotoAndStop("idle");
attacking = false;

}
if (Key.isDown(Key.UP) && !jumping) {

jumping = true;
attacking = false;

}
if (jumping) {

this.gotoAndStop("jump");
this._y -= jump;
_root._y += jump;


jump -= .5;

if (jump<0) {

falling = true;



}
if (jump<-15) {
jump = -15;


}


}
if (_root.ground.hitTest(this._x, this._y, true) && falling) {

jump = 8;

jumping = false;

falling = false;

}

}
}

fw2803
March 3rd, 2008, 02:45 AM
It's simple logic. Your problem now is that... According to your codes, only when the player presses the jump button, the stage will move. So when the player falls, he/she is not pressing the jump button. Then the stage won't move. To solve the problem, you have to put the code in the frames so that...

When Flash detects a movement of player in _y value, the stage moves. So the correct condition should be:

if player_yIsChanging, stageMoves. (This is pseudocode, just to show the logic)

And for the problem of falling through floors... Let's say... Your character is at the coordinates (100,100). The floor is at (0,400) and its thickness is 10 pix, for example. The initial speed of the player is 0 but since there is gravity, the player accelerates. It might acclerates to 20 pix, for example. This number is exceeding the thickness of the floor. You set the test point of the player as the players coordinates, right? So the test point go straight through the floor.

To solve the problem, you must set a speed limit to the player's falling speed. And whatever your speed limit is, the thickness of the wall must be the same or larger than the value of the limit.

And the greatest problem...

Your game is not a tile-based one. That means you are having a very large map on the stage. Whenever you moves, the huge map moves so it is very computer-resources-consuming. You can consider changing your game to tile-based if time is allowed.

ArmoredSandwich
March 3rd, 2008, 08:09 AM
That would be a very good idea, tile based. But only if he doesn't actually has to understand the code (for a new coder it will be very hard to really understand what's going on).

http://oos.moxiecode.com/
http://www.tonypa.pri.ee/tbw/start.html

fw2803
March 3rd, 2008, 08:55 AM
So...

if time is allowed.

I've looked at his game... Strong "smell" of Prince of Persia :D. A pity if he can't make the game smooth... Or simply use traditional, Prince-of-Persia-style scene changing... I remember well that at high levels, I darenot run blindly into a new scene... :)

Baelberith
March 3rd, 2008, 03:14 PM
thanks for the advise, the stage moves fine now ^^

but you are quite right about it being processor intensive
so if there's enough time (my project is due in two months, and this game is only a minor element) I'm going to try and rework it to a tile based game,

I checked out the link to the tutorial, which seemed a bit intimidating, but also lots of fun :)

fw2803
March 4th, 2008, 03:04 AM
The code is definitely hard to understand if you are new. So if you just don't have enough time, switch to the Prince of Persia style of scene changing (if you know what I mean... i.e. the player leave scene 1 and instantly appear at one end of scene 2)

Anyway... Your game looks nice. Make it smooth and it's perfect.