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>(48, 152));
77 heroesLayout.AddPosition(Point<Uint8>(80, 168));
78 heroesLayout.AddPosition(Point<Uint8>(128, 152));
79 heroesLayout.AddPosition(Point<Uint8>(160, 168));
81 SDL_Surface *monsterImg(IMG_Load("test-data/monster.png"));
82 Sprite dummySprite(monsterImg, 64, 64);
84 monster.SetName("Monster");
85 monster.SetSprite(&dummySprite);
86 monster.SetMaxHealth(10);
87 monster.SetHealth(10);
89 SDL_Surface *maximImg(IMG_Load("test-data/maxim.png"));
90 Sprite maximSprite(maximImg, 64, 64);
92 maxim.SetName("Maxim");
94 maxim.SetSprite(&maximSprite);
95 maxim.SetMaxHealth(33);
101 SDL_Surface *selanImg(IMG_Load("test-data/selan.png"));
102 Sprite selanSprite(selanImg, 64, 64);
104 selan.SetName("Selan");
106 selan.SetSprite(&selanSprite);
107 selan.SetMaxHealth(28);
109 selan.SetMaxMana(23);
113 SDL_Surface *guyImg(IMG_Load("test-data/guy.png"));
114 Sprite guySprite(guyImg, 64, 64);
118 guy.SetSprite(&guySprite);
119 guy.SetMaxHealth(38);
125 SDL_Surface *dekarImg(IMG_Load("test-data/dekar.png"));
126 Sprite dekarSprite(dekarImg, 64, 64);
128 dekar.SetName("Dekar");
130 dekar.SetSprite(&dekarSprite);
131 dekar.SetMaxHealth(38);
137 battle::Resources battleRes;
139 SDL_Surface *swapCursorImg(IMG_Load("test-data/swap-cursor.png"));
140 Sprite swapCursorSprite(swapCursorImg, 32, 32);
141 battleRes.swapCursor = &swapCursorSprite;
142 SDL_Surface *attackIconsImg(IMG_Load("test-data/attack-type-icons.png"));
143 Sprite attackIconsSprite(attackIconsImg, 32, 32);
144 battleRes.attackIcons = &attackIconsSprite;
145 SDL_Surface *attackChoiceIconsImg(IMG_Load("test-data/attack-choice-icons.png"));
146 Sprite attackChoiceIconsSprite(attackChoiceIconsImg, 16, 16);
147 battleRes.attackChoiceIcons = &attackChoiceIconsSprite;
148 SDL_Surface *moveIconsImg(IMG_Load("test-data/move-icons.png"));
149 Sprite moveIconsSprite(moveIconsImg, 32, 32);
150 battleRes.moveIcons = &moveIconsSprite;
152 SDL_Surface *titleFrameImg(IMG_Load("test-data/title-frame.png"));
153 Frame titleFrame(titleFrameImg, 16, 16);
154 battleRes.titleFrame = &titleFrame;
156 SDL_Surface *largeFontImg(IMG_Load("test-data/large-font.png"));
157 Sprite largeFontSprite(largeFontImg, 16, 32);
158 Font largeFont(&largeFontSprite);
159 largeFont.MapRange('A', 'M', 0, 1);
160 largeFont.MapRange('N', 'Z', 0, 2);
161 largeFont.MapRange('a', 'm', 0, 3);
162 largeFont.MapRange('n', 'z', 0, 4);
163 largeFont.MapChar(':', 10, 0);
164 largeFont.MapChar('!', 11, 0);
165 largeFont.MapChar('?', 12, 0);
166 // TODO: add '.' and '-' characters
167 battleRes.titleFont = &largeFont;
169 SDL_Surface *heroTagImg(IMG_Load("test-data/hero-tag-sprites.png"));
170 Sprite heroTagSprite(heroTagImg, 32, 16);
171 battleRes.heroTagLabels = &heroTagSprite;
172 SDL_Surface *numbersImg(IMG_Load("test-data/numbers.png"));
173 Sprite numbersSprite(numbersImg, 16, 16);
174 Font heroTagFont(&numbersSprite);
175 battleRes.heroTagFont = &heroTagFont;
176 SDL_Surface *tagFramesImg(IMG_Load("test-data/tag-frames.png"));
177 Frame heroTagFrame(tagFramesImg, 16, 16, 1, 1, 0, 33);
178 battleRes.heroTagFrame = &heroTagFrame;
179 Frame activeHeroTagFrame(tagFramesImg, 16, 16);
180 battleRes.activeHeroTagFrame = &activeHeroTagFrame;
182 SDL_Surface *gauges(IMG_Load("test-data/gauges.png"));
183 Gauge healthGauge(gauges, 0, 16, 0, 0, 16, 6, 1, 6);
184 battleRes.healthGauge = &healthGauge;
185 Gauge manaGauge(gauges, 0, 32, 0, 0, 16, 6, 1, 6);
186 battleRes.manaGauge = &manaGauge;
187 Gauge ikariGauge(gauges, 0, 48, 0, 0, 16, 6, 1, 6);
188 battleRes.ikariGauge = &ikariGauge;
190 SDL_Surface *selectFrameImg(IMG_Load("test-data/select-frame.png"));
191 Frame selectFrame(selectFrameImg, 16, 16);
192 battleRes.selectFrame = &selectFrame;
194 SDL_Surface *normalFontImg(IMG_Load("test-data/normal-font.png"));
195 Sprite normalFontSprite(normalFontImg, 16, 16);
196 Font normalFont(&normalFontSprite);
197 normalFont.MapRange('A', 'M', 0, 1);
198 normalFont.MapRange('N', 'Z', 0, 2);
199 normalFont.MapRange('a', 'm', 0, 3);
200 normalFont.MapRange('n', 'z', 0, 4);
201 normalFont.MapChar(':', 10, 0);
202 normalFont.MapChar('!', 11, 0);
203 normalFont.MapChar('?', 12, 0);
204 // TODO: add '.' and '-' characters
205 battleRes.normalFont = &normalFont;
207 SDL_Surface *disabledFontImg(IMG_Load("test-data/disabled-font.png"));
208 Sprite disabledFontSprite(disabledFontImg, 16, 16);
209 Font disabledFont(&disabledFontSprite);
210 disabledFont.MapRange('A', 'M', 0, 1);
211 disabledFont.MapRange('N', 'Z', 0, 2);
212 disabledFont.MapRange('a', 'm', 0, 3);
213 disabledFont.MapRange('n', 'z', 0, 4);
214 disabledFont.MapChar(':', 10, 0);
215 disabledFont.MapChar('!', 11, 0);
216 disabledFont.MapChar('?', 12, 0);
217 // TODO: add '.' and '-' characters
218 battleRes.disabledFont = &disabledFont;
220 SDL_Surface *handCursorImg(IMG_Load("test-data/cursor-hand.png"));
221 Sprite handCursorSprite(handCursorImg, 32, 32);
222 battleRes.menuCursor = &handCursorSprite;
224 SDL_Surface *targetingIconsImg(IMG_Load("test-data/targeting-icons.png"));
225 Sprite weaponTargetCursor(targetingIconsImg, 32, 32);
226 Sprite magicTargetCursor(targetingIconsImg, 32, 32, 0, 32);
227 Sprite itemTargetCursor(targetingIconsImg, 32, 32, 0, 64);
228 battleRes.weaponTargetCursor = &weaponTargetCursor;
229 // TODO: add image for magic targeting cursor
230 battleRes.magicTargetCursor = &magicTargetCursor;
231 // TODO: add image for item targeting cursor
232 battleRes.itemTargetCursor = &itemTargetCursor;
235 resetSpell.SetName("Reset");
236 maxim.AddSpell(&resetSpell);
238 strongSpell.SetName("Strong");
239 strongSpell.SetCost(3);
240 strongSpell.SetUsableInBattle();
241 strongSpell.GetTargetingMode().TargetMultipleAllies();
242 maxim.AddSpell(&strongSpell);
243 selan.AddSpell(&strongSpell);
245 strongerSpell.SetName("Stronger");
246 strongerSpell.SetCost(8);
247 strongerSpell.SetUsableInBattle();
248 strongerSpell.GetTargetingMode().TargetMultipleAllies();
249 maxim.AddSpell(&strongerSpell);
250 selan.AddSpell(&strongerSpell);
252 championSpell.SetName("Champion");
253 championSpell.SetCost(16);
254 championSpell.SetUsableInBattle();
255 championSpell.GetTargetingMode().TargetMultipleAllies();
256 maxim.AddSpell(&championSpell);
257 selan.AddSpell(&championSpell);
259 rallySpell.SetName("Rally");
260 rallySpell.SetCost(10);
261 rallySpell.SetUsableInBattle();
262 rallySpell.GetTargetingMode().TargetMultipleAllies();
263 maxim.AddSpell(&rallySpell);
264 selan.AddSpell(&rallySpell);
266 escapeSpell.SetName("Escape");
267 escapeSpell.SetCost(8);
268 selan.AddSpell(&escapeSpell);
270 valorSpell.SetName("Valor");
271 valorSpell.SetCost(30);
272 valorSpell.SetUsableInBattle();
273 valorSpell.GetTargetingMode().TargetMultipleAllies();
274 maxim.AddSpell(&valorSpell);
275 selan.AddSpell(&valorSpell);
277 battleRes.spellMenuHeadline = "Please choose a spell.";
278 battleRes.spellMenuPrototype = Menu<const Spell *>(&normalFont, &disabledFont, &handCursorSprite, 9, 6, 8, 0, 2, 32, 2, ':');
280 SDL_Surface *itemIcons(IMG_Load("test-data/item-icons.png"));
281 Sprite potionIcon(itemIcons, 16, 16);
282 Sprite ballIcon(itemIcons, 16, 16, 0, 16);
283 Sprite crankIcon(itemIcons, 16, 16, 0, 32);
284 Sprite spearIcon(itemIcons, 16, 16, 0, 48);
285 Sprite swordIcon(itemIcons, 16, 16, 0, 64);
286 Sprite axIcon(itemIcons, 16, 16, 0, 80);
287 Sprite rodIcon(itemIcons, 16, 16, 0, 96);
288 Sprite armorIcon(itemIcons, 16, 16, 0, 112);
289 Sprite shieldIcon(itemIcons, 16, 16, 0, 128);
290 Sprite helmetIcon(itemIcons, 16, 16, 0, 144);
291 Sprite ringIcon(itemIcons, 16, 16, 0, 160);
292 Sprite jewelIcon(itemIcons, 16, 16, 0, 176);
294 battleRes.weaponMenuIcon = &swordIcon;
295 battleRes.armorMenuIcon = &armorIcon;
296 battleRes.shieldMenuIcon = &shieldIcon;
297 battleRes.helmetMenuIcon = &helmetIcon;
298 battleRes.ringMenuIcon = &ringIcon;
299 battleRes.jewelMenuIcon = &jewelIcon;
303 antidote.SetName("Antidote");
304 antidote.SetMenuIcon(&potionIcon);
305 antidote.SetUsableInBattle();
306 antidote.GetTargetingMode().TargetSingleAlly();
307 inventory.Add(&antidote, 9);
309 magicJar.SetName("Magic jar");
310 magicJar.SetMenuIcon(&potionIcon);
311 magicJar.SetUsableInBattle();
312 magicJar.GetTargetingMode().TargetSingleAlly();
313 inventory.Add(&magicJar, 4);
315 hiPotion.SetName("Hi-Potion");
316 hiPotion.SetMenuIcon(&potionIcon);
317 hiPotion.SetUsableInBattle();
318 hiPotion.GetTargetingMode().TargetSingleAlly();
319 inventory.Add(&hiPotion, 4);
321 powerPotion.SetName("Power potion");
322 powerPotion.SetMenuIcon(&potionIcon);
323 inventory.Add(&powerPotion, 4);
325 escape.SetName("Escape");
326 inventory.Add(&escape, 2);
328 sleepBall.SetName("Sleep ball");
329 sleepBall.SetMenuIcon(&ballIcon);
330 sleepBall.SetUsableInBattle();
331 sleepBall.GetTargetingMode().TargetSingleEnemy();
332 inventory.Add(&sleepBall, 1);
334 multiBall.SetName("Multi-ball!");
335 multiBall.SetMenuIcon(&ballIcon);
336 multiBall.SetUsableInBattle();
337 multiBall.GetTargetingMode().TargetMultipleEnemies();
338 inventory.Add(&multiBall, 1);
340 figgoru.SetName("Figgoru");
341 figgoru.SetMenuIcon(&crankIcon);
342 figgoru.GetTargetingMode().TargetAllEnemies();
343 inventory.Add(&figgoru, 1);
344 battleRes.inventory = &inventory;
346 battleRes.itemMenuHeadline = "Please choose an item.";
347 battleRes.itemMenuPrototype = Menu<const common::Item *>(&normalFont, &disabledFont, &handCursorSprite, 15, 6, 8, 16, 1, 32, 2, ':');
350 zircoSword.SetName("Zirco sword");
351 zircoSword.SetMenuIcon(&swordIcon);
353 firestorm.SetName("Firestorm");
354 firestorm.SetCost(224);
355 firestorm.GetTargetingMode().TargetAllEnemies();
356 firestorm.SetPhysical();
357 zircoSword.SetIkari(&firestorm);
358 maxim.SetWeapon(&zircoSword);
360 zirconArmor.SetName("Zircon armor");
361 zirconArmor.SetMenuIcon(&armorIcon);
363 magicCure.SetName("Magic cure");
364 magicCure.SetCost(128);
365 magicCure.GetTargetingMode().TargetSingleAlly();
366 magicCure.SetMagical();
367 zirconArmor.SetIkari(&magicCure);
368 maxim.SetArmor(&zirconArmor);
370 holyShield.SetName("Holy shield");
371 holyShield.SetMenuIcon(&shieldIcon);
373 lightGuard.SetName("Light guard");
374 lightGuard.SetCost(128);
375 lightGuard.GetTargetingMode().TargetAllAllies(); // FIXME: actually only targets self
376 lightGuard.SetMagical();
377 holyShield.SetIkari(&lightGuard);
378 maxim.SetShield(&holyShield);
380 legendHelm.SetName("Legend helm");
381 legendHelm.SetMenuIcon(&helmetIcon);
383 boomerang.SetName("Boomerang");
384 boomerang.SetCost(164);
385 boomerang.GetTargetingMode().TargetAllAllies(); // FIXME: actually only targets self
386 boomerang.SetMagical();
387 legendHelm.SetIkari(&boomerang);
388 maxim.SetHelmet(&legendHelm);
390 sProRing.SetName("S-pro ring");
391 sProRing.SetMenuIcon(&ringIcon);
393 courage.SetName("Courage");
395 courage.GetTargetingMode().TargetMultipleAllies();
396 courage.SetMagical();
397 sProRing.SetIkari(&courage);
398 maxim.SetRing(&sProRing);
400 evilJewel.SetName("Evil jewel");
401 evilJewel.SetMenuIcon(&jewelIcon);
403 gloomy.SetName("Gloomy");
405 gloomy.GetTargetingMode().TargetAllEnemies();
407 evilJewel.SetIkari(&gloomy);
408 maxim.SetJewel(&evilJewel);
411 zircoWhip.SetName("Zirco whip");
412 zircoWhip.SetMenuIcon(&rodIcon);
414 thundershriek.SetName("Thundershriek");
415 thundershriek.SetCost(224);
416 thundershriek.GetTargetingMode().TargetAllEnemies();
417 thundershriek.SetPhysical();
418 zircoWhip.SetIkari(&thundershriek);
419 selan.SetWeapon(&zircoWhip);
421 zirconPlate.SetName("Zircon plate");
422 zirconPlate.SetMenuIcon(&armorIcon);
424 suddenCure.SetName("Sudden cure");
425 suddenCure.SetCost(96);
426 suddenCure.GetTargetingMode().TargetAllAllies();
427 suddenCure.SetMagical();
428 zirconPlate.SetIkari(&suddenCure);
429 selan.SetArmor(&zirconPlate);
431 zircoGloves.SetName("Zirco gloves");
432 zircoGloves.SetMenuIcon(&shieldIcon);
434 forcefield.SetName("Forcefield");
435 forcefield.SetCost(64);
436 forcefield.GetTargetingMode().TargetAllAllies();
437 forcefield.SetMagical();
438 zircoGloves.SetIkari(&forcefield);
439 selan.SetShield(&zircoGloves);
441 holyCap.SetName("Holy cap");
442 holyCap.SetMenuIcon(&helmetIcon);
444 vulnerable.SetName("Vulnerable");
445 vulnerable.SetCost(196);
446 vulnerable.GetTargetingMode().TargetAllEnemies();
447 vulnerable.SetPhysical();
448 holyCap.SetIkari(&vulnerable);
449 selan.SetHelmet(&holyCap);
451 ghostRing.SetName("Ghost ring");
452 ghostRing.SetMenuIcon(&ringIcon);
454 destroy.SetName("Destroy");
455 destroy.SetCost(128);
456 destroy.GetTargetingMode().TargetMultipleEnemies();
457 destroy.SetMagical();
458 ghostRing.SetIkari(&destroy);
459 selan.SetRing(&ghostRing);
461 eagleRock.SetName("Eagle rock");
462 eagleRock.SetMenuIcon(&jewelIcon);
464 dive.SetName("Dive");
466 dive.GetTargetingMode().TargetSingleEnemy();
468 eagleRock.SetIkari(&dive);
469 selan.SetJewel(&eagleRock);
472 zircoAx.SetName("Zirco ax");
473 zircoAx.SetMenuIcon(&axIcon);
475 torrent.SetName("Torrent");
476 torrent.SetCost(224);
477 torrent.GetTargetingMode().TargetAllEnemies();
478 torrent.SetPhysical();
479 zircoAx.SetIkari(&torrent);
480 guy.SetWeapon(&zircoAx);
481 guy.SetArmor(&zirconArmor);
483 megaShield.SetName("Mega shield");
484 megaShield.SetMenuIcon(&shieldIcon);
486 ironBarrier.SetName("Iron barrier");
487 ironBarrier.SetCost(255);
488 ironBarrier.GetTargetingMode().TargetAllAllies(); // FIXME: actually only targets self
489 ironBarrier.SetMagical();
490 megaShield.SetIkari(&ironBarrier);
491 guy.SetShield(&megaShield);
493 zircoHelmet.SetName("Zirco helmet");
494 zircoHelmet.SetMenuIcon(&helmetIcon);
496 slow.SetName("Slow");
498 slow.GetTargetingMode().TargetAllEnemies();
500 zircoHelmet.SetIkari(&slow);
501 guy.SetHelmet(&zircoHelmet);
503 powerRing.SetName("Power ring");
504 powerRing.SetMenuIcon(&ringIcon);
506 trick.SetName("Trick");
508 trick.GetTargetingMode().TargetAllEnemies();
510 zircoHelmet.SetIkari(&trick);
511 guy.SetRing(&powerRing);
512 guy.SetJewel(&evilJewel);
514 // NOTE: this is actually Artea equipment
516 lizardBlow.SetName("Lizard blow");
517 lizardBlow.SetMenuIcon(&swordIcon);
519 dragonRush.SetName("Dragon rush");
520 dragonRush.SetCost(164);
521 dragonRush.GetTargetingMode().TargetSingleEnemy();
522 dragonRush.SetPhysical();
523 lizardBlow.SetIkari(&dragonRush);
524 dekar.SetWeapon(&lizardBlow);
526 holyRobe.SetName("Holy robe");
527 holyRobe.SetMenuIcon(&armorIcon);
529 crisisCure.SetName("Crisis cure");
530 crisisCure.SetCost(164);
531 crisisCure.GetTargetingMode().TargetAllAllies();
532 crisisCure.SetMagical();
533 holyRobe.SetIkari(&crisisCure);
534 dekar.SetArmor(&holyRobe);
535 dekar.SetShield(&zircoGloves);
536 dekar.SetHelmet(&holyCap);
538 rocketRing.SetName("Rocket ring");
539 rocketRing.SetMenuIcon(&ringIcon);
541 fake.SetName("Fake");
543 fake.GetTargetingMode().TargetSingleAlly();
545 rocketRing.SetIkari(&fake);
546 dekar.SetRing(&rocketRing);
548 krakenRock.SetName("Kraken rock");
549 krakenRock.SetMenuIcon(&jewelIcon);
551 tenLegger.SetName("Ten-legger");
552 tenLegger.SetCost(164);
553 tenLegger.GetTargetingMode().TargetAllEnemies();
554 tenLegger.SetPhysical();
555 rocketRing.SetIkari(&tenLegger);
556 dekar.SetJewel(&krakenRock);
558 battleRes.ikariMenuHeadline = "Please choose equipment.";
559 battleRes.noEquipmentText = "No equip";
560 battleRes.ikariMenuPrototype = Menu<const Item *>(&normalFont, &disabledFont, &handCursorSprite, 12, 6, normalFont.CharHeight() / 2, normalFont.CharWidth(), 1, normalFont.CharWidth() * 2, 0, ':', 12, normalFont.CharWidth());
562 battleRes.escapeText = "Escapes.";
564 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &battleRes));
565 battleState->AddMonster(monster);
566 battleState->AddMonster(monster);
567 battleState->AddMonster(monster);
568 battleState->AddMonster(monster);
569 battleState->AddHero(maxim);
570 battleState->AddHero(selan);
571 battleState->AddHero(guy);
572 battleState->AddHero(dekar);
573 Application app(&screen, battleState);
574 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
575 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
576 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
577 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
578 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
579 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
580 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
581 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
582 app.Buttons().MapKey(SDLK_RETURN, Input::START);
583 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
584 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
585 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
589 } catch (exception &e) {
590 cerr << "exception in main(): " << e.what() << endl;