$(CC) $(LDFLAGS) $^ -o $(TEST) $(LDFLAGS)
$(OBJDIR)/%.o: %.cc $(SRC_H)
- $(CC) $(CCFLAGS) -c -o $@ $<
+ $(CC) $(CCFLAGS) $(LDFLAGS) -c -o $@ $<
run:
./$(EXE)
{
"start_pos": [200, 200],
"scale": [0.5, 0.5],
- "max_speed": 5
+ "max_speed": 5,
+ "sack" :
+ {
+ "offset" : [30, 18],
+ "scale" : [0.3, 0.3],
+ "angle" : -25
+ }
+
},
"helper": {
"start_pos": [1000, 50],
},
"game_constants":
{
- "bottles_per_second" : 2
+ "bottles_per_second" : 2,
+ "game_time" : 20
+
},
"map":
{
- "points_pos": [100, 100],
- "font_size": 24
+ "points_pos": [5, 0],
+ "font_size": 40
},
"main_enemy":
{
- "scale" : [0.35, 0.35]
+ "scale" : [0.35, 0.35],
+ "start_pos" : [50, 600]
}
-
}
\ No newline at end of file
//texture.loadFromFile("assets/6Ling_figur2.png");
texture = txtr;
sprite.setTexture(texture);
-
+ position = {params["start_pos"][0], params["start_pos"][1]};
sprite.setScale(params["scale"][0], params["scale"][1]);
sf::FloatRect gb {sprite.getGlobalBounds()};
sprite.setOrigin(gb.width / 2, gb.height / 2);
if ( !font.loadFromFile ("assets/fonts/Philosopher-Regular.ttf") )
throw std::invalid_argument ("Unable to load font");
- point_text = sf::Text{"Points: 0", font, params["font_size"] };
+ point_text = sf::Text{"Points: 0", font, params["font_size"]};
sf::FloatRect gbts {point_text.getGlobalBounds()};
- point_text.setOrigin(gbts.width / 2, gbts.height / 2);
point_text.setPosition (params["points_pos"][0], params["points_pos"][1]);
- point_text.setFillColor(sf::Color::Red);
+ point_text.setFillColor(sf::Color::Black);
+
}
-void Map::update(int points)
+void Map::update(int const points, int const game_time)
{
- point_text.setString("Points: " + std::to_string(points));
+ point_text.setString("Points: " + std::to_string(points) + "\n" + "Time left: " + std::to_string(game_time) + " s");
}
void Map::render(sf::RenderWindow& window) const
Map(json& params);
~Map() = default;
- void update(int points);
+ void update(int const points, int const game_state);
void render(sf::RenderWindow& window) const;
protected:
private:
sack_texture.loadFromFile("assets/sack.png");
sack.setTexture(sack_texture);
- sack.setScale(0.5, 0.5);
+ sack.setScale(params["sack"]["scale"][0], params["sack"]["scale"][1]);
sf::FloatRect gb_s {sack.getGlobalBounds()};
- sack.setOrigin(gb_s.width / 2, gb_s.height / 2);
- sack_offset = {gb.width/4, -gb.height/15};
+ sack.setOrigin(gb_s.width / 3, gb_s.height / 5);
+ sack_offset = {params["sack"]["offset"][0], params["sack"]["offset"][1]};
+ sack.rotate(params["sack"]["angle"]);
sack.setPosition(position + sack_offset);
}
#include "json.hpp"
#include <fstream>
+#include <cmath>
using json = nlohmann::json;
helper{},
main_enemy_texture{},
time_since_last_bottle{0.0f},
+ game_time{0},
bottle_texture {},
data{},
enemy{},
pause_game = false;
return;
}
- // std::vector<Bottle> :: iterator it = bottles.begin();
-
- /*for(std::unique_ptr<Bottle> &b: bottles)
+
+ game_time += context.time.asSeconds();
+ int remaining_time {static_cast<int>(data["game_constants"]["game_time"]) - static_cast<int>(game_time)};
+ if (remaining_time < 0)
{
- if(player.collides(*b))
- {
- std::cout <<"crash" << std::endl;
+ context.next_state = std::make_unique<Start_menu>();
+ return;
+ }
+
- player.add_collected();
- }
- }*/
for (unsigned int i {0}; i < bottles.size(); ++i)
{
if (player->collides(*(bottles[i])))
}
}
- helper->update(context);
player->update(context);
+ helper->update(context);
+
if (player->collides(*helper))
{
points += player->get_collected();
player->collision(*helper);
helper->collision(*player);
}
+ /*
+ if (player->get_x() < 0) player->set_x(0);
+ if (player->get_x() > S_WIDTH) player->set_x(S_WIDTH);
+ if (player->get_y() < 0) player->set_y(0);
+ if (player->get_y() > S_HEIGHT) player->set_y(S_HEIGHT);
+ */
-
time_since_last_bottle += context.time.asSeconds();
+
//std::cout << std::fixed << std::setprecision(3) << time_since_last_bottle << std::endl;
if (time_since_last_bottle >= data["game_constants"]["bottles_per_second"])
{
std::cout << "placed bottle"<< std::endl;
time_since_last_bottle = 0;
}
- game_map->update(points);
+ //game time
enemy->update(context);
+ game_map->update(points, remaining_time);
+
}
void Game_state::render(sf::RenderWindow &window) const
protected:
private:
float time_since_last_bottle;
+ float game_time;
std::unique_ptr<Map> game_map;
std::unique_ptr<Player> player;