This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Pawn.hpp" // Klasa przeciwnika dziedziczy po pionku. Dodajemy go. | |
/* Tworzymy klase pionka podobnie jak klase gracza | |
z ta roznica, ze jej kontroler poki co nic nie bedzie robil. | |
Zachowaniem wroga zajmiemy sie pozniej. | |
*/ | |
class CEnemy | |
: public IPawn | |
{ | |
sf::Sprite m_sprite; // Tworzymy sprajta do wyswietlania wroga |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "..\Include\Player.hpp" | |
#include "..\Include\Game.hpp" // Potrzebujemy klasy gry bo w niej znajduje sie okno, na ktorym bedziemy wyswietlac gracza. | |
#include "..\Include\TextureManager.hpp" // Potrzebujemy texture menedzera by dostac teksture | |
//////////////////////////////////////////////////////// | |
CPlayer::CPlayer() // Konstruktor klasy | |
: IPawn(new CPlayerController) // klasa bazowa IPawn pobiera wskaznik na kontroler, ktory sami musimy sobie utworzyc. | |
{ | |
/* Tutaj przeprowadzimy sobie konfiguracje naszego gracza. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Pawn.hpp" // Klasa dziedziczy po pionku, wiec pamietamy by dodac plik naglowkowy | |
// Klasa gracza | |
class CPlayer | |
: public IPawn | |
{ | |
sf::Sprite m_sprite; // Potrzebujemy sprita by wyswietlac naszego gracza | |
public: | |
CPlayer(); // Konstruktor |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CPlayer | |
: public IPawn | |
{ | |
sf::Sprite m_sprite; | |
public: | |
CPlayer(); | |
virtual void SetLocation(const grim::Vector2 &location) override; | |
virtual void Draw() override; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void CGame::Run() // Glowny kod gry. | |
{ | |
/* Pamiętamy żeby ustawić odpowiedni status aplikacji. */ | |
m_status = Status::Running; | |
/* Ciemnoszary kolor. */ | |
sf::Color bgColor(30, 30, 30); | |
/* By prawidłowo uaktualniać scenę potrzebujemy czasu klatki. */ | |
sf::Clock GameClock; | |
/* W DeltaTime przechowujemy czas klatki. */ | |
float DeltaTime = 1 / 60.f; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sf::Clock GameClock; | |
// Pierwszy pomiar zostanie zakonczony dopiero na koncu pierwszej klatki. | |
// Na początku zakładamy, że czas klatki to idealnie 1 / 60 sekundy (60 FPS) | |
float DeltaTime = 1 / 60.f; | |
while(...) | |
{ | |
float frameStartTime = GameClock.getElapsedTime().asSeconds(); | |
// Kod pętli głównej... | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CLevel::CLevel() | |
{ | |
} | |
//////////////////////////////////////////////////////////////// | |
CLevel::~CLevel() | |
{ | |
/* Przy niszczeniu sceny niszczymy także aktorów. */ | |
this->Cleanup(); | |
} | |
//////////////////////////////////////////////////////////////// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CLevel final | |
{ | |
public: | |
/* Ułatwmy sobie życie typedefem. */ | |
typedef std::vector<IActor *> TActorsV; | |
/* Konstruktor klasy poziomu. | |
*/ | |
CLevel(); | |
/* Destruktor klasy poziomu. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IPawn::IPawn(IPawnController * controller) | |
: m_controller(nullptr) | |
{ | |
if (controller && controller->Possess(this)) | |
{ | |
m_controller = controller; | |
} | |
} | |
///////////////////////////////////////////////////////////////////////// | |
IPawn::~IPawn() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///////////////////////////////////////////////////////////////////////// | |
IPawnController::IPawnController() | |
: m_owner(nullptr) | |
{ | |
} | |
///////////////////////////////////////////////////////////////////////// | |
IPawnController::~IPawnController() | |
{ | |
} |