yaze 0.2.0
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
sprite.h
Go to the documentation of this file.
1#ifndef YAZE_APP_ZELDA3_SPRITE_H
2#define YAZE_APP_ZELDA3_SPRITE_H
3
4#include <SDL.h>
5
6#include <cstdint>
7#include <string>
8#include <vector>
9
10#include "app/zelda3/common.h"
12
13namespace yaze {
14namespace app {
15namespace zelda3 {
16
17static const std::string kSpriteDefaultNames[]{
18 "00 Raven",
19 "01 Vulture",
20 "02 Flying Stalfos Head",
21 "03 No Pointer (Empty",
22 "04 Pull Switch (good",
23 "05 Pull Switch (unused",
24 "06 Pull Switch (bad",
25 "07 Pull Switch (unused",
26 "08 Octorock (one way",
27 "09 Moldorm (Boss",
28 "0A Octorock (four way",
29 "0B Chicken",
30 "0C Octorock (?",
31 "0D Buzzblock",
32 "0E Snapdragon",
33 "0F Octoballoon",
34 "10 Octoballon Hatchlings",
35 "11 Hinox",
36 "12 Moblin",
37 "13 Mini Helmasaure",
38 "14 Gargoyle's Domain Gate",
39 "15 Antifairy",
40 "16 Sahasrahla / Aginah",
41 "17 Bush Hoarder",
42 "18 Mini Moldorm",
43 "19 Poe",
44 "1A Dwarves",
45 "1B Arrow in wall",
46 "1C Statue",
47 "1D Weathervane",
48 "1E Crystal Switch",
49 "1F Bug-Catching Kid",
50 "20 Sluggula",
51 "21 Push Switch",
52 "22 Ropa",
53 "23 Red Bari",
54 "24 Blue Bari",
55 "25 Talking Tree",
56 "26 Hardhat Beetle",
57 "27 Deadrock",
58 "28 Storytellers",
59 "29 Blind Hideout attendant",
60 "2A Sweeping Lady",
61 "2B Storytellers",
62 "2C Lumberjacks",
63 "2D Telepathic Stones",
64 "2E Multipurpose Sprite",
65 "2F Race Npc",
66 "30 Person?",
67 "31 Fortune Teller",
68 "32 Angry Brothers",
69 "33 Pull for items",
70 "34 Scared Girl",
71 "35 Innkeeper",
72 "36 Witch",
73 "37 Waterfall",
74 "38 Arrow Target",
75 "39 Average Middle",
76 "3A Half Magic Bat",
77 "3B Dash Item",
78 "3C Village Kid",
79 "3D Signs? Chicken lady also showed up / Scared ladies outside houses.",
80 "3E Rock Hoarder",
81 "3F Tutorial Soldier",
82 "40 Lightning Lock",
83 "41 Blue Sword Soldier / Used by guards to detect player",
84 "42 Green Sword Soldier",
85 "43 Red Spear Soldier",
86 "44 Assault Sword Soldier",
87 "45 Green Spear Soldier",
88 "46 Blue Archer",
89 "47 Green Archer",
90 "48 Red Javelin Soldier",
91 "49 Red Javelin Soldier 2",
92 "4A Red Bomb Soldiers",
93 "4B Green Soldier Recruits",
94 "4C Geldman",
95 "4D Rabbit",
96 "4E Popo",
97 "4F Popo 2",
98 "50 Cannon Balls",
99 "51 Armos",
100 "52 Giant Zora",
101 "53 Armos Knights (Boss",
102 "54 Lanmolas (Boss",
103 "55 Fireball Zora",
104 "56 Walking Zora",
105 "57 Desert Palace Barriers",
106 "58 Crab",
107 "59 Bird",
108 "5A Squirrel",
109 "5B Spark (Left to Right",
110 "5C Spark (Right to Left",
111 "5D Roller (vertical moving",
112 "5E Roller (vertical moving",
113 "5F Roller",
114 "60 Roller (horizontal moving",
115 "61 Beamos",
116 "62 Master Sword",
117 "63 Devalant (Non",
118 "64 Devalant (Shooter",
119 "65 Shooting Gallery Proprietor",
120 "66 Moving Cannon Ball Shooters (Right",
121 "67 Moving Cannon Ball Shooters (Left",
122 "68 Moving Cannon Ball Shooters (Down",
123 "69 Moving Cannon Ball Shooters (Up",
124 "6A Ball N' Chain Trooper",
125 "6B Cannon Soldier",
126 "6C Mirror Portal",
127 "6D Rat",
128 "6E Rope",
129 "6F Keese",
130 "70 Helmasaur King Fireball",
131 "71 Leever",
132 "72 Activator for the ponds (where you throw in items",
133 "73 Uncle / Priest",
134 "74 Running Man",
135 "75 Bottle Salesman",
136 "76 Princess Zelda",
137 "77 Antifairy (Alternate",
138 "78 Village Elder",
139 "79 Bee",
140 "7A Agahnim",
141 "7B Agahnim Energy Ball",
142 "7C Hyu",
143 "7D Big Spike Trap",
144 "7E Guruguru Bar (Clockwise",
145 "7F Guruguru Bar (Counter Clockwise",
146 "80 Winder",
147 "81 Water Tektite",
148 "82 Antifairy Circle",
149 "83 Green Eyegore",
150 "84 Red Eyegore",
151 "85 Yellow Stalfos",
152 "86 Kodongos",
153 "87 Flames",
154 "88 Mothula (Boss",
155 "89 Mothula's Beam",
156 "8A Spike Trap",
157 "8B Gibdo",
158 "8C Arrghus (Boss",
159 "8D Arrghus spawn",
160 "8E Terrorpin",
161 "8F Slime",
162 "90 Wallmaster",
163 "91 Stalfos Knight",
164 "92 Helmasaur King",
165 "93 Bumper",
166 "94 Swimmers",
167 "95 Eye Laser (Right",
168 "96 Eye Laser (Left",
169 "97 Eye Laser (Down",
170 "98 Eye Laser (Up",
171 "99 Pengator",
172 "9A Kyameron",
173 "9B Wizzrobe",
174 "9C Tadpoles",
175 "9D Tadpoles",
176 "9E Ostrich (Haunted Grove",
177 "9F Flute",
178 "A0 Birds (Haunted Grove",
179 "A1 Freezor",
180 "A2 Kholdstare (Boss",
181 "A3 Kholdstare's Shell",
182 "A4 Falling Ice",
183 "A5 Zazak Fireball",
184 "A6 Red Zazak",
185 "A7 Stalfos",
186 "A8 Bomber Flying Creatures from Darkworld",
187 "A9 Bomber Flying Creatures from Darkworld",
188 "AA Pikit",
189 "AB Maiden",
190 "AC Apple",
191 "AD Lost Old Man",
192 "AE Down Pipe",
193 "AF Up Pipe",
194 "B0 Right Pip",
195 "B1 Left Pipe",
196 "B2 Good bee again?",
197 "B3 Hylian Inscription",
198 "B4 Thief?s chest (not the one that follows you",
199 "B5 Bomb Salesman",
200 "B6 Kiki",
201 "B7 Maiden following you in Blind Dungeon",
202 "B8 Monologue Testing Sprite",
203 "B9 Feuding Friends on Death Mountain",
204 "BA Whirlpool",
205 "BB Salesman / chestgame guy / 300 rupee giver guy / Chest game thief",
206 "BC Drunk in the inn",
207 "BD Vitreous (Large Eyeball",
208 "BE Vitreous (Small Eyeball",
209 "BF Vitreous' Lightning",
210 "C0 Monster in Lake of Ill Omen / Quake Medallion",
211 "C1 Agahnim teleporting Zelda to dark world",
212 "C2 Boulders",
213 "C3 Gibo",
214 "C4 Thief",
215 "C5 Medusa",
216 "C6 Four Way Fireball Spitters (spit when you use your sword",
217 "C7 Hokku",
218 "C8 Big Fairy who heals you",
219 "C9 Tektite",
220 "CA Chain Chomp",
221 "CB Trinexx",
222 "CC Another part of trinexx",
223 "CD Yet another part of trinexx",
224 "CE Blind The Thief (Boss)",
225 "CF Swamola",
226 "D0 Lynel",
227 "D1 Bunny Beam",
228 "D2 Flopping fish",
229 "D3 Stal",
230 "D4 Landmine",
231 "D5 Digging Game Proprietor",
232 "D6 Ganon",
233 "D7 Copy of Ganon",
234 "D8 Heart",
235 "D9 Green Rupee",
236 "DA Blue Rupee",
237 "DB Red Rupee",
238 "DC Bomb Refill (1)",
239 "DD Bomb Refill (4)",
240 "DE Bomb Refill (8)",
241 "DF Small Magic Refill",
242 "E0 Full Magic Refill",
243 "E1 Arrow Refill (5)",
244 "E2 Arrow Refill (10)",
245 "E3 Fairy",
246 "E4 Key",
247 "E5 Big Key",
248 "E6 Shield",
249 "E7 Mushroom",
250 "E8 Fake Master Sword",
251 "E9 Magic Shop dude / His items",
252 "EA Heart Container",
253 "EB Heart Piece",
254 "EC Bushes",
255 "ED Cane Of Somaria Platform",
256 "EE Mantle",
257 "EF Cane of Somaria Platform (Unused)",
258 "F0 Cane of Somaria Platform (Unused)",
259 "F1 Cane of Somaria Platform (Unused)",
260 "F2 Medallion Tablet",
261 "F3",
262 "F4 Falling Rocks",
263 "F5",
264 "F6",
265 "F7",
266 "F8",
267 "F9",
268 "FA",
269 "FB",
270 "FC",
271 "FD",
272 "FE",
273 "FF",
274};
275
280class Sprite : public GameEntity {
281 public:
282 Sprite() = default;
283 Sprite(std::vector<uint8_t> src, uint8_t overworld_map_id, uint8_t id,
284 uint8_t x, uint8_t y, int map_x, int map_y)
285 : map_id_(static_cast<int>(overworld_map_id)),
286 id_(id),
287 nx_(x),
288 ny_(y),
289 map_x_(map_x),
290 map_y_(map_y),
291 current_gfx_(src) {
293 entity_id_ = id;
294 x_ = map_x_;
295 y_ = map_y_;
296 overworld_ = true;
297 name_ = kSpriteDefaultNames[id];
298 preview_gfx_.resize(64 * 64, 0xFF);
299 }
300
301 Sprite(uint8_t id, uint8_t x, uint8_t y, uint8_t subtype, uint8_t layer)
302 : id_(id), nx_(x), ny_(y), subtype_(subtype), layer_(layer) {
303 x_ = x;
304 y_ = y;
305 name_ = kSpriteDefaultNames[id];
306 if (((subtype & 0x07) == 0x07) && id > 0 && id <= 0x1A) {
307 name_ = kOverlordNames[id - 1];
308 overlord_ = 1;
309 }
310 }
311
312 void InitSprite(const std::vector<uint8_t> &src, uint8_t overworld_map_id,
313 uint8_t id, uint8_t x, uint8_t y, int map_x, int map_y) {
314 current_gfx_ = src;
315 overworld_ = true;
316 map_id_ = static_cast<int>(overworld_map_id);
317 id_ = id;
319 entity_id_ = id;
320 x_ = map_x_;
321 y_ = map_y_;
322 nx_ = x;
323 ny_ = y;
324 name_ = kSpriteDefaultNames[id];
325 map_x_ = map_x;
326 map_y_ = map_y;
327 preview_gfx_.resize(64 * 64, 0xFF);
328 }
329 void UpdateBoundaryBox();
330
331 void Draw();
332 void DrawSpriteTile(int x, int y, int srcx, int srcy, int pal,
333 bool mirror_x = false, bool mirror_y = false,
334 int sizex = 2, int sizey = 2);
335
336 void UpdateMapProperties(uint16_t map_id) override;
337
338 // New methods
339 void UpdateCoordinates(int map_x, int map_y);
340
341 auto PreviewGraphics() const { return preview_gfx_; }
342 auto id() const { return id_; }
343 auto set_id(uint8_t id) { id_ = id; }
344 auto x() const { return x_; }
345 auto y() const { return y_; }
346 auto nx() const { return nx_; }
347 auto ny() const { return ny_; }
348 auto map_id() const { return map_id_; }
349 auto map_x() const { return map_x_; }
350 auto map_y() const { return map_y_; }
351 auto game_state() const { return game_state_; }
352
353 auto layer() const { return layer_; }
354 auto subtype() const { return subtype_; }
355
356 auto width() const { return bounding_box_.w; }
357 auto height() const { return bounding_box_.h; }
358 auto name() { return name_; }
359 auto deleted() const { return deleted_; }
361 auto set_key_drop(int key) { key_drop_ = key; }
362
363 private:
364 uint8_t map_id_;
365 uint8_t game_state_;
366 uint8_t id_;
367 uint8_t nx_;
368 uint8_t ny_;
369 uint8_t overlord_ = 0;
370 uint8_t lower_x_ = 32;
371 uint8_t lower_y_ = 32;
372 uint8_t higher_x_ = 0;
373 uint8_t higher_y_ = 0;
374
375 int width_ = 16;
376 int height_ = 16;
377 int map_x_ = 0;
378 int map_y_ = 0;
379 int layer_ = 0;
380 int subtype_ = 0;
381 int key_drop_ = 0;
382
383 bool deleted_ = false;
385
386 std::string name_;
387 std::vector<uint8_t> preview_gfx_;
388 std::vector<uint8_t> current_gfx_;
389
391};
392
393} // namespace zelda3
394} // namespace app
395} // namespace yaze
396
397#endif
Base class for all overworld and dungeon entities.
Definition common.h:35
enum yaze::app::zelda3::GameEntity::EntityType entity_type_
A class for managing sprites in the overworld and underworld.
Definition sprite.h:280
auto deleted() const
Definition sprite.h:359
auto map_id() const
Definition sprite.h:348
auto height() const
Definition sprite.h:357
auto subtype() const
Definition sprite.h:354
void InitSprite(const std::vector< uint8_t > &src, uint8_t overworld_map_id, uint8_t id, uint8_t x, uint8_t y, int map_x, int map_y)
Definition sprite.h:312
void UpdateMapProperties(uint16_t map_id) override
Definition sprite.cc:9
auto PreviewGraphics() const
Definition sprite.h:341
auto set_deleted(bool deleted)
Definition sprite.h:360
auto set_key_drop(int key)
Definition sprite.h:361
Sprite(std::vector< uint8_t > src, uint8_t overworld_map_id, uint8_t id, uint8_t x, uint8_t y, int map_x, int map_y)
Definition sprite.h:283
Sprite(uint8_t id, uint8_t x, uint8_t y, uint8_t subtype, uint8_t layer)
Definition sprite.h:301
std::vector< uint8_t > preview_gfx_
Definition sprite.h:387
void UpdateCoordinates(int map_x, int map_y)
Definition sprite.cc:15
std::vector< uint8_t > current_gfx_
Definition sprite.h:388
void DrawSpriteTile(int x, int y, int srcx, int srcy, int pal, bool mirror_x=false, bool mirror_y=false, int sizex=2, int sizey=2)
Definition sprite.cc:873
auto set_id(uint8_t id)
Definition sprite.h:343
auto game_state() const
Definition sprite.h:351
Definition common.cc:22