2010-10-12 10:55:23 +02:00
|
|
|
/*
|
2011-03-05 13:44:21 +01:00
|
|
|
* This software is licensed under the terms of the MIT-License
|
|
|
|
* See COPYING for further information.
|
|
|
|
* ---
|
|
|
|
* Copyright (C) 2011, Lukas Weber <laochailan@web.de>
|
2010-10-12 10:55:23 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stage.h"
|
|
|
|
|
|
|
|
#include <SDL/SDL.h>
|
2012-07-14 19:46:03 +02:00
|
|
|
#include <time.h>
|
2010-10-12 10:55:23 +02:00
|
|
|
#include "global.h"
|
2012-07-14 16:37:52 +02:00
|
|
|
#include "replay.h"
|
|
|
|
#include "config.h"
|
|
|
|
#include "player.h"
|
2011-06-13 18:48:36 +02:00
|
|
|
#include "menu/ingamemenu.h"
|
2012-07-16 17:47:06 +02:00
|
|
|
#include "menu/savereplay.h"
|
2010-10-12 10:55:23 +02:00
|
|
|
|
2012-07-14 09:40:37 +02:00
|
|
|
StageInfo stages[] = {
|
|
|
|
// TODO: Give the stages actual titles/subtitles
|
|
|
|
|
2012-07-14 19:46:03 +02:00
|
|
|
{1, stage0_loop, False, "Stage 1", "(insert subtitle here)"},
|
|
|
|
{2, stage1_loop, False, "Stage 2", "(insert subtitle here)"},
|
|
|
|
{3, stage2_loop, False, "Stage 3", "(insert subtitle here)"},
|
|
|
|
{4, stage3_loop, False, "Stage 4", "(insert subtitle here)"},
|
2012-07-14 09:40:37 +02:00
|
|
|
|
2012-07-14 19:46:03 +02:00
|
|
|
{0, NULL, False, NULL, NULL}
|
2012-07-14 09:40:37 +02:00
|
|
|
};
|
|
|
|
|
2012-07-14 19:46:03 +02:00
|
|
|
// NOTE: This returns the stage BY ID, not by the array index!
|
2012-07-14 09:40:37 +02:00
|
|
|
StageInfo* stage_get(int n) {
|
|
|
|
int i;
|
|
|
|
for(i = 0; stages[i].loop; ++i)
|
2012-07-14 19:46:03 +02:00
|
|
|
if(stages[i].id == n)
|
2012-07-14 09:40:37 +02:00
|
|
|
return &(stages[i]);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-10-12 10:55:23 +02:00
|
|
|
void stage_start() {
|
2011-05-08 13:48:25 +02:00
|
|
|
global.timer = 0;
|
2011-06-13 18:48:36 +02:00
|
|
|
global.frames = 0;
|
|
|
|
global.game_over = 0;
|
2011-06-27 08:20:42 +02:00
|
|
|
global.points = 0;
|
2012-07-13 22:42:35 +02:00
|
|
|
global.nostagebg = False;
|
2012-07-17 09:55:06 +02:00
|
|
|
|
|
|
|
global.fps.show_fps = 60;
|
|
|
|
global.fps.fpstime = SDL_GetTicks();
|
2012-07-14 19:46:03 +02:00
|
|
|
|
2012-07-14 11:13:06 +02:00
|
|
|
global.plr.recovery = 0;
|
2010-10-12 10:55:23 +02:00
|
|
|
}
|
|
|
|
|
2012-07-14 16:37:52 +02:00
|
|
|
void stage_ingamemenu() {
|
|
|
|
if(!global.menu)
|
|
|
|
global.menu = create_ingame_menu();
|
|
|
|
else
|
|
|
|
global.menu->quit = 1;
|
|
|
|
}
|
|
|
|
|
2012-07-14 19:46:03 +02:00
|
|
|
void replay_input() {
|
|
|
|
if(global.menu) {
|
|
|
|
menu_input(global.menu);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_Event event;
|
|
|
|
while(SDL_PollEvent(&event)) {
|
2012-07-18 12:33:37 +02:00
|
|
|
global_processevent(&event);
|
2012-07-14 19:46:03 +02:00
|
|
|
int sym = event.key.keysym.sym;
|
|
|
|
|
|
|
|
switch(event.type) {
|
|
|
|
case SDL_KEYDOWN:
|
|
|
|
if(sym == SDLK_ESCAPE)
|
|
|
|
stage_ingamemenu();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SDL_QUIT:
|
|
|
|
exit(1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-17 09:55:06 +02:00
|
|
|
// I know this loop is not (yet) optimal - consider it a sketch
|
2012-07-14 19:46:03 +02:00
|
|
|
int i;
|
|
|
|
for(i = 0; i < global.replay.ecount; ++i) {
|
|
|
|
ReplayEvent *e = &(global.replay.events[i]);
|
|
|
|
|
|
|
|
if(e->frame == global.frames) switch(e->type) {
|
|
|
|
case EV_OVER:
|
|
|
|
global.game_over = GAMEOVER_ABORT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if(global.dialog && e->type == EV_PRESS && (e->key == KEY_SHOT || e->key == KEY_BOMB))
|
|
|
|
page_dialog(&global.dialog);
|
|
|
|
else
|
|
|
|
player_event(&global.plr, e->type, e->key);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
player_applymovement(&global.plr);
|
|
|
|
}
|
|
|
|
|
2011-05-13 19:03:02 +02:00
|
|
|
void stage_input() {
|
2011-06-13 18:48:36 +02:00
|
|
|
if(global.menu) {
|
|
|
|
menu_input(global.menu);
|
|
|
|
return;
|
2012-07-14 19:46:03 +02:00
|
|
|
}
|
2011-06-13 18:48:36 +02:00
|
|
|
|
2011-05-13 19:03:02 +02:00
|
|
|
SDL_Event event;
|
2010-10-12 10:55:23 +02:00
|
|
|
while(SDL_PollEvent(&event)) {
|
2012-07-18 12:33:37 +02:00
|
|
|
global_processevent(&event);
|
2011-05-21 18:20:04 +02:00
|
|
|
int sym = event.key.keysym.sym;
|
2012-07-14 16:37:52 +02:00
|
|
|
int key = config_sym2key(sym);
|
2011-07-02 18:36:08 +02:00
|
|
|
|
2012-07-14 16:37:52 +02:00
|
|
|
switch(event.type) {
|
|
|
|
case SDL_KEYDOWN:
|
|
|
|
if(global.dialog && (key == KEY_SHOT || key == KEY_BOMB)) {
|
2011-05-21 18:20:04 +02:00
|
|
|
page_dialog(&global.dialog);
|
2012-07-14 19:46:03 +02:00
|
|
|
replay_event(&global.replay, EV_PRESS, key);
|
2012-07-14 16:37:52 +02:00
|
|
|
} else if(sym == SDLK_ESCAPE) {
|
|
|
|
stage_ingamemenu();
|
|
|
|
} else {
|
|
|
|
player_event(&global.plr, EV_PRESS, key);
|
2012-07-14 19:46:03 +02:00
|
|
|
replay_event(&global.replay, EV_PRESS, key);
|
2012-07-14 16:37:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SDL_KEYUP:
|
|
|
|
player_event(&global.plr,EV_RELEASE, key);
|
2012-07-14 19:46:03 +02:00
|
|
|
replay_event(&global.replay, EV_RELEASE, key);
|
2012-07-14 16:37:52 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SDL_QUIT:
|
|
|
|
exit(1);
|
|
|
|
break;
|
2010-10-12 10:55:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-14 16:37:52 +02:00
|
|
|
player_applymovement(&global.plr);
|
2010-10-12 10:55:23 +02:00
|
|
|
}
|
|
|
|
|
2011-05-08 13:48:25 +02:00
|
|
|
void draw_hud() {
|
2011-08-23 17:37:14 +02:00
|
|
|
draw_texture(SCREEN_W/2.0, SCREEN_H/2.0, "hud");
|
2010-10-12 10:55:23 +02:00
|
|
|
|
2010-11-14 13:24:56 +01:00
|
|
|
char buf[16];
|
2011-03-23 12:26:30 +01:00
|
|
|
int i;
|
2010-10-12 10:55:23 +02:00
|
|
|
|
2011-03-23 12:26:30 +01:00
|
|
|
glPushMatrix();
|
|
|
|
glTranslatef(615,0,0);
|
|
|
|
|
2011-04-10 10:23:24 +02:00
|
|
|
for(i = 0; i < global.plr.lifes; i++)
|
2011-03-23 12:26:30 +01:00
|
|
|
draw_texture(16*i,167, "star");
|
2011-06-27 13:36:35 +02:00
|
|
|
|
2011-03-23 12:26:30 +01:00
|
|
|
for(i = 0; i < global.plr.bombs; i++)
|
|
|
|
draw_texture(16*i,200, "star");
|
|
|
|
|
|
|
|
sprintf(buf, "%.2f", global.plr.power);
|
2011-06-24 12:35:03 +02:00
|
|
|
draw_text(AL_Center, 10, 236, buf, _fonts.standard);
|
2011-03-23 12:26:30 +01:00
|
|
|
|
2011-04-10 10:23:24 +02:00
|
|
|
sprintf(buf, "%i", global.points);
|
2011-06-24 12:35:03 +02:00
|
|
|
draw_text(AL_Center, 13, 49, buf, _fonts.standard);
|
2011-04-10 10:23:24 +02:00
|
|
|
|
2011-03-23 12:26:30 +01:00
|
|
|
glPopMatrix();
|
2011-05-09 13:42:02 +02:00
|
|
|
|
2012-07-17 17:34:18 +02:00
|
|
|
sprintf(buf, "%i fps / %i stgframes", global.fps.show_fps, global.timer);
|
2011-07-02 12:45:32 +02:00
|
|
|
draw_text(AL_Right, SCREEN_W, SCREEN_H-20, buf, _fonts.standard);
|
2011-08-27 15:56:02 +02:00
|
|
|
|
|
|
|
if(global.boss)
|
|
|
|
draw_texture(VIEWPORT_X+creal(global.boss->pos), 590, "boss_indicator");
|
2010-10-12 10:55:23 +02:00
|
|
|
}
|
|
|
|
|
2012-01-06 21:52:55 +01:00
|
|
|
void stage_draw(StageRule bgdraw, ShaderRule *shaderrules, int time) {
|
|
|
|
if(!tconfig.intval[NO_SHADER])
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, resources.fbg[0].fbo);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
glPushMatrix();
|
|
|
|
glTranslatef(-(VIEWPORT_X+VIEWPORT_W/2.0), -(VIEWPORT_Y+VIEWPORT_H/2.0),0);
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
2012-07-17 09:55:06 +02:00
|
|
|
|
|
|
|
if(tconfig.intval[NO_STAGEBG] == 2 && global.fps.show_fps < tconfig.intval[NO_STAGEBG_FPSLIMIT]
|
2012-07-14 07:45:14 +02:00
|
|
|
&& !global.nostagebg) {
|
|
|
|
|
|
|
|
printf("stage_draw(): !- Stage background has been switched off due to low frame rate. You can change that in the options.\n");
|
|
|
|
global.nostagebg = True;
|
|
|
|
}
|
2012-07-13 22:42:35 +02:00
|
|
|
|
2012-07-16 17:47:06 +02:00
|
|
|
if(tconfig.intval[NO_STAGEBG] == 1)
|
|
|
|
global.nostagebg = True;
|
|
|
|
|
2012-07-14 09:03:51 +02:00
|
|
|
if(!global.nostagebg && !global.menu)
|
2012-01-06 21:52:55 +01:00
|
|
|
bgdraw();
|
2012-07-14 07:45:14 +02:00
|
|
|
|
2012-01-06 21:52:55 +01:00
|
|
|
glPopMatrix();
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
|
|
|
2011-06-24 12:35:03 +02:00
|
|
|
set_ortho();
|
2011-08-23 17:37:14 +02:00
|
|
|
|
2012-07-16 17:47:06 +02:00
|
|
|
if(!global.menu) {
|
|
|
|
glPushMatrix();
|
|
|
|
glTranslatef(VIEWPORT_X,VIEWPORT_Y,0);
|
2011-06-13 18:48:36 +02:00
|
|
|
|
2011-06-27 13:36:35 +02:00
|
|
|
if(!tconfig.intval[NO_SHADER])
|
2012-01-06 21:52:55 +01:00
|
|
|
apply_bg_shaders(shaderrules);
|
2011-05-08 13:48:25 +02:00
|
|
|
|
2011-08-26 15:19:14 +02:00
|
|
|
if(global.boss) {
|
|
|
|
glPushMatrix();
|
|
|
|
glTranslatef(creal(global.boss->pos), cimag(global.boss->pos), 0);
|
|
|
|
|
2012-04-04 17:19:53 +02:00
|
|
|
if(!(global.frames % 5)) {
|
|
|
|
complex offset = (frand()-0.5)*50 + (frand()-0.5)*20I;
|
|
|
|
create_particle3c("boss_shadow", -20I, rgba(0.2,0.35,0.5,0.5), EnemyFlareShrink, enemy_flare, 50, (-100I-offset)/(50.0+frand()*10), add_ref(global.boss));
|
|
|
|
}
|
|
|
|
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
2012-04-05 14:24:55 +02:00
|
|
|
|
2011-08-26 15:19:14 +02:00
|
|
|
glRotatef(global.frames*4.0, 0, 0, -1);
|
|
|
|
float f = 0.8+0.1*sin(global.frames/8.0);
|
|
|
|
glScalef(f,f,f);
|
|
|
|
draw_texture(0,0,"boss_circle");
|
|
|
|
|
2012-04-04 17:19:53 +02:00
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
2011-08-26 15:19:14 +02:00
|
|
|
|
|
|
|
glPopMatrix();
|
|
|
|
}
|
|
|
|
|
2011-06-13 18:48:36 +02:00
|
|
|
player_draw(&global.plr);
|
|
|
|
|
2011-12-25 08:18:03 +01:00
|
|
|
draw_items();
|
2011-06-13 18:48:36 +02:00
|
|
|
draw_projectiles(global.projs);
|
2011-12-25 08:18:03 +01:00
|
|
|
|
2012-04-04 17:19:53 +02:00
|
|
|
|
|
|
|
draw_projectiles(global.particles);
|
2011-06-13 18:48:36 +02:00
|
|
|
draw_enemies(global.enemies);
|
|
|
|
draw_lasers();
|
|
|
|
|
|
|
|
if(global.boss)
|
|
|
|
draw_boss(global.boss);
|
|
|
|
|
|
|
|
if(global.dialog)
|
|
|
|
draw_dialog(global.dialog);
|
2011-07-02 12:45:32 +02:00
|
|
|
|
2011-06-27 13:36:35 +02:00
|
|
|
if(!tconfig.intval[NO_SHADER]) {
|
2011-12-25 08:18:03 +01:00
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
2011-07-05 15:20:19 +02:00
|
|
|
|
|
|
|
glPushMatrix();
|
|
|
|
if(global.plr.cha == Marisa && global.plr.shot == MarisaLaser && global.frames - global.plr.recovery < 0)
|
|
|
|
glTranslatef(8*sin(global.frames),8*sin(global.frames+3),0);
|
2011-12-29 09:37:17 +01:00
|
|
|
// glColor4f(1,1,1,0.2);
|
2011-07-04 09:14:08 +02:00
|
|
|
draw_fbo_viewport(&resources.fsec);
|
2011-12-29 09:37:17 +01:00
|
|
|
// glColor4f(1,1,1,1);
|
2011-07-05 15:20:19 +02:00
|
|
|
glPopMatrix();
|
2011-06-27 13:36:35 +02:00
|
|
|
}
|
2012-07-16 17:47:06 +02:00
|
|
|
|
|
|
|
glPopMatrix();
|
2011-05-09 13:42:02 +02:00
|
|
|
}
|
2011-07-02 12:45:32 +02:00
|
|
|
|
2012-01-06 21:52:55 +01:00
|
|
|
if(global.frames < 4*FADE_TIME)
|
|
|
|
fade_out(1.0 - global.frames/(float)(4*FADE_TIME));
|
|
|
|
if(global.timer > time - 4*FADE_TIME) {
|
|
|
|
fade_out((global.timer - time + 4*FADE_TIME)/(float)(4*FADE_TIME));
|
2011-06-13 18:48:36 +02:00
|
|
|
}
|
2012-01-06 21:52:55 +01:00
|
|
|
|
2012-07-16 17:47:06 +02:00
|
|
|
if(global.menu) {
|
|
|
|
glPushMatrix();
|
|
|
|
glTranslatef(VIEWPORT_X,VIEWPORT_Y,0);
|
|
|
|
draw_ingame_menu(global.menu);
|
|
|
|
glPopMatrix();
|
|
|
|
}
|
2012-01-06 21:52:55 +01:00
|
|
|
|
2012-07-16 17:47:06 +02:00
|
|
|
draw_hud();
|
2012-01-06 21:52:55 +01:00
|
|
|
|
2012-07-16 17:47:06 +02:00
|
|
|
if(global.menu) {
|
|
|
|
// horrible hacks because we have no sane transitions between ingame menus
|
|
|
|
|
|
|
|
if(REPLAY_ASKSAVE) {
|
|
|
|
if(global.menu->context && global.menu->quit == 1) {
|
|
|
|
fade_out(global.menu->fade);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fade_out(global.menu->fade);
|
|
|
|
}
|
|
|
|
}
|
2011-06-13 18:48:36 +02:00
|
|
|
}
|
|
|
|
|
2012-01-06 21:52:55 +01:00
|
|
|
void apply_bg_shaders(ShaderRule *shaderrules) {
|
|
|
|
int fbonum = 0;
|
|
|
|
int i;
|
|
|
|
|
2011-08-23 17:37:14 +02:00
|
|
|
if(global.boss && global.boss->current && global.boss->current->draw_rule) {
|
2012-01-06 21:52:55 +01:00
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, resources.fbg[0].fbo);
|
2011-08-23 17:37:14 +02:00
|
|
|
global.boss->current->draw_rule(global.boss, global.frames - global.boss->current->starttime);
|
2011-06-13 18:48:36 +02:00
|
|
|
|
2011-08-26 15:19:14 +02:00
|
|
|
glPushMatrix();
|
|
|
|
glTranslatef(creal(global.boss->pos), cimag(global.boss->pos), 0);
|
|
|
|
glRotatef(global.frames*7.0, 0, 0, -1);
|
|
|
|
|
|
|
|
int t;
|
|
|
|
if((t = global.frames - global.boss->current->starttime) < 0) {
|
|
|
|
float f = 1.0 - t/(float)ATTACK_START_DELAY;
|
|
|
|
glScalef(f,f,f);
|
|
|
|
}
|
|
|
|
|
|
|
|
draw_texture(0,0,"boss_spellcircle0");
|
|
|
|
glPopMatrix();
|
|
|
|
|
2011-12-25 08:18:03 +01:00
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
2012-07-13 22:42:35 +02:00
|
|
|
} else if(!global.nostagebg) {
|
2012-01-06 21:52:55 +01:00
|
|
|
for(i = 0; shaderrules != NULL && shaderrules[i] != NULL; i++) {
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, resources.fbg[!fbonum].fbo);
|
|
|
|
shaderrules[i](fbonum);
|
|
|
|
|
|
|
|
fbonum = !fbonum;
|
|
|
|
}
|
2011-08-23 17:37:14 +02:00
|
|
|
}
|
|
|
|
|
2011-12-25 08:18:03 +01:00
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, resources.fsec.fbo);
|
2011-08-23 17:37:14 +02:00
|
|
|
|
2011-04-25 19:40:21 +02:00
|
|
|
if(global.boss) { // Boss background shader
|
2012-04-05 16:27:18 +02:00
|
|
|
Shader *shader = get_shader("boss_zoom");
|
|
|
|
glUseProgram(shader->prog);
|
2011-04-25 19:40:21 +02:00
|
|
|
|
2011-08-23 17:37:14 +02:00
|
|
|
complex fpos = VIEWPORT_H*I + conj(global.boss->pos) + (VIEWPORT_X + VIEWPORT_Y*I);
|
|
|
|
complex pos = fpos + 15*cexp(I*global.frames/4.5);
|
2011-04-25 19:40:21 +02:00
|
|
|
|
2012-04-05 16:27:18 +02:00
|
|
|
glUniform2f(uniloc(shader, "blur_orig"),
|
2012-01-06 21:52:55 +01:00
|
|
|
creal(pos)/resources.fbg[fbonum].nw, cimag(pos)/resources.fbg[fbonum].nh);
|
2012-04-05 16:27:18 +02:00
|
|
|
glUniform2f(uniloc(shader, "fix_orig"),
|
2012-01-06 21:52:55 +01:00
|
|
|
creal(fpos)/resources.fbg[fbonum].nw, cimag(fpos)/resources.fbg[fbonum].nh);
|
2012-04-05 16:27:18 +02:00
|
|
|
glUniform1f(uniloc(shader, "blur_rad"), 0.2+0.025*sin(global.frames/15.0));
|
|
|
|
glUniform1f(uniloc(shader, "rad"), 0.24);
|
|
|
|
glUniform1f(uniloc(shader, "ratio"), (float)resources.fbg[fbonum].nh/resources.fbg[fbonum].nw);
|
2012-07-18 15:02:26 +02:00
|
|
|
if(global.boss->zoomcolor)
|
|
|
|
glUniform4f(uniloc(shader, "color"), global.boss->zoomcolor->r,
|
|
|
|
global.boss->zoomcolor->g,
|
|
|
|
global.boss->zoomcolor->b,
|
|
|
|
global.boss->zoomcolor->a);
|
|
|
|
else
|
|
|
|
glUniform4f(uniloc(shader, "color"), 0.1, 0.2, 0.3, 1);
|
2011-04-25 19:40:21 +02:00
|
|
|
}
|
|
|
|
|
2012-01-06 21:52:55 +01:00
|
|
|
draw_fbo_viewport(&resources.fbg[fbonum]);
|
2011-04-25 19:40:21 +02:00
|
|
|
|
2011-12-25 08:18:03 +01:00
|
|
|
glUseProgram(0);
|
2011-07-05 15:20:19 +02:00
|
|
|
|
|
|
|
if(global.frames - global.plr.recovery < 0) {
|
|
|
|
float t = BOMB_RECOVERY - global.plr.recovery + global.frames;
|
|
|
|
float fade = 1;
|
|
|
|
|
|
|
|
if(t < BOMB_RECOVERY/6)
|
|
|
|
fade = t/BOMB_RECOVERY*6;
|
|
|
|
|
|
|
|
if(t > BOMB_RECOVERY/4*3)
|
|
|
|
fade = 1-t/BOMB_RECOVERY*4 + 3;
|
|
|
|
|
|
|
|
glPushMatrix();
|
|
|
|
glTranslatef(-30,-30,0);
|
|
|
|
fade_out(fade*0.6);
|
|
|
|
glPopMatrix();
|
|
|
|
}
|
2011-04-25 19:40:21 +02:00
|
|
|
}
|
|
|
|
|
2012-01-06 21:52:55 +01:00
|
|
|
void stage_logic(int time) {
|
2011-06-13 18:48:36 +02:00
|
|
|
if(global.menu) {
|
|
|
|
ingame_menu_logic(&global.menu);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-12 10:55:23 +02:00
|
|
|
player_logic(&global.plr);
|
|
|
|
|
2011-04-26 12:04:45 +02:00
|
|
|
process_enemies(&global.enemies);
|
2011-05-06 17:09:43 +02:00
|
|
|
process_projectiles(&global.projs, True);
|
2011-04-29 10:26:37 +02:00
|
|
|
process_items();
|
2011-04-24 15:39:17 +02:00
|
|
|
process_lasers();
|
2011-05-13 19:03:02 +02:00
|
|
|
process_projectiles(&global.particles, False);
|
2010-10-12 10:55:23 +02:00
|
|
|
|
2011-08-23 17:37:14 +02:00
|
|
|
if(global.boss && !global.dialog) {
|
2011-04-08 18:59:03 +02:00
|
|
|
process_boss(global.boss);
|
2011-05-09 13:42:02 +02:00
|
|
|
if(global.boss->dmg > global.boss->attacks[global.boss->acount-1].dmglimit)
|
|
|
|
boss_death(&global.boss);
|
2011-04-08 18:59:03 +02:00
|
|
|
}
|
2011-05-08 13:48:25 +02:00
|
|
|
|
2010-10-12 10:55:23 +02:00
|
|
|
global.frames++;
|
2011-05-08 13:48:25 +02:00
|
|
|
|
2012-07-14 19:46:03 +02:00
|
|
|
if(!global.dialog && !global.boss)
|
|
|
|
global.timer++;
|
2011-06-13 18:48:36 +02:00
|
|
|
|
2012-01-06 21:52:55 +01:00
|
|
|
if(global.timer >= time)
|
|
|
|
global.game_over = GAMEOVER_WIN;
|
|
|
|
|
2010-10-12 10:55:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void stage_end() {
|
2011-05-06 17:09:43 +02:00
|
|
|
delete_projectiles(&global.projs);
|
2011-06-13 18:48:36 +02:00
|
|
|
delete_projectiles(&global.particles);
|
2011-04-26 22:39:50 +02:00
|
|
|
delete_enemies(&global.enemies);
|
2011-04-29 10:26:37 +02:00
|
|
|
delete_items();
|
2011-04-26 22:47:13 +02:00
|
|
|
delete_lasers();
|
2011-06-27 08:20:42 +02:00
|
|
|
|
2011-06-13 18:48:36 +02:00
|
|
|
if(global.menu) {
|
|
|
|
destroy_menu(global.menu);
|
|
|
|
global.menu = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(global.dialog) {
|
|
|
|
delete_dialog(global.dialog);
|
|
|
|
global.dialog = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(global.boss) {
|
|
|
|
free_boss(global.boss);
|
|
|
|
global.boss = NULL;
|
|
|
|
}
|
2010-10-12 10:55:23 +02:00
|
|
|
}
|
2011-06-25 12:41:40 +02:00
|
|
|
|
2012-07-14 19:46:03 +02:00
|
|
|
void stage_loop(StageInfo* info, StageRule start, StageRule end, StageRule draw, StageRule event, ShaderRule *shaderrules, int endtime) {
|
2012-01-06 21:52:55 +01:00
|
|
|
if(global.game_over == GAMEOVER_WIN) {
|
|
|
|
global.game_over = 0;
|
|
|
|
} else if(global.game_over) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-14 19:46:03 +02:00
|
|
|
int seed = time(0);
|
|
|
|
srand(seed);
|
|
|
|
|
|
|
|
if(global.replaymode == REPLAY_RECORD) {
|
|
|
|
replay_destroy(&global.replay);
|
2012-07-17 14:17:53 +02:00
|
|
|
if(!global.plr.continues)
|
|
|
|
replay_init(&global.replay, info, seed, &global.plr);
|
2012-07-15 12:16:27 +02:00
|
|
|
printf("Random seed: %d\n", seed);
|
2012-07-14 19:46:03 +02:00
|
|
|
} else {
|
|
|
|
printf("REPLAY_PLAY mode: %d events\n", global.replay.ecount);
|
|
|
|
|
|
|
|
srand(global.replay.seed);
|
2012-07-15 12:16:27 +02:00
|
|
|
printf("Random seed: %d\n", global.replay.seed);
|
|
|
|
|
2012-07-14 19:46:03 +02:00
|
|
|
global.diff = global.replay.diff;
|
|
|
|
global.points = global.replay.points;
|
|
|
|
|
|
|
|
global.plr.shot = global.replay.plr_shot;
|
|
|
|
global.plr.cha = global.replay.plr_char;
|
|
|
|
global.plr.pos = global.replay.plr_pos;
|
|
|
|
global.plr.lifes = global.replay.plr_lifes;
|
|
|
|
global.plr.bombs = global.replay.plr_bombs;
|
|
|
|
global.plr.power = global.replay.plr_power;
|
|
|
|
}
|
|
|
|
|
2011-06-25 12:41:40 +02:00
|
|
|
stage_start();
|
|
|
|
start();
|
|
|
|
|
|
|
|
while(global.game_over <= 0) {
|
2012-07-15 18:54:01 +02:00
|
|
|
if(!global.boss && !global.dialog && !global.menu)
|
2011-08-23 17:37:14 +02:00
|
|
|
event();
|
2012-07-14 19:46:03 +02:00
|
|
|
((global.replaymode == REPLAY_PLAY)? replay_input : stage_input)();
|
2012-07-14 08:34:34 +02:00
|
|
|
stage_logic(endtime);
|
2012-07-17 09:55:06 +02:00
|
|
|
|
2012-07-14 08:34:34 +02:00
|
|
|
calc_fps(&global.fps);
|
2012-01-06 21:52:55 +01:00
|
|
|
|
|
|
|
stage_draw(draw, shaderrules, endtime);
|
2011-06-25 12:41:40 +02:00
|
|
|
|
|
|
|
SDL_GL_SwapBuffers();
|
|
|
|
frame_rate(&global.lasttime);
|
|
|
|
}
|
|
|
|
|
2012-07-16 17:47:06 +02:00
|
|
|
if(global.replaymode == REPLAY_RECORD) {
|
2012-07-14 19:46:03 +02:00
|
|
|
replay_event(&global.replay, EV_OVER, 0);
|
2012-07-16 17:47:06 +02:00
|
|
|
|
|
|
|
if(REPLAY_ASKSAVE) {
|
|
|
|
global.menu = create_saverpy_menu();
|
|
|
|
while(global.menu) {
|
|
|
|
ingame_menu_logic(&global.menu);
|
|
|
|
|
|
|
|
if(!global.menu)
|
|
|
|
break;
|
2012-07-17 09:55:06 +02:00
|
|
|
|
2012-07-16 17:47:06 +02:00
|
|
|
menu_input(global.menu);
|
|
|
|
stage_draw(draw, shaderrules, endtime);
|
|
|
|
|
|
|
|
SDL_GL_SwapBuffers();
|
|
|
|
frame_rate(&global.lasttime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(global.replay.active && tconfig.intval[SAVE_RPY] == 1)
|
|
|
|
save_rpy(NULL);
|
|
|
|
}
|
2012-07-14 19:46:03 +02:00
|
|
|
|
2011-06-25 12:41:40 +02:00
|
|
|
end();
|
|
|
|
stage_end();
|
|
|
|
}
|
2012-07-14 19:46:03 +02:00
|
|
|
|
2011-11-06 16:17:46 +01:00
|
|
|
void draw_stage_title(int t, int dur, char *stage, char *subtitle) {
|
|
|
|
if(t < 0 || t > dur)
|
|
|
|
return;
|
|
|
|
|
|
|
|
draw_text(AL_Center, VIEWPORT_W/2, VIEWPORT_H/2, stage, _fonts.mainmenu);
|
2012-07-13 22:42:35 +02:00
|
|
|
}
|