PDA

View Full Version : platform type game thing!!


frodo
12-07-2001, 03:51 PM
I am currently working on a platform type game and after much searching on different actionscript forums i managed to find some code on this forum :

-- CODE ON THE HERO MOVIE CLIP --

onClipEvent(load){
MovieClip.prototype.keepOnFloor = function(gr,floor){
this._y+=this._gravity+=gr;
var pos=new Object();
pos.x=this._x; pos.y=this._y;
for (var i=0;i<=this._gravity; i++){
if (floor.hitTest(pos.x,pos.y -i,1)){
while(floor.hitTest(pos.x,pos.y -i,1)){
pos.y--;
}
this._y=pos.y-i;
this._gravity=0;
}
}
}
}

onClipEvent(enterFrame){
if (key.isdown(key.LEFT)) {_x-=5;}
else if (key.isdown(key.RIGHT)) {_x+=5;}
else if (key.isdown(key.UP)&&this._gravity==0){
this._gravity=-50;
}
this.keepOnFloor(7,ground);
}

--CODE IN PLATFORM MOVIE CLIP--

onClipEvent(enterFrame){
if (hitTest("_root.hero")){
_root.hero.ground = this;
//trace(this);
}
}

The code works like this:

If the hero is detected on a platform the name of that platform is passed to the hero movie clip via this as is indicated in the platform movie clip.
This work some of the time but at others the hero just falls through the platform. If there is anyone who can help in any way it would be well apprieciated.Thanks.

20 Ton Squirrel
12-08-2001, 03:21 AM
Yo! I, too, have suffered at the hands of side-scrolling fruity goodness... with my hero plummetting to doomy doom despite ingenious code. Indeed even the Friends of Ed, who are indirectly friends of mine because I happen to like Ed, have tasted the bitter tang of defeatedosity.

THE WEED OF CRIME BEARS BITTER FRUIT!!!!

Ummm... right. You might want to check out a marvelous book by the Friends of Ed titled Flash 5 Game Studio (http://www.amazon.com/exec/obidos/ASIN/1903450675/ref=pd_sxp_elt_l1/102-1382007-3387329). Contained in this book are samples galore of gaming things.

In fact, on the FOE website you can find sample code that deals with THIS VERY PROBLEM... sort of. I found that the character still fell through despite their rather clever collision detection. But heck, it's a start, right? Check it out...

20 Ton Squirrel's Shameless Plug for FOE (http://www.friendsofed.com/books/studio/games/code.html)

frodo
12-08-2001, 12:50 PM
Thanks for the reply 20 after about 2 hours of extra tweeking i managed to solve it, to a certain extent, but the man still seem to fall through before the code compensates and puts the hero on the platform. So yes, i suppose it works.But being the perfectionist i am [--this being my new years resolution or will be,oh yes!!--] i want the hero to fall and land first time on the platform. But your right, it's a start..
I have a copy of Flash 5 Games Studio and i have seen the code which you mensioned, i think, but i will have a closer look. And i'll have a look on FOE web site.
Thanks a lot again..

20 Ton Squirrel
12-08-2001, 06:25 PM
Post up if you find a good solution, I'd like to hear it. Maybe when I get some of the current crap off my plate o' projects I can come back to this one... if I find anything I'll let you know as well.

303 maddec
02-22-2003, 02:59 PM
I'm looking around this tutorial from friends of ed (recuerun) now, I don't know if you're always interested on ;)

Yes, I think too that it is a good point to begin... but do you go further into this, did you made some improvements?

First there is a bug when the character is fallingdown after a jump,
the movement don't go fluently to the platform, there is little jerk, do you know how to explain this problem? Is it because platform coord. aren't integer???

second I'm trying to make this game better, and be as near as possible to a mario game in the quality of the playability etc...
(very ambitious ;)).
the first problem I saw, is that all jump are the same height because the scripting don't use a on clipevent (keyUp).
I have tried to use one and put: speedVert*=-1;
so the hight of the jump is changing depending on how much time you push your key down.... but it didn't play very well,,,
because jerks. I'm going looking around this problem now...
maybe the jump() function is a bit too much simple???
I'm interested on your reply about that, and about what you experienced yourself...

second I have put a specific value for maxspeed and speedincrement to use during the jump, --> the character is less easily moveable during a jump than during his walking....
like in mario....

more later........
Thank you for your help and comments.