Arch Game Engine  0.2
tileset.cpp
1 #include "tileset.h"
2 
3 Tileset::Tileset() {
4 }
5 Tileset::~Tileset() {}
6 
7 vector<Tile> Tileset::create(string name, string img, SDL_Renderer* ren, int width, int height, int r, int count) {
8  create(1, name, img, ren, width, height, r, count);
9  return tiles;
10 }
11 vector<Tile> Tileset::create(string name, string img, SDL_Renderer* ren, int width, int height, int r, int rcount, int count) {
12  create(1, name, img, ren, width, height, r, rcount, count);
13  return tiles;
14 }
15 vector<Tile> Tileset::create(int startid, string name, string img, SDL_Renderer* ren, int width, int height, int r, int count) {
16  create(startid, name, img, ren, width, height, r, count, count);
17  return tiles;
18 }
19 vector<Tile> Tileset::create(int startid, string name, string img, SDL_Renderer* ren, int width, int height, int r, int rcount, int count) {
20  int tag = 0;
21  for(int i=0; i<r; i++) {
22  for(int j=0; j<rcount; j++) {
23  addTile(name, img, ren, tag+startid, i+1, j+1, width, height);
24  tag++;
25  if(tag>count) { break; }
26  }
27  if(tag>count) break;
28  }
29  return tiles;
30 }
31 
33  tiles.push_back(t);
34 }
35 Tile Tileset::addTile(string name, string file, SDL_Renderer* ren, int value, int c, int r, int width, int height) {
36  Tile tmp;
37  tmp.setName(name);
38  tmp.setFrame(((r-1)*width), ((c-1)*height), width, height);
39  tmp.setDestSize(width, height);
40  tmp.setPosSize(width, height);
41  tmp.setImage(file, ren);
42  tmp.setValue(value);
43  addTile(tmp);
44  return tmp;
45 }
46 Tile Tileset::addTile(string name, string file, SDL_Renderer* ren, int value, int width, int height) {
47  Tile tmp = addTile(name, file, ren, value, 1, value, width, height);
48  return tmp;
49 }
50 Tile Tileset::addTile(string name, string file, SDL_Renderer* ren, int value, int size) {
51  Tile tmp = addTile(name, file, ren, value, 1, value, size, size);
52  return tmp;
53 }
54 
55 void Tileset::setAngle(int ang) {
56  for(int i=0; i<tiles.size(); i++) {
57  tiles[i].setAngle(ang);
58  }
59 }
60 
61 void Tileset::setSolid() {
62  setSolid(1, tiles.size()+1);
63 }
64 void Tileset::setSolid(int t) {
65  tiles[t].setSolid();
66 }
67 void Tileset::setSolid(int s, int e) {
68  for(int i=s; i<(e+1); i++) {
69  setSolid(i);
70  }
71 }
72 
73 void Tileset::setPassable() {
74  setPassable(1, tiles.size()+1);
75 }
76 void Tileset::setPassable(int t) {
77  tiles[t].setPassable();
78 }
79 void Tileset::setPassable(int s, int e) {
80  for(int i=s; i<(e+1); i++) {
81  setPassable(i);
82  }
83 }
84 
85 void Tileset::setName(string n, int id) {
86  tiles[id].setName(n);
87 }
void setImage(Image i)
Set the Object&#39;s Image with a given Image.
Definition: object.h:56
void setValue(int v)
Set value of the tile. This is used when reading from a map file, etc.
Definition: tile.cpp:5
void setFrame(SDL_Rect i)
Set the frame with a given SDL_Rect.
Definition: object.h:72
vector< Tile > create(string name, string img, SDL_Renderer *ren, int width, int height, int r, int count)
Load in a map file with the name for all the tiles, the path to the map file, path to the tileset ima...
Definition: tileset.cpp:7
void addTile(Tile t)
Push Tile in tile with given Tile.
Definition: tileset.cpp:32
An Object class that stores the a tile value and name.
Definition: tile.h:7
void setAngle(int ang)
Set the angle of all the tiles. Calls pushAng().
Definition: tileset.cpp:55