Help with platforms in a Platform game

I have a problem for a 2D platform game I’m trying to make. It’s my first real platform game and I’m trying to make it really good so I’m being really picky about it, or at least some people might say so. My problem lies within the platforms in the game. I am trying to make it so that the character can fall at a constantly increasing speed and still land on any platform beneath them without going through it or sinking into it for one frame before popping up to the correct height. How I did this at first was I had each platform check the _y distance between the character and the platform, if the distance between the character and the platform is less than or equal to the distance the character will go down in the next frame then it tells the character to go to the same height as the platform and basically land. So now I have all that king fine but I feel I have to rethink it because I want all the items and enemies to be able to interact with the platforms as well, in which case I would have to duplicate that same code over and over except with different instance names for the different objects and enemies etc. I think the solution I am looking for to cut down on massive amounts of repetitive code is to put the landing-on-platforms code inside the objects themselves that are landing on the platforms instead of in the platforms so that the objects are self-sufficient so-to-speak. One obvious solution would be to say the same thing except reversed: so that instead of “if that object is gonna touch or go past the this platform, then land ON this platform.” say inside the objects “if this object is gonna touch or go past that platform, then land ON that platform.” But this in turn would require saying that same code over and over to address every instance of the platform that are on the screen to land on. So summarized, is there any way that I can say something more along the lines of “if this is going to pass any platform then stop on that platform” so that I have one short sweet line of code in each object???

I’ll be watching the thread closely of course so just ask anything you dont get and ill explain :wink: thnx

dude… platformers arent exactly my area of even rudimentary knowledge… but maybe you want to post the file or the code your having trouble with, if not me, Im sure a bunch of others on here would be able to help you out.

and Im pretty sure theres a way to do what your looking to do because repetitve code can usually be made smaller and more efficient.

I had a similar problem with my platform game. I went with the repetetive code system, where each platform checks if a ‘char’ is above it, and then sets the 'char’s virtual ground to the level of the platform. The standard ground-hitting code then takes over to stop him going through the platform.

(‘char’ is a one of the game characters, be it the player guy, or the enemy guys. It checks through them all in order.)

If I remember, I’ll convert the platform-test code to run through an array of currently ‘alive’ characters, because I’m sure I can save some time there, too, especially when all the enemy guys are dead…

I was fond of solving my own problems, so I made this up myself. I’ve never actually read a platform game tutorial, so I don’t know how other people do it. Be worth checking though. My methods are probably not the most efficient.

dal platinum, your method sounds probably a LOT more efficient then mine, i’m not very into getting answers from others either but in my case it has lead me to things such as not understanding arrays at all… :stuck_out_tongue: theres still a lot i have to learn and i guess i just thought if i wanna “keep up” i’ve got to start asking for help more often. Thanks for the comment though and i guess ill go look into more tutorials and things. I see that those links that are at the top of this forum look very interesting and will probably help alot, idk though… thnx for the comments! (btw that doesn’t mean like, im closing the thread, im still open for more suggestions :-P)

You could try a book :D. I bought two books on gaming, and they both explain the platformer :). here they are:

thank you, el pooter, ill look into those books.

Your welcome