matteus wrote:I wondered if someone could tell me if there was an easier way of delaying text than doing this!
Code: Select all
case 6 :
if (drawnScreen == 0) {
ind = TILE_USERINDEX;
VDP_drawImageEx(BPLAN, &roomNorth_image, TILE_ATTR_FULL(PAL2, FALSE, FALSE, FALSE, ind), 0, 0, TRUE, TRUE);
ind += roomNorth_image.tileset->numTile;
clearMessageBox();
drawnScreen = 1;
}
if (SubStageInt == 60) {
VDP_drawText("Welcome inside...", 2, 23);
} else if (SubStageInt == 120) {
VDP_drawText("You have entered the tomb of Dracula.", 2, 24);
} else if (SubStageInt == 180) {
VDP_drawText("The door closes behind you...", 2, 25);
SubStageInt = 0;
StageInt = 7;
}
SubStageInt++;
handleInput();
break;
case 7 :
I'd love to get it writing the text character by character but I'm not sure how easy that is to do!
What you have there are basically scripted events. At a certain time value, you do something different. If you really want to avoid writing your event /text code this way, you're going to need a more generic way to do it.
The following is just to give you ideas. There are most likely much better ways.
Every room has events like "show a picture" and "print text", right? You could put them in a structure like. (pseudo-C ahead)
Code: Select all
// event types
#define EVENT_SHOWSCREEN 0
#define EVENT_CLEARTEXT 1
#define EVENT_PRINTTEXT 2
#define EVENT_WAIT 3
#define EVENT_END 4
// event struct
typedef struct
{
u16 eventType;
void* parameter;
} Event;
typedef struct
{
u16 plan;
const Image *image;
u16 basetile;
u16 x;
u16 y;
u16 load pal;
u16 use_dma
} BackgroundParameters;
And then for each room, you define a series of events.
Code: Select all
BackgroundParameters roomt20Image = { BPLAN, &roomNorth_image, TILE_ATTR_FULL(PAL2, FALSE, FALSE, FALSE, ind), 0, 0, TRUE, TRUE }
Event room20Events[] = {
{ EVENT_SHOWSCREEN, (void*)&room20Image},
{ EVENT_CLEARTEXT, 0 },
{ EVENT_WAIT, 60 }, // 60 is the amount of time to wait
{ EVENT_PRINTTEXT, "Welcome inside..."}, // your text box manager will know where to print this
{ EVENT_WAIT, 60 },
{ EVENT_PRINTTEXT, "You have entered the tomb of Dracula."}, // your textbox manager will know to print this after the first line
{ EVENT_WAIT, 60 },
{ EVENT_PRINTTEXT, "The door closes behind you...""},
{ EVENT_WAIT_FOR_KEYPRESS, 0},
{ EVENT_END, 0}
}
You would have a manager that acts as a state machine. It takes an array of those events and processes them.
So when you enter room #20, some code somewhere will call:
Code: Select all
EventManager_runEvents(room20Events);
The EventManager, run every frame, will process those events. It'll be pretty much a big switch statement.
Code: Select all
void EventManager_runEvents(Event* events)
{
EventMananger_ResetVariables();
currentEvents = events;
}
// run every frame
void EventManager_UpdateEvents()
{
if (timer > 0)
{
timer--;
return;
}
while (currentEvent != 0)
{
switch (currentEvent->eventType)
{
case EVENT_SHOWSCREEN:
BackgroundParameters* parameters = (BackgroundParameters*)currentEvent->eventType;
VDP_drawImageEx(parameter->plan, parameter->image, etc, etc.);
break;
case EVENT_CLEARTEXT:
// clears the text box
break;
case EVENT_PRINT:
char* text = currentEvent->parameter;
VDP_drawText(text, 2, 23 + currentLine); // change the 23 (or whatever the y of the first line is) to a define or a constant.
currentLine++
if (currentLine > maxNumberOfLines)
{
currentLine = 0;
}
break;
case EVENT_WAIT
timer = currentEvent->parameter;
currentEvent++;
return;
case EVENT_END:
currentEvent = null.
return;
}
currentEvents++;
}
}
It's really rough, but something like that. Don't expect the above to work or compile
I can't build it for you, but you should be able to get ideas from it.
You can add new events like EVENT_CHANGEROOM which will load up another series of events. Anything you want.
For printing one letter at time, you'd add an extra event like EVENT_PRINTSLOW and use a timer inside the update function to print one letter at a time.
You're basically building a state machine for your game. There's a lot of information about them out there.
A system like that is more complicated up front than writing everything like you are now, but it's more flexible in the long term. Maybe not for your current game, but maybe for the next one.