From d0b4c74690bb4cdc1cec228f754f4a503f0379f2 Mon Sep 17 00:00:00 2001 From: Adrian Hedqvist Date: Thu, 21 Sep 2017 22:44:05 +0200 Subject: [PATCH] Rename a bunch of functions --- src/Actor.cpp | 4 +- src/Actor.h | 4 +- src/App.cpp | 10 ++-- src/AttackEnemyNode.cpp | 12 ++-- src/ExploreNode.cpp | 2 +- src/FieldOfView.cpp | 4 +- src/FleeNode.cpp | 8 +-- src/HealFriendNode.cpp | 6 +- src/IfNotSeeEnemyNode.cpp | 6 +- src/IfSeeEnemyNode.cpp | 6 +- src/IfSeeFriendNode.cpp | 6 +- src/Input.cpp | 18 +++--- src/Input.h | 17 +++--- src/Pathfinder.cpp | 8 +-- src/PlayState.cpp | 122 +++++++++++++++++++------------------- src/RangedAttackNode.cpp | 6 +- src/Renderer.cpp | 18 +++--- src/Renderer.h | 16 ++--- src/Tilemap.cpp | 20 +++---- src/Tilemap.h | 6 +- src/Tileset.cpp | 2 +- src/Tileset.h | 2 +- src/WanderNode.cpp | 2 +- 23 files changed, 156 insertions(+), 149 deletions(-) diff --git a/src/Actor.cpp b/src/Actor.cpp index 6e4f688..c27785d 100644 --- a/src/Actor.cpp +++ b/src/Actor.cpp @@ -7,7 +7,7 @@ Actor::Actor(Tilemap * map, vec2i pos) { position = pos; } -const vec2i Actor::getPosition() { +const vec2i Actor::get_position() { return position; } @@ -21,7 +21,7 @@ bool Actor::Move(int dx, int dy) { return false; } -void Actor::Update() { +void Actor::update() { if (!alive) return; if (bt) { diff --git a/src/Actor.h b/src/Actor.h index 5519738..a696bf2 100644 --- a/src/Actor.h +++ b/src/Actor.h @@ -27,12 +27,12 @@ public: Actor(Tilemap* map, vec2i pos); - const vec2i getPosition(); + const vec2i get_position(); bool IsAlive(){ return alive; }; bool Move(int dx, int dy); int GetHealth() { return health; } void Kill() { alive = false; health = 0; }; - void Update(); + void update(); virtual bool isTypeOf(Actors actor){ return actor == ACT_BASE; }; virtual Actors Type() { return ACT_BASE; }; ~Actor(); diff --git a/src/App.cpp b/src/App.cpp index 22b9c98..9d4fe81 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -50,8 +50,8 @@ bool App::init() { return false; } - renderer->SetVSyncEnabled(vsync); - renderer->SetWireframesEnabled(wireframe); + renderer->set_vsync_enabled(vsync); + renderer->set_wireframes_enabled(wireframe); input = new Input(); srand(static_cast(time(nullptr))); @@ -124,13 +124,13 @@ int App::start() { break; case SDL_KEYDOWN: if (!io.WantCaptureKeyboard) { - InputEvent inputEvent = input->setkey(ev.key.keysym.sym, (SDL_Keymod)ev.key.keysym.mod, true); + InputEvent inputEvent = input->set_key(ev.key.keysym.sym, (SDL_Keymod) ev.key.keysym.mod, true); current->inputevent(&inputEvent); } break; case SDL_KEYUP: if (!io.WantCaptureKeyboard){ - InputEvent inputEvent = input->setkey(ev.key.keysym.sym, (SDL_Keymod)ev.key.keysym.mod, false); + InputEvent inputEvent = input->set_key(ev.key.keysym.sym, (SDL_Keymod) ev.key.keysym.mod, false); current->inputevent(&inputEvent); } break; @@ -143,7 +143,7 @@ int App::start() { } while (running && accumulator >= dt) { nextstate = current->update(dt); - input->newframe(); + input->new_frame(); accumulator -= dt; } diff --git a/src/AttackEnemyNode.cpp b/src/AttackEnemyNode.cpp index d0f9627..b5de374 100644 --- a/src/AttackEnemyNode.cpp +++ b/src/AttackEnemyNode.cpp @@ -12,15 +12,15 @@ AttackEnemyNode::~AttackEnemyNode() {} BehaviourTreeStatus AttackEnemyNode::tick(BTTick * tick) { bool ishero = tick->target->isTypeOf(ACT_HERO); - auto actors = tick->target->map->GetActorList(); + auto actors = tick->target->map->get_actor_list(); std::vector visibleEnemies; for (auto actor : *actors) { if (actor == tick->target) continue; if (actor->isTypeOf(ACT_HERO) != ishero) { - vec2i pos = actor->getPosition(); - if (line_of_sight(tick->target->map, tick->target->getPosition(), pos)) { + vec2i pos = actor->get_position(); + if (line_of_sight(tick->target->map, tick->target->get_position(), pos)) { visibleEnemies.push_back(actor); } } @@ -33,7 +33,7 @@ BehaviourTreeStatus AttackEnemyNode::tick(BTTick * tick) { Actor* closestActor = nullptr; float closestDist; for (Actor* actor : visibleEnemies) { - float dist = Pathfinder::distance(tick->target->getPosition(), actor->getPosition()); + float dist = Pathfinder::distance(tick->target->get_position(), actor->get_position()); if (closestActor == nullptr || dist < closestDist) { closestActor = actor; @@ -50,8 +50,8 @@ BehaviourTreeStatus AttackEnemyNode::tick(BTTick * tick) { return BT_RUNNING; } else { - vec2i pos = tick->target->getPosition(); - vec2i goal = closestActor->getPosition(); + vec2i pos = tick->target->get_position(); + vec2i goal = closestActor->get_position(); auto path = Pathfinder::aStar(tick->target->map, pos, goal); if (path.size() > 0) { //path.pop_back(); diff --git a/src/ExploreNode.cpp b/src/ExploreNode.cpp index c2408ba..0013399 100644 --- a/src/ExploreNode.cpp +++ b/src/ExploreNode.cpp @@ -26,7 +26,7 @@ BehaviourTreeStatus ExploreNode::tick(BTTick * tick) { } Pathfinder::calcDijkstraMap(map, &unexplored, &dijkstra, 99999); - vec2i pos = tick->target->getPosition(); + vec2i pos = tick->target->get_position(); std::vector neigh = map->getNeighbours(pos.x, pos.y); std::vector options; diff --git a/src/FieldOfView.cpp b/src/FieldOfView.cpp index e9933df..6a0fc03 100644 --- a/src/FieldOfView.cpp +++ b/src/FieldOfView.cpp @@ -18,7 +18,7 @@ FieldOfView::~FieldOfView() { void FieldOfView::calc(vec2i pos, float range) { counter++; - seen->SetTile(pos.x, pos.y, counter); + seen->set_tile(pos.x, pos.y, counter); // Once for each octant cast_light(1, 1.0f, 0.0f, 0, -1, -1, 0, pos.x, pos.y, range); cast_light(1, 1.0f, 0.0f, -1, 0, 0, -1, pos.x, pos.y, range); @@ -61,7 +61,7 @@ void FieldOfView::cast_light(int row, float start, float end, int xx, int xy, in } if (sqrt(deltaX*deltaX + deltaY*deltaY) <= radius) { - seen->SetTile(currentX, currentY, counter); + seen->set_tile(currentX, currentY, counter); } if (blocked) { diff --git a/src/FleeNode.cpp b/src/FleeNode.cpp index 4ec4661..5516767 100644 --- a/src/FleeNode.cpp +++ b/src/FleeNode.cpp @@ -17,11 +17,11 @@ BehaviourTreeStatus FleeNode::tick(BTTick * tick) { Tilemap * map = tick->target->map; std::vector enemyPos; bool ishero = tick->target->isTypeOf(ACT_HERO); - auto actors = tick->target->map->GetActorList(); + auto actors = tick->target->map->get_actor_list(); for (Actor* actor : *actors) { if (actor->isTypeOf(ACT_HERO) != ishero) { - vec2i pos = actor->getPosition(); - if (line_of_sight(tick->target->map, tick->target->getPosition(), pos)) { + vec2i pos = actor->get_position(); + if (line_of_sight(tick->target->map, tick->target->get_position(), pos)) { enemyPos.push_back(pos); } } @@ -45,7 +45,7 @@ BehaviourTreeStatus FleeNode::tick(BTTick * tick) { Pathfinder::calcDijkstraMap(map, &safety, &dijkstra); - vec2i pos = tick->target->getPosition(); + vec2i pos = tick->target->get_position(); std::vector neigh = map->getNeighbours(pos.x, pos.y); std::vector options; diff --git a/src/HealFriendNode.cpp b/src/HealFriendNode.cpp index 032c974..1e2eb0b 100644 --- a/src/HealFriendNode.cpp +++ b/src/HealFriendNode.cpp @@ -12,14 +12,14 @@ HealFriendNode::~HealFriendNode() {} BehaviourTreeStatus HealFriendNode::tick(BTTick * tick) { bool ishero = tick->target->isTypeOf(ACT_HERO); - auto actors = tick->target->map->GetActorList(); + auto actors = tick->target->map->get_actor_list(); std::vector friends; for (auto actor : *actors) { if (actor == tick->target) continue; if (actor->isTypeOf(ACT_HERO) == ishero && actor->health < actor->maxhealth-1) { - vec2i pos = actor->getPosition(); - if (line_of_sight(tick->target->map, tick->target->getPosition(), pos)) { + vec2i pos = actor->get_position(); + if (line_of_sight(tick->target->map, tick->target->get_position(), pos)) { friends.push_back(actor); } } diff --git a/src/IfNotSeeEnemyNode.cpp b/src/IfNotSeeEnemyNode.cpp index d3ccf8b..c988073 100644 --- a/src/IfNotSeeEnemyNode.cpp +++ b/src/IfNotSeeEnemyNode.cpp @@ -15,13 +15,13 @@ BehaviourTreeStatus IfNotSeeEnemyNode::tick(BTTick * tick) { } bool ishero = tick->target->isTypeOf(ACT_HERO); - auto actors = tick->target->map->GetActorList(); + auto actors = tick->target->map->get_actor_list(); for (auto actor : *actors) { if (actor == tick->target) continue; if (actor->isTypeOf(ACT_HERO) != ishero) { - vec2i pos = actor->getPosition(); - if (line_of_sight(tick->target->map, tick->target->getPosition(), pos)) { + vec2i pos = actor->get_position(); + if (line_of_sight(tick->target->map, tick->target->get_position(), pos)) { return BT_FAILED; } } diff --git a/src/IfSeeEnemyNode.cpp b/src/IfSeeEnemyNode.cpp index 5b73288..41f16f5 100644 --- a/src/IfSeeEnemyNode.cpp +++ b/src/IfSeeEnemyNode.cpp @@ -15,13 +15,13 @@ BehaviourTreeStatus IfSeeEnemyNode::tick(BTTick * tick) { } bool ishero = tick->target->isTypeOf(ACT_HERO); - auto actors = tick->target->map->GetActorList(); + auto actors = tick->target->map->get_actor_list(); for (auto actor : *actors) { if (actor == tick->target) continue; if (actor->isTypeOf(ACT_HERO) != ishero) { - vec2i pos = actor->getPosition(); - if (line_of_sight(tick->target->map, tick->target->getPosition(), pos)) { + vec2i pos = actor->get_position(); + if (line_of_sight(tick->target->map, tick->target->get_position(), pos)) { return children[0]->execute(tick); } } diff --git a/src/IfSeeFriendNode.cpp b/src/IfSeeFriendNode.cpp index 774d293..beed9fb 100644 --- a/src/IfSeeFriendNode.cpp +++ b/src/IfSeeFriendNode.cpp @@ -16,13 +16,13 @@ BehaviourTreeStatus IfSeeFriendNode::tick(BTTick * tick) { } bool ishero = tick->target->isTypeOf(ACT_HERO); - auto actors = tick->target->map->GetActorList(); + auto actors = tick->target->map->get_actor_list(); for (auto actor : *actors) { if (actor == tick->target) continue; if (actor->isTypeOf(ACT_HERO) == ishero) { - vec2i pos = actor->getPosition(); - if (line_of_sight(tick->target->map, tick->target->getPosition(), pos)) { + vec2i pos = actor->get_position(); + if (line_of_sight(tick->target->map, tick->target->get_position(), pos)) { return children[0]->execute(tick); } } diff --git a/src/Input.cpp b/src/Input.cpp index 938bc45..75ec6dd 100644 --- a/src/Input.cpp +++ b/src/Input.cpp @@ -16,14 +16,14 @@ Input::~Input() { } -void Input::newframe() { +void Input::new_frame() { for(int i = 0; i < INPUTACTION_END; i++) { justpressed[i] = false; justreleased[i] = false; } } -InputEvent Input::setkey(SDL_Keycode key, SDL_Keymod mod, bool pressed) +InputEvent Input::set_key(SDL_Keycode key, SDL_Keymod mod, bool pressed) { InputEvent event{}; event.type = INPUT_KEY_EVENT; @@ -57,25 +57,25 @@ InputEvent Input::setkey(SDL_Keycode key, SDL_Keymod mod, bool pressed) return event; } -void Input::bindkey(SDL_Keycode key, InputAction action, SDL_Keymod mod) { +void Input::bind_key(SDL_Keycode key, InputAction action, SDL_Keymod mod) { Bind bind = { key, mod }; binds[bind] = action; } -void Input::unbindkey(SDL_Keycode key, SDL_Keymod mod) { +void Input::unbind_key(SDL_Keycode key, SDL_Keymod mod) { Bind bind = { key, mod }; binds.erase(bind); } -bool Input::isPressed(InputAction action) { +bool Input::is_pressed(InputAction action) { return ispressed[action]; } -bool Input::wasJustPressed(InputAction action) { +bool Input::was_just_pressed(InputAction action) { return justpressed[action]; } -bool Input::wasJustReleased(InputAction action) { +bool Input::was_just_released(InputAction action) { return justreleased[action]; } @@ -107,3 +107,7 @@ InputEvent Input::set_mouse_button(int button, int x, int y, bool pressed) { event.mouse_click_event.y = y; return event; } + +vec2i Input::get_mouse_pos() { + return {mouse_x, mouse_y}; +} diff --git a/src/Input.h b/src/Input.h index a8a8756..4b03598 100644 --- a/src/Input.h +++ b/src/Input.h @@ -2,6 +2,7 @@ #include #include +#include "vec2i.h" enum InputAction { ACTION_NONE, @@ -16,6 +17,7 @@ enum InputAction { ACTION_MOVE_SOUTH, ACTION_MOVE_SOUTHWEST, ACTION_MOVE_SOUTHEAST, + ACTION_WAIT, INPUTACTION_END // Used to get the length of the enum. Must be the final entry. }; @@ -76,14 +78,15 @@ class Input public: Input(); ~Input(); - void newframe(); - InputEvent setkey(SDL_Keycode key, SDL_Keymod mod, bool pressed); + void new_frame(); + InputEvent set_key(SDL_Keycode key, SDL_Keymod mod, bool pressed); InputEvent set_mouse_pos(int x, int y, int dx, int dy); InputEvent set_mouse_button(int button, int x, int y, bool pressed); - void bindkey(SDL_Keycode key, InputAction action, SDL_Keymod mod = KMOD_NONE); - void unbindkey(SDL_Keycode key, SDL_Keymod mod); - bool isPressed(InputAction action); - bool wasJustPressed(InputAction action); - bool wasJustReleased(InputAction action); + void bind_key(SDL_Keycode key, InputAction action, SDL_Keymod mod = KMOD_NONE); + void unbind_key(SDL_Keycode key, SDL_Keymod mod); + bool is_pressed(InputAction action); + bool was_just_pressed(InputAction action); + bool was_just_released(InputAction action); + vec2i get_mouse_pos(); }; diff --git a/src/Pathfinder.cpp b/src/Pathfinder.cpp index 8dd0070..1b15ce2 100644 --- a/src/Pathfinder.cpp +++ b/src/Pathfinder.cpp @@ -36,7 +36,7 @@ namespace Pathfinder } open.erase(open.begin()+currentindex); closed.push_back(current); - //map->SetTile(current->pos.x, current->pos.y, TILE_CLOSED); + //map->set_tile(current->pos.x, current->pos.y, TILE_CLOSED); auto neighbours = map->getNeighbours(current->pos.x, current->pos.y); for (auto pos : neighbours) @@ -89,7 +89,7 @@ namespace Pathfinder closed.erase(it); delete (*it); open.push_back(neighbour); - //map->SetTile(neighbour->pos.x, neighbour->pos.y, TILE_OPENED); + //map->set_tile(neighbour->pos.x, neighbour->pos.y, TILE_OPENED); isClosed = false; } break; @@ -111,7 +111,7 @@ namespace Pathfinder open.erase(it); delete (*it); open.push_back(neighbour); - //map->SetTile(neighbour->pos.x, neighbour->pos.y, TILE_OPENED); + //map->set_tile(neighbour->pos.x, neighbour->pos.y, TILE_OPENED); } break; } @@ -120,7 +120,7 @@ namespace Pathfinder if (!isOpened) { open.push_back(neighbour); - //map->SetTile(neighbour->pos.x, neighbour->pos.y, TILE_OPENED); + //map->set_tile(neighbour->pos.x, neighbour->pos.y, TILE_OPENED); } } else diff --git a/src/PlayState.cpp b/src/PlayState.cpp index e34aa4d..eee7644 100644 --- a/src/PlayState.cpp +++ b/src/PlayState.cpp @@ -56,18 +56,18 @@ void PlayState::load() { ascii = new Tileset(app->renderer, "./assets/12x12.bmp", 192, 192, 12, 12); SDL_LogVerbose(SDL_LOG_CATEGORY_SYSTEM, "Created ascii tileset.\n"); - app->input->bindkey(SDLK_ESCAPE, ACTION_ESCAPE_MENU); - app->input->bindkey(SDLK_KP_8, ACTION_MOVE_NORTH); - app->input->bindkey(SDLK_KP_7, ACTION_MOVE_NORTHWEST); - app->input->bindkey(SDLK_KP_9, ACTION_MOVE_NORTHEAST); - app->input->bindkey(SDLK_KP_4, ACTION_MOVE_WEST); - app->input->bindkey(SDLK_KP_6, ACTION_MOVE_EAST); - app->input->bindkey(SDLK_KP_2, ACTION_MOVE_SOUTH); - app->input->bindkey(SDLK_KP_1, ACTION_MOVE_SOUTHWEST); - app->input->bindkey(SDLK_KP_3, ACTION_MOVE_SOUTHEAST); - app->input->bindkey(SDLK_F1, ACTION_TOGGLE_DEBUG); + app->input->bind_key(SDLK_ESCAPE, ACTION_ESCAPE_MENU); + app->input->bind_key(SDLK_KP_8, ACTION_MOVE_NORTH); + app->input->bind_key(SDLK_KP_7, ACTION_MOVE_NORTHWEST); + app->input->bind_key(SDLK_KP_9, ACTION_MOVE_NORTHEAST); + app->input->bind_key(SDLK_KP_4, ACTION_MOVE_WEST); + app->input->bind_key(SDLK_KP_6, ACTION_MOVE_EAST); + app->input->bind_key(SDLK_KP_2, ACTION_MOVE_SOUTH); + app->input->bind_key(SDLK_KP_1, ACTION_MOVE_SOUTHWEST); + app->input->bind_key(SDLK_KP_3, ACTION_MOVE_SOUTHEAST); + app->input->bind_key(SDLK_F1, ACTION_TOGGLE_DEBUG); - app->input->bindkey(SDLK_r, ACTION_RESET); + app->input->bind_key(SDLK_r, ACTION_RESET); SDL_LogVerbose(SDL_LOG_CATEGORY_SYSTEM, "Keybinds bound.\n"); new_game(); @@ -111,26 +111,26 @@ void PlayState::new_game() { if (map[i] == '@') { hero = new Hero(tilemap, vec2i(x, y)); - tilemap->AddActor(hero); - tilemap->SetTile(x, y, '.'); + tilemap->add_actor(hero); + tilemap->set_tile(x, y, '.'); } else if (map[i] == 'g') { - tilemap->AddActor(new Goblin(tilemap, vec2i(x, y))); - tilemap->SetTile(x, y, '.'); + tilemap->add_actor(new Goblin(tilemap, vec2i(x, y))); + tilemap->set_tile(x, y, '.'); } else if (map[i] == 's') { - tilemap->AddActor(new Shaman(tilemap, vec2i(x, y))); - tilemap->SetTile(x, y, '.'); + tilemap->add_actor(new Shaman(tilemap, vec2i(x, y))); + tilemap->set_tile(x, y, '.'); } else { - tilemap->SetTile(x, y, map[i]); + tilemap->set_tile(x, y, map[i]); } x++; } SDL_LogVerbose(SDL_LOG_CATEGORY_SYSTEM, "Done.\n"); SDL_LogVerbose(SDL_LOG_CATEGORY_SYSTEM, "Calculating initial FOV...\n"); fov = new FieldOfView(tilemap); - fov->calc(hero->getPosition(), 6); + fov->calc(hero->get_position(), 6); SDL_LogVerbose(SDL_LOG_CATEGORY_SYSTEM, "Done.\n"); } @@ -140,9 +140,9 @@ Gamestate *PlayState::update(double delta) { if (timer >= delay) { timer = 0; - auto actors = tilemap->GetActorList(); + auto actors = tilemap->get_actor_list(); for (Actor* var : *actors) { - var->Update(); + var->update(); } for (int i = (int)actors->size() - 1; i >= 0; i--) { if (!actors->at(i)->alive) { @@ -153,7 +153,7 @@ Gamestate *PlayState::update(double delta) { actors->erase(actors->begin() + i); } } - fov->calc(hero->getPosition(), 6); + fov->calc(hero->get_position(), 6); } } return nullptr; @@ -161,12 +161,12 @@ Gamestate *PlayState::update(double delta) { void PlayState::draw(double delta) { if (debug) { - bool wireframe = app->renderer->IsWireframesEnabled(); + bool wireframe = app->renderer->is_wireframes_enabled(); ImGui::Checkbox("Wireframes", &wireframe); - app->renderer->SetWireframesEnabled(wireframe); - bool vsync = app->renderer->IsVSyncEnabled(); + app->renderer->set_wireframes_enabled(wireframe); + bool vsync = app->renderer->is_vsync_enabled(); ImGui::Checkbox("VSync", &vsync); - app->renderer->SetVSyncEnabled(vsync); + app->renderer->set_vsync_enabled(vsync); ImGui::BeginMainMenuBar(); @@ -188,71 +188,71 @@ void PlayState::draw(double delta) { } vec2i offset; - offset.x = app->renderer->GetRendererWidth() / 2; - offset.y = app->renderer->GetRendererHeight() / 2; - vec2i heropos = hero->getPosition(); + offset.x = app->renderer->get_renderer_width() / 2; + offset.y = app->renderer->get_renderer_height() / 2; + vec2i heropos = hero->get_position(); offset.x -= heropos.x * 12; offset.y -= heropos.y * 12; tilemap->draw(app->renderer, ascii, offset.x, offset.y, fov); - auto actors = tilemap->GetActorList(); + auto actors = tilemap->get_actor_list(); for (Actor* var : *actors) { - vec2i pos = var->getPosition(); + vec2i pos = var->get_position(); if (fov == nullptr || fov->can_see(pos)) { - app->renderer->SetColor(0, 0, 0, 255); - app->renderer->DrawSprite(ascii->GetSprite(219), offset.x + pos.x * 12, offset.y + pos.y * 12); + app->renderer->set_color(0, 0, 0, 255); + app->renderer->draw_sprite(ascii->get_sprite(219), offset.x + pos.x * 12, offset.y + pos.y * 12); int sprite; switch (var->Type()) { case ACT_HERO: - app->renderer->SetColor(.2f, .6f, 1, 1); + app->renderer->set_color(.2f, .6f, 1, 1); sprite = '@'; break; case ACT_GOBLIN: - app->renderer->SetColor(.6f, 1, .2f, 1); + app->renderer->set_color(.6f, 1, .2f, 1); sprite = 'g'; break; case ACT_SHAMAN: - app->renderer->SetColor(.2f, 1, .6f, 1); + app->renderer->set_color(.2f, 1, .6f, 1); sprite = 's'; break; default: - app->renderer->SetColor(1, 1, 1, 1); + app->renderer->set_color(1, 1, 1, 1); sprite = 2; break; } - app->renderer->DrawSprite(ascii->GetSprite(sprite), offset.x + pos.x * 12, offset.y + pos.y * 12); + app->renderer->draw_sprite(ascii->get_sprite(sprite), offset.x + pos.x * 12, offset.y + pos.y * 12); } } if (hero != nullptr) { - app->renderer->SetColor(155, 5, 5, 255); + app->renderer->set_color(155, 5, 5, 255); for (int i = 0; i < hero->health; i++) { - app->renderer->SetColor(0, 0, 0, 255); - app->renderer->DrawSprite(ascii->GetSprite(219), i * 12, 0); - app->renderer->SetColor(255, 0, 0, 255); - app->renderer->DrawSprite(ascii->GetSprite(3), i * 12, 0); + app->renderer->set_color(0, 0, 0, 255); + app->renderer->draw_sprite(ascii->get_sprite(219), i * 12, 0); + app->renderer->set_color(255, 0, 0, 255); + app->renderer->draw_sprite(ascii->get_sprite(3), i * 12, 0); } } if (paused) { - app->renderer->SetColor(255, 0, 0, 255); - app->renderer->DrawSprite(ascii->GetSprite(219), 12 * 0, 0); - app->renderer->DrawSprite(ascii->GetSprite(219), 12 * 1, 0); - app->renderer->DrawSprite(ascii->GetSprite(219), 12 * 2, 0); - app->renderer->DrawSprite(ascii->GetSprite(219), 12 * 3, 0); - app->renderer->DrawSprite(ascii->GetSprite(219), 12 * 4, 0); - app->renderer->DrawSprite(ascii->GetSprite(219), 12 * 5, 0); - app->renderer->DrawSprite(ascii->GetSprite(219), 12 * 6, 0); - app->renderer->DrawSprite(ascii->GetSprite(219), 12 * 7, 0); - app->renderer->SetColor(0, 0, 0, 255); - app->renderer->DrawSprite(ascii->GetSprite('-'), 12 * 0, 0); - app->renderer->DrawSprite(ascii->GetSprite('P'), 12 * 1, 0); - app->renderer->DrawSprite(ascii->GetSprite('A'), 12 * 2, 0); - app->renderer->DrawSprite(ascii->GetSprite('U'), 12 * 3, 0); - app->renderer->DrawSprite(ascii->GetSprite('S'), 12 * 4, 0); - app->renderer->DrawSprite(ascii->GetSprite('E'), 12 * 5, 0); - app->renderer->DrawSprite(ascii->GetSprite('D'), 12 * 6, 0); - app->renderer->DrawSprite(ascii->GetSprite('-'), 12 * 7, 0); + app->renderer->set_color(255, 0, 0, 255); + app->renderer->draw_sprite(ascii->get_sprite(219), 12 * 0, 0); + app->renderer->draw_sprite(ascii->get_sprite(219), 12 * 1, 0); + app->renderer->draw_sprite(ascii->get_sprite(219), 12 * 2, 0); + app->renderer->draw_sprite(ascii->get_sprite(219), 12 * 3, 0); + app->renderer->draw_sprite(ascii->get_sprite(219), 12 * 4, 0); + app->renderer->draw_sprite(ascii->get_sprite(219), 12 * 5, 0); + app->renderer->draw_sprite(ascii->get_sprite(219), 12 * 6, 0); + app->renderer->draw_sprite(ascii->get_sprite(219), 12 * 7, 0); + app->renderer->set_color(0, 0, 0, 255); + app->renderer->draw_sprite(ascii->get_sprite('-'), 12 * 0, 0); + app->renderer->draw_sprite(ascii->get_sprite('P'), 12 * 1, 0); + app->renderer->draw_sprite(ascii->get_sprite('A'), 12 * 2, 0); + app->renderer->draw_sprite(ascii->get_sprite('U'), 12 * 3, 0); + app->renderer->draw_sprite(ascii->get_sprite('S'), 12 * 4, 0); + app->renderer->draw_sprite(ascii->get_sprite('E'), 12 * 5, 0); + app->renderer->draw_sprite(ascii->get_sprite('D'), 12 * 6, 0); + app->renderer->draw_sprite(ascii->get_sprite('-'), 12 * 7, 0); } } diff --git a/src/RangedAttackNode.cpp b/src/RangedAttackNode.cpp index b66fbe2..86b4a76 100644 --- a/src/RangedAttackNode.cpp +++ b/src/RangedAttackNode.cpp @@ -16,14 +16,14 @@ BehaviourTreeStatus RangedAttackNode::tick(BTTick * tick) { } bool ishero = tick->target->isTypeOf(ACT_HERO); - auto actors = tick->target->map->GetActorList(); + auto actors = tick->target->map->get_actor_list(); std::vector enemies; for (auto actor : *actors) { if (actor == tick->target) continue; if (actor->isTypeOf(ACT_HERO) != ishero) { - vec2i pos = actor->getPosition(); - if (line_of_sight(tick->target->map, tick->target->getPosition(), pos)) { + vec2i pos = actor->get_position(); + if (line_of_sight(tick->target->map, tick->target->get_position(), pos)) { enemies.push_back(actor); } } diff --git a/src/Renderer.cpp b/src/Renderer.cpp index 53a3bb9..d85bb8e 100644 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -170,12 +170,12 @@ bool Renderer::Init(std::string title, int width, int height) { return true; } -void Renderer::SetColor(float r, float g, float b, float a) { +void Renderer::set_color(float r, float g, float b, float a) { currentcolor = { r, g, b, a }; } void Renderer::SetColor(Color col) { - SetColor(col.r, col.g, col.b, col.a); + set_color(col.r, col.g, col.b, col.a); } void Renderer::SetTitle(const char * title) { @@ -206,27 +206,27 @@ void Renderer::SetClearColor(Color col) { glClearColor(col.r, col.g, col.b, col.a); } -void Renderer::SetVSyncEnabled(bool enabled) { +void Renderer::set_vsync_enabled(bool enabled) { SDL_GL_SetSwapInterval(enabled ? 1 : 0); } -bool Renderer::IsVSyncEnabled() { +bool Renderer::is_vsync_enabled() { return SDL_GL_GetSwapInterval() == 1; } -void Renderer::SetWireframesEnabled(bool enabled) { +void Renderer::set_wireframes_enabled(bool enabled) { wireframe = enabled; } -bool Renderer::IsWireframesEnabled() { +bool Renderer::is_wireframes_enabled() { return wireframe; } -int Renderer::GetRendererWidth() { +int Renderer::get_renderer_width() { return windowwidth; } -int Renderer::GetRendererHeight() { +int Renderer::get_renderer_height() { return windowheight; } @@ -314,7 +314,7 @@ Sprite Renderer::CreateSprite(std::string path, int x, int y, int w, int h) { } -void Renderer::DrawSprite(Sprite * sprite, int x, int y, float sx, float sy) { +void Renderer::draw_sprite(Sprite *sprite, int x, int y, float sx, float sy) { glm::mat4 model = glm::translate(glm::vec3(x, y, 0)) * glm::scale(glm::vec3(sprite->region.w * sx, sprite->region.h * sy, 1)) * glm::mat4(1); diff --git a/src/Renderer.h b/src/Renderer.h index 16d3bd5..9122a97 100644 --- a/src/Renderer.h +++ b/src/Renderer.h @@ -46,23 +46,23 @@ public: Renderer(); ~Renderer(); bool Init(std::string title, int width, int height); - void SetColor(float r, float g, float b, float a); + void set_color(float r, float g, float b, float a); void SetColor(Color col); void SetTitle(const char* title); void SetWindowSize(int width, int height); void SetClearColor(float r, float g, float b, float a); void SetClearColor(Color col); - void SetVSyncEnabled(bool enabled); - bool IsVSyncEnabled(); - void SetWireframesEnabled(bool enabled); - bool IsWireframesEnabled(); - int GetRendererWidth(); - int GetRendererHeight(); + void set_vsync_enabled(bool enabled); + bool is_vsync_enabled(); + void set_wireframes_enabled(bool enabled); + bool is_wireframes_enabled(); + int get_renderer_width(); + int get_renderer_height(); bool ImguiProcessEvents(SDL_Event *e); void ImguiNewFrame(); Texture * LoadTexture(std::string path); Sprite CreateSprite(std::string path, int x, int y, int w, int h); - void DrawSprite(Sprite * sprite, int x, int y, float sx = 1, float sy = 1); + void draw_sprite(Sprite *sprite, int x, int y, float sx = 1, float sy = 1); void Clear(); void Present(); }; diff --git a/src/Tilemap.cpp b/src/Tilemap.cpp index 0c8ff5d..2dc689a 100644 --- a/src/Tilemap.cpp +++ b/src/Tilemap.cpp @@ -62,7 +62,7 @@ std::vector Tilemap::getNeighbours(int x, int y, int range) return neigh; } -void Tilemap::SetTile(int x, int y, int tile) +void Tilemap::set_tile(int x, int y, int tile) { if (IsInsideBounds(x, y)) { @@ -87,7 +87,7 @@ bool Tilemap::IsBlocked(int x, int y) return true; } for (Actor* var : actors) { - vec2i pos = var->getPosition(); + vec2i pos = var->get_position(); if (var->IsAlive() && pos.x == x && pos.y == y) { return true; } @@ -97,7 +97,7 @@ bool Tilemap::IsBlocked(int x, int y) return true; } -void Tilemap::AddActor(Actor * actor) { +void Tilemap::add_actor(Actor *actor) { for (Actor* var : actors) { if (var == actor) { return; @@ -119,7 +119,7 @@ Actor * Tilemap::GetActor(int x, int y, Actors type) { vec2i pos = { x,y }; for (Actor* act : actors) { if (act->isTypeOf(type)) { - vec2i apos = act->getPosition(); + vec2i apos = act->get_position(); if (apos == pos) { return act; } @@ -134,7 +134,7 @@ std::vector Tilemap::GetActors(int x, int y, int range, Actors type) { for (Actor* act : actors) { for (vec2i pos : neigh) { if (act->isTypeOf(type)) { - vec2i apos = act->getPosition(); + vec2i apos = act->get_position(); if (apos == pos) { found.push_back(act); break; @@ -145,7 +145,7 @@ std::vector Tilemap::GetActors(int x, int y, int range, Actors type) { return found; } -std::vector* Tilemap::GetActorList() { +std::vector* Tilemap::get_actor_list() { return &actors; } @@ -153,12 +153,12 @@ void Tilemap::draw(Renderer *renderer, Tileset* tileset, int ox, int oy, FieldOf for (int x = 0; x < 32; x++) { for (int y = 0; y < 32; y++) { if (view == nullptr || view->has_seen({x, y})) { - renderer->SetColor(1, 1, 1, 1); - renderer->DrawSprite(tileset->GetSprite(GetTile(x, y)), ox + x * 12, oy + y * 12); + renderer->set_color(1, 1, 1, 1); + renderer->draw_sprite(tileset->get_sprite(GetTile(x, y)), ox + x * 12, oy + y * 12); if (view != nullptr && !view->can_see({x, y})) { - renderer->SetColor(0, 0, 0, .5f); - renderer->DrawSprite(tileset->GetSprite(219), ox + x * 12, oy + y * 12); + renderer->set_color(0, 0, 0, .5f); + renderer->draw_sprite(tileset->get_sprite(219), ox + x * 12, oy + y * 12); } } } diff --git a/src/Tilemap.h b/src/Tilemap.h index 9a2267c..041037b 100644 --- a/src/Tilemap.h +++ b/src/Tilemap.h @@ -20,19 +20,19 @@ public: int GetIndex(int x, int y); // Converts [x,y] to a 1D index. bool IsInsideBounds(int x, int y); std::vector getNeighbours(int x, int y, int range = 1); - void SetTile(int x, int y, int tile); // "Tile" is inteded for tile ids, but can be anything really. + void set_tile(int x, int y, int tile); // "Tile" is inteded for tile ids, but can be anything really. int GetTile(int x, int y); bool IsBlocked(int x, int y); // Checks if there is an actor blocking the tile. void draw(Renderer *renderer, Tileset *tileset, int x, int y, FieldOfView* view); - void AddActor(Actor* actor); + void add_actor(Actor *actor); void RemoveActor(Actor* actor); void debug_print(); Actor* GetActor(int x, int y, Actors type); std::vector GetActors(int x, int y, int range, Actors type); - std::vector* GetActorList(); + std::vector* get_actor_list(); }; diff --git a/src/Tileset.cpp b/src/Tileset.cpp index 3005489..05cc1c4 100644 --- a/src/Tileset.cpp +++ b/src/Tileset.cpp @@ -26,7 +26,7 @@ int Tileset::GetAmount() { return amount; } -Sprite * Tileset::GetSprite(int tileId) { +Sprite * Tileset::get_sprite(int tileId) { if (tileId >= 0 && tileId < amount) { return &sprites[tileId]; } diff --git a/src/Tileset.h b/src/Tileset.h index 33e510a..8ccf7f7 100644 --- a/src/Tileset.h +++ b/src/Tileset.h @@ -12,6 +12,6 @@ public: Tileset(Renderer* renderer, std::string imgPath, int imgWidth, int imgHeight, int tileWidth, int tileHeight); ~Tileset(); int GetAmount(); - Sprite* GetSprite(int tileId); + Sprite* get_sprite(int tileId); }; diff --git a/src/WanderNode.cpp b/src/WanderNode.cpp index 8536fa1..3483265 100644 --- a/src/WanderNode.cpp +++ b/src/WanderNode.cpp @@ -10,7 +10,7 @@ WanderNode::WanderNode(BehaviourTreeNode* parent) : BehaviourTreeNode(parent){} WanderNode::~WanderNode() {} BehaviourTreeStatus WanderNode::tick(BTTick * tick) { - vec2i pos = tick->target->getPosition(); + vec2i pos = tick->target->get_position(); std::vector neighbours = tick->target->map->getNeighbours(pos.x, pos.y); while (true) { if (neighbours.size() <= 0) {