Skip to content

Commit

Permalink
Add gameloop and menu loop handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
giodueck committed Oct 2, 2022
1 parent e34c061 commit eefe3ec
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 10 deletions.
7 changes: 4 additions & 3 deletions LCD.c
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,8 @@ void LCD_gChar(int16_t x, int16_t y, char c, LCD_pixel textColor, LCD_pixel bgCo
return;
}

LCD_SetArea(x, y, x + 6 * size - 1, y + 8 * size - 1);
// + 3 accounts for the space in the memory buffer that is offscreen
LCD_SetArea(x + 3, y + 3, x + 6 * size - 1 + 3, y + 8 * size - 1 + 3);
LCD_ActivateWrite();

line = 0x01; // print top row first
Expand Down Expand Up @@ -1112,9 +1113,9 @@ void LCD_gCharT(int16_t x, int16_t y, char c, LCD_pixel textColor, uint8_t size)
if (line & 0x01)
{
if (size == 1)
LCD_gDrawPixel((uint8_t) x + i, (uint8_t) y + j, textColor.r, textColor.g, textColor.b);
LCD_gDrawPixel((uint8_t) x + i + 3, (uint8_t) y + j + 3, textColor.r, textColor.g, textColor.b);
else
LCD_gFillRectangle(x, y, i * size, j * size, textColor);
LCD_gFillRectangle(x + 3, y + 3, i * size, j * size, textColor);
}
}
}
Expand Down
50 changes: 48 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,53 @@
int main()
{
// textdemo();
graphicsdemo();
// graphicsdemo();
GEdemo();
}

void GEdemoMenu()
{
LCD_pixel colors[21] = {
LCD_DARK_GREY,
LCD_GREY,
LCD_LIGHT_GREY,
LCD_WHITE,
LCD_RED,
LCD_GREEN,
LCD_BLUE,
LCD_YELLOW,
LCD_MAGENTA,
LCD_CYAN,
LCD_DARK_RED,
LCD_DARK_GREEN,
LCD_DARK_BLUE,
LCD_DARK_YELLOW,
LCD_PURPLE,
LCD_TEAL,
LCD_BROWN,
LCD_PINK,
LCD_TURQUOISE,
LCD_ORANGE,
LCD_GOLD
};
static uint8_t color = 0;

LCD_SetBGColor(colors[color]);
LCD_gString(0, 0, "Inside menu loop", LCD_GREEN);
LCD_gChar(0, 8, color, LCD_MAGENTA, colors[color], 2);

color++;
if (color == 21) color = 0;
delay(250);
}

int GEdemo()
{
GE_Setup();

GE_SetMainMenu(GEdemoMenu);

GE_Loop();
}

int textdemo()
Expand Down Expand Up @@ -83,7 +129,7 @@ int textdemo()
x += 6;
if (y - 8 >= LCD_HEIGHT)
y = 0;
LCD_gChar(x + 3, y + 3, c, colors[color], LCD_BLACK, 1);
LCD_gChar(x, y, c, colors[color], LCD_BLACK, 1);
}
}

Expand Down
2 changes: 2 additions & 0 deletions tiva-gc-inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#define ON 1
#define OFF 0

#define NULL ((void *)0)

typedef struct point
{
int32_t x, y;
Expand Down
24 changes: 24 additions & 0 deletions tiva-gc.uvoptx
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,30 @@
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>1</GroupNumber>
<FileNumber>13</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>.\tiva-ge.c</PathWithFileName>
<FilenameWithoutPath>tiva-ge.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>1</GroupNumber>
<FileNumber>14</FileNumber>
<FileType>5</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>.\tiva-ge.h</PathWithFileName>
<FilenameWithoutPath>tiva-ge.h</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
</Group>

<Group>
Expand Down
10 changes: 10 additions & 0 deletions tiva-gc.uvprojx
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,16 @@
<FileType>5</FileType>
<FilePath>.\tiva-gc-inc.h</FilePath>
</File>
<File>
<FileName>tiva-ge.c</FileName>
<FileType>1</FileType>
<FilePath>.\tiva-ge.c</FilePath>
</File>
<File>
<FileName>tiva-ge.h</FileName>
<FileType>5</FileType>
<FilePath>.\tiva-ge.h</FilePath>
</File>
</Files>
</Group>
<Group>
Expand Down
38 changes: 34 additions & 4 deletions tiva-ge.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
GE_Button SW1 = {0}, SW2 = {0}, SEL = {0};
GE_Joystick JS = {0};

static void (*_mainMenu)(void) = NULL;
static int (*_update)(float elapsedTime) = NULL;

void GE_Input(void);

// Performs input and screen initializations and clears screen to black.
Expand Down Expand Up @@ -44,9 +47,9 @@ void GE_Input(void)
// it is the function responsible for setting which game will be run.
// Param:
// func: pointer to void function
void GE_SetMainMenu(void (*func))
void GE_SetMainMenu(void (*func)(void))
{

_mainMenu = func;
}

// Set update function/game
Expand All @@ -59,11 +62,38 @@ void GE_SetMainMenu(void (*func))
// func: pointer to function taking one float parameter and returning int
void GE_SetUpdate(int (*func)(float elapsed_time))
{

_update = func;
}

// Runs the main gameloop
// Runs the main menu and gameloop
void GE_Loop(void)
{
LCD_SetBGColor(LCD_BLACK);
LCD_gClear();

// Checks for menus or games set
if (!_mainMenu && !_update)
{
LCD_gString(0, 0, "E: No main menu", LCD_RED);
LCD_gString(3, 1, "function set!", LCD_RED);
while (1);
}

// Main program loop
while (1)
{
// Menu
while (!_update)
{
_mainMenu();
}

// Gameloop
while (_update)
{
if (!_update(0.0f))
_update = NULL;
}
}

}
2 changes: 1 addition & 1 deletion tiva-ge.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void GE_Setup(void);
// it is the function responsible for setting which game will be run.
// Param:
// func: pointer to void function
void GE_SetMainMenu(void (*func));
void GE_SetMainMenu(void (*func)(void));

// Set update function/game
// The logic for the game must be in a function to be looped by the game engine.
Expand Down

0 comments on commit eefe3ec

Please sign in to comment.