-
Notifications
You must be signed in to change notification settings - Fork 0
/
terrain.h
61 lines (58 loc) · 1.17 KB
/
terrain.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
#pragma once
#include <fstream>
#include <string>
#include <sstream>
#include "constants.h"
#include "texture.h"
#include "gameTexture.h"
int mapT[nRow][nCol];
void loadMap()
{
std::ifstream map("assets/map.csv");
std::string line,dat;
int i=0,j=0;
while(getline(map,line))
{
std::stringstream s(line);
while(getline(s,dat,','))
{
mapT[i][j]=atoi(dat.c_str());
j++;
}
i++;
j=0;
}
}
/*
class terrain
{
public:
terrain(int x,int y,int type);
void render(SDL_Renderer* renderer);
private:
int x,y;
int type;
};
terrain::terrain(int x=0,int y=0,int type=0)
{
this->x = x;
this->y = y;
this->type = type;
}
void terrain::render(SDL_Renderer* renderer)
{
tile.render(renderer,&tType[type],x,y);
}*/
SDL_Rect tType[3] = {{0,0,40,40},{40,0,40,40},{80,0,40,40}};
void renderTerrain(SDL_Renderer* renderer)
{
for(int i=0;i<nRow;i++)
{
for(int j=0;j<nCol;j++)
{
/*terrain t(j*tSize,i*tSize,mapT[i][j]);
t.render(renderer);*/
tile.render(renderer,&tType[mapT[i][j]],j*tSize,i*tSize,tSize,tSize);
}
}
}