LoginLogin

How do I convert numbers to bg tiles/bg-># to sprites and vice versa?

Root / Programming Questions / [.]

DefaultioCreated:
This is sort of what it takes to make a side scroller, roughly: You need a virtual map. Not just the stuff you draw on the screen, but an array of numbers in memory that represent the map. You have to design it yourself, decide what numbers mean what. 0 is the sky, 1 is the ground, 2 is a ramp going up to the right, 3 is a ramp going up to the left, 4 is a rock. Making the maps can be a big hurdle. If it's a large, complex game it is always a good idea to make a map editor so you can draw it easily, convert the drawing to an array of numbers, and export that somehow to your program. You need to have sets of data for all the stuff that can move around or is interactive. A monster might need things like an ID number (which monster is he out of 10 possible at any given time?), a monster type (bat, wolf, goblin?), an X position, a Y position, an X velocity, a Y velocity, an AI state (is he asleep, is he fleeing?), hit points, magic points, a counter to refer to how long he will keep doing something, an animation frame identifier, and possibly a lot more. Even a simple bullet needs an ID, a type, X, Y, VX, VY, maybe a counter to say when it should explode or disintegrate. Typically you have all this in arrays. MONARRAY(10,10), where the first number is which monster out of your 10 monsters is the one you're referring to, and the second is which bit of data about that monster you want to look at or change. You just have to remember what the number means to you. You have to be good with loops. Loop through all the monsters and update their positions, loop through and see if any are touching the player, loop through and find an empty monster slot so you can spawn a new one. Loop through the bullets and see if any are hitting the monsters. etc., etc. If you want it to be any good, you need to have a rudimentary knowledge of physics. You can't make a good platformer by just adding numbers directly to objects' X and Y values. You'd end up with a guy whose jump is floating straight up for a second and floating right back down at a constant speed. No, you have to use variables for velocity, gravity and friction. Gravity is trying to move the player downward at all times - in other words, you are always trying to increase his Y value - but if something is in the way like, say, the ground, the program doesn't let him move downward. To jump, you give him a negative Y velocity, and then gravity can decrease that every frame by a certain amount...but he also needs a maximum falling speed so things don't get too crazy. You also need to let him build up some speed but pull his horizontal speed toward 0 at all times, with just the right amount of force. You don't want him stopping on a dime, but you also don't want it like he's sliding around on ice all the time. You need a complicated drawing engine that can take care of the difference between your virtual map data and the camera. You are literally drawing the screen onto Petit Computer's 512x512 BG layer, maybe you're at 32, 57...but virtually, maybe the map tile in the top left corner of the screen is 72, 3 in your map array, and multiplied by 16 pixels it's as if you're at 1152, 48, if your level was a huge picture in MSPaint. You have to be able to account for this difference and draw everything in the proper place. Maybe with the camera pointing at 72, 3 there should be a goblin who is spawning on a platform at 88, 10 on the map, so you do some math and figure out that means you have to draw him at 288, 169, just off screen. Then when the camera moves an instant later you have to calculate where he should be drawn again. You have to program this to happen automatically and quickly every frame. There's a lot more to it than that, too. A program state engine, for example... There are definitely some simpler ways to do these things, but you wouldn't call it much of a platformer without them. Almost all of them are an integral part of even Super Mario Bros. 1!
BAsically what he said. This is not going to be a smb1 or 2 or 3 or 4 or 5 or 21 port. Just a test program.... derp. would it be possible? I just need numbers that can be converted to either bg tiles or sprites, whichever is easier, (sprites please so i can use SPHITSP).

If you ask a more specific question, it would be easier to answer. Before you do though, I recommend that you read the manual (it's not long) and skim over the sprite category in the reference.

Basically a Conversion mechanism that converts numbers into invisible sprites. So i can use SPHITSP and what not. Like: 0=sky 1=ground 2=floating platform 3=enemy etc. it gets turned into sprites

Whoa, this is surreal. I was just clicking through topics here and stumble across this thing I wrote at GameFAQs 4 years ago. http://www.gamefaqs.com/boards/663843-petit-computer/63562812 What were you doing that you found this 4 year old locked GameFAQs topic about sidescrollers? :P