+#include "Bottle.h"
+#include "constants.h"
+#include "Context.h"
+#include <random>
+
+Bottle::Bottle()
+{
+ texture.loadFromFile("assets/kir.png");
+ sprite.setTexture(texture);
+ position ={rand()%(S_WIDTH*5/7 - S_WIDTH/5 +1) + S_WIDTH/5, rand()%S_HEIGHT+1}; //x-pixel WIDTH/5 - WIDTH*5/7
+ sprite.setScale(S_SCALE_KOEFF, S_SCALE_KOEFF);
+ sf::FloatRect gb {sprite.getGlobalBounds()};
+ sprite.setOrigin(gb.width / 2, gb.height / 2);
+ sprite.setPosition(position);
+}
+bool Bottle::collides(Object& other)
+{
+
+}
+void Bottle::collision(Object& other)
+{
+
+}
+void Bottle::update(Context& context)
+{
+
+}
+
+void Bottle::render(sf::RenderWindow& window) const
+{
+ window.draw(sprite);
+}
\ No newline at end of file
-#include "Static_object.h"
-#include <SFML/Graphics.hpp>
-
-
#ifndef BOTTLE_H
#define BOTTLE_H
+#include "Static_object.h"
+#include <SFML/Graphics.hpp>
-class Bottle : Static_object
+class Bottle : public Static_object
{
- public:
- Object();
- ~Object();
-
- bool collides(Object& other) override;
- void collision(Object& other) override;
- void update() override;
- void render(sf::RenderWindow& window) override;
- private:
+public:
+ Bottle();
+
+
+ bool collides(Object& other) override;
+ void collision(Object& other) override;
+ void update(Context& context) override;
+ void render(sf::RenderWindow& window) const override;
+private:
};
#define CONTEXT_H
#include "States.h"
+#include <SFML/Graphics.hpp>
struct Context
{
std::unique_ptr<State> current_state {nullptr};
std::unique_ptr<State> next_state {nullptr};
std::unique_ptr<Game_state> saved_game {nullptr};
+ sf::Int32 time;
};
#endif
\ No newline at end of file
-#ifndef MOVING_OBJECTS_H
-#define MOVING_OBJECTS_H
+#ifndef MOVING_OBJECT_H
+#define MOVING_OBJECT_H
#include "Object.h"
#include <memory>
-
+#include <iostream>
#include "States.h"
#include "Context.h"
#include "constants.h"
-Game_state::Game_state() : game_map{}, player{}, pause_game{false}
+Game_state::Game_state() : game_map{}, player{}, pause_game{false}, bottles{}
{
+ Bottle* bottle = new Bottle {};
+ bottles.push_back(bottle);
}
void Game_state::update(Context& context)
pause_game = false;
return;
}
+ time_since_last_bottle += context.time;
+ //std::cout << time_since_last_bottle << std::endl;
+ if (time_since_last_bottle >= 2)
+ {
+ Bottle* bottle = new Bottle {};
+ bottles.push_back(bottle);
+ std::cout << "placed bottle"<< std::endl;
+ time_since_last_bottle = 0;
+
+ }
game_map.update(context);
player.update(context);
}
{
game_map.render(window);
player.render(window);
+ for (int i {}; i < int(bottles.size()); ++i)
+ {
+ bottles[i]->render(window);
+ }
+
}
void Game_state::handle_input(sf::Event& event)
#define STATES_H
#include "SFML/Graphics.hpp"
+#include <vector>
#include "Map.h"
#include "Player.h"
+#include "Bottle.h"
struct Context; //finns en strukt som säger att Context finns innan den är deklarerad
void handle_input(sf::Event& event) override;
protected:
private:
+ float time_since_last_bottle {0};
+ std::vector<Bottle*> bottles;
Map game_map;
Player player;
bool pause_game;
#ifndef STATIC_OBJECT_H
#define STATIC_OBJECT_H
-#include <Object.h>
+#include "Object.h"
#include <SFML/Graphics.hpp>
-class Static_obejct : public Object
+class Static_object : public Object
{
public:
Static_object() = default;
- virtual ~Static_object() = default;
- virtual bool collides(Object &other) = 0;
- virtual void collision(Object &other) = 0;
- virtual void update() = 0;
- virtual void render(sf::RenderWindow &window) = 0;
+ ~Static_object() = default;
private:
};
game_context.current_state->handle_input(event);
}
+ //game_context.time = game_clock.getElapsedtime().asSeconds()
// Update startmeny
game_context.current_state->update(game_context);