mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2025-02-01 02:56:43 +01:00
giant refactoring... and giant breakage :P
This commit is contained in:
parent
9a43132af3
commit
3ba92508e2
14 changed files with 195 additions and 171 deletions
|
@ -23,7 +23,7 @@ if(MINGW)
|
|||
set(LINK_FLAGS -Wl,-subsystem,windows)
|
||||
endif(MINGW)
|
||||
|
||||
SET(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib/superderpy:\$ORIGIN/gamestates:\$ORIGIN:\$ORIGIN/../lib")
|
||||
SET(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib/superderpy:\$ORIGIN/gamestates:\$ORIGIN/levels:\$ORIGIN:\$ORIGIN/../lib")
|
||||
|
||||
#IF(${PACKAGE_BUILD})
|
||||
# SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
|
||||
|
@ -52,6 +52,7 @@ if(ALLEGRO5_MAIN_FOUND)
|
|||
endif(ALLEGRO5_MAIN_FOUND)
|
||||
|
||||
add_subdirectory(gamestates)
|
||||
add_subdirectory(levels)
|
||||
|
||||
install(TARGETS ${EXECUTABLE} DESTINATION ${BIN_INSTALL_DIR})
|
||||
install(TARGETS "libsuperderpy" DESTINATION ${LIB_INSTALL_DIR})
|
||||
|
|
|
@ -14,12 +14,7 @@ GAMESTATE("menu")
|
|||
GAMESTATE("disclaimer")
|
||||
GAMESTATE("intro")
|
||||
GAMESTATE("map")
|
||||
#GAMESTATE("level1")
|
||||
#GAMESTATE("level2")
|
||||
#GAMESTATE("level3")
|
||||
#GAMESTATE("level4")
|
||||
#GAMESTATE("level5")
|
||||
#GAMESTATE("level6")
|
||||
GAMESTATE("about")
|
||||
#GAMESTATE("pause")
|
||||
|
||||
GAMESTATE("loading")
|
||||
|
|
|
@ -18,77 +18,55 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include "../levels/level1.h"
|
||||
#include "../levels/level2.h"
|
||||
#include "../levels/level3.h"
|
||||
#include "../levels/level4.h"
|
||||
#include "../levels/level5.h"
|
||||
#include "../levels/level6.h"
|
||||
#include "../config.h"
|
||||
#include "pause.h"
|
||||
#include "level.h"
|
||||
#include "../utils.h"
|
||||
#include "../timeline.h"
|
||||
#include "level.h"
|
||||
|
||||
#define LEVELS(name, ...) switch (game->level.current_level) { \
|
||||
case 1: \
|
||||
Level1_ ## name (__VA_ARGS__); break;\
|
||||
case 2: \
|
||||
Level2_ ## name (__VA_ARGS__); break;\
|
||||
case 3: \
|
||||
Level3_ ## name (__VA_ARGS__); break;\
|
||||
case 4: \
|
||||
Level4_ ## name (__VA_ARGS__); break;\
|
||||
case 5: \
|
||||
Level5_ ## name (__VA_ARGS__); break;\
|
||||
case 6: \
|
||||
Level6_ ## name (__VA_ARGS__); break;\
|
||||
}
|
||||
#include <stdio.h>
|
||||
|
||||
void SelectDerpySpritesheet(struct Game *game, char* name) {
|
||||
struct Spritesheet *tmp = game->level.derpy_sheets;
|
||||
PrintConsole(game, "Selecting Derpy spritesheet: %s", name);
|
||||
void SelectSpritesheet(struct Game *game, struct Character *character, char* name) {
|
||||
struct Spritesheet *tmp = character->spritesheets;
|
||||
PrintConsole(game, "Selecting spritesheet for %s: %s", character->name, name);
|
||||
if (!tmp) {
|
||||
PrintConsole(game, "ERROR: No spritesheets registered for Derpy!");
|
||||
PrintConsole(game, "ERROR: No spritesheets registered for %s!", character->name);
|
||||
return;
|
||||
}
|
||||
while (tmp) {
|
||||
if (!strcmp(tmp->name, name)) {
|
||||
game->level.derpy_sheet = &(tmp->bitmap);
|
||||
game->level.sheet_rows = tmp->rows;
|
||||
game->level.sheet_cols = tmp->cols;
|
||||
game->level.sheet_blanks = tmp->blanks;
|
||||
game->level.sheet_speed_modifier = tmp->speed;
|
||||
game->level.sheet_pos = 0;
|
||||
game->level.sheet_scale = tmp->scale;
|
||||
game->level.sheet_successor = tmp->successor;
|
||||
if (game->level.derpy) al_destroy_bitmap(game->level.derpy);
|
||||
game->level.derpy = al_create_bitmap((game->viewportHeight*0.25)*tmp->aspect*tmp->scale, (game->viewportHeight*0.25)*tmp->scale);
|
||||
PrintConsole(game, "SUCCESS: Derpy spritesheet activated: %s (%dx%d)", name, al_get_bitmap_width(game->level.derpy), al_get_bitmap_height(game->level.derpy));
|
||||
character->spritesheet = tmp;
|
||||
//game->level.sheet_rows = tmp->rows;
|
||||
//game->level.sheet_cols = tmp->cols;
|
||||
//game->level.sheet_blanks = tmp->blanks;
|
||||
//game->level.sheet_speed_modifier = tmp->speed;
|
||||
character->pos = 0;
|
||||
//game->level.sheet_scale = tmp->scale;
|
||||
//game->level.sheet_successor = tmp->successor;
|
||||
if (character->bitmap) al_destroy_bitmap(character->bitmap);
|
||||
character->bitmap = al_create_bitmap((game->viewport.height*0.25)*tmp->aspect*tmp->scale, (game->viewport.height*0.25)*tmp->scale);
|
||||
PrintConsole(game, "SUCCESS: Spritesheet for %s activated: %s (%dx%d)", character->name, name, al_get_bitmap_width(character->bitmap), al_get_bitmap_height(character->bitmap));
|
||||
return;
|
||||
}
|
||||
tmp = tmp->next;
|
||||
}
|
||||
PrintConsole(game, "ERROR: No spritesheets registered for Derpy with given name: %s", name);
|
||||
PrintConsole(game, "ERROR: No spritesheets registered for %s with given name: %s", character->name, name);
|
||||
return;
|
||||
}
|
||||
|
||||
void RegisterDerpySpritesheet(struct Game *game, char* name) {
|
||||
struct Spritesheet *s = game->level.derpy_sheets;
|
||||
void RegisterSpritesheet(struct Game *game, struct Character *character, char* name) {
|
||||
struct Spritesheet *s = character->spritesheets;
|
||||
while (s) {
|
||||
if (!strcmp(s->name, name)) {
|
||||
//PrintConsole(game, "Derpy spritesheet %s already registered!", name);
|
||||
//PrintConsole(game, "%s spritesheet %s already registered!", character->name, name);
|
||||
return;
|
||||
}
|
||||
s = s->next;
|
||||
}
|
||||
PrintConsole(game, "Registering %s spritesheet: %s", character->name, name);
|
||||
char filename[255] = { };
|
||||
sprintf(filename, "levels/derpy/%s.ini", name);
|
||||
ALLEGRO_CONFIG *config = al_load_config_file(GetDataFilePath(filename));
|
||||
sprintf(filename, "levels/%s/%s.ini", character->name, name);
|
||||
ALLEGRO_CONFIG *config = al_load_config_file(GetDataFilePath(game, filename));
|
||||
s = malloc(sizeof(struct Spritesheet));
|
||||
s->name = malloc((strlen(name)+1)*sizeof(char));
|
||||
strcpy(s->name, name);
|
||||
s->name = strdup(name);
|
||||
s->bitmap = NULL;
|
||||
s->cols = atoi(al_get_config_value(config, "", "cols"));
|
||||
s->rows = atoi(al_get_config_value(config, "", "rows"));
|
||||
|
@ -100,14 +78,14 @@ void RegisterDerpySpritesheet(struct Game *game, char* name) {
|
|||
const char* successor = al_get_config_value(config, "", "successor");
|
||||
if (successor) {
|
||||
s->successor = malloc(255*sizeof(char));
|
||||
strcpy(s->successor, successor);
|
||||
strncpy(s->successor, successor, 255);
|
||||
}
|
||||
s->next = game->level.derpy_sheets;
|
||||
game->level.derpy_sheets = s;
|
||||
s->next = character->spritesheets;
|
||||
character->spritesheets = s;
|
||||
al_destroy_config(config);
|
||||
PrintConsole(game, "Registering Derpy spritesheet: %s", name);
|
||||
}
|
||||
|
||||
/*
|
||||
void Level_Passed(struct Game *game) {
|
||||
if (game->level.current_level<6) {
|
||||
int available = atoi(GetConfigOptionDefault("MuffinAttack", "level", "1"));
|
||||
|
@ -247,6 +225,7 @@ void Level_ProcessEvent(struct Game *game, ALLEGRO_EVENT *ev) {
|
|||
}
|
||||
|
||||
char* GetLevelFilename(struct Game *game, char* filename) {
|
||||
// FIXME: it should work with larger numbers too
|
||||
char* name = strdup(filename);
|
||||
char* ch = strchr(name, '?');
|
||||
ch[0] = '0' + game->level.current_level;
|
||||
|
@ -373,3 +352,4 @@ void Level_PreloadBitmaps(struct Game *game, void (*progress)(struct Game*, floa
|
|||
}
|
||||
LEVELS(PreloadBitmaps, game, &ChildProgress);
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -20,9 +20,45 @@
|
|||
*/
|
||||
#include "../main.h"
|
||||
|
||||
void SelectDerpySpritesheet(struct Game *game, char* name);
|
||||
void RegisterDerpySpritesheet(struct Game *game, char* name);
|
||||
void Level_Passed(struct Game *game);
|
||||
|
||||
/*! \brief Structure representing one spritesheet for character animation. */
|
||||
struct Spritesheet {
|
||||
char* name; /*!< Name of the spritesheet (used in file paths). */
|
||||
ALLEGRO_BITMAP* bitmap; /*!< Spritesheet bitmap. */
|
||||
int rows; /*!< Number of rows in the spritesheet. */
|
||||
int cols; /*!< Number of columns in the spritesheet. */
|
||||
int blanks; /*!< Number of blank frames at the end of the spritesheet. */
|
||||
float speed; /*!< Speed modifier of spritesheet animation. */
|
||||
float aspect; /*!< Aspect ratio of the frame. */
|
||||
float scale; /*!< Scale modifier of the frame. */
|
||||
char* successor; /*!< Name of animation successor. If it's not blank, then animation will be played only once. */
|
||||
struct Spritesheet* next; /*!< Next spritesheet in the queue. */
|
||||
};
|
||||
|
||||
/*! \brief Structure representing one visible character. */
|
||||
struct Character {
|
||||
char* name; /*!< Name of the character (used in file paths). */
|
||||
struct Spritesheet *spritesheet; /*!< Current spritesheet used by character. */
|
||||
struct Spritesheet *spritesheets; /*!< List of all spritesheets registered to character. */
|
||||
ALLEGRO_BITMAP* bitmap;
|
||||
int pos; /*!< Current spritesheet position. */
|
||||
float x; /*!< Horizontal position of character (0-1). */
|
||||
float y; /*!< Vertical position of character (0-1). */
|
||||
float angle; /*!< Characters display angle (radians). */
|
||||
void* data; /*!< Additional, custom character data (HP etc.). */
|
||||
};
|
||||
|
||||
|
||||
void SelectSpritesheet(struct Game *game, struct Character *character, char* name);
|
||||
void RegisterSpritesheet(struct Game *game, struct Character *character, char* name);
|
||||
void AdvanceLevel(struct Game *game);
|
||||
/*! \brief Replaces first '?' char in filename with current level number. */
|
||||
char* GetLevelFilename(struct Game *game, char* filename);
|
||||
|
||||
void DrawCharacter(struct Game *game, struct Character *character);
|
||||
|
||||
|
||||
/*void Level_Passed(struct Game *game);
|
||||
void Level_Pause(struct Game *game);
|
||||
void Level_Resume(struct Game *game);
|
||||
void Level_Draw(struct Game *game);
|
||||
|
@ -34,4 +70,4 @@ void Level_ProcessEvent(struct Game *game, ALLEGRO_EVENT *ev);
|
|||
int Level_Keydown(struct Game *game, ALLEGRO_EVENT *ev);
|
||||
void Level_UnloadBitmaps(struct Game *game);
|
||||
void Level_PreloadBitmaps(struct Game *game, void (*progress)(struct Game*, float));
|
||||
char* GetLevelFilename(struct Game *game, char* filename);
|
||||
*/
|
||||
|
|
|
@ -333,7 +333,6 @@ void Gamestate_Unload(struct Game *game, struct MenuResources* data) {
|
|||
al_destroy_sample(data->sample);
|
||||
al_destroy_sample(data->rain_sample);
|
||||
al_destroy_sample(data->click_sample);
|
||||
data->loaded = false;
|
||||
}
|
||||
|
||||
void Gamestate_Start(struct Game *game, struct MenuResources* data) {
|
||||
|
|
|
@ -65,7 +65,6 @@ struct MenuResources {
|
|||
ALLEGRO_FONT *font_selected; /*!< Font of selected menu item. */
|
||||
int selected; /*!< Number of selected menu item. */
|
||||
enum menustate_enum menustate; /*!< Current menu page. */
|
||||
bool loaded; /*!< True if Menu state has been already loaded. */
|
||||
struct {
|
||||
bool fullscreen;
|
||||
int fps;
|
||||
|
|
27
src/levels/CMakeLists.txt
Normal file
27
src/levels/CMakeLists.txt
Normal file
|
@ -0,0 +1,27 @@
|
|||
add_library("libsuperderpy-muffinattack-levels" SHARED "actions.c" "../gamestates/level.c" "modules/moonwalk.c")
|
||||
|
||||
SET_TARGET_PROPERTIES("libsuperderpy-muffinattack-levels" PROPERTIES PREFIX "")
|
||||
|
||||
target_link_libraries("libsuperderpy-muffinattack-levels" ${ALLEGRO5_LIBRARIES} ${ALLEGRO5_FONT_LIBRARIES} ${ALLEGRO5_TTF_LIBRARIES} ${ALLEGRO5_PRIMITIVES_LIBRARIES} ${ALLEGRO5_AUDIO_LIBRARIES} ${ALLEGRO5_ACODEC_LIBRARIES} ${ALLEGRO5_IMAGE_LIBRARIES} m libsuperderpy)
|
||||
|
||||
install(TARGETS "libsuperderpy-muffinattack-levels" DESTINATION ${LIB_INSTALL_DIR})
|
||||
|
||||
|
||||
MACRO(GAMESTATE name)
|
||||
|
||||
add_library("libsuperderpy-muffinattack-${name}" SHARED "${name}.c")
|
||||
|
||||
SET_TARGET_PROPERTIES("libsuperderpy-muffinattack-${name}" PROPERTIES PREFIX "")
|
||||
|
||||
target_link_libraries("libsuperderpy-muffinattack-${name}" ${ALLEGRO5_LIBRARIES} ${ALLEGRO5_FONT_LIBRARIES} ${ALLEGRO5_TTF_LIBRARIES} ${ALLEGRO5_PRIMITIVES_LIBRARIES} ${ALLEGRO5_AUDIO_LIBRARIES} ${ALLEGRO5_ACODEC_LIBRARIES} ${ALLEGRO5_IMAGE_LIBRARIES} m libsuperderpy libsuperderpy-muffinattack-levels)
|
||||
|
||||
install(TARGETS "libsuperderpy-muffinattack-${name}" DESTINATION ${LIB_INSTALL_DIR})
|
||||
|
||||
ENDMACRO()
|
||||
|
||||
#GAMESTATE("level1")
|
||||
GAMESTATE("level2")
|
||||
#GAMESTATE("level3")
|
||||
#GAMESTATE("level4")
|
||||
#GAMESTATE("level5")
|
||||
#GAMESTATE("level6")
|
|
@ -19,48 +19,52 @@
|
|||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <allegro5/allegro_primitives.h>
|
||||
#include "../utils.h"
|
||||
#include "../gamestate.h"
|
||||
#include "actions.h"
|
||||
#include "../gamestates/level.h"
|
||||
|
||||
bool LevelFailed(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
|
||||
if (state == TM_ACTIONSTATE_DRAW) {
|
||||
al_draw_filled_rectangle(0, 0, game->viewportWidth, game->viewportHeight, al_map_rgba(0,0,0,100));
|
||||
al_draw_text_with_shadow(game->menu.font_title, al_map_rgb(255,255,255), game->viewportWidth*0.5, game->viewportHeight*0.4, ALLEGRO_ALIGN_CENTRE, "Failed!");
|
||||
al_draw_filled_rectangle(0, 0, game->viewport.width, game->viewport.height, al_map_rgba(0,0,0,100));
|
||||
//FIXME: font
|
||||
//DrawTextWithShadow(game->menu.font_title, al_map_rgb(255,255,255), game->viewport.width*0.5, game->viewport.height*0.4, ALLEGRO_ALIGN_CENTRE, "Failed!");
|
||||
} else if (state == TM_ACTIONSTATE_RUNNING) {
|
||||
// FIXME: this should be more generic. Some callback function?
|
||||
game->level.speed-=0.00001;
|
||||
if (game->level.speed<=0) {
|
||||
// FIXME: data
|
||||
//game->level.speed-=0.00001;
|
||||
//if (game->level.speed<=0) {
|
||||
return true;
|
||||
}
|
||||
//}
|
||||
} else if (state == TM_ACTIONSTATE_DESTROY) {
|
||||
Level_Unload(game);
|
||||
game->gamestate = GAMESTATE_LOADING;
|
||||
game->loadstate = GAMESTATE_MAP;
|
||||
SwitchGamestate(game, "level", "map");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ShowMeter(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
|
||||
if (state != TM_ACTIONSTATE_RUNNING) return false;
|
||||
game->level.meter_alpha+=4;
|
||||
if (game->level.meter_alpha>=255) {
|
||||
game->level.meter_alpha=255;
|
||||
//FIXME: data
|
||||
//game->level.meter_alpha+=4;
|
||||
//if (game->level.meter_alpha>=255) {
|
||||
// game->level.meter_alpha=255;
|
||||
return true;
|
||||
}
|
||||
//}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Stop(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
|
||||
if (state != TM_ACTIONSTATE_RUNNING) return false;
|
||||
game->level.speed=0;
|
||||
SelectDerpySpritesheet(game, "stand");
|
||||
//FIXME: data
|
||||
//game->level.speed=0;
|
||||
//SelectDerpySpritesheet(game, "stand");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FadeIn(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
|
||||
if (!action->arguments) {
|
||||
action->arguments = TM_AddToArgs(action->arguments, malloc(sizeof(float)));
|
||||
action->arguments = TM_AddToArgs(action->arguments, (void*)al_create_bitmap(game->viewportWidth, game->viewportHeight));
|
||||
action->arguments = TM_AddToArgs(action->arguments, (void*)al_create_bitmap(game->viewport.width, game->viewport.height));
|
||||
}
|
||||
float* fadeloop;
|
||||
ALLEGRO_BITMAP* fade_bitmap;
|
||||
|
@ -81,7 +85,8 @@ bool FadeIn(struct Game *game, struct TM_Action *action, enum TM_ActionState sta
|
|||
free(fadeloop);
|
||||
TM_DestroyArgs(action->arguments);
|
||||
action->arguments = NULL;
|
||||
al_play_sample_instance(game->level.music);
|
||||
//FIXME: data
|
||||
//al_play_sample_instance(game->level.music);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -89,7 +94,7 @@ bool FadeIn(struct Game *game, struct TM_Action *action, enum TM_ActionState sta
|
|||
bool FadeOut(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
|
||||
if (!action->arguments) {
|
||||
action->arguments = TM_AddToArgs(action->arguments, malloc(sizeof(float)));
|
||||
action->arguments = TM_AddToArgs(action->arguments, (void*)al_create_bitmap(game->viewportWidth, game->viewportHeight));
|
||||
action->arguments = TM_AddToArgs(action->arguments, (void*)al_create_bitmap(game->viewport.width, game->viewport.height));
|
||||
}
|
||||
float* fadeloop;
|
||||
ALLEGRO_BITMAP* fade_bitmap;
|
||||
|
@ -106,12 +111,11 @@ bool FadeOut(struct Game *game, struct TM_Action *action, enum TM_ActionState st
|
|||
} else if (state == TM_ACTIONSTATE_DRAW) {
|
||||
al_draw_tinted_bitmap(fade_bitmap,al_map_rgba_f(1,1,1,*fadeloop/255.0),0,0,0);
|
||||
} else if (state == TM_ACTIONSTATE_DESTROY) {
|
||||
PrintConsole(game, "Leaving level with %d HP", (int)(game->level.hp*100));
|
||||
//FIXME: data
|
||||
//PrintConsole(game, "Leaving level with %d HP", (int)(game->level.hp*100));
|
||||
al_destroy_bitmap(fade_bitmap);
|
||||
free(fadeloop);
|
||||
Level_Unload(game);
|
||||
game->gamestate = GAMESTATE_LOADING;
|
||||
game->loadstate = GAMESTATE_MAP;
|
||||
SwitchGamestate(game, "level", "map");
|
||||
TM_DestroyArgs(action->arguments);
|
||||
action->arguments = NULL;
|
||||
}
|
||||
|
@ -143,7 +147,8 @@ bool Welcome(struct Game *game, struct TM_Action *action, enum TM_ActionState st
|
|||
if (*tmp<=0) { return true; }
|
||||
}
|
||||
} else if (state == TM_ACTIONSTATE_DRAW) {
|
||||
al_draw_tinted_bitmap(game->level.welcome, al_map_rgba_f(*tmp/255.0,*tmp/255.0,*tmp/255.0,*tmp/255.0), 0, 0, 0);
|
||||
//FIXME: data
|
||||
//al_draw_tinted_bitmap(game->level.welcome, al_map_rgba_f(*tmp/255.0,*tmp/255.0,*tmp/255.0,*tmp/255.0), 0, 0, 0);
|
||||
} else if (state == TM_ACTIONSTATE_DESTROY) {
|
||||
free(action->arguments->value);
|
||||
free(action->arguments->next->value);
|
||||
|
@ -155,7 +160,8 @@ bool Welcome(struct Game *game, struct TM_Action *action, enum TM_ActionState st
|
|||
|
||||
bool PassLevel(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
|
||||
if (state == TM_ACTIONSTATE_DESTROY) {
|
||||
Level_Passed(game);
|
||||
//FIXME: data
|
||||
/*Level_Passed(game);
|
||||
Level_Unload(game);
|
||||
if (game->level.current_level<6) {
|
||||
game->gamestate = GAMESTATE_LOADING;
|
||||
|
@ -163,7 +169,7 @@ bool PassLevel(struct Game *game, struct TM_Action *action, enum TM_ActionState
|
|||
} else {
|
||||
game->gamestate = GAMESTATE_LOADING;
|
||||
game->loadstate = GAMESTATE_ABOUT;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -173,7 +179,9 @@ bool Letter(struct Game *game, struct TM_Action *action, enum TM_ActionState sta
|
|||
float* f = (float*)malloc(sizeof(float));
|
||||
*f = 0;
|
||||
ALLEGRO_AUDIO_STREAM** stream = (ALLEGRO_AUDIO_STREAM**)malloc(sizeof(ALLEGRO_AUDIO_STREAM*));
|
||||
*stream = al_load_audio_stream(GetDataFilePath(GetLevelFilename(game, "levels/?/letter.flac")), 4, 1024);
|
||||
//FIXME: GetLevelFilename
|
||||
//*stream = al_load_audio_stream(GetDataFilePath(game, GetLevelFilename(game, "levels/?/letter.flac")), 4, 1024);
|
||||
*stream = al_load_audio_stream(GetDataFilePath(game, "levels/1/letter.flac"), 4, 1024);
|
||||
al_attach_audio_stream_to_mixer(*stream, game->audio.voice);
|
||||
al_set_audio_stream_playing(*stream, false);
|
||||
al_set_audio_stream_gain(*stream, 2.00);
|
||||
|
@ -188,8 +196,9 @@ bool Letter(struct Game *game, struct TM_Action *action, enum TM_ActionState sta
|
|||
free(action->arguments->value);
|
||||
TM_DestroyArgs(action->arguments);
|
||||
} else if (state == TM_ACTIONSTATE_DRAW) {
|
||||
float* f = (float*)action->arguments->value;
|
||||
al_draw_tinted_bitmap(game->level.letter, al_map_rgba(*f,*f,*f,*f), (game->viewportWidth-al_get_bitmap_width(game->level.letter))/2.0, al_get_bitmap_height(game->level.letter)*-0.05, 0);
|
||||
//float* f = (float*)action->arguments->value;
|
||||
//FIXME: data
|
||||
//al_draw_tinted_bitmap(game->level.letter, al_map_rgba(*f,*f,*f,*f), (game->viewport.width-al_get_bitmap_width(game->level.letter))/2.0, al_get_bitmap_height(game->level.letter)*-0.05, 0);
|
||||
return false;
|
||||
} else if (state == TM_ACTIONSTATE_PAUSE) {
|
||||
ALLEGRO_AUDIO_STREAM** stream = (ALLEGRO_AUDIO_STREAM**)action->arguments->next->value;
|
||||
|
@ -203,7 +212,8 @@ bool Letter(struct Game *game, struct TM_Action *action, enum TM_ActionState sta
|
|||
float* f = (float*)action->arguments->value;
|
||||
*f+=5;
|
||||
if (*f>255) *f=255;
|
||||
al_draw_tinted_bitmap(game->level.letter, al_map_rgba(*f,*f,*f,*f), (game->viewportWidth-al_get_bitmap_width(game->level.letter))/2.0, al_get_bitmap_height(game->level.letter)*-0.05, 0);
|
||||
//FIXME: data
|
||||
//al_draw_tinted_bitmap(game->level.letter, al_map_rgba(*f,*f,*f,*f), (game->viewport.width-al_get_bitmap_width(game->level.letter))/2.0, al_get_bitmap_height(game->level.letter)*-0.05, 0);
|
||||
struct ALLEGRO_KEYBOARD_STATE keyboard;
|
||||
al_get_keyboard_state(&keyboard);
|
||||
// FIXME: do it the proper way
|
||||
|
|
|
@ -25,54 +25,60 @@
|
|||
#include "actions.h"
|
||||
#include "level2.h"
|
||||
|
||||
void Level2_Load(struct Game *game) {
|
||||
void Gamestate_Load(struct Game *game) {
|
||||
Moonwalk_Load(game);
|
||||
TM_Init(game);
|
||||
TM_AddAction(&DoMoonwalk, NULL, "moonwalk");
|
||||
TM_AddAction(&PassLevel, NULL, "passlevel");
|
||||
FadeGameState(game, true);
|
||||
//FadeGameState(game, true);
|
||||
}
|
||||
|
||||
void Level2_Unload(struct Game *game) {
|
||||
void Gamestate_Unload(struct Game *game) {
|
||||
Moonwalk_Unload(game);
|
||||
}
|
||||
|
||||
void Level2_UnloadBitmaps(struct Game *game) {
|
||||
void Gamestate_UnloadBitmaps(struct Game *game) {
|
||||
Moonwalk_UnloadBitmaps(game);
|
||||
}
|
||||
|
||||
void Level2_Preload(struct Game *game) {
|
||||
Moonwalk_Preload(game);
|
||||
void Gamestate_Start(struct Game *game) {
|
||||
Moonwalk_Start(game);
|
||||
}
|
||||
|
||||
inline int Level2_PreloadSteps(void) {
|
||||
return 0+Moonwalk_PreloadSteps();
|
||||
void Gamestate_Stop(struct Game *game) {
|
||||
Moonwalk_Stop(game);
|
||||
}
|
||||
|
||||
void Level2_PreloadBitmaps(struct Game *game, void (*progress)(struct Game*, float)) {
|
||||
void Gamestate_LoadBitmaps(struct Game *game, void (*progress)(struct Game*, float)) {
|
||||
//PROGRESS_INIT(Level2_PreloadSteps());
|
||||
Moonwalk_PreloadBitmaps(game, progress);
|
||||
Moonwalk_LoadBitmaps(game, progress);
|
||||
}
|
||||
|
||||
void Level2_Draw(struct Game *game) {
|
||||
void Gamestate_Draw(struct Game *game) {
|
||||
Moonwalk_Draw(game);
|
||||
}
|
||||
|
||||
void Level2_Logic(struct Game *game) {
|
||||
void Gamestate_Logic(struct Game *game) {
|
||||
Moonwalk_Logic(game);
|
||||
}
|
||||
|
||||
void Level2_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
|
||||
Moonwalk_Keydown(game, ev);
|
||||
}
|
||||
|
||||
void Level2_ProcessEvent(struct Game *game, ALLEGRO_EVENT *ev) {
|
||||
void Gamestate_ProcessEvent(struct Game *game, void* data, ALLEGRO_EVENT *ev) {
|
||||
Moonwalk_ProcessEvent(game, ev);
|
||||
if (ev->type == ALLEGRO_EVENT_KEY_DOWN) {
|
||||
if (ev->keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
|
||||
SwitchGamestate(game, "level2", "menu");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Level2_Resume(struct Game *game) {
|
||||
void Gamestate_Resume(struct Game *game) {
|
||||
Moonwalk_Resume(game);
|
||||
}
|
||||
|
||||
void Level2_Pause(struct Game *game) {
|
||||
void Gamestate_Pause(struct Game *game) {
|
||||
Moonwalk_Pause(game);
|
||||
}
|
||||
|
||||
void Gamestate_Reload(struct Game *game) {}
|
||||
|
||||
int Gamestate_ProgressCount = 0;
|
||||
|
|
|
@ -19,16 +19,3 @@
|
|||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
#include "../main.h"
|
||||
|
||||
void Level2_Load(struct Game *game);
|
||||
void Level2_Unload(struct Game *game);
|
||||
void Level2_UnloadBitmaps(struct Game *game);
|
||||
void Level2_Preload(struct Game *game);
|
||||
void Level2_PreloadBitmaps(struct Game *game, void (*progress)(struct Game*, float));
|
||||
inline int Level2_PreloadSteps(void);
|
||||
void Level2_Draw(struct Game *game);
|
||||
void Level2_Logic(struct Game *game);
|
||||
void Level2_Keydown(struct Game *game, ALLEGRO_EVENT *ev);
|
||||
void Level2_ProcessEvent(struct Game *game, ALLEGRO_EVENT *ev);
|
||||
void Level2_Resume(struct Game *game);
|
||||
void Level2_Pause(struct Game *game);
|
||||
|
|
|
@ -26,15 +26,15 @@
|
|||
// TODO: use Walk action instead
|
||||
bool DoMoonwalk(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
|
||||
if (state == TM_ACTIONSTATE_START) {
|
||||
SelectDerpySpritesheet(game, "walk");
|
||||
game->level.sheet_speed_modifier = 0.94;
|
||||
game->level.moonwalk.derpy_pos = -0.2;
|
||||
//SelectDerpySpritesheet(game, "walk");
|
||||
//game->level.sheet_speed_modifier = 0.94;
|
||||
//game->level.moonwalk.derpy_pos = -0.2;
|
||||
}
|
||||
else if (state == TM_ACTIONSTATE_RUNNING) {
|
||||
game->level.moonwalk.derpy_pos=game->level.moonwalk.derpy_pos+0.00092;
|
||||
if (game->level.moonwalk.derpy_pos>1) {
|
||||
//game->level.moonwalk.derpy_pos=game->level.moonwalk.derpy_pos+0.00092;
|
||||
//if (game->level.moonwalk.derpy_pos>1) {
|
||||
return true;
|
||||
}
|
||||
//}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -42,45 +42,39 @@ bool DoMoonwalk(struct Game *game, struct TM_Action *action, enum TM_ActionState
|
|||
void Moonwalk_Logic(struct Game *game) {}
|
||||
|
||||
void Moonwalk_Draw(struct Game *game) {
|
||||
al_set_target_bitmap(game->level.derpy);
|
||||
/* al_set_target_bitmap(game->level.derpy);
|
||||
al_clear_to_color(al_map_rgba(0,0,0,0));
|
||||
al_draw_bitmap_region(*(game->level.derpy_sheet),al_get_bitmap_width(game->level.derpy)*(game->level.sheet_pos%6),al_get_bitmap_height(game->level.derpy)*(game->level.sheet_pos/6),al_get_bitmap_width(game->level.derpy), al_get_bitmap_height(game->level.derpy),0,0,0);
|
||||
al_set_target_bitmap(al_get_backbuffer(game->display));
|
||||
|
||||
al_draw_scaled_bitmap(game->level.stage,0,0,al_get_bitmap_width(game->level.stage),al_get_bitmap_height(game->level.stage),0,0,game->viewportWidth, game->viewportHeight,0);
|
||||
al_draw_bitmap(game->level.derpy, game->level.moonwalk.derpy_pos*game->viewportWidth, game->viewportHeight*0.95-al_get_bitmap_height(game->level.derpy), ALLEGRO_FLIP_HORIZONTAL);
|
||||
al_draw_textf(game->font, al_map_rgb(255,255,255), game->viewportWidth/2, game->viewportHeight/2.2, ALLEGRO_ALIGN_CENTRE, "Level %d: Not implemented yet!", game->level.current_level);
|
||||
al_draw_text(game->font, al_map_rgb(255,255,255), game->viewportWidth/2, game->viewportHeight/1.8, ALLEGRO_ALIGN_CENTRE, "Have some moonwalk instead.");
|
||||
al_draw_scaled_bitmap(game->level.stage,0,0,al_get_bitmap_width(game->level.stage),al_get_bitmap_height(game->level.stage),0,0,game->viewport.width, game->viewport.height,0);
|
||||
al_draw_bitmap(game->level.derpy, game->level.moonwalk.derpy_pos*game->viewport.width, game->viewport.height*0.95-al_get_bitmap_height(game->level.derpy), ALLEGRO_FLIP_HORIZONTAL);
|
||||
al_draw_textf(game->font, al_map_rgb(255,255,255), game->viewport.width/2, game->viewport.height/2.2, ALLEGRO_ALIGN_CENTRE, "Level %d: Not implemented yet!", game->level.current_level);
|
||||
al_draw_text(game->font, al_map_rgb(255,255,255), game->viewport.width/2, game->viewport.height/1.8, ALLEGRO_ALIGN_CENTRE, "Have some moonwalk instead.");*/
|
||||
}
|
||||
|
||||
void Moonwalk_Load(struct Game *game) {
|
||||
game->level.moonwalk.derpy_pos = 0;
|
||||
al_play_sample_instance(game->level.music);
|
||||
void Moonwalk_Start(struct Game *game) {
|
||||
/*game->level.moonwalk.derpy_pos = 0;
|
||||
al_play_sample_instance(game->level.music);*/
|
||||
}
|
||||
|
||||
void Moonwalk_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {}
|
||||
|
||||
inline int Moonwalk_PreloadSteps(void) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
void Moonwalk_PreloadBitmaps(struct Game *game, void (*progress)(struct Game*, float)) {
|
||||
PROGRESS_INIT(Moonwalk_PreloadSteps());
|
||||
void Moonwalk_LoadBitmaps(struct Game *game, void (*progress)(struct Game*, float)) {
|
||||
// nasty hack: overwrite level background
|
||||
al_destroy_bitmap(game->level.stage);
|
||||
game->level.stage = LoadScaledBitmap("levels/moonwalk/disco.jpg", game->viewportWidth, game->viewportHeight);
|
||||
PROGRESS;
|
||||
/*al_destroy_bitmap(game->level.stage);
|
||||
game->level.stage = LoadScaledBitmap("levels/moonwalk/disco.jpg", game->viewport.width, game->viewport.height);
|
||||
*/
|
||||
al_set_target_bitmap(al_get_backbuffer(game->display));
|
||||
}
|
||||
|
||||
void Moonwalk_Preload(struct Game *game) {
|
||||
RegisterDerpySpritesheet(game, "walk");
|
||||
void Moonwalk_Load(struct Game *game) {
|
||||
//RegisterSpritesheet(game, DERPY, "walk");
|
||||
// nasty hack: overwrite level music
|
||||
al_destroy_sample(game->level.sample);
|
||||
game->level.sample = al_load_sample( GetDataFilePath("levels/moonwalk/moonwalk.flac") );
|
||||
//al_destroy_sample(game->level.sample);
|
||||
//game->level.sample = al_load_sample( GetDataFilePath("levels/moonwalk/moonwalk.flac") );
|
||||
}
|
||||
|
||||
void Moonwalk_UnloadBitmaps(struct Game *game) {}
|
||||
void Moonwalk_Stop(struct Game *game) {}
|
||||
void Moonwalk_Unload(struct Game *game) {}
|
||||
void Moonwalk_ProcessEvent(struct Game *game, ALLEGRO_EVENT *ev) {}
|
||||
void Moonwalk_Resume(struct Game *game) {}
|
||||
|
|
|
@ -24,13 +24,12 @@
|
|||
bool DoMoonwalk(struct Game *game, struct TM_Action *action, enum TM_ActionState state);
|
||||
void Moonwalk_Draw(struct Game *game);
|
||||
void Moonwalk_Logic(struct Game *game);
|
||||
void Moonwalk_Preload(struct Game *game);
|
||||
void Moonwalk_Start(struct Game *game);
|
||||
void Moonwalk_Stop(struct Game *game);
|
||||
void Moonwalk_Unload(struct Game *game);
|
||||
void Moonwalk_Load(struct Game *game);
|
||||
void Moonwalk_Keydown(struct Game *game, ALLEGRO_EVENT *ev);
|
||||
void Moonwalk_UnloadBitmaps(struct Game *game);
|
||||
void Moonwalk_PreloadBitmaps(struct Game *game, void (*progress)(struct Game*, float));
|
||||
void Moonwalk_LoadBitmaps(struct Game *game, void (*progress)(struct Game*, float));
|
||||
void Moonwalk_ProcessEvent(struct Game *game, ALLEGRO_EVENT *ev);
|
||||
void Moonwalk_Resume(struct Game *game);
|
||||
void Moonwalk_Pause(struct Game *game);
|
||||
inline int Moonwalk_PreloadSteps(void);
|
||||
|
|
|
@ -499,17 +499,11 @@ int main(int argc, char **argv){
|
|||
while (tmp) {
|
||||
if (tmp->started) {
|
||||
PrintConsole(&game, "Stopping gamestate \"%s\"...", tmp->name);
|
||||
al_clear_to_color(al_map_rgb(255,255,0));
|
||||
DrawConsole(&game);
|
||||
al_flip_display();
|
||||
(*tmp->api.Gamestate_Stop)(&game, tmp->data);
|
||||
tmp->started = false;
|
||||
}
|
||||
if (tmp->loaded) {
|
||||
PrintConsole(&game, "Unloading gamestate \"%s\"...", tmp->name);
|
||||
al_clear_to_color(al_map_rgb(255,0,0));
|
||||
DrawConsole(&game);
|
||||
al_flip_display();
|
||||
(*tmp->api.Gamestate_Unload)(&game, tmp->data);
|
||||
dlclose(tmp->handle);
|
||||
tmp->loaded = false;
|
||||
|
|
|
@ -208,8 +208,7 @@ struct TM_Action* TM_AddAction(bool (*func)(struct Game*, struct TM_Action*, enu
|
|||
action->next = NULL;
|
||||
action->function = func;
|
||||
action->arguments = args;
|
||||
action->name = malloc((strlen(name)+1)*sizeof(char));
|
||||
strcpy(action->name, name);
|
||||
action->name = strdup(name);
|
||||
action->timer = NULL;
|
||||
action->active = false;
|
||||
action->delay = 0;
|
||||
|
@ -235,8 +234,7 @@ struct TM_Action* TM_AddBackgroundAction(bool (*func)(struct Game*, struct TM_Ac
|
|||
action->next = NULL;
|
||||
action->function = func;
|
||||
action->arguments = args;
|
||||
action->name = malloc((strlen(name)+1)*sizeof(char));
|
||||
strcpy(action->name, name);
|
||||
action->name = strdup(name);
|
||||
action->delay = delay;
|
||||
action->id = ++lastid;
|
||||
if (delay) {
|
||||
|
@ -272,8 +270,7 @@ struct TM_Action* TM_AddQueuedBackgroundAction(bool (*func)(struct Game*, struct
|
|||
arguments = TM_AddToArgs(arguments, malloc(sizeof(int)));
|
||||
arguments = TM_AddToArgs(arguments, NULL);
|
||||
*(int*)(arguments->next->value) = delay;
|
||||
arguments->next->next->value = malloc((strlen(name)+1)*sizeof(char));
|
||||
strcpy(arguments->next->next->value, name);
|
||||
arguments->next->next->value = strdup(name);
|
||||
|
||||
arguments->next->next->next = args;
|
||||
return TM_AddAction(*runinbackground, arguments, "TM_BackgroundAction");
|
||||
|
|
Loading…
Reference in a new issue