Map--noob in need

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
PsyOps
Posts: 5
Joined: Tue Jan 23, 2007 12:50 pm

Map--noob in need

Post by PsyOps »

ok there doesnt seem to be much going on in the lua section of this forum so i hope im not bugging anyone with questions...

Im not trying to make this game for others to play. If it gets that far i will give the source out and gfx. But my intention is just to get an understanding of the gaming physics and how to code. Im trying to duplictae Subspace. a 2d space shooter game that maneuvers alot like the old asteroids game.

I have very little done so far. I have 40 frames for ship rotation (360degrees) and some tile images that i will use to make maps.

Where would you suggest i start?

Im trying to understand the physics of a 2d flyer game like this and i dont know how i would start with actually coding it. i dont wanna just copy and paste some code from somewhere, i wanna understand it.

anywho heres a few questions for those of you who are willing to help a noob out.

1.)How do i make a level bigger then the screen size. Like mario scrolls sideways...i want the ship to go in any direction, but be limited to mapsize.

2.)how would i start off with coding ship movement. I understand that its like putting a circle in a grid and having to plot the different points as closely as possible to the angle of flight. As of now...i have 40 frames for rotation which breaks down to 9% of rotation per frame.how would i plot the movement in pixels for every angle.

3.) this i will probably leave until the end, if i ever get to it. Once 1 and 2 are coded how would i code in collision for the map walls n stuff.

oh and if anyone needs help with gfx please lemme know, thats more my thing.

--noob in need
Snoochie Boochies
Altair
Posts: 76
Joined: Sat May 20, 2006 2:33 am
Location: The Netherlands

Post by Altair »

1) there are alot of scrolling tuts. It basicly comes down to this. You blit that part of the map to the screen that is visible. What part is visible, depends on where you're ship is.
As LUA can't handle bigger png images then 512x512, the map can't be bigger then that, IF you only want to use one image.
However you can make a tilesystem (or look in the tuts and use those). This looks where you are on the map and blits those tiles to the screen. This is a bit slow in LUA, because now it has to blit more then one image to the screen. (so this works with multiple smaller images)
Last thing you could do (which is what I do, as long as it will fit in the memory, haven't tested the limits, but it works with 1000x1000) is load a big JPG image, which is totally black) and blit the seperate images (tiles) on the big JPG image. Now you have one big image instead of alot of small tiles, and you dont need a tilesystem which saves processing time and blitting time.

So I would go for the last thing, since it's really easy. (I have LUA 0.16 I dont know if this works for other versions, as this is actually a bug, so Shine says)



2) Always try to think of how a computer would see things. Atleast thats how I solve these "how do I start"-things. Moving is translational and rotational moving. Translation is just x = x +/- n and y = y +/- i.

The rotation for you is pretty easy, because you have seperate images, so you dont need to actually rotate. You have to determine the direction you are flying in. How to do this depends on your controls aswell.
If you move the ship when you move the analog stick, you take the dx and dy of the analog stick. Now you know the direction and you can blit the according image.
If you use the analog/D-pad only to stear you would do something like this. If you press the left button, add 9degrees to the angle and blit according image.



3) By walls of the map, do you mean the boundaries of the map? If so, that's really easy, just do something like:

if x < 0 then x = 0 end
if x > map_width then x = map_width end

same for y.

If you mean collision with abjects on the map, it's a little harder. It also depends on what you want to happen when there is collision.
The collision detection itself is pretty easy. You have to check if the x and y coords of the ship are the same of an object. Also keep the width and height of the ship and object in mind.

If you want to make it so that you die when you collide. You can just do: if collision then show gameover stuff and restart end
or something similar.

To make the ship stop or bounce its a little harder. You would have to incorporate the direction you are coming from and the angle at which you hit the object etc.



Hope it's all a bit clear, if not I'll try to explain better, let me know.
Good luck
PsyOps
Posts: 5
Joined: Tue Jan 23, 2007 12:50 pm

flagelrudlehopplebuns

Post by PsyOps »

hey thanks alot bud.
i had lots of help from all around.
The movement of the ship some how broke down into a circle and alot of triangles hehe.

The code i used worked out well. Someone also suggested using a table to hold all the sin and cos values so the app wont have to process it during the game. it would just bring them up from the table.

could you maybe show me a bit of code as to how i would blit each of the diff techniques. Seems like the speed of the game depends on how fast lua processes the images. Is there a method to sort of clean up memory? Seems like each time i run the game, the second time i try and run it in a row it tells me it cant load an image. Not sure if thats memory related.

anywho thnx in advance for the help. If i have any more questions ill try and post them before i forget.
Snoochie Boochies
Post Reply