Skip to content

Commit d523c9a

Browse files
committed
Added Character class
1 parent 031654a commit d523c9a

12 files changed

+148
-7
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Each character can face in multiple of 20 degrees up to 180 (9 angles)
2+
Each angle / direction has a set amount of animation frames

res/config.json

Whitespace-only changes.

src/arena/Arena.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace arena {
1111
switch (arena_type)
1212
{
1313
case Training:
14-
arenaFile = "./assets/arena/Bone.png";
14+
arenaFile = "./assets/arena/Training.png";
1515
break;
1616
default:
1717
break;

src/arena/ArenaType.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55

66
#include <string>
77

8-
enum ArenaType
9-
{
10-
Training,
11-
};
8+
namespace arena {
9+
enum ArenaType
10+
{
11+
Training,
12+
};
13+
}
1214

1315
#endif

src/character/Character.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include "Character.h"
2+
3+
namespace character {
4+
Character::Character()
5+
{
6+
this->orientation = static_cast<Orientation>(Random::getInstance().randomIntFromInterval(0, 9));
7+
}
8+
9+
Character::~Character()
10+
{
11+
12+
}
13+
}

src/character/Character.h

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef CHARACTER_H
2+
#define CHARACTER_H
3+
4+
#pragma once
5+
6+
#include "../util/Random.h"
7+
#include "Orientation.h"
8+
9+
namespace character {
10+
class Character
11+
{
12+
public:
13+
Character();
14+
~Character();
15+
16+
private:
17+
Orientation orientation;
18+
};
19+
}
20+
21+
#endif

src/character/CharacterType.h

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef CHARACTERTYPE_H
2+
#define CHARACTERTYPE_H
3+
4+
#pragma once
5+
6+
namespace character {
7+
enum CharacterType
8+
{
9+
Barbarian
10+
};
11+
}
12+
13+
#endif

src/character/Orientation.h

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef ORIENTATION_H
2+
#define ORIENTATION_H
3+
4+
#pragma once
5+
6+
namespace character {
7+
enum Orientation
8+
{
9+
_0,
10+
_20,
11+
_40,
12+
_60,
13+
_80,
14+
_100,
15+
_120,
16+
_140,
17+
_160,
18+
_180,
19+
};
20+
}
21+
22+
#endif

src/data/TowerPosition.h

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef TOWERPOSITION_H
2+
#define TOWERPOSITION_H
3+
4+
#pragma once
5+
6+
class TowerPosition
7+
{
8+
public:
9+
/*static constexpr char TrainingCampTowerPosition[] = {
10+
#include "TrainingCampTowerPosition.json.h"
11+
};*/
12+
};
13+
14+
#endif

src/util/Random.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include "Random.h"
2+
3+
Random::Random()
4+
{
5+
engine = std::mt19937(this->random_device());
6+
}
7+
8+
int Random::randomIntFromInterval(int min, int max)
9+
{
10+
std::uniform_int_distribution<> distr(min, max);
11+
return distr(engine);
12+
}

src/util/Random.h

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <random>
2+
#ifndef RANDOM_H
3+
#define RANDOM_H
4+
5+
#pragma once
6+
7+
class Random
8+
{
9+
public:
10+
Random();
11+
Random(Random const&) = delete;
12+
Random& operator=(Random const&) = delete;
13+
template<class Iterator>
14+
void shuffle(Iterator iterator);
15+
int randomIntFromInterval(int min, int max);
16+
static Random& getInstance() {
17+
static Random instance;
18+
return instance;
19+
}
20+
private:
21+
std::random_device random_device;
22+
std::mt19937 engine;
23+
};
24+
25+
#endif
26+
27+
template<class Iterator>
28+
inline void Random::shuffle(Iterator iterator)
29+
{
30+
std::shuffle(iterator.begin(), iterator.end(), this->engine);
31+
}

xmake.lua

+13-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,23 @@ add_requires("tl_expected")
44

55
target("CR-Battle-Dataset-Generator")
66
set_kind("binary")
7+
add_rules("utils.bin2c", {extensions = {".json"}})
8+
add_packages("skia")
9+
add_packages("tl_expected")
10+
if is_mode("debug") then
11+
set_targetdir("$(buildir)/debug/$(os)/$(arch)")
12+
set_configdir("$(buildir)/debug/$(os)/$(arch)/res")
13+
else
14+
set_targetdir("$(buildir)/release/$(os)/$(arch)")
15+
set_configdir("$(buildir)/release/$(os)/$(arch)/res")
16+
end
717
add_files("src/*.cpp")
818
add_headerfiles("src/*.h")
919
add_files("src/*/*.cpp")
1020
add_headerfiles("src/*/*.h")
11-
add_packages("skia")
12-
add_packages("tl_expected")
21+
-- add_files("res/TowerPosition/*.json")
22+
add_configfiles("res/config.json")
23+
1324
--
1425
-- If you want to known more usage about xmake, please see https://xmake.io
1526
--

0 commit comments

Comments
 (0)