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>(128, 152));
78 heroesLayout.AddPosition(Point<Uint8>(80, 168));
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, 0, -2);
159 battleRes.titleFont = &largeFont;
161 SDL_Surface *heroTagImg(IMG_Load("test-data/hero-tag-sprites.png"));
162 Sprite heroTagSprite(heroTagImg, 32, 16);
163 battleRes.heroTagLabels = &heroTagSprite;
164 battleRes.levelLabelCol = 0;
165 battleRes.levelLabelRow = 0;
166 battleRes.healthLabelCol = 0;
167 battleRes.healthLabelRow = 1;
168 battleRes.manaLabelCol = 0;
169 battleRes.manaLabelRow = 2;
170 battleRes.moveLabelCol = 0;
171 battleRes.moveLabelRow = 3;
172 battleRes.ikariLabelCol = 0;
173 battleRes.ikariLabelRow = 4;
175 SDL_Surface *numbersImg(IMG_Load("test-data/numbers.png"));
176 Sprite numbersSprite(numbersImg, 16, 16);
177 Font heroTagFont(&numbersSprite, 0, -3);
178 battleRes.heroTagFont = &heroTagFont;
179 SDL_Surface *tagFramesImg(IMG_Load("test-data/tag-frames.png"));
180 Frame heroTagFrame(tagFramesImg, 16, 16, 1, 1, 0, 33);
181 battleRes.heroTagFrame = &heroTagFrame;
182 Frame activeHeroTagFrame(tagFramesImg, 16, 16);
183 battleRes.activeHeroTagFrame = &activeHeroTagFrame;
184 SDL_Surface *smallTagFrameImg(IMG_Load("test-data/small-tag-frame.png"));
185 Frame smallTagFrame(smallTagFrameImg, 8, 16);
186 battleRes.smallHeroTagFrame = &smallTagFrame;
187 Frame lastSmallTagFrame(smallTagFrameImg, 8, 16, 1, 1, 0, 33);
188 battleRes.lastSmallHeroTagFrame = &lastSmallTagFrame;
189 battleRes.heroesBgColor = SDL_MapRGB(screen.Screen()->format, 0x18, 0x28, 0x31);
191 SDL_Surface *gauges(IMG_Load("test-data/gauges.png"));
192 Gauge healthGauge(gauges, 0, 16, 0, 0, 16, 6, 1, 6);
193 battleRes.healthGauge = &healthGauge;
194 Gauge manaGauge(gauges, 0, 32, 0, 0, 16, 6, 1, 6);
195 battleRes.manaGauge = &manaGauge;
196 Gauge ikariGauge(gauges, 0, 48, 0, 0, 16, 6, 1, 6);
197 battleRes.ikariGauge = &ikariGauge;
199 SDL_Surface *selectFrameImg(IMG_Load("test-data/select-frame.png"));
200 Frame selectFrame(selectFrameImg, 16, 16);
201 battleRes.selectFrame = &selectFrame;
203 SDL_Surface *normalFontImg(IMG_Load("test-data/normal-font.png"));
204 Sprite normalFontSprite(normalFontImg, 16, 16);
205 Font normalFont(&normalFontSprite, 0, -2);
206 battleRes.normalFont = &normalFont;
208 SDL_Surface *disabledFontImg(IMG_Load("test-data/disabled-font.png"));
209 Sprite disabledFontSprite(disabledFontImg, 16, 16);
210 Font disabledFont(&disabledFontSprite, 0, -2);
211 battleRes.disabledFont = &disabledFont;
213 SDL_Surface *handCursorImg(IMG_Load("test-data/cursor-hand.png"));
214 Sprite handCursorSprite(handCursorImg, 32, 32);
215 battleRes.menuCursor = &handCursorSprite;
217 SDL_Surface *targetingIconsImg(IMG_Load("test-data/targeting-icons.png"));
218 Sprite weaponTargetCursor(targetingIconsImg, 32, 32);
219 Sprite magicTargetCursor(targetingIconsImg, 32, 32, 0, 32);
220 Sprite itemTargetCursor(targetingIconsImg, 32, 32, 0, 64);
221 battleRes.weaponTargetCursor = &weaponTargetCursor;
222 // TODO: add image for magic targeting cursor
223 battleRes.magicTargetCursor = &magicTargetCursor;
224 // TODO: add image for item targeting cursor
225 battleRes.itemTargetCursor = &itemTargetCursor;
228 resetSpell.SetName("Reset");
229 maxim.AddSpell(&resetSpell);
231 strongSpell.SetName("Strong");
232 strongSpell.SetCost(3);
233 strongSpell.SetUsableInBattle();
234 strongSpell.GetTargetingMode().TargetMultipleAllies();
235 maxim.AddSpell(&strongSpell);
236 selan.AddSpell(&strongSpell);
238 strongerSpell.SetName("Stronger");
239 strongerSpell.SetCost(8);
240 strongerSpell.SetUsableInBattle();
241 strongerSpell.GetTargetingMode().TargetMultipleAllies();
242 maxim.AddSpell(&strongerSpell);
243 selan.AddSpell(&strongerSpell);
245 championSpell.SetName("Champion");
246 championSpell.SetCost(16);
247 championSpell.SetUsableInBattle();
248 championSpell.GetTargetingMode().TargetMultipleAllies();
249 maxim.AddSpell(&championSpell);
250 selan.AddSpell(&championSpell);
252 rallySpell.SetName("Rally");
253 rallySpell.SetCost(10);
254 rallySpell.SetUsableInBattle();
255 rallySpell.GetTargetingMode().TargetMultipleAllies();
256 maxim.AddSpell(&rallySpell);
257 selan.AddSpell(&rallySpell);
259 escapeSpell.SetName("Escape");
260 escapeSpell.SetCost(8);
261 selan.AddSpell(&escapeSpell);
263 valorSpell.SetName("Valor");
264 valorSpell.SetCost(30);
265 valorSpell.SetUsableInBattle();
266 valorSpell.GetTargetingMode().TargetMultipleAllies();
267 maxim.AddSpell(&valorSpell);
268 selan.AddSpell(&valorSpell);
270 battleRes.spellMenuHeadline = "Please choose a spell.";
271 battleRes.spellMenuPrototype = Menu<const Spell *>(&normalFont, &disabledFont, &handCursorSprite, 9, 6, 8, 0, 2, 32, 2, ':');
273 SDL_Surface *itemIcons(IMG_Load("test-data/item-icons.png"));
274 Sprite potionIcon(itemIcons, 16, 16);
275 Sprite ballIcon(itemIcons, 16, 16, 0, 16);
276 Sprite crankIcon(itemIcons, 16, 16, 0, 32);
277 Sprite spearIcon(itemIcons, 16, 16, 0, 48);
278 Sprite swordIcon(itemIcons, 16, 16, 0, 64);
279 Sprite axIcon(itemIcons, 16, 16, 0, 80);
280 Sprite rodIcon(itemIcons, 16, 16, 0, 96);
281 Sprite armorIcon(itemIcons, 16, 16, 0, 112);
282 Sprite shieldIcon(itemIcons, 16, 16, 0, 128);
283 Sprite helmetIcon(itemIcons, 16, 16, 0, 144);
284 Sprite ringIcon(itemIcons, 16, 16, 0, 160);
285 Sprite jewelIcon(itemIcons, 16, 16, 0, 176);
287 battleRes.weaponMenuIcon = &swordIcon;
288 battleRes.armorMenuIcon = &armorIcon;
289 battleRes.shieldMenuIcon = &shieldIcon;
290 battleRes.helmetMenuIcon = &helmetIcon;
291 battleRes.ringMenuIcon = &ringIcon;
292 battleRes.jewelMenuIcon = &jewelIcon;
296 antidote.SetName("Antidote");
297 antidote.SetMenuIcon(&potionIcon);
298 antidote.SetUsableInBattle();
299 antidote.GetTargetingMode().TargetSingleAlly();
300 inventory.Add(&antidote, 9);
302 magicJar.SetName("Magic jar");
303 magicJar.SetMenuIcon(&potionIcon);
304 magicJar.SetUsableInBattle();
305 magicJar.GetTargetingMode().TargetSingleAlly();
306 inventory.Add(&magicJar, 4);
308 hiPotion.SetName("Hi-Potion");
309 hiPotion.SetMenuIcon(&potionIcon);
310 hiPotion.SetUsableInBattle();
311 hiPotion.GetTargetingMode().TargetSingleAlly();
312 inventory.Add(&hiPotion, 4);
314 powerPotion.SetName("Power potion");
315 powerPotion.SetMenuIcon(&potionIcon);
316 inventory.Add(&powerPotion, 4);
318 escape.SetName("Escape");
319 inventory.Add(&escape, 2);
321 sleepBall.SetName("Sleep ball");
322 sleepBall.SetMenuIcon(&ballIcon);
323 sleepBall.SetUsableInBattle();
324 sleepBall.GetTargetingMode().TargetSingleEnemy();
325 inventory.Add(&sleepBall, 1);
327 multiBall.SetName("Multi-ball!");
328 multiBall.SetMenuIcon(&ballIcon);
329 multiBall.SetUsableInBattle();
330 multiBall.GetTargetingMode().TargetMultipleEnemies();
331 inventory.Add(&multiBall, 1);
333 figgoru.SetName("Figgoru");
334 figgoru.SetMenuIcon(&crankIcon);
335 figgoru.GetTargetingMode().TargetAllEnemies();
336 inventory.Add(&figgoru, 1);
337 battleRes.inventory = &inventory;
339 battleRes.itemMenuHeadline = "Please choose an item.";
340 battleRes.itemMenuPrototype = Menu<const common::Item *>(&normalFont, &disabledFont, &handCursorSprite, 15, 6, 8, 16, 1, 32, 2, ':');
343 zircoSword.SetName("Zirco sword");
344 zircoSword.SetMenuIcon(&swordIcon);
346 firestorm.SetName("Firestorm");
347 firestorm.SetCost(224);
348 firestorm.GetTargetingMode().TargetAllEnemies();
349 firestorm.SetPhysical();
350 zircoSword.SetIkari(&firestorm);
351 maxim.SetWeapon(&zircoSword);
353 zirconArmor.SetName("Zircon armor");
354 zirconArmor.SetMenuIcon(&armorIcon);
356 magicCure.SetName("Magic cure");
357 magicCure.SetCost(128);
358 magicCure.GetTargetingMode().TargetSingleAlly();
359 magicCure.SetMagical();
360 zirconArmor.SetIkari(&magicCure);
361 maxim.SetArmor(&zirconArmor);
363 holyShield.SetName("Holy shield");
364 holyShield.SetMenuIcon(&shieldIcon);
366 lightGuard.SetName("Light guard");
367 lightGuard.SetCost(128);
368 lightGuard.GetTargetingMode().TargetAllAllies(); // FIXME: actually only targets self
369 lightGuard.SetMagical();
370 holyShield.SetIkari(&lightGuard);
371 maxim.SetShield(&holyShield);
373 legendHelm.SetName("Legend helm");
374 legendHelm.SetMenuIcon(&helmetIcon);
376 boomerang.SetName("Boomerang");
377 boomerang.SetCost(164);
378 boomerang.GetTargetingMode().TargetAllAllies(); // FIXME: actually only targets self
379 boomerang.SetMagical();
380 legendHelm.SetIkari(&boomerang);
381 maxim.SetHelmet(&legendHelm);
383 sProRing.SetName("S-pro ring");
384 sProRing.SetMenuIcon(&ringIcon);
386 courage.SetName("Courage");
388 courage.GetTargetingMode().TargetMultipleAllies();
389 courage.SetMagical();
390 sProRing.SetIkari(&courage);
391 maxim.SetRing(&sProRing);
393 evilJewel.SetName("Evil jewel");
394 evilJewel.SetMenuIcon(&jewelIcon);
396 gloomy.SetName("Gloomy");
398 gloomy.GetTargetingMode().TargetAllEnemies();
400 evilJewel.SetIkari(&gloomy);
401 maxim.SetJewel(&evilJewel);
404 zircoWhip.SetName("Zirco whip");
405 zircoWhip.SetMenuIcon(&rodIcon);
407 thundershriek.SetName("Thundershriek");
408 thundershriek.SetCost(224);
409 thundershriek.GetTargetingMode().TargetAllEnemies();
410 thundershriek.SetPhysical();
411 zircoWhip.SetIkari(&thundershriek);
412 selan.SetWeapon(&zircoWhip);
414 zirconPlate.SetName("Zircon plate");
415 zirconPlate.SetMenuIcon(&armorIcon);
417 suddenCure.SetName("Sudden cure");
418 suddenCure.SetCost(96);
419 suddenCure.GetTargetingMode().TargetAllAllies();
420 suddenCure.SetMagical();
421 zirconPlate.SetIkari(&suddenCure);
422 selan.SetArmor(&zirconPlate);
424 zircoGloves.SetName("Zirco gloves");
425 zircoGloves.SetMenuIcon(&shieldIcon);
427 forcefield.SetName("Forcefield");
428 forcefield.SetCost(64);
429 forcefield.GetTargetingMode().TargetAllAllies();
430 forcefield.SetMagical();
431 zircoGloves.SetIkari(&forcefield);
432 selan.SetShield(&zircoGloves);
434 holyCap.SetName("Holy cap");
435 holyCap.SetMenuIcon(&helmetIcon);
437 vulnerable.SetName("Vulnerable");
438 vulnerable.SetCost(196);
439 vulnerable.GetTargetingMode().TargetAllEnemies();
440 vulnerable.SetPhysical();
441 holyCap.SetIkari(&vulnerable);
442 selan.SetHelmet(&holyCap);
444 ghostRing.SetName("Ghost ring");
445 ghostRing.SetMenuIcon(&ringIcon);
447 destroy.SetName("Destroy");
448 destroy.SetCost(128);
449 destroy.GetTargetingMode().TargetMultipleEnemies();
450 destroy.SetMagical();
451 ghostRing.SetIkari(&destroy);
452 selan.SetRing(&ghostRing);
454 eagleRock.SetName("Eagle rock");
455 eagleRock.SetMenuIcon(&jewelIcon);
457 dive.SetName("Dive");
459 dive.GetTargetingMode().TargetSingleEnemy();
461 eagleRock.SetIkari(&dive);
462 selan.SetJewel(&eagleRock);
465 zircoAx.SetName("Zirco ax");
466 zircoAx.SetMenuIcon(&axIcon);
468 torrent.SetName("Torrent");
469 torrent.SetCost(224);
470 torrent.GetTargetingMode().TargetAllEnemies();
471 torrent.SetPhysical();
472 zircoAx.SetIkari(&torrent);
473 guy.SetWeapon(&zircoAx);
474 guy.SetArmor(&zirconArmor);
476 megaShield.SetName("Mega shield");
477 megaShield.SetMenuIcon(&shieldIcon);
479 ironBarrier.SetName("Iron barrier");
480 ironBarrier.SetCost(255);
481 ironBarrier.GetTargetingMode().TargetAllAllies(); // FIXME: actually only targets self
482 ironBarrier.SetMagical();
483 megaShield.SetIkari(&ironBarrier);
484 guy.SetShield(&megaShield);
486 zircoHelmet.SetName("Zirco helmet");
487 zircoHelmet.SetMenuIcon(&helmetIcon);
489 slow.SetName("Slow");
491 slow.GetTargetingMode().TargetAllEnemies();
493 zircoHelmet.SetIkari(&slow);
494 guy.SetHelmet(&zircoHelmet);
496 powerRing.SetName("Power ring");
497 powerRing.SetMenuIcon(&ringIcon);
499 trick.SetName("Trick");
501 trick.GetTargetingMode().TargetAllEnemies();
503 zircoHelmet.SetIkari(&trick);
504 guy.SetRing(&powerRing);
505 guy.SetJewel(&evilJewel);
507 // NOTE: this is actually Artea equipment
509 lizardBlow.SetName("Lizard blow");
510 lizardBlow.SetMenuIcon(&swordIcon);
512 dragonRush.SetName("Dragon rush");
513 dragonRush.SetCost(164);
514 dragonRush.GetTargetingMode().TargetSingleEnemy();
515 dragonRush.SetPhysical();
516 lizardBlow.SetIkari(&dragonRush);
517 dekar.SetWeapon(&lizardBlow);
519 holyRobe.SetName("Holy robe");
520 holyRobe.SetMenuIcon(&armorIcon);
522 crisisCure.SetName("Crisis cure");
523 crisisCure.SetCost(164);
524 crisisCure.GetTargetingMode().TargetAllAllies();
525 crisisCure.SetMagical();
526 holyRobe.SetIkari(&crisisCure);
527 dekar.SetArmor(&holyRobe);
528 dekar.SetShield(&zircoGloves);
529 dekar.SetHelmet(&holyCap);
531 rocketRing.SetName("Rocket ring");
532 rocketRing.SetMenuIcon(&ringIcon);
534 fake.SetName("Fake");
536 fake.GetTargetingMode().TargetSingleAlly();
538 rocketRing.SetIkari(&fake);
539 dekar.SetRing(&rocketRing);
541 krakenRock.SetName("Kraken rock");
542 krakenRock.SetMenuIcon(&jewelIcon);
544 tenLegger.SetName("Ten-legger");
545 tenLegger.SetCost(164);
546 tenLegger.GetTargetingMode().TargetAllEnemies();
547 tenLegger.SetPhysical();
548 rocketRing.SetIkari(&tenLegger);
549 dekar.SetJewel(&krakenRock);
551 battleRes.ikariMenuHeadline = "Please choose equipment.";
552 battleRes.noEquipmentText = "No equip";
553 battleRes.ikariMenuPrototype = Menu<const Item *>(&normalFont, &disabledFont, &handCursorSprite, 12, 6, normalFont.CharHeight() / 2, normalFont.CharWidth(), 1, normalFont.CharWidth() * 2, 0, ':', 12, normalFont.CharWidth());
555 battleRes.escapeText = "Escapes.";
557 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &battleRes));
558 battleState->AddMonster(monster);
559 battleState->AddMonster(monster);
560 battleState->AddMonster(monster);
561 battleState->AddMonster(monster);
562 battleState->AddHero(maxim);
563 battleState->AddHero(selan);
564 battleState->AddHero(guy);
565 battleState->AddHero(dekar);
566 Application app(&screen, battleState);
567 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
568 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
569 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
570 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
571 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
572 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
573 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
574 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
575 app.Buttons().MapKey(SDLK_RETURN, Input::START);
576 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
577 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
578 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
582 } catch (exception &e) {
583 cerr << "exception in main(): " << e.what() << endl;