#include "Object.h"
-class Moving_object : Object
+class Moving_object : public Object
{
public:
protected:
class Object
{
public:
+ Object() : x_pos(0), y_pos(0), sprite(), texture() {};
+
virtual bool collides(Object& other) = 0;
virtual void collision(Object& other) = 0;
virtual void update() = 0;
virtual void render(sf::RenderWindow& window) = 0;
virtual ~Object() = default;
-private:
-protected:
+
double x_pos;
double y_pos;
sf::Sprite sprite;
+ sf::Texture texture;
+
+protected:
+private:
};
#endif
\ No newline at end of file
+#include "Player.h"
+
+Player::Player() : Object(), collected(0)
+{
+ texture.loadFromFile("assets/4V_figur.png");
+ sprite.setTexture(texture);
+
+ sprite.setScale(S_SCALE_KOEFF, S_SCALE_KOEFF);
+ sprite.setPosition(S_WIDTH / 2, S_HEIGHT / 2);
+}
+
+bool Player::collides(Object& other)
+{
+ return false;
+}
+
+void Player::collision(Object& other)
+{
+ return;
+}
+
+void Player::update()
+{
+ x_pos += 0.1;
+ sprite.setPosition((S_WIDTH / 2) + x_pos, S_HEIGHT / 2);
+ return;
+}
+
+void Player::render(sf::RenderWindow& window)
+{
+ window.draw(sprite);
+}
\ No newline at end of file
#include <SFML/Graphics.hpp>
+
#include "Moving_object.h"
#include "Object.h"
+#include "constants.h"
-class Player : Moving_object
+class Player : public Object
{
public:
Player();
- ~Player();
+ ~Player() = default;
bool collides(Object& other);
void collision(Object& other);
void update();
*/
#include <SFML/Graphics.hpp> // includes most things in SFML
-#include "Object.h"
+#include "constants.h"
-const unsigned int S_WIDTH {1280};
-const unsigned int S_HEIGHT {720};
-
-const double S_SCALE_KOEFF {S_WIDTH / 1920.0};
+#include "Player.h"
int main ()
{
"DespYrat"
};
+ Player test_player{};
sf::Texture t;
t.loadFromFile("assets/hel_bakgrund.png");
- sf::Sprite s(t);
+ sf::Sprite s;
+ s.setTexture(t);
s.setScale(S_SCALE_KOEFF, S_SCALE_KOEFF);
}
}
-
- /* rita ut */
+ /* rita ut */
window.clear(); // rensa skärmen
window.draw(s);
+ test_player.render(window);
+ test_player.update();
window.display(); // visa ändringarna
}
}
--- /dev/null
+#ifndef CONSTANTS_H
+#define CONSTANTS_H
+
+const unsigned int S_WIDTH {1280};
+const unsigned int S_HEIGHT {720};
+
+const double S_SCALE_KOEFF {S_WIDTH / 1920.0};
+
+#endif
\ No newline at end of file