Apologies for repeated posts but i'm slowly learning my way SGDK & C.
I'm doing as much legwork as I can but I do need help with a few things.
I've structured my game (early WIP) by using cases however I'm having issues with it waiting for a joypad instruction.
Here is the code so far:
Code: Select all
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <genesis.h>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <gfx.h>
#include <sprite.h>
#include <sound.h>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define GAME 2
#define TITLE 0
#define INTRO 1
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define LINES 36
#define TILE 40
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static void handleInput();
static void joyEvent(u16 joy, u16 changed, u16 state);
static void introJoyEvent(u16 joy, u16 changed, u16 state); // Intro Trigger
static void gameJoyEvent(u16 joy, u16 changed, u16 state); // Game Trigger
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int gamestate = INTRO;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
volatile int waitflag = FALSE;
int score = 0; // SCORE TRACKER FOR LATER
int main()
{
u16 palette[64]; // DECLARE PALETTE
u16 ind; //DECLARE IND
SYS_disableInts(); // disable interrupt when accessing VDP
VDP_setScreenWidth320(); // initialization
JOY_setEventHandler(joyEvent);
VDP_fadeIn(0, (4 * 16) - 1, palette, 20, FALSE);
// set all palette to black
VDP_setPaletteColors(0, (u16*) palette_black, 64);
///////////////////////////////////////////////////////////////////////////////////////////////////////////
// prepare palettes
memcpy(&palette[0], bgb_image.palette->data, 1024 * 2);
memcpy(&palette[16], bga_image.palette->data, 32 * 2);
///////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
VDP_clearPlan(PLAN_A, TRUE);
VDP_clearPlan(PLAN_B, TRUE);
SYS_enableInts();
while(TRUE)
{
switch(gamestate)
{
case TITLE:
waitMs (400);
SYS_disableInts();
//Clear the A Plane to remove the logo and title screen text
VDP_clearPlan(PLAN_A, TRUE);
VDP_clearPlan(PLAN_B, TRUE);
VDP_drawImageEx(PLAN_A, &bga_image, TILE_ATTR_FULL(PAL1, FALSE, FALSE, FALSE, ind), 0, 0, FALSE, TRUE);
ind += bga_image.tileset->numTile;
SYS_enableInts();
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//gamestate = TITLE;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
waitMs (400);
break;
case GAME:
//VDP_drawText("Score:", 0, 0);
//VDP_waitVSync();
//JOY_setEventHandler(gameJoyEvent);
break;
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
case INTRO:
SYS_disableInts();
JOY_init();
waitMs (400);
VDP_fadeIn(0, (4 * 16) - 1, palette, 20, FALSE);
//VDP_fadeOut(0, 16, 30, FALSE);
// load background
ind = TILE_USERINDEX;
VDP_drawImageEx(PLAN_B, &bgb_image, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, ind), 0, 0, FALSE, TRUE);
ind += bgb_image.tileset->numTile;
//Main Menu Process
////////////////////////////////////////////////////////////////////////////////////////
VDP_drawText("* Press START *", 8, 15);
VDP_drawText("By Joseph Ioannou (53K70R)", 7, 25);
VDP_drawText("(C) Ponyo - Studio Ghibli", 6, 26);
VDP_waitVSync();
JOY_setEventHandler(introJoyEvent);
SYS_enableInts();
break;
}
}
return 0;
}
static void introJoyEvent(u16 joy, u16 changed, u16 state)
{
// START button state changed
if (changed & BUTTON_START)
{
//VDP_fadeOut(0, 16, 30, FALSE); //FADE TO BLACK
gamestate = TITLE;
}
if (changed & state & (BUTTON_A | BUTTON_B | BUTTON_C))
{
}
}
static void joyEvent(u16 joy, u16 changed, u16 state)
{
// START button state changed
if (changed & BUTTON_START)
{
gamestate = TITLE;
}
if (changed & state & (BUTTON_A | BUTTON_B | BUTTON_C))
{
}
}
I've setup joyevents as noted above however it doesnt seem to have any sort of effect when pressing start etc,
Any help would be great!! Thanks!
[UPDATE] I've noticed that when I use frame skip, it seems to wait for the instruction then moves to the next case so I'm wondering what I'm doing wrong?