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 "player.h"
|
|
|
|
|
|
|
|
#include <SDL/SDL.h>
|
|
|
|
#include "projectile.h"
|
|
|
|
#include "global.h"
|
2011-04-10 11:19:44 +02:00
|
|
|
#include "plrmodes.h"
|
2010-10-12 10:55:23 +02:00
|
|
|
|
2011-04-29 10:26:37 +02:00
|
|
|
void init_player(Player* plr, Character cha, ShotMode shot) {
|
2011-03-18 19:03:06 +01:00
|
|
|
plr->pos = VIEWPORT_W/2 + I*(VIEWPORT_H-20);
|
2010-10-12 10:55:23 +02:00
|
|
|
|
|
|
|
plr->focus = False;
|
|
|
|
plr->fire = False;
|
|
|
|
plr->moving = False;
|
|
|
|
plr->dir = 0;
|
2011-03-23 12:26:30 +01:00
|
|
|
plr->power = 0;
|
|
|
|
|
2011-04-10 10:23:24 +02:00
|
|
|
plr->lifes = 2;
|
2011-03-23 12:26:30 +01:00
|
|
|
plr->bombs = 3;
|
|
|
|
|
2011-04-10 11:19:44 +02:00
|
|
|
plr->slaves = NULL;
|
|
|
|
|
2011-03-23 12:26:30 +01:00
|
|
|
plr->recovery = 0;
|
2010-10-12 10:55:23 +02:00
|
|
|
|
|
|
|
plr->cha = cha;
|
2011-04-29 10:26:37 +02:00
|
|
|
plr->shot = shot;
|
2010-10-12 10:55:23 +02:00
|
|
|
|
2011-04-10 11:19:44 +02:00
|
|
|
switch(cha) {
|
|
|
|
case Youmu:
|
|
|
|
plr->ani = get_ani("youmu");
|
|
|
|
break;
|
|
|
|
case Marisa:
|
|
|
|
plr->ani = get_ani("marisa");
|
|
|
|
break;
|
|
|
|
}
|
2010-10-12 10:55:23 +02:00
|
|
|
}
|
|
|
|
|
2011-04-10 11:19:44 +02:00
|
|
|
void player_draw(Player* plr) {
|
2011-04-26 12:04:45 +02:00
|
|
|
draw_enemies(plr->slaves);
|
2011-04-10 11:19:44 +02:00
|
|
|
|
2010-10-12 10:55:23 +02:00
|
|
|
glPushMatrix();
|
2011-03-18 19:03:06 +01:00
|
|
|
glTranslatef(creal(plr->pos), cimag(plr->pos), 0);
|
2010-11-28 12:54:13 +01:00
|
|
|
|
|
|
|
if(plr->focus != 0) {
|
|
|
|
glPushMatrix();
|
|
|
|
glRotatef(global.frames*10, 0, 0, 1);
|
2011-03-19 09:11:05 +01:00
|
|
|
glScalef(1, 1, 1);
|
2010-11-28 12:54:13 +01:00
|
|
|
glColor4f(1,1,1,0.2);
|
2011-03-19 16:21:48 +01:00
|
|
|
draw_texture(0, 0, "fairy_circle");
|
2010-11-28 12:54:13 +01:00
|
|
|
glColor4f(1,1,1,1);
|
|
|
|
glPopMatrix();
|
|
|
|
}
|
|
|
|
|
|
|
|
glDisable(GL_CULL_FACE);
|
|
|
|
if(plr->dir) {
|
|
|
|
glPushMatrix();
|
|
|
|
glScalef(-1,1,1);
|
|
|
|
}
|
|
|
|
|
2011-03-29 15:55:46 +02:00
|
|
|
if(global.frames - abs(plr->recovery) < 0 && (global.frames/17)&1)
|
|
|
|
glColor4f(0.8,0.8,1,0.9);
|
|
|
|
|
2011-03-19 16:21:48 +01:00
|
|
|
draw_animation_p(0, 0, !plr->moving, plr->ani);
|
2010-11-28 12:54:13 +01:00
|
|
|
|
2011-03-29 15:55:46 +02:00
|
|
|
glColor4f(1,1,1,1);
|
|
|
|
|
2010-11-28 12:54:13 +01:00
|
|
|
if(plr->dir)
|
|
|
|
glPopMatrix();
|
|
|
|
|
|
|
|
glEnable(GL_CULL_FACE);
|
|
|
|
|
|
|
|
if(plr->focus != 0) {
|
|
|
|
glPushMatrix();
|
|
|
|
glColor4f(1,1,1,fabs((float)plr->focus/30.0f));
|
|
|
|
glRotatef(global.frames, 0, 0, -1);
|
2011-03-19 16:21:48 +01:00
|
|
|
draw_texture(0, 0, "focus");
|
2010-11-28 12:54:13 +01:00
|
|
|
glColor4f(1,1,1,1);
|
|
|
|
glPopMatrix();
|
|
|
|
}
|
|
|
|
|
2010-10-12 10:55:23 +02:00
|
|
|
glPopMatrix();
|
|
|
|
}
|
|
|
|
|
|
|
|
void player_logic(Player* plr) {
|
2011-04-26 12:04:45 +02:00
|
|
|
process_enemies(&plr->slaves);
|
2011-04-10 11:19:44 +02:00
|
|
|
|
2011-04-29 10:26:37 +02:00
|
|
|
if(plr->fire && plr->cha == Youmu) {
|
|
|
|
if(!(global.frames % 4)) {
|
2011-05-21 15:02:19 +02:00
|
|
|
create_projectile("youmu", plr->pos + 10 - I*20, NULL, linear, rarg(-20I))->type = PlrProj;
|
|
|
|
create_projectile("youmu", plr->pos - 10 - I*20, NULL, linear, rarg(-20I))->type = PlrProj;
|
2011-05-06 17:09:43 +02:00
|
|
|
|
2011-04-29 10:26:37 +02:00
|
|
|
if(plr->power >= 2) {
|
|
|
|
float a = 0.20;
|
|
|
|
if(plr->focus > 0) a = 0.06;
|
2011-05-21 15:02:19 +02:00
|
|
|
create_projectile("youmu", plr->pos - 10 - I*20, NULL, linear, rarg(I*-20*cexp(-I*a)))->type = PlrProj;
|
|
|
|
create_projectile("youmu", plr->pos + 10 - I*20, NULL, linear, rarg(I*-20*cexp(I*a)))->type = PlrProj;
|
2011-04-29 10:26:37 +02:00
|
|
|
}
|
2010-11-14 13:24:56 +01:00
|
|
|
}
|
2011-04-29 10:26:37 +02:00
|
|
|
|
|
|
|
float a = 1;
|
|
|
|
if(plr->focus > 0)
|
2011-05-14 17:26:43 +02:00
|
|
|
a = 0.4;
|
2011-05-13 19:03:02 +02:00
|
|
|
if(plr->shot == YoumuHoming && !(global.frames % 7)) {
|
|
|
|
complex ref = -1;
|
|
|
|
if(global.boss != NULL)
|
|
|
|
ref = add_ref(global.boss);
|
|
|
|
else if(global.enemies != NULL)
|
|
|
|
ref = add_ref(global.enemies);
|
|
|
|
|
|
|
|
if(ref != -1)
|
2011-05-21 15:02:19 +02:00
|
|
|
create_projectile("hghost", plr->pos, NULL, youmu_homing, rarg(a*cexp(I*rand()), ref))->type = PlrProj;
|
2011-05-13 19:03:02 +02:00
|
|
|
}
|
2010-10-12 10:55:23 +02:00
|
|
|
}
|
2011-03-23 12:26:30 +01:00
|
|
|
|
2010-11-28 12:54:13 +01:00
|
|
|
if(plr->focus < 0 || (plr->focus > 0 && plr->focus < 30))
|
|
|
|
plr->focus++;
|
2011-04-10 10:23:24 +02:00
|
|
|
|
2011-04-29 10:26:37 +02:00
|
|
|
if(plr->shot == YoumuOpposite && plr->slaves == NULL)
|
2011-04-26 12:04:45 +02:00
|
|
|
create_enemy(&plr->slaves, youmu_opposite_draw, youmu_opposite_logic, plr->pos, ENEMY_IMMUNE, plr, 0);
|
2011-03-23 12:26:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void plr_bomb(Player *plr) {
|
2011-04-10 10:23:24 +02:00
|
|
|
if(global.frames - plr->recovery >= 0 && plr->bombs > 0) {
|
2011-04-26 12:04:45 +02:00
|
|
|
Enemy *e;
|
|
|
|
for(e = global.enemies; e; e = e->next)
|
|
|
|
if(e->hp != ENEMY_IMMUNE)
|
|
|
|
e->hp = 0;
|
|
|
|
|
2011-05-06 17:09:43 +02:00
|
|
|
delete_projectiles(&global.projs);
|
2011-04-02 12:14:37 +02:00
|
|
|
|
|
|
|
play_sound("laser1");
|
|
|
|
|
2011-03-23 12:26:30 +01:00
|
|
|
plr->bombs--;
|
|
|
|
plr->recovery = global.frames + 200;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void plr_death(Player *plr) {
|
2011-04-10 10:23:24 +02:00
|
|
|
if(plr->lifes-- == 0) {
|
2011-03-23 12:26:30 +01:00
|
|
|
game_over();
|
|
|
|
} else {
|
2011-04-29 10:26:37 +02:00
|
|
|
create_item(plr->pos, 6-15*I, Power);
|
|
|
|
create_item(plr->pos, -6-15*I, Power);
|
2011-03-23 12:26:30 +01:00
|
|
|
|
|
|
|
plr->pos = VIEWPORT_W/2 + VIEWPORT_H*I;
|
2011-03-29 15:55:46 +02:00
|
|
|
plr->recovery = -(global.frames + 200);
|
2011-03-23 12:26:30 +01:00
|
|
|
|
|
|
|
if(global.plr.bombs < 2)
|
|
|
|
global.plr.bombs = 2;
|
|
|
|
}
|
2011-04-10 11:19:44 +02:00
|
|
|
|
2011-04-24 15:39:17 +02:00
|
|
|
if(plr->slaves)
|
2011-04-26 22:39:50 +02:00
|
|
|
delete_enemies(&plr->slaves);
|
2010-10-12 10:55:23 +02:00
|
|
|
}
|