From 001ed62181f582a4a8deeb8b1187f4ca69111122 Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Wed, 5 Jun 2013 23:20:55 +0200 Subject: [PATCH] lots of level 1 tweaks --- src/gamestates/level.c | 7 ++---- src/gamestates/level.h | 2 +- src/levels/level1.c | 26 +++++++++++++++------ src/levels/level_placeholder.c | 1 + src/levels/modules/dodger.c | 30 +++++++++++++----------- src/levels/modules/dodger/actions.c | 36 +++++++++++++++++------------ src/levels/modules/moonwalk.c | 2 +- src/timeline.h | 3 +++ 8 files changed, 64 insertions(+), 43 deletions(-) diff --git a/src/gamestates/level.c b/src/gamestates/level.c index 0ecd6be..53ef188 100644 --- a/src/gamestates/level.c +++ b/src/gamestates/level.c @@ -196,16 +196,13 @@ void AdvanceLevel(struct Game *game, int current_level, bool last) { return name; }*/ -void DrawCharacter(struct Game *game, struct Character *character, int flags) { - // TODO: support for additional states, like being hit (transparency, color tilt etc.) - bool colision = false; - +void DrawCharacter(struct Game *game, struct Character *character, ALLEGRO_COLOR tilt, int flags) { al_set_target_bitmap(character->bitmap); al_clear_to_color(al_map_rgba(0,0,0,0)); al_draw_bitmap_region(character->spritesheet->bitmap, al_get_bitmap_width(character->bitmap)*(character->pos%character->spritesheet->cols),al_get_bitmap_height(character->bitmap)*(character->pos/character->spritesheet->cols),al_get_bitmap_width(character->bitmap), al_get_bitmap_height(character->bitmap),0,0,0); al_set_target_bitmap(al_get_backbuffer(game->display)); - al_draw_tinted_rotated_bitmap(character->bitmap, al_map_rgba(255,255-colision*255,255-colision*255,255), al_get_bitmap_width(character->bitmap), al_get_bitmap_height(character->bitmap)/2, character->x*game->viewport.width + game->viewport.width*0.1953125, character->y*game->viewport.height + al_get_bitmap_height(character->bitmap)/2, character->angle, flags); // FIXME: viewport height? omg character should have its dimensions ;_; + al_draw_tinted_rotated_bitmap(character->bitmap, tilt, al_get_bitmap_width(character->bitmap), al_get_bitmap_height(character->bitmap)/2, character->x*game->viewport.width + game->viewport.width*0.1953125, character->y*game->viewport.height + al_get_bitmap_height(character->bitmap)/2, character->angle, flags); // FIXME: viewport height? omg character should have its dimensions ;_; } diff --git a/src/gamestates/level.h b/src/gamestates/level.h index 232557a..9522a69 100644 --- a/src/gamestates/level.h +++ b/src/gamestates/level.h @@ -56,7 +56,7 @@ void AdvanceLevel(struct Game *game, int current_level, bool last); /*! \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, int flags); +void DrawCharacter(struct Game *game, struct Character *character, ALLEGRO_COLOR tilt, int flags); struct Character* CreateCharacter(struct Game *game, char* name); void DestroyCharacter(struct Game *game, struct Character *character); diff --git a/src/levels/level1.c b/src/levels/level1.c index 32c89e2..9fb2a91 100644 --- a/src/levels/level1.c +++ b/src/levels/level1.c @@ -20,6 +20,7 @@ */ #include #include "allegro5/allegro_ttf.h" +#include "../timeline.h" #include "../gamestates/level.h" #include "actions.h" #include "../utils.h" @@ -27,7 +28,7 @@ #include "modules/dodger/actions.h" #include "level1.h" -int Gamestate_ProgressCount = 9001; +int Gamestate_ProgressCount = 2; void Gamestate_Start(struct Game *game, struct Level1Resources* data) { TM_AddBackgroundAction(&FadeIn, NULL, 0, "fadein"); @@ -58,7 +59,11 @@ void Gamestate_Start(struct Game *game, struct Level1Resources* data) { // second part gameplay goes here // cutscene goes here */ - TM_AddAction(&PassLevel, NULL, "passlevel"); + + struct TM_Arguments *args = TM_AddToArgs(NULL, strdup("level1")); + TM_WrapArg(int, level, 1); + TM_AddToArgs(args, level); + TM_AddAction(&PassLevel, args, "passlevel"); // init level specific obstacle (owl) for Dodger module struct Obstacle *obst = malloc(sizeof(struct Obstacle)); @@ -170,9 +175,18 @@ struct Level1Resources* Gamestate_Load(struct Game *game) { RegisterSpritesheet(game, character, "stand"); RegisterSpritesheet(game, character, "fly"); RegisterSpritesheet(game, character, "run"); - SelectSpritesheet(game, character, "stand"); + SelectSpritesheet(game, character, "walk"); + SetCharacterPosition(game, character, 0.1, 0.7, 0); data->dodger = Dodger_Load(game, character); + data->failed=false; + data->cl_pos=0; + data->bg_pos=0; + data->fg_pos=0.2; + data->st_pos=0.1; + data->handle_input = false; + data->meter_alpha=0; + Gamestate_PreloadBitmaps(game, data); LoadSpritesheets(game, character); return data; @@ -184,14 +198,12 @@ void Gamestate_Draw(struct Game *game, struct Level1Resources* data) { } void Gamestate_Logic(struct Game *game, struct Level1Resources* data) { + TM_Process(); Dodger_Logic(game, data->dodger); } -void Gamestate_Keydown(struct Game *game, struct Level1Resources* data, ALLEGRO_EVENT *ev) { - Dodger_Keydown(game, data->dodger, ev); -} - void Gamestate_ProcessEvent(struct Game *game, struct Level1Resources* data, ALLEGRO_EVENT *ev) { + TM_HandleEvent(ev); Dodger_ProcessEvent(game, data->dodger, ev); if (ev->type == ALLEGRO_EVENT_KEY_DOWN) { if (ev->keyboard.keycode == ALLEGRO_KEY_ESCAPE) { diff --git a/src/levels/level_placeholder.c b/src/levels/level_placeholder.c index 31bdd47..50a8747 100644 --- a/src/levels/level_placeholder.c +++ b/src/levels/level_placeholder.c @@ -84,6 +84,7 @@ void Gamestate_Logic(struct Game *game, struct LevelXResources* data) { } void Gamestate_ProcessEvent(struct Game *game, struct LevelXResources* data, ALLEGRO_EVENT *ev) { + TM_HandleEvent(ev); Moonwalk_ProcessEvent(game, data->moonwalk, ev); if (ev->type == ALLEGRO_EVENT_KEY_DOWN) { if (ev->keyboard.keycode == ALLEGRO_KEY_ESCAPE) { diff --git a/src/levels/modules/dodger.c b/src/levels/modules/dodger.c index 82a36c7..7ddda21 100644 --- a/src/levels/modules/dodger.c +++ b/src/levels/modules/dodger.c @@ -27,6 +27,8 @@ #include "dodger.h" #include "dodger/actions.h" +int Dodger_ProgressCount = 0; + void Dodger_Logic(struct Game *game, struct Dodger* data) { struct ALLEGRO_KEYBOARD_STATE keyboard; al_get_keyboard_state(&keyboard); @@ -57,10 +59,10 @@ void Dodger_Logic(struct Game *game, struct Dodger* data) { if ( data->character->y < 0) data->character->y=0; else if ( data->character->y > 0.8) data->character->y=0.8; - data->character->y += data->character->angle / 30; + MoveCharacter(game, data->character, 0, data->character->angle / 30, 0); } - int derpyx = data->character->x*game->viewport.height*1.6; + int derpyx = data->character->x*game->viewport.width; int derpyy = data->character->y*game->viewport.height; int derpyw = al_get_bitmap_width(data->character->bitmap); int derpyh = al_get_bitmap_height(data->character->bitmap); @@ -119,6 +121,7 @@ void Dodger_Logic(struct Game *game, struct Dodger* data) { } } /*if (colision) data->hp-=tps(game, 60*0.002);*/ + AnimateCharacter(game, data->character, data->speed_modifier); } @@ -168,12 +171,13 @@ void Dodger_Draw(struct Game *game, struct Dodger* data) { } /*if (colision) data->hp-=tps(game, 60*0.002);*/ - al_set_target_bitmap(data->character->bitmap); +/* al_set_target_bitmap(data->character->bitmap); al_clear_to_color(al_map_rgba(0,0,0,0)); al_draw_bitmap_region(data->character->spritesheet->bitmap,al_get_bitmap_width(data->character->bitmap)*(data->character->pos%data->character->spritesheet->cols),al_get_bitmap_height(data->character->bitmap)*(data->character->pos/data->character->spritesheet->cols),al_get_bitmap_width(data->character->bitmap), al_get_bitmap_height(data->character->bitmap),0,0,0); al_set_target_bitmap(al_get_backbuffer(game->display)); - al_draw_tinted_rotated_bitmap(data->character->bitmap, al_map_rgba(255,255-colision*255,255-colision*255,255), al_get_bitmap_width(data->character->bitmap), al_get_bitmap_height(data->character->bitmap)/2, derpyx+game->viewport.height*1.6*0.1953125, derpyy + al_get_bitmap_height(data->character->bitmap)/2, data->character->angle, 0); + al_draw_tinted_rotated_bitmap(data->character->bitmap, al_map_rgba(255,255-colision*255,255-colision*255,255), al_get_bitmap_width(data->character->bitmap), al_get_bitmap_height(data->character->bitmap)/2, derpyx+game->viewport.height*1.6*0.1953125, derpyy + al_get_bitmap_height(data->character->bitmap)/2, data->character->angle, 0);*/ + DrawCharacter(game, data->character, al_map_rgba(255,255-colision*255,255-colision*255,255), 0); /* if ((((x>=derpyx+0.36*derpyw) && (x<=derpyx+0.94*derpyw)) || ((x+w>=derpyx+0.36*derpyw) && (x+w<=derpyx+0.94*derpyw))) && (((y>=derpyy+0.26*derpyh) && (y<=derpyy+0.76*derpyh)) || ((y+h>=derpyy+0.26*derpyh) && (y+h<=derpyy+0.76*derpyh)))) { @@ -188,17 +192,15 @@ struct Dodger* Dodger_Load(struct Game *game, struct Character *character) { struct Dodger *data = malloc(sizeof(struct Dodger)); data->obstacles = NULL; data->character = character; - return data; -} -void Dodger_Keydown(struct Game *game, struct Dodger* data, ALLEGRO_EVENT *ev) { - if (data->handle_input) { - if (ev->keyboard.keycode==ALLEGRO_KEY_LEFT) { - data->speed_modifier = 0.75; - } else if (ev->keyboard.keycode==ALLEGRO_KEY_RIGHT) { - data->speed_modifier = 1.3; - } - } + data->failed=false; + data->hp=1; + data->speed = 0; + data->speed_modifier = 1; + data->handle_input = true; + data->debug_show_sprite_frames=false; + + return data; } void Dodger_ProcessEvent(struct Game *game, struct Dodger* data, ALLEGRO_EVENT *ev) { diff --git a/src/levels/modules/dodger/actions.c b/src/levels/modules/dodger/actions.c index e90daca..7f226e9 100644 --- a/src/levels/modules/dodger/actions.c +++ b/src/levels/modules/dodger/actions.c @@ -24,11 +24,19 @@ #include "../../actions.h" #include "../../../gamestates/level.h" -void SelectDerpySpritesheet(void* a, void* b) { - +// TODO: make it configurable and move to generic actions +// args: struct Character* character +bool Walk(struct Game *game, struct TM_Action *action, enum TM_ActionState state) { + if (state == TM_ACTIONSTATE_START) return false; //SelectDerpySpritesheet(game, "walk"); + else if (state != TM_ACTIONSTATE_RUNNING) return false; + //game->level.derpy_x+=(0.00125*1280)/(float)game->viewportWidth; + //if (game->level.derpy_x>=(0.05*1280)/(float)game->viewportWidth) return true; + return true; + return false; } -// TODO: make it configurable and move to generic actions +// TODO: make it configurable +// args: struct Dodger* data bool Accelerate(struct Game *game, struct TM_Action *action, enum TM_ActionState state) { if (state != TM_ACTIONSTATE_RUNNING) return false; //game->level.speed+=0.000015; @@ -36,26 +44,19 @@ bool Accelerate(struct Game *game, struct TM_Action *action, enum TM_ActionState return false; } -// TODO: make it configurable and move to generic actions -bool Walk(struct Game *game, struct TM_Action *action, enum TM_ActionState state) { - if (state == TM_ACTIONSTATE_START) SelectDerpySpritesheet(game, "walk"); - else if (state != TM_ACTIONSTATE_RUNNING) return false; - //game->level.derpy_x+=(0.00125*1280)/(float)game->viewportWidth; - //if (game->level.derpy_x>=(0.05*1280)/(float)game->viewportWidth) return true; - return false; -} - -// TODO: make it configurable and move to generic actions +// args: struct Dodger* data bool Move(struct Game *game, struct TM_Action *action, enum TM_ActionState state) { if (state != TM_ACTIONSTATE_RUNNING) return false; // game->level.speed=0.000345; // if (game->level.st_pos>=0.275) return true; + return true; return false; } +// args: struct Dodger* data bool Fly(struct Game *game, struct TM_Action *action, enum TM_ActionState state) { if (state == TM_ACTIONSTATE_START) { - SelectDerpySpritesheet(game, "fly"); +// SelectDerpySpritesheet(game, "fly"); // game->level.derpy_angle = -0.15; TM_AddBackgroundAction(&ShowMeter, NULL, 0, "showmeter"); } @@ -65,9 +66,11 @@ bool Fly(struct Game *game, struct TM_Action *action, enum TM_ActionState state) else if (state != TM_ACTIONSTATE_RUNNING) return false; // game->level.derpy_y-=0.004; // if (game->level.derpy_y<=0.2) return true; + return true; return false; } +// args: struct Dodger* data bool Run(struct Game *game, struct TM_Action *action, enum TM_ActionState state) { if (state == TM_ACTIONSTATE_START) { // game->level.handle_input=false; @@ -75,16 +78,18 @@ bool Run(struct Game *game, struct TM_Action *action, enum TM_ActionState state) } else if (state == TM_ACTIONSTATE_DESTROY) { // game->level.derpy_angle = 0; - SelectDerpySpritesheet(game, "run"); +// SelectDerpySpritesheet(game, "run"); } else if (state != TM_ACTIONSTATE_RUNNING) return false; // game->level.derpy_y+=0.0042; // if (game->level.derpy_angle > 0) { game->level.derpy_angle -= 0.02; if (game->level.derpy_angle < 0) game->level.derpy_angle = 0; } // if (game->level.derpy_angle < 0) { game->level.derpy_angle += 0.02; if (game->level.derpy_angle > 0) game->level.derpy_angle = 0; } // if (game->level.derpy_y>=0.65) return true; + return true; return false; } +// args: struct Dodger* data bool GenerateObstacles(struct Game *game, struct TM_Action *action, enum TM_ActionState state) { int* count; if (!action->arguments) { @@ -175,5 +180,6 @@ bool GenerateObstacles(struct Game *game, struct TM_Action *action, enum TM_Acti TM_DestroyArgs(action->arguments); action->arguments = NULL; } + return true; return false; } diff --git a/src/levels/modules/moonwalk.c b/src/levels/modules/moonwalk.c index 34b69d9..0fd2bec 100644 --- a/src/levels/modules/moonwalk.c +++ b/src/levels/modules/moonwalk.c @@ -47,7 +47,7 @@ void Moonwalk_Logic(struct Game *game, struct Moonwalk *data) { void Moonwalk_Draw(struct Game *game, struct Moonwalk *data) { al_draw_scaled_bitmap(data->background,0,0,al_get_bitmap_width(data->background),al_get_bitmap_height(data->background),0,0,game->viewport.width, game->viewport.height, 0); - DrawCharacter(game, data->derpy, ALLEGRO_FLIP_HORIZONTAL); + DrawCharacter(game, data->derpy, al_map_rgba(255,255,255,255), ALLEGRO_FLIP_HORIZONTAL); } void Moonwalk_Start(struct Game *game, struct Moonwalk *data) { diff --git a/src/timeline.h b/src/timeline.h index a9f86ef..bc0421c 100644 --- a/src/timeline.h +++ b/src/timeline.h @@ -18,11 +18,14 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ + #ifndef TIMELINE_H #define TIMELINE_H #include "main.h" +#define TM_WrapArg(type, result, val) type* result = malloc(sizeof(type)); *result = val; + /*! \brief State of the TM_Action. */ enum TM_ActionState { TM_ACTIONSTATE_INIT,