From 1631d76a3023e93e88d2a6800af3e946850f053b Mon Sep 17 00:00:00 2001 From: aleksav013 Date: Fri, 21 May 2021 12:42:27 +0200 Subject: Adding enemies --- main.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 10 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 4614500..8f7227f 100644 --- a/main.cpp +++ b/main.cpp @@ -1,22 +1,48 @@ +#include +#include #include #include -class Player +#include +std::mt19937 rng(time(0)); +const int n=30; +class Entity { public: float x,y; sf::RectangleShape telo; - Player(); + Entity() {} + Entity(sf::Vector2f pozicija,sf::Vector2f velicina,sf::Color boja); }; -Player::Player() +Entity::Entity(sf::Vector2f pozicija, sf::Vector2f velicina,sf::Color boja) { - telo.setSize(sf::Vector2f(100.0f,100.0f)); + telo.setSize(velicina); + telo.setFillColor(boja); telo.setOrigin(sf::Vector2f(telo.getSize().x/2,telo.getSize().y/2)); - x=y=0; + x=pozicija.x; + y=pozicija.y; } +class Enemy:public Entity +{ + public: + Enemy():Entity() {} + Enemy(sf::Vector2f pozicija,sf::Vector2f velicina,sf::Color boja):Entity(pozicija,velicina,boja) {} +}; +class Player:public Entity +{ + int health; + public: + Player():Entity() {} + Player(sf::Vector2f pozicija,sf::Vector2f velicina,sf::Color boja):Entity(pozicija,velicina,boja) + { + health=100; + } +}; class Game { Player igrac; + Enemy neprijatelj[n]; sf::RenderWindow prozor; + int visina,sirina; public: Game(); void loop(); @@ -28,16 +54,23 @@ class Game Game::Game() { prozor.create(sf::VideoMode(512,512),"RPG igra"); + visina=prozor.getSize().y; + sirina=prozor.getSize().x; + prozor.setFramerateLimit(60); + + igrac = Player(sf::Vector2f((float)sirina/2,(float)visina/2),sf::Vector2f(100.0f,100.0f),sf::Color::White); + for(int i=0;i0) igrac.y-=dist; + if(sf::Keyboard::isKeyPressed(sf::Keyboard::A)&&igrac.x>0) igrac.x-=dist; + if(sf::Keyboard::isKeyPressed(sf::Keyboard::S)&&igrac.y