GP32 Tut3


Siajj

Still Fresh
Joined
Apr 22, 2004
Messages
12
Could someone please help me, I just got my game park yesterday and I have been spending all afternoon looking at some tutorials. I get the basics because I programmed with other languages before, the problem is that I can’t get tut3 to work.

If anyone has got it to work could you please put all the files into a zip, like what has been done with tut2, hopefully this will not only benefit me but other people.
 
npal should be in the file output from the GP32 convertor. The utility that converted your images into an array in a .h file. Is it there? It could be under a different name.

Edit: The pallette won't be there if your source images aren't palettized.
 
well, i've had the same problem - daz, where exactly does it define npal? i have looked everywhere, and in the picture's header file itself, and i cannot find anything called npal
 
If you converted a palettized image, you there will be a palette in the image header file. It could be called something completely different to npal though. It will be the smaller of two arrays. if you only have one big array, you must have converted a 24bit image by mistake.

You need to rename your palette's array to npal, or you need to change that reference to point towards your real palette.
 
That’s helped fix the npal error but I am still getting other errors such as:

‘tile’ undeclared <first use in this function>
stray ‘\240’ in program

coRp have you been able to get it to work???


This is my code:



/* Rico's GP32 Programming Tutorial, part 2
Example source */

#include <stdlib.h>
#include "gpdef.h"
#include "gpstdlib.h"
#include "gpgraphic.h"
#include "gpmain.h"
#include "gpstdio.h"
#include "gpfont.h"
#include "tileset.h"

#define TILESIZE 32
#define MAPH 100
#define MAPW 200

int py, px, ex, ey, exmax, eymax;
unsigned char map[MAPW][MAPH];

void GpMain(void *arg)
{
Init();
GameEngine();
}

void Init()
{
int i, j;
GpClockSpeedChange(132000000, 0x24001, 2); /* speed = 133 Mhz */

/* Page-flipper - we need to keep track of which video page we're on. We'll start with page 1. */
nflip = 1;

/* Enable and clear LCD screen:
go through each page (this loop is a little pointless) and register it as a 'page' with the GP32. */
for(i = 0; i < 2 ; i++)
{
GpLcdSurfaceGet(&gpDraw, i);
}
/* Here we wipe the first screen clear white - it starts off with random garbage. We don't need to clear screen 0, since it
is a direct copy of screen 1. */
GpRectFill(NULL, &gpDraw[nflip], 0, 0, gpDraw[nflip].buf_w, gpDraw[nflip].buf_h, 0xff);

h_pal = GpPaletteCreate(256, (GP_PALETTEENTRY*)npal);
GpPaletteSelect(h_pal);
GpPaletteRealize();
GpPaletteDelete(h_pal);
h_pal = NULL;

/* The GP32 needs to know to show screen 0 on the LCD, while we show screen 1 */
GpSurfaceSet(&gpDraw[0]);

/* The random values all come from one number, this case 36547. The random numbers will be
the same every time this way, but we'll improve that later */
srand(36547);

py = px = 400;
exmax = MAPW * TILESIZE - 320;
eymax = MAPH * TILESIZE - 240;

for(i = 0; i < MAPW; i++)
{
for(j = 0; j < MAPH; j++)
{
map[j] = (unsigned char)(rand() % 36);
}
}
}

void GameEngine()
{
while(1)
{
HandleInput();
ex = px - 160;
ey = py - 120;

if (ex < 0) ex = 0;
if (ey < 0) ey = 0;
if (ex > exmax) ex = exmax;
if (ey > eymax) ey = eymax;
DrawTiles(ex, ey);
/* Now we tell the LCD to swtich to the next page, and tell our program to draw on the next page
e.g. at the start of the code, LCD is set to 0, drawing (nflip) is set to 1
Now LCD is set to 1, nflip is set to 0 ... clever eh? */

GpRectFill(NULL, &gpDraw[nflip], px - ex - 5, py - ey - 5, 10, 10, 255);
GpRectFill(NULL, &gpDraw[nflip], px - ex - 4, py - ey - 4, 8, 8, 0);
GpSurfaceFlip(&gpDraw[nflip++]);
nflip &= 0x01;
}
}

void DrawTiles (int x, int y)
{
int xtile, ytile, xpos, ypos, i, j;
/* Getting starting tile to draw at */
xtile = x / TILESIZE;
ytile = y / TILESIZE;
/* Get the pixel offset to draw at
By the way, 'xpos = x & 31' is the same as 'xpos = x % 32' but faster */
xpos = x & (TILESIZE - 1);
ypos = y & (TILESIZE - 1);
/* Now draw the tiles */
for(i = 0; i < (320/TILESIZE + 1); i++)
{
for(j = 0; j < (240/TILESIZE + 2); j++)
{
/* Get tile number to draw, draw it */
tile = map[ytile + j][xtile + i];
GpBitBlt(NULL, &gpDraw[nflip], i * TILESIZE - xpos, j * TILESIZE - ypos, TILESIZE, TILESIZE,
(unsigned char*)sprite_tileset, tile * TILESIZE, 0, sprite_tileset_width, sprite_tileset_height);
}
}
}

void HandleInput()
{
ExKey = GpKeyGet();

if (ExKey & GPC_VK_LEFT) px--;
if (ExKey & GPC_VK_RIGHT) px++;
if (ExKey & GPC_VK_UP) py--;
if (ExKey & GPC_VK_DOWN) py++;
}
 
try adding tile as a variable right below where 'map[MAPW][MAPH]' is declared

add this line there.

unsigned char tile;

This may not need to be declared globally. So you may also be able to declare it at the beginning of the GameEngine() function instead.
 
That worked but i'm still getting errors, has anyone actually been able to get tut3 to work?? The reason I ask is I’m just wondering if you went by the tutorial exactly or did you have to add small snippets of code in order to get it to work.
 
Back
Top