GP32 Tiles


seth

Member
Joined
Apr 28, 2003
Messages
171
In games say like Tomak(arent thoose called side scrollers) how would i go about making a game like that
what would i have to do to make it scroll and such?
 
Make your self a whatever width * 240 high, background picture
set up the GpSurfaceFlip animaiton thing

#include "gpdef.h"
#include "gpstdlib.h"
#include "gpgraphic.h"
#include "gpmain.h"

GPDRAWSURFACE gpDraw[2];
int nflip = 0;

void GpMain(void *arg)
{
int i;
unsigned int n_tick;

for (i = 0 ; i < 2 ; i++)
{
GpLcdSurfaceGet(&gpDraw, i); //creates LCD surfaces (one for primary & the other for back)
}

GpSurfaceSet(&gpDraw[0]); //sets gpDraw[0] as primary surface

nflip = 1; //sets gpDraw[1] as back surface

while(1)
{


GpSurfaceFlip(&gpDraw[nflip]); //sets back surface as primary buffer

nflip = (nflip + 1) & 0x01; //sets previous primary buffer as back buffer

n_tick = GpTickCountGet(); //gets current time
//synchronizes frame rate with about 1000 msec
while ( ( GpTickCountGet() - n_tick ) < 1000)
;
}
}


Convert your image with GP32Converter delete the commented guff at the top of the converted file and add it to your program with these lines

#include "yourpicture.h"
extern const unsigned char yourpicture[1600]; (the 1600 is any number but represents your pictures height times its width 1600 is for a 40x40 bitmap)

Then draw your background to the screen with.
GpBitBlt(NULL, &gpDraw[nflip], 0, 0,320,240,(unsigned char*)yourpicture,screen_start,0,screen_start +320,240);

screen_start is the location on your pictures width to start drawing, usaly starts at 0 to start drawing your background from the farleft. the start_screen+320 stops drawing your pictre at the far right of the screen. So to scroll along like in tomak you make a loop that adds to screen_start every time it passes through the loop meaning the screen scrolls from left to right.

Example:
(lets call this your picture and make it 1000 pixels wide by 240 high
<----------------------------1000-------------------------->
/***************************************\
|***************************************|
|***************************************|
|***************************************|
\***************************************/

the area out lined by 1's is the GP's screen
11111111111
1/********1******************************\
1|********1******************************|
1|********1******************************|
1|********1******************************|
1\********1******************************/
11111111111
^--------------^
0--------------320(screen_start+320
(screen_start = 0)

Now if we add 20 to screen_start
......111111111
/**1********1****************************\
|**1********1****************************|
|**1********1****************************|
|**1********1****************************|
\**1********1****************************/
......1111111111
......^--------------- ^
......20---------------360 (screen_start+320)
(screen_start =20)

Lets add another 20 to that making screen_start=40
..........1111111111
/****1*********1************************\
|****1*********1*************************|
|****1*********1*************************|
|****1*********1*************************|
\****1*********1*************************/
..........111111111

notice how it scrolls through the bit map.


This is probably a bit crude and others will use tiles to achive this, hell its probably wrong as sleep deprivation has stollen my mind. just remember you need a loop that adds to screen_start each cycle. I hope you get the general gist of this.
 
Back
Top