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
// Deklaracja w pliku .hpp | |
// Metoda, ktorej uzyjemy do update-owania zmyslow | |
virtual void Update(const float &deltaTime) override; | |
// Definicja w pliku .cpp | |
void CEnemy::Update(const float & deltaTime) | |
{ | |
// Bardzo wazne! Wykonujemy tez to co wykonuje klasa bazowa! | |
IPawn::Update(deltaTime); |
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
//////////////////////////////////////////////// | |
IAISense::TQueryActors CSightSense::QueryActors(bool(*filterFunc)(IActor * const)) | |
{ | |
// W tej funkcji wykonujemy od nowa sprawdzenie jacy aktorzy sa w polu widzenia. | |
// Na poczatku musimy porzucic stare wyniki. | |
m_sensedActors.clear(); | |
// Bierzemy liste aktorow ze sceny. | |
auto actors = CGame::Instance().GetLevel()->GetActors(); |
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
//////////////////////////////////////////////// | |
bool CSightSense::SetSightDistance(const float & sightDistance) | |
{ | |
/* Musimy zapobiedz ustawieniu ujemnego zasiegu wzroku. */ | |
if (sightDistance > 0) | |
{ | |
m_sightDistance = sightDistance; | |
return true; | |
} | |
return false; |
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
CSightSense::CSightSense(IPawn &owner, const float &sightDistance, const float &sightAngle) | |
: IAISense(owner) | |
{ | |
/* Konstruktor po prostu ustawia poczatkowe wartosci. */ | |
SetSightDistance(sightDistance); | |
SetSightAngle(sightAngle); | |
} |
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
// Klasa zmyslu wzroku. | |
class CSightSense | |
: public IAISense | |
{ | |
/* Musimy ponizsze zmienne zrobic prywatne ze wzgledu na koniecznosc walidacji danych. | |
Nie chcemy przeciez, zeby zasieg wzroku byl ujemny albo by pole widzenia bylo wieksze niz 180 stopni. | |
*/ | |
float m_sightDistance; // Zasieg wzroku w pikselach. | |
/* Pole widzenia w stopniach. |
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/AISense.hpp" | |
//////////////////////////////////////////////// | |
IAISense::IAISense(IPawn &owner) | |
: m_owner(owner) | |
{ | |
} |
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 "Actor.hpp" // Klasa bedzie operowala na aktorach ze sceny. | |
#include "Pawn.hpp" // Potrzebna bedzie tez klasa pionka | |
// Klasa bazowa dla wszelkich zmyslow. | |
class IAISense | |
{ | |
protected: | |
IPawn &m_owner; // Wlasciciel tego konkretnego zmyslu. | |
public: | |
/* Jest to konstruktor klasy zmyslu. |
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; | |
auto player = new CPlayer(); | |
/* Btw. taki zapis to skrot od player->SetLocation(grim::Vector2(400,300)); | |
Kompilator powinien sie domyslic o co chodzi. | |
*/ |
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
// Konstruktor klasy CGame (Game.hpp) | |
// Tekstury beda dostepne do pobrania w linku na koncu artykulu. | |
CTextureManager::Load("Player_Stand_01", "Data/Textures/BlueMage/Mage_Stand_01.png"); | |
CTextureManager::Load("Enemy_Stand_01", "Data/Textures/OrangeMage/Mage_Stand_01.png"); |
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\Enemy.hpp" | |
#include "..\Include\Game.hpp" // Klasa gry potrzebna do wyswietlenia wroga. | |
#include "..\Include\TextureManager.hpp" // Klasa menedzera tekstur do ich pobrania. | |
//////////////////////////////////////////////////////// | |
CEnemy::CEnemy() | |
: IPawn(new CEnemyAIController) // Tak jak w klasie gracza wywolujemy konstruktor klasy bazowej z wlasnym kontrolerem AI. | |
{ | |
/* Aby zobaczyc pelne wytlumaczenie ponizszego kodu przejdz do kontruktora klasy CPlayer |