/
misc.c++
147 lines (122 loc) · 3.29 KB
/
misc.c++
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
void Door::before_move () {
if (rata->floor)
rata->propose_action(Rata::action_enter, this, pos, 1);
}
Door::Door (room::Def* loc, Vec pos, room::Def* destloc, Vec destpos) :
Spatial(type::door, loc, pos),
destloc(destloc),
destpos(destpos)
{ }
struct Crate : Object {
virtual char* describe () { return "There's a wooden crate sitting here.\x80\nIt looks like it can be pushed around."; }
virtual void damage (int d) { Object::damage(d); snd::def[snd::woodhit].play(); }
Crate (room::Def* loc, Vec pos, Vec vel = Vec(0, 0)) : Object(type::crate, loc, pos, vel) {
life = max_life = 144;
}
};
struct Heart : Object {
virtual char* describe () { return "Just as rats live off the refuse of humans,\x80\nYou too can live off of the rats.\x80\nPick this up to restore one heart."; }
Heart (room::Def* loc, Vec pos, Vec vel = Vec(0, 0)) : Object(type::heart, loc, pos, vel) { }
};
struct TileLayer : Actor {
void draw () {
int minx = floor(camera.x - screen.x/2);
int miny = floor(camera.y - screen.y/2);
int maxx = ceil(camera.x + screen.x/2);
int maxy = ceil(camera.y + screen.y/2);
for (int x=minx; x < maxx; x++)
for (int y=miny; y < maxy; y++) {
int tile = map::at(x, y).tile1;
if (tile) {
bool fliph = tile & 0x8000;
bool flipv = tile & 0x4000;
tile &= 0x3fff;
if (type == type::front_tiles ? tile::def[tile].front : tile::def[tile].back) {
draw::image(
img::tiles,
Vec(x+.5, y+.5),
tile, fliph, flipv
);
}
}
tile = map::at(x, y).tile2;
if (tile) {
bool fliph = tile & 0x8000;
bool flipv = tile & 0x4000;
tile &= 0x3fff;
if (type == type::front_tiles ? tile::def[tile].front : tile::def[tile].back) {
draw::image(
img::tiles,
Vec(x+.5, y+.5),
tile, fliph, flipv
);
}
}
}
}
TileLayer (int16 type) : Actor(type) { }
};
struct BulletLayer : Actor {
void draw () {
for (uint i=0; i < MAX_BULLETS; i++) {
bullets[i].draw();
}
}
BulletLayer () : Actor(type::bullet_layer) { }
};
struct CursorLayer : Actor {
void draw () {
if (draw_cursor) {
float ax = rata->aim_center().x;
float ay = rata->aim_center().y;
float cx = cursor.x;
float cy = cursor.y;
if (cx+ax > camera.x + screen.x/2) {
cy *= (camera.x + screen.x/2 - ax) / cx;
cx = camera.x + screen.x/2 - ax;
}
else if (cx+ax < camera.x - screen.x/2) {
cy *= (camera.x - screen.x/2 - ax) / cx;
cx = camera.x - screen.x/2 - ax;
}
if (cy+ay > camera.y + screen.y/2) {
cx *= (camera.y + screen.y/2 - ay) / cy;
cy = camera.y + screen.y/2 - ay;
}
else if (cy+ay < camera.y - screen.y/2) {
cx *= (camera.y - screen.y/2 - ay) / cy;
cy = camera.y - screen.y/2 - ay;
}
draw::image(cursor_img, Vec(cx+ax, cy+ay));
}
}
CursorLayer () : Actor(type::cursor_layer) { }
};
struct Shade : Spatial {
Vec pos;
Vec size;
Color color;
void draw () {
draw::rect(
Rect(pos, pos + size),
color
);
}
Shade (room::Def* loc, Vec pos, Vec size, Color color) :
Spatial(type::shade, loc, pos),
size(size),
color(color)
{ }
};
struct BGColor : Spatial {
Vec size;
Color color;
void draw () {
draw::rect(Rect(pos, pos + size), color);
}
BGColor (room::Def* loc, Vec pos, Vec size, Color color) :
Spatial(type::bg_color, loc, pos),
size(size),
color(color)
{ }
};