add "power meter"

This commit is contained in:
Sebastian Krzyszkowiak 2012-05-09 10:58:45 +02:00
parent 896b9d57aa
commit 389c4c27aa
6 changed files with 65 additions and 8 deletions

View file

@ -4,9 +4,9 @@ CFLAGS=-I$(IDIR) -Wall -ansi -g
SRCDIR=src
ODIR=obj
LIBS=-lallegro -lallegro_audio -lallegro_acodec -lallegro_image -lallegro_font -lallegro_main -lallegro_ttf -lm
LIBS=-lallegro -lallegro_audio -lallegro_acodec -lallegro_image -lallegro_font -lallegro_main -lallegro_ttf -lallegro_primitives -lm
_OBJ = config.o main.o about.o intro.o loading.o map.o menu.o level.o moonwalk.o pause.o timeline.o
_OBJ = config.o main.o about.o intro.o loading.o map.o menu.o level.o moonwalk.o pause.o timeline.o allegro_utils.o
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
OUTPUTDIR = bin

24
src/allegro_utils.c Normal file
View file

@ -0,0 +1,24 @@
#include "allegro_utils.h"
void al_draw_vertical_gradient_rect(float x, float y, float w, float h, ALLEGRO_COLOR top, ALLEGRO_COLOR bottom) {
ALLEGRO_VERTEX v[] = {
{.x = x, .y = y, .z = 0, .color = top},
{.x = x + w, .y = y, .z = 0, .color = top},
{.x = x, .y = y + h, .z = 0, .color = bottom},
{.x = x + w, .y = y + h, .z = 0, .color = bottom}};
al_draw_prim(v, NULL, NULL, 0, 4, ALLEGRO_PRIM_TRIANGLE_STRIP);
}
void al_draw_horizontal_gradient_rect(float x, float y, float w, float h, ALLEGRO_COLOR left, ALLEGRO_COLOR right) {
ALLEGRO_VERTEX v[] = {
{.x = x, .y = y, .z = 0, .color = left},
{.x = x + w, .y = y, .z = 0, .color = right},
{.x = x, .y = y + h, .z = 0, .color = left},
{.x = x + w, .y = y + h, .z = 0, .color = right}};
al_draw_prim(v, NULL, NULL, 0, 4, ALLEGRO_PRIM_TRIANGLE_STRIP);
}
void al_draw_text_with_shadow(ALLEGRO_FONT *font, ALLEGRO_COLOR color, float x, float y, int flags, char const *text) {
al_draw_text(font, al_map_rgba(0,0,0,128), x+1, y+1, flags, text);
al_draw_text(font, color, x, y, flags, text);
}

7
src/allegro_utils.h Normal file
View file

@ -0,0 +1,7 @@
#include <allegro5/allegro.h>
#include <allegro5/allegro_primitives.h>
#include <allegro5/allegro_font.h>
void al_draw_vertical_gradient_rect(float x, float y, float w, float h, ALLEGRO_COLOR top, ALLEGRO_COLOR bottom);
void al_draw_horizontal_gradient_rect(float x, float y, float w, float h, ALLEGRO_COLOR left, ALLEGRO_COLOR right);
void al_draw_text_with_shadow(ALLEGRO_FONT *font, ALLEGRO_COLOR color, float x, float y, int flags, char const *text);

View file

@ -113,10 +113,24 @@ bool Move(struct Game *game, struct TM_Action *action, enum TM_ActionState state
return true;
}
bool ShowMeter(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
if (state != TM_ACTIONSTATE_RUNNING) return false;
game->level.meter_alpha+=tps(game, 60*3);
if (game->level.meter_alpha>=255) {
game->level.meter_alpha=255;
return true;
}
return false;
}
bool Fly(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
if (state == TM_ACTIONSTATE_INIT) action->arguments = NULL;
if (state != TM_ACTIONSTATE_RUNNING) return false;
if (!(action->arguments)) { SelectDerpySpritesheet(game, "fly"); game->level.flying = true; }
if (!(action->arguments)) {
SelectDerpySpritesheet(game, "fly");
game->level.flying = true;
TM_AddBackgroundAction(&ShowMeter, NULL, 0, "showmeter");
}
action->arguments++;
game->level.derpy_y-=tps(game, 60*0.004);
if (game->level.derpy_y>0.2) return false;
@ -312,6 +326,11 @@ void Level_Draw(struct Game *game) {
if (game->level.cl_pos >= 1) game->level.cl_pos=game->level.cl_pos-1;
al_hold_bitmap_drawing(false);
al_set_target_bitmap(game->level.meter_bmp);
al_draw_horizontal_gradient_rect(0, 0, al_get_bitmap_width(game->level.meter_bmp), al_get_bitmap_height(game->level.meter_bmp), al_map_rgb(255,0,0), al_map_rgb(0,255,0));
al_set_target_bitmap(al_get_backbuffer(game->display));
al_draw_tinted_bitmap(game->level.meter_bmp, al_map_rgba(game->level.meter_alpha,game->level.meter_alpha,game->level.meter_alpha,game->level.meter_alpha), al_get_display_width(game->display)*0.75, al_get_display_height(game->display)*0.925, 0);
TM_Process();
}
}
@ -430,6 +449,7 @@ void Level_Load(struct Game *game) {
game->level.handle_input = false;
game->level.obstracles = NULL;
game->level.flying = false;
game->level.meter_alpha=0;
al_clear_to_color(al_map_rgb(0,0,0));
if (game->level.current_level!=1) Moonwalk_Load(game);
else {
@ -555,6 +575,7 @@ void Level_UnloadBitmaps(struct Game *game) {
al_destroy_bitmap(game->level.clouds);
al_destroy_bitmap(game->level.welcome);
al_destroy_bitmap(game->level.obst_bmps.pie);
al_destroy_bitmap(game->level.meter_bmp);
}
}
@ -582,5 +603,7 @@ void Level_PreloadBitmaps(struct Game *game) {
al_draw_text_with_shadow(game->menu.font_title, al_map_rgb(255,255,255), al_get_display_width(game->display)*0.5, al_get_display_height(game->display)*0.1, ALLEGRO_ALIGN_CENTRE, "Level 1");
al_draw_text_with_shadow(game->menu.font_subtitle, al_map_rgb(255,255,255), al_get_display_width(game->display)*0.5, al_get_display_height(game->display)*0.275, ALLEGRO_ALIGN_CENTRE, "Fluttershy");
al_set_target_bitmap(al_get_backbuffer(game->display));
game->level.meter_bmp = al_create_bitmap(al_get_display_width(game->display)*0.2, al_get_display_height(game->display)*0.025);
}
}

View file

@ -60,11 +60,6 @@
double old_time = 0, fps;
int frames_done = 0;
void al_draw_text_with_shadow(ALLEGRO_FONT *font, ALLEGRO_COLOR color, float x, float y, int flags, char const *text) {
al_draw_text(font, al_map_rgba(0,0,0,128), x+1, y+1, flags, text);
al_draw_text(font, color, x, y, flags, text);
}
void PrintConsole(struct Game *game, char* format, ...) {
va_list vl;
va_start(vl, format);
@ -329,6 +324,11 @@ int main(int argc, char **argv){
return -1;
}
if(!al_init_primitives_addon()){
fprintf(stderr, "failed to initialize primitives!\n");
return -1;
}
/* if (!al_reserve_samples(10)){
fprintf(stderr, "failed to reserve samples!\n");
return -1;

View file

@ -29,6 +29,7 @@
#include <allegro5/allegro_image.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_ttf.h>
#include "allegro_utils.h"
struct Game;
@ -77,6 +78,7 @@ struct Level {
float derpy_x, derpy_y;
bool handle_input;
bool flying;
float meter_alpha;
int sheet_rows, sheet_cols, sheet_pos, sheet_blanks;
float sheet_tmp, sheet_speed, sheet_speed_modifier;
ALLEGRO_SAMPLE *sample; /*!< Sample with background music. */
@ -86,6 +88,7 @@ struct Level {
ALLEGRO_BITMAP *welcome;
ALLEGRO_BITMAP **derpy_sheet; /*!< Active Derpy sprite sheet. */
ALLEGRO_BITMAP *derpy; /*!< Derpy sprite. */
ALLEGRO_BITMAP *meter_bmp;
struct Spritesheet* derpy_sheets; /*!< List of sprite sheets of Derpy character. */
struct Spritesheet* pony_sheets; /*!< List of sprite sheets of character rescued by Derpy. */
struct {