Now compiles with CLion+MinGW
This commit is contained in:
parent
6a31952257
commit
c4997823ed
1
.gitattributes
vendored
1
.gitattributes
vendored
|
@ -1 +0,0 @@
|
||||||
*.bmp filter=lfs diff=lfs merge=lfs -text
|
|
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -10,6 +10,11 @@
|
||||||
[Dd]ebug
|
[Dd]ebug
|
||||||
[Rr]elease
|
[Rr]elease
|
||||||
|
|
||||||
|
# CLion idea
|
||||||
|
.idea
|
||||||
|
cmake-build-debug
|
||||||
|
cmake-build-release
|
||||||
|
|
||||||
# CMake
|
# CMake
|
||||||
CMakeCache.txt
|
CMakeCache.txt
|
||||||
CMakeFiles
|
CMakeFiles
|
||||||
|
|
|
@ -1,14 +1,17 @@
|
||||||
cmake_minimum_required(VERSION 2.8.9)
|
cmake_minimum_required(VERSION 2.8.9)
|
||||||
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
|
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
|
||||||
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
|
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
|
||||||
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++")
|
||||||
|
|
||||||
project(dungeon)
|
project(dungeon)
|
||||||
|
|
||||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${dungeon_SOURCE_DIR}/cmake")
|
find_package(OpenGL REQUIRED)
|
||||||
|
|
||||||
find_package(SDL2 REQUIRED)
|
find_package(SDL2 REQUIRED)
|
||||||
include_directories(${SDL2_INCLUDE_DIR} "libs/glm")
|
include_directories(${OPENGL_INCLUDE_DIR} ${SDL2_INCLUDE_DIR} "libs/glm")
|
||||||
link_libraries(${SDL2_LIBRARY})
|
link_libraries(${OPENGL_LIBRARIES} ${SDL2_LIBRARY})
|
||||||
|
|
||||||
file(GLOB SOURCES "src/*.cpp" "src/*.c" "src/*.h")
|
file(GLOB SOURCES "src/*.cpp" "src/*.c" "src/*.h")
|
||||||
add_executable(dungeon ${SOURCES})
|
add_executable(dungeon ${SOURCES})
|
||||||
|
|
|
@ -14,7 +14,7 @@ BehaviourTreeStatus AttackEnemyNode::tick(BTTick * tick) {
|
||||||
auto actors = tick->target->map->GetActorList();
|
auto actors = tick->target->map->GetActorList();
|
||||||
std::vector<Actor*> visibleEnemies;
|
std::vector<Actor*> visibleEnemies;
|
||||||
|
|
||||||
for each (auto actor in *actors) {
|
for (auto actor : *actors) {
|
||||||
if (actor == tick->target) continue;
|
if (actor == tick->target) continue;
|
||||||
|
|
||||||
if (actor->isTypeOf(ACT_HERO) != ishero) {
|
if (actor->isTypeOf(ACT_HERO) != ishero) {
|
||||||
|
@ -31,7 +31,7 @@ BehaviourTreeStatus AttackEnemyNode::tick(BTTick * tick) {
|
||||||
|
|
||||||
Actor* closestActor = nullptr;
|
Actor* closestActor = nullptr;
|
||||||
float closestDist;
|
float closestDist;
|
||||||
for each (Actor* actor in visibleEnemies) {
|
for (Actor* actor : visibleEnemies) {
|
||||||
float dist = Pathfinder::distance(tick->target->getPosition(), actor->getPosition());
|
float dist = Pathfinder::distance(tick->target->getPosition(), actor->getPosition());
|
||||||
if (closestActor == nullptr ||
|
if (closestActor == nullptr ||
|
||||||
dist < closestDist) {
|
dist < closestDist) {
|
||||||
|
|
|
@ -10,7 +10,7 @@ BehaviourTreeNode::BehaviourTreeNode(BehaviourTreeNode* parent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
BehaviourTreeNode::~BehaviourTreeNode() {
|
BehaviourTreeNode::~BehaviourTreeNode() {
|
||||||
for each (BehaviourTreeNode* child in children) {
|
for (BehaviourTreeNode* child : children) {
|
||||||
delete child;
|
delete child;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ static inline void trim(string &s) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Config::Config(char* path) {
|
Config::Config(string path) {
|
||||||
this->path = path;
|
this->path = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,13 +99,13 @@ void Config::save() {
|
||||||
ofstream conf(path, ios::trunc);
|
ofstream conf(path, ios::trunc);
|
||||||
if (conf.is_open()) {
|
if (conf.is_open()) {
|
||||||
vector<string> vec;
|
vector<string> vec;
|
||||||
for each (auto it in ints) {
|
for (auto it : ints) {
|
||||||
vec.push_back(it.first + " = " + to_string(it.second));
|
vec.push_back(it.first + " = " + to_string(it.second));
|
||||||
}
|
}
|
||||||
for each (auto it in floats) {
|
for (auto it : floats) {
|
||||||
vec.push_back(it.first + " = " + to_string(it.second));
|
vec.push_back(it.first + " = " + to_string(it.second));
|
||||||
}
|
}
|
||||||
for each (auto it in bools) {
|
for (auto it : bools) {
|
||||||
string b;
|
string b;
|
||||||
if (it.second) {
|
if (it.second) {
|
||||||
b = "true";
|
b = "true";
|
||||||
|
@ -115,11 +115,11 @@ void Config::save() {
|
||||||
}
|
}
|
||||||
vec.push_back(it.first + " = " + b);
|
vec.push_back(it.first + " = " + b);
|
||||||
}
|
}
|
||||||
for each (auto it in strings) {
|
for (auto it : strings) {
|
||||||
vec.push_back(it.first + " = " + it.second);
|
vec.push_back(it.first + " = " + it.second);
|
||||||
}
|
}
|
||||||
sort(vec.begin(), vec.end());
|
sort(vec.begin(), vec.end());
|
||||||
for each (auto it in vec) {
|
for (auto it : vec) {
|
||||||
conf << it << "\n";
|
conf << it << "\n";
|
||||||
}
|
}
|
||||||
conf.close();
|
conf.close();
|
||||||
|
|
|
@ -3,13 +3,13 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
class Config {
|
class Config {
|
||||||
char* path;
|
std::string path;
|
||||||
std::map<std::string, std::string> strings;
|
std::map<std::string, std::string> strings;
|
||||||
std::map<std::string, float> floats;
|
std::map<std::string, float> floats;
|
||||||
std::map<std::string, int> ints;
|
std::map<std::string, int> ints;
|
||||||
std::map<std::string, bool> bools;
|
std::map<std::string, bool> bools;
|
||||||
public:
|
public:
|
||||||
Config(char* path);
|
Config(std::string path);
|
||||||
void load();
|
void load();
|
||||||
void save();
|
void save();
|
||||||
void deleteValue(std::string key);
|
void deleteValue(std::string key);
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <cstdlib>
|
||||||
#include "ExploreNode.h"
|
#include "ExploreNode.h"
|
||||||
#include "Pathfinder.h"
|
#include "Pathfinder.h"
|
||||||
#include "BehaviourTree.h"
|
#include "BehaviourTree.h"
|
||||||
|
@ -26,7 +27,7 @@ BehaviourTreeStatus ExploreNode::tick(BTTick * tick) {
|
||||||
std::vector<vec2i> neigh = map->getNeighbours(pos.x, pos.y);
|
std::vector<vec2i> neigh = map->getNeighbours(pos.x, pos.y);
|
||||||
std::vector<vec2i> options;
|
std::vector<vec2i> options;
|
||||||
float lowestval = 999999;
|
float lowestval = 999999;
|
||||||
for each (vec2i npos in neigh) {
|
for (vec2i npos : neigh) {
|
||||||
float val = dijkstra.getValue(npos.x, npos.y);
|
float val = dijkstra.getValue(npos.x, npos.y);
|
||||||
if (val < lowestval) {
|
if (val < lowestval) {
|
||||||
lowestval = val;
|
lowestval = val;
|
||||||
|
@ -41,7 +42,7 @@ BehaviourTreeStatus ExploreNode::tick(BTTick * tick) {
|
||||||
return BT_FAILED;
|
return BT_FAILED;
|
||||||
}
|
}
|
||||||
while (options.size() > 0) {
|
while (options.size() > 0) {
|
||||||
int i = rand() % options.size();
|
int i = std::rand() % options.size();
|
||||||
vec2i next = options[i];
|
vec2i next = options[i];
|
||||||
vec2i dp = next - pos;
|
vec2i dp = next - pos;
|
||||||
if (tick->target->Move(dp.x, dp.y)) {
|
if (tick->target->Move(dp.x, dp.y)) {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <cmath>
|
||||||
#include "FieldOfVision.h"
|
#include "FieldOfVision.h"
|
||||||
#include "Tilemap.h"
|
#include "Tilemap.h"
|
||||||
|
|
||||||
|
@ -18,7 +19,7 @@ namespace FOV {
|
||||||
|
|
||||||
void CastLight(Tilemap* map, Tilemap* vision, int visioncounter, int row, float start, float end, int xx, int xy, int yx, int yy, int startX, int startY, float radius) {
|
void CastLight(Tilemap* map, Tilemap* vision, int visioncounter, int row, float start, float end, int xx, int xy, int yx, int yy, int startX, int startY, float radius) {
|
||||||
float newStart = 0.0f;
|
float newStart = 0.0f;
|
||||||
if (start < end) {
|
if (start < end) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bool blocked = false;
|
bool blocked = false;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <cstdlib>
|
||||||
#include "FleeNode.h"
|
#include "FleeNode.h"
|
||||||
#include "Pathfinder.h"
|
#include "Pathfinder.h"
|
||||||
#include "BehaviourTree.h"
|
#include "BehaviourTree.h"
|
||||||
|
@ -16,7 +17,7 @@ BehaviourTreeStatus FleeNode::tick(BTTick * tick) {
|
||||||
std::vector<vec2i> enemyPos;
|
std::vector<vec2i> enemyPos;
|
||||||
bool ishero = tick->target->isTypeOf(ACT_HERO);
|
bool ishero = tick->target->isTypeOf(ACT_HERO);
|
||||||
auto actors = tick->target->map->GetActorList();
|
auto actors = tick->target->map->GetActorList();
|
||||||
for each (Actor* actor in *actors) {
|
for (Actor* actor : *actors) {
|
||||||
if (actor->isTypeOf(ACT_HERO) != ishero) {
|
if (actor->isTypeOf(ACT_HERO) != ishero) {
|
||||||
vec2i pos = actor->getPosition();
|
vec2i pos = actor->getPosition();
|
||||||
if (tick->target->CanSee(pos.x, pos.y)) {
|
if (tick->target->CanSee(pos.x, pos.y)) {
|
||||||
|
@ -48,7 +49,7 @@ BehaviourTreeStatus FleeNode::tick(BTTick * tick) {
|
||||||
std::vector<vec2i> neigh = map->getNeighbours(pos.x, pos.y);
|
std::vector<vec2i> neigh = map->getNeighbours(pos.x, pos.y);
|
||||||
std::vector<vec2i> options;
|
std::vector<vec2i> options;
|
||||||
float lowestval = 999999;
|
float lowestval = 999999;
|
||||||
for each (vec2i npos in neigh) {
|
for (vec2i npos : neigh) {
|
||||||
float val = dijkstra.getValue(npos.x, npos.y);
|
float val = dijkstra.getValue(npos.x, npos.y);
|
||||||
if (val < lowestval) {
|
if (val < lowestval) {
|
||||||
lowestval = val;
|
lowestval = val;
|
||||||
|
|
|
@ -140,7 +140,7 @@ void update(double dt) {
|
||||||
timer = 0;
|
timer = 0;
|
||||||
|
|
||||||
auto actors = tilemap->GetActorList();
|
auto actors = tilemap->GetActorList();
|
||||||
for each (Actor* var in *actors) {
|
for (Actor* var : *actors) {
|
||||||
var->Update();
|
var->Update();
|
||||||
}
|
}
|
||||||
for (int i = (int)actors->size() - 1; i >= 0; i--) {
|
for (int i = (int)actors->size() - 1; i >= 0; i--) {
|
||||||
|
@ -200,7 +200,7 @@ void draw(double alpha) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto actors = tilemap->GetActorList();
|
auto actors = tilemap->GetActorList();
|
||||||
for each (Actor* var in *actors) {
|
for (Actor* var : *actors) {
|
||||||
vec2i pos = var->getPosition();
|
vec2i pos = var->getPosition();
|
||||||
if (hero == nullptr || hero->CanSee(pos.x, pos.y)) {
|
if (hero == nullptr || hero->CanSee(pos.x, pos.y)) {
|
||||||
renderer->SetColor(0, 0, 0, 255);
|
renderer->SetColor(0, 0, 0, 255);
|
||||||
|
|
|
@ -13,7 +13,7 @@ BehaviourTreeStatus HealFriendNode::tick(BTTick * tick) {
|
||||||
|
|
||||||
auto actors = tick->target->map->GetActorList();
|
auto actors = tick->target->map->GetActorList();
|
||||||
std::vector<Actor*> friends;
|
std::vector<Actor*> friends;
|
||||||
for each (auto actor in *actors) {
|
for (auto actor : *actors) {
|
||||||
if (actor == tick->target) continue;
|
if (actor == tick->target) continue;
|
||||||
|
|
||||||
if (actor->isTypeOf(ACT_HERO) == ishero && actor->health < actor->maxhealth-1) {
|
if (actor->isTypeOf(ACT_HERO) == ishero && actor->health < actor->maxhealth-1) {
|
||||||
|
@ -30,7 +30,7 @@ BehaviourTreeStatus HealFriendNode::tick(BTTick * tick) {
|
||||||
|
|
||||||
Actor* lowestHpActor = nullptr;
|
Actor* lowestHpActor = nullptr;
|
||||||
int lowestHp;
|
int lowestHp;
|
||||||
for each (Actor* actor in friends) {
|
for (Actor* actor : friends) {
|
||||||
if (lowestHpActor == nullptr || actor->health < lowestHp) {
|
if (lowestHpActor == nullptr || actor->health < lowestHp) {
|
||||||
lowestHpActor = actor;
|
lowestHpActor = actor;
|
||||||
lowestHp = actor->health;
|
lowestHp = actor->health;
|
||||||
|
|
|
@ -15,7 +15,7 @@ BehaviourTreeStatus IfNotSeeEnemyNode::tick(BTTick * tick) {
|
||||||
bool ishero = tick->target->isTypeOf(ACT_HERO);
|
bool ishero = tick->target->isTypeOf(ACT_HERO);
|
||||||
|
|
||||||
auto actors = tick->target->map->GetActorList();
|
auto actors = tick->target->map->GetActorList();
|
||||||
for each (auto actor in *actors) {
|
for (auto actor : *actors) {
|
||||||
if (actor == tick->target) continue;
|
if (actor == tick->target) continue;
|
||||||
|
|
||||||
if (actor->isTypeOf(ACT_HERO) != ishero) {
|
if (actor->isTypeOf(ACT_HERO) != ishero) {
|
||||||
|
|
|
@ -15,7 +15,7 @@ BehaviourTreeStatus IfSeeEnemyNode::tick(BTTick * tick) {
|
||||||
bool ishero = tick->target->isTypeOf(ACT_HERO);
|
bool ishero = tick->target->isTypeOf(ACT_HERO);
|
||||||
|
|
||||||
auto actors = tick->target->map->GetActorList();
|
auto actors = tick->target->map->GetActorList();
|
||||||
for each (auto actor in *actors) {
|
for (auto actor : *actors) {
|
||||||
if (actor == tick->target) continue;
|
if (actor == tick->target) continue;
|
||||||
|
|
||||||
if (actor->isTypeOf(ACT_HERO) != ishero) {
|
if (actor->isTypeOf(ACT_HERO) != ishero) {
|
||||||
|
|
|
@ -16,7 +16,7 @@ BehaviourTreeStatus IfSeeFriendNode::tick(BTTick * tick) {
|
||||||
bool ishero = tick->target->isTypeOf(ACT_HERO);
|
bool ishero = tick->target->isTypeOf(ACT_HERO);
|
||||||
|
|
||||||
auto actors = tick->target->map->GetActorList();
|
auto actors = tick->target->map->GetActorList();
|
||||||
for each (auto actor in *actors) {
|
for (auto actor : *actors) {
|
||||||
if (actor == tick->target) continue;
|
if (actor == tick->target) continue;
|
||||||
|
|
||||||
if (actor->isTypeOf(ACT_HERO) == ishero) {
|
if (actor->isTypeOf(ACT_HERO) == ishero) {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
//#define _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH
|
//#define _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH
|
||||||
//#define _ITERATOR_DEBUG_LEVEL 0
|
//#define _ITERATOR_DEBUG_LEVEL 0
|
||||||
|
|
||||||
#include "Renderer.h"
|
|
||||||
|
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -9,6 +8,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "Renderer.h"
|
||||||
#include "Input.h"
|
#include "Input.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "Game.h"
|
#include "Game.h"
|
||||||
|
@ -19,6 +19,7 @@ Uint64 perfFreq;
|
||||||
|
|
||||||
double currTime();
|
double currTime();
|
||||||
|
|
||||||
|
#undef main
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
Renderer* renderer;
|
Renderer* renderer;
|
||||||
Input* input;
|
Input* input;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <math.h>
|
||||||
#include "Pathfinder.h"
|
#include "Pathfinder.h"
|
||||||
#include "Tilemap.h"
|
#include "Tilemap.h"
|
||||||
|
|
||||||
|
@ -38,7 +39,7 @@ namespace Pathfinder
|
||||||
//map->SetTile(current->pos.x, current->pos.y, TILE_CLOSED);
|
//map->SetTile(current->pos.x, current->pos.y, TILE_CLOSED);
|
||||||
|
|
||||||
auto neighbours = map->getNeighbours(current->pos.x, current->pos.y);
|
auto neighbours = map->getNeighbours(current->pos.x, current->pos.y);
|
||||||
for each (auto pos in neighbours)
|
for (auto pos : neighbours)
|
||||||
{
|
{
|
||||||
if (map->GetTile(pos.x, pos.y) == '#')
|
if (map->GetTile(pos.x, pos.y) == '#')
|
||||||
{
|
{
|
||||||
|
@ -64,11 +65,11 @@ namespace Pathfinder
|
||||||
path.push_back(current->pos);
|
path.push_back(current->pos);
|
||||||
current = current->from;
|
current = current->from;
|
||||||
}
|
}
|
||||||
for each (AStarNode* var in open)
|
for (AStarNode* var : open)
|
||||||
{
|
{
|
||||||
delete var;
|
delete var;
|
||||||
}
|
}
|
||||||
for each (AStarNode* var in closed)
|
for (AStarNode* var : closed)
|
||||||
{
|
{
|
||||||
delete var;
|
delete var;
|
||||||
}
|
}
|
||||||
|
@ -137,11 +138,11 @@ namespace Pathfinder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for each (AStarNode* var in open)
|
for (AStarNode* var : open)
|
||||||
{
|
{
|
||||||
delete var;
|
delete var;
|
||||||
}
|
}
|
||||||
for each (AStarNode* var in closed)
|
for (AStarNode* var : closed)
|
||||||
{
|
{
|
||||||
delete var;
|
delete var;
|
||||||
}
|
}
|
||||||
|
@ -158,15 +159,15 @@ namespace Pathfinder
|
||||||
}
|
}
|
||||||
out->height = map->GetHeight();
|
out->height = map->GetHeight();
|
||||||
out->width = map->GetWidth();
|
out->width = map->GetWidth();
|
||||||
for each (vec2i pos in *goals) {
|
for (vec2i pos : *goals) {
|
||||||
out->setValue(pos.x, pos.y, 0);
|
out->setValue(pos.x, pos.y, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<vec2i> queue;
|
std::vector<vec2i> queue;
|
||||||
|
|
||||||
for each (vec2i pos in *goals) {
|
for (vec2i pos : *goals) {
|
||||||
auto neigh = map->getNeighbours(pos.x, pos.y);
|
auto neigh = map->getNeighbours(pos.x, pos.y);
|
||||||
for each (vec2i npos in neigh) {
|
for (vec2i npos : neigh) {
|
||||||
int val = out->getValue(npos.x, npos.y);
|
int val = out->getValue(npos.x, npos.y);
|
||||||
if (map->GetTile(npos.x, npos.y) != '#' && val > 1) {
|
if (map->GetTile(npos.x, npos.y) != '#' && val > 1) {
|
||||||
if (npos.x != 0 && npos.y != 0) {
|
if (npos.x != 0 && npos.y != 0) {
|
||||||
|
|
|
@ -17,7 +17,7 @@ BehaviourTreeStatus RangedAttackNode::tick(BTTick * tick) {
|
||||||
|
|
||||||
auto actors = tick->target->map->GetActorList();
|
auto actors = tick->target->map->GetActorList();
|
||||||
std::vector<Actor*> enemies;
|
std::vector<Actor*> enemies;
|
||||||
for each (auto actor in *actors) {
|
for (auto actor : *actors) {
|
||||||
if (actor == tick->target) continue;
|
if (actor == tick->target) continue;
|
||||||
|
|
||||||
if (actor->isTypeOf(ACT_HERO) != ishero) {
|
if (actor->isTypeOf(ACT_HERO) != ishero) {
|
||||||
|
@ -34,7 +34,7 @@ BehaviourTreeStatus RangedAttackNode::tick(BTTick * tick) {
|
||||||
|
|
||||||
Actor* lowestHpActor = nullptr;
|
Actor* lowestHpActor = nullptr;
|
||||||
int lowestHp;
|
int lowestHp;
|
||||||
for each (Actor* actor in enemies) {
|
for (Actor* actor : enemies) {
|
||||||
if (lowestHpActor == nullptr || actor->health < lowestHp) {
|
if (lowestHpActor == nullptr || actor->health < lowestHp) {
|
||||||
lowestHpActor = actor;
|
lowestHpActor = actor;
|
||||||
lowestHp = actor->health;
|
lowestHp = actor->health;
|
||||||
|
|
|
@ -106,13 +106,13 @@ GLuint spriteVertArrayId;
|
||||||
GLuint colorUniform;
|
GLuint colorUniform;
|
||||||
GLuint mvpUniform;
|
GLuint mvpUniform;
|
||||||
|
|
||||||
bool Renderer::Init(char* title, int width, int height) {
|
bool Renderer::Init(std::string title, int width, int height) {
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
|
||||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||||
|
|
||||||
window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL);
|
window = SDL_CreateWindow(title.data(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL);
|
||||||
if (window == NULL) {
|
if (window == NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -268,24 +268,26 @@ Texture * Renderer::LoadTexture(std::string path) {
|
||||||
// Texture already loaded, no need to load it again
|
// Texture already loaded, no need to load it again
|
||||||
return &it->second;
|
return &it->second;
|
||||||
}
|
}
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Sprite Renderer::CreateSprite(std::string path, int x, int y, int w, int h) {
|
Sprite Renderer::CreateSprite(std::string path, int x, int y, int w, int h) {
|
||||||
Sprite sprite;
|
Sprite sprite;
|
||||||
sprite.region = {x, y, w, h};
|
sprite.region.x = x;
|
||||||
|
sprite.region.y = y;
|
||||||
|
sprite.region.w = w;
|
||||||
|
sprite.region.h = h;
|
||||||
sprite.texture = LoadTexture(path);
|
sprite.texture = LoadTexture(path);
|
||||||
if (sprite.texture != nullptr) {
|
if (sprite.texture != nullptr) {
|
||||||
float tw = sprite.texture->w;
|
float tw = (float)sprite.texture->w;
|
||||||
float th = sprite.texture->h;
|
float th = (float)sprite.texture->h;
|
||||||
const float uvs[] = {
|
const float uvs[] = {
|
||||||
x / tw, y / th,
|
x / tw, y / th,
|
||||||
(x + w) / tw, y / th,
|
(x + w) / tw, y / th,
|
||||||
x / tw, (y + h) / th,
|
x / tw, (y + h) / th,
|
||||||
(x + w) / tw, (y + h) / th,
|
(x + w) / tw, (y + h) / th,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
glCreateBuffers(1, &sprite.uvBuf);
|
glCreateBuffers(1, &sprite.uvBuf);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, sprite.uvBuf);
|
glBindBuffer(GL_ARRAY_BUFFER, sprite.uvBuf);
|
||||||
|
|
|
@ -45,7 +45,7 @@ class Renderer
|
||||||
public:
|
public:
|
||||||
Renderer();
|
Renderer();
|
||||||
~Renderer();
|
~Renderer();
|
||||||
bool Init(char* title, int width, int height);
|
bool Init(std::string title, int width, int height);
|
||||||
void SetColor(float r, float g, float b, float a);
|
void SetColor(float r, float g, float b, float a);
|
||||||
void SetColor(Color col);
|
void SetColor(Color col);
|
||||||
void SetTitle(const char* title);
|
void SetTitle(const char* title);
|
||||||
|
|
|
@ -17,7 +17,7 @@ Tilemap::Tilemap(int width, int height)
|
||||||
Tilemap::~Tilemap()
|
Tilemap::~Tilemap()
|
||||||
{
|
{
|
||||||
delete tilemap;
|
delete tilemap;
|
||||||
for each (auto var in actors) {
|
for (auto var : actors) {
|
||||||
delete var;
|
delete var;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ bool Tilemap::IsBlocked(int x, int y)
|
||||||
if (tilemap[GetIndex(x,y)] == '#') { // TODO: Replace hardcoded tiles
|
if (tilemap[GetIndex(x,y)] == '#') { // TODO: Replace hardcoded tiles
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
for each (Actor* var in actors) {
|
for (Actor* var : actors) {
|
||||||
vec2i pos = var->getPosition();
|
vec2i pos = var->getPosition();
|
||||||
if (var->IsAlive() && pos.x == x && pos.y == y) {
|
if (var->IsAlive() && pos.x == x && pos.y == y) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -94,7 +94,7 @@ bool Tilemap::IsBlocked(int x, int y)
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tilemap::AddActor(Actor * actor) {
|
void Tilemap::AddActor(Actor * actor) {
|
||||||
for each (Actor* var in actors) {
|
for (Actor* var : actors) {
|
||||||
if (var == actor) {
|
if (var == actor) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ void Tilemap::RemoveActor(Actor * actor) {
|
||||||
|
|
||||||
Actor * Tilemap::GetActor(int x, int y, Actors type) {
|
Actor * Tilemap::GetActor(int x, int y, Actors type) {
|
||||||
vec2i pos = { x,y };
|
vec2i pos = { x,y };
|
||||||
for each (Actor* act in actors) {
|
for (Actor* act : actors) {
|
||||||
if (act->isTypeOf(type)) {
|
if (act->isTypeOf(type)) {
|
||||||
vec2i apos = act->getPosition();
|
vec2i apos = act->getPosition();
|
||||||
if (apos == pos) {
|
if (apos == pos) {
|
||||||
|
@ -127,8 +127,8 @@ Actor * Tilemap::GetActor(int x, int y, Actors type) {
|
||||||
std::vector<Actor*> Tilemap::GetActors(int x, int y, int range, Actors type) {
|
std::vector<Actor*> Tilemap::GetActors(int x, int y, int range, Actors type) {
|
||||||
std::vector<Actor*> found;
|
std::vector<Actor*> found;
|
||||||
std::vector<vec2i> neigh = getNeighbours(x, y, range);
|
std::vector<vec2i> neigh = getNeighbours(x, y, range);
|
||||||
for each (Actor* act in actors) {
|
for (Actor* act : actors) {
|
||||||
for each (vec2i pos in neigh) {
|
for (vec2i pos : neigh) {
|
||||||
if (act->isTypeOf(type)) {
|
if (act->isTypeOf(type)) {
|
||||||
vec2i apos = act->getPosition();
|
vec2i apos = act->getPosition();
|
||||||
if (apos == pos) {
|
if (apos == pos) {
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "Actor.h"
|
||||||
|
|
||||||
struct vec2i;
|
struct vec2i;
|
||||||
|
|
||||||
class Actor;
|
|
||||||
enum Actors;
|
|
||||||
|
|
||||||
class Tilemap {
|
class Tilemap {
|
||||||
unsigned int* tilemap;
|
unsigned int* tilemap;
|
||||||
std::vector<Actor*> actors;
|
std::vector<Actor*> actors;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "Tileset.h"
|
#include "Tileset.h"
|
||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
|
|
||||||
Tileset::Tileset(Renderer* renderer, char * imgPath, int imgWidth, int imgHeight, int tileWidth, int tileHeight) {
|
Tileset::Tileset(Renderer* renderer, std::string imgPath, int imgWidth, int imgHeight, int tileWidth, int tileHeight) {
|
||||||
int tilesX = imgWidth / tileWidth;
|
int tilesX = imgWidth / tileWidth;
|
||||||
int tilesY = imgHeight / tileHeight;
|
int tilesY = imgHeight / tileHeight;
|
||||||
amount = tilesX*tilesY;
|
amount = tilesX*tilesY;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
|
||||||
class Renderer;
|
class Renderer;
|
||||||
struct Sprite;
|
struct Sprite;
|
||||||
|
@ -8,7 +9,7 @@ class Tileset {
|
||||||
Sprite* sprites;
|
Sprite* sprites;
|
||||||
int amount;
|
int amount;
|
||||||
public:
|
public:
|
||||||
Tileset(Renderer* renderer, char* imgPath, int imgWidth, int imgHeight, int tileWidth, int tileHeight);
|
Tileset(Renderer* renderer, std::string imgPath, int imgWidth, int imgHeight, int tileWidth, int tileHeight);
|
||||||
~Tileset();
|
~Tileset();
|
||||||
int GetAmount();
|
int GetAmount();
|
||||||
Sprite* GetSprite(int tileId);
|
Sprite* GetSprite(int tileId);
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <cstdlib>
|
||||||
#include "WanderNode.h"
|
#include "WanderNode.h"
|
||||||
#include "BehaviourTree.h"
|
#include "BehaviourTree.h"
|
||||||
#include "Actor.h"
|
#include "Actor.h"
|
||||||
|
@ -19,7 +20,7 @@ BehaviourTreeStatus WanderNode::tick(BTTick * tick) {
|
||||||
int i = rand() % neighbours.size();
|
int i = rand() % neighbours.size();
|
||||||
vec2i dp = neighbours[i] - pos;
|
vec2i dp = neighbours[i] - pos;
|
||||||
bool valid = true;
|
bool valid = true;
|
||||||
for each (vec2i var in previous) {
|
for (vec2i var : previous) {
|
||||||
if (var == neighbours[i]) {
|
if (var == neighbours[i]) {
|
||||||
valid = false;
|
valid = false;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "World.h"
|
#include "World.h"
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
World::World() {
|
World::World() {
|
||||||
World(0);
|
World(0);
|
||||||
|
@ -38,7 +39,7 @@ Tilemap* World::GetMap(unsigned int level) {
|
||||||
|
|
||||||
World::~World() {
|
World::~World() {
|
||||||
seeds.clear();
|
seeds.clear();
|
||||||
for each (Tilemap* map in maps) {
|
for (Tilemap* map : maps) {
|
||||||
if (map != nullptr) {
|
if (map != nullptr) {
|
||||||
delete map;
|
delete map;
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,6 +106,7 @@
|
||||||
#include <KHR/khrplatform.h>
|
#include <KHR/khrplatform.h>
|
||||||
#include <EGL/eglplatform.h>
|
#include <EGL/eglplatform.h>
|
||||||
|
|
||||||
|
#define GLEW_STATIC
|
||||||
#include "glew.h"
|
#include "glew.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef GLEW_INCLUDE
|
#ifndef GLEW_INCLUDE
|
||||||
|
#define GLEW_STATIC
|
||||||
#include "glew.h"
|
#include "glew.h"
|
||||||
#else
|
#else
|
||||||
#include GLEW_INCLUDE
|
#include GLEW_INCLUDE
|
||||||
|
|
Loading…
Reference in a new issue