tweaks and estetics for level2/moonwalk code

This commit is contained in:
Sebastian Krzyszkowiak 2013-02-26 00:59:20 +01:00
parent 91d3bb0d59
commit e85fcdf8a6
6 changed files with 33 additions and 10 deletions

View file

@ -25,6 +25,9 @@
#include <stdio.h>
// TODO: move this file to better place
// it's now a place for level related utilities - certainly not a gamestate
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);

View file

@ -20,10 +20,12 @@
*/
#include <stdio.h>
#include "allegro5/allegro_ttf.h"
#include "../gamestates/level.h"
#include "modules/moonwalk.h"
#include "../timeline.h"
#include "actions.h"
#include "../utils.h"
#include "level2.h"
@ -31,18 +33,24 @@ void* Gamestate_Load(struct Game *game, void (*progress)(struct Game*)) {
struct Level2Resources *data = malloc(sizeof(struct Level2Resources));
data->moonwalk = Moonwalk_Load(game, 2);
(*progress)(game);
struct TM_Arguments *args = TM_AddToArgs(NULL, strdup("level2"));
int* level = malloc(sizeof(int));
*level=2;
TM_AddToArgs(args, level);
TM_AddAction(&PassLevel, args, "passlevel");
(*progress)(game);
data->font = al_load_ttf_font(GetDataFilePath(game, "fonts/ShadowsIntoLight.ttf"),game->viewport.height*0.09,0 );
(*progress)(game);
return data;
}
void Gamestate_Unload(struct Game *game, struct Level2Resources* data) {
Moonwalk_Unload(game, data->moonwalk);
al_destroy_font(data->font);
free(data);
}
@ -56,10 +64,9 @@ void Gamestate_Stop(struct Game *game, struct Level2Resources* data) {
void Gamestate_Draw(struct Game *game, struct Level2Resources* data) {
Moonwalk_Draw(game, data->moonwalk);
al_draw_textf(game->_priv.font, al_map_rgb(255,255,255), game->viewport.width/2, game->viewport.height/2.2, ALLEGRO_ALIGN_CENTRE, "Level %d: Not implemented yet!", 2);
al_draw_text(game->_priv.font, al_map_rgb(255,255,255), game->viewport.width/2, game->viewport.height/1.8, ALLEGRO_ALIGN_CENTRE, "Have some moonwalk instead.");
// FIXME: _priv... please fix me :/
al_draw_textf(data->font, al_map_rgb(255,255,255), game->viewport.width/2, game->viewport.height/2.2, ALLEGRO_ALIGN_CENTRE, "Level %d: Not implemented yet!", 2);
al_draw_text(data->font, al_map_rgb(255,255,255), game->viewport.width/2, game->viewport.height/1.8, ALLEGRO_ALIGN_CENTRE, "Have some moonwalk instead.");
}
void Gamestate_Logic(struct Game *game, struct Level2Resources* data) {
@ -85,4 +92,4 @@ void Gamestate_Pause(struct Game *game, struct Level2Resources* data) {
void Gamestate_Reload(struct Game *game, struct Level2Resources* data) {}
int Gamestate_ProgressCount = 0;
int Gamestate_ProgressCount = 3;

View file

@ -23,4 +23,5 @@
struct Moonwalk;
struct Level2Resources {
struct Moonwalk *moonwalk;
ALLEGRO_FONT *font;
};

View file

@ -24,7 +24,7 @@
#include "../../utils.h"
#include "moonwalk.h"
// TODO: use Walk action instead
// TODO: maybe use Walk action instead
bool DoMoonwalk(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
struct Character *derpy = action->arguments->value;
if (state == TM_ACTIONSTATE_START) {
@ -53,6 +53,7 @@ void Moonwalk_Draw(struct Game *game, struct Moonwalk *data) {
void Moonwalk_Start(struct Game *game, struct Moonwalk *data) {
SelectSpritesheet(game, data->derpy, "walk");
al_play_sample_instance(data->music);
// TODO: find some way to restart Timeline
}
@ -84,7 +85,6 @@ struct Moonwalk* Moonwalk_Load(struct Game *game, int current_level) {
al_attach_sample_instance_to_mixer(data->music, game->audio.music);
al_set_sample_instance_playmode(data->music, ALLEGRO_PLAYMODE_LOOP);
TM_Init(game);
TM_AddAction(&DoMoonwalk, TM_AddToArgs(NULL, data->derpy), "moonwalk");
@ -101,9 +101,20 @@ void Moonwalk_Unload(struct Game *game, struct Moonwalk *data) {
free(data);
TM_Destroy();
}
void Moonwalk_ProcessEvent(struct Game *game, struct Moonwalk *data, ALLEGRO_EVENT *ev) {}
void Moonwalk_Resume(struct Game *game, struct Moonwalk *data) {}
void Moonwalk_Pause(struct Game *game, struct Moonwalk *data) {}
void Moonwalk_Pause(struct Game *game, struct Moonwalk *data) {
data->music_pos = al_get_sample_instance_position(data->music);
al_set_sample_instance_playing(data->music, false);
TM_Pause();
}
void Moonwalk_Resume(struct Game *game, struct Moonwalk *data) {
al_set_sample_instance_position(data->music, data->music_pos);
al_set_sample_instance_playing(data->music, true);
TM_Resume();
}
void Moonwalk_Reload(struct Game *game, struct Moonwalk *data) {
unload_bitmaps(game, data);

View file

@ -27,6 +27,7 @@ struct Moonwalk {
ALLEGRO_BITMAP *background;
ALLEGRO_SAMPLE *sample;
ALLEGRO_SAMPLE_INSTANCE *music;
int music_pos;
};
bool DoMoonwalk(struct Game *game, struct TM_Action *action, enum TM_ActionState state);

View file

@ -22,7 +22,7 @@
#include "utils.h"
#include "timeline.h"
// FIXME: pack into Timeline structure
// FIXME: pack into Timeline structure (multipe instances support)
unsigned int lastid;
struct Game* game = NULL;
struct TM_Action *queue, *background;