2010-10-12 10:55:23 +02:00
|
|
|
/*
|
2011-03-05 19:03:32 +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 19:03:32 +01:00
|
|
|
* ---
|
2018-01-04 18:14:31 +01:00
|
|
|
* Copyright (c) 2011-2018, Lukas Weber <laochailan@web.de>.
|
|
|
|
* Copyright (c) 2012-2018, 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 "projectile.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "global.h"
|
2010-10-27 19:51:49 +02:00
|
|
|
#include "list.h"
|
2011-12-25 08:18:03 +01:00
|
|
|
#include "vbo.h"
|
2017-12-13 20:05:12 +01:00
|
|
|
#include "stageobjects.h"
|
2011-04-26 16:55:18 +02:00
|
|
|
|
2017-11-10 21:49:16 +01:00
|
|
|
static ProjArgs defaults_proj = {
|
|
|
|
.texture = "proj/",
|
|
|
|
.draw_rule = ProjDraw,
|
|
|
|
.dest = &global.projs,
|
|
|
|
.type = EnemyProj,
|
|
|
|
.color = RGB(1, 1, 1),
|
|
|
|
.color_transform_rule = proj_clrtransform_bullet,
|
2017-11-23 16:27:41 +01:00
|
|
|
.insertion_rule = proj_insert_sizeprio,
|
2017-11-10 21:49:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static ProjArgs defaults_part = {
|
|
|
|
.texture = "part/",
|
|
|
|
.draw_rule = ProjDraw,
|
|
|
|
.dest = &global.particles,
|
|
|
|
.type = Particle,
|
|
|
|
.color = RGB(1, 1, 1),
|
|
|
|
.color_transform_rule = proj_clrtransform_particle,
|
2017-11-23 16:27:41 +01:00
|
|
|
.insertion_rule = list_append,
|
2017-11-25 16:51:43 +01:00
|
|
|
// .insertion_rule = proj_insert_sizeprio,
|
2017-11-10 21:49:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static void process_projectile_args(ProjArgs *args, ProjArgs *defaults) {
|
|
|
|
int texargs = (bool)args->texture + (bool)args->texture_ptr + (bool)args->size;
|
|
|
|
|
|
|
|
if(texargs != 1) {
|
|
|
|
log_fatal("Exactly one of .texture, .texture_ptr, or .size is required");
|
|
|
|
}
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2017-11-10 21:49:16 +01:00
|
|
|
if(!args->rule) {
|
|
|
|
log_fatal(".rule is required");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(args->texture) {
|
|
|
|
args->texture_ptr = prefix_get_tex(args->texture, defaults->texture);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!args->draw_rule) {
|
|
|
|
args->draw_rule = ProjDraw;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!args->dest) {
|
|
|
|
args->dest = defaults->dest;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!args->type) {
|
|
|
|
args->type = defaults->type;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!args->color) {
|
|
|
|
args->color = defaults->color;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!args->color_transform_rule) {
|
|
|
|
args->color_transform_rule = defaults->color_transform_rule;
|
|
|
|
}
|
|
|
|
|
2017-11-23 16:27:41 +01:00
|
|
|
if(!args->insertion_rule) {
|
|
|
|
args->insertion_rule = defaults->insertion_rule;
|
|
|
|
}
|
|
|
|
|
2017-11-10 21:49:16 +01:00
|
|
|
if(!args->max_viewport_dist && (args->type == Particle || args->type >= PlrProj)) {
|
|
|
|
args->max_viewport_dist = 300;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-23 16:27:41 +01:00
|
|
|
static double projectile_rect_area(Projectile *p) {
|
|
|
|
if(p->tex) {
|
|
|
|
return p->tex->w * p->tex->h;
|
|
|
|
} else {
|
|
|
|
return creal(p->size) * cimag(p->size);
|
2017-11-10 21:49:16 +01:00
|
|
|
}
|
|
|
|
}
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2017-11-23 16:27:41 +01:00
|
|
|
static void projectile_size(Projectile *p, double *w, double *h) {
|
|
|
|
if(p->tex) {
|
|
|
|
*w = p->tex->w;
|
|
|
|
*h = p->tex->h;
|
|
|
|
} else {
|
|
|
|
*w = creal(p->size);
|
|
|
|
*h = cimag(p->size);
|
|
|
|
}
|
2017-11-10 21:49:16 +01:00
|
|
|
}
|
|
|
|
|
2017-11-21 15:45:01 +01:00
|
|
|
int projectile_prio_func(List *vproj) {
|
|
|
|
Projectile *proj = (Projectile*)vproj;
|
2017-11-23 16:27:41 +01:00
|
|
|
return -rint(projectile_rect_area(proj));
|
|
|
|
}
|
|
|
|
|
|
|
|
List* proj_insert_sizeprio(List **dest, List *elem) {
|
|
|
|
return list_insert_at_priority(dest, elem, projectile_prio_func(elem), projectile_prio_func);
|
2017-11-10 21:49:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Projectile* _create_projectile(ProjArgs *args) {
|
2017-11-15 07:05:47 +01:00
|
|
|
if(IN_DRAW_CODE) {
|
|
|
|
log_fatal("Tried to spawn a projectile while in drawing code");
|
|
|
|
}
|
|
|
|
|
2017-12-13 20:05:12 +01:00
|
|
|
Projectile *p = (Projectile*)objpool_acquire(stage_object_pools.projectiles);
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2011-03-07 07:26:43 +01:00
|
|
|
p->birthtime = global.frames;
|
2017-11-10 21:49:16 +01:00
|
|
|
p->pos = p->pos0 = args->pos;
|
|
|
|
p->angle = args->angle;
|
|
|
|
p->rule = args->rule;
|
|
|
|
p->draw_rule = args->draw_rule;
|
|
|
|
p->color_transform_rule = args->color_transform_rule;
|
|
|
|
p->tex = args->texture_ptr;
|
|
|
|
p->type = args->type;
|
|
|
|
p->color = args->color;
|
|
|
|
p->grazed = (bool)(args->flags & PFLAG_NOGRAZE);
|
|
|
|
p->max_viewport_dist = args->max_viewport_dist;
|
|
|
|
p->size = args->size;
|
|
|
|
p->flags = args->flags;
|
|
|
|
|
|
|
|
memcpy(p->args, args->args, sizeof(p->args));
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2017-10-20 20:31:21 +02:00
|
|
|
// BUG: this currently breaks some projectiles
|
|
|
|
// enable this when they're fixed
|
|
|
|
// assert(rule != NULL);
|
|
|
|
// rule(p, EVENT_BIRTH);
|
|
|
|
|
2017-11-23 16:27:41 +01:00
|
|
|
return (Projectile*)args->insertion_rule((List**)args->dest, (List*)p);
|
2010-10-12 10:55:23 +02:00
|
|
|
}
|
|
|
|
|
2017-11-10 21:49:16 +01:00
|
|
|
Projectile* create_projectile(ProjArgs *args) {
|
|
|
|
process_projectile_args(args, &defaults_proj);
|
|
|
|
return _create_projectile(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
Projectile* create_particle(ProjArgs *args) {
|
|
|
|
process_projectile_args(args, &defaults_part);
|
|
|
|
return _create_projectile(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef PROJ_DEBUG
|
2017-11-23 16:27:41 +01:00
|
|
|
Projectile* _proj_attach_dbginfo(Projectile *p, DebugInfo *dbg, const char *callsite_str) {
|
|
|
|
// log_debug("Spawn: [%s]", callsite_str);
|
2017-11-15 07:05:47 +01:00
|
|
|
memcpy(&p->debug, dbg, sizeof(DebugInfo));
|
|
|
|
set_debug_info(dbg);
|
2017-11-10 21:49:16 +01:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-11-21 15:45:01 +01:00
|
|
|
static void* _delete_projectile(List **projs, List *proj, void *arg) {
|
|
|
|
Projectile *p = (Projectile*)proj;
|
2011-05-21 15:02:19 +02:00
|
|
|
p->rule(p, EVENT_DEATH);
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2011-05-13 19:03:02 +02:00
|
|
|
del_ref(proj);
|
2017-12-13 20:05:12 +01:00
|
|
|
objpool_release(stage_object_pools.projectiles, (ObjectInterface*)list_unlink(projs, proj));
|
|
|
|
|
2017-11-21 15:45:01 +01:00
|
|
|
return NULL;
|
2011-04-26 22:39:50 +02:00
|
|
|
}
|
|
|
|
|
2011-05-06 17:09:43 +02:00
|
|
|
void delete_projectile(Projectile **projs, Projectile *proj) {
|
2017-11-21 15:45:01 +01:00
|
|
|
_delete_projectile((List**)projs, (List*)proj, NULL);
|
2010-10-12 10:55:23 +02:00
|
|
|
}
|
|
|
|
|
2011-05-06 17:09:43 +02:00
|
|
|
void delete_projectiles(Projectile **projs) {
|
2017-12-24 07:16:25 +01:00
|
|
|
list_foreach(projs, _delete_projectile, NULL);
|
2010-10-12 10:55:23 +02:00
|
|
|
}
|
|
|
|
|
2017-12-28 10:05:54 +01:00
|
|
|
void calc_projectile_collision(Projectile *p, ProjCollisionResult *out_col) {
|
|
|
|
assert(out_col != NULL);
|
|
|
|
|
|
|
|
out_col->type = PCOL_NONE;
|
|
|
|
out_col->entity = NULL;
|
|
|
|
out_col->fatal = false;
|
|
|
|
out_col->location = p->pos;
|
|
|
|
out_col->damage = 0;
|
|
|
|
|
2017-11-05 15:02:49 +01:00
|
|
|
if(p->type == EnemyProj) {
|
2017-11-01 05:47:36 +01:00
|
|
|
double w, h;
|
2017-11-23 16:27:41 +01:00
|
|
|
projectile_size(p, &w, &h);
|
2017-11-01 05:47:36 +01:00
|
|
|
|
2012-08-13 21:53:36 +02:00
|
|
|
double angle = carg(global.plr.pos - p->pos) + p->angle;
|
2017-11-11 16:38:32 +01:00
|
|
|
double projr = sqrt(pow(w/2*cos(angle), 2) + pow(h/2*sin(angle), 2)) * 0.45;
|
2017-11-01 05:47:36 +01:00
|
|
|
double grazer = max(w, h);
|
2012-08-13 21:53:36 +02:00
|
|
|
double dst = cabs(global.plr.pos - p->pos);
|
2017-02-10 23:05:22 +01:00
|
|
|
grazer = (0.9 * sqrt(grazer) + 0.1 * grazer) * 6;
|
|
|
|
|
2017-12-28 10:05:54 +01:00
|
|
|
if(dst < projr + 1) {
|
|
|
|
out_col->type = PCOL_PLAYER;
|
|
|
|
out_col->entity = &global.plr;
|
|
|
|
out_col->fatal = true;
|
|
|
|
} else if(!p->grazed && dst < grazer && global.frames - abs(global.plr.recovery) > 0) {
|
|
|
|
out_col->location = p->pos - grazer * 0.3 * cexp(I*carg(p->pos - global.plr.pos));
|
|
|
|
out_col->type = PCOL_PLAYER_GRAZE;
|
|
|
|
out_col->entity = &global.plr;
|
2012-08-12 21:29:10 +02:00
|
|
|
}
|
2011-07-06 14:33:53 +02:00
|
|
|
} else if(p->type >= PlrProj) {
|
2017-02-10 23:05:22 +01:00
|
|
|
int damage = p->type - PlrProj;
|
|
|
|
|
2017-12-28 10:05:54 +01:00
|
|
|
for(Enemy *e = global.enemies; e; e = e->next) {
|
2017-10-28 05:41:45 +02:00
|
|
|
if(e->hp != ENEMY_IMMUNE && cabs(e->pos - p->pos) < 30) {
|
2017-12-28 10:05:54 +01:00
|
|
|
out_col->type = PCOL_ENEMY;
|
|
|
|
out_col->entity = e;
|
|
|
|
out_col->fatal = true;
|
|
|
|
out_col->damage = damage;
|
2017-03-06 13:02:46 +01:00
|
|
|
|
2017-12-28 10:05:54 +01:00
|
|
|
return;
|
2010-10-17 10:39:07 +02:00
|
|
|
}
|
|
|
|
}
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2017-09-27 11:08:32 +02:00
|
|
|
if(global.boss && cabs(global.boss->pos - p->pos) < 42) {
|
2017-12-28 10:05:54 +01:00
|
|
|
if(boss_is_vulnerable(global.boss)) {
|
|
|
|
out_col->type = PCOL_BOSS;
|
|
|
|
out_col->entity = global.boss;
|
|
|
|
out_col->fatal = true;
|
|
|
|
out_col->damage = damage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(out_col->type == PCOL_NONE && !projectile_in_viewport(p)) {
|
|
|
|
out_col->type = PCOL_VOID;
|
|
|
|
out_col->fatal = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void apply_projectile_collision(Projectile **projlist, Projectile *p, ProjCollisionResult *col) {
|
|
|
|
switch(col->type) {
|
|
|
|
case PCOL_NONE: {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PCOL_PLAYER: {
|
|
|
|
if(global.frames - abs(((Player*)col->entity)->recovery) >= 0) {
|
|
|
|
player_death(col->entity);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PCOL_PLAYER_GRAZE: {
|
|
|
|
p->grazed = true;
|
|
|
|
player_graze(col->entity, col->location, 50);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PCOL_ENEMY: {
|
|
|
|
Enemy *e = col->entity;
|
|
|
|
player_add_points(&global.plr, col->damage * 0.5);
|
|
|
|
|
|
|
|
#ifdef PLR_DPS_STATS
|
|
|
|
global.plr.total_dmg += min(e->hp, col->damage);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
e->hp -= col->damage;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PCOL_BOSS: {
|
|
|
|
if(boss_damage(col->entity, col->damage)) {
|
|
|
|
player_add_points(&global.plr, col->damage * 0.2);
|
2017-03-06 13:02:46 +01:00
|
|
|
|
2017-09-27 11:08:32 +02:00
|
|
|
#ifdef PLR_DPS_STATS
|
2017-12-28 10:05:54 +01:00
|
|
|
global.plr.total_dmg += col->damage;
|
2017-09-27 11:08:32 +02:00
|
|
|
#endif
|
|
|
|
}
|
2017-12-28 10:05:54 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PCOL_VOID: {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default: {
|
|
|
|
log_fatal("Invalid collision type %x", col->type);
|
2011-04-08 18:59:03 +02:00
|
|
|
}
|
2010-10-17 10:39:07 +02:00
|
|
|
}
|
2017-12-28 10:05:54 +01:00
|
|
|
|
|
|
|
if(col->fatal) {
|
|
|
|
delete_projectile(projlist, p);
|
|
|
|
}
|
2010-10-17 09:27:44 +02:00
|
|
|
}
|
|
|
|
|
2017-11-10 21:49:16 +01:00
|
|
|
void static_clrtransform_bullet(Color c, ColorTransform *out) {
|
2017-11-20 11:08:57 +01:00
|
|
|
memcpy(out, (&(ColorTransform) {
|
2017-11-10 21:49:16 +01:00
|
|
|
.B[0] = c & ~CLRMASK_A,
|
|
|
|
.B[1] = rgba(1, 1, 1, 0),
|
|
|
|
.A[1] = c & CLRMASK_A,
|
2017-11-20 11:08:57 +01:00
|
|
|
}), sizeof(ColorTransform));
|
2017-11-10 21:49:16 +01:00
|
|
|
}
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2017-11-10 21:49:16 +01:00
|
|
|
void static_clrtransform_particle(Color c, ColorTransform *out) {
|
2017-11-20 11:08:57 +01:00
|
|
|
memcpy(out, (&(ColorTransform) {
|
2017-11-10 21:49:16 +01:00
|
|
|
.R[1] = c & CLRMASK_R,
|
|
|
|
.G[1] = c & CLRMASK_G,
|
|
|
|
.B[1] = c & CLRMASK_B,
|
|
|
|
.A[1] = c & CLRMASK_A,
|
2017-11-20 11:08:57 +01:00
|
|
|
}), sizeof(ColorTransform));
|
2017-11-10 21:49:16 +01:00
|
|
|
}
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2017-11-10 21:49:16 +01:00
|
|
|
void proj_clrtransform_bullet(Projectile *p, int t, Color c, ColorTransform *out) {
|
|
|
|
static_clrtransform_bullet(c, out);
|
2010-10-18 14:40:15 +02:00
|
|
|
}
|
2010-10-17 09:27:44 +02:00
|
|
|
|
2017-11-10 21:49:16 +01:00
|
|
|
void proj_clrtransform_particle(Projectile *p, int t, Color c, ColorTransform *out) {
|
|
|
|
static_clrtransform_particle(c, out);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void draw_projectile(Projectile *proj) {
|
2017-11-15 07:05:47 +01:00
|
|
|
#ifdef PROJ_DEBUG
|
|
|
|
static Projectile prev_state;
|
|
|
|
memcpy(&prev_state, proj, sizeof(Projectile));
|
|
|
|
|
2017-11-10 21:49:16 +01:00
|
|
|
proj->draw_rule(proj, global.frames - proj->birthtime);
|
2017-10-24 04:57:14 +02:00
|
|
|
|
2017-11-15 07:05:47 +01:00
|
|
|
if(memcmp(&prev_state, proj, sizeof(Projectile))) {
|
|
|
|
set_debug_info(&proj->debug);
|
|
|
|
log_fatal("Projectile modified its state in draw rule");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2017-11-10 21:49:16 +01:00
|
|
|
int cur_shader;
|
2017-11-15 07:05:47 +01:00
|
|
|
glGetIntegerv(GL_CURRENT_PROGRAM, &cur_shader); // NOTE: this can be really slow!
|
2017-11-10 21:49:16 +01:00
|
|
|
|
2017-11-15 07:05:47 +01:00
|
|
|
if(cur_shader != recolor_get_shader()->prog) {
|
|
|
|
set_debug_info(&proj->debug);
|
|
|
|
log_fatal("Bad shader after drawing projectile");
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
#else
|
|
|
|
proj->draw_rule(proj, global.frames - proj->birthtime);
|
2017-11-10 21:49:16 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void draw_projectiles(Projectile *projs, ProjPredicate predicate) {
|
|
|
|
glUseProgram(recolor_get_shader()->prog);
|
|
|
|
|
|
|
|
if(predicate) {
|
|
|
|
for(Projectile *proj = projs; proj; proj = proj->next) {
|
|
|
|
if(predicate(proj)) {
|
|
|
|
draw_projectile(proj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for(Projectile *proj = projs; proj; proj = proj->next) {
|
|
|
|
draw_projectile(proj);
|
|
|
|
}
|
2017-10-24 04:57:14 +02:00
|
|
|
}
|
|
|
|
|
2017-11-10 21:49:16 +01:00
|
|
|
glUseProgram(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool projectile_in_viewport(Projectile *proj) {
|
2017-11-01 05:47:36 +01:00
|
|
|
double w, h;
|
2017-11-10 21:49:16 +01:00
|
|
|
int e = proj->max_viewport_dist;
|
2017-11-23 16:27:41 +01:00
|
|
|
projectile_size(proj, &w, &h);
|
2017-11-01 05:47:36 +01:00
|
|
|
|
|
|
|
return !(creal(proj->pos) + w/2 + e < 0 || creal(proj->pos) - w/2 - e > VIEWPORT_W
|
|
|
|
|| cimag(proj->pos) + h/2 + e < 0 || cimag(proj->pos) - h/2 - e > VIEWPORT_H);
|
2017-10-24 04:57:14 +02:00
|
|
|
}
|
|
|
|
|
2017-02-11 04:52:08 +01:00
|
|
|
void process_projectiles(Projectile **projs, bool collision) {
|
2017-12-28 10:05:54 +01:00
|
|
|
ProjCollisionResult col = { 0 };
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2011-05-13 19:03:02 +02:00
|
|
|
char killed = 0;
|
|
|
|
int action;
|
2017-12-28 10:05:54 +01:00
|
|
|
|
|
|
|
for(Projectile *proj = *projs, *next; proj; proj = next) {
|
|
|
|
next = proj->next;
|
|
|
|
|
2011-05-13 19:03:02 +02:00
|
|
|
action = proj->rule(proj, global.frames - proj->birthtime);
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2012-07-20 11:45:29 +02:00
|
|
|
if(proj->type == DeadProj && killed < 5) {
|
2011-05-13 19:03:02 +02:00
|
|
|
killed++;
|
|
|
|
action = ACTION_DESTROY;
|
2017-10-31 14:47:20 +01:00
|
|
|
create_bpoint(proj->pos);
|
2011-05-13 19:03:02 +02:00
|
|
|
}
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2017-12-28 10:05:54 +01:00
|
|
|
if(collision) {
|
|
|
|
calc_projectile_collision(proj, &col);
|
|
|
|
|
2017-12-31 10:23:57 +01:00
|
|
|
if(col.fatal && col.type != PCOL_VOID) {
|
2017-12-28 10:05:54 +01:00
|
|
|
PARTICLE(
|
|
|
|
.texture_ptr = proj->tex,
|
|
|
|
.pos = proj->pos,
|
|
|
|
.color = proj->color,
|
|
|
|
.flags = proj->flags,
|
|
|
|
.color_transform_rule = proj->color_transform_rule,
|
|
|
|
.rule = timeout_linear,
|
|
|
|
.draw_rule = DeathShrink,
|
|
|
|
.args = { 10, 5*cexp(proj->angle*I) },
|
|
|
|
.type = proj->type >= PlrProj ? PlrProj : Particle,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
memset(&col, 0, sizeof(col));
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2017-12-28 10:05:54 +01:00
|
|
|
if(!projectile_in_viewport(proj)) {
|
|
|
|
col.fatal = true;
|
|
|
|
}
|
|
|
|
}
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2017-12-28 10:05:54 +01:00
|
|
|
if(action == ACTION_DESTROY) {
|
|
|
|
col.fatal = true;
|
2010-10-17 10:39:07 +02:00
|
|
|
}
|
2017-12-28 10:05:54 +01:00
|
|
|
|
|
|
|
apply_projectile_collision(projs, proj, &col);
|
2010-10-27 19:51:49 +02:00
|
|
|
}
|
2010-10-12 10:55:23 +02:00
|
|
|
}
|
|
|
|
|
2017-12-28 11:40:40 +01:00
|
|
|
int trace_projectile(Projectile *p, ProjCollisionResult *out_col, ProjCollisionType stopflags, int timeofs) {
|
|
|
|
int t;
|
|
|
|
|
|
|
|
for(t = timeofs; p; ++t) {
|
2017-11-01 05:47:36 +01:00
|
|
|
int action = p->rule(p, t);
|
2017-12-28 10:05:54 +01:00
|
|
|
calc_projectile_collision(p, out_col);
|
2017-11-01 05:47:36 +01:00
|
|
|
|
2017-12-28 10:05:54 +01:00
|
|
|
if(out_col->type & stopflags || action == ACTION_DESTROY) {
|
2017-12-28 11:40:40 +01:00
|
|
|
return t;
|
2017-11-01 05:47:36 +01:00
|
|
|
}
|
|
|
|
}
|
2017-12-28 11:40:40 +01:00
|
|
|
|
|
|
|
return t;
|
2017-11-01 05:47:36 +01:00
|
|
|
}
|
2011-05-21 15:02:19 +02:00
|
|
|
|
2011-07-07 14:34:30 +02:00
|
|
|
int linear(Projectile *p, int t) { // sure is physics in here; a[0]: velocity
|
|
|
|
if(t < 0)
|
|
|
|
return 1;
|
2011-05-06 17:09:43 +02:00
|
|
|
p->angle = carg(p->args[0]);
|
|
|
|
p->pos = p->pos0 + p->args[0]*t;
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2011-05-13 19:03:02 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-06-27 13:36:35 +02:00
|
|
|
int accelerated(Projectile *p, int t) {
|
2011-07-07 14:34:30 +02:00
|
|
|
if(t < 0)
|
|
|
|
return 1;
|
2012-07-31 14:34:20 +02:00
|
|
|
p->angle = carg(p->args[0]);
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2012-07-31 14:34:20 +02:00
|
|
|
p->pos += p->args[0];
|
|
|
|
p->args[0] += p->args[1];
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2011-06-27 13:36:35 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-06-28 19:23:02 +02:00
|
|
|
int asymptotic(Projectile *p, int t) { // v = a[0]*(a[1] + 1); a[1] -> 0
|
2011-07-07 14:34:30 +02:00
|
|
|
if(t < 0)
|
|
|
|
return 1;
|
2011-08-27 15:56:02 +02:00
|
|
|
p->angle = carg(p->args[0]);
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2011-06-28 19:23:02 +02:00
|
|
|
p->args[1] *= 0.8;
|
|
|
|
p->pos += p->args[0]*(p->args[1] + 1);
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2011-06-28 19:23:02 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-11-10 21:49:16 +01:00
|
|
|
static inline void apply_common_transforms(Projectile *proj, int t) {
|
2011-05-13 19:03:02 +02:00
|
|
|
glTranslatef(creal(proj->pos), cimag(proj->pos), 0);
|
|
|
|
glRotatef(proj->angle*180/M_PI+90, 0, 0, 1);
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2017-11-10 21:49:16 +01:00
|
|
|
if(t >= 16) {
|
|
|
|
return;
|
2012-04-06 15:54:30 +02:00
|
|
|
}
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2017-11-10 21:49:16 +01:00
|
|
|
if(proj->flags & PFLAG_NOSPAWNZOOM) {
|
|
|
|
return;
|
|
|
|
}
|
2017-04-20 18:37:46 +02:00
|
|
|
|
2017-11-10 21:49:16 +01:00
|
|
|
if(proj->type != EnemyProj && proj->type != FakeProj) {
|
|
|
|
return;
|
|
|
|
}
|
2017-04-20 18:37:46 +02:00
|
|
|
|
2017-11-10 21:49:16 +01:00
|
|
|
float s = 2.0-t/16.0;
|
|
|
|
if(s != 1) {
|
|
|
|
glScalef(s, s, 1);
|
|
|
|
}
|
2012-07-18 23:12:31 +02:00
|
|
|
}
|
|
|
|
|
2017-11-10 21:49:16 +01:00
|
|
|
static inline void apply_color(Projectile *proj, Color c) {
|
|
|
|
static ColorTransform ct;
|
2017-11-21 10:26:11 +01:00
|
|
|
proj->color_transform_rule(proj, global.frames - proj->birthtime, c, &ct);
|
2017-11-10 21:49:16 +01:00
|
|
|
recolor_apply_transform(&ct);
|
2012-07-25 15:32:37 +02:00
|
|
|
}
|
|
|
|
|
2017-11-10 21:49:16 +01:00
|
|
|
void ProjDrawCore(Projectile *proj, Color c) {
|
|
|
|
apply_color(proj, c);
|
2011-06-29 17:01:03 +02:00
|
|
|
|
2017-11-10 21:49:16 +01:00
|
|
|
if(proj->flags & PFLAG_DRAWADD) {
|
|
|
|
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
|
|
|
|
draw_texture_p(0, 0, proj->tex);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
} else if(proj->flags & PFLAG_DRAWSUB) {
|
|
|
|
glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
|
|
|
|
draw_texture_p(0, 0, proj->tex);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
glBlendEquation(GL_FUNC_ADD);
|
|
|
|
} else {
|
|
|
|
draw_texture_p(0, 0, proj->tex);
|
2017-02-26 21:59:51 +01:00
|
|
|
}
|
2017-11-10 21:49:16 +01:00
|
|
|
}
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2017-11-10 21:49:16 +01:00
|
|
|
void ProjDraw(Projectile *proj, int t) {
|
|
|
|
glPushMatrix();
|
|
|
|
apply_common_transforms(proj, t);
|
|
|
|
ProjDrawCore(proj, proj->color);
|
2012-04-05 14:24:55 +02:00
|
|
|
glPopMatrix();
|
2011-06-29 17:01:03 +02:00
|
|
|
}
|
2011-11-02 20:00:14 +01:00
|
|
|
|
2017-10-18 01:53:42 +02:00
|
|
|
void ProjNoDraw(Projectile *proj, int t) {
|
|
|
|
}
|
|
|
|
|
2017-11-15 07:05:47 +01:00
|
|
|
int blast_timeout(Projectile *p, int t) {
|
2011-06-28 19:23:02 +02:00
|
|
|
if(t == 1) {
|
|
|
|
p->args[1] = frand()*360 + frand()*I;
|
|
|
|
p->args[2] = frand() + frand()*I;
|
|
|
|
}
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2017-11-15 07:05:47 +01:00
|
|
|
return timeout(p, t);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Blast(Projectile *p, int t) {
|
2011-06-28 19:23:02 +02:00
|
|
|
glPushMatrix();
|
2017-11-10 21:49:16 +01:00
|
|
|
glTranslatef(creal(p->pos), cimag(p->pos), 0);
|
2011-06-28 19:23:02 +02:00
|
|
|
glRotatef(creal(p->args[1]), cimag(p->args[1]), creal(p->args[2]), cimag(p->args[2]));
|
2017-11-10 21:49:16 +01:00
|
|
|
if(t != p->args[0] && p->args[0] != 0)
|
2012-04-05 14:24:55 +02:00
|
|
|
glScalef(t/p->args[0], t/p->args[0], 1);
|
2017-11-10 21:49:16 +01:00
|
|
|
|
|
|
|
apply_color(p, rgba(0.3, 0.6, 1.0, 1.0 - t/p->args[0]));
|
|
|
|
|
2017-03-21 11:59:31 +01:00
|
|
|
draw_texture_p(0,0,p->tex);
|
2017-03-21 09:22:10 +01:00
|
|
|
glScalef(0.5+creal(p->args[2]),0.5+creal(p->args[2]),1);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
|
2011-06-28 19:23:02 +02:00
|
|
|
draw_texture_p(0,0,p->tex);
|
2017-03-21 09:22:10 +01:00
|
|
|
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
2011-06-28 19:23:02 +02:00
|
|
|
glPopMatrix();
|
|
|
|
}
|
2017-02-10 23:05:22 +01:00
|
|
|
|
|
|
|
void Shrink(Projectile *p, int t) {
|
2011-05-13 19:03:02 +02:00
|
|
|
glPushMatrix();
|
2017-11-10 21:49:16 +01:00
|
|
|
apply_common_transforms(p, t);
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2017-11-10 21:49:16 +01:00
|
|
|
float s = 2.0-t/p->args[0]*2;
|
|
|
|
if(s != 1) {
|
2012-04-05 14:24:55 +02:00
|
|
|
glScalef(s, s, 1);
|
2017-11-10 21:49:16 +01:00
|
|
|
}
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2017-11-10 21:49:16 +01:00
|
|
|
ProjDrawCore(p, p->color);
|
2011-05-13 19:03:02 +02:00
|
|
|
glPopMatrix();
|
2011-05-21 15:02:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void DeathShrink(Projectile *p, int t) {
|
|
|
|
glPushMatrix();
|
2017-11-10 21:49:16 +01:00
|
|
|
apply_common_transforms(p, t);
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2017-11-10 21:49:16 +01:00
|
|
|
float s = 2.0-t/p->args[0]*2;
|
|
|
|
if(s != 1) {
|
2012-04-05 14:24:55 +02:00
|
|
|
glScalef(s, 1, 1);
|
2017-11-10 21:49:16 +01:00
|
|
|
}
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2017-11-10 21:49:16 +01:00
|
|
|
ProjDrawCore(p, p->color);
|
2011-05-21 15:02:19 +02:00
|
|
|
glPopMatrix();
|
2011-05-13 19:03:02 +02:00
|
|
|
}
|
|
|
|
|
2011-06-28 19:23:02 +02:00
|
|
|
void GrowFade(Projectile *p, int t) {
|
|
|
|
glPushMatrix();
|
2017-11-10 21:49:16 +01:00
|
|
|
apply_common_transforms(p, t);
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2012-08-18 01:49:59 +02:00
|
|
|
float s = t/p->args[0]*(1 + (creal(p->args[2])? p->args[2] : p->args[1]));
|
2017-11-10 21:49:16 +01:00
|
|
|
if(s != 1) {
|
2012-04-05 14:24:55 +02:00
|
|
|
glScalef(s, s, 1);
|
2017-11-10 21:49:16 +01:00
|
|
|
}
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2017-11-10 21:49:16 +01:00
|
|
|
ProjDrawCore(p, multiply_colors(p->color, rgba(1, 1, 1, 1 - t/p->args[0])));
|
2011-06-28 19:23:02 +02:00
|
|
|
glPopMatrix();
|
2017-02-10 23:05:22 +01:00
|
|
|
}
|
2011-06-28 19:23:02 +02:00
|
|
|
|
2011-05-13 19:03:02 +02:00
|
|
|
void Fade(Projectile *p, int t) {
|
2017-11-10 21:49:16 +01:00
|
|
|
glPushMatrix();
|
|
|
|
apply_common_transforms(p, t);
|
|
|
|
ProjDrawCore(p, multiply_colors(p->color, rgba(1, 1, 1, 1 - t/p->args[0])));
|
|
|
|
glPopMatrix();
|
2011-05-13 19:03:02 +02:00
|
|
|
}
|
|
|
|
|
2017-11-10 21:49:16 +01:00
|
|
|
void ScaleFade(Projectile *p, int t) {
|
2012-08-01 17:32:11 +02:00
|
|
|
glPushMatrix();
|
2017-11-10 21:49:16 +01:00
|
|
|
apply_common_transforms(p, t);
|
|
|
|
glScalef(creal(p->args[1]), creal(p->args[1]), 1);
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2017-11-10 21:49:16 +01:00
|
|
|
float a = (1.0 - t/creal(p->args[0])) * (1.0 - cimag(p->args[1]));
|
|
|
|
Color c = rgba(1, 1, 1, a);
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2017-11-10 21:49:16 +01:00
|
|
|
ProjDrawCore(p, c);
|
|
|
|
glPopMatrix();
|
2012-08-01 17:32:11 +02:00
|
|
|
}
|
|
|
|
|
2011-05-13 19:03:02 +02:00
|
|
|
int timeout(Projectile *p, int t) {
|
|
|
|
if(t >= creal(p->args[0]))
|
|
|
|
return ACTION_DESTROY;
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2011-05-13 19:03:02 +02:00
|
|
|
return 1;
|
2011-05-21 15:02:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int timeout_linear(Projectile *p, int t) {
|
|
|
|
if(t >= creal(p->args[0]))
|
|
|
|
return ACTION_DESTROY;
|
2011-07-07 14:34:30 +02:00
|
|
|
if(t < 0)
|
|
|
|
return 1;
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2011-05-21 15:02:19 +02:00
|
|
|
p->angle = carg(p->args[1]);
|
|
|
|
p->pos = p->pos0 + p->args[1]*t;
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2011-06-26 16:10:13 +02:00
|
|
|
return 1;
|
2011-08-28 10:57:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Petal(Projectile *p, int t) {
|
|
|
|
float x = creal(p->args[2]);
|
|
|
|
float y = cimag(p->args[2]);
|
|
|
|
float z = creal(p->args[3]);
|
2017-02-10 23:05:22 +01:00
|
|
|
|
2017-03-24 14:53:57 +01:00
|
|
|
float r = sqrt(x*x+y*y+z*z);
|
|
|
|
x /= r; y /= r; z /= r;
|
|
|
|
|
2011-08-28 10:57:45 +02:00
|
|
|
glDisable(GL_CULL_FACE);
|
|
|
|
glPushMatrix();
|
2017-11-10 21:49:16 +01:00
|
|
|
glTranslatef(creal(p->pos), cimag(p->pos),0);
|
2011-08-28 10:57:45 +02:00
|
|
|
glRotatef(t*4.0 + cimag(p->args[3]), x, y, z);
|
2017-11-10 21:49:16 +01:00
|
|
|
ProjDrawCore(p, p->color);
|
2011-08-28 10:57:45 +02:00
|
|
|
glPopMatrix();
|
|
|
|
glEnable(GL_CULL_FACE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void petal_explosion(int n, complex pos) {
|
2017-11-21 10:26:11 +01:00
|
|
|
for(int i = 0; i < n; i++) {
|
2017-03-24 14:53:57 +01:00
|
|
|
tsrand_fill(6);
|
|
|
|
float t = frand();
|
|
|
|
Color c = rgba(sin(5*t),cos(5*t),0.5,t);
|
2017-11-10 21:49:16 +01:00
|
|
|
|
|
|
|
PARTICLE("petal", pos, c, asymptotic,
|
|
|
|
.draw_rule = Petal,
|
|
|
|
.args = {
|
|
|
|
(3+5*afrand(2))*cexp(I*M_PI*2*afrand(3)),
|
|
|
|
5,
|
2017-11-21 10:26:11 +01:00
|
|
|
afrand(4) + afrand(5)*I,
|
|
|
|
afrand(1) + 360.0*I*afrand(0),
|
2017-11-10 21:49:16 +01:00
|
|
|
},
|
|
|
|
.flags = PFLAG_DRAWADD,
|
2017-11-21 10:26:11 +01:00
|
|
|
.type = PlrProj, // hack: never reflect these in stage1 water (GL_CULL_FACE conflict)
|
2017-11-10 21:49:16 +01:00
|
|
|
);
|
2011-08-28 10:57:45 +02:00
|
|
|
}
|
2012-07-18 12:33:37 +02:00
|
|
|
}
|
2017-03-11 04:41:57 +01:00
|
|
|
|
|
|
|
void projectiles_preload(void) {
|
|
|
|
preload_resources(RES_TEXTURE, RESF_PERMANENT,
|
2017-03-20 07:38:07 +01:00
|
|
|
// XXX: maybe split this up into stage-specific preloads too?
|
|
|
|
// some of these are ubiquitous, but some only appear in very specific parts.
|
|
|
|
|
2017-03-11 04:41:57 +01:00
|
|
|
"part/blast",
|
|
|
|
"part/flare",
|
|
|
|
"part/lasercurve",
|
|
|
|
"part/petal",
|
|
|
|
"part/smoke",
|
|
|
|
"part/stain",
|
2017-03-20 07:38:07 +01:00
|
|
|
"part/lightning0",
|
|
|
|
"part/lightning1",
|
|
|
|
"part/lightningball",
|
2017-03-11 04:41:57 +01:00
|
|
|
"proj/ball",
|
|
|
|
"proj/bigball",
|
|
|
|
"proj/bullet",
|
|
|
|
"proj/card",
|
|
|
|
"proj/crystal",
|
|
|
|
"proj/flea",
|
|
|
|
"proj/hghost",
|
|
|
|
"proj/plainball",
|
|
|
|
"proj/rice",
|
|
|
|
"proj/soul",
|
|
|
|
"proj/thickrice",
|
|
|
|
"proj/wave",
|
|
|
|
"proj/youhoming",
|
|
|
|
NULL);
|
|
|
|
|
2017-09-30 20:11:10 +02:00
|
|
|
preload_resources(RES_SFX, RESF_PERMANENT,
|
|
|
|
"shot1",
|
2017-10-29 04:43:32 +01:00
|
|
|
"shot2",
|
2017-09-30 20:11:10 +02:00
|
|
|
"shot1_loop",
|
2017-10-22 21:11:15 +02:00
|
|
|
"shot_special1",
|
|
|
|
"redirect",
|
2017-09-30 20:11:10 +02:00
|
|
|
NULL);
|
2017-03-11 04:41:57 +01:00
|
|
|
}
|