4 * Created on: Aug 1, 2012
8 #include "app/Application.h"
10 #include "battle/BattleState.h"
11 #include "battle/Hero.h"
12 #include "battle/Monster.h"
13 #include "battle/PartyLayout.h"
14 #include "battle/Resources.h"
15 #include "common/Ikari.h"
16 #include "common/Inventory.h"
17 #include "common/Item.h"
18 #include "common/Spell.h"
19 #include "geometry/Point.h"
20 #include "graphics/Font.h"
21 #include "graphics/Frame.h"
22 #include "graphics/Gauge.h"
23 #include "graphics/Menu.h"
24 #include "graphics/Sprite.h"
25 #include "sdl/InitImage.h"
26 #include "sdl/InitScreen.h"
27 #include "sdl/InitSDL.h"
32 #include <SDL_image.h>
34 using app::Application;
36 using battle::BattleState;
38 using battle::Monster;
39 using battle::PartyLayout;
41 using common::Inventory;
44 using geometry::Point;
46 using graphics::Frame;
47 using graphics::Gauge;
49 using graphics::Sprite;
51 using sdl::InitScreen;
59 int main(int argc, char **argv) {
60 const int width = 800;
61 const int height = 480;
65 InitImage image(IMG_INIT_PNG);
66 InitScreen screen(width, height);
68 // temporary test data
69 SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
70 PartyLayout monstersLayout;
71 monstersLayout.AddPosition(Point<Uint8>(88, 104));
72 monstersLayout.AddPosition(Point<Uint8>(128, 104));
73 monstersLayout.AddPosition(Point<Uint8>(168, 104));
74 monstersLayout.AddPosition(Point<Uint8>(208, 104));
75 PartyLayout heroesLayout;
76 heroesLayout.AddPosition(Point<Uint8>(27, 219));
77 heroesLayout.AddPosition(Point<Uint8>(104, 227));
78 heroesLayout.AddPosition(Point<Uint8>(66, 238));
79 heroesLayout.AddPosition(Point<Uint8>(143, 246));
81 SDL_Surface *monsterImg(IMG_Load("test-data/monster.png"));
82 Sprite dummySprite(monsterImg, 64, 64);
84 monster.SetSprite(&dummySprite);
85 monster.SetMaxHealth(10);
86 monster.SetHealth(10);
88 SDL_Surface *maximImg(IMG_Load("test-data/maxim.png"));
89 Sprite maximSprite(maximImg, 64, 64);
91 maxim.SetName("Maxim");
93 maxim.SetSprite(&maximSprite);
94 maxim.SetMaxHealth(33);
100 SDL_Surface *selanImg(IMG_Load("test-data/selan.png"));
101 Sprite selanSprite(selanImg, 64, 64);
103 selan.SetName("Selan");
105 selan.SetSprite(&selanSprite);
106 selan.SetMaxHealth(28);
108 selan.SetMaxMana(23);
112 SDL_Surface *guyImg(IMG_Load("test-data/guy.png"));
113 Sprite guySprite(guyImg, 64, 64);
117 guy.SetSprite(&guySprite);
118 guy.SetMaxHealth(38);
124 SDL_Surface *dekarImg(IMG_Load("test-data/dekar.png"));
125 Sprite dekarSprite(dekarImg, 64, 64);
127 dekar.SetName("Dekar");
129 dekar.SetSprite(&dekarSprite);
130 dekar.SetMaxHealth(38);
136 battle::Resources battleRes;
138 SDL_Surface *swapCursorImg(IMG_Load("test-data/swap-cursor.png"));
139 Sprite swapCursorSprite(swapCursorImg, 32, 32);
140 battleRes.swapCursor = &swapCursorSprite;
141 SDL_Surface *attackIconsImg(IMG_Load("test-data/attack-type-icons.png"));
142 Sprite attackIconsSprite(attackIconsImg, 32, 32);
143 battleRes.attackIcons = &attackIconsSprite;
144 SDL_Surface *attackChoiceIconsImg(IMG_Load("test-data/attack-choice-icons.png"));
145 Sprite attackChoiceIconsSprite(attackChoiceIconsImg, 16, 16);
146 battleRes.attackChoiceIcons = &attackChoiceIconsSprite;
147 SDL_Surface *moveIconsImg(IMG_Load("test-data/move-icons.png"));
148 Sprite moveIconsSprite(moveIconsImg, 32, 32);
149 battleRes.moveIcons = &moveIconsSprite;
150 SDL_Surface *heroTagImg(IMG_Load("test-data/hero-tag-sprites.png"));
151 Sprite heroTagSprite(heroTagImg, 32, 16);
152 battleRes.heroTagLabels = &heroTagSprite;
153 SDL_Surface *numbersImg(IMG_Load("test-data/numbers.png"));
154 Sprite numbersSprite(numbersImg, 16, 16);
155 Font heroTagFont(&numbersSprite);
156 battleRes.heroTagFont = &heroTagFont;
157 SDL_Surface *tagFramesImg(IMG_Load("test-data/tag-frames.png"));
158 Frame heroTagFrame(tagFramesImg, 16, 16, 1, 1, 0, 33);
159 battleRes.heroTagFrame = &heroTagFrame;
160 Frame activeHeroTagFrame(tagFramesImg, 16, 16);
161 battleRes.activeHeroTagFrame = &activeHeroTagFrame;
163 SDL_Surface *gauges(IMG_Load("test-data/gauges.png"));
164 Gauge healthGauge(gauges, 0, 16, 0, 0, 16, 6, 1, 6);
165 battleRes.healthGauge = &healthGauge;
166 Gauge manaGauge(gauges, 0, 32, 0, 0, 16, 6, 1, 6);
167 battleRes.manaGauge = &manaGauge;
168 Gauge ikariGauge(gauges, 0, 48, 0, 0, 16, 6, 1, 6);
169 battleRes.ikariGauge = &ikariGauge;
171 SDL_Surface *selectFrameImg(IMG_Load("test-data/select-frame.png"));
172 Frame selectFrame(selectFrameImg, 16, 16);
173 battleRes.selectFrame = &selectFrame;
175 SDL_Surface *normalFontImg(IMG_Load("test-data/normal-font.png"));
176 Sprite normalFontSprite(normalFontImg, 16, 16);
177 Font normalFont(&normalFontSprite);
178 normalFont.MapRange('A', 'M', 0, 1);
179 normalFont.MapRange('N', 'Z', 0, 2);
180 normalFont.MapRange('a', 'm', 0, 3);
181 normalFont.MapRange('n', 'z', 0, 4);
182 normalFont.MapChar(':', 10, 0);
183 normalFont.MapChar('!', 11, 0);
184 normalFont.MapChar('?', 12, 0);
185 // TODO: add '.' and '-' characters
186 battleRes.normalFont = &normalFont;
188 SDL_Surface *disabledFontImg(IMG_Load("test-data/disabled-font.png"));
189 Sprite disabledFontSprite(disabledFontImg, 16, 16);
190 Font disabledFont(&disabledFontSprite);
191 disabledFont.MapRange('A', 'M', 0, 1);
192 disabledFont.MapRange('N', 'Z', 0, 2);
193 disabledFont.MapRange('a', 'm', 0, 3);
194 disabledFont.MapRange('n', 'z', 0, 4);
195 disabledFont.MapChar(':', 10, 0);
196 disabledFont.MapChar('!', 11, 0);
197 disabledFont.MapChar('?', 12, 0);
198 // TODO: add '.' and '-' characters
199 battleRes.disabledFont = &disabledFont;
201 SDL_Surface *handCursorImg(IMG_Load("test-data/cursor-hand.png"));
202 Sprite handCursorSprite(handCursorImg, 32, 32);
203 battleRes.menuCursor = &handCursorSprite;
205 SDL_Surface *targetingIconsImg(IMG_Load("test-data/targeting-icons.png"));
206 Sprite weaponTargetCursor(targetingIconsImg, 32, 32);
207 Sprite magicTargetCursor(targetingIconsImg, 32, 32, 0, 32);
208 Sprite itemTargetCursor(targetingIconsImg, 32, 32, 0, 64);
209 battleRes.weaponTargetCursor = &weaponTargetCursor;
210 // TODO: add image for magic targeting cursor
211 battleRes.magicTargetCursor = &magicTargetCursor;
212 // TODO: add image for item targeting cursor
213 battleRes.itemTargetCursor = &itemTargetCursor;
216 resetSpell.SetName("Reset");
217 maxim.AddSpell(&resetSpell);
219 strongSpell.SetName("Strong");
220 strongSpell.SetCost(3);
221 strongSpell.SetUsableInBattle();
222 strongSpell.GetTargetingMode().TargetMultipleAllies();
223 maxim.AddSpell(&strongSpell);
224 selan.AddSpell(&strongSpell);
226 strongerSpell.SetName("Stronger");
227 strongerSpell.SetCost(8);
228 strongerSpell.SetUsableInBattle();
229 strongerSpell.GetTargetingMode().TargetMultipleAllies();
230 maxim.AddSpell(&strongerSpell);
231 selan.AddSpell(&strongerSpell);
233 championSpell.SetName("Champion");
234 championSpell.SetCost(16);
235 championSpell.SetUsableInBattle();
236 championSpell.GetTargetingMode().TargetMultipleAllies();
237 maxim.AddSpell(&championSpell);
238 selan.AddSpell(&championSpell);
240 rallySpell.SetName("Rally");
241 rallySpell.SetCost(10);
242 rallySpell.SetUsableInBattle();
243 rallySpell.GetTargetingMode().TargetMultipleAllies();
244 maxim.AddSpell(&rallySpell);
245 selan.AddSpell(&rallySpell);
247 escapeSpell.SetName("Escape");
248 escapeSpell.SetCost(8);
249 selan.AddSpell(&escapeSpell);
251 valorSpell.SetName("Valor");
252 valorSpell.SetCost(30);
253 valorSpell.SetUsableInBattle();
254 valorSpell.GetTargetingMode().TargetMultipleAllies();
255 maxim.AddSpell(&valorSpell);
256 selan.AddSpell(&valorSpell);
258 battleRes.spellMenuHeadline = "Please choose a spell.";
259 battleRes.spellMenuPrototype = Menu<const Spell *>(&normalFont, &disabledFont, &handCursorSprite, 9, 6, 8, 0, 2, 32, 2, ':');
261 SDL_Surface *itemIcons(IMG_Load("test-data/item-icons.png"));
262 Sprite potionIcon(itemIcons, 16, 16);
263 Sprite ballIcon(itemIcons, 16, 16, 0, 16);
264 Sprite crankIcon(itemIcons, 16, 16, 0, 32);
265 Sprite spearIcon(itemIcons, 16, 16, 0, 48);
266 Sprite swordIcon(itemIcons, 16, 16, 0, 64);
267 Sprite axIcon(itemIcons, 16, 16, 0, 80);
268 Sprite rodIcon(itemIcons, 16, 16, 0, 96);
269 Sprite armorIcon(itemIcons, 16, 16, 0, 112);
270 Sprite shieldIcon(itemIcons, 16, 16, 0, 128);
271 Sprite helmetIcon(itemIcons, 16, 16, 0, 144);
272 Sprite ringIcon(itemIcons, 16, 16, 0, 160);
273 Sprite jewelIcon(itemIcons, 16, 16, 0, 176);
275 battleRes.weaponMenuIcon = &swordIcon;
276 battleRes.armorMenuIcon = &armorIcon;
277 battleRes.shieldMenuIcon = &shieldIcon;
278 battleRes.helmetMenuIcon = &helmetIcon;
279 battleRes.ringMenuIcon = &ringIcon;
280 battleRes.jewelMenuIcon = &jewelIcon;
284 antidote.SetName("Antidote");
285 antidote.SetMenuIcon(&potionIcon);
286 antidote.SetUsableInBattle();
287 antidote.GetTargetingMode().TargetSingleAlly();
288 inventory.Add(&antidote, 9);
290 magicJar.SetName("Magic jar");
291 magicJar.SetMenuIcon(&potionIcon);
292 magicJar.SetUsableInBattle();
293 magicJar.GetTargetingMode().TargetSingleAlly();
294 inventory.Add(&magicJar, 4);
296 hiPotion.SetName("Hi-Potion");
297 hiPotion.SetMenuIcon(&potionIcon);
298 hiPotion.SetUsableInBattle();
299 hiPotion.GetTargetingMode().TargetSingleAlly();
300 inventory.Add(&hiPotion, 4);
302 powerPotion.SetName("Power potion");
303 powerPotion.SetMenuIcon(&potionIcon);
304 inventory.Add(&powerPotion, 4);
306 escape.SetName("Escape");
307 inventory.Add(&escape, 2);
309 sleepBall.SetName("Sleep ball");
310 sleepBall.SetMenuIcon(&ballIcon);
311 sleepBall.SetUsableInBattle();
312 sleepBall.GetTargetingMode().TargetSingleEnemy();
313 inventory.Add(&sleepBall, 1);
315 multiBall.SetName("Multi-ball!");
316 multiBall.SetMenuIcon(&ballIcon);
317 multiBall.SetUsableInBattle();
318 multiBall.GetTargetingMode().TargetMultipleEnemies();
319 inventory.Add(&multiBall, 1);
321 figgoru.SetName("Figgoru");
322 figgoru.SetMenuIcon(&crankIcon);
323 figgoru.GetTargetingMode().TargetAllEnemies();
324 inventory.Add(&figgoru, 1);
325 battleRes.inventory = &inventory;
327 battleRes.itemMenuHeadline = "Please choose an item.";
328 battleRes.itemMenuPrototype = Menu<const common::Item *>(&normalFont, &disabledFont, &handCursorSprite, 15, 6, 8, 16, 1, 32, 2, ':');
331 zircoSword.SetName("Zirco sword");
332 zircoSword.SetMenuIcon(&swordIcon);
334 firestorm.SetName("Firestorm");
335 firestorm.SetCost(224);
336 firestorm.GetTargetingMode().TargetAllEnemies();
337 firestorm.SetPhysical();
338 zircoSword.SetIkari(&firestorm);
339 maxim.SetWeapon(&zircoSword);
341 zirconArmor.SetName("Zircon armor");
342 zirconArmor.SetMenuIcon(&armorIcon);
344 magicCure.SetName("Magic cure");
345 magicCure.SetCost(128);
346 magicCure.GetTargetingMode().TargetSingleAlly();
347 magicCure.SetMagical();
348 zirconArmor.SetIkari(&magicCure);
349 maxim.SetArmor(&zirconArmor);
351 holyShield.SetName("Holy shield");
352 holyShield.SetMenuIcon(&shieldIcon);
354 lightGuard.SetName("Light guard");
355 lightGuard.SetCost(128);
356 lightGuard.GetTargetingMode().TargetAllAllies(); // FIXME: actually only targets self
357 lightGuard.SetMagical();
358 holyShield.SetIkari(&lightGuard);
359 maxim.SetShield(&holyShield);
361 legendHelm.SetName("Legend helm");
362 legendHelm.SetMenuIcon(&helmetIcon);
364 boomerang.SetName("Boomerang");
365 boomerang.SetCost(164);
366 boomerang.GetTargetingMode().TargetAllAllies(); // FIXME: actually only targets self
367 boomerang.SetMagical();
368 legendHelm.SetIkari(&boomerang);
369 maxim.SetHelmet(&legendHelm);
371 sProRing.SetName("S-pro ring");
372 sProRing.SetMenuIcon(&ringIcon);
374 courage.SetName("Courage");
376 courage.GetTargetingMode().TargetMultipleAllies();
377 courage.SetMagical();
378 sProRing.SetIkari(&courage);
379 maxim.SetRing(&sProRing);
381 evilJewel.SetName("Evil jewel");
382 evilJewel.SetMenuIcon(&jewelIcon);
384 gloomy.SetName("Gloomy");
386 gloomy.GetTargetingMode().TargetAllEnemies();
388 evilJewel.SetIkari(&gloomy);
389 maxim.SetJewel(&evilJewel);
392 zircoWhip.SetName("Zirco whip");
393 zircoWhip.SetMenuIcon(&rodIcon);
395 thundershriek.SetName("Thundershriek");
396 thundershriek.SetCost(224);
397 thundershriek.GetTargetingMode().TargetAllEnemies();
398 thundershriek.SetPhysical();
399 zircoWhip.SetIkari(&thundershriek);
400 selan.SetWeapon(&zircoWhip);
402 zirconPlate.SetName("Zircon plate");
403 zirconPlate.SetMenuIcon(&armorIcon);
405 suddenCure.SetName("Sudden cure");
406 suddenCure.SetCost(96);
407 suddenCure.GetTargetingMode().TargetAllAllies();
408 suddenCure.SetMagical();
409 zirconPlate.SetIkari(&suddenCure);
410 selan.SetArmor(&zirconPlate);
412 zircoGloves.SetName("Zirco gloves");
413 zircoGloves.SetMenuIcon(&shieldIcon);
415 forcefield.SetName("Forcefield");
416 forcefield.SetCost(64);
417 forcefield.GetTargetingMode().TargetAllAllies();
418 forcefield.SetMagical();
419 zircoGloves.SetIkari(&forcefield);
420 selan.SetShield(&zircoGloves);
422 holyCap.SetName("Holy cap");
423 holyCap.SetMenuIcon(&helmetIcon);
425 vulnerable.SetName("Vulnerable");
426 vulnerable.SetCost(196);
427 vulnerable.GetTargetingMode().TargetAllEnemies();
428 vulnerable.SetPhysical();
429 holyCap.SetIkari(&vulnerable);
430 selan.SetHelmet(&holyCap);
432 ghostRing.SetName("Ghost ring");
433 ghostRing.SetMenuIcon(&ringIcon);
435 destroy.SetName("Destroy");
436 destroy.SetCost(128);
437 destroy.GetTargetingMode().TargetMultipleEnemies();
438 destroy.SetMagical();
439 ghostRing.SetIkari(&destroy);
440 selan.SetRing(&ghostRing);
442 eagleRock.SetName("Eagle rock");
443 eagleRock.SetMenuIcon(&jewelIcon);
445 dive.SetName("Dive");
447 dive.GetTargetingMode().TargetSingleEnemy();
449 eagleRock.SetIkari(&dive);
450 selan.SetJewel(&eagleRock);
453 zircoAx.SetName("Zirco ax");
454 zircoAx.SetMenuIcon(&axIcon);
456 torrent.SetName("Torrent");
457 torrent.SetCost(224);
458 torrent.GetTargetingMode().TargetAllEnemies();
459 torrent.SetPhysical();
460 zircoAx.SetIkari(&torrent);
461 guy.SetWeapon(&zircoAx);
462 guy.SetArmor(&zirconArmor);
464 megaShield.SetName("Mega shield");
465 megaShield.SetMenuIcon(&shieldIcon);
467 ironBarrier.SetName("Iron barrier");
468 ironBarrier.SetCost(255);
469 ironBarrier.GetTargetingMode().TargetAllAllies(); // FIXME: actually only targets self
470 ironBarrier.SetMagical();
471 megaShield.SetIkari(&ironBarrier);
472 guy.SetShield(&megaShield);
474 zircoHelmet.SetName("Zirco helmet");
475 zircoHelmet.SetMenuIcon(&helmetIcon);
477 slow.SetName("Slow");
479 slow.GetTargetingMode().TargetAllEnemies();
481 zircoHelmet.SetIkari(&slow);
482 guy.SetHelmet(&zircoHelmet);
484 powerRing.SetName("Power ring");
485 powerRing.SetMenuIcon(&ringIcon);
487 trick.SetName("Trick");
489 trick.GetTargetingMode().TargetAllEnemies();
491 zircoHelmet.SetIkari(&trick);
492 guy.SetRing(&powerRing);
493 guy.SetJewel(&evilJewel);
495 // NOTE: this is actually Artea equipment
497 lizardBlow.SetName("Lizard blow");
498 lizardBlow.SetMenuIcon(&swordIcon);
500 dragonRush.SetName("Dragon rush");
501 dragonRush.SetCost(164);
502 dragonRush.GetTargetingMode().TargetSingleEnemy();
503 dragonRush.SetPhysical();
504 lizardBlow.SetIkari(&dragonRush);
505 dekar.SetWeapon(&lizardBlow);
507 holyRobe.SetName("Holy robe");
508 holyRobe.SetMenuIcon(&armorIcon);
510 crisisCure.SetName("Crisis cure");
511 crisisCure.SetCost(164);
512 crisisCure.GetTargetingMode().TargetAllAllies();
513 crisisCure.SetMagical();
514 holyRobe.SetIkari(&crisisCure);
515 dekar.SetArmor(&holyRobe);
516 dekar.SetShield(&zircoGloves);
517 dekar.SetHelmet(&holyCap);
519 rocketRing.SetName("Rocket ring");
520 rocketRing.SetMenuIcon(&ringIcon);
522 fake.SetName("Fake");
524 fake.GetTargetingMode().TargetSingleAlly();
526 rocketRing.SetIkari(&fake);
527 dekar.SetRing(&rocketRing);
529 krakenRock.SetName("Kraken rock");
530 krakenRock.SetMenuIcon(&jewelIcon);
532 tenLegger.SetName("Ten-legger");
533 tenLegger.SetCost(164);
534 tenLegger.GetTargetingMode().TargetAllEnemies();
535 tenLegger.SetPhysical();
536 rocketRing.SetIkari(&tenLegger);
537 dekar.SetJewel(&krakenRock);
539 battleRes.ikariMenuHeadline = "Please choose equipment.";
540 battleRes.noEquipmentText = "No equip";
541 battleRes.ikariMenuPrototype = Menu<const Item *>(&normalFont, &disabledFont, &handCursorSprite, 12, 6, normalFont.CharHeight() / 2, normalFont.CharWidth(), 1, normalFont.CharWidth() * 2, 0, ':', 12, normalFont.CharWidth());
543 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &battleRes));
544 battleState->AddMonster(monster);
545 battleState->AddMonster(monster);
546 battleState->AddMonster(monster);
547 battleState->AddMonster(monster);
548 battleState->AddHero(maxim);
549 battleState->AddHero(selan);
550 battleState->AddHero(guy);
551 battleState->AddHero(dekar);
552 Application app(&screen, battleState);
553 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
554 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
555 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
556 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
557 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
558 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
559 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
560 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
561 app.Buttons().MapKey(SDLK_RETURN, Input::START);
562 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
563 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
564 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
568 } catch (exception &e) {
569 cerr << "exception in main(): " << e.what() << endl;