mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2025-02-08 06:06:43 +01:00
add level gamestate
This commit is contained in:
parent
a715d37be9
commit
add0c3d3ba
6 changed files with 99 additions and 1 deletions
2
Makefile
2
Makefile
|
@ -6,7 +6,7 @@ SRCDIR=src
|
|||
ODIR=obj
|
||||
LIBS=-lallegro -lallegro_audio-debug -lallegro_acodec-debug -lallegro_image-debug -lallegro_font-debug -lallegro_ttf-debug -lm
|
||||
|
||||
_OBJ = main.o about.o intro.o loading.o map.o menu.o
|
||||
_OBJ = main.o about.o intro.o loading.o map.o menu.o level.o
|
||||
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
|
||||
|
||||
OUTPUTDIR = bin
|
||||
|
|
62
src/level.c
Normal file
62
src/level.c
Normal file
|
@ -0,0 +1,62 @@
|
|||
#include <allegro5/allegro.h>
|
||||
#include <allegro5/allegro_font.h>
|
||||
#include <stdio.h>
|
||||
#include "level.h"
|
||||
|
||||
void Level_Draw(struct Game *game) {
|
||||
al_draw_scaled_bitmap(game->level.image,0,0,al_get_bitmap_width(game->level.image),al_get_bitmap_height(game->level.image),0,0,al_get_display_width(game->display), al_get_display_height(game->display),0);
|
||||
al_draw_textf(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, "Level %d: Not implemented yet!", game->level.current_level);
|
||||
}
|
||||
|
||||
void Level_Load(struct Game *game) {
|
||||
al_play_sample(game->level.sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_LOOP, NULL);
|
||||
ALLEGRO_EVENT ev;
|
||||
for(int fadeloop=0; fadeloop<256; fadeloop+=10){
|
||||
al_wait_for_event(game->event_queue, &ev);
|
||||
al_draw_tinted_bitmap(game->level.fade_bitmap,al_map_rgba_f(fadeloop/255.0,fadeloop/255.0,fadeloop/255.0,1),0,0,0);
|
||||
DrawConsole(game);
|
||||
al_flip_display();
|
||||
}
|
||||
al_destroy_bitmap(game->level.fade_bitmap);
|
||||
Level_Draw(game);
|
||||
}
|
||||
int Level_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
|
||||
//if (ev->keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
|
||||
UnloadGameState(game);
|
||||
game->gamestate = GAMESTATE_LOADING;
|
||||
game->loadstate = GAMESTATE_MENU;
|
||||
return 0;
|
||||
//}
|
||||
}
|
||||
void Level_Preload(struct Game *game) {
|
||||
PrintConsole(game, "Initializing level %d...", game->level.current_level);
|
||||
game->level.image = al_load_bitmap( "data/table.png" );
|
||||
game->level.sample = al_load_sample( "data/about.flac" );
|
||||
|
||||
if (!game->level.sample){
|
||||
fprintf(stderr, "Audio clip sample not loaded!\n" );
|
||||
exit(-1);
|
||||
}
|
||||
game->level.fade_bitmap = al_create_bitmap(al_get_display_width(game->display), al_get_display_height(game->display));
|
||||
al_set_target_bitmap(game->level.fade_bitmap);
|
||||
al_draw_scaled_bitmap(game->level.image,0,0,al_get_bitmap_width(game->level.image),al_get_bitmap_height(game->level.image),0,0,al_get_display_width(game->display), al_get_display_height(game->display),0);
|
||||
al_draw_textf(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, "Level %d: Not implemented yet!", game->level.current_level);
|
||||
al_set_target_bitmap(al_get_backbuffer(game->display));
|
||||
}
|
||||
void Level_Unload(struct Game *game) {
|
||||
ALLEGRO_EVENT ev;
|
||||
game->level.fade_bitmap = al_create_bitmap(al_get_display_width(game->display), al_get_display_height(game->display));
|
||||
al_set_target_bitmap(game->level.fade_bitmap);
|
||||
al_draw_scaled_bitmap(game->level.image,0,0,al_get_bitmap_width(game->level.image),al_get_bitmap_height(game->level.image),0,0,al_get_display_width(game->display), al_get_display_height(game->display),0);
|
||||
al_draw_textf(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, "Level %d: Not implemented yet!", game->level.current_level);
|
||||
al_set_target_bitmap(al_get_backbuffer(game->display));
|
||||
for(int fadeloop=255; fadeloop>=0; fadeloop-=10){
|
||||
al_wait_for_event(game->event_queue, &ev);
|
||||
al_draw_tinted_bitmap(game->level.fade_bitmap, al_map_rgba_f(fadeloop/255.0,fadeloop/255.0,fadeloop/255.0,1), 0, 0, 0);
|
||||
DrawConsole(game);
|
||||
al_flip_display();
|
||||
}
|
||||
al_destroy_bitmap(game->level.image);
|
||||
al_destroy_bitmap(game->level.fade_bitmap);
|
||||
al_destroy_sample(game->level.sample);
|
||||
}
|
7
src/level.h
Normal file
7
src/level.h
Normal file
|
@ -0,0 +1,7 @@
|
|||
#include "main.h"
|
||||
|
||||
void Level_Draw(struct Game *game);
|
||||
void Level_Preload(struct Game *game);
|
||||
void Level_Unload(struct Game *game);
|
||||
void Level_Load(struct Game *game);
|
||||
int Level_Keydown(struct Game *game, ALLEGRO_EVENT *ev);
|
21
src/main.c
21
src/main.c
|
@ -5,6 +5,7 @@
|
|||
#include "about.h"
|
||||
#include "intro.h"
|
||||
#include "map.h"
|
||||
#include "level.h"
|
||||
|
||||
float FPS = 60;
|
||||
int DISPLAY_WIDTH = 800;
|
||||
|
@ -66,6 +67,12 @@ void PreloadGameState(struct Game *game) {
|
|||
DrawConsole(game);
|
||||
al_flip_display();
|
||||
Map_Preload(game);
|
||||
}
|
||||
else if (game->loadstate==GAMESTATE_LEVEL) {
|
||||
PrintConsole(game, "Preload GAMESTATE_LEVEL...");
|
||||
DrawConsole(game);
|
||||
al_flip_display();
|
||||
Level_Preload(game);
|
||||
} else {
|
||||
PrintConsole(game, "ERROR: Attempted to preload unknown gamestate %d!", game->loadstate);
|
||||
}
|
||||
|
@ -92,6 +99,10 @@ void UnloadGameState(struct Game *game) {
|
|||
else if (game->gamestate==GAMESTATE_MAP) {
|
||||
PrintConsole(game, "Unload GAMESTATE_MAP...");
|
||||
Map_Unload(game);
|
||||
}
|
||||
else if (game->gamestate==GAMESTATE_LEVEL) {
|
||||
PrintConsole(game, "Unload GAMESTATE_LEVEL...");
|
||||
Level_Unload(game);
|
||||
} else {
|
||||
PrintConsole(game, "ERROR: Attempted to unload unknown gamestate %d!", game->gamestate);
|
||||
}
|
||||
|
@ -118,6 +129,10 @@ void LoadGameState(struct Game *game) {
|
|||
else if (game->loadstate==GAMESTATE_MAP) {
|
||||
PrintConsole(game, "Load GAMESTATE_MAP...");
|
||||
Map_Load(game);
|
||||
}
|
||||
else if (game->loadstate==GAMESTATE_LEVEL) {
|
||||
PrintConsole(game, "Load GAMESTATE_LEVEL...");
|
||||
Level_Load(game);
|
||||
} else {
|
||||
PrintConsole(game, "ERROR: Attempted to load unknown gamestate %d!", game->loadstate);
|
||||
}
|
||||
|
@ -247,6 +262,9 @@ int main(int argc, char **argv){
|
|||
else if (game.gamestate==GAMESTATE_MAP) {
|
||||
if (Map_Keydown(&game, &ev)) break;
|
||||
}
|
||||
else if (game.gamestate==GAMESTATE_LEVEL) {
|
||||
if (Level_Keydown(&game, &ev)) break;
|
||||
}
|
||||
else {
|
||||
game.showconsole = true;
|
||||
PrintConsole(&game, "ERROR: Keystroke in unknown (%d) gamestate! (5 sec sleep)", game.gamestate);
|
||||
|
@ -275,6 +293,9 @@ int main(int argc, char **argv){
|
|||
}
|
||||
else if (game.gamestate==GAMESTATE_MAP) {
|
||||
Map_Draw(&game);
|
||||
}
|
||||
else if (game.gamestate==GAMESTATE_LEVEL) {
|
||||
Level_Draw(&game);
|
||||
}
|
||||
else {
|
||||
game.showconsole = true;
|
||||
|
|
|
@ -17,6 +17,12 @@ enum gamestate_enum {
|
|||
GAMESTATE_LEVEL
|
||||
};
|
||||
|
||||
struct Level {
|
||||
ALLEGRO_BITMAP *fade_bitmap, *image;
|
||||
ALLEGRO_SAMPLE *sample;
|
||||
int current_level;
|
||||
};
|
||||
|
||||
struct Menu {
|
||||
ALLEGRO_BITMAP *menu_bitmap, *menu_fade_bitmap, *image;
|
||||
ALLEGRO_BITMAP *cloud_bitmap, *cloud, *cloud2_bitmap, *cloud2, *pie, *pie_bitmap;
|
||||
|
@ -69,6 +75,7 @@ struct Game {
|
|||
struct Intro intro;
|
||||
struct About about;
|
||||
struct Map map;
|
||||
struct Level level;
|
||||
};
|
||||
|
||||
void PreloadGameState(struct Game *game);
|
||||
|
|
|
@ -59,6 +59,7 @@ int Map_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
|
|||
al_play_sample(game->map.click_sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL);
|
||||
} else if (ev->keyboard.keycode==ALLEGRO_KEY_ENTER) {
|
||||
PrintConsole(game, "Selecting level %d...", game->map.selected);
|
||||
game->level.current_level = game->map.selected;
|
||||
UnloadGameState(game);
|
||||
game->gamestate = GAMESTATE_LOADING;
|
||||
game->loadstate = GAMESTATE_LEVEL;
|
||||
|
|
Loading…
Reference in a new issue