use new RNG api in boss.c, enemy.c, item.c

This commit is contained in:
Andrei Alexeyev 2019-11-29 09:38:45 +02:00
parent 3268a7ae04
commit dc8ecc0dc7
No known key found for this signature in database
GPG key ID: 363707CD4C7FE8A4
3 changed files with 25 additions and 22 deletions

View file

@ -638,7 +638,7 @@ static void spawn_particle_effects(Boss *boss) {
.timeout = 180,
.draw_rule = Shrink,
.args = { 0, add_ref(boss), },
.angle = M_PI * 2 * frand(),
.angle = rng_angle(),
);
}
@ -807,7 +807,7 @@ static void boss_rule_extra(Boss *boss, float alpha) {
if(alpha == 0) {
lt += 2;
alpha = 1 * frand();
alpha = rng_real();
}
for(int i = 0; i < cnt; ++i) {
@ -818,7 +818,7 @@ static void boss_rule_extra(Boss *boss, float alpha) {
float psina = psin(a);
PARTICLE(
.sprite = (frand() < v*0.3 || lt > 1) ? "stain" : "arc",
.sprite = (rng_chance(v * 0.3) || lt > 1) ? "stain" : "arc",
.pos = boss->pos + dir * (100 + 50 * psin(alpha*global.frames/10.0+2*i)) * alpha,
.color = color_mul_scalar(RGBA(
1.0 - 0.5 * psina * v,
@ -1120,7 +1120,7 @@ void process_boss(Boss **pboss) {
if(boss_is_dying(boss)) {
float t = (global.frames - boss->current->endtime)/(float)BOSS_DEATH_DELAY + 1;
tsrand_fill(6);
RNG_ARRAY(rng, 6);
Color *clr = RGBA_MUL_ALPHA(0.1 + sin(10*t), 0.1 + cos(10*t), 0.5, t);
clr->a = 0;
@ -1132,10 +1132,10 @@ void process_boss(Boss **pboss) {
.draw_rule = Petal,
.color = clr,
.args = {
sign(anfrand(5))*(3+t*5*afrand(0))*cexp(I*M_PI*8*t),
vrng_sign(rng[5]) * (3 + t * 5 * vrng_real(rng[0])) * cdir(M_PI*8*t),
5+I,
afrand(2) + afrand(3)*I,
afrand(4) + 360.0*I*afrand(1)
vrng_real(rng[2]) + vrng_real(rng[3])*I,
vrng_real(rng[4]) + 360.0*I*vrng_real(rng[1])
},
.layer = LAYER_PARTICLE_PETAL,
.flags = PFLAG_REQUIREDPARTICLE,
@ -1155,14 +1155,14 @@ void process_boss(Boss **pboss) {
}
for(int i = 0; i < 256; i++) {
tsrand_fill(3);
RNG_ARRAY(rng, 3);
PARTICLE(
.sprite = "flare",
.pos = boss->pos,
.timeout = 60 + 10 * afrand(2),
.timeout = vrng_range(rng[2], 60, 70),
.rule = linear,
.draw_rule = Fade,
.args = { (3+afrand(0)*10)*cexp(I*tsrand_a(1)) },
.args = { vrng_range(rng[0], 3, 13) * vrng_dir(rng[1]) },
);
}
@ -1353,16 +1353,16 @@ void boss_start_attack(Boss *b, Attack *a) {
play_sound(a->type == AT_ExtraSpell ? "charge_extra" : "charge_generic");
for(int i = 0; i < 10+5*(a->type == AT_ExtraSpell); i++) {
tsrand_fill(4);
RNG_ARRAY(rng, 4);
PARTICLE(
.sprite = "stain",
.pos = VIEWPORT_W/2 + VIEWPORT_W/4*anfrand(0)+I*VIEWPORT_H/2+I*anfrand(1)*30,
.pos = CMPLX(VIEWPORT_W/2 + vrng_sreal(rng[0]) * VIEWPORT_W/4, VIEWPORT_H/2 + vrng_sreal(rng[1]) * 30),
.color = RGBA(0.2, 0.3, 0.4, 0.0),
.rule = linear,
.timeout = 50,
.draw_rule = GrowFade,
.args = { sign(anfrand(2))*10*(1+afrand(3)) },
.args = { vrng_sign(rng[2]) * 10 * vrng_range(rng[3], 1, 4) },
);
}
}

View file

@ -122,15 +122,14 @@ static void* _delete_enemy(ListAnchor *enemies, List* enemy, void *arg) {
play_sound("enemydeath");
for(int i = 0; i < 10; i++) {
tsrand_fill(2);
RNG_ARRAY(rng, 2);
PARTICLE(
.sprite = "flare",
.pos = e->pos,
.timeout = 10,
.rule = linear,
.draw_rule = Fade,
.args = { (3+afrand(0)*10)*cexp(I*afrand(1)*2*M_PI) },
.args = { vrng_range(rng[0], 3, 13) * vrng_dir(rng[1]) },
);
}
@ -235,7 +234,8 @@ int enemy_flare(Projectile *p, int t) { // a[0] velocity, a[1] ref to enemy
void BigFairy(Enemy *e, int t, bool render) {
if(!render) {
if(!(t % 5)) {
cmplx offset = (frand()-0.5)*30 + (frand()-0.5)*20.0*I;
cmplx offset = rng_sreal() * 15;
offset += rng_sreal() * 10 * I;
PARTICLE(
.sprite = "smoothdot",

View file

@ -142,7 +142,7 @@ Item *create_clear_item(cmplx pos, uint clear_flags) {
type = ITEM_VOLTAGE;
}
Item *i = create_item(pos, -10*I + 5*nfrand(), type);
Item *i = create_item(pos, -10*I + 5*rng_sreal(), type);
if(i) {
PARTICLE(
@ -251,7 +251,7 @@ void process_items(void) {
if(collect_item(item, 1)) {
item->pos0 = item->pos;
item->birthtime = global.frames;
item->v = -20*I + 10*nfrand();
item->v = -20*I + 10*rng_sreal();
}
}
@ -276,7 +276,7 @@ void process_items(void) {
item->auto_collect = 0;
item->pos0 = item->pos;
item->birthtime = global.frames;
item->v = -10*I + 5*nfrand();
item->v = -10*I + 5*rng_sreal();
}
}
@ -347,8 +347,11 @@ int collision_item(Item *i) {
}
static void spawn_item_internal(cmplx pos, ItemType type, float collect_value) {
tsrand_fill(2);
Item *i = create_item(pos, (12 + 6 * afrand(0)) * (cexp(I*(3*M_PI/2 + anfrand(1)*M_PI/11))) - 3*I, type);
cmplx v = rng_range(12, 18);
v *= cdir(3*M_PI/2 + rng_sreal() * M_PI/11);
v -= 3*I;
Item *i = create_item(pos, v, type);
if(i != NULL && collect_value >= 0) {
collect_item(i, collect_value);