From f28f4145cbf4986a909dba7ab570bc402dab7454 Mon Sep 17 00:00:00 2001 From: stian853 Date: Thu, 30 Nov 2023 14:45:29 +0100 Subject: [PATCH] =?utf8?q?cykel=20sinusv=C3=A5g,=20Arvid,=20Stina,=20Nils?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- assets/data.json | 7 ++++--- assets/highscore.csv | 8 +++----- src/Bike_enemy.cc | 10 +++++++--- src/Bike_enemy.h | 4 ++++ 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/assets/data.json b/assets/data.json index a1f1c49..9a1798c 100644 --- a/assets/data.json +++ b/assets/data.json @@ -29,7 +29,7 @@ "game_constants": { "bottles_per_second" : 1, - "game_time" : 20, + "game_time" : 60, "yf_per_second": 0.125, "bikes_per_second": 0.25, "scoreboard" : 5 @@ -62,8 +62,9 @@ { "scale" : [0.25, 0.25], "max_speed" : 5.0, - "direction": [0, 1] - + "direction": [0, 1], + "sin_amplitude": 50, + "sin_omega": 5 } } \ No newline at end of file diff --git a/assets/highscore.csv b/assets/highscore.csv index fb3da42..84f9f79 100644 --- a/assets/highscore.csv +++ b/assets/highscore.csv @@ -1,5 +1,3 @@ -Gorilla,14 -Gorilla,10 -Gorilla,9 -Gorilla,7 -Gorilla,6 +Gorilla,36 +Gorilla,27 +Gorilla,13 diff --git a/src/Bike_enemy.cc b/src/Bike_enemy.cc index aadcab7..ed20f0e 100644 --- a/src/Bike_enemy.cc +++ b/src/Bike_enemy.cc @@ -4,15 +4,17 @@ #include "Context.h" #include "States.h" #include +#include -Bike_enemy::Bike_enemy(sf::Texture& txtr, json& params) : max_speed{params["max_speed"]} +Bike_enemy::Bike_enemy(sf::Texture& txtr, json& params) : max_speed{params["max_speed"]}, elapsed_time{0}, start_x{0}, sin_amplitude{params["sin_amplitude"]}, sin_omega{params["sin_omega"]} { direction = {params["direction"][0], params["direction"][1]}; texture = txtr; sprite.setTexture(texture); //position = {500, 500}; - position ={rand()%(S_WIDTH*5/7 - S_WIDTH/5 +1) + S_WIDTH/5, 0}; //x-pixel WIDTH/5 - WIDTH*5/7 + start_x = rand()%(S_WIDTH*5/7 - S_WIDTH/5 +1) + S_WIDTH/5; + position ={start_x, 0}; //x-pixel WIDTH/5 - WIDTH*5/7 //sprite.setScale(params["scale"][0], params["scale"][1]); sprite.setScale(params["scale"][0],params["scale"][1]); sf::FloatRect gb {sprite.getGlobalBounds()}; @@ -27,8 +29,10 @@ void Bike_enemy::collision(Object &other) } void Bike_enemy::update(Context& context) { - Game_state* game = static_cast(context.current_state.get()); + //Game_state* game = static_cast(context.current_state.get()); + elapsed_time += context.time.asSeconds(); position += direction*max_speed; + position.x = start_x + (sin_amplitude * sin(sin_omega * elapsed_time)); sprite.setPosition(position); } void Bike_enemy::render(sf::RenderWindow &window) const diff --git a/src/Bike_enemy.h b/src/Bike_enemy.h index 838258d..58cc348 100644 --- a/src/Bike_enemy.h +++ b/src/Bike_enemy.h @@ -20,6 +20,10 @@ public: private: //void move(Time) override; float max_speed; + float elapsed_time; + float start_x; + float sin_amplitude; + float sin_omega; protected: -- 2.30.2