-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMap.cpp
More file actions
90 lines (80 loc) · 1.53 KB
/
Map.cpp
File metadata and controls
90 lines (80 loc) · 1.53 KB
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
#include "Map.h"
#include <string>
#include <fstream>
#include <iostream>
#include <list>
#include "Block.h"
#include "Color.h"
Map::Map(const std::string& filename, float origin_x, float origin_y) : Point(origin_x, origin_y)
{
ReadMapFromFile(filename);
}
bool Map::Intersects(const Rectangle& r)
{
for(const Block& b : blocks)
{
if(r.Intersects(b.GetRect()))
{
return true;
}
}
return false;
}
void Map::Tick()
{
for(Block& b : blocks)
{
b.Tick();
}
}
void Map::Render()
{
for(Block& b : blocks)
{
b.Render();
}
}
void Map::ReadMapFromFile(const std::string& filename)
{
std::ifstream fin(filename);
char buf;
int w, h;
fin >> w >> h;
buf = fin.get();
for(int i = h; i > 0; i--)
{
for(int j = 0; j <= w; j++)
{
buf = fin.get();
switch(buf)
{
case '1': blocks.push_back(Block(j - x, i - y, 0.8f, 0.8f, Color(77, 77, 77), false)); //undestructible wall
break;
case '2': blocks.push_back(Block(j - x, i - y, 0.8f, 0.8f, Color(25, 212, 0), false)); //undestructible player
break;
case '3': blocks.push_back(Block(j - x, i - y, 0.8f, 0.8f, Color(179, 179, 179), true, 1)); //destructinble wall
break;
case '4': blocks.push_back(Block(j - x, i - y, 0.8f, 0.8f, Color(255, 76, 5), true, 3)); //undestructible enemy
break;
}
}
}
fin.close();
}
void Map::Translate(float x, float y)
{
for(Block& b : blocks)
{
b.Translate(x, y);
}
}
std::list<Block>& Map::GetBlocks()
{
return blocks;
}
void Map::Keyboard(int key)
{
}
void Map::SpecialKeyboard(int key)
{
}