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