mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2024-12-12 20:18:00 +01:00
lots of level 1 tweaks
This commit is contained in:
parent
d0ac545e4b
commit
001ed62181
8 changed files with 64 additions and 43 deletions
|
@ -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 ;_;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
*/
|
||||
#include <stdio.h>
|
||||
#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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue