Alice Community Help With a 2D Platformer

 Help With a 2D Platformer
 cbw92 Guest   Status: Posts: n/a Help With a 2D Platformer - 03-07-2009, 11:02 PM Hey everyone. I'm working on a 2D platormer and need some help with things like collisions with higher elevated platforms, and landing on top of higher leveled platforms without dropping down below to the elevation I was on previously. Any help is appreciated! Also, if it's helpful, I have a decent idea of how to do horizontal colisions, but as it is now, any time I land on the box with a collision thing, I'm pushed backwards and drop down to the original level. Last edited by cbw92; 03-07-2009 at 11:11 PM.
 rich0e0rick Senior Member     Status: Offline Posts: 141 Join Date: Jan 2008 Location: Sturgeon Falls 03-08-2009, 12:08 AM anychance you can post the world? im currently working on GUERRE a 2d platformer that was doing very well, but the code was amasingly complex (about i think it was 20+diferent methods) but my world was more than horiontal, there was angles and elevations in it to. i had basically done a gravity simulator after working out the camera movements. by making my character go at a variable speed indefinately (starts at 0) and then finding out if hes touching the ground or not, i can make the variable go up or down every 0.05 seconds, giving a acceleration (or decelaration if going up). i used big squares to create the basic shape of the map, and then went in and at the corners of each "meeting point" of the squares, i put more cubes. the cubes i therefore used to find out if my character passed in between them (or through the ground technically). and if he did, i would tell the gravity variable to go back to 0 and bring up the caracter to go back up to "sit" on the ground. i thought of a simpler way of doing it after my computer crashed (again arg!) YAY for my new mac! SUCKS that i lost most of the work.... thank god for the backup file i had done at the beginning...ill still have lots of work to do to get back to were i was but ya, if i can go through the code, im sure i can figure out wats wrong. hope i can help rick im back!!! FINNALY!!! got windows working on my mac again!!!
 cbw92 Guest   Status: Posts: n/a 03-08-2009, 12:54 AM Ok, that seems to make sense... I need to first figure out how to make a gravity generator first thoguh, lol. Thanks though, I'll see what I can do!
 cbw92 Guest   Status: Posts: n/a 03-08-2009, 10:01 PM Also, is there a way to constrain a character to a 2d plane? I think I figured out a way to work a 2d platformer, but onyl if I can keep my character on the plane permanently. Thanks!
 x2495iiii Super Moderator     Status: Offline Posts: 3,508 Join Date: Dec 2008 Location: Somewhere in the Continental U.S. 03-08-2009, 10:27 PM You could only events which correspond to the direction he can move be linked to the arrow keys. Example, if you're playing a sidescroller, have four events, one for each arrow key (while a key is pressed). Have the left/right keys move the character left, right, then have the up down arrow keys have the character climb vertically or descend vertically (like on ladders in Contra or Megaman). As for ground collision detection, the easiest way is to have a function for how far the character is aobve the ground itself. there's no need to add objects, just use the ground. Since the ground is a flat plane, if the character's feet are always a certain distance above the ground's center (where the distance is measured), the feet are always that same distance above the rest of the ground as well. As for object collision detection, simply use the same method but with the object as the target. If the object's center is used to measure the object's position, use the objects width/height/length as the distance. If not, place an object (like the squares rick used) at the top of the object, then use the square as the target. If you'd like' I can post a world that explains what I mean. (')>
 rich0e0rick Senior Member     Status: Offline Posts: 141 Join Date: Jan 2008 Location: Sturgeon Falls 03-09-2009, 11:55 AM exactly, i only put squares at the corners of the tops for each angle, since my world wasnt horizontal lines, it was rough terrain. you should easily be able to find the height of your ground, and then simply substarct that from your equation to find the edge. although you might want to still put squares at the corners if you need collition detection from the side as well, since you can simply find that certain object, and therfore use the (left of __) function or watever rick im back!!! FINNALY!!! got windows working on my mac again!!!
 rich0e0rick Senior Member     Status: Offline Posts: 141 Join Date: Jan 2008 Location: Sturgeon Falls 03-09-2009, 12:02 PM for gravity, put in a method that starts at the world begining: in a infinite loop put a character move down at speed (variable gravity) duration= 0.05 then in your gravity method. find out if it touches the ground; if so---put (variable gravity at 0 if not ---- variable gravity = variable gravity plus 0.03 (fine tune this one, it depends on your sizes) jumping function when your press space: do jumping method------ if character on ground---- variable gravity = -13 if not, ---- do nothing this should help you figure out the gravity, simply change the numbers to your liking p.s. you might have to find a way to overrun the gravity function wen jumping, since if not the (variable gravity) might stay at 0 and seem to not work.... rick im back!!! FINNALY!!! got windows working on my mac again!!!
cbw92
Guest

Status:
Posts: n/a
03-09-2009, 05:32 PM

Ok, thnak you for the help guys, I will do my best to try and work my way through your instructions. I appoligize, I didn't notice your request to post my world, here it is.. assuming I post it right, lol.

This one is my current attempt. I made a simple gravity generator, but I'd like to try your suggestion. I'm very new to Alice, so it's nothing much!
Attached Files
 Bunny Cube.a2w (584.6 KB, 28 views)

 DrJim Guest   Status: Posts: n/a 03-10-2009, 11:01 AM You might also want to take a look at http://www.alice.org/community/showt...hlight=davario , a very nice takeoff on Mario. Note that while all the action is basically 2D, the game does make good use of 3D in the way the characters move against the background. The comments are in Dutch, but the code is fairly easy to follow.
cbw92
Guest

Status:
Posts: n/a
03-14-2009, 02:21 PM

Thank you DrJim, that was fairly helpful. I must thank you all, I think I finally figured it out! Here's a sample of my current project, it's still pretty rough. Here's a sample! I do have one final question (I hope), is there a way to measure distances between objects without the trial and error method?
Attached Files
 Kube-aroo.a2w (1.85 MB, 21 views)

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Announcements     Community News and Announcements Alice 3     How Do I?     Works In Progress     Share Your World     Share Custom Classes     Bugs and Trouble Shooting     Suggestion Box Alice 2     How do I...?     Works-In-Progress     Share Worlds     Share Objects     Bugs and Troubleshooting     Suggestion Box Educators     Teaching with Alice     Teaching Using Alice 3     Teaching Using Alice 2     CS Principles and Alice     AP CSA and Intro to Java and Alice     Workshops General Discussion     Questions and Comments     The Lounge