-
Notifications
You must be signed in to change notification settings - Fork 0
/
databattle.h
149 lines (129 loc) · 3.49 KB
/
databattle.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#ifndef __DATABATTLE_SFML_H__
#define __DATABATTLE_SFML_H__
#include <SFML/Graphics.hpp>
#include <cmath>
#include <vector>
#include <list>
#include <iostream>
/*#define MAX_GRID_W 16
#define MAX_GRID_H 16
#define OFFSET(x, y) ((y & 0xF) + ((x & 0xF)*0x100))
#define LOBYTE(a) (a & 0xF)
#define HIBYTE(a) ((a & 0xF0) >> 8)
void _setBit(BYTE& b, short index, bool setToWhat) {
if (index > 7) return;
int n = pow(2, index);
if (setToWhat) b |= n;
else b &= 0xFF-n;
}
bool _isBit(BYTE b, short index, bool what) {
if (index > 7) return;
b &= pow(2, index);
return !(b == 0);
}
BYTE currentGrid[(MAX_GRID_W/8)*MAX_GRID_H] = {(BYTE) 255};
bool LoadGrid(HEADERINFO* hi, TILEINFO* ti, int numOfTiles) {
int rowOffset = hi->yoff;
for (int i=0; i<numOfTiles; i++) {
if (
if (ti[i].progID == PID_NONE) {
setBit(currentGrid[(i/8)+(int) rowOffset*(MAX_GRID_WIDTH/8)], i%8, 0);
}
}
}*/
class ProgramTile;
class ProgramHead;
class ProgramTail;
class Databattle;
class ProgramTile
{
friend class Databattle;
static const unsigned pixelsPerGrid;
protected:
static sf::Texture heads;
static sf::Texture tails;
sf::Vector2i imgCoords;
bool isTail;
void* sourceObject;
public:
static bool loadHeadTexture(const char* filename);
static bool loadTailTexture(const char* filename);
ProgramTile();
void setImgCoords(unsigned x, unsigned y);
void setSourceObj(void* obj);
};
class ProgramHead
{
friend class Databattle;
protected:
unsigned progID;
int move;
int maxSize;
int currSize;
ProgramTail* tail;
public:
ProgramHead();
ProgramHead& setID(unsigned id);
ProgramHead& setMove(int mov);
ProgramHead& setMaxSize(int max);
void decrementMove();
void decreaseMove(unsigned num);
unsigned getID();
unsigned getMove();
unsigned getMaxSize();
unsigned getCurrSize();
};
class ProgramTail
{
friend class ProgramHead;
protected:
ProgramHead* head;
ProgramTail* next; //towards head
ProgramTail* prev; //away from head
public:
ProgramTail();
ProgramTail(ProgramHead& prog);
};
class Databattle
{
protected:
static sf::Texture environ;
sf::Sprite progSprite;
sf::Sprite envSprite;
sf::Vector2f gridCoords;
sf::RenderWindow wnd;
std::vector<bool> grid;
std::vector<ProgramTile*> progTiles;
std::vector<bool> indicators;
sf::Vector2f selected;
unsigned cells_h;
int indicator_rng;
unsigned indicators_h;
void drawGrid();
void drawProgs();
void drawEnv();
void drawFX();
void draw();
bool checkBounds(int cellX, int cellY);
int cellsToIndex(unsigned cellX, unsigned cellY);
int cellsToIndex(unsigned cellX, unsigned cellY, unsigned gridWidth);
sf::Vector2i indexToCells(unsigned index);
sf::Vector2i indexToCells(unsigned index, unsigned gridWidth);
sf::Vector2i mouseToGrid(int mouseX, int mouseY);
void makeRange(unsigned range);
void correctRange();
sf::Vector2f correctGridCoord(int cellX, int cellY);
sf::Vector2i uncorrectGridCoord(sf::Vector2f coords);
public:
static bool loadEnvironmentTexture(const char* filename);
Databattle(unsigned cells_hor);
void begin();
void addTile(bool tile);
void addProg(ProgramTile* prog);
ProgramTile* getProg(unsigned cellX, unsigned cellY);
bool checkSolidAndEmpty(unsigned cellX, unsigned cellY);
bool setProgramPos(ProgramTile** prog, unsigned cellX, unsigned cellY);
bool setTile(unsigned cellX, unsigned cellY, bool value);
bool setProgTile(unsigned cellX, unsigned cellY, ProgramTile* prog);
};
#endif