add about state (with "not implemented yet" text :D)

This commit is contained in:
Sebastian Krzyszkowiak 2012-02-17 00:19:21 +01:00
parent 49049b3a85
commit 234d9a68e2
8 changed files with 61 additions and 4 deletions

18
about.c Normal file
View file

@ -0,0 +1,18 @@
#include <allegro5/allegro.h>
#include <allegro5/allegro_font.h>
#include "about.h"
void About_Draw(struct Game *game) {
al_clear_to_color(al_map_rgb(0,0,0));
al_draw_text(game->font, al_map_rgb(255,255,255), al_get_display_width(game->display)/2, al_get_display_height(game->display)/2, ALLEGRO_ALIGN_CENTRE, "Not implemented yet!");
al_flip_display();
al_rest(5.0);
UnloadGameState(game);
game->gamestate = GAMESTATE_LOADING;
game->loadstate = GAMESTATE_MENU;
}
void About_Load(struct Game *game) {}
int About_Keydown(struct Game *game, ALLEGRO_EVENT *ev) { return 0; }
void About_Preload(struct Game *game) {}
void About_Unload(struct Game *game) {}

7
about.h Normal file
View file

@ -0,0 +1,7 @@
#include "main.h"
void About_Draw(struct Game *game);
void About_Preload(struct Game *game);
void About_Unload(struct Game *game);
void About_Load(struct Game *game);
int About_Keydown(struct Game *game, ALLEGRO_EVENT *ev);

View file

@ -37,4 +37,6 @@ void Loading_Load(struct Game *game) {
al_destroy_bitmap(game->loading.image);
}
int Loading_Keydown(struct Game *game, ALLEGRO_EVENT *ev) { return 0; }
int Loading_Keydown(struct Game *game, ALLEGRO_EVENT *ev) { return 0; }
void Loading_Preload(struct Game *game) {}
void Loading_Unload(struct Game *game) {}

View file

@ -1,5 +1,7 @@
#include "main.h"
void Loading_Draw(struct Game *game);
void Loading_Preload(struct Game *game);
void Loading_Unload(struct Game *game);
void Loading_Load(struct Game *game);
int Loading_Keydown(struct Game *game, ALLEGRO_EVENT *ev);

22
main.c
View file

@ -1,6 +1,7 @@
#include <stdio.h>
#include "menu.h"
#include "loading.h"
#include "about.h"
float FPS = 60;
int DISPLAY_WIDTH = 800;
@ -11,12 +12,24 @@ void PreloadGameState(struct Game *game) {
if (game->loadstate==GAMESTATE_MENU) {
Menu_Preload(game);
}
else if (game->loadstate==GAMESTATE_LOADING) {
Loading_Preload(game);
}
else if (game->loadstate==GAMESTATE_ABOUT) {
About_Preload(game);
}
}
void UnloadGameState(struct Game *game) {
if (game->gamestate==GAMESTATE_MENU) {
Menu_Unload(game);
}
else if (game->gamestate==GAMESTATE_LOADING) {
Loading_Unload(game);
}
else if (game->gamestate==GAMESTATE_ABOUT) {
About_Unload(game);
}
}
void LoadGameState(struct Game *game) {
@ -26,6 +39,9 @@ void LoadGameState(struct Game *game) {
else if (game->loadstate==GAMESTATE_LOADING) {
Loading_Load(game);
}
else if (game->loadstate==GAMESTATE_ABOUT) {
About_Load(game);
}
game->gamestate = game->loadstate;
game->loadstate = -1;
}
@ -132,6 +148,9 @@ int main(int argc, char **argv){
else if (game.gamestate==GAMESTATE_MENU) {
if (Menu_Keydown(&game, &ev)) break;
}
else if (game.gamestate==GAMESTATE_ABOUT) {
if (About_Keydown(&game, &ev)) break;
}
}
if(redraw && al_is_event_queue_empty(game.event_queue)) {
@ -142,6 +161,9 @@ int main(int argc, char **argv){
else if (game.gamestate==GAMESTATE_MENU) {
Menu_Draw(&game);
}
else if (game.gamestate==GAMESTATE_ABOUT) {
About_Draw(&game);
}
}
}

4
main.h
View file

@ -10,7 +10,9 @@
enum gamestate_enum {
GAMESTATE_LOADING,
GAMESTATE_MENU
GAMESTATE_MENU,
GAMESTATE_ABOUT,
GAMESTATE_INTRO
};
struct Menu {

2
make
View file

@ -1,2 +1,2 @@
#!/bin/sh
gcc main.c menu.c loading.c -o superderpy -lallegro -lallegro_audio -lallegro_acodec -lallegro_image -lallegro_font -lallegro_ttf -std=gnu99 -g && ./superderpy
gcc main.c about.c menu.c loading.c -o superderpy -lallegro -lallegro_audio -lallegro_acodec -lallegro_image -lallegro_font -lallegro_ttf -std=gnu99 -g && ./superderpy

6
menu.c
View file

@ -189,10 +189,14 @@ int Menu_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
game->menu.selected++;
} else if ((!game->menu.options) && (((ev->keyboard.keycode==ALLEGRO_KEY_ENTER) && (game->menu.selected==3)) || (ev->keyboard.keycode == ALLEGRO_KEY_ESCAPE))) {
return 1;
} else if ((ev->keyboard.keycode==ALLEGRO_KEY_ENTER) && (!game->menu.options) && (game->menu.selected!=1)) {
} else if ((ev->keyboard.keycode==ALLEGRO_KEY_ENTER) && (!game->menu.options) && (game->menu.selected==0)) {
UnloadGameState(game);
game->gamestate = GAMESTATE_LOADING;
game->loadstate = GAMESTATE_MENU;
} else if ((ev->keyboard.keycode==ALLEGRO_KEY_ENTER) && (!game->menu.options) && (game->menu.selected==2)) {
UnloadGameState(game);
game->gamestate = GAMESTATE_LOADING;
game->loadstate = GAMESTATE_ABOUT;
} else if (((ev->keyboard.keycode==ALLEGRO_KEY_ENTER) && (!game->menu.options) && (game->menu.selected==1)) || ((game->menu.options) && ((ev->keyboard.keycode == ALLEGRO_KEY_ESCAPE)) || ((ev->keyboard.keycode==ALLEGRO_KEY_ENTER) && (game->menu.selected==3)))) {
game->menu.options=!game->menu.options;
game->menu.selected=0;