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