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>
|
|
|
|
#include "global.h"
|
2011-06-13 18:48:36 +02:00
|
|
|
#include "menu/ingamemenu.h"
|
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;
|
2010-10-12 10:55:23 +02:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-05-13 19:03:02 +02:00
|
|
|
SDL_Event event;
|
2010-10-12 10:55:23 +02:00
|
|
|
while(SDL_PollEvent(&event)) {
|
2011-05-21 18:20:04 +02:00
|
|
|
int sym = event.key.keysym.sym;
|
2010-10-12 10:55:23 +02:00
|
|
|
if(event.type == SDL_KEYDOWN) {
|
2011-05-21 18:20:04 +02:00
|
|
|
if(sym == tconfig.intval[KEY_FOCUS])
|
|
|
|
global.plr.focus = 1;
|
|
|
|
else if(sym == tconfig.intval[KEY_SHOT]) {
|
|
|
|
if(!global.dialog)
|
|
|
|
global.plr.fire = True;
|
|
|
|
else
|
|
|
|
page_dialog(&global.dialog);
|
|
|
|
} else if(sym == tconfig.intval[KEY_BOMB]) {
|
|
|
|
if(!global.dialog)
|
|
|
|
plr_bomb(&global.plr);
|
|
|
|
} else if(sym == SDLK_ESCAPE) {
|
2011-06-13 18:48:36 +02:00
|
|
|
if(!global.menu)
|
|
|
|
global.menu = create_ingame_menu();
|
|
|
|
else
|
|
|
|
global.menu->quit = 1;
|
2010-10-12 10:55:23 +02:00
|
|
|
}
|
|
|
|
} else if(event.type == SDL_KEYUP) {
|
2011-05-21 18:20:04 +02:00
|
|
|
if(sym == tconfig.intval[KEY_FOCUS])
|
|
|
|
global.plr.focus = -30; // that's for the transparency timer
|
|
|
|
else if(sym == tconfig.intval[KEY_SHOT])
|
|
|
|
global.plr.fire = False;
|
2010-10-12 10:55:23 +02:00
|
|
|
} else if(event.type == SDL_QUIT) {
|
2011-06-13 18:48:36 +02:00
|
|
|
exit(1);
|
2010-10-12 10:55:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-07 07:26:43 +01:00
|
|
|
float speed = 0.01*VIEWPORT_W/((global.plr.focus > 0)+1);
|
2010-10-12 10:55:23 +02:00
|
|
|
|
|
|
|
Uint8 *keys = SDL_GetKeyState(NULL);
|
|
|
|
|
|
|
|
global.plr.moving = False;
|
|
|
|
|
2011-05-21 18:20:04 +02:00
|
|
|
if(keys[tconfig.intval[KEY_LEFT]] && !keys[tconfig.intval[KEY_RIGHT]]) {
|
2010-10-12 10:55:23 +02:00
|
|
|
global.plr.moving = True;
|
|
|
|
global.plr.dir = 1;
|
2011-05-21 18:20:04 +02:00
|
|
|
} else if(keys[tconfig.intval[KEY_RIGHT]] && !keys[tconfig.intval[KEY_LEFT]]) {
|
2010-10-12 10:55:23 +02:00
|
|
|
global.plr.moving = True;
|
|
|
|
global.plr.dir = 0;
|
|
|
|
}
|
|
|
|
|
2011-05-21 18:20:04 +02:00
|
|
|
if(keys[tconfig.intval[KEY_LEFT]] && creal(global.plr.pos) - global.plr.ani->w/2 - speed > 0)
|
2011-03-18 19:03:06 +01:00
|
|
|
global.plr.pos -= speed;
|
2011-05-21 18:20:04 +02:00
|
|
|
if(keys[tconfig.intval[KEY_RIGHT]] && creal(global.plr.pos) + global.plr.ani->w/2 + speed < VIEWPORT_W)
|
2011-03-18 19:03:06 +01:00
|
|
|
global.plr.pos += speed;
|
2011-05-21 18:20:04 +02:00
|
|
|
if(keys[tconfig.intval[KEY_UP]] && cimag(global.plr.pos) - global.plr.ani->h/2 - speed > 0)
|
2011-03-18 19:03:06 +01:00
|
|
|
global.plr.pos -= I*speed;
|
2011-05-21 18:20:04 +02:00
|
|
|
if(keys[tconfig.intval[KEY_DOWN]] && cimag(global.plr.pos) + global.plr.ani->h/2 + speed < VIEWPORT_H)
|
2011-03-18 19:03:06 +01:00
|
|
|
global.plr.pos += I*speed;
|
2011-06-13 18:48:36 +02:00
|
|
|
|
|
|
|
if(!keys[tconfig.intval[KEY_SHOT]] && global.plr.fire)
|
|
|
|
global.plr.fire = False;
|
|
|
|
if(!keys[tconfig.intval[KEY_FOCUS]] && global.plr.focus > 0)
|
|
|
|
global.plr.focus = -30;
|
2010-10-12 10:55:23 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-05-08 13:48:25 +02:00
|
|
|
void draw_hud() {
|
|
|
|
draw_texture(SCREEN_W/2, SCREEN_H/2, "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);
|
|
|
|
|
|
|
|
// glColor3f(1,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");
|
|
|
|
// glColor3f(0,1,0);
|
|
|
|
for(i = 0; i < global.plr.bombs; i++)
|
|
|
|
draw_texture(16*i,200, "star");
|
|
|
|
glColor3f(1,1,1);
|
|
|
|
|
|
|
|
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
|
|
|
|
2011-06-13 18:48:36 +02:00
|
|
|
sprintf(buf, "%i fps", global.fps.show_fps);
|
2011-06-24 12:35:03 +02:00
|
|
|
draw_text(AL_Left, SCREEN_W, SCREEN_H-20, buf, _fonts.standard);
|
2010-10-12 10:55:23 +02:00
|
|
|
}
|
|
|
|
|
2011-05-08 13:48:25 +02:00
|
|
|
void stage_draw() {
|
2011-06-24 12:35:03 +02:00
|
|
|
set_ortho();
|
2011-06-13 18:48:36 +02:00
|
|
|
|
2011-05-08 13:48:25 +02:00
|
|
|
glPushMatrix();
|
|
|
|
glTranslatef(VIEWPORT_X,VIEWPORT_Y,0);
|
2011-06-13 18:48:36 +02:00
|
|
|
|
|
|
|
if(!global.menu) {
|
|
|
|
apply_bg_shaders();
|
|
|
|
glPushMatrix();
|
|
|
|
glTranslatef(-VIEWPORT_X/3.0,0,0);
|
2011-05-08 13:48:25 +02:00
|
|
|
|
2011-06-13 18:48:36 +02:00
|
|
|
player_draw(&global.plr);
|
|
|
|
|
|
|
|
draw_projectiles(global.projs);
|
|
|
|
draw_enemies(global.enemies);
|
|
|
|
draw_items();
|
|
|
|
draw_lasers();
|
|
|
|
|
|
|
|
if(global.boss)
|
|
|
|
draw_boss(global.boss);
|
|
|
|
|
|
|
|
draw_projectiles(global.particles);
|
|
|
|
|
|
|
|
if(global.dialog)
|
|
|
|
draw_dialog(global.dialog);
|
2011-05-08 13:48:25 +02:00
|
|
|
|
2011-05-09 13:42:02 +02:00
|
|
|
glPopMatrix();
|
2011-06-13 18:48:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
|
|
|
draw_fbo_viewport(&global.fsec);
|
|
|
|
} if(global.menu) {
|
|
|
|
draw_ingame_menu(global.menu);
|
2011-05-09 13:42:02 +02:00
|
|
|
}
|
2011-06-13 18:48:36 +02:00
|
|
|
glPopMatrix();
|
|
|
|
draw_hud();
|
2011-05-09 13:42:02 +02:00
|
|
|
|
2011-06-13 18:48:36 +02:00
|
|
|
if(global.frames < FADE_TIME)
|
|
|
|
fade_out(1.0 - global.frames/(float)FADE_TIME);
|
|
|
|
if(global.menu && global.menu->selected == 1) {
|
|
|
|
fade_out(global.menu->fade);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void apply_bg_shaders() {
|
|
|
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, global.fsec.fbo);
|
|
|
|
|
2011-04-25 19:40:21 +02:00
|
|
|
if(global.boss) { // Boss background shader
|
|
|
|
GLuint shader = get_shader("boss_zoom");
|
|
|
|
glUseProgram(shader);
|
|
|
|
|
2011-06-13 18:48:36 +02:00
|
|
|
complex fpos = VIEWPORT_H*I + conj(global.boss->pos) + (VIEWPORT_X + VIEWPORT_Y*I)*0.5;
|
|
|
|
complex pos = fpos + 15*cexp(I*global.frames/5.0);
|
2011-04-25 19:40:21 +02:00
|
|
|
|
|
|
|
glUniform2f(glGetUniformLocation(shader, "blur_orig"),
|
2011-06-13 18:48:36 +02:00
|
|
|
creal(pos)/global.fbg.nw, cimag(pos)/global.fbg.nh);
|
2011-04-25 19:40:21 +02:00
|
|
|
glUniform2f(glGetUniformLocation(shader, "fix_orig"),
|
2011-06-13 18:48:36 +02:00
|
|
|
creal(fpos)/global.fbg.nw, cimag(fpos)/global.fbg.nh);
|
2011-05-09 13:42:02 +02:00
|
|
|
glUniform1f(glGetUniformLocation(shader, "blur_rad"), 0.2+0.05*sin(global.frames/10.0));
|
2011-04-25 19:40:21 +02:00
|
|
|
glUniform1f(glGetUniformLocation(shader, "rad"), 0.3);
|
2011-06-13 18:48:36 +02:00
|
|
|
glUniform1f(glGetUniformLocation(shader, "ratio"), (float)global.fbg.nh/global.fbg.nw);
|
2011-04-25 19:40:21 +02:00
|
|
|
}
|
|
|
|
|
2011-06-13 18:48:36 +02:00
|
|
|
draw_fbo_viewport(&global.fbg);
|
2011-04-25 19:40:21 +02:00
|
|
|
|
|
|
|
glUseProgramObjectARB(0);
|
2011-06-13 18:48:36 +02:00
|
|
|
|
|
|
|
if(global.boss && global.boss->current && global.boss->current->draw_rule) {
|
|
|
|
glPushMatrix();
|
|
|
|
glTranslatef(-VIEWPORT_X,0,0); // Some transformation for convenience. Don't ask why. it's because of rtt.
|
|
|
|
glScalef((VIEWPORT_W+VIEWPORT_X)/(float)VIEWPORT_W, (VIEWPORT_H+VIEWPORT_Y)/(float)VIEWPORT_H, 1);
|
|
|
|
global.boss->current->draw_rule(global.boss, global.frames - global.boss->current->starttime);
|
|
|
|
glPopMatrix();
|
|
|
|
}
|
2011-04-25 19:40:21 +02:00
|
|
|
}
|
|
|
|
|
2010-10-12 10:55:23 +02:00
|
|
|
void stage_logic() {
|
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-04-08 18:59:03 +02:00
|
|
|
if(global.boss) {
|
|
|
|
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
|
|
|
|
2011-06-26 13:45:27 +02:00
|
|
|
if(!global.dialog && !global.boss)
|
2011-05-08 13:48:25 +02:00
|
|
|
global.timer++;
|
2011-06-13 18:48:36 +02:00
|
|
|
|
|
|
|
calc_fps(&global.fps);
|
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-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
|
|
|
|
|
|
|
void stage_loop(StageRule start, StageRule end, StageRule draw, StageRule event) {
|
|
|
|
stage_start();
|
|
|
|
start();
|
|
|
|
|
|
|
|
while(global.game_over <= 0) {
|
|
|
|
event();
|
|
|
|
stage_input();
|
|
|
|
stage_logic();
|
|
|
|
|
|
|
|
draw();
|
|
|
|
stage_draw();
|
|
|
|
|
|
|
|
SDL_GL_SwapBuffers();
|
|
|
|
frame_rate(&global.lasttime);
|
|
|
|
}
|
|
|
|
|
|
|
|
end();
|
|
|
|
stage_end();
|
|
|
|
}
|
2010-10-12 10:55:23 +02:00
|
|
|
|