From 68bf7b8acaaa3a41ae707eff27789eebe99aeb39 Mon Sep 17 00:00:00 2001 From: pojedah Date: Thu, 10 Jan 2019 18:59:13 +0500 Subject: [PATCH] 4x speed and additional controls: W and S. --- src/audio.c | 4 ++-- src/control.c | 16 +++++++--------- src/game.c | 18 ++++++++++++++---- src/game.h | 4 ++-- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/audio.c b/src/audio.c index a3f7824..dee4d6e 100644 --- a/src/audio.c +++ b/src/audio.c @@ -87,8 +87,8 @@ static void audio_mix(void *data, Uint8 *stream, int len) float both = audio_index_value(&audio->back, 0) + audio_index_value(&audio->hit, 0) + audio_index_value(&audio->crash, 0); - float left = audio_index_value(&audio->left, audio->ship->lefton); - float right = audio_index_value(&audio->right, audio->ship->righton); + float left = audio_index_value(&audio->left, audio->ship->lefton || audio->ship->upon || audio->ship->downon); + float right = audio_index_value(&audio->right, audio->ship->righton || audio->ship->upon || audio->ship->downon); buffer[i++] = audio_soft_clamp(right + both); buffer[i++] = audio_soft_clamp(left + both); diff --git a/src/control.c b/src/control.c index 94b8daa..98bfd17 100644 --- a/src/control.c +++ b/src/control.c @@ -106,17 +106,15 @@ static void control (Render* render, Audio* audio, Game* game, Input* input, Arg static void player_control (Ship* player, Input* input, int game_mode) { #define K(k) (input->pressed[SDLK_##k]) - bool up = K(DOWN) || K(UP) || K(w) || K(s);; + bool up = K(UP) || K(w); bool left = K(LEFT) || K(LSHIFT) || K(LCTRL) || K(a); bool right = K(RIGHT) || K(RSHIFT) || K(RCTRL) || K(d); - - if (game_mode == ONE_BUTTON) { - player->lefton = player->righton = left || up || right; - } - else { - player->lefton = left || (up && !right); - player->righton = right || (up && !left); - } + bool down = K(DOWN) || K(s); + + player->upon = up; + player->lefton = left; + player->righton = right; + player->downon = down; } static void args_init (Args* args, int argc, char* argv[]) diff --git a/src/game.c b/src/game.c index 3afb60f..e0862cd 100644 --- a/src/game.c +++ b/src/game.c @@ -162,7 +162,7 @@ static void ship_init (Ship* ship, float radius) ship->radius = radius; ship->dist = FLT_MAX; SET (ship->repulsion,0,1,0); - ship->lefton = ship->righton = false; + ship->lefton = ship->righton = ship->downon = ship->upon = false; } static void digger_init(Digger *digger, float radius) @@ -230,18 +230,28 @@ void ship_move (Ship* ship, float dt) { float acc = THRUST*dt; int roll = 0; - + + if(ship->upon) { + Vec3 up = { 0, acc*2.0, 0 }; + ADD(ship->vel, up); + } + if(ship->lefton) { - Vec3 leftup = { -acc, acc/2, 0 }; + Vec3 leftup = { -acc*2, acc/2.0, 0 }; ADD(ship->vel, leftup); roll--; } if(ship->righton) { - Vec3 rightup = { +acc, acc/2, 0 }; + Vec3 rightup = { +acc*2, acc/2.0, 0 }; ADD(ship->vel, rightup); roll++; } + + if(ship->downon) { + Vec3 down = { 0, -acc*2, 0 }; + ADD(ship->vel, down); + } ship->vel[1] -= GRAVITY*dt; diff --git a/src/game.h b/src/game.h index a852b07..7a24d69 100644 --- a/src/game.h +++ b/src/game.h @@ -35,7 +35,7 @@ typedef struct Ship_struct float radius; Vec3 pos, vel, lookAt; float roll; - bool lefton, righton; + bool lefton, righton, downon, upon; float dist; // distance to cave wall Vec3 repulsion; // normal to collision float start; @@ -113,7 +113,7 @@ extern const char* data_paths[]; #define GRAVITY 9.8 #define THRUST (GRAVITY*2) -#define VELOCITY 30.0 +#define VELOCITY 120.0 #define MAX_CAVE_RADIUS (SHIP_RADIUS*30) #define MIN_CAVE_RADIUS (SHIP_RADIUS*5)