From 1c97641366e37ea02a639b47f3f3e84d3e62efe7 Mon Sep 17 00:00:00 2001 From: David Olofson Date: Tue, 17 Jan 2017 03:02:25 +0100 Subject: [PATCH] Updated "charged fire" secondary player weapon The secondary weapon now fires all bolts from right in front of the ship, just like the primary nose gun. Instead, the bolts are spread over an arrow shaped "front," and the're spread by means of different velocities instead. This prevents firing through base pipes. The charged bolts now travel slower than the primary weapon as well, which feels more interesting and "motivated" from a gameplay point of view. Closes #319. --- src/myship.cpp | 17 ++++++++++------- src/myship.h | 3 ++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/myship.cpp b/src/myship.cpp index 43b4e5f..3fd56e7 100644 --- a/src/myship.cpp +++ b/src/myship.cpp @@ -655,7 +655,7 @@ void KOBO_myship::render() } -void KOBO_myship::shot_single(float dir, int loffset, int hoffset) +void KOBO_myship::shot_single(float dir, int loffset, int hoffset, int speed) { int i; for(i = 0; i < MAX_BOLTS && bolts[i].state; i++) @@ -671,8 +671,9 @@ void KOBO_myship::shot_single(float dir, int loffset, int hoffset) int cdi = cos(M_PI * (dir - 1) / 4) * 256.0f; bolts[i].x = x - vx + loffset * sdi + hoffset * cdi; bolts[i].y = y - vy - loffset * cdi + hoffset * sdi; - bolts[i].dx = vx + game.bolt_speed * sdi; - bolts[i].dy = vy - game.bolt_speed * cdi; + int sp = game.bolt_speed * speed; + bolts[i].dx = vx + sp * sdi >> 16; + bolts[i].dy = vy - sp * cdi >> 16; if(!bolts[i].object) bolts[i].object = gengine->get_obj(LAYER_PLAYER); if(bolts[i].object) @@ -708,15 +709,17 @@ void KOBO_myship::charged_fire(int dir) } int power = _charge > game.charge_max ? game.charge_max : _charge; + int maxbolts = game.charge_max / game.charge_drain; sound.g_player_charged_fire((float)power / game.charge_max); - while(power >= game.charge_drain) + for(int b = 0; power >= game.charge_drain; ++b) { power -= game.charge_drain; _charge -= game.charge_drain; float spread = gamerand.get(16) * (8.0f / 65536.0f) - 4.0f; - spread *= game.charge_spread * (1.0f / 360.0f), - shot_single(dir + spread, 15 + power / game.charge_drain, - gamerand.get(3) - 4); + spread *= game.charge_spread * (1.0f / 360.0f); + int cx = gamerand.get(3) - 4; + shot_single(dir + spread, GUN_NOSE_Y - labs(cx), cx, + (b + maxbolts * 2) * 16384 / maxbolts); } charge_cool = game.charge_cooldown; } diff --git a/src/myship.h b/src/myship.h index fa14b4d..0538ad7 100644 --- a/src/myship.h +++ b/src/myship.h @@ -68,7 +68,8 @@ class KOBO_myship // For the gfxengine connection static cs_obj_t *object; - static void shot_single(float dir, int loffset, int hoffset); + static void shot_single(float dir, int loffset, int hoffset, + int speed = 65536); static void charged_fire(int dir); static void apply_position(); static void explode();