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
|
2017-02-10 23:05:22 +01:00
|
|
|
* See COPYING for further information.
|
2011-03-05 13:44:21 +01:00
|
|
|
* ---
|
2019-01-23 21:10:43 +01:00
|
|
|
* Copyright (c) 2011-2019, Lukas Weber <laochailan@web.de>.
|
|
|
|
* Copyright (c) 2012-2019, Andrei Alexeyev <akari@alienslab.net>.
|
2010-10-12 10:55:23 +02:00
|
|
|
*/
|
|
|
|
|
2017-11-25 20:45:11 +01:00
|
|
|
#include "taisei.h"
|
|
|
|
|
2010-10-12 10:55:23 +02:00
|
|
|
#include "player.h"
|
|
|
|
|
|
|
|
#include "projectile.h"
|
|
|
|
#include "global.h"
|
2011-04-10 11:19:44 +02:00
|
|
|
#include "plrmodes.h"
|
2012-08-17 20:58:23 +02:00
|
|
|
#include "stage.h"
|
2017-09-16 03:15:34 +02:00
|
|
|
#include "stagetext.h"
|
2018-07-04 10:36:16 +02:00
|
|
|
#include "stagedraw.h"
|
2018-04-13 21:13:48 +02:00
|
|
|
#include "entity.h"
|
2010-10-12 10:55:23 +02:00
|
|
|
|
2017-10-08 13:30:51 +02:00
|
|
|
void player_init(Player *plr) {
|
2011-06-25 12:41:40 +02:00
|
|
|
memset(plr, 0, sizeof(Player));
|
2019-03-05 12:50:29 +01:00
|
|
|
plr->pos = PLR_SPAWN_POS;
|
2017-03-21 11:09:32 +01:00
|
|
|
plr->lives = PLR_START_LIVES;
|
2011-07-02 12:45:32 +02:00
|
|
|
plr->bombs = PLR_START_BOMBS;
|
2019-02-22 00:56:03 +01:00
|
|
|
plr->point_item_value = PLR_START_PIV;
|
|
|
|
plr->power = 100;
|
2011-06-25 12:41:40 +02:00
|
|
|
plr->deathtime = -1;
|
2017-10-29 23:45:24 +01:00
|
|
|
plr->continuetime = -1;
|
2017-10-08 13:30:51 +02:00
|
|
|
plr->mode = plrmode_find(0, 0);
|
2011-07-04 09:14:08 +02:00
|
|
|
}
|
|
|
|
|
2017-10-08 13:30:51 +02:00
|
|
|
void player_stage_pre_init(Player *plr) {
|
2017-02-15 17:09:09 +01:00
|
|
|
plr->recovery = 0;
|
|
|
|
plr->respawntime = 0;
|
|
|
|
plr->deathtime = -1;
|
|
|
|
plr->axis_lr = 0;
|
|
|
|
plr->axis_ud = 0;
|
2017-10-08 23:12:38 +02:00
|
|
|
plrmode_preload(plr->mode);
|
2017-10-08 13:30:51 +02:00
|
|
|
}
|
|
|
|
|
2018-05-02 08:08:32 +02:00
|
|
|
double player_property(Player *plr, PlrProperty prop) {
|
|
|
|
return plr->mode->procs.property(plr, prop);
|
|
|
|
}
|
|
|
|
|
2018-04-13 21:13:48 +02:00
|
|
|
static void ent_draw_player(EntityInterface *ent);
|
2018-07-30 09:04:09 +02:00
|
|
|
static DamageResult ent_damage_player(EntityInterface *ent, const DamageInfo *dmg);
|
|
|
|
|
2018-06-01 20:40:18 +02:00
|
|
|
static void player_spawn_focus_circle(Player *plr);
|
2018-04-13 21:13:48 +02:00
|
|
|
|
2017-10-08 13:30:51 +02:00
|
|
|
void player_stage_post_init(Player *plr) {
|
|
|
|
assert(plr->mode != NULL);
|
|
|
|
|
|
|
|
// ensure the essential callbacks are there. other code tests only for the optional ones
|
|
|
|
assert(plr->mode->procs.shot != NULL);
|
|
|
|
assert(plr->mode->procs.bomb != NULL);
|
2018-05-02 08:08:32 +02:00
|
|
|
assert(plr->mode->procs.property != NULL);
|
2018-07-15 17:48:22 +02:00
|
|
|
assert(plr->mode->character != NULL);
|
|
|
|
assert(plr->mode->dialog != NULL);
|
2017-10-24 04:57:14 +02:00
|
|
|
|
|
|
|
delete_enemies(&global.plr.slaves);
|
|
|
|
|
|
|
|
if(plr->mode->procs.init != NULL) {
|
|
|
|
plr->mode->procs.init(plr);
|
|
|
|
}
|
|
|
|
|
2018-04-12 16:08:48 +02:00
|
|
|
aniplayer_create(&plr->ani, get_ani(plr->mode->character->player_sprite_name), "main");
|
2018-04-13 21:13:48 +02:00
|
|
|
|
|
|
|
plr->ent.draw_layer = LAYER_PLAYER;
|
|
|
|
plr->ent.draw_func = ent_draw_player;
|
2018-07-30 09:04:09 +02:00
|
|
|
plr->ent.damage_func = ent_damage_player;
|
2018-04-13 21:13:48 +02:00
|
|
|
ent_register(&plr->ent, ENT_PLAYER);
|
|
|
|
|
2018-06-01 20:40:18 +02:00
|
|
|
player_spawn_focus_circle(plr);
|
2019-02-22 00:56:03 +01:00
|
|
|
|
|
|
|
plr->extralife_threshold = player_next_extralife_threshold(plr->extralives_given);
|
|
|
|
|
|
|
|
while(plr->points >= plr->extralife_threshold) {
|
|
|
|
plr->extralife_threshold = player_next_extralife_threshold(++plr->extralives_given);
|
|
|
|
}
|
2017-02-15 17:09:09 +01:00
|
|
|
}
|
|
|
|
|
2017-11-25 16:51:43 +01:00
|
|
|
void player_free(Player *plr) {
|
|
|
|
if(plr->mode->procs.free) {
|
|
|
|
plr->mode->procs.free(plr);
|
|
|
|
}
|
2018-04-13 21:13:48 +02:00
|
|
|
|
2018-05-08 18:17:18 +02:00
|
|
|
aniplayer_free(&plr->ani);
|
2018-04-13 21:13:48 +02:00
|
|
|
ent_unregister(&plr->ent);
|
2018-06-01 20:40:18 +02:00
|
|
|
delete_enemy(&plr->focus_circle, plr->focus_circle.first);
|
2017-11-25 16:51:43 +01:00
|
|
|
}
|
|
|
|
|
2017-03-19 03:56:55 +01:00
|
|
|
static void player_full_power(Player *plr) {
|
|
|
|
play_sound("full_power");
|
2018-01-06 10:24:46 +01:00
|
|
|
stage_clear_hazards(CLEAR_HAZARDS_ALL);
|
2018-07-23 19:07:59 +02:00
|
|
|
stagetext_add("Full Power!", VIEWPORT_W * 0.5 + VIEWPORT_H * 0.33 * I, ALIGN_CENTER, get_font("big"), RGB(1, 1, 1), 0, 60, 20, 20);
|
2017-03-19 03:56:55 +01:00
|
|
|
}
|
|
|
|
|
2017-10-24 04:57:14 +02:00
|
|
|
bool player_set_power(Player *plr, short npow) {
|
2019-02-22 00:56:03 +01:00
|
|
|
int pow_base = clamp(npow, 0, PLR_MAX_POWER);
|
|
|
|
int pow_overflow = clamp(npow - PLR_MAX_POWER, 0, PLR_MAX_POWER_OVERFLOW);
|
2017-03-30 17:11:21 +02:00
|
|
|
|
2017-10-08 13:30:51 +02:00
|
|
|
if(plr->mode->procs.power) {
|
2019-02-22 00:56:03 +01:00
|
|
|
plr->mode->procs.power(plr, pow_base);
|
2011-07-04 09:14:08 +02:00
|
|
|
}
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2017-03-19 03:56:55 +01:00
|
|
|
int oldpow = plr->power;
|
2019-02-22 00:56:03 +01:00
|
|
|
int oldpow_over = plr->power_overflow;
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
plr->power = pow_base;
|
|
|
|
plr->power_overflow = pow_overflow;
|
|
|
|
|
|
|
|
if((oldpow + oldpow_over) / 100 < (pow_base + pow_overflow) / 100) {
|
2017-12-26 04:18:57 +01:00
|
|
|
play_sound("powerup");
|
|
|
|
}
|
|
|
|
|
2017-10-24 04:57:14 +02:00
|
|
|
if(plr->power == PLR_MAX_POWER && oldpow < PLR_MAX_POWER) {
|
2017-03-19 03:56:55 +01:00
|
|
|
player_full_power(plr);
|
|
|
|
}
|
2017-09-19 20:46:28 +02:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
return (oldpow + oldpow_over) != (plr->power + plr->power_overflow);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool player_add_power(Player *plr, short pdelta) {
|
|
|
|
return player_set_power(plr, plr->power + plr->power_overflow + pdelta);
|
2011-07-04 09:14:08 +02:00
|
|
|
}
|
|
|
|
|
2012-07-20 16:11:24 +02:00
|
|
|
void player_move(Player *plr, complex delta) {
|
2018-05-02 08:08:32 +02:00
|
|
|
delta *= player_property(plr, PLR_PROP_SPEED);
|
2017-10-06 12:19:17 +02:00
|
|
|
complex lastpos = plr->pos;
|
2017-11-11 22:44:54 +01:00
|
|
|
double x = clamp(creal(plr->pos) + creal(delta), PLR_MIN_BORDER_DIST, VIEWPORT_W - PLR_MIN_BORDER_DIST);
|
|
|
|
double y = clamp(cimag(plr->pos) + cimag(delta), PLR_MIN_BORDER_DIST, VIEWPORT_H - PLR_MIN_BORDER_DIST);
|
|
|
|
plr->pos = x + y*I;
|
2017-10-06 12:19:17 +02:00
|
|
|
complex realdir = plr->pos - lastpos;
|
|
|
|
|
|
|
|
if(cabs(realdir)) {
|
|
|
|
plr->lastmovedir = realdir / cabs(realdir);
|
|
|
|
}
|
2018-05-13 15:08:58 +02:00
|
|
|
|
|
|
|
plr->velocity = realdir;
|
2011-07-05 15:20:19 +02:00
|
|
|
}
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2018-04-13 21:13:48 +02:00
|
|
|
static void ent_draw_player(EntityInterface *ent) {
|
|
|
|
Player *plr = ENT_CAST(ent, Player);
|
|
|
|
|
2019-03-05 12:50:29 +01:00
|
|
|
if(plr->deathtime >= global.frames) {
|
2018-05-19 01:24:49 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-03-19 03:14:28 +01:00
|
|
|
|
2018-04-13 21:13:48 +02:00
|
|
|
if(plr->focus) {
|
|
|
|
r_draw_sprite(&(SpriteParams) {
|
|
|
|
.sprite = "fairy_circle",
|
|
|
|
.rotation.angle = DEG2RAD * global.frames * 10,
|
2018-07-23 19:07:59 +02:00
|
|
|
.color = RGBA_MUL_ALPHA(1, 1, 1, 0.2 * (clamp(plr->focus, 0, 15) / 15.0)),
|
2018-04-13 21:13:48 +02:00
|
|
|
.pos = { creal(plr->pos), cimag(plr->pos) },
|
|
|
|
});
|
|
|
|
}
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2018-04-13 21:13:48 +02:00
|
|
|
Color c;
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2019-01-04 23:59:39 +01:00
|
|
|
if(!player_is_vulnerable(plr)) {
|
|
|
|
float f = 0.3*sin(0.1*global.frames);
|
|
|
|
c = *RGBA_MUL_ALPHA(1.0+f, 1.0, 1.0-f, 0.7+f);
|
2018-04-13 21:13:48 +02:00
|
|
|
} else {
|
2018-07-23 19:07:59 +02:00
|
|
|
c = *RGBA_MUL_ALPHA(1.0, 1.0, 1.0, 1.0);
|
2018-04-13 21:13:48 +02:00
|
|
|
}
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2018-04-13 21:13:48 +02:00
|
|
|
r_draw_sprite(&(SpriteParams) {
|
|
|
|
.sprite_ptr = aniplayer_get_frame(&plr->ani),
|
|
|
|
.pos = { creal(plr->pos), cimag(plr->pos) },
|
2018-07-23 19:07:59 +02:00
|
|
|
.color = &c,
|
2018-04-13 21:13:48 +02:00
|
|
|
});
|
|
|
|
}
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2018-04-13 21:13:48 +02:00
|
|
|
static int player_focus_circle_logic(Enemy *e, int t) {
|
2018-05-08 09:06:33 +02:00
|
|
|
if(t < 0) {
|
|
|
|
return ACTION_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
double alpha = creal(e->args[0]);
|
|
|
|
|
|
|
|
if(t <= 1) {
|
|
|
|
alpha = min(0.1, alpha);
|
|
|
|
} else {
|
|
|
|
alpha = approach(alpha, (global.plr.inputflags & INFLAG_FOCUS) ? 1 : 0, 1/30.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
e->args[0] = alpha;
|
|
|
|
return ACTION_NONE;
|
2018-04-13 21:13:48 +02:00
|
|
|
}
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2018-04-13 21:13:48 +02:00
|
|
|
static void player_focus_circle_visual(Enemy *e, int t, bool render) {
|
2019-02-22 00:56:03 +01:00
|
|
|
if(!render) {
|
2018-04-13 21:13:48 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
float focus_opacity = creal(e->args[0]);
|
2018-05-08 09:06:33 +02:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
if(focus_opacity > 0) {
|
|
|
|
int trans_frames = 12;
|
|
|
|
double trans_factor = 1 - min(trans_frames, t) / (double)trans_frames;
|
|
|
|
double rot_speed = DEG2RAD * global.frames * (1 + 3 * trans_factor);
|
|
|
|
double scale = 1.0 + trans_factor;
|
2018-04-13 21:13:48 +02:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
r_draw_sprite(&(SpriteParams) {
|
|
|
|
.sprite = "focus",
|
|
|
|
.rotation.angle = rot_speed,
|
|
|
|
.color = RGBA_MUL_ALPHA(1, 1, 1, creal(e->args[0])),
|
|
|
|
.pos = { creal(e->pos), cimag(e->pos) },
|
|
|
|
.scale.both = scale,
|
|
|
|
});
|
|
|
|
|
|
|
|
r_draw_sprite(&(SpriteParams) {
|
|
|
|
.sprite = "focus",
|
|
|
|
.rotation.angle = rot_speed * -1,
|
|
|
|
.color = RGBA_MUL_ALPHA(1, 1, 1, creal(e->args[0])),
|
|
|
|
.pos = { creal(e->pos), cimag(e->pos) },
|
|
|
|
.scale.both = scale,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
float ps_opacity = 1.0;
|
|
|
|
float ps_fill_factor = 1.0;
|
|
|
|
|
|
|
|
if(player_is_powersurge_active(&global.plr)) {
|
|
|
|
ps_opacity *= clamp((global.frames - global.plr.powersurge.time.activated) / 30.0, 0, 1);
|
|
|
|
} else if(global.plr.powersurge.time.expired == 0) {
|
|
|
|
ps_opacity = 0;
|
|
|
|
} else {
|
|
|
|
ps_opacity *= (1 - clamp((global.frames - global.plr.powersurge.time.expired) / 40.0, 0, 1));
|
|
|
|
ps_fill_factor = pow(ps_opacity, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ps_opacity > 0) {
|
|
|
|
r_state_push();
|
|
|
|
r_mat_push();
|
|
|
|
r_mat_translate(creal(e->pos), cimag(e->pos), 0);
|
|
|
|
r_mat_scale(140, 140, 0);
|
|
|
|
r_shader("healthbar_radial");
|
|
|
|
r_uniform_vec4_rgba("borderColor", RGBA(0.5, 0.5, 0.5, 0.5));
|
|
|
|
r_uniform_vec4_rgba("glowColor", RGBA(0.5, 0.5, 0.5, 0.75));
|
|
|
|
r_uniform_vec4_rgba("fillColor", RGBA(1.5, 0.5, 0.0, 0.75));
|
|
|
|
r_uniform_vec4_rgba("altFillColor", RGBA(0.0, 0.5, 1.5, 0.75));
|
|
|
|
r_uniform_vec4_rgba("coreFillColor", RGBA(0.8, 0.8, 0.8, 0.25));
|
|
|
|
r_uniform_vec2("fill", global.plr.powersurge.positive * ps_fill_factor, global.plr.powersurge.negative * ps_fill_factor);
|
|
|
|
r_uniform_float("opacity", ps_opacity);
|
|
|
|
r_draw_quad();
|
|
|
|
r_mat_pop();
|
|
|
|
r_state_pop();
|
|
|
|
|
|
|
|
char buf[64];
|
|
|
|
format_huge_num(0, global.plr.powersurge.bonus.baseline, sizeof(buf), buf);
|
|
|
|
Font *fnt = get_font("monotiny");
|
|
|
|
|
|
|
|
float x = creal(e->pos);
|
|
|
|
float y = cimag(e->pos) + 80;
|
|
|
|
|
|
|
|
float text_opacity = ps_opacity * 0.75;
|
|
|
|
|
|
|
|
x += text_draw(buf, &(TextParams) {
|
|
|
|
.shader = "text_hud",
|
|
|
|
.font_ptr = fnt,
|
|
|
|
.pos = { x, y },
|
|
|
|
.color = RGBA_MUL_ALPHA(1.0, 1.0, 1.0, text_opacity),
|
|
|
|
.align = ALIGN_CENTER,
|
|
|
|
});
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), " +%u", global.plr.powersurge.bonus.gain_rate);
|
|
|
|
|
|
|
|
text_draw(buf, &(TextParams) {
|
|
|
|
.shader = "text_hud",
|
|
|
|
.font_ptr = fnt,
|
|
|
|
.pos = { x, y },
|
|
|
|
.color = RGBA_MUL_ALPHA(0.3, 0.6, 1.0, text_opacity),
|
|
|
|
.align = ALIGN_LEFT,
|
|
|
|
});
|
|
|
|
|
|
|
|
r_shader("sprite_filled_circle");
|
|
|
|
r_uniform_vec4("color_inner", 0, 0, 0, 0);
|
|
|
|
r_uniform_vec4("color_outer", 0, 0, 0.1 * ps_opacity, 0.1 * ps_opacity);
|
|
|
|
}
|
2018-04-13 21:13:48 +02:00
|
|
|
}
|
|
|
|
|
2018-06-01 20:40:18 +02:00
|
|
|
static void player_spawn_focus_circle(Player *plr) {
|
|
|
|
Enemy *f = create_enemy_p(&plr->focus_circle, 0, ENEMY_IMMUNE, player_focus_circle_visual, player_focus_circle_logic, 0, 0, 0, 0);
|
2018-04-13 21:13:48 +02:00
|
|
|
f->ent.draw_layer = LAYER_PLAYER_FOCUS;
|
2010-10-12 10:55:23 +02:00
|
|
|
}
|
|
|
|
|
2017-04-04 02:57:38 +02:00
|
|
|
static void player_fail_spell(Player *plr) {
|
2018-01-12 19:26:07 +01:00
|
|
|
if( !global.boss ||
|
2017-04-04 02:57:38 +02:00
|
|
|
!global.boss->current ||
|
|
|
|
global.boss->current->finished ||
|
|
|
|
global.boss->current->failtime ||
|
2017-10-01 00:41:32 +02:00
|
|
|
global.boss->current->starttime >= global.frames ||
|
2017-04-04 02:57:38 +02:00
|
|
|
global.stage->type == STAGE_SPELL
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
global.boss->current->failtime = global.frames;
|
|
|
|
|
|
|
|
if(global.boss->current->type == AT_ExtraSpell) {
|
|
|
|
boss_finish_current_attack(global.boss);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-08 13:30:51 +02:00
|
|
|
bool player_should_shoot(Player *plr, bool extra) {
|
2018-07-31 09:07:34 +02:00
|
|
|
return
|
|
|
|
(plr->inputflags & INFLAG_SHOT) &&
|
2019-02-22 00:56:03 +01:00
|
|
|
!global.dialog
|
|
|
|
&& player_is_alive(&global.plr)
|
|
|
|
/* && (!extra || !player_is_bomb_active(plr)) */;
|
2017-10-08 13:30:51 +02:00
|
|
|
}
|
|
|
|
|
2018-07-30 15:14:27 +02:00
|
|
|
void player_placeholder_bomb_logic(Player *plr) {
|
2018-07-31 09:07:34 +02:00
|
|
|
if(!player_is_bomb_active(plr)) {
|
2018-07-30 15:14:27 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DamageInfo dmg;
|
|
|
|
dmg.amount = 100;
|
|
|
|
dmg.type = DMG_PLAYER_BOMB;
|
|
|
|
|
|
|
|
for(Enemy *en = global.enemies.first; en; en = en->next) {
|
|
|
|
ent_damage(&en->ent, &dmg);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(global.boss) {
|
|
|
|
ent_damage(&global.boss->ent, &dmg);
|
|
|
|
}
|
|
|
|
|
|
|
|
stage_clear_hazards(CLEAR_HAZARDS_ALL);
|
|
|
|
}
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
static void player_powersurge_expired(Player *plr);
|
|
|
|
|
|
|
|
static void _powersurge_trail_draw(Projectile *p, float t, float cmul) {
|
|
|
|
float nt = t / p->timeout;
|
|
|
|
float s = 1 + (2 + 0.5 * psin((t+global.frames*1.23)/5.0)) * nt * nt;
|
|
|
|
|
|
|
|
r_draw_sprite(&(SpriteParams) {
|
|
|
|
.sprite_ptr = p->sprite,
|
|
|
|
.scale.both = s,
|
|
|
|
.pos = { creal(p->pos), cimag(p->pos) },
|
|
|
|
.color = color_mul_scalar(RGBA(0.8, 0.1 + 0.2 * psin((t+global.frames)/5.0), 0.1, 0.0), 0.5 * (1 - nt) * cmul),
|
|
|
|
.shader_params = &(ShaderCustomParams){{ -2 * nt * nt }},
|
|
|
|
.shader = "sprite_silhouette",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
static void powersurge_trail_draw(Projectile *p, int t) {
|
|
|
|
if(t > 0) {
|
|
|
|
_powersurge_trail_draw(p, t - 0.5, 0.25);
|
|
|
|
_powersurge_trail_draw(p, t, 0.25);
|
|
|
|
} else {
|
|
|
|
_powersurge_trail_draw(p, t, 0.5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int powersurge_trail(Projectile *p, int t) {
|
|
|
|
if(t == EVENT_BIRTH) {
|
|
|
|
return ACTION_ACK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(t == EVENT_DEATH) {
|
|
|
|
free(p->sprite);
|
|
|
|
return ACTION_ACK;
|
|
|
|
}
|
|
|
|
|
|
|
|
complex v = (global.plr.pos - p->pos) * 0.05;
|
|
|
|
p->args[0] += (v - p->args[0]) * (1 - t / p->timeout);
|
|
|
|
p->pos += p->args[0];
|
|
|
|
|
|
|
|
return ACTION_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void player_powersurge_calc_bonus(Player *plr, PowerSurgeBonus *b) {
|
|
|
|
b->gain_rate = round(1000 * plr->powersurge.negative * plr->powersurge.negative);
|
2019-03-28 16:56:06 +01:00
|
|
|
b->baseline = plr->powersurge.power + plr->powersurge.damage_done * 0.4;
|
2019-02-22 00:56:03 +01:00
|
|
|
b->score = b->baseline;
|
|
|
|
b->discharge_power = sqrtf(0.2 * b->baseline + 1024 * log1pf(b->baseline)) * smoothstep(0, 1, 0.0001 * b->baseline);
|
|
|
|
b->discharge_range = 1.2 * b->discharge_power;
|
|
|
|
b->discharge_damage = 10 * pow(b->discharge_power, 1.1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int powersurge_charge_particle(Projectile *p, int t) {
|
|
|
|
if(t == EVENT_BIRTH) {
|
|
|
|
return ACTION_ACK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(t == EVENT_DEATH) {
|
|
|
|
return ACTION_ACK;
|
|
|
|
}
|
|
|
|
|
|
|
|
Player *plr = &global.plr;
|
|
|
|
|
|
|
|
if(player_is_alive(plr)) {
|
|
|
|
p->pos = plr->pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ACTION_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void player_powersurge_logic(Player *plr) {
|
2019-02-28 11:00:35 +01:00
|
|
|
if(global.dialog) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
plr->powersurge.positive = max(0, plr->powersurge.positive - lerp(PLR_POWERSURGE_POSITIVE_DRAIN_MIN, PLR_POWERSURGE_POSITIVE_DRAIN_MAX, plr->powersurge.positive));
|
|
|
|
plr->powersurge.negative = max(0, plr->powersurge.negative - lerp(PLR_POWERSURGE_NEGATIVE_DRAIN_MIN, PLR_POWERSURGE_NEGATIVE_DRAIN_MAX, plr->powersurge.negative));
|
|
|
|
|
|
|
|
if(stage_is_cleared()) {
|
|
|
|
player_cancel_powersurge(plr);
|
2019-02-28 11:00:35 +01:00
|
|
|
return;
|
2019-02-22 00:56:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(plr->powersurge.positive <= plr->powersurge.negative) {
|
|
|
|
player_powersurge_expired(plr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
player_powersurge_calc_bonus(plr, &plr->powersurge.bonus);
|
|
|
|
|
|
|
|
PARTICLE(
|
|
|
|
.sprite_ptr = memdup(aniplayer_get_frame(&plr->ani), sizeof(Sprite)),
|
|
|
|
.pos = plr->pos,
|
|
|
|
.color = RGBA(1, 1, 1, 0.5),
|
|
|
|
.rule = powersurge_trail,
|
|
|
|
.draw_rule = powersurge_trail_draw,
|
|
|
|
.timeout = 15,
|
|
|
|
.layer = LAYER_PARTICLE_HIGH,
|
|
|
|
.flags = PFLAG_NOREFLECT,
|
|
|
|
);
|
|
|
|
|
|
|
|
if(!(global.frames % 6)) {
|
|
|
|
Sprite *spr = get_sprite("part/powersurge_field");
|
|
|
|
double scale = 2 * plr->powersurge.bonus.discharge_range / spr->w;
|
|
|
|
double angle = frand() * 2 * M_PI;
|
|
|
|
|
|
|
|
PARTICLE(
|
|
|
|
.sprite_ptr = spr,
|
|
|
|
.pos = plr->pos,
|
|
|
|
.color = color_mul_scalar(frand() < 0.5 ? RGBA(1.5, 0.5, 0.0, 0.1) : RGBA(0.0, 0.5, 1.5, 0.1), 0.25),
|
|
|
|
.rule = powersurge_charge_particle,
|
|
|
|
.draw_rule = ScaleFade,
|
|
|
|
.timeout = 14,
|
|
|
|
.angle = angle,
|
|
|
|
.args = { 0, 0, (1+I)*scale, 0},
|
|
|
|
.layer = LAYER_PLAYER - 1,
|
|
|
|
.flags = PFLAG_NOREFLECT,
|
|
|
|
);
|
|
|
|
|
|
|
|
PARTICLE(
|
|
|
|
.sprite_ptr = spr,
|
|
|
|
.pos = plr->pos,
|
|
|
|
.color = RGBA(0.5, 0.5, 0.5, 0),
|
|
|
|
.rule = powersurge_charge_particle,
|
|
|
|
.draw_rule = ScaleFade,
|
|
|
|
.timeout = 3,
|
|
|
|
.angle = angle,
|
|
|
|
.args = { 0, 0, (1+I)*scale, 0},
|
|
|
|
.layer = LAYER_PLAYER - 1,
|
|
|
|
.flags = PFLAG_NOREFLECT,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
plr->powersurge.power += plr->powersurge.bonus.gain_rate;
|
|
|
|
}
|
|
|
|
|
2011-06-24 19:16:05 +02:00
|
|
|
void player_logic(Player* plr) {
|
2017-10-29 23:45:24 +01:00
|
|
|
if(plr->continuetime == global.frames) {
|
|
|
|
plr->lives = PLR_START_LIVES;
|
|
|
|
plr->bombs = PLR_START_BOMBS;
|
2019-02-22 00:56:03 +01:00
|
|
|
plr->point_item_value = PLR_START_PIV;
|
2017-10-29 23:45:24 +01:00
|
|
|
plr->life_fragments = 0;
|
|
|
|
plr->bomb_fragments = 0;
|
|
|
|
plr->continues_used += 1;
|
2017-10-31 07:58:49 +01:00
|
|
|
player_set_power(plr, 0);
|
2018-01-06 10:24:46 +01:00
|
|
|
stage_clear_hazards(CLEAR_HAZARDS_ALL);
|
2019-03-03 12:53:45 +01:00
|
|
|
spawn_items(plr->deathpos, ITEM_POWER, (int)ceil(PLR_MAX_POWER/(double)POWER_VALUE));
|
2017-10-29 23:45:24 +01:00
|
|
|
}
|
|
|
|
|
2011-07-05 15:20:19 +02:00
|
|
|
process_enemies(&plr->slaves);
|
2017-10-03 17:25:38 +02:00
|
|
|
aniplayer_update(&plr->ani);
|
2018-04-13 21:13:48 +02:00
|
|
|
|
2019-03-05 12:50:29 +01:00
|
|
|
if(plr->respawntime > global.frames) {
|
|
|
|
double x = PLR_SPAWN_POS_X;
|
|
|
|
double y = lerp(PLR_SPAWN_POS_Y, VIEWPORT_H + 64, smoothstep(0.0, 1.0, (plr->respawntime - global.frames) / (double)PLR_RESPAWN_TIME));
|
|
|
|
plr->pos = CMPLX(x, y);
|
2018-01-06 10:24:46 +01:00
|
|
|
stage_clear_hazards(CLEAR_HAZARDS_ALL | CLEAR_HAZARDS_NOW);
|
2011-07-04 14:10:12 +02:00
|
|
|
return;
|
|
|
|
}
|
2012-08-11 14:24:58 +02:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
if(player_is_powersurge_active(plr)) {
|
|
|
|
player_powersurge_logic(plr);
|
|
|
|
}
|
|
|
|
|
2017-03-06 15:24:57 +01:00
|
|
|
plr->focus = approach(plr->focus, (plr->inputflags & INFLAG_FOCUS) ? 30 : 0, 1);
|
2018-06-01 20:40:18 +02:00
|
|
|
plr->focus_circle.first->pos = plr->pos;
|
2018-05-08 09:06:33 +02:00
|
|
|
process_enemies(&plr->focus_circle);
|
2018-04-13 21:13:48 +02:00
|
|
|
|
2017-10-08 13:30:51 +02:00
|
|
|
if(plr->mode->procs.think) {
|
|
|
|
plr->mode->procs.think(plr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(player_should_shoot(plr, false)) {
|
|
|
|
plr->mode->procs.shot(plr);
|
2012-08-03 17:06:25 +02:00
|
|
|
}
|
|
|
|
|
2017-10-31 14:47:20 +01:00
|
|
|
if(global.frames == plr->deathtime) {
|
2012-07-20 16:11:24 +02:00
|
|
|
player_realdeath(plr);
|
2017-10-31 14:47:20 +01:00
|
|
|
} else if(plr->deathtime > global.frames) {
|
2018-01-06 10:24:46 +01:00
|
|
|
stage_clear_hazards(CLEAR_HAZARDS_ALL | CLEAR_HAZARDS_NOW);
|
2017-10-31 14:47:20 +01:00
|
|
|
}
|
2012-08-11 14:24:58 +02:00
|
|
|
|
2018-07-31 09:07:34 +02:00
|
|
|
if(player_is_bomb_active(plr)) {
|
2017-10-17 22:27:35 +02:00
|
|
|
if(plr->bombcanceltime) {
|
|
|
|
int bctime = plr->bombcanceltime + plr->bombcanceldelay;
|
|
|
|
|
|
|
|
if(bctime <= global.frames) {
|
|
|
|
plr->recovery = global.frames;
|
|
|
|
plr->bombcanceltime = 0;
|
|
|
|
plr->bombcanceldelay = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-04 02:57:38 +02:00
|
|
|
player_fail_spell(plr);
|
2011-11-01 21:20:40 +01:00
|
|
|
}
|
2011-06-24 19:16:05 +02:00
|
|
|
}
|
|
|
|
|
2019-01-24 21:21:08 +01:00
|
|
|
static bool player_bomb(Player *plr) {
|
2012-08-16 15:07:14 +02:00
|
|
|
if(global.boss && global.boss->current && global.boss->current->type == AT_ExtraSpell)
|
2017-09-19 20:46:28 +02:00
|
|
|
return false;
|
2012-08-16 15:07:14 +02:00
|
|
|
|
2018-05-02 08:08:32 +02:00
|
|
|
int bomb_time = floor(player_property(plr, PLR_PROP_BOMB_TIME));
|
|
|
|
|
|
|
|
if(bomb_time <= 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-03-05 12:50:29 +01:00
|
|
|
if(!player_is_bomb_active(plr) && (plr->bombs > 0 || plr->iddqd) && global.frames >= plr->respawntime) {
|
2017-04-04 02:57:38 +02:00
|
|
|
player_fail_spell(plr);
|
2019-02-22 00:56:03 +01:00
|
|
|
// player_cancel_powersurge(plr);
|
2019-03-26 16:58:38 +01:00
|
|
|
// stage_clear_hazards(CLEAR_HAZARDS_ALL);
|
2019-02-22 00:56:03 +01:00
|
|
|
|
2017-10-08 13:30:51 +02:00
|
|
|
plr->mode->procs.bomb(plr);
|
2011-06-26 13:45:27 +02:00
|
|
|
plr->bombs--;
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2019-03-05 12:50:29 +01:00
|
|
|
if(plr->deathtime >= global.frames) {
|
|
|
|
// death bomb - unkill the player!
|
2011-06-25 12:41:40 +02:00
|
|
|
plr->deathtime = -1;
|
2017-03-19 03:05:06 +01:00
|
|
|
|
2018-05-02 08:08:32 +02:00
|
|
|
if(plr->bombs) {
|
2017-03-19 03:05:06 +01:00
|
|
|
plr->bombs--;
|
2018-05-02 08:08:32 +02:00
|
|
|
}
|
2017-02-10 23:05:22 +01:00
|
|
|
}
|
|
|
|
|
2017-02-11 02:24:47 +01:00
|
|
|
if(plr->bombs < 0) {
|
|
|
|
plr->bombs = 0;
|
|
|
|
}
|
|
|
|
|
2018-05-02 08:08:32 +02:00
|
|
|
plr->bombtotaltime = bomb_time;
|
|
|
|
plr->recovery = global.frames + plr->bombtotaltime;
|
2017-10-17 22:27:35 +02:00
|
|
|
plr->bombcanceltime = 0;
|
|
|
|
plr->bombcanceldelay = 0;
|
2017-09-19 20:46:28 +02:00
|
|
|
|
2019-03-05 12:50:29 +01:00
|
|
|
assert(player_is_alive(plr));
|
2019-02-22 00:56:03 +01:00
|
|
|
collect_all_items(1);
|
2017-09-19 20:46:28 +02:00
|
|
|
return true;
|
2011-03-23 12:26:30 +01:00
|
|
|
}
|
2017-09-19 20:46:28 +02:00
|
|
|
|
|
|
|
return false;
|
2011-03-23 12:26:30 +01:00
|
|
|
}
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
static bool player_powersurge(Player *plr) {
|
|
|
|
if(
|
|
|
|
!player_is_alive(plr) ||
|
|
|
|
player_is_bomb_active(plr) ||
|
|
|
|
player_is_powersurge_active(plr) ||
|
|
|
|
plr->power + plr->power_overflow < PLR_POWERSURGE_POWERCOST
|
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
plr->powersurge.positive = 1.0;
|
|
|
|
plr->powersurge.negative = 0.0;
|
|
|
|
plr->powersurge.time.activated = global.frames;
|
|
|
|
plr->powersurge.power = 0;
|
|
|
|
plr->powersurge.damage_accum = 0;
|
|
|
|
player_add_power(plr, -PLR_POWERSURGE_POWERCOST);
|
|
|
|
|
|
|
|
collect_all_items(1);
|
|
|
|
stagetext_add("Power Surge!", plr->pos - 64 * I, ALIGN_CENTER, get_font("standard"), RGBA(0.75, 0.75, 0.75, 0.75), 0, 45, 10, 20);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool player_is_powersurge_active(Player *plr) {
|
|
|
|
return plr->powersurge.positive > plr->powersurge.negative;
|
|
|
|
}
|
|
|
|
|
2018-07-31 09:07:34 +02:00
|
|
|
bool player_is_bomb_active(Player *plr) {
|
|
|
|
return global.frames - plr->recovery < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool player_is_vulnerable(Player *plr) {
|
|
|
|
return global.frames - abs(plr->recovery) >= 0 && !plr->iddqd && player_is_alive(plr);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool player_is_alive(Player *plr) {
|
2019-03-05 12:50:29 +01:00
|
|
|
return plr->deathtime < global.frames && global.frames >= plr->respawntime;
|
2018-07-31 09:07:34 +02:00
|
|
|
}
|
|
|
|
|
2017-10-17 22:27:35 +02:00
|
|
|
void player_cancel_bomb(Player *plr, int delay) {
|
2018-07-31 09:07:34 +02:00
|
|
|
if(!player_is_bomb_active(plr)) {
|
2017-10-17 22:27:35 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(plr->bombcanceltime) {
|
|
|
|
int canceltime_queued = plr->bombcanceltime + plr->bombcanceldelay;
|
|
|
|
int canceltime_requested = global.frames + delay;
|
|
|
|
|
|
|
|
if(canceltime_queued > canceltime_requested) {
|
|
|
|
plr->bombcanceldelay -= (canceltime_queued - canceltime_requested);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
plr->bombcanceltime = global.frames;
|
|
|
|
plr->bombcanceldelay = delay;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
static void player_powersurge_expired(Player *plr) {
|
|
|
|
plr->powersurge.time.expired = global.frames;
|
|
|
|
|
|
|
|
PowerSurgeBonus bonus;
|
|
|
|
player_powersurge_calc_bonus(plr, &bonus);
|
|
|
|
|
|
|
|
Sprite *blast = get_sprite("part/blast_huge_halo");
|
|
|
|
float scale = 2 * bonus.discharge_range / blast->w;
|
|
|
|
|
|
|
|
PARTICLE(
|
|
|
|
.sprite_ptr = blast,
|
|
|
|
.pos = plr->pos,
|
|
|
|
.color = RGBA(0.6, 1.0, 4.4, 0.0),
|
|
|
|
.draw_rule = ScaleFade,
|
|
|
|
.timeout = 20,
|
|
|
|
.args = { 0, 0, scale * (2 + 0 * I) },
|
|
|
|
.angle = M_PI*2*frand(),
|
|
|
|
);
|
|
|
|
|
|
|
|
player_add_points(&global.plr, bonus.score);
|
|
|
|
ent_area_damage(plr->pos, bonus.discharge_range, &(DamageInfo) { bonus.discharge_damage, DMG_PLAYER_DISCHARGE }, NULL, NULL);
|
|
|
|
stage_clear_hazards_at(plr->pos, bonus.discharge_range, CLEAR_HAZARDS_ALL | CLEAR_HAZARDS_NOW | CLEAR_HAZARDS_SPAWN_VOLTAGE);
|
|
|
|
|
|
|
|
log_debug(
|
|
|
|
"Power Surge expired at %i (duration: %i); baseline = %u; score = %u; discharge = %g, dmg = %g, range = %g",
|
|
|
|
plr->powersurge.time.expired,
|
|
|
|
plr->powersurge.time.expired - plr->powersurge.time.activated,
|
|
|
|
bonus.baseline,
|
|
|
|
bonus.score,
|
|
|
|
bonus.discharge_power,
|
|
|
|
bonus.discharge_damage,
|
|
|
|
bonus.discharge_range
|
|
|
|
);
|
|
|
|
|
|
|
|
plr->powersurge.damage_done = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void player_cancel_powersurge(Player *plr) {
|
|
|
|
if(player_is_powersurge_active(plr)) {
|
|
|
|
plr->powersurge.positive = plr->powersurge.negative;
|
|
|
|
player_powersurge_expired(plr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void player_extend_powersurge(Player *plr, float pos, float neg) {
|
|
|
|
if(player_is_powersurge_active(plr)) {
|
|
|
|
plr->powersurge.positive = clamp(plr->powersurge.positive + pos, 0, 1);
|
|
|
|
plr->powersurge.negative = clamp(plr->powersurge.negative + neg, 0, 1);
|
|
|
|
|
|
|
|
if(plr->powersurge.positive <= plr->powersurge.negative) {
|
|
|
|
player_powersurge_expired(plr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-26 14:06:35 +01:00
|
|
|
double player_get_bomb_progress(Player *plr, double *out_speed) {
|
2018-07-31 09:07:34 +02:00
|
|
|
if(!player_is_bomb_active(plr)) {
|
2017-10-17 22:27:35 +02:00
|
|
|
if(out_speed != NULL) {
|
|
|
|
*out_speed = 1.0;
|
|
|
|
}
|
|
|
|
|
2017-11-26 14:06:35 +01:00
|
|
|
return 1;
|
2017-10-17 22:27:35 +02:00
|
|
|
}
|
|
|
|
|
2018-05-02 08:08:32 +02:00
|
|
|
int start_time = plr->recovery - plr->bombtotaltime;
|
2017-10-17 22:27:35 +02:00
|
|
|
int end_time = plr->recovery;
|
|
|
|
|
|
|
|
if(!plr->bombcanceltime || plr->bombcanceltime + plr->bombcanceldelay >= end_time) {
|
|
|
|
if(out_speed != NULL) {
|
|
|
|
*out_speed = 1.0;
|
|
|
|
}
|
|
|
|
|
2018-05-02 08:08:32 +02:00
|
|
|
return (plr->bombtotaltime - (end_time - global.frames))/(double)plr->bombtotaltime;
|
2017-10-17 22:27:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int cancel_time = plr->bombcanceltime + plr->bombcanceldelay;
|
|
|
|
int passed_time = plr->bombcanceltime - start_time;
|
|
|
|
|
2018-05-02 08:08:32 +02:00
|
|
|
int shortened_total_time = (plr->bombtotaltime - passed_time) - (end_time - cancel_time);
|
2017-10-17 22:27:35 +02:00
|
|
|
int shortened_passed_time = (global.frames - plr->bombcanceltime);
|
|
|
|
|
2018-05-02 08:08:32 +02:00
|
|
|
double passed_fraction = passed_time / (double)plr->bombtotaltime;
|
2017-10-17 22:27:35 +02:00
|
|
|
double shortened_fraction = shortened_passed_time / (double)shortened_total_time;
|
|
|
|
shortened_fraction *= (1 - passed_fraction);
|
|
|
|
|
|
|
|
if(out_speed != NULL) {
|
2018-05-02 08:08:32 +02:00
|
|
|
*out_speed = (plr->bombtotaltime - passed_time) / (double)shortened_total_time;
|
2017-10-17 22:27:35 +02:00
|
|
|
}
|
|
|
|
|
2017-11-26 14:06:35 +01:00
|
|
|
return passed_fraction + shortened_fraction;
|
2017-10-17 22:27:35 +02:00
|
|
|
}
|
|
|
|
|
2012-07-20 16:11:24 +02:00
|
|
|
void player_realdeath(Player *plr) {
|
2019-03-05 12:50:29 +01:00
|
|
|
plr->respawntime = global.frames + PLR_RESPAWN_TIME;
|
2017-03-06 15:24:57 +01:00
|
|
|
plr->inputflags &= ~INFLAGS_MOVE;
|
2017-10-29 23:45:24 +01:00
|
|
|
plr->deathpos = plr->pos;
|
2017-02-23 11:39:31 +01:00
|
|
|
plr->pos = VIEWPORT_W/2 + VIEWPORT_H*I+30.0*I;
|
2019-03-05 12:50:29 +01:00
|
|
|
plr->recovery = -(plr->respawntime + 150);
|
2018-01-06 10:24:46 +01:00
|
|
|
stage_clear_hazards(CLEAR_HAZARDS_ALL);
|
2017-04-04 02:57:38 +02:00
|
|
|
player_fail_spell(plr);
|
2017-09-13 15:41:28 +02:00
|
|
|
|
|
|
|
if(global.stage->type != STAGE_SPELL && global.boss && global.boss->current && global.boss->current->type == AT_ExtraSpell) {
|
|
|
|
// deaths in extra spells "don't count"
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
int total_power = plr->power + plr->power_overflow;
|
|
|
|
|
|
|
|
int drop = max(2, (total_power * 0.15) / POWER_VALUE);
|
2019-03-03 12:53:45 +01:00
|
|
|
spawn_items(plr->deathpos, ITEM_POWER, drop);
|
2017-09-13 15:41:28 +02:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
player_set_power(plr, total_power * 0.7);
|
2017-09-13 15:41:28 +02:00
|
|
|
plr->bombs = PLR_START_BOMBS;
|
|
|
|
plr->bomb_fragments = 0;
|
2019-02-22 00:56:03 +01:00
|
|
|
plr->voltage *= 0.9;
|
2017-02-12 01:11:25 +01:00
|
|
|
|
2017-09-13 15:41:28 +02:00
|
|
|
if(plr->lives-- == 0 && global.replaymode != REPLAY_PLAY) {
|
2012-08-17 20:58:23 +02:00
|
|
|
stage_gameover();
|
2017-09-13 15:41:28 +02:00
|
|
|
}
|
2011-06-25 12:41:40 +02:00
|
|
|
}
|
|
|
|
|
2018-05-19 01:24:49 +02:00
|
|
|
static void player_death_effect_draw_overlay(Projectile *p, int t) {
|
2018-07-04 10:36:16 +02:00
|
|
|
FBPair *framebuffers = stage_get_fbpair(FBPAIR_FG);
|
|
|
|
r_framebuffer(framebuffers->front);
|
OpenGL ES 3.0 rendering backend (#148)
* First steps towards shader transpilation
Needs to be manually enabled via -Dshader_transpiler=true.
Requires shaderc. https://github.com/google/shaderc
Not yet functional due to missing SPIRV-Cross integration. SPIRV-Cross
currently does not have an official C API, and crossc is too minimal to
be useful. The current plan is to extend crossc and vendor it, while
also sending PRs upstream.
* Integrate crossc; shader transpilation for GLES now works
* fix leak
* gles30 backend now playable on Mesa with 3.2 context
Some rendering issues are present. Identified so far:
- Marisa's lasers are invisible
- Death effect looks wrong
Also, a small pixmap manipulation library has been written, and the
texture uploading API redesigned around it.
* fix marisa lasers in GLES (uniform name clashed with builtin)
* fix player death effect in GLES (another name clash)
* Dump ANGLE's translated shader code in debug log
* fix screenshots
* Drop support for triangle fans, switch to strips
Fans offer no advantage over strips, and they've been removed in D3D10+,
so ANGLE has to emulate them.
* crude workaround for an ANGLE bug
* Re-enable GL debug labels, fix an issue with them that affected ANGLE (but was always technically a bug)
* fix race condition in shaderc initialization
* New SDL_RWops interface for vertex buffers
* Optimize VBO streaming via buffering updates
Measurable performance improvement even with the main gl33 renderer,
drastic improvement with ANGLE.
* Fix the depth texture binding problem under ANGLE
Apparently it hates GL_DEPTH_COMPONENT16 for some reason. Sized internal
formats are not supported in GLES 2.0 anyway, so not using them is
probably a good idea.
* fix GLES2.0 segfault (the backend still doesn't work, though)
* dump GL extensions at info log level, not debug
* get around a Mesa bug; more correct texture format table for GLES2
* Correct GLES3 texture format table according to the spec
Not a Mesa bug after all
* require crossc>=1.5.0, fallback to subproject
* Request at least 8bit per color channel in GL backends
* Forbid lto for static windows builds with shader_transpiler=true
* fix edge case segfault
* Add basic ANGLE bundling support to the build system
Windows only, and no NSIS support yet
* Fix various windows-related build system and installer brokenness
* Disable gles backends by default
* update documentation
2018-10-02 00:36:10 +02:00
|
|
|
r_uniform_sampler("noise_tex", "static");
|
2018-05-18 20:15:11 +02:00
|
|
|
r_uniform_int("frames", global.frames);
|
|
|
|
r_uniform_float("progress", t / p->timeout);
|
|
|
|
r_uniform_vec2("origin", creal(p->pos), VIEWPORT_H - cimag(p->pos));
|
|
|
|
r_uniform_vec2("clear_origin", creal(global.plr.pos), VIEWPORT_H - cimag(global.plr.pos));
|
|
|
|
r_uniform_vec2("viewport", VIEWPORT_W, VIEWPORT_H);
|
2018-07-04 10:36:16 +02:00
|
|
|
draw_framebuffer_tex(framebuffers->back, VIEWPORT_W, VIEWPORT_H);
|
|
|
|
fbpair_swap(framebuffers);
|
2018-05-19 01:24:49 +02:00
|
|
|
|
|
|
|
// This change must propagate, hence the r_state salsa. Yes, pop then push, I know what I'm doing.
|
|
|
|
r_state_pop();
|
2018-07-04 10:36:16 +02:00
|
|
|
r_framebuffer(framebuffers->back);
|
2018-05-19 01:24:49 +02:00
|
|
|
r_state_push();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void player_death_effect_draw_sprite(Projectile *p, int t) {
|
|
|
|
float s = t / p->timeout;
|
|
|
|
|
|
|
|
float stretch_range = 3, sx, sy;
|
|
|
|
|
|
|
|
sx = 0.5 + 0.5 * cos(M_PI * (2 * pow(s, 0.5) + 1));
|
|
|
|
sx = (1 - s) * (1 + (stretch_range - 1) * sx) + s * stretch_range * sx;
|
|
|
|
sy = 1 + pow(s, 3);
|
|
|
|
|
|
|
|
if(sx <= 0 || sy <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
r_draw_sprite(&(SpriteParams) {
|
|
|
|
.sprite_ptr = p->sprite,
|
|
|
|
.pos = { creal(p->pos), cimag(p->pos) },
|
|
|
|
.scale = { .x = sx, .y = sy },
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
static int player_death_effect(Projectile *p, int t) {
|
|
|
|
if(t < 0) {
|
|
|
|
if(t == EVENT_DEATH) {
|
|
|
|
for(int i = 0; i < 12; ++i) {
|
|
|
|
PARTICLE(
|
|
|
|
.sprite = "blast",
|
|
|
|
.pos = p->pos + 2 * frand() * cexp(I*M_PI*2*frand()),
|
2018-07-23 19:07:59 +02:00
|
|
|
.color = RGBA(0.15, 0.2, 0.5, 0),
|
2018-05-19 01:24:49 +02:00
|
|
|
.timeout = 12 + i + 2 * nfrand(),
|
|
|
|
.draw_rule = GrowFade,
|
|
|
|
.args = { 0, 20 + i },
|
|
|
|
.angle = M_PI*2*frand(),
|
|
|
|
.flags = PFLAG_NOREFLECT,
|
|
|
|
.layer = LAYER_OVERLAY,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ACTION_ACK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ACTION_NONE;
|
2018-05-18 20:15:11 +02:00
|
|
|
}
|
|
|
|
|
2012-07-20 16:11:24 +02:00
|
|
|
void player_death(Player *plr) {
|
2019-02-22 00:56:03 +01:00
|
|
|
if(!player_is_vulnerable(plr) || stage_is_cleared()) {
|
2018-01-02 08:36:14 +01:00
|
|
|
return;
|
2018-07-31 09:07:34 +02:00
|
|
|
}
|
2018-01-02 08:36:14 +01:00
|
|
|
|
2018-07-31 09:07:34 +02:00
|
|
|
play_sound("death");
|
2017-11-10 21:49:16 +01:00
|
|
|
|
2018-07-31 09:07:34 +02:00
|
|
|
for(int i = 0; i < 60; i++) {
|
|
|
|
tsrand_fill(2);
|
2017-11-10 21:49:16 +01:00
|
|
|
PARTICLE(
|
2018-07-31 09:07:34 +02:00
|
|
|
.sprite = "flare",
|
2017-11-10 21:49:16 +01:00
|
|
|
.pos = plr->pos,
|
2018-07-31 09:07:34 +02:00
|
|
|
.rule = linear,
|
|
|
|
.timeout = 40,
|
|
|
|
.draw_rule = Shrink,
|
|
|
|
.args = { (3+afrand(0)*7)*cexp(I*tsrand_a(1)) },
|
|
|
|
.flags = PFLAG_NOREFLECT,
|
2018-05-18 20:15:11 +02:00
|
|
|
);
|
2018-07-31 09:07:34 +02:00
|
|
|
}
|
2018-05-18 20:15:11 +02:00
|
|
|
|
2018-07-31 09:07:34 +02:00
|
|
|
stage_clear_hazards(CLEAR_HAZARDS_ALL);
|
2018-05-19 01:24:49 +02:00
|
|
|
|
2018-07-31 09:07:34 +02:00
|
|
|
PARTICLE(
|
|
|
|
.sprite = "blast",
|
|
|
|
.pos = plr->pos,
|
|
|
|
.color = RGBA(0.5, 0.15, 0.15, 0),
|
|
|
|
.timeout = 35,
|
|
|
|
.draw_rule = GrowFade,
|
|
|
|
.args = { 0, 2.4 },
|
|
|
|
.flags = PFLAG_NOREFLECT | PFLAG_REQUIREDPARTICLE,
|
|
|
|
);
|
|
|
|
|
|
|
|
PARTICLE(
|
|
|
|
.pos = plr->pos,
|
|
|
|
.size = 1+I,
|
|
|
|
.timeout = 90,
|
|
|
|
.draw_rule = player_death_effect_draw_overlay,
|
|
|
|
.blend = BLEND_NONE,
|
|
|
|
.flags = PFLAG_NOREFLECT | PFLAG_REQUIREDPARTICLE,
|
|
|
|
.layer = LAYER_OVERLAY,
|
|
|
|
.shader = "player_death",
|
|
|
|
);
|
|
|
|
|
|
|
|
PARTICLE(
|
|
|
|
.sprite_ptr = aniplayer_get_frame(&plr->ani),
|
|
|
|
.pos = plr->pos,
|
|
|
|
.timeout = 30,
|
|
|
|
.rule = player_death_effect,
|
|
|
|
.draw_rule = player_death_effect_draw_sprite,
|
|
|
|
.flags = PFLAG_NOREFLECT | PFLAG_REQUIREDPARTICLE,
|
|
|
|
.layer = LAYER_PLAYER_FOCUS, // LAYER_OVERLAY | 1,
|
|
|
|
);
|
|
|
|
|
|
|
|
plr->deathtime = global.frames + floor(player_property(plr, PLR_PROP_DEATHBOMB_WINDOW));
|
2019-02-22 00:56:03 +01:00
|
|
|
|
|
|
|
if(player_is_powersurge_active(plr)) {
|
|
|
|
player_cancel_powersurge(plr);
|
|
|
|
// player_bomb(plr);
|
|
|
|
}
|
2011-07-02 11:39:36 +02:00
|
|
|
}
|
2012-07-14 16:37:52 +02:00
|
|
|
|
2018-07-30 09:04:09 +02:00
|
|
|
static DamageResult ent_damage_player(EntityInterface *ent, const DamageInfo *dmg) {
|
|
|
|
Player *plr = ENT_CAST(ent, Player);
|
|
|
|
|
|
|
|
if(
|
2018-07-31 09:07:34 +02:00
|
|
|
!player_is_vulnerable(plr) ||
|
2018-07-30 09:04:09 +02:00
|
|
|
(dmg->type != DMG_ENEMY_SHOT && dmg->type != DMG_ENEMY_COLLISION)
|
|
|
|
) {
|
|
|
|
return DMG_RESULT_IMMUNE;
|
|
|
|
}
|
|
|
|
|
|
|
|
player_death(plr);
|
|
|
|
return DMG_RESULT_OK;
|
|
|
|
}
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
void player_damage_hook(Player *plr, EntityInterface *target, DamageInfo *dmg) {
|
|
|
|
if(player_is_powersurge_active(plr) && dmg->type == DMG_PLAYER_SHOT) {
|
|
|
|
dmg->amount *= 1.2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-06 15:24:57 +01:00
|
|
|
static PlrInputFlag key_to_inflag(KeyIndex key) {
|
2012-07-14 16:37:52 +02:00
|
|
|
switch(key) {
|
2017-11-21 22:02:32 +01:00
|
|
|
case KEY_UP: return INFLAG_UP;
|
|
|
|
case KEY_DOWN: return INFLAG_DOWN;
|
|
|
|
case KEY_LEFT: return INFLAG_LEFT;
|
|
|
|
case KEY_RIGHT: return INFLAG_RIGHT;
|
|
|
|
case KEY_FOCUS: return INFLAG_FOCUS;
|
|
|
|
case KEY_SHOT: return INFLAG_SHOT;
|
|
|
|
case KEY_SKIP: return INFLAG_SKIP;
|
2017-03-06 15:24:57 +01:00
|
|
|
default: return 0;
|
2012-07-14 16:37:52 +02:00
|
|
|
}
|
2017-03-06 15:24:57 +01:00
|
|
|
}
|
|
|
|
|
2019-01-24 21:21:08 +01:00
|
|
|
static bool player_updateinputflags(Player *plr, PlrInputFlag flags) {
|
2017-10-01 02:48:55 +02:00
|
|
|
if(flags == plr->inputflags) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-08 09:06:33 +02:00
|
|
|
if((flags & INFLAG_FOCUS) && !(plr->inputflags & INFLAG_FOCUS)) {
|
2018-06-01 20:40:18 +02:00
|
|
|
plr->focus_circle.first->birthtime = global.frames;
|
2018-05-08 09:06:33 +02:00
|
|
|
}
|
|
|
|
|
2017-09-19 20:46:28 +02:00
|
|
|
plr->inputflags = flags;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-01-24 21:21:08 +01:00
|
|
|
static bool player_updateinputflags_moveonly(Player *plr, PlrInputFlag flags) {
|
2017-09-19 20:46:28 +02:00
|
|
|
return player_updateinputflags(plr, (flags & INFLAGS_MOVE) | (plr->inputflags & ~INFLAGS_MOVE));
|
|
|
|
}
|
|
|
|
|
2019-01-24 21:21:08 +01:00
|
|
|
static bool player_setinputflag(Player *plr, KeyIndex key, bool mode) {
|
2017-09-19 20:46:28 +02:00
|
|
|
PlrInputFlag newflags = plr->inputflags;
|
|
|
|
PlrInputFlag keyflag = key_to_inflag(key);
|
|
|
|
|
|
|
|
if(!keyflag) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-03-06 15:24:57 +01:00
|
|
|
|
2017-09-19 20:46:28 +02:00
|
|
|
if(mode) {
|
|
|
|
newflags |= keyflag;
|
2012-08-12 18:00:56 +02:00
|
|
|
} else {
|
2017-09-19 20:46:28 +02:00
|
|
|
newflags &= ~keyflag;
|
2012-08-12 18:00:56 +02:00
|
|
|
}
|
2017-09-19 20:46:28 +02:00
|
|
|
|
2017-10-06 12:19:17 +02:00
|
|
|
return player_updateinputflags(plr, newflags);
|
2012-07-14 16:37:52 +02:00
|
|
|
}
|
|
|
|
|
2017-09-19 20:46:28 +02:00
|
|
|
static bool player_set_axis(int *aptr, uint16_t value) {
|
|
|
|
int16_t new = (int16_t)value;
|
|
|
|
|
|
|
|
if(*aptr == new) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aptr = new;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-10-31 10:48:30 +01:00
|
|
|
void player_event(Player *plr, uint8_t type, uint16_t value, bool *out_useful, bool *out_cheat) {
|
2017-09-19 20:46:28 +02:00
|
|
|
bool useful = true;
|
2017-10-29 23:45:24 +01:00
|
|
|
bool cheat = false;
|
2017-10-31 10:48:30 +01:00
|
|
|
bool is_replay = global.replaymode == REPLAY_PLAY;
|
2017-09-19 20:46:28 +02:00
|
|
|
|
2012-07-14 16:37:52 +02:00
|
|
|
switch(type) {
|
|
|
|
case EV_PRESS:
|
2017-09-19 20:46:28 +02:00
|
|
|
if(global.dialog && (value == KEY_SHOT || value == KEY_BOMB)) {
|
2017-11-12 18:16:15 +01:00
|
|
|
useful = page_dialog(&global.dialog);
|
2017-09-19 20:46:28 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(value) {
|
2012-07-14 16:37:52 +02:00
|
|
|
case KEY_BOMB:
|
2017-09-19 20:46:28 +02:00
|
|
|
useful = player_bomb(plr);
|
2017-10-17 22:27:35 +02:00
|
|
|
|
|
|
|
if(!useful && plr->iddqd) {
|
|
|
|
// smooth bomb cancellation test
|
|
|
|
player_cancel_bomb(plr, 60);
|
|
|
|
useful = true;
|
|
|
|
}
|
|
|
|
|
2012-07-14 16:37:52 +02:00
|
|
|
break;
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
case KEY_SPECIAL:
|
2019-02-28 11:00:35 +01:00
|
|
|
if(global.dialog) {
|
|
|
|
useful = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
useful = player_powersurge(plr);
|
|
|
|
|
|
|
|
if(!useful/* && plr->iddqd*/) {
|
|
|
|
player_cancel_powersurge(plr);
|
|
|
|
useful = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2017-02-11 02:24:47 +01:00
|
|
|
case KEY_IDDQD:
|
2017-02-11 02:56:34 +01:00
|
|
|
plr->iddqd = !plr->iddqd;
|
2017-10-29 23:45:24 +01:00
|
|
|
cheat = true;
|
2017-02-11 02:24:47 +01:00
|
|
|
break;
|
|
|
|
|
2017-03-06 13:02:46 +01:00
|
|
|
case KEY_POWERUP:
|
2019-02-22 00:56:03 +01:00
|
|
|
useful = player_add_power(plr, 100);
|
2017-10-29 23:45:24 +01:00
|
|
|
cheat = true;
|
2017-03-06 13:02:46 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_POWERDOWN:
|
2019-02-22 00:56:03 +01:00
|
|
|
useful = player_add_power(plr, -100);
|
2017-10-29 23:45:24 +01:00
|
|
|
cheat = true;
|
2017-03-06 13:02:46 +01:00
|
|
|
break;
|
|
|
|
|
2012-07-14 16:37:52 +02:00
|
|
|
default:
|
2017-09-19 20:46:28 +02:00
|
|
|
useful = player_setinputflag(plr, value, true);
|
2012-07-14 16:37:52 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2012-07-14 16:37:52 +02:00
|
|
|
case EV_RELEASE:
|
2017-10-23 12:10:40 +02:00
|
|
|
useful = player_setinputflag(plr, value, false);
|
2012-07-14 16:37:52 +02:00
|
|
|
break;
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2012-08-15 16:36:39 +02:00
|
|
|
case EV_AXIS_LR:
|
2017-09-19 20:46:28 +02:00
|
|
|
useful = player_set_axis(&plr->axis_lr, value);
|
2012-08-15 16:36:39 +02:00
|
|
|
break;
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2012-08-15 16:36:39 +02:00
|
|
|
case EV_AXIS_UD:
|
2017-09-19 20:46:28 +02:00
|
|
|
useful = player_set_axis(&plr->axis_ud, value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EV_INFLAGS:
|
|
|
|
useful = player_updateinputflags(plr, value);
|
2012-08-15 16:36:39 +02:00
|
|
|
break;
|
2017-03-21 03:28:35 +01:00
|
|
|
|
2017-10-29 23:45:24 +01:00
|
|
|
case EV_CONTINUE:
|
|
|
|
// continuing in the same frame will desync the replay,
|
|
|
|
// so schedule it for the next one
|
|
|
|
plr->continuetime = global.frames + 1;
|
|
|
|
useful = true;
|
|
|
|
break;
|
|
|
|
|
2017-03-21 03:28:35 +01:00
|
|
|
default:
|
2017-09-19 20:46:28 +02:00
|
|
|
log_warn("Can not handle event: [%i:%02x:%04x]", global.frames, type, value);
|
|
|
|
useful = false;
|
2017-03-21 03:28:35 +01:00
|
|
|
break;
|
2012-07-14 16:37:52 +02:00
|
|
|
}
|
2017-09-19 20:46:28 +02:00
|
|
|
|
2017-10-31 10:48:30 +01:00
|
|
|
if(is_replay) {
|
2017-10-29 23:45:24 +01:00
|
|
|
if(!useful) {
|
|
|
|
log_warn("Useless event in replay: [%i:%02x:%04x]", global.frames, type, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(cheat) {
|
|
|
|
log_warn("Cheat event in replay: [%i:%02x:%04x]", global.frames, type, value);
|
|
|
|
|
2018-01-12 19:26:07 +01:00
|
|
|
if( !(global.replay.flags & REPLAY_GFLAG_CHEATS) ||
|
|
|
|
!(global.replay_stage->flags & REPLAY_SFLAG_CHEATS)) {
|
2017-10-29 23:45:24 +01:00
|
|
|
log_warn("...but this replay was NOT properly cheat-flagged! Not cool, not cool at all");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(type == EV_CONTINUE && (
|
2018-01-12 19:26:07 +01:00
|
|
|
!(global.replay.flags & REPLAY_GFLAG_CONTINUES) ||
|
|
|
|
!(global.replay_stage->flags & REPLAY_SFLAG_CONTINUES))) {
|
2017-10-29 23:45:24 +01:00
|
|
|
log_warn("Continue event in replay: [%i:%02x:%04x], but this replay was not properly continue-flagged", global.frames, type, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(out_useful) {
|
|
|
|
*out_useful = useful;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(out_cheat) {
|
|
|
|
*out_cheat = cheat;
|
|
|
|
}
|
2017-09-19 20:46:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool player_event_with_replay(Player *plr, uint8_t type, uint16_t value) {
|
2017-10-29 23:45:24 +01:00
|
|
|
bool useful, cheat;
|
2017-09-19 20:46:28 +02:00
|
|
|
assert(global.replaymode == REPLAY_RECORD);
|
2017-10-31 10:48:30 +01:00
|
|
|
|
|
|
|
if(config_get_int(CONFIG_SHOT_INVERTED) && value == KEY_SHOT && (type == EV_PRESS || type == EV_RELEASE)) {
|
|
|
|
type = type == EV_PRESS ? EV_RELEASE : EV_PRESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
player_event(plr, type, value, &useful, &cheat);
|
2017-09-19 20:46:28 +02:00
|
|
|
|
2017-10-29 23:45:24 +01:00
|
|
|
if(useful) {
|
2017-09-19 20:46:28 +02:00
|
|
|
replay_stage_event(global.replay_stage, global.frames, type, value);
|
2017-10-29 23:45:24 +01:00
|
|
|
|
|
|
|
if(type == EV_CONTINUE) {
|
|
|
|
global.replay.flags |= REPLAY_GFLAG_CONTINUES;
|
|
|
|
global.replay_stage->flags |= REPLAY_SFLAG_CONTINUES;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(cheat) {
|
|
|
|
global.replay.flags |= REPLAY_GFLAG_CHEATS;
|
|
|
|
global.replay_stage->flags |= REPLAY_SFLAG_CHEATS;
|
|
|
|
}
|
|
|
|
|
2017-09-19 20:46:28 +02:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
log_debug("Useless event discarded: [%i:%02x:%04x]", global.frames, type, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2012-07-14 16:37:52 +02:00
|
|
|
}
|
|
|
|
|
2012-08-15 16:36:39 +02:00
|
|
|
// free-axis movement
|
2019-01-24 21:21:08 +01:00
|
|
|
static bool player_applymovement_gamepad(Player *plr) {
|
2017-02-04 14:41:15 +01:00
|
|
|
if(!plr->axis_lr && !plr->axis_ud) {
|
|
|
|
if(plr->gamepadmove) {
|
2017-02-11 04:52:08 +01:00
|
|
|
plr->gamepadmove = false;
|
2017-03-06 15:24:57 +01:00
|
|
|
plr->inputflags &= ~INFLAGS_MOVE;
|
2017-02-04 14:41:15 +01:00
|
|
|
}
|
2017-02-11 04:52:08 +01:00
|
|
|
return false;
|
2017-02-04 14:41:15 +01:00
|
|
|
}
|
|
|
|
|
2018-01-14 04:15:25 +01:00
|
|
|
complex direction = (
|
|
|
|
gamepad_normalize_axis_value(plr->axis_lr) +
|
|
|
|
gamepad_normalize_axis_value(plr->axis_ud) * I
|
|
|
|
);
|
|
|
|
|
|
|
|
if(cabs(direction) > 1) {
|
2012-08-15 17:03:53 +02:00
|
|
|
direction /= cabs(direction);
|
2018-01-14 04:15:25 +01:00
|
|
|
}
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2017-03-06 16:32:51 +01:00
|
|
|
int sr = sign(creal(direction));
|
|
|
|
int si = sign(cimag(direction));
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2017-09-19 20:46:28 +02:00
|
|
|
player_updateinputflags_moveonly(plr,
|
|
|
|
(INFLAG_UP * (si == -1)) |
|
|
|
|
(INFLAG_DOWN * (si == 1)) |
|
|
|
|
(INFLAG_LEFT * (sr == -1)) |
|
|
|
|
(INFLAG_RIGHT * (sr == 1))
|
|
|
|
);
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2017-02-04 14:41:15 +01:00
|
|
|
if(direction) {
|
2017-02-11 04:52:08 +01:00
|
|
|
plr->gamepadmove = true;
|
2012-08-15 16:36:39 +02:00
|
|
|
player_move(&global.plr, direction);
|
2017-02-04 14:41:15 +01:00
|
|
|
}
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2017-02-11 04:52:08 +01:00
|
|
|
return true;
|
2012-08-15 16:36:39 +02:00
|
|
|
}
|
|
|
|
|
2018-05-05 11:23:56 +02:00
|
|
|
static const char *moveseqname(int dir) {
|
2018-04-12 16:08:48 +02:00
|
|
|
switch(dir) {
|
2018-05-05 11:23:56 +02:00
|
|
|
case -1: return "left";
|
|
|
|
case 0: return "main";
|
|
|
|
case 1: return "right";
|
2018-04-12 16:08:48 +02:00
|
|
|
default: log_fatal("Invalid player animation dir given");
|
|
|
|
}
|
2018-05-05 11:23:56 +02:00
|
|
|
}
|
2018-04-12 16:08:48 +02:00
|
|
|
|
2018-05-05 11:23:56 +02:00
|
|
|
static void player_ani_moving(Player *plr, int dir) {
|
2018-04-12 16:08:48 +02:00
|
|
|
if(plr->lastmovesequence == dir)
|
|
|
|
return;
|
2018-05-05 11:23:56 +02:00
|
|
|
const char *seqname = moveseqname(dir);
|
|
|
|
const char *lastseqname = moveseqname(plr->lastmovesequence);
|
|
|
|
|
|
|
|
char *transition = strjoin(lastseqname,"2",seqname,NULL);
|
|
|
|
|
|
|
|
aniplayer_hard_switch(&plr->ani,transition,1);
|
|
|
|
aniplayer_queue(&plr->ani,seqname,0);
|
2018-04-12 16:08:48 +02:00
|
|
|
plr->lastmovesequence = dir;
|
2018-05-05 11:23:56 +02:00
|
|
|
free(transition);
|
2017-10-03 17:25:38 +02:00
|
|
|
}
|
|
|
|
|
2012-08-17 20:58:23 +02:00
|
|
|
void player_applymovement(Player *plr) {
|
2018-05-13 15:08:58 +02:00
|
|
|
plr->velocity = 0;
|
|
|
|
|
2019-03-05 12:50:29 +01:00
|
|
|
if(!player_is_alive(plr))
|
2012-07-14 16:37:52 +02:00
|
|
|
return;
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2017-02-11 04:52:08 +01:00
|
|
|
bool gamepad = player_applymovement_gamepad(plr);
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2018-04-12 16:08:48 +02:00
|
|
|
int up = plr->inputflags & INFLAG_UP;
|
|
|
|
int down = plr->inputflags & INFLAG_DOWN;
|
|
|
|
int left = plr->inputflags & INFLAG_LEFT;
|
|
|
|
int right = plr->inputflags & INFLAG_RIGHT;
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2012-07-14 16:37:52 +02:00
|
|
|
if(left && !right) {
|
2018-04-12 16:08:48 +02:00
|
|
|
player_ani_moving(plr,-1);
|
2012-07-14 16:37:52 +02:00
|
|
|
} else if(right && !left) {
|
2018-04-12 16:08:48 +02:00
|
|
|
player_ani_moving(plr,1);
|
|
|
|
} else {
|
|
|
|
player_ani_moving(plr,0);
|
2012-08-15 16:36:39 +02:00
|
|
|
}
|
2018-05-13 15:08:58 +02:00
|
|
|
|
|
|
|
if(gamepad) {
|
2012-08-15 16:36:39 +02:00
|
|
|
return;
|
2018-05-13 15:08:58 +02:00
|
|
|
}
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2012-07-14 16:37:52 +02:00
|
|
|
complex direction = 0;
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2018-01-12 19:26:07 +01:00
|
|
|
if(up) direction -= 1.0*I;
|
|
|
|
if(down) direction += 1.0*I;
|
2018-05-18 20:15:11 +02:00
|
|
|
if(left) direction -= 1.0;
|
|
|
|
if(right) direction += 1.0;
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2012-07-20 16:11:24 +02:00
|
|
|
if(cabs(direction))
|
|
|
|
direction /= cabs(direction);
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2012-07-14 16:37:52 +02:00
|
|
|
if(direction)
|
2012-07-20 16:11:24 +02:00
|
|
|
player_move(&global.plr, direction);
|
2012-08-17 20:58:23 +02:00
|
|
|
}
|
|
|
|
|
2017-09-19 20:46:28 +02:00
|
|
|
void player_fix_input(Player *plr) {
|
|
|
|
// correct input state to account for any events we might have missed,
|
|
|
|
// usually because the pause menu ate them up
|
|
|
|
|
|
|
|
PlrInputFlag newflags = plr->inputflags;
|
2017-10-31 10:48:30 +01:00
|
|
|
bool invert_shot = config_get_int(CONFIG_SHOT_INVERTED);
|
2017-03-07 00:57:14 +01:00
|
|
|
|
2017-03-06 15:24:57 +01:00
|
|
|
for(KeyIndex key = KEYIDX_FIRST; key <= KEYIDX_LAST; ++key) {
|
|
|
|
int flag = key_to_inflag(key);
|
|
|
|
|
2017-09-19 20:46:28 +02:00
|
|
|
if(flag && !(plr->gamepadmove && (flag & INFLAGS_MOVE))) {
|
2017-03-06 15:24:57 +01:00
|
|
|
bool flagset = plr->inputflags & flag;
|
|
|
|
bool keyheld = gamekeypressed(key);
|
|
|
|
|
2017-10-31 10:48:30 +01:00
|
|
|
if(invert_shot && key == KEY_SHOT) {
|
|
|
|
keyheld = !keyheld;
|
|
|
|
}
|
|
|
|
|
2017-03-06 15:24:57 +01:00
|
|
|
if(flagset && !keyheld) {
|
2017-09-19 20:46:28 +02:00
|
|
|
newflags &= ~flag;
|
2017-03-06 15:24:57 +01:00
|
|
|
} else if(!flagset && keyheld) {
|
2017-09-19 20:46:28 +02:00
|
|
|
newflags |= flag;
|
2017-03-06 15:24:57 +01:00
|
|
|
}
|
2017-09-19 20:46:28 +02:00
|
|
|
}
|
|
|
|
}
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2017-09-19 20:46:28 +02:00
|
|
|
if(newflags != plr->inputflags) {
|
|
|
|
player_event_with_replay(plr, EV_INFLAGS, newflags);
|
|
|
|
}
|
|
|
|
|
2018-01-18 10:30:42 +01:00
|
|
|
int axis_lr = gamepad_player_axis_value(PLRAXIS_LR);
|
|
|
|
int axis_ud = gamepad_player_axis_value(PLRAXIS_UD);
|
2017-09-19 20:46:28 +02:00
|
|
|
|
2018-01-18 10:30:42 +01:00
|
|
|
if(plr->axis_lr != axis_lr) {
|
|
|
|
player_event_with_replay(plr, EV_AXIS_LR, axis_lr);
|
|
|
|
}
|
2017-09-19 20:46:28 +02:00
|
|
|
|
2018-01-18 10:30:42 +01:00
|
|
|
if(plr->axis_ud != axis_ud) {
|
|
|
|
player_event_with_replay(plr, EV_AXIS_UD, axis_ud);
|
2012-07-29 15:27:15 +02:00
|
|
|
}
|
2012-07-14 16:37:52 +02:00
|
|
|
}
|
2012-08-14 16:14:53 +02:00
|
|
|
|
2019-01-04 23:59:39 +01:00
|
|
|
void player_graze(Player *plr, complex pos, int pts, int effect_intensity, const Color *color) {
|
2019-02-22 00:56:03 +01:00
|
|
|
if(++plr->graze >= PLR_MAX_GRAZE) {
|
|
|
|
log_debug("Graze counter overflow");
|
|
|
|
plr->graze = PLR_MAX_GRAZE;
|
2018-01-09 19:49:30 +01:00
|
|
|
}
|
2017-03-25 19:18:24 +01:00
|
|
|
|
2019-01-04 23:59:39 +01:00
|
|
|
pos = (pos + plr->pos) * 0.5;
|
|
|
|
|
2018-01-06 10:44:27 +01:00
|
|
|
player_add_points(plr, pts);
|
2012-08-14 16:14:53 +02:00
|
|
|
play_sound("graze");
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2019-01-04 23:59:39 +01:00
|
|
|
Color *c = COLOR_COPY(color);
|
|
|
|
color_add(c, RGBA(1, 1, 1, 1));
|
|
|
|
color_mul_scalar(c, 0.5);
|
|
|
|
c->a = 0;
|
|
|
|
|
2018-01-06 10:44:27 +01:00
|
|
|
for(int i = 0; i < effect_intensity; ++i) {
|
2019-01-04 23:59:39 +01:00
|
|
|
tsrand_fill(4);
|
2017-11-10 21:49:16 +01:00
|
|
|
|
|
|
|
PARTICLE(
|
2019-01-04 23:59:39 +01:00
|
|
|
.sprite = "graze",
|
|
|
|
.color = c,
|
2017-11-10 21:49:16 +01:00
|
|
|
.pos = pos,
|
2019-01-04 23:59:39 +01:00
|
|
|
.rule = asymptotic,
|
|
|
|
.timeout = 24 + 5 * afrand(2),
|
|
|
|
.draw_rule = ScaleSquaredFade,
|
|
|
|
.args = { 0.2 * (1+afrand(0)*5)*cexp(I*M_PI*2*afrand(1)), 16 * (1 + 0.5 * anfrand(3)), 1 },
|
2018-01-11 21:16:18 +01:00
|
|
|
.flags = PFLAG_NOREFLECT,
|
2019-01-04 23:59:39 +01:00
|
|
|
// .layer = LAYER_PARTICLE_LOW,
|
2017-11-10 21:49:16 +01:00
|
|
|
);
|
2019-01-04 23:59:39 +01:00
|
|
|
|
|
|
|
color_mul_scalar(c, 0.4);
|
2012-08-14 16:14:53 +02:00
|
|
|
}
|
2019-02-22 00:56:03 +01:00
|
|
|
|
2019-03-03 12:53:45 +01:00
|
|
|
spawn_items(pos, ITEM_POWER_MINI, 1);
|
2012-08-14 16:14:53 +02:00
|
|
|
}
|
2017-03-11 04:41:57 +01:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
static void player_add_fragments(Player *plr, int frags, int *pwhole, int *pfrags, int maxfrags, int maxwhole, const char *fragsnd, const char *upsnd, int score_per_excess) {
|
|
|
|
int total_frags = *pfrags + maxfrags * *pwhole;
|
|
|
|
int excess_frags = total_frags + frags - maxwhole * maxfrags;
|
|
|
|
|
|
|
|
if(excess_frags > 0) {
|
|
|
|
player_add_points(plr, excess_frags * score_per_excess);
|
|
|
|
frags -= excess_frags;
|
2017-03-21 11:09:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
*pfrags += frags;
|
|
|
|
int up = *pfrags / maxfrags;
|
|
|
|
|
|
|
|
*pwhole += up;
|
|
|
|
*pfrags %= maxfrags;
|
|
|
|
|
|
|
|
if(up) {
|
|
|
|
play_sound(upsnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(frags) {
|
|
|
|
// FIXME: when we have the extra life/bomb sounds,
|
|
|
|
// don't play this if upsnd was just played.
|
|
|
|
play_sound(fragsnd);
|
|
|
|
}
|
|
|
|
|
2017-12-01 14:09:30 +01:00
|
|
|
if(*pwhole >= maxwhole) {
|
2017-03-21 11:09:32 +01:00
|
|
|
*pwhole = maxwhole;
|
2017-12-01 14:09:30 +01:00
|
|
|
*pfrags = 0;
|
2017-03-21 11:09:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void player_add_life_fragments(Player *plr, int frags) {
|
2019-02-22 00:56:03 +01:00
|
|
|
player_add_fragments(
|
|
|
|
plr,
|
|
|
|
frags,
|
|
|
|
&plr->lives,
|
|
|
|
&plr->life_fragments,
|
|
|
|
PLR_MAX_LIFE_FRAGMENTS,
|
|
|
|
PLR_MAX_LIVES,
|
2017-03-21 11:09:32 +01:00
|
|
|
"item_generic", // FIXME: replacement needed
|
2019-02-22 00:56:03 +01:00
|
|
|
"extra_life",
|
|
|
|
(plr->point_item_value * 10) / PLR_MAX_LIFE_FRAGMENTS
|
2017-03-21 11:09:32 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void player_add_bomb_fragments(Player *plr, int frags) {
|
2019-02-22 00:56:03 +01:00
|
|
|
player_add_fragments(
|
|
|
|
plr,
|
|
|
|
frags,
|
|
|
|
&plr->bombs,
|
|
|
|
&plr->bomb_fragments,
|
|
|
|
PLR_MAX_BOMB_FRAGMENTS,
|
|
|
|
PLR_MAX_BOMBS,
|
2017-03-21 11:09:32 +01:00
|
|
|
"item_generic", // FIXME: replacement needed
|
2019-02-22 00:56:03 +01:00
|
|
|
"extra_bomb",
|
|
|
|
(plr->point_item_value * 5) / PLR_MAX_BOMB_FRAGMENTS
|
2017-03-21 11:09:32 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void player_add_lives(Player *plr, int lives) {
|
|
|
|
player_add_life_fragments(plr, PLR_MAX_LIFE_FRAGMENTS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void player_add_bombs(Player *plr, int bombs) {
|
|
|
|
player_add_bomb_fragments(plr, PLR_MAX_BOMB_FRAGMENTS);
|
|
|
|
}
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
void player_add_points(Player *plr, uint points) {
|
|
|
|
plr->points += points;
|
|
|
|
|
|
|
|
while(plr->points >= plr->extralife_threshold) {
|
|
|
|
plr->extralife_threshold = player_next_extralife_threshold(++plr->extralives_given);
|
2019-02-28 11:10:03 +01:00
|
|
|
player_add_lives(plr, 1);
|
2019-02-22 00:56:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void player_add_piv(Player *plr, uint piv) {
|
|
|
|
uint v = plr->point_item_value + piv;
|
2017-03-25 19:18:24 +01:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
if(v > PLR_MAX_PIV || v < plr->point_item_value) {
|
|
|
|
plr->point_item_value = PLR_MAX_PIV;
|
|
|
|
} else {
|
|
|
|
plr->point_item_value = v;
|
|
|
|
}
|
|
|
|
}
|
2017-03-25 19:18:24 +01:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
void player_add_voltage(Player *plr, uint voltage) {
|
|
|
|
uint v = plr->voltage + voltage;
|
|
|
|
|
|
|
|
if(v > PLR_MAX_VOLTAGE || v < plr->voltage) {
|
|
|
|
plr->voltage = PLR_MAX_VOLTAGE;
|
|
|
|
} else {
|
|
|
|
plr->voltage = v;
|
2017-03-25 19:18:24 +01:00
|
|
|
}
|
2019-02-22 00:56:03 +01:00
|
|
|
|
|
|
|
player_add_bomb_fragments(plr, voltage);
|
2017-03-25 19:18:24 +01:00
|
|
|
}
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
bool player_drain_voltage(Player *plr, uint voltage) {
|
|
|
|
// TODO: animate (or maybe handle that at stagedraw level)
|
2017-03-25 19:18:24 +01:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
if(plr->voltage >= voltage) {
|
|
|
|
plr->voltage -= voltage;
|
|
|
|
return true;
|
2017-03-27 13:08:26 +02:00
|
|
|
}
|
2019-02-22 00:56:03 +01:00
|
|
|
|
|
|
|
plr->voltage = 0;
|
|
|
|
return false;
|
2017-03-25 19:18:24 +01:00
|
|
|
}
|
|
|
|
|
2018-07-30 09:04:09 +02:00
|
|
|
void player_register_damage(Player *plr, EntityInterface *target, const DamageInfo *damage) {
|
2019-02-22 00:56:03 +01:00
|
|
|
if(!DAMAGETYPE_IS_PLAYER(damage->type)) {
|
2018-07-30 09:04:09 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
complex pos = NAN;
|
|
|
|
|
2018-07-30 09:04:09 +02:00
|
|
|
if(target != NULL) {
|
|
|
|
switch(target->type) {
|
|
|
|
case ENT_ENEMY: {
|
|
|
|
player_add_points(&global.plr, damage->amount * 0.5);
|
2019-02-22 00:56:03 +01:00
|
|
|
pos = ENT_CAST(target, Enemy)->pos;
|
2018-07-30 09:04:09 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ENT_BOSS: {
|
|
|
|
player_add_points(&global.plr, damage->amount * 0.2);
|
2019-02-22 00:56:03 +01:00
|
|
|
pos = ENT_CAST(target, Boss)->pos;
|
2018-07-30 09:04:09 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
if(!isnan(creal(pos)) && damage->type == DMG_PLAYER_DISCHARGE) {
|
|
|
|
double rate = target->type == ENT_BOSS ? 110 : 256;
|
2019-03-03 12:53:45 +01:00
|
|
|
spawn_and_collect_items(pos, 1, ITEM_VOLTAGE, (int)(damage->amount / rate));
|
2019-02-22 00:56:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(player_is_powersurge_active(plr)) {
|
|
|
|
plr->powersurge.damage_done += damage->amount;
|
|
|
|
plr->powersurge.damage_accum += damage->amount;
|
|
|
|
|
|
|
|
if(!isnan(creal(pos))) {
|
|
|
|
double rate = 500;
|
|
|
|
|
|
|
|
while(plr->powersurge.damage_accum > rate) {
|
|
|
|
plr->powersurge.damage_accum -= rate;
|
|
|
|
spawn_item(pos, ITEM_SURGE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-30 09:04:09 +02:00
|
|
|
|
2018-05-03 19:51:10 +02:00
|
|
|
#ifdef PLR_DPS_STATS
|
|
|
|
while(global.frames > plr->dmglogframe) {
|
|
|
|
memmove(plr->dmglog + 1, plr->dmglog, sizeof(plr->dmglog) - sizeof(*plr->dmglog));
|
|
|
|
plr->dmglog[0] = 0;
|
|
|
|
plr->dmglogframe++;
|
|
|
|
}
|
|
|
|
|
2018-07-30 09:04:09 +02:00
|
|
|
plr->dmglog[0] += damage->amount;
|
2018-05-03 19:51:10 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
uint64_t player_next_extralife_threshold(uint64_t step) {
|
|
|
|
static uint64_t base = 5000000;
|
|
|
|
return base * (step * step + step + 2) / 2;
|
|
|
|
}
|
|
|
|
|
2017-03-11 04:41:57 +01:00
|
|
|
void player_preload(void) {
|
|
|
|
const int flags = RESF_DEFAULT;
|
|
|
|
|
2018-05-18 20:15:11 +02:00
|
|
|
preload_resources(RES_SHADER_PROGRAM, flags,
|
|
|
|
"player_death",
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
preload_resources(RES_TEXTURE, flags,
|
|
|
|
"static",
|
|
|
|
NULL);
|
|
|
|
|
2018-02-06 07:19:25 +01:00
|
|
|
preload_resources(RES_SPRITE, flags,
|
2017-03-11 04:41:57 +01:00
|
|
|
"fairy_circle",
|
2019-02-22 00:56:03 +01:00
|
|
|
"focus",
|
|
|
|
"part/blast_huge_halo",
|
|
|
|
"part/powersurge_field",
|
2017-03-11 04:41:57 +01:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
preload_resources(RES_SFX, flags | RESF_OPTIONAL,
|
|
|
|
"death",
|
2017-03-21 11:09:32 +01:00
|
|
|
"extra_bomb",
|
2019-02-22 00:56:03 +01:00
|
|
|
"extra_life",
|
|
|
|
"full_power",
|
|
|
|
"generic_shot",
|
|
|
|
"graze",
|
2018-08-14 02:56:16 +02:00
|
|
|
"hit0",
|
|
|
|
"hit1",
|
2019-02-22 00:56:03 +01:00
|
|
|
"powerup",
|
2017-03-11 04:41:57 +01:00
|
|
|
NULL);
|
|
|
|
}
|
2018-08-11 21:13:48 +02:00
|
|
|
|
|
|
|
// FIXME: where should this be?
|
|
|
|
|
|
|
|
complex plrutil_homing_target(complex org, complex fallback) {
|
|
|
|
double mindst = INFINITY;
|
|
|
|
complex target = fallback;
|
|
|
|
|
|
|
|
if(global.boss && boss_is_vulnerable(global.boss)) {
|
|
|
|
target = global.boss->pos;
|
|
|
|
mindst = cabs(target - org);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(Enemy *e = global.enemies.first; e; e = e->next) {
|
|
|
|
if(e->hp == ENEMY_IMMUNE) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
double dst = cabs(e->pos - org);
|
|
|
|
|
|
|
|
if(dst < mindst) {
|
|
|
|
mindst = dst;
|
|
|
|
target = e->pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return target;
|
|
|
|
}
|