LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

Platformer Help

Root / Programming Questions / [.]

UltraPhoenix4Created:
I need to know a good way to make a platformer as in:Collision with Sprite and BG tiles or something similar, Jump physics, So basically the basics of a platformer. Please and thank you.

This is a much more complicated question than you know. There are a lot of concepts behind it that you will need to understand before you can properly get started, which is probably beyond the scope of a single answer to a thread like this. It's best to look for general tutorials online, which I know can be difficult since so many tutorials are tailor made for specific platforms...you might want to learn on a different, potentially easier platform like Unity or Game Maker so you can apply those concepts here. I mean just for some examples...you'll want a main loop that repeats endlessly and vsyncs every frame. Then within that loop, you perform a lot of different tasks that will happen 60 times per second. These include modifying the background graphics and/or BG offset so it looks like you are moving, modifying the player sprite/animation depending on the player's current behavior (falling, running etc.), dealing with enemy behavior (whether they are walking or jumping etc.) and checking for collisions with them, detecting button presses and modifying the player's location and actions based on that, plus whatever else you think your game will need (projectiles, physics etc.). Since this stuff is happening 60 times per second, the values for these movements will be small, probably 1 or less. You will need variables to track the player's X and Y location, and if you want to have decent physics you will also want the player to have X and Y velocity that gets added to their location every frame, and have button presses modify their velocity instead of X and Y position directly. Plus you have gravity always attempting to increase their Y velocity downward, but then detect when ground is just below them and prevent the movement due to gravity when they would intersect with the ground. You will need to be able to make one or more arrays to track the tiles the background is made from, and/or which tiles are empty and which should be collided with. And then be able to perform math to translate between pixel coordinates and tile coordinates to check the status of a given tile based on the pixel coords. Some of these tasks can be made easier by built in SmileBASIC commands but I tend to write my own systems for these, because built in commands for collision etc. don't cover all my use cases or just don't work the way I want them to. But you could look into functions like SPHIT and SPCOL.

Unclesporky is right. Platformers are constructed of lots of little problems to figure out. You have to take them one at a time. You even listed a few components to a platformer, so maybe just pick one of them for now. I'd suggest movement and jumping. Don't worry about collisions for now, because they can quickly become very complicated. Here's a thread I responded to on reddit: https://www.reddit.com/r/SmileBASIC/comments/486x9b/require_help_check_description_for_details/, about adding a jumping mechanic and gravity. It's example code, but it does work. So maybe take a look at that comment thread and try to replicate something like that. The person I was responding to was interested in making a MegaMan style game, so that shares a lot of similarities to platformers in general.

Thank you both! I'll try my best. And UncleSporky, I'll try to use the info you gave to make a basic platformer, and I'll upload the key here. And I'll keep adding onto it until it becomes decent.