-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap16block.h
214 lines (184 loc) · 4.77 KB
/
map16block.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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#pragma once
#define tile_table_size 14
#define tile_1 0
#define tile_2 2
#define tile_3 4
#define tile_4 6
#define tile_palette_1 8
#define tile_palette_2 9
#define tile_flips 10
#define collision 11
#define act_as_high 12
#define act_as_low 13
#define ram_level_low 0x8000
#define ram_level_high 0xC000
uint_fast8_t map16_entries[0x1C00];
uint_fast8_t spawned_grabbable = 0xFF;
void reset_map()
{
for (int i = ram_level_low; i < ram_level_high; i++) {
RAM[i] = 0x25;
RAM[i + 0x4000] = 0x00;
}
for (int i = 0; i < 0x1000; i++) {
RAM[0x2000 + i] = 0;
}
}
void initialize_map16()
{
string file = path + "Map16/Global.Cmap16";
cout << blue << "[MAP16] Loading " << file << white << endl;
ifstream input(file, ios::binary);
vector<unsigned char> buffer(istreambuf_iterator<char>(input), {});
uint8_t temp[16];
int current_byte = 0;
for (auto &v : buffer)
{
temp[current_byte] = uint8_t(v);
current_byte += 1;
if (current_byte >= 16) {
uint16_t replace_p = temp[1] + temp[0] * 256; //this is actually a thing.
for (int i = 0; i < tile_table_size; i++)
{
map16_entries[(replace_p * tile_table_size) + i] = temp[i + 2];
}
int integer = map16_entries[collision + replace_p * tile_table_size];
current_byte = 0;
}
}
input.close();
}
class map16blockhandler //Map16 loaded block
{
public:
uint_fast16_t tile;
uint_fast16_t act_as;
bool logic[8];
void get_map_16_details()
{
uint_fast16_t entry = (tile & 0x1FF) * tile_table_size;
act_as = map16_entries[entry + act_as_low] + (map16_entries[entry + act_as_high] << 8);
uint_fast8_t integer = map16_entries[entry + collision];
for (uint_fast8_t i = 0; i < 8; i++)
{
logic[i] = ((integer >> (7 - i)) & 1) != 0;
}
if (tile >= 0x166 && tile <= 0x167)
{
bool solid = tile == 0x166 ? (!RAM[0x14AF]) : (RAM[0x14AF]);
logic[0] = solid; logic[1] = solid; logic[2] = solid; logic[3] = solid;
}
}
/*
Update Map Tile
*/
void update_map_tile(uint_fast16_t x, uint_fast16_t y)
{
uint_fast32_t index = (x % mapWidth) + (max(uint_fast16_t(0), min(mapHeight, y)) * mapWidth);
tile = RAM[ram_level_low + index] + (RAM[ram_level_high + index] << 8);
get_map_16_details();
}
/*
Replace Map tile with anything
*/
void replace_map_tile(uint16_t tile, uint_fast16_t x, uint_fast16_t y)
{
uint_fast32_t index = (x % mapWidth) + (max(uint_fast16_t(0), min(mapHeight, y)) * mapWidth);
RAM[ram_level_low + index] = tile & 0xFF; RAM[ram_level_high + index] = tile >> 8;
RAM_decay_time_level[index] = level_ram_decay_time * PlayerAmount;
}
/*
Get ground
*/
double ground_y(double x_relative, uint_fast16_t x, uint_fast16_t y)
{
uint_fast16_t tile = get_tile(x, y);
if (tile == 0x1AA) //45* slope Right
{
if (x_relative <= 0 || x_relative >= 16) { return -9999; }
return x_relative;
}
if (tile == 0x1AF) //45* slope Left
{
if (x_relative <= 0 || x_relative >= 16) { return -9999; }
return 16.0 - x_relative;
}
return 16.0;
}
double ground_s(uint_fast16_t x, uint_fast16_t y)
{
uint_fast16_t tile = get_tile(x, y);
if (tile == 0x1AA || tile == 0x1AF) //45* slope Right/Left
{
return 17.0;
}
return 15.0;
}
/*
Check if a tile is sloped
*/
uint_fast8_t get_slope(uint_fast16_t x, uint_fast16_t y)
{
if (tile == 0x1AA) { return 1; }
if (tile == 0x1AF) { return 2; }
return 0;
}
/*
Process block hit.
*/
void process_block(uint_fast16_t x, uint_fast16_t y, uint8_t side, bool pressing_y = false)
{
if (!networking || !isClient)
{
uint_fast32_t index = (x % mapWidth) + (y * mapWidth);
uint_fast16_t t = RAM[ram_level_low + index] + (RAM[ram_level_high + index] << 8);
if (t == 0x0124 && side == bottom)
{
replace_map_tile(0x0132, x, y);
}
if (t == 0x011F && side == bottom)
{
replace_map_tile(0x0132, x, y);
x *= 16;
y *= 16;
uint_fast8_t spr = spawnSpriteJFKMarioWorld(0x74, 5, x, y + 8, 1, true);
RAM[0x2480 + spr] = 0x20;
}
if (t == 0x0112 && side == bottom)
{
RAM[0x14AF] = !RAM[0x14AF];
RAM[0x1DF9] = 0xB;
}
if (t == 0x0038)
{
replace_map_tile(0x0025, x, y);
RAM[0x1DF9] = 5;
ASM.Write_To_Ram(0x3F0B, x * 16, 2);
ASM.Write_To_Ram(0x3F0D, y * 16, 2);
midway_activated = true;
}
if (t == 0x002B)
{
replace_map_tile(0x0025, x, y);
RAM[0x1DFC] = 1;
RAM[0x0DBF] += 1;
}
if (t == 0x012E && pressing_y)
{
replace_map_tile(0x0025, x, y);
x *= 16;
y *= 16;
spawned_grabbable = spawnSpriteJFKMarioWorld(0x53, 2, x, y, 0, true);
}
}
}
/*
Get tile on map.
*/
uint_fast16_t get_tile(uint_fast16_t x, uint_fast16_t y)
{
uint_fast32_t index = (x % mapWidth) + (max(uint_fast16_t(0),min(mapHeight-1,y)) * mapWidth);
return RAM[ram_level_low + index] + (RAM[ram_level_high + index] << 8);
}
};
map16blockhandler map16_handler;