-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTile.cpp
56 lines (49 loc) · 1013 Bytes
/
Tile.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
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include "Tile.h"
#include "collision.h"
#include "TileAtlas.h"
#include "Game.h"
Tile::Tile(LTexture &texture, LGame &game, int x, int y, int width, int height, int tileID) : mTexture(texture), mGame(game)
{
// Get the offsets
mBox.x = x;
mBox.y = y;
// Set the collision box
mBox.w = width;
mBox.h = height;
// Get the tile id
mID = tileID ;
mType = -1 ;
}
int Tile::render(SDL_Renderer *renderer, SDL_Rect &camera)
{
// If the tile is on screen
if (checkCollision(camera, mBox))
{
// Show the tile
SDL_Rect clipRect = mGame.getTileClip(mID);
mTexture.render(renderer, mBox.x - camera.x, mBox.y - camera.y, &clipRect);
}
return 0;
}
void Tile :: setType( int type )
{
this-> mType = type ;
}
int Tile :: getType( )
{
return mType;
}
int Tile::getID()
{
return mID;
}
SDL_Rect Tile::getBox()
{
return mBox;
}
void Tile::cleanUp()
{
mTexture.free();
}