-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpringLink.cpp
More file actions
56 lines (41 loc) · 1.65 KB
/
Copy pathSpringLink.cpp
File metadata and controls
56 lines (41 loc) · 1.65 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
////////////////////////////////////// INCLUDES & FORWARDS /////////////////////////////////////////////
#include "SpringLink.h"
#include "Spring.h"
#include "Room.h"
#include "Renderer.h"
////////////////////////////////////////// Constructor /////////////////////////////////////////////
SpringLink::SpringLink(const Point &pos, Spring *parent, int index)
: StaticObject(pos, '#', ObjectType::SPRING_LINK),
parentSpring(parent), linkIndex(index), collapsed(false) {}
////////////////////////////////////////// clone /////////////////////////////////////////////
GameObject *SpringLink::clone() const { return new SpringLink(*this); }
////////////////////////////////////////// onExplosion /////////////////////////////////////////////
bool SpringLink::onExplosion() {
if (parentSpring) parentSpring->destroyAllLinks();
return true;
}
////////////////////////////////////////// collapse /////////////////////////////////////////////
void SpringLink::collapse(Room *room) {
if (collapsed) return;
collapsed = true;
sprite = ' ';
if (room != nullptr)
{
room->setCharAt(getX(), getY(), sprite);
Renderer::printAt(getX(), getY(), sprite);
Renderer::flush();
}
}
////////////////////////////////////////// reset /////////////////////////////////////////////
void SpringLink::reset(Room *room)
{
if (!collapsed) return;
collapsed = false;
sprite = '#';
if (room != nullptr)
{
room->setCharAt(getX(), getY(), sprite);
Renderer::printAt(getX(), getY(), sprite);
Renderer::flush();
}
}