"game_constants":
{
"bottles_per_second" : 1,
- "game_time" : 20,
+ "game_time" : 60,
"yf_per_second": 0.125,
"bikes_per_second": 0.25,
"scoreboard" : 5
{
"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
#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()};
}
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