81 lines
2.1 KiB
C++
81 lines
2.1 KiB
C++
#include <catch2/catch_test_macros.hpp>
|
|
#include <fmt/core.h>
|
|
#include "game/systems.hpp"
|
|
#include <cmath>
|
|
#include <numbers>
|
|
#include "game/registry.hpp"
|
|
|
|
using components::Position;
|
|
|
|
TEST_CASE("figure out best rotation direction", "[systems-rotate]") {
|
|
Matrix map = matrix::make(3, 3);
|
|
|
|
Point player_at{1, 1};
|
|
map[player_at.y][player_at.x] = 2;
|
|
|
|
|
|
for(matrix::box target{map, player_at.x, player_at.y, 1}; target.next();) {
|
|
for(matrix::box aiming_at{map, player_at.x, player_at.y, 1}; aiming_at.next();) {
|
|
map[aiming_at.y][aiming_at.x] = 10;
|
|
|
|
float target_dx = float(player_at.x) - float(target.x);
|
|
float target_dy = float(player_at.y) - float(target.y);
|
|
float aiming_dx = float(player_at.x) - float(aiming_at.x);
|
|
float aiming_dy = float(player_at.y) - float(aiming_at.y);
|
|
|
|
float target_angle = atan2(-target_dy, target_dx) * (180.0 / std::numbers::pi);
|
|
float aiming_angle = atan2(-aiming_dy, aiming_dx) * (180.0 / std::numbers::pi);
|
|
|
|
float diff = target_angle - aiming_angle;
|
|
double normalized = fmod(diff + 360.0, 360.0);
|
|
|
|
REQUIRE(normalized >= 0);
|
|
REQUIRE(normalized <= 360);
|
|
|
|
map[aiming_at.y][aiming_at.x] = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void test_moving(Position& move_to) {
|
|
fmt::println("MOVING: {},{}", move_to.location.x, move_to.location.y);
|
|
}
|
|
|
|
void test_combat(int attack_id) {
|
|
fmt::println("ATTACK: {}", attack_id);
|
|
}
|
|
|
|
void test_render() {
|
|
fmt::println("RENDER");
|
|
}
|
|
|
|
void test_update() {
|
|
fmt::println("UPDATE");
|
|
}
|
|
|
|
void test_use_item(const std::string& slot_name) {
|
|
fmt::println("USE ITEM {}", slot_name);
|
|
}
|
|
|
|
void test_pickup() {
|
|
fmt::println("PICKUP");
|
|
}
|
|
|
|
TEST_CASE("new system running engine thing", "[systems-engine]") {
|
|
System::Registry systems;
|
|
|
|
systems.addMoving(test_moving);
|
|
systems.addCombat(test_combat);
|
|
systems.addRender(test_render);
|
|
systems.addUpdate(test_update);
|
|
systems.addUseItem(test_use_item);
|
|
systems.addPickup(test_pickup);
|
|
|
|
systems.runCombat(1);
|
|
systems.runMoving({1,1});
|
|
systems.runRender();
|
|
systems.runUpdate();
|
|
systems.runUseItem("hand_l");
|
|
systems.runPickup();
|
|
}
|