-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameObject.cpp
More file actions
99 lines (89 loc) · 2.21 KB
/
Copy pathGameObject.cpp
File metadata and controls
99 lines (89 loc) · 2.21 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
91
92
93
94
95
96
97
98
99
////////////////////////////////////// INCLUDES & FORWARDS /////////////////////////////////////////////
#include "GameObject.h"
#include "Bomb.h"
#include "Door.h"
#include "Items.h"
#include "Riddle.h"
#include "StaticObjects.h"
#include "Switch.h"
class Player;
////////////////////////////////////////// createObjectFromChar /////////////////////////////////////////////
GameObject *createObjectFromChar(char ch, int x, int y, int riddleId)
{
Point pos(x, y, 0, 0, ch);
static int nextRiddleId = 0;
switch (ch)
{
case 'K':
return new Key(pos);
case '@':
return new Bomb(pos);
case '!':
return new Torch(pos);
case '\\':
return new Switch(pos, false);
case '/':
return new Switch(pos, true);
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
return new Door(pos, ch - '0');
case 'w':
return new BreakableWall(pos);
case 'Z':
return new SwitchWall(pos);
case '?':
{
int id = (riddleId >= 0) ? riddleId : nextRiddleId++;
return new Riddle(pos, id);
}
default:
return nullptr;
}
}
// ... (existing code)
////////////////////////////////////////// draw //////////////////////////////////////////
void GameObject::draw() const
{
if (!active || position.getX() < 0 || position.getY() < 0) return;
switch (type)
{
case ObjectType::WALL:
case ObjectType::BREAKABLE_WALL:
case ObjectType::SWITCH_WALL:
set_color(Color::White);
break;
case ObjectType::TORCH:
set_color(Color::LightYellow);
break;
case ObjectType::BOMB:
set_color(Color::Green);
break;
case ObjectType::KEY:
case ObjectType::SWITCH_ON:
case ObjectType::SWITCH_OFF:
set_color(Color::LightPurple);
break;
case ObjectType::DOOR:
set_color(Color::Purple);
break;
case ObjectType::RIDDLE:
set_color(Color::LightBlue);
break;
case ObjectType::SPRING:
case ObjectType::OBSTACLE_BLOCK:
set_color(Color::Gray);
break;
default:
break;
}
Renderer::printAt(position.getX(), position.getY(), sprite);
reset_color();
}