Added init state to game, where the welcome screen is painted.

This commit is contained in:
T-moe
2016-01-29 16:18:46 +01:00
parent 424bc54d55
commit 9c9b52b304
5 changed files with 28 additions and 4 deletions

View File

@@ -9,7 +9,7 @@
uint16_t bitmap_draw( unsigned int width, unsigned int height,
unsigned int bytes_per_pixel,
unsigned char *pixel_data){
const unsigned char *pixel_data){
if(bytes_per_pixel != BYTES_PER_PIXEL){
return -1;

View File

@@ -12,6 +12,6 @@
* @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 */

View File

@@ -5,6 +5,9 @@
#include "game.h"
#include "io.h"
#include "draw.h"
#include "bitmap.h" //generated by gimp
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);
// struct init
game->state=prestart;
game->state=init;
game->ticks_per_pixel = SPEED_SLOW;
game->ticks_leftover = 0;
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 [] = {
"Config Instructions:",
"* 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
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);
case running:
return game_step_running(game,delta_time);

View File

@@ -57,6 +57,7 @@ typedef struct game_s{
player_t player[PLAYER_COUNT];
enum{ // Current state of the game
init,
prestart,
running,
ended