mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2024-12-12 20:18:00 +01:00
make level 1 compilable... of course it doesn't work yet :D
This commit is contained in:
parent
ced56209c1
commit
f0c72edfd5
8 changed files with 233 additions and 206 deletions
|
@ -1,4 +1,4 @@
|
|||
add_library("libsuperderpy-muffinattack-levels" SHARED "actions.c" "../gamestates/level.c" "modules/moonwalk.c" "modules/dodger.c")
|
||||
add_library("libsuperderpy-muffinattack-levels" SHARED "actions.c" "../gamestates/level.c" "modules/moonwalk.c" "modules/dodger.c" "modules/dodger/actions.c" "modules/dodger/callbacks.c")
|
||||
|
||||
SET_TARGET_PROPERTIES("libsuperderpy-muffinattack-levels" PROPERTIES PREFIX "")
|
||||
|
||||
|
@ -19,7 +19,7 @@ MACRO(GAMESTATE name)
|
|||
|
||||
ENDMACRO()
|
||||
|
||||
#GAMESTATE("level1")
|
||||
GAMESTATE("level1")
|
||||
GAMESTATE("level2")
|
||||
GAMESTATE("level3")
|
||||
GAMESTATE("level4")
|
||||
|
|
|
@ -19,14 +19,17 @@
|
|||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include "allegro5/allegro_ttf.h"
|
||||
#include "../gamestates/level.h"
|
||||
#include "actions.h"
|
||||
#include "../utils.h"
|
||||
#include "modules/dodger.h"
|
||||
#include "modules/dodger/actions.h"
|
||||
#include "level1.h"
|
||||
|
||||
void Level1_Load(struct Game *game) {
|
||||
Dodger_Load(game, 1);
|
||||
int Gamestate_ProgressCount = 9001;
|
||||
|
||||
void Gamestate_Start(struct Game *game, struct Level1Resources* data) {
|
||||
TM_AddBackgroundAction(&FadeIn, NULL, 0, "fadein");
|
||||
TM_AddDelay(1000);
|
||||
TM_AddQueuedBackgroundAction(&Welcome, NULL, 0, "welcome");
|
||||
|
@ -75,41 +78,43 @@ void Level1_Load(struct Game *game) {
|
|||
obst->angle = 0;
|
||||
obst->callback = NULL;
|
||||
obst->data = NULL;
|
||||
obst->bitmap = &(game->level.level1.owl);
|
||||
game->level.dodger.obstacles = obst;
|
||||
obst->bitmap = &(data->owl);
|
||||
data->dodger->obstacles = obst;
|
||||
}
|
||||
|
||||
void Level1_Unload(struct Game *game) {
|
||||
Dodger_Unload(game);
|
||||
void Gamestate_Reload(struct Game *game, struct Level1Resources* data) {}
|
||||
|
||||
void Gamestate_Stop(struct Game *game, struct Level1Resources* data) {
|
||||
|
||||
}
|
||||
|
||||
void Level1_UnloadBitmaps(struct Game *game) {
|
||||
Dodger_UnloadBitmaps(game);
|
||||
al_destroy_font(game->level.letter_font);
|
||||
al_destroy_bitmap(game->level.letter);
|
||||
al_destroy_bitmap(game->level.level1.owl);
|
||||
void Gamestate_Unload(struct Game *game, struct Level1Resources* data) {
|
||||
Dodger_Unload(game, data->dodger);
|
||||
}
|
||||
|
||||
void Level1_Preload(struct Game *game) {
|
||||
Dodger_Preload(game);
|
||||
void Gamestate_UnloadBitmaps(struct Game *game, struct Level1Resources* data) {
|
||||
Dodger_UnloadBitmaps(game, data->dodger);
|
||||
al_destroy_font(data->letter_font);
|
||||
al_destroy_bitmap(data->letter);
|
||||
al_destroy_bitmap(data->owl);
|
||||
}
|
||||
|
||||
inline int Level1_PreloadSteps(void) {
|
||||
return 4+Dodger_PreloadSteps();
|
||||
}
|
||||
|
||||
void Level1_PreloadBitmaps(struct Game *game, void (*progress)(struct Game*, float)) {
|
||||
PROGRESS_INIT(Level1_PreloadSteps());
|
||||
game->level.level1.owl = LoadScaledBitmap("levels/1/owl.png", game->viewport.height*0.1275, game->viewport.height*0.1275);
|
||||
PROGRESS;
|
||||
game->level.letter_font = al_load_ttf_font(GetDataFilePath("fonts/DejaVuSans.ttf"),game->viewport.height*0.0225,0 );
|
||||
PROGRESS;
|
||||
game->level.letter = LoadScaledBitmap("levels/1/letter.png", game->viewport.height*1.3, game->viewport.height*1.2);
|
||||
al_set_target_bitmap(game->level.letter);
|
||||
void Gamestate_PreloadBitmaps(struct Game *game, struct Level1Resources* data) {
|
||||
data->welcome = al_create_bitmap(game->viewport.width, game->viewport.height/2);
|
||||
|
||||
data->font_title = al_load_ttf_font(GetDataFilePath(game, "fonts/ShadowsIntoLight.ttf"),game->viewport.height*0.16,0 );
|
||||
data->font_subtitle = al_load_ttf_font(GetDataFilePath(game, "fonts/ShadowsIntoLight.ttf"),game->viewport.height*0.08,0 );
|
||||
data->font = al_load_ttf_font(GetDataFilePath(game, "fonts/ShadowsIntoLight.ttf"),game->viewport.height*0.05,0 );
|
||||
|
||||
data->owl = LoadScaledBitmap(game, "levels/1/owl.png", game->viewport.height*0.1275, game->viewport.height*0.1275);
|
||||
data->letter_font = al_load_ttf_font(GetDataFilePath(game, "fonts/DejaVuSans.ttf"),game->viewport.height*0.0225,0 );
|
||||
data->letter = LoadScaledBitmap(game, "levels/1/letter.png", game->viewport.height*1.3, game->viewport.height*1.2);
|
||||
al_set_target_bitmap(data->letter);
|
||||
float y = 0.20;
|
||||
float x = 0.19;
|
||||
void draw_text(char* text) {
|
||||
al_draw_text(game->level.letter_font, al_map_rgb(0,0,0), al_get_bitmap_width(game->level.letter)*x, game->viewport.height*y, ALLEGRO_ALIGN_LEFT, text);
|
||||
al_draw_text(data->letter_font, al_map_rgb(0,0,0), al_get_bitmap_width(data->letter)*x, game->viewport.height*y, ALLEGRO_ALIGN_LEFT, text);
|
||||
y+=0.028;
|
||||
}
|
||||
draw_text("Dear Derpy,");
|
||||
|
@ -143,40 +148,62 @@ void Level1_PreloadBitmaps(struct Game *game, void (*progress)(struct Game*, flo
|
|||
x = 0.26;
|
||||
draw_text("Yours,");
|
||||
draw_text("Twilight Sparkle");
|
||||
al_draw_text_with_shadow(game->menu.font, al_map_rgb(255,255,255), al_get_bitmap_width(game->level.letter)*0.5, al_get_bitmap_height(game->level.letter)*0.8, ALLEGRO_ALIGN_CENTRE, "Press enter to continue...");
|
||||
DrawTextWithShadow(data->font, al_map_rgb(255,255,255), al_get_bitmap_width(data->letter)*0.5, al_get_bitmap_height(data->letter)*0.8, ALLEGRO_ALIGN_CENTRE, "Press enter to continue...");
|
||||
al_set_target_bitmap(al_get_backbuffer(game->display));
|
||||
PROGRESS;
|
||||
|
||||
al_set_target_bitmap(game->level.welcome);
|
||||
al_set_target_bitmap(data->welcome);
|
||||
al_clear_to_color(al_map_rgba(0,0,0,0));
|
||||
al_draw_text_with_shadow(game->menu.font_title, al_map_rgb(255,255,255), game->viewport.width*0.5, game->viewport.height*0.1, ALLEGRO_ALIGN_CENTRE, "Level 1");
|
||||
al_draw_text_with_shadow(game->menu.font_subtitle, al_map_rgb(255,255,255), game->viewport.width*0.5, game->viewport.height*0.275, ALLEGRO_ALIGN_CENTRE, "Fluttershy");
|
||||
PROGRESS;
|
||||
DrawTextWithShadow(data->font_title, al_map_rgb(255,255,255), game->viewport.width*0.5, game->viewport.height*0.1, ALLEGRO_ALIGN_CENTRE, "Level 1");
|
||||
DrawTextWithShadow(data->font_subtitle, al_map_rgb(255,255,255), game->viewport.width*0.5, game->viewport.height*0.275, ALLEGRO_ALIGN_CENTRE, "Fluttershy");
|
||||
|
||||
al_set_target_bitmap(al_get_backbuffer(game->display));
|
||||
|
||||
Dodger_PreloadBitmaps(game, progress);
|
||||
Dodger_PreloadBitmaps(game, data->dodger);
|
||||
}
|
||||
|
||||
void Level1_Draw(struct Game *game) {
|
||||
Dodger_Draw(game);
|
||||
struct Level1Resources* Gamestate_Load(struct Game *game) {
|
||||
TM_Init(game);
|
||||
|
||||
struct Level1Resources *data = malloc(sizeof(struct Level1Resources));
|
||||
struct Character *character = CreateCharacter(game, "derpy");
|
||||
RegisterSpritesheet(game, character, "walk");
|
||||
RegisterSpritesheet(game, character, "stand");
|
||||
RegisterSpritesheet(game, character, "fly");
|
||||
RegisterSpritesheet(game, character, "run");
|
||||
SelectSpritesheet(game, character, "stand");
|
||||
data->dodger = Dodger_Load(game, character);
|
||||
|
||||
Gamestate_PreloadBitmaps(game, data);
|
||||
LoadSpritesheets(game, character);
|
||||
return data;
|
||||
}
|
||||
|
||||
void Level1_Logic(struct Game *game) {
|
||||
Dodger_Logic(game);
|
||||
|
||||
void Gamestate_Draw(struct Game *game, struct Level1Resources* data) {
|
||||
Dodger_Draw(game, data->dodger);
|
||||
}
|
||||
|
||||
void Level1_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
|
||||
Dodger_Keydown(game, ev);
|
||||
void Gamestate_Logic(struct Game *game, struct Level1Resources* data) {
|
||||
Dodger_Logic(game, data->dodger);
|
||||
}
|
||||
|
||||
void Level1_ProcessEvent(struct Game *game, ALLEGRO_EVENT *ev) {
|
||||
Dodger_ProcessEvent(game, ev);
|
||||
void Gamestate_Keydown(struct Game *game, struct Level1Resources* data, ALLEGRO_EVENT *ev) {
|
||||
Dodger_Keydown(game, data->dodger, ev);
|
||||
}
|
||||
|
||||
void Level1_Resume(struct Game *game) {
|
||||
Dodger_Resume(game);
|
||||
void Gamestate_ProcessEvent(struct Game *game, struct Level1Resources* data, ALLEGRO_EVENT *ev) {
|
||||
Dodger_ProcessEvent(game, data->dodger, ev);
|
||||
if (ev->type == ALLEGRO_EVENT_KEY_DOWN) {
|
||||
if (ev->keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
|
||||
SwitchGamestate(game, "level1", "map");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Level1_Pause(struct Game *game) {
|
||||
Dodger_Pause(game);
|
||||
void Gamestate_Resume(struct Game *game, struct Level1Resources* data) {
|
||||
Dodger_Resume(game, data->dodger);
|
||||
}
|
||||
|
||||
void Gamestate_Pause(struct Game *game, struct Level1Resources* data) {
|
||||
Dodger_Pause(game, data->dodger);
|
||||
}
|
||||
|
|
|
@ -20,15 +20,62 @@
|
|||
*/
|
||||
#include "../main.h"
|
||||
|
||||
void Level1_Load(struct Game *game);
|
||||
void Level1_Unload(struct Game *game);
|
||||
void Level1_UnloadBitmaps(struct Game *game);
|
||||
void Level1_Preload(struct Game *game);
|
||||
void Level1_PreloadBitmaps(struct Game *game, void (*progress)(struct Game*, float));
|
||||
inline int Level1_PreloadSteps(void);
|
||||
void Level1_Draw(struct Game *game);
|
||||
void Level1_Logic(struct Game *game);
|
||||
void Level1_Keydown(struct Game *game, ALLEGRO_EVENT *ev);
|
||||
void Level1_ProcessEvent(struct Game *game, ALLEGRO_EVENT *ev);
|
||||
void Level1_Resume(struct Game *game);
|
||||
void Level1_Pause(struct Game *game);
|
||||
struct Dodger;
|
||||
struct Level1Resources {
|
||||
struct Dodger *dodger;
|
||||
|
||||
ALLEGRO_FONT *letter_font; /*!< Font used in letter from Twilight on first level. */
|
||||
ALLEGRO_SAMPLE *sample; /*!< Sample with background music. */
|
||||
ALLEGRO_SAMPLE_INSTANCE *music; /*!< Sample instance with background music. */
|
||||
unsigned int music_pos; /*!< Position of sample instance. Used when pausing game. */
|
||||
ALLEGRO_BITMAP *background; /*!< Bitmap of the background layer of the scene. */
|
||||
ALLEGRO_BITMAP *stage; /*!< Bitmap of the stage layer of the scene. */
|
||||
ALLEGRO_BITMAP *foreground; /*!< Bitmap of the foreground layer of the scene. */
|
||||
ALLEGRO_BITMAP *clouds; /*!< Bitmap of the clouds layer of the scene. */
|
||||
ALLEGRO_BITMAP *welcome; /*!< Bitmap of the welcome text (for instance "Level 1: Fluttershy"). */
|
||||
ALLEGRO_BITMAP **derpy_sheet; /*!< Pointer to active Derpy sprite sheet. */
|
||||
ALLEGRO_BITMAP *derpy_bmp; /*!< Derpy sprite. */
|
||||
ALLEGRO_BITMAP *meter_bmp; /*!< Bitmap of the HP meter. */
|
||||
ALLEGRO_BITMAP *meter_image; /*!< Derpy image used in the HP meter. */
|
||||
ALLEGRO_BITMAP *letter; /*!< Bitmap with letter from Twilight. */
|
||||
struct Character *derpy;
|
||||
struct {
|
||||
ALLEGRO_BITMAP *pie1; /*!< Pie bitmap. */
|
||||
ALLEGRO_BITMAP *pie2; /*!< Pie bitmap (crossed). */
|
||||
ALLEGRO_BITMAP *muffin; /*!< Good muffin bitmap. */
|
||||
ALLEGRO_BITMAP *badmuffin; /*!< Bad muffin bitmap. */
|
||||
ALLEGRO_BITMAP *cherry; /*!< Cherry bitmap. */
|
||||
ALLEGRO_BITMAP *pig; /*!< Pig spritesheet bitmap. */
|
||||
ALLEGRO_BITMAP *screwball; /*!< Screwball spritesheet bitmap. */
|
||||
} obst_bmps; /*!< Obstacle bitmaps. */
|
||||
|
||||
float bg_pos; /*!< Position of the background layer of the scene. */
|
||||
float st_pos; /*!< Position of the stage layer of the scene. */
|
||||
float fg_pos; /*!< Position of the foreground layer of the scene. */
|
||||
float cl_pos; /*!< Position of the clouds layer of the scene. */
|
||||
|
||||
ALLEGRO_FONT *font;
|
||||
ALLEGRO_FONT *font_title;
|
||||
ALLEGRO_FONT *font_subtitle;
|
||||
|
||||
bool handle_input; /*!< When false, player looses control over Derpy. */
|
||||
|
||||
bool failed; /*!< Indicates if player failed level. */
|
||||
bool unloading; /*!< Indicated if level is already being unloaded. */
|
||||
|
||||
float meter_alpha; /*!< Alpha level of HP meter. */
|
||||
//int sheet_rows; /*!< Number of rows in current spritesheet. */
|
||||
//int sheet_cols; /*!< Number of cols in current spritesheet. */
|
||||
//int sheet_pos; /*!< Frame position in current spritesheet. */
|
||||
//int sheet_blanks; /*!< Number of blank frames at the end of current spritesheet. */
|
||||
//char* sheet_successor; /*!< Successor of current animation. If blank, then it's looped. */
|
||||
//float sheet_tmp; /*!< Temporary counter used to slow down spritesheet animation. */
|
||||
//float sheet_speed; /*!< Current speed of Derpy animation. */
|
||||
//float sheet_speed_modifier; /*!< Modifier of speed, specified by current spritesheet. */
|
||||
//float sheet_scale; /*!< Scale modifier of current spritesheet. */
|
||||
|
||||
//struct Spritesheet* derpy_sheets; /*!< List of spritesheets of Derpy character. */
|
||||
//struct Spritesheet* pony_sheets; /*!< List of spritesheets of character rescued by Derpy. */
|
||||
ALLEGRO_BITMAP *owl; /*!< Owlicious bitmap. */
|
||||
|
||||
};
|
||||
|
|
|
@ -31,18 +31,16 @@ void Dodger_Logic(struct Game *game, struct Dodger* data) {
|
|||
struct ALLEGRO_KEYBOARD_STATE keyboard;
|
||||
al_get_keyboard_state(&keyboard);
|
||||
if (data->handle_input) {
|
||||
if (data->derpy_angle > 0) { data->derpy_angle -= 0.02; if (data->derpy_angle < 0) data->derpy_angle = 0; }
|
||||
if (data->derpy_angle < 0) { data->derpy_angle += 0.02; if (data->derpy_angle > 0) data->derpy_angle = 0; }
|
||||
if (data->character->angle > 0) { data->character->angle -= 0.02; if (data->character->angle < 0) data->character->angle = 0; }
|
||||
if (data->character->angle < 0) { data->character->angle += 0.02; if (data->character->angle > 0) data->character->angle = 0; }
|
||||
if (al_key_down(&keyboard, ALLEGRO_KEY_UP)) {
|
||||
data->derpy_y -= 0.005;
|
||||
data->derpy_angle -= 0.03;
|
||||
if (data->derpy_angle < -0.15) data->derpy_angle = -0.15;
|
||||
MoveCharacter(game, data->character, 0, -0.005, -0.03);
|
||||
if (data->character->angle < -0.15) data->character->angle = -0.15;
|
||||
/*PrintConsole(game, "Derpy Y position: %f", data->derpy_y);*/
|
||||
}
|
||||
if (al_key_down(&keyboard, ALLEGRO_KEY_DOWN)) {
|
||||
data->derpy_y += 0.005;
|
||||
data->derpy_angle += 0.03;
|
||||
if (data->derpy_angle > 0.15) data->derpy_angle = 0.15;
|
||||
MoveCharacter(game, data->character, 0, 0.005, 0.03);
|
||||
if (data->character->angle > 0.15) data->character->angle = 0.15;
|
||||
/*PrintConsole(game, "Derpy Y position: %f", data->derpy_y);*/
|
||||
}
|
||||
/*if ((data->derpy_y > 0.6) && (data->flying)) {
|
||||
|
@ -56,18 +54,18 @@ void Dodger_Logic(struct Game *game, struct Dodger* data) {
|
|||
data->sheet_speed = tps(game, 60*2.4);
|
||||
}
|
||||
if (!data->flying) data->sheet_speed = tps(game, 60*0.0020/data->speed); */
|
||||
if (data->derpy_y < 0) data->derpy_y=0;
|
||||
else if (data->derpy_y > 0.8) data->derpy_y=0.8;
|
||||
if ( data->character->y < 0) data->character->y=0;
|
||||
else if ( data->character->y > 0.8) data->character->y=0.8;
|
||||
|
||||
data->derpy_y += data->derpy_angle / 30;
|
||||
data->character->y += data->character->angle / 30;
|
||||
}
|
||||
|
||||
int derpyx = data->derpy_x*game->viewport.height*1.6;
|
||||
int derpyy = data->derpy_y*game->viewport.height;
|
||||
int derpyw = al_get_bitmap_width(data->derpy);
|
||||
int derpyh = al_get_bitmap_height(data->derpy);
|
||||
int derpyo = game->viewport.height*1.6*0.1953125-al_get_bitmap_width(data->derpy); /* offset */
|
||||
struct Obstacle *tmp = data->dodger.obstacles;
|
||||
int derpyx = data->character->x*game->viewport.height*1.6;
|
||||
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);
|
||||
int derpyo = game->viewport.height*1.6*0.1953125-al_get_bitmap_width(data->character->bitmap); /* offset */
|
||||
struct Obstacle *tmp = data->obstacles;
|
||||
while (tmp) {
|
||||
/*PrintConsole(game, "DRAWING %f %f", tmp->x, tmp->y);*/
|
||||
int x = (tmp->x/100.0)*game->viewport.width;
|
||||
|
@ -105,7 +103,7 @@ void Dodger_Logic(struct Game *game, struct Dodger* data) {
|
|||
TM_AddBackgroundAction(&LevelFailed, NULL, 0, "levelfailed");
|
||||
}
|
||||
}
|
||||
tmp->x -= data->speed*data->speed_modifier*tmp->speed*100*al_get_bitmap_width(data->stage)/(float)game->viewport.width;
|
||||
tmp->x -= data->speed*data->speed_modifier*tmp->speed*100*al_get_display_width(game->display)/(float)game->viewport.width;
|
||||
if (tmp->callback) tmp->callback(game, tmp);
|
||||
tmp = tmp->next;
|
||||
} else {
|
||||
|
@ -114,7 +112,7 @@ void Dodger_Logic(struct Game *game, struct Dodger* data) {
|
|||
if (tmp->prev)
|
||||
tmp->prev->next = tmp->next;
|
||||
else
|
||||
data->dodger.obstacles = tmp->next;
|
||||
data->obstacles = tmp->next;
|
||||
struct Obstacle *t = tmp;
|
||||
tmp = tmp->next;
|
||||
free(t);
|
||||
|
@ -125,13 +123,13 @@ void Dodger_Logic(struct Game *game, struct Dodger* data) {
|
|||
}
|
||||
|
||||
void Dodger_Draw(struct Game *game, struct Dodger* data) {
|
||||
int derpyx = data->derpy_x*game->viewport.height*1.6;
|
||||
int derpyy = data->derpy_y*game->viewport.height;
|
||||
int derpyw = al_get_bitmap_width(data->derpy);
|
||||
int derpyh = al_get_bitmap_height(data->derpy);
|
||||
int derpyo = game->viewport.height*1.6*0.1953125-al_get_bitmap_width(data->derpy); /* offset */
|
||||
int derpyx = data->character->x*game->viewport.height*1.6;
|
||||
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);
|
||||
int derpyo = game->viewport.height*1.6*0.1953125-al_get_bitmap_width(data->character->bitmap); /* offset */
|
||||
bool colision = false;
|
||||
struct Obstacle *tmp = data->dodger.obstacles;
|
||||
struct Obstacle *tmp = data->obstacles;
|
||||
while (tmp) {
|
||||
/*PrintConsole(game, "DRAWING %f %f", tmp->x, tmp->y);*/
|
||||
int x = (tmp->x/100.0)*game->viewport.width;
|
||||
|
@ -162,7 +160,7 @@ void Dodger_Draw(struct Game *game, struct Dodger* data) {
|
|||
if (tmp->prev)
|
||||
tmp->prev->next = tmp->next;
|
||||
else
|
||||
data->dodger.obstacles = tmp->next;
|
||||
data->obstacles = tmp->next;
|
||||
struct Obstacle *t = tmp;
|
||||
tmp = tmp->next;
|
||||
free(t);
|
||||
|
@ -170,12 +168,12 @@ void Dodger_Draw(struct Game *game, struct Dodger* data) {
|
|||
}
|
||||
/*if (colision) data->hp-=tps(game, 60*0.002);*/
|
||||
|
||||
al_set_target_bitmap(data->derpy);
|
||||
al_set_target_bitmap(data->character->bitmap);
|
||||
al_clear_to_color(al_map_rgba(0,0,0,0));
|
||||
al_draw_bitmap_region(*(data->derpy_sheet),al_get_bitmap_width(data->derpy)*(data->sheet_pos%data->sheet_cols),al_get_bitmap_height(data->derpy)*(data->sheet_pos/data->sheet_cols),al_get_bitmap_width(data->derpy), al_get_bitmap_height(data->derpy),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->derpy, al_map_rgba(255,255-colision*255,255-colision*255,255), al_get_bitmap_width(data->derpy), al_get_bitmap_height(data->derpy)/2, derpyx+game->viewport.height*1.6*0.1953125, derpyy + al_get_bitmap_height(data->derpy)/2, data->derpy_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);
|
||||
|
||||
/* 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)))) {
|
||||
|
@ -186,14 +184,10 @@ void Dodger_Draw(struct Game *game, struct Dodger* data) {
|
|||
}
|
||||
}
|
||||
|
||||
struct Dodger* Dodger_Load(struct Game *game, int current_level) {
|
||||
struct Dodger* Dodger_Load(struct Game *game, struct Character *character) {
|
||||
struct Dodger *data = malloc(sizeof(struct Dodger));
|
||||
data->dodger.obstacles = NULL;
|
||||
data->character = CreateCharacter(game, "derpy");
|
||||
RegisterSpritesheet(game, data->character, "walk");
|
||||
RegisterSpritesheet(game, data->character, "stand");
|
||||
RegisterSpritesheet(game, data->character, "fly");
|
||||
RegisterSpritesheet(game, data->character, "run");
|
||||
data->obstacles = NULL;
|
||||
data->character = character;
|
||||
return data;
|
||||
}
|
||||
|
||||
|
@ -231,36 +225,36 @@ inline int Dodger_PreloadSteps(void) {
|
|||
return 7;
|
||||
}
|
||||
|
||||
void Dodger_PreloadBitmaps(struct Game *game, struct Dodger* data, void (*progress)(struct Game*, float)) {
|
||||
void Dodger_PreloadBitmaps(struct Game *game, struct Dodger* data) {
|
||||
//PROGRESS_INIT(Dodger_PreloadSteps());
|
||||
data->dodger.obst_bmps.pie1 = LoadScaledBitmap(game, "levels/dodger/pie1.png", game->viewport.height*1.6*0.1, game->viewport.height*0.08);
|
||||
data->obst_bmps.pie1 = LoadScaledBitmap(game, "levels/dodger/pie1.png", game->viewport.height*1.6*0.1, game->viewport.height*0.08);
|
||||
|
||||
data->dodger.obst_bmps.pie2 = LoadScaledBitmap(game, "levels/dodger/pie2.png", game->viewport.height*1.6*0.1, game->viewport.height*0.08);
|
||||
data->obst_bmps.pie2 = LoadScaledBitmap(game, "levels/dodger/pie2.png", game->viewport.height*1.6*0.1, game->viewport.height*0.08);
|
||||
|
||||
data->dodger.obst_bmps.pig = LoadScaledBitmap(game, "levels/dodger/pig.png", (int)(game->viewport.height*1.6*0.15)*3, (int)(game->viewport.height*0.2)*3);
|
||||
data->obst_bmps.pig = LoadScaledBitmap(game, "levels/dodger/pig.png", (int)(game->viewport.height*1.6*0.15)*3, (int)(game->viewport.height*0.2)*3);
|
||||
|
||||
data->dodger.obst_bmps.screwball = LoadScaledBitmap(game, "levels/dodger/screwball.png", (int)(game->viewport.height*0.2)*4*1.4, (int)(game->viewport.height*0.2)*4);
|
||||
data->obst_bmps.screwball = LoadScaledBitmap(game, "levels/dodger/screwball.png", (int)(game->viewport.height*0.2)*4*1.4, (int)(game->viewport.height*0.2)*4);
|
||||
|
||||
data->dodger.obst_bmps.muffin = LoadScaledBitmap(game, "levels/dodger/muffin.png", game->viewport.height*1.6*0.07, game->viewport.height*0.1);
|
||||
data->obst_bmps.muffin = LoadScaledBitmap(game, "levels/dodger/muffin.png", game->viewport.height*1.6*0.07, game->viewport.height*0.1);
|
||||
|
||||
data->dodger.obst_bmps.cherry = LoadScaledBitmap(game, "levels/dodger/cherry.png", game->viewport.height*1.6*0.03, game->viewport.height*0.08);
|
||||
data->obst_bmps.cherry = LoadScaledBitmap(game, "levels/dodger/cherry.png", game->viewport.height*1.6*0.03, game->viewport.height*0.08);
|
||||
|
||||
data->dodger.obst_bmps.badmuffin = LoadScaledBitmap(game, "levels/dodger/badmuffin.png", game->viewport.height*1.6*0.07, game->viewport.height*0.1);
|
||||
data->obst_bmps.badmuffin = LoadScaledBitmap(game, "levels/dodger/badmuffin.png", game->viewport.height*1.6*0.07, game->viewport.height*0.1);
|
||||
|
||||
}
|
||||
|
||||
void Dodger_UnloadBitmaps(struct Game *game, struct Dodger* data) {
|
||||
al_destroy_bitmap(data->dodger.obst_bmps.pie1);
|
||||
al_destroy_bitmap(data->dodger.obst_bmps.pie2);
|
||||
al_destroy_bitmap(data->dodger.obst_bmps.pig);
|
||||
al_destroy_bitmap(data->dodger.obst_bmps.cherry);
|
||||
al_destroy_bitmap(data->dodger.obst_bmps.muffin);
|
||||
al_destroy_bitmap(data->dodger.obst_bmps.badmuffin);
|
||||
al_destroy_bitmap(data->dodger.obst_bmps.screwball);
|
||||
al_destroy_bitmap(data->obst_bmps.pie1);
|
||||
al_destroy_bitmap(data->obst_bmps.pie2);
|
||||
al_destroy_bitmap(data->obst_bmps.pig);
|
||||
al_destroy_bitmap(data->obst_bmps.cherry);
|
||||
al_destroy_bitmap(data->obst_bmps.muffin);
|
||||
al_destroy_bitmap(data->obst_bmps.badmuffin);
|
||||
al_destroy_bitmap(data->obst_bmps.screwball);
|
||||
}
|
||||
|
||||
void Dodger_Unload(struct Game *game, struct Dodger* data) {
|
||||
struct Obstacle *t = data->dodger.obstacles;
|
||||
struct Obstacle *t = data->obstacles;
|
||||
if (t) {
|
||||
while (t->next) {
|
||||
if (t->prev) free(t->prev);
|
||||
|
@ -268,13 +262,7 @@ void Dodger_Unload(struct Game *game, struct Dodger* data) {
|
|||
}
|
||||
free(t);
|
||||
}
|
||||
struct Spritesheet *tmp, *s = data->derpy_sheets;
|
||||
tmp = s;
|
||||
while (s) {
|
||||
tmp = s;
|
||||
s = s->next;
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
DestroyCharacter(game, data->character);
|
||||
free(data);
|
||||
}
|
||||
|
|
|
@ -20,72 +20,6 @@
|
|||
*/
|
||||
#include "../../main.h"
|
||||
|
||||
struct Dodger {
|
||||
|
||||
struct Character *character; /* TODO: move to level */
|
||||
|
||||
struct {
|
||||
struct {
|
||||
ALLEGRO_BITMAP *pie1; /*!< Pie bitmap. */
|
||||
ALLEGRO_BITMAP *pie2; /*!< Pie bitmap (crossed). */
|
||||
ALLEGRO_BITMAP *muffin; /*!< Good muffin bitmap. */
|
||||
ALLEGRO_BITMAP *badmuffin; /*!< Bad muffin bitmap. */
|
||||
ALLEGRO_BITMAP *cherry; /*!< Cherry bitmap. */
|
||||
ALLEGRO_BITMAP *pig; /*!< Pig spritesheet bitmap. */
|
||||
ALLEGRO_BITMAP *screwball; /*!< Screwball spritesheet bitmap. */
|
||||
} obst_bmps; /*!< Obstacle bitmaps. */
|
||||
struct Obstacle *obstacles; /*!< List of obstacles being currently rendered. */
|
||||
} dodger;
|
||||
|
||||
|
||||
struct {
|
||||
int current_level; /*!< Level number. */
|
||||
} input; /*!< Gamestate input data. */
|
||||
int current_level; /*!< Level number. */
|
||||
float speed; /*!< Speed of the player. */
|
||||
float speed_modifier; /*!< Modifier of the speed of the player. */
|
||||
float bg_pos; /*!< Position of the background layer of the scene. */
|
||||
float st_pos; /*!< Position of the stage layer of the scene. */
|
||||
float fg_pos; /*!< Position of the foreground layer of the scene. */
|
||||
float cl_pos; /*!< Position of the clouds layer of the scene. */
|
||||
float derpy_x; /*!< Horizontal position of Derpy (0-1). */
|
||||
float derpy_y; /*!< Vertical position of Derpy (0-1). */
|
||||
float derpy_angle; /*!< Angle of Derpy sprite on screen (radians). */
|
||||
float hp; /*!< Player health points (0-1). */
|
||||
bool handle_input; /*!< When false, player looses control over Derpy. */
|
||||
bool failed; /*!< Indicates if player failed level. */
|
||||
bool unloading; /*!< Indicated if level is already being unloaded. */
|
||||
float meter_alpha; /*!< Alpha level of HP meter. */
|
||||
int sheet_rows; /*!< Number of rows in current spritesheet. */
|
||||
int sheet_cols; /*!< Number of cols in current spritesheet. */
|
||||
int sheet_pos; /*!< Frame position in current spritesheet. */
|
||||
int sheet_blanks; /*!< Number of blank frames at the end of current spritesheet. */
|
||||
char* sheet_successor; /*!< Successor of current animation. If blank, then it's looped. */
|
||||
float sheet_tmp; /*!< Temporary counter used to slow down spritesheet animation. */
|
||||
float sheet_speed; /*!< Current speed of Derpy animation. */
|
||||
float sheet_speed_modifier; /*!< Modifier of speed, specified by current spritesheet. */
|
||||
float sheet_scale; /*!< Scale modifier of current spritesheet. */
|
||||
ALLEGRO_FONT *letter_font; /*!< Font used in letter from Twilight on first level. */
|
||||
ALLEGRO_SAMPLE *sample; /*!< Sample with background music. */
|
||||
ALLEGRO_SAMPLE_INSTANCE *music; /*!< Sample instance with background music. */
|
||||
unsigned int music_pos; /*!< Position of sample instance. Used when pausing game. */
|
||||
ALLEGRO_BITMAP *background; /*!< Bitmap of the background layer of the scene. */
|
||||
ALLEGRO_BITMAP *stage; /*!< Bitmap of the stage layer of the scene. */
|
||||
ALLEGRO_BITMAP *foreground; /*!< Bitmap of the foreground layer of the scene. */
|
||||
ALLEGRO_BITMAP *clouds; /*!< Bitmap of the clouds layer of the scene. */
|
||||
ALLEGRO_BITMAP *welcome; /*!< Bitmap of the welcome text (for instance "Level 1: Fluttershy"). */
|
||||
ALLEGRO_BITMAP **derpy_sheet; /*!< Pointer to active Derpy sprite sheet. */
|
||||
ALLEGRO_BITMAP *derpy; /*!< Derpy sprite. */
|
||||
ALLEGRO_BITMAP *meter_bmp; /*!< Bitmap of the HP meter. */
|
||||
ALLEGRO_BITMAP *meter_image; /*!< Derpy image used in the HP meter. */
|
||||
ALLEGRO_BITMAP *letter; /*!< Bitmap with letter from Twilight. */
|
||||
bool debug_show_sprite_frames; /*!< When true, displays colorful borders around spritesheets and their active areas. */
|
||||
struct Spritesheet* derpy_sheets; /*!< List of spritesheets of Derpy character. */
|
||||
//struct Spritesheet* pony_sheets; /*!< List of spritesheets of character rescued by Derpy. */
|
||||
struct {
|
||||
ALLEGRO_BITMAP *owl; /*!< Owlicious bitmap. */
|
||||
} level1; /*!< Resources used by level 1. */
|
||||
};
|
||||
|
||||
/*! \brief Structure representing obstacles and power-ups flying through the level. */
|
||||
struct Obstacle {
|
||||
|
@ -110,12 +44,38 @@ struct Obstacle {
|
|||
struct Obstacle *next; /*!< Next obstacle on the list. */
|
||||
};
|
||||
|
||||
struct Dodger {
|
||||
|
||||
|
||||
struct Obstacle *obstacles; /*!< List of obstacles being currently rendered. */
|
||||
struct Obstacle *possible_obstacles; /* TODO: make list of used obstacles dynamic */
|
||||
float speed; /*!< Speed of the player. */
|
||||
float speed_modifier; /*!< Modifier of the speed of the player. */
|
||||
float hp; /*!< Player health points (0-1). */
|
||||
bool debug_show_sprite_frames; /*!< When true, displays colorful borders around spritesheets and their active areas. */
|
||||
struct Character *character;
|
||||
bool failed;
|
||||
bool handle_input; /*!< When false, player looses control over Derpy. */
|
||||
|
||||
struct {
|
||||
ALLEGRO_BITMAP *pie1; /*!< Pie bitmap. */
|
||||
ALLEGRO_BITMAP *pie2; /*!< Pie bitmap (crossed). */
|
||||
ALLEGRO_BITMAP *muffin; /*!< Good muffin bitmap. */
|
||||
ALLEGRO_BITMAP *badmuffin; /*!< Bad muffin bitmap. */
|
||||
ALLEGRO_BITMAP *cherry; /*!< Cherry bitmap. */
|
||||
ALLEGRO_BITMAP *pig; /*!< Pig spritesheet bitmap. */
|
||||
ALLEGRO_BITMAP *screwball; /*!< Screwball spritesheet bitmap. */
|
||||
} obst_bmps; /*!< Obstacle bitmaps. */
|
||||
|
||||
};
|
||||
|
||||
void Dodger_PreloadBitmaps(struct Game *game, struct Dodger* data);
|
||||
void Dodger_Keydown(struct Game *game, struct Dodger* data, ALLEGRO_EVENT *ev);
|
||||
|
||||
void Dodger_Draw(struct Game *game, struct Dodger *data);
|
||||
void Dodger_Logic(struct Game *game, struct Dodger *data);
|
||||
void Dodger_Start(struct Game *game, struct Dodger *data);
|
||||
void Dodger_Stop(struct Game *game, struct Dodger *data);
|
||||
void Dodger_Unload(struct Game *game, struct Dodger *data);
|
||||
struct Dodger* Dodger_Load(struct Game *game, int current_level);
|
||||
struct Dodger* Dodger_Load(struct Game *game, struct Character *character);
|
||||
void Dodger_UnloadBitmaps(struct Game *game, struct Dodger *data);
|
||||
void Dodger_LoadBitmaps(struct Game *game, struct Dodger *data, void (*progress)(struct Game*, float));
|
||||
void Dodger_ProcessEvent(struct Game *game, struct Dodger *data, ALLEGRO_EVENT *ev);
|
||||
|
|
|
@ -24,11 +24,15 @@
|
|||
#include "../../actions.h"
|
||||
#include "../../../gamestates/level.h"
|
||||
|
||||
void SelectDerpySpritesheet(void* a, void* b) {
|
||||
|
||||
}
|
||||
|
||||
// TODO: make it configurable and move to generic actions
|
||||
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;
|
||||
if (game->level.speed>=0.0025) return true;
|
||||
//game->level.speed+=0.000015;
|
||||
//if (game->level.speed>=0.0025) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -36,48 +40,48 @@ bool Accelerate(struct Game *game, struct TM_Action *action, enum TM_ActionState
|
|||
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;
|
||||
//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
|
||||
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;
|
||||
// game->level.speed=0.000345;
|
||||
// if (game->level.st_pos>=0.275) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Fly(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
|
||||
if (state == TM_ACTIONSTATE_START) {
|
||||
SelectDerpySpritesheet(game, "fly");
|
||||
game->level.derpy_angle = -0.15;
|
||||
// game->level.derpy_angle = -0.15;
|
||||
TM_AddBackgroundAction(&ShowMeter, NULL, 0, "showmeter");
|
||||
}
|
||||
else if (state == TM_ACTIONSTATE_DESTROY) {
|
||||
game->level.handle_input = true;
|
||||
// game->level.handle_input = true;
|
||||
}
|
||||
else if (state != TM_ACTIONSTATE_RUNNING) return false;
|
||||
game->level.derpy_y-=0.004;
|
||||
if (game->level.derpy_y<=0.2) return true;
|
||||
// game->level.derpy_y-=0.004;
|
||||
// if (game->level.derpy_y<=0.2) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Run(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
|
||||
if (state == TM_ACTIONSTATE_START) {
|
||||
game->level.handle_input=false;
|
||||
game->level.speed_modifier=1;
|
||||
// game->level.handle_input=false;
|
||||
// game->level.speed_modifier=1;
|
||||
}
|
||||
else if (state == TM_ACTIONSTATE_DESTROY) {
|
||||
game->level.derpy_angle = 0;
|
||||
// game->level.derpy_angle = 0;
|
||||
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;
|
||||
// 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 false;
|
||||
}
|
||||
|
||||
|
@ -91,7 +95,7 @@ bool GenerateObstacles(struct Game *game, struct TM_Action *action, enum TM_Acti
|
|||
*count = 0;
|
||||
}
|
||||
else if (state == TM_ACTIONSTATE_RUNNING) {
|
||||
if (rand()%(10000/(int)(85*game->level.speed_modifier))<=3) {
|
||||
/* if (rand()%(10000/(int)(85*game->level.speed_modifier))<=3) {
|
||||
PrintConsole(game, "OBSTACLE %d", *count);
|
||||
(*count)++;
|
||||
struct Obstacle *obst = malloc(sizeof(struct Obstacle));
|
||||
|
@ -165,7 +169,7 @@ bool GenerateObstacles(struct Game *game, struct TM_Action *action, enum TM_Acti
|
|||
}
|
||||
game->level.dodger.obstacles = obst;
|
||||
if (*count > 128) return true;
|
||||
}
|
||||
}*/
|
||||
} else if (state == TM_ACTIONSTATE_DESTROY) {
|
||||
free(action->arguments->value);
|
||||
TM_DestroyArgs(action->arguments);
|
||||
|
|
|
@ -30,7 +30,7 @@ void Obst_MoveUpDown(struct Game *game, struct Obstacle *obstacle) {
|
|||
}
|
||||
} else {
|
||||
obstacle->y += 0.5;
|
||||
if (obstacle->y>=((game->viewportHeight-al_get_bitmap_height(*(obstacle->bitmap))/obstacle->rows)/(float)game->viewportHeight)*100) {
|
||||
if (obstacle->y>=((game->viewport.height-al_get_bitmap_height(*(obstacle->bitmap))/obstacle->rows)/(float)game->viewport.height)*100) {
|
||||
*((bool*)obstacle->data)=true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "../dodger.h"
|
||||
#include "../../../main.h"
|
||||
|
||||
/*! \brief Move up or down until reaching the edge of the screen. After that - change direction. */
|
||||
|
|
Loading…
Reference in a new issue