forked from mloc/tile-thing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
atoms.cpp
59 lines (51 loc) · 1.19 KB
/
atoms.cpp
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
#include <SFML/Graphics.hpp>
#include <string>
#include <vector>
#include "important.hpp"
#include "atoms.hpp"
#include <memory>
using namespace std;
std::vector<atom> objList;
void atom::loadTexture()
{
this->spr.setTexture(*(this->Texture));
this->spr.setTextureRect(this->coords);
}
atom::atom(sf::Texture * ts, sf::IntRect coords)
{
this->setup(ts, coords, 0);
}
atom::atom(sf::Texture * ts, sf::IntRect coords, bool dens)
{
this->setup(ts, coords, dens);
}
void atom::setup(sf::Texture * ts, sf::IntRect coords, bool dens)
{
this->coords = coords;
this->texrend = 0;
this->density = dens;
this->Texture = ts;
objList.push_back(*this);
}
bool atom::move(signed int xmove, signed int ymove)
{
static vector<atom>::iterator iter;
for(iter=objList.begin(); iter != objList.end(); iter++)
{
if((iter->x == (this->x+xmove)) && (iter->y == this->y+ymove))
{
if(iter->density)
{
return 0;
}
}
}
this -> x += xmove;
this -> y += ymove;
this -> posFromCoords();
return 1;
}
void atom::posFromCoords()
{
this->spr.setPosition((this->x)*tile_x, (this->y)*tile_y);
}