Merge branch 'newmenu' into events

Conflicts:
	src/credits.c
This commit is contained in:
Andrew "Akari" Alexeyew 2012-08-14 19:05:28 +03:00
commit 4a8ef08639
24 changed files with 186 additions and 58 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 172 KiB

After

Width:  |  Height:  |  Size: 180 KiB

Binary file not shown.

View file

@ -32,6 +32,7 @@ set(SRCs
stageutils.c
matrix.c
video.c
transition.c
menu/menu.c
menu/mainmenu.c
menu/options.c

View file

@ -213,8 +213,7 @@ void credits_draw(void) {
credits_draw_entry(&(credits.entries[i]));
glPopMatrix();
colorfill(1, 1, 1, 1 - (global.frames / 300.0));
colorfill(1, 1, 1, credits.fadeout);
draw_transition();
}
void credits_process(void) {
@ -232,8 +231,8 @@ void credits_process(void) {
credits.panelalpha -= 1 / 120.0;
}
if(global.frames >= credits.end) {
credits.fadeout += 1 / 120.0;
if(global.frames == credits.end) {
set_transition(TransFadeWhite, CREDITS_FADEOUT, CREDITS_FADEOUT);
}
}
@ -251,7 +250,7 @@ void credits_free(void) {
void credits_loop(void) {
credits_init();
while(credits.fadeout <= 1) {
while(global.frames <= credits.end + CREDITS_FADEOUT) {
handle_events(NULL, 0, NULL);
credits_process();
credits_draw();

View file

@ -16,4 +16,6 @@ void credits_add(char*, int);
#define CREDITS_ENTRY_FADEOUT 100.0
#define CREDITS_YUKKURI_SCALE 0.5
#define CREDITS_FADEOUT 120
#endif

View file

@ -116,10 +116,7 @@ void ending_draw(Ending *e) {
draw_text(AL_Center, SCREEN_W/2, SCREEN_H/5*4, e->entries[e->pos].msg, _fonts.standard);
glColor4f(1,1,1,1);
if(global.frames > - e->entries[e->count-1].time-ENDING_FADE_OUT)
colorfill(1, 1, 1, (global.frames - e->entries[e->count-1].time + ENDING_FADE_OUT)/(float)ENDING_FADE_OUT);
// colorfill(1, 1, 1, 1);
draw_transition();
}
void ending_loop(void) {
@ -128,7 +125,7 @@ void ending_loop(void) {
global.frames = 0;
set_ortho();
while(e.pos < e.count-1) {
handle_events(NULL, 0, NULL);
@ -139,5 +136,8 @@ void ending_loop(void) {
if(global.frames >= e.entries[e.pos+1].time)
e.pos++;
if(global.frames == e.entries[e.count-1].time-ENDING_FADE_OUT)
set_transition(TransFadeWhite, ENDING_FADE_OUT, ENDING_FADE_OUT);
}
}

View file

@ -51,7 +51,7 @@ enum {
POINT_OF_COLLECT = VIEWPORT_H/4,
ATTACK_START_DELAY = 40,
BOMB_RECOVERY = 250,
BOMB_RECOVERY = 300,
DEATHBOMB_TIME = 10,
DEATH_DELAY = 70,

View file

@ -226,6 +226,8 @@ int collision_laser_curve(Laser *l) {
pos = l->prule(l,t);
if(collision_line(last, pos, global.plr.pos, l->width*0.5))
return 1;
else if(!(global.frames % 5) && global.frames - abs(global.plr.recovery) > 0 && collision_line(last, pos, global.plr.pos, l->width*1.7))
player_graze(&global.plr, pos, 1);
last = pos;
}

View file

@ -34,13 +34,14 @@ void create_gameover_menu(MenuData *m) {
create_menu(m);
m->flags = MF_Transient;
m->transition = NULL;
m->context = "Game Over";
char s[64];
int c = MAX_CONTINUES - global.plr.continues;
snprintf(s, sizeof(s), "Continue (%i)", c);
add_menu_entry(m, s, c? continue_game : NULL, NULL);
add_menu_entry(m, c? "Give up" : "Return to Title", give_up, NULL);
add_menu_entry(m, c? "Give up" : "Return to Title", give_up, NULL)->transition = TransFadeBlack;
if(!c)
m->cursor = 1;

View file

@ -20,15 +20,13 @@ void return_to_title(void *arg) {
void create_ingame_menu(MenuData *m) {
create_menu(m);
m->flags = MF_Abortable | MF_Transient;
m->transition = NULL;
add_menu_entry(m, "Return to Game", return_to_game, NULL);
add_menu_entry(m, "Return to Title", return_to_title, NULL);
add_menu_entry(m, "Return to Title", return_to_title, NULL)->transition = TransFadeBlack;
}
void draw_ingame_menu(MenuData *menu) {
float rad = (1.0-menu_fade(menu))*IMENU_BLUR;
glPushMatrix();
glTranslatef(VIEWPORT_X, VIEWPORT_Y, 0);
void draw_ingame_menu_bg(float f) {
float rad = f*IMENU_BLUR;
if(!tconfig.intval[NO_SHADER]) {
glBindFramebuffer(GL_FRAMEBUFFER, 0);
@ -41,13 +39,19 @@ void draw_ingame_menu(MenuData *menu) {
glUseProgram(0);
}
}
void draw_ingame_menu(MenuData *menu) {
glPushMatrix();
glTranslatef(VIEWPORT_X, VIEWPORT_Y, 0);
draw_ingame_menu_bg(1.0-menu_fade(menu));
glPushMatrix();
glTranslatef(VIEWPORT_W/2, VIEWPORT_H/4, 0);
draw_menu_selector(0, menu->drawdata[0], menu->drawdata[1]/45.0, 0.25, menu->frames);
// cirno's perfect math class #2: Euler Sign ~ Differential Fun
menu->drawdata[0] += (menu->cursor*35 - menu->drawdata[0])/7.0;
menu->drawdata[1] += (strlen(menu->entries[menu->cursor].name)*5 - menu->drawdata[1])/10.0;

View file

@ -10,6 +10,8 @@
#include "menu.h"
void draw_ingame_menu_bg(float f);
void create_ingame_menu(MenuData *menu);
void draw_ingame_menu(MenuData *menu);
int ingame_menu_loop(MenuData *menu);

View file

@ -155,5 +155,6 @@ void draw_main_menu(MenuData *menu) {
}
void main_menu_loop(MenuData *menu) {
set_transition(TransFadeBlack, -1, FADE_TIME);
menu_loop(menu, NULL, draw_main_menu, NULL);
}

View file

@ -8,11 +8,11 @@
#include "menu.h"
#include "global.h"
void add_menu_entry(MenuData *menu, char *name, MenuAction action, void *arg) {
add_menu_entry_f(menu, name, action, arg, 0);
MenuEntry *add_menu_entry(MenuData *menu, char *name, MenuAction action, void *arg) {
return add_menu_entry_f(menu, name, action, arg, 0);
}
void add_menu_entry_f(MenuData *menu, char *name, MenuAction action, void *arg, int flags) {
MenuEntry *add_menu_entry_f(MenuData *menu, char *name, MenuAction action, void *arg, int flags) {
menu->entries = realloc(menu->entries, (++menu->ecount)*sizeof(MenuEntry));
MenuEntry *e = &(menu->entries[menu->ecount-1]);
memset(e, 0, sizeof(MenuEntry));
@ -22,6 +22,8 @@ void add_menu_entry_f(MenuData *menu, char *name, MenuAction action, void *arg,
e->action = action;
e->arg = arg;
e->flags = flags;
e->transition = menu->transition;
return e;
}
void add_menu_separator(MenuData *menu) {
@ -46,13 +48,21 @@ void create_menu(MenuData *menu) {
menu->selected = -1;
menu->quitdelay = FADE_TIME;
menu->transition = TransFadeBlack;
}
void close_menu(MenuData *menu) {
TransitionRule trans = menu->transition;
if(menu->selected != -1)
trans = menu->entries[menu->selected].transition;
set_transition(trans, menu->quitdelay, menu->quitdelay);
menu->quitframe = menu->frames;
}
void close_menu(MenuData *menu) {
menu->quitframe = menu->frames;
}
void kill_menu(MenuData *menu) {
void kill_menu(MenuData *menu) {
menu->state = MS_Dead;
}
@ -138,6 +148,9 @@ int menu_loop(MenuData *menu, void (*input)(MenuData*), void (*draw)(MenuData*),
}
draw(menu);
if(!(menu->flags & MF_ManualDrawTransition))
draw_transition();
SDL_GL_SwapBuffers();
frame_rate(&menu->lasttime);
}

View file

@ -8,6 +8,8 @@
#ifndef MENU_H
#define MENU_H
#include "transition.h"
#define IMENU_BLUR 0.05
#define TS_KR_DELAY SDL_DEFAULT_REPEAT_DELAY
#define TS_KR_INTERVAL (SDL_DEFAULT_REPEAT_INTERVAL*2)
@ -27,15 +29,21 @@ typedef struct {
int flags;
float drawdata;
float drawdata;
TransitionRule transition;
} MenuEntry;
typedef enum MenuFlag {
// enum EntryFlag {
// MF_InstantSelect = 4
// };
enum MenuFlag {
MF_Transient = 1, // whether to close on selection or not.
MF_Abortable = 2,
MF_InstantSelect = 4
} MenuType;
MF_InstantSelect = 4,
MF_ManualDrawTransition = 8, // the menu will not call draw_transition() automatically
};
enum MenuState{
MS_Normal = 0,
@ -59,13 +67,15 @@ typedef struct MenuData{
int quitframe;
int quitdelay;
TransitionRule transition;
float drawdata[4];
void *context;
} MenuData;
void add_menu_entry(MenuData *menu, char *name, MenuAction action, void *arg);
void add_menu_entry_f(MenuData *menu, char *name, MenuAction action, void *arg, int flags);
MenuEntry *add_menu_entry(MenuData *menu, char *name, MenuAction action, void *arg);
MenuEntry *add_menu_entry_f(MenuData *menu, char *name, MenuAction action, void *arg, int flags);
void add_menu_separator(MenuData *menu);
void create_menu(MenuData *menu);

View file

@ -577,8 +577,7 @@ void draw_options_menu(MenuData *menu) {
}
}
}
glPopMatrix();
}

View file

@ -63,9 +63,10 @@ MenuData* replayview_stageselect(Replay *rpy) {
create_menu(m);
m->context = rpy;
m->flags = MF_Transient | MF_Abortable;
m->transition = 0;
for(i = 0; i < rpy->stgcount; ++i) {
add_menu_entry(m, stage_get(rpy->stages[i].stage)->title, start_replay, rpy);
add_menu_entry(m, stage_get(rpy->stages[i].stage)->title, start_replay, rpy)->transition = TransFadeBlack;
}
return m;
@ -220,6 +221,7 @@ static void replayview_draw(MenuData *m) {
replayview_draw_stagemenu(sm);
}
}
}
@ -250,7 +252,7 @@ int fill_replayview_menu(MenuData *m) {
continue;
}
add_menu_entry_f(m, " ", replayview_run, rpy, (rpy->stgcount > 1)*MF_InstantSelect);
add_menu_entry_f(m, " ", replayview_run, rpy, (rpy->stgcount > 1)*MF_InstantSelect)->transition = rpy->stgcount < 1 ? TransFadeBlack : NULL;
++rpys;
}

View file

@ -44,7 +44,7 @@ void create_saverpy_menu(MenuData *m) {
m->flags = MF_Transient;
add_menu_entry(m, "Yes", save_rpy, m);
add_menu_entry(m, "No", (MenuAction) close_menu, m);
add_menu_entry(m, "No", (MenuAction) kill_menu, m);
}
void draw_saverpy_menu(MenuData *m) {

View file

@ -26,7 +26,7 @@ void create_stage_menu(MenuData *m) {
}
add_menu_separator(m);
add_menu_entry(m, "Back", (MenuAction)close_menu, m);
add_menu_entry(m, "Back", (MenuAction)kill_menu, m);
}
void draw_menu_list(MenuData *m, float x, float y, void (*draw)(void *, int, int)) {

View file

@ -18,10 +18,10 @@ void init_player(Player* plr) {
memset(plr, 0, sizeof(Player));
plr->pos = VIEWPORT_W/2 + I*(VIEWPORT_H-20);
plr->lifes = PLR_START_LIVES;
plr->bombs = PLR_START_BOMBS;
plr->deathtime = -1;
plr->continues = 0;
}
@ -344,3 +344,14 @@ void player_applymovement(Player* plr) {
}
}
}
void player_graze(Player *plr, complex pos, int pts) {
global.points += pts;
plr->graze++;
play_sound("graze");
int i = 0; for(i = 0; i < 5; ++i) {
tsrand_fill(3);
create_particle2c("flare", pos, NULL, Shrink, timeout_linear, 5 + 5 * afrand(2), (1+afrand(0)*5)*cexp(I*tsrand_a(1)));
}
}

View file

@ -44,6 +44,7 @@ typedef struct {
short dir;
float power;
int graze;
int lifes;
int bombs;
@ -78,7 +79,7 @@ void player_move(Player*, complex delta);
void player_bomb(Player*);
void player_realdeath(Player*);
void player_death(Player*);
void player_graze(Player*, complex, int);
void player_setmoveflag(Player* plr, int key, int mode);
void player_event(Player* plr,int type, int key);

View file

@ -65,26 +65,20 @@ void delete_projectiles(Projectile **projs) {
delete_all_elements((void **)projs, _delete_projectile);
}
int collision_projectile(Projectile *p) {
int collision_projectile(Projectile *p) {
if(p->type == FairyProj) {
float angle = carg(global.plr.pos - p->pos) + p->angle;
int projr = sqrt(pow(p->tex->w/4*cos(angle),2)*5/10.0 + pow(p->tex->h/2*sin(angle)*5/10.0,2));
double angle = carg(global.plr.pos - p->pos) + p->angle;
double projr = sqrt(pow(p->tex->w/4*cos(angle),2)*5/10.0 + pow(p->tex->h/2*sin(angle)*5/10.0,2));
double grazer = max(p->tex->w, p->tex->h);
double dst = cabs(global.plr.pos - p->pos);
grazer = (0.9 * sqrt(grazer) + 0.1 * grazer) * 5;
int dst = cabs(global.plr.pos - p->pos);
if(dst < projr + 1)
return 1;
if(!p->grazed && dst < grazer) {
if(!p->grazed && dst < grazer && global.frames - abs(global.plr.recovery) > 0) {
p->grazed = True;
global.points += 10;
play_sound("graze");
int i = 0; for(i = 0; i < 10; ++i) {
tsrand_fill(3);
create_particle2c("flare", p->pos - grazer * 0.3 * cexp(I*carg(p->pos - global.plr.pos)), NULL, Shrink, timeout_linear, 10 + 10 * afrand(2), (1+afrand(0)*5)*cexp(I*tsrand_a(1)));
}
player_graze(&global.plr, p->pos - grazer * 0.3 * cexp(I*carg(p->pos - global.plr.pos)), 10);
}
} else if(p->type >= PlrProj) {
Enemy *e = global.enemies;
@ -106,10 +100,10 @@ int collision_projectile(Projectile *p) {
return 0;
}
void draw_projectiles(Projectile *projs) {
void draw_projectiles(Projectile *projs) {
Projectile *proj;
for(proj = projs; proj; proj = proj->next)
for(proj = projs; proj; proj = proj->next)
proj->draw(proj, global.frames - proj->birthtime);
}
@ -129,7 +123,7 @@ void process_projectiles(Projectile **projs, char collision) {
create_particle1c("flare", proj->pos, NULL, Fade, timeout, 30);
create_item(proj->pos, 0, BPoint)->auto_collect = 10;
}
if(collision)
col = collision_projectile(proj);

View file

@ -179,6 +179,9 @@ void draw_hud(void) {
sprintf(buf, "%.2f", global.plr.power);
draw_text(AL_Center, 10, 236, buf, _fonts.standard);
sprintf(buf, "%i", global.plr.graze);
draw_text(AL_Left, -5, 270, buf, _fonts.standard);
sprintf(buf, "%i", global.points);
draw_text(AL_Center, 13, 49, buf, _fonts.standard);
@ -283,6 +286,7 @@ void stage_draw(StageInfo *info, StageRule bgdraw, ShaderRule *shaderrules, int
glPopMatrix();
draw_hud();
draw_transition();
}
int apply_shaderrules(ShaderRule *shaderrules, int fbonum) {
@ -393,6 +397,9 @@ void stage_logic(int time) {
if(!global.dialog && !global.boss)
global.timer++;
if(global.timer == time - FADE_TIME)
set_transition(TransFadeBlack, FADE_TIME, FADE_TIME*2);
if(global.timer >= time)
global.game_over = GAMEOVER_WIN;
}

51
src/transition.c Normal file
View file

@ -0,0 +1,51 @@
/*
* This software is licensed under the terms of the MIT-License
* See COPYING for further information.
* ---
* Copyright (C) 2011, Lukas Weber <laochailan@web.de>
*/
#include "transition.h"
#include "menu/ingamemenu.h"
#include "global.h"
static Transition transition;
float trans_fade(Transition *t) {
if(t->frames <= t->dur1)
return t->frames/(float)t->dur1;
else
return (t->dur1+t->dur2-t->frames)/(float)t->dur2;
}
void TransFadeBlack(Transition *t) {
fade_out(trans_fade(t));
}
void TransFadeWhite(Transition *t) {
colorfill(1,1,1,trans_fade(t));
}
void set_transition(TransitionRule rule, int dur1, int dur2) {
if(!rule)
return;
memset(&transition, 0, sizeof(Transition));
transition.rule = rule;
transition.dur1 = dur1;
transition.dur2 = dur2;
}
void draw_transition(void) {
if(!transition.rule)
return;
transition.rule(&transition);
transition.frames++;
if(transition.frames > transition.dur1 + transition.dur2)
memset(&transition, 0, sizeof(Transition));
}

28
src/transition.h Normal file
View file

@ -0,0 +1,28 @@
/*
* This software is licensed under the terms of the MIT-License
* See COPYING for further information.
* ---
* Copyright (C) 2011, Lukas Weber <laochailan@web.de>
*/
#ifndef TRANSITION_H
#define TRANSITION_H
typedef struct Transition Transition;
typedef void (*TransitionRule)(Transition *t);
struct Transition {
int frames;
int dur1; // first half
int dur2; // second half
TransitionRule rule;
};
void TransFadeBlack(Transition *t);
void TransFadeWhite(Transition *t);
void set_transition(TransitionRule rule, int dur1, int dur2);
void draw_transition(void);
#endif