From 58dd22abfb2ddb6a66bd664a421c6a4022f79304 Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Fri, 17 Feb 2012 20:32:58 +0100 Subject: [PATCH] add intro state --- intro.c | 19 +++++++++++++++++++ intro.h | 7 +++++++ main.c | 44 +++++++++++++++++++++++++++++++++++--------- make | 2 +- menu.c | 10 +++++----- 5 files changed, 67 insertions(+), 15 deletions(-) create mode 100644 intro.c create mode 100644 intro.h diff --git a/intro.c b/intro.c new file mode 100644 index 0000000..5925271 --- /dev/null +++ b/intro.c @@ -0,0 +1,19 @@ +#include +#include +#include "intro.h" + +void Intro_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!"); + DrawConsole(game); + al_flip_display(); + al_rest(5.0); + UnloadGameState(game); + game->gamestate = GAMESTATE_LOADING; + game->loadstate = GAMESTATE_MENU; +} + +void Intro_Load(struct Game *game) {} +int Intro_Keydown(struct Game *game, ALLEGRO_EVENT *ev) { return 0; } +void Intro_Preload(struct Game *game) {} +void Intro_Unload(struct Game *game) {} diff --git a/intro.h b/intro.h new file mode 100644 index 0000000..e29603b --- /dev/null +++ b/intro.h @@ -0,0 +1,7 @@ +#include "main.h" + +void Intro_Draw(struct Game *game); +void Intro_Preload(struct Game *game); +void Intro_Unload(struct Game *game); +void Intro_Load(struct Game *game); +int Intro_Keydown(struct Game *game, ALLEGRO_EVENT *ev); \ No newline at end of file diff --git a/main.c b/main.c index ca34432..c657e7b 100644 --- a/main.c +++ b/main.c @@ -2,6 +2,7 @@ #include "menu.h" #include "loading.h" #include "about.h" +#include "intro.h" float FPS = 60; int DISPLAY_WIDTH = 800; @@ -31,54 +32,66 @@ void PreloadGameState(struct Game *game) { if (game->loadstate==GAMESTATE_MENU) { PrintConsole(game, "Preload GAMESTATE_MENU..."); Menu_Preload(game); - PrintConsole(game, "finished"); } else if (game->loadstate==GAMESTATE_LOADING) { PrintConsole(game, "Preload GAMESTATE_LOADING..."); Loading_Preload(game); - PrintConsole(game, "finished"); } else if (game->loadstate==GAMESTATE_ABOUT) { PrintConsole(game, "Preload GAMESTATE_ABOUT..."); About_Preload(game); - PrintConsole(game, "finished"); } + else if (game->loadstate==GAMESTATE_INTRO) { + PrintConsole(game, "Preload GAMESTATE_INTRO..."); + Intro_Preload(game); + } else { + PrintConsole(game, "ERROR: Attempted to preload unknown gamestate!"); + } + PrintConsole(game, "finished"); } void UnloadGameState(struct Game *game) { if (game->gamestate==GAMESTATE_MENU) { PrintConsole(game, "Unload GAMESTATE_MENU..."); Menu_Unload(game); - PrintConsole(game, "finished"); } else if (game->gamestate==GAMESTATE_LOADING) { PrintConsole(game, "Unload GAMESTATE_LOADING..."); Loading_Unload(game); - PrintConsole(game, "finished"); } else if (game->gamestate==GAMESTATE_ABOUT) { PrintConsole(game, "Unload GAMESTATE_ABOUT..."); About_Unload(game); - PrintConsole(game, "finished"); } + else if (game->gamestate==GAMESTATE_INTRO) { + PrintConsole(game, "Unload GAMESTATE_INTRO..."); + Intro_Unload(game); + } else { + PrintConsole(game, "ERROR: Attempted to unload unknown gamestate!"); + } + PrintConsole(game, "finished"); } void LoadGameState(struct Game *game) { if (game->loadstate==GAMESTATE_MENU) { PrintConsole(game, "Load GAMESTATE_MENU..."); Menu_Load(game); - PrintConsole(game, "finished"); } else if (game->loadstate==GAMESTATE_LOADING) { PrintConsole(game, "Load GAMESTATE_LOADING..."); Loading_Load(game); - PrintConsole(game, "finished"); } else if (game->loadstate==GAMESTATE_ABOUT) { PrintConsole(game, "Load GAMESTATE_ABOUT..."); About_Load(game); - PrintConsole(game, "finished"); } + else if (game->loadstate==GAMESTATE_INTRO) { + PrintConsole(game, "Load GAMESTATE_INTRO..."); + Intro_Load(game); + } else { + PrintConsole(game, "ERROR: Attempted to load unknown gamestate!"); + } + PrintConsole(game, "finished"); game->gamestate = game->loadstate; game->loadstate = -1; } @@ -210,6 +223,19 @@ int main(int argc, char **argv){ } else if (game.gamestate==GAMESTATE_ABOUT) { About_Draw(&game); + } + else if (game.gamestate==GAMESTATE_INTRO) { + Intro_Draw(&game); + } + else { + game.showconsole = true; + PrintConsole(&game, "ERROR: Unknown gamestate reached! (5 sec sleep)"); + DrawConsole(&game); + al_flip_display(); + al_rest(5.0); + PrintConsole(&game, "Returning to menu..."); + game.gamestate = GAMESTATE_LOADING; + game.loadstate = GAMESTATE_MENU; } DrawConsole(&game); al_flip_display(); diff --git a/make b/make index 3264045..a1c2e70 100755 --- a/make +++ b/make @@ -1,2 +1,2 @@ #!/bin/sh -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 +gcc loading.c main.c menu.c about.c intro.c -o superderpy -lallegro -lallegro_audio -lallegro_acodec -lallegro_image -lallegro_font -lallegro_ttf -std=gnu99 -g && ./superderpy diff --git a/menu.c b/menu.c index d4c9024..4e3fb25 100644 --- a/menu.c +++ b/menu.c @@ -10,12 +10,12 @@ void Menu_Draw(struct Game *game) { //game->menu.pinkcloud_bitmap = al_create_bitmap(al_get_display_width(game->display)*0.33125, al_get_display_height(game->display)); //*0.8122); al_set_target_bitmap(game->menu.pinkcloud_bitmap); al_clear_to_color(al_map_rgba(0,0,0,0)); - float x = 2*(rand() / (float)RAND_MAX); + float x = 1.5;//*(rand() / (float)RAND_MAX); int minus; if (game->menu.cloud_position>0) minus=1; else minus=-1; - al_draw_scaled_bitmap(game->menu.rain, 0, 0, al_get_bitmap_width(game->menu.rain), al_get_bitmap_height(game->menu.rain), fmod(minus*game->menu.cloud_position,3)*x*5+al_get_bitmap_width(game->menu.pinkcloud_bitmap)/2.7, al_get_bitmap_height(game->menu.pinkcloud_bitmap)*(0.88+(fmod(-2*(game->menu.cloud_position+80), 3))/10.0), al_get_bitmap_width(game->menu.pinkcloud_bitmap)*0.5, al_get_bitmap_height(game->menu.pinkcloud_bitmap)*0.1, 0); - al_draw_scaled_bitmap(game->menu.rain, 0, 0, al_get_bitmap_width(game->menu.rain), al_get_bitmap_height(game->menu.rain), fmod(minus*game->menu.cloud_position,3)*x*3+al_get_bitmap_width(game->menu.pinkcloud_bitmap)/3.1, al_get_bitmap_height(game->menu.pinkcloud_bitmap)*(0.78+(fmod(-3*(game->menu.cloud_position+80), 2))/10.0), al_get_bitmap_width(game->menu.pinkcloud_bitmap)*0.5, al_get_bitmap_height(game->menu.pinkcloud_bitmap)*0.1, 0); - al_draw_scaled_bitmap(game->menu.rain, 0, 0, al_get_bitmap_width(game->menu.rain), al_get_bitmap_height(game->menu.rain), fmod(minus*game->menu.cloud_position,3)*x*6+al_get_bitmap_width(game->menu.pinkcloud_bitmap)/2.1, al_get_bitmap_height(game->menu.pinkcloud_bitmap)*(0.87+(fmod(-5*(game->menu.cloud_position+80), 4))/12.0), al_get_bitmap_width(game->menu.pinkcloud_bitmap)*0.4, al_get_bitmap_height(game->menu.pinkcloud_bitmap)*0.08, 0); + al_draw_scaled_bitmap(game->menu.rain, 0, 0, al_get_bitmap_width(game->menu.rain), al_get_bitmap_height(game->menu.rain), fmod(minus*game->menu.cloud_position,3)*x*5+al_get_bitmap_width(game->menu.pinkcloud_bitmap)/2.7, al_get_bitmap_height(game->menu.pinkcloud_bitmap)*(0.88+(fmod(-2*(game->menu.cloud_position+80), 6))/20.0), al_get_bitmap_width(game->menu.pinkcloud_bitmap)*0.5, al_get_bitmap_height(game->menu.pinkcloud_bitmap)*0.1, 0); + al_draw_scaled_bitmap(game->menu.rain, 0, 0, al_get_bitmap_width(game->menu.rain), al_get_bitmap_height(game->menu.rain), fmod(minus*game->menu.cloud_position,3)*x*3+al_get_bitmap_width(game->menu.pinkcloud_bitmap)/3.1, al_get_bitmap_height(game->menu.pinkcloud_bitmap)*(0.78+(fmod(-3*(game->menu.cloud_position+80), 4))/20.0), al_get_bitmap_width(game->menu.pinkcloud_bitmap)*0.5, al_get_bitmap_height(game->menu.pinkcloud_bitmap)*0.1, 0); + al_draw_scaled_bitmap(game->menu.rain, 0, 0, al_get_bitmap_width(game->menu.rain), al_get_bitmap_height(game->menu.rain), fmod(minus*game->menu.cloud_position,3)*x*6+al_get_bitmap_width(game->menu.pinkcloud_bitmap)/2.1, al_get_bitmap_height(game->menu.pinkcloud_bitmap)*(0.87+(fmod(-5*(game->menu.cloud_position+80), 8))/24.0), al_get_bitmap_width(game->menu.pinkcloud_bitmap)*0.4, al_get_bitmap_height(game->menu.pinkcloud_bitmap)*0.08, 0); al_draw_scaled_bitmap(game->menu.pinkcloud,0, 0, al_get_bitmap_width(game->menu.pinkcloud), al_get_bitmap_height(game->menu.pinkcloud), 0, 0, al_get_bitmap_width(game->menu.pinkcloud_bitmap), al_get_bitmap_height(game->menu.pinkcloud_bitmap)*0.8122,0); al_set_target_bitmap(al_get_backbuffer(game->display)); @@ -193,7 +193,7 @@ int Menu_Keydown(struct Game *game, ALLEGRO_EVENT *ev) { } 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; + game->loadstate = GAMESTATE_INTRO; } else if ((ev->keyboard.keycode==ALLEGRO_KEY_ENTER) && (!game->menu.options) && (game->menu.selected==2)) { UnloadGameState(game); game->gamestate = GAMESTATE_LOADING;