Added init state to game, where the welcome screen is painted.
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
uint16_t bitmap_draw( unsigned int width, unsigned int height,
|
uint16_t bitmap_draw( unsigned int width, unsigned int height,
|
||||||
unsigned int bytes_per_pixel,
|
unsigned int bytes_per_pixel,
|
||||||
unsigned char *pixel_data){
|
const unsigned char *pixel_data){
|
||||||
|
|
||||||
if(bytes_per_pixel != BYTES_PER_PIXEL){
|
if(bytes_per_pixel != BYTES_PER_PIXEL){
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@@ -12,6 +12,6 @@
|
|||||||
* @return -1 if error 0 else
|
* @return -1 if error 0 else
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
uint16_t bitmap_draw( unsigned int width, unsigned int height, unsigned int bytes_per_pixel, unsigned char *pixel_data);
|
uint16_t bitmap_draw(unsigned int width, unsigned int height, unsigned int bytes_per_pixel, const unsigned char *pixel_data);
|
||||||
|
|
||||||
#endif /* DRAW_H */
|
#endif /* DRAW_H */
|
||||||
|
|||||||
27
src/game.c
27
src/game.c
@@ -5,6 +5,9 @@
|
|||||||
|
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
|
#include "draw.h"
|
||||||
|
#include "bitmap.h" //generated by gimp
|
||||||
|
|
||||||
|
|
||||||
void game_init(game_t* game, uint16_t ticks_per_sec) {
|
void game_init(game_t* game, uint16_t ticks_per_sec) {
|
||||||
|
|
||||||
@@ -16,7 +19,7 @@ void game_init(game_t* game, uint16_t ticks_per_sec) {
|
|||||||
LCD_Clear(GUI_COLOR_BLACK);
|
LCD_Clear(GUI_COLOR_BLACK);
|
||||||
|
|
||||||
// struct init
|
// struct init
|
||||||
game->state=prestart;
|
game->state=init;
|
||||||
game->ticks_per_pixel = SPEED_SLOW;
|
game->ticks_per_pixel = SPEED_SLOW;
|
||||||
game->ticks_leftover = 0;
|
game->ticks_leftover = 0;
|
||||||
game->ticks_per_sec = ticks_per_sec;
|
game->ticks_per_sec = ticks_per_sec;
|
||||||
@@ -241,6 +244,24 @@ void game_get_color(uint16_t confbits, uint16_t* player1_color, uint16_t* player
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool game_step_init(game_t* game) {
|
||||||
|
|
||||||
|
//Draw welcome bitmap
|
||||||
|
bitmap_draw(gimp_image.width,gimp_image.height,gimp_image.bytes_per_pixel,gimp_image.pixel_data);
|
||||||
|
|
||||||
|
//Wait on player to press the start button
|
||||||
|
while(!io_button_has_edge(BTN_START));
|
||||||
|
|
||||||
|
//Change game state
|
||||||
|
game->state=prestart;
|
||||||
|
|
||||||
|
LCD_Clear(GUI_COLOR_BLACK); // Clear the background
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static const char* texts [] = {
|
static const char* texts [] = {
|
||||||
"Config Instructions:",
|
"Config Instructions:",
|
||||||
"* Change the player colors using the switches S7-S0",
|
"* Change the player colors using the switches S7-S0",
|
||||||
@@ -467,7 +488,9 @@ bool game_step_ended(game_t* game) {
|
|||||||
bool game_step(game_t* game, uint64_t delta_time) { // Calculate the next game step
|
bool game_step(game_t* game, uint64_t delta_time) { // Calculate the next game step
|
||||||
|
|
||||||
switch(game->state) {
|
switch(game->state) {
|
||||||
case prestart: // If the game is in prestart state
|
case init:
|
||||||
|
return game_step_init(game);
|
||||||
|
case prestart:
|
||||||
return game_step_prestart(game);
|
return game_step_prestart(game);
|
||||||
case running:
|
case running:
|
||||||
return game_step_running(game,delta_time);
|
return game_step_running(game,delta_time);
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ typedef struct game_s{
|
|||||||
player_t player[PLAYER_COUNT];
|
player_t player[PLAYER_COUNT];
|
||||||
|
|
||||||
enum{ // Current state of the game
|
enum{ // Current state of the game
|
||||||
|
init,
|
||||||
prestart,
|
prestart,
|
||||||
running,
|
running,
|
||||||
ended
|
ended
|
||||||
|
|||||||
Reference in New Issue
Block a user