cykel sinusvåg, Arvid, Stina, Nils
authorstian853 <stian853@tlvm-4-2-3.ad.liu.se>
Thu, 30 Nov 2023 13:45:29 +0000 (14:45 +0100)
committerstian853 <stian853@tlvm-4-2-3.ad.liu.se>
Thu, 30 Nov 2023 13:45:29 +0000 (14:45 +0100)
assets/data.json
assets/highscore.csv
src/Bike_enemy.cc
src/Bike_enemy.h

index a1f1c49df31887087d693d1eee3488b78d307657..9a1798c930f29484bba90658e9bdcde390f7b3ba 100644 (file)
@@ -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
index fb3da424f08d1c362a90fcbcfb153e441b06dfd2..84f9f79576e514b62dbe2e67f209a520b2ea71fc 100644 (file)
@@ -1,5 +1,3 @@
-Gorilla,14
-Gorilla,10
-Gorilla,9
-Gorilla,7
-Gorilla,6
+Gorilla,36
+Gorilla,27
+Gorilla,13
index aadcab7daa8ea11e0ac3115b1f68c84bee08f4b7..ed20f0e05a5826e35a233dba5e85f5f71823557b 100644 (file)
@@ -4,15 +4,17 @@
 #include "Context.h"
 #include "States.h"
 #include <random>
+#include <cmath>
 
 
-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<Game_state*>(context.current_state.get());
+    //Game_state* game = static_cast<Game_state*>(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
index 838258dc9b9959c56fa3a17197329997403ca107..58cc348a808e9af57231c0fc570e8d7b7b686cc6 100644 (file)
@@ -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: