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);
100 maxim.SetAttackFrames(3);
101 maxim.SetSpellFrames(2);
103 SDL_Surface *selanImg(IMG_Load("test-data/selan.png"));
104 Sprite selanSprite(selanImg, 64, 64);
106 selan.SetName("Selan");
108 selan.SetSprite(&selanSprite);
109 selan.SetMaxHealth(28);
111 selan.SetMaxMana(23);
114 selan.SetAttackFrames(3);
115 selan.SetSpellFrames(4);
117 SDL_Surface *guyImg(IMG_Load("test-data/guy.png"));
118 Sprite guySprite(guyImg, 64, 64);
122 guy.SetSprite(&guySprite);
123 guy.SetMaxHealth(38);
128 guy.SetAttackFrames(3);
129 guy.SetSpellFrames(0);
131 SDL_Surface *dekarImg(IMG_Load("test-data/dekar.png"));
132 Sprite dekarSprite(dekarImg, 64, 64);
134 dekar.SetName("Dekar");
136 dekar.SetSprite(&dekarSprite);
137 dekar.SetMaxHealth(38);
142 dekar.SetAttackFrames(3);
143 dekar.SetSpellFrames(3);
145 battle::Resources battleRes;
147 SDL_Surface *swapCursorImg(IMG_Load("test-data/swap-cursor.png"));
148 Sprite swapCursorSprite(swapCursorImg, 32, 32);
149 battleRes.swapCursor = &swapCursorSprite;
150 SDL_Surface *attackIconsImg(IMG_Load("test-data/attack-type-icons.png"));
151 Sprite attackIconsSprite(attackIconsImg, 32, 32);
152 battleRes.attackIcons = &attackIconsSprite;
153 SDL_Surface *attackChoiceIconsImg(IMG_Load("test-data/attack-choice-icons.png"));
154 Sprite attackChoiceIconsSprite(attackChoiceIconsImg, 16, 16);
155 battleRes.attackChoiceIcons = &attackChoiceIconsSprite;
156 SDL_Surface *moveIconsImg(IMG_Load("test-data/move-icons.png"));
157 Sprite moveIconsSprite(moveIconsImg, 32, 32);
158 battleRes.moveIcons = &moveIconsSprite;
160 SDL_Surface *titleFrameImg(IMG_Load("test-data/title-frame.png"));
161 Frame titleFrame(titleFrameImg, 16, 16);
162 battleRes.titleFrame = &titleFrame;
164 SDL_Surface *largeFontImg(IMG_Load("test-data/large-font.png"));
165 Sprite largeFontSprite(largeFontImg, 16, 32);
166 Font largeFont(&largeFontSprite, 0, -2);
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 battleRes.levelLabelCol = 0;
173 battleRes.levelLabelRow = 0;
174 battleRes.healthLabelCol = 0;
175 battleRes.healthLabelRow = 1;
176 battleRes.manaLabelCol = 0;
177 battleRes.manaLabelRow = 2;
178 battleRes.moveLabelCol = 0;
179 battleRes.moveLabelRow = 3;
180 battleRes.ikariLabelCol = 0;
181 battleRes.ikariLabelRow = 4;
183 SDL_Surface *numbersImg(IMG_Load("test-data/numbers.png"));
184 Sprite numbersSprite(numbersImg, 16, 16);
185 Font heroTagFont(&numbersSprite, 0, -3);
186 battleRes.heroTagFont = &heroTagFont;
187 SDL_Surface *tagFramesImg(IMG_Load("test-data/tag-frames.png"));
188 Frame heroTagFrame(tagFramesImg, 16, 16, 1, 1, 0, 33);
189 battleRes.heroTagFrame = &heroTagFrame;
190 Frame activeHeroTagFrame(tagFramesImg, 16, 16);
191 battleRes.activeHeroTagFrame = &activeHeroTagFrame;
192 SDL_Surface *smallTagFrameImg(IMG_Load("test-data/small-tag-frame.png"));
193 Frame smallTagFrame(smallTagFrameImg, 8, 16);
194 battleRes.smallHeroTagFrame = &smallTagFrame;
195 Frame lastSmallTagFrame(smallTagFrameImg, 8, 16, 1, 1, 0, 33);
196 battleRes.lastSmallHeroTagFrame = &lastSmallTagFrame;
197 battleRes.heroesBgColor = SDL_MapRGB(screen.Screen()->format, 0x18, 0x28, 0x31);
199 SDL_Surface *gauges(IMG_Load("test-data/gauges.png"));
200 Gauge healthGauge(gauges, 0, 16, 0, 0, 16, 6, 1, 6);
201 battleRes.healthGauge = &healthGauge;
202 Gauge manaGauge(gauges, 0, 32, 0, 0, 16, 6, 1, 6);
203 battleRes.manaGauge = &manaGauge;
204 Gauge ikariGauge(gauges, 0, 48, 0, 0, 16, 6, 1, 6);
205 battleRes.ikariGauge = &ikariGauge;
207 SDL_Surface *selectFrameImg(IMG_Load("test-data/select-frame.png"));
208 Frame selectFrame(selectFrameImg, 16, 16);
209 battleRes.selectFrame = &selectFrame;
211 SDL_Surface *normalFontImg(IMG_Load("test-data/normal-font.png"));
212 Sprite normalFontSprite(normalFontImg, 16, 16);
213 Font normalFont(&normalFontSprite, 0, -2);
214 battleRes.normalFont = &normalFont;
216 SDL_Surface *disabledFontImg(IMG_Load("test-data/disabled-font.png"));
217 Sprite disabledFontSprite(disabledFontImg, 16, 16);
218 Font disabledFont(&disabledFontSprite, 0, -2);
219 battleRes.disabledFont = &disabledFont;
221 SDL_Surface *handCursorImg(IMG_Load("test-data/cursor-hand.png"));
222 Sprite handCursorSprite(handCursorImg, 32, 32);
223 battleRes.menuCursor = &handCursorSprite;
225 SDL_Surface *targetingIconsImg(IMG_Load("test-data/targeting-icons.png"));
226 Sprite weaponTargetCursor(targetingIconsImg, 32, 32);
227 Sprite magicTargetCursor(targetingIconsImg, 32, 32, 0, 32);
228 Sprite itemTargetCursor(targetingIconsImg, 32, 32, 0, 64);
229 battleRes.weaponTargetCursor = &weaponTargetCursor;
230 // TODO: add image for magic targeting cursor
231 battleRes.magicTargetCursor = &magicTargetCursor;
232 // TODO: add image for item targeting cursor
233 battleRes.itemTargetCursor = &itemTargetCursor;
236 resetSpell.SetName("Reset");
237 maxim.AddSpell(&resetSpell);
239 strongSpell.SetName("Strong");
240 strongSpell.SetCost(3);
241 strongSpell.SetUsableInBattle();
242 strongSpell.GetTargetingMode().TargetMultipleAllies();
243 maxim.AddSpell(&strongSpell);
244 selan.AddSpell(&strongSpell);
246 strongerSpell.SetName("Stronger");
247 strongerSpell.SetCost(8);
248 strongerSpell.SetUsableInBattle();
249 strongerSpell.GetTargetingMode().TargetMultipleAllies();
250 maxim.AddSpell(&strongerSpell);
251 selan.AddSpell(&strongerSpell);
253 championSpell.SetName("Champion");
254 championSpell.SetCost(16);
255 championSpell.SetUsableInBattle();
256 championSpell.GetTargetingMode().TargetMultipleAllies();
257 maxim.AddSpell(&championSpell);
258 selan.AddSpell(&championSpell);
260 rallySpell.SetName("Rally");
261 rallySpell.SetCost(10);
262 rallySpell.SetUsableInBattle();
263 rallySpell.GetTargetingMode().TargetMultipleAllies();
264 maxim.AddSpell(&rallySpell);
265 selan.AddSpell(&rallySpell);
267 escapeSpell.SetName("Escape");
268 escapeSpell.SetCost(8);
269 selan.AddSpell(&escapeSpell);
271 valorSpell.SetName("Valor");
272 valorSpell.SetCost(30);
273 valorSpell.SetUsableInBattle();
274 valorSpell.GetTargetingMode().TargetMultipleAllies();
275 maxim.AddSpell(&valorSpell);
276 selan.AddSpell(&valorSpell);
278 battleRes.spellMenuHeadline = "Please choose a spell.";
279 battleRes.spellMenuPrototype = Menu<const Spell *>(&normalFont, &disabledFont, &handCursorSprite, 9, 6, 8, 0, 2, 32, 2, ':');
281 SDL_Surface *itemIcons(IMG_Load("test-data/item-icons.png"));
282 Sprite potionIcon(itemIcons, 16, 16);
283 Sprite ballIcon(itemIcons, 16, 16, 0, 16);
284 Sprite crankIcon(itemIcons, 16, 16, 0, 32);
285 Sprite spearIcon(itemIcons, 16, 16, 0, 48);
286 Sprite swordIcon(itemIcons, 16, 16, 0, 64);
287 Sprite axIcon(itemIcons, 16, 16, 0, 80);
288 Sprite rodIcon(itemIcons, 16, 16, 0, 96);
289 Sprite armorIcon(itemIcons, 16, 16, 0, 112);
290 Sprite shieldIcon(itemIcons, 16, 16, 0, 128);
291 Sprite helmetIcon(itemIcons, 16, 16, 0, 144);
292 Sprite ringIcon(itemIcons, 16, 16, 0, 160);
293 Sprite jewelIcon(itemIcons, 16, 16, 0, 176);
295 battleRes.weaponMenuIcon = &swordIcon;
296 battleRes.armorMenuIcon = &armorIcon;
297 battleRes.shieldMenuIcon = &shieldIcon;
298 battleRes.helmetMenuIcon = &helmetIcon;
299 battleRes.ringMenuIcon = &ringIcon;
300 battleRes.jewelMenuIcon = &jewelIcon;
304 antidote.SetName("Antidote");
305 antidote.SetMenuIcon(&potionIcon);
306 antidote.SetUsableInBattle();
307 antidote.GetTargetingMode().TargetSingleAlly();
308 inventory.Add(&antidote, 9);
310 magicJar.SetName("Magic jar");
311 magicJar.SetMenuIcon(&potionIcon);
312 magicJar.SetUsableInBattle();
313 magicJar.GetTargetingMode().TargetSingleAlly();
314 inventory.Add(&magicJar, 4);
316 hiPotion.SetName("Hi-Potion");
317 hiPotion.SetMenuIcon(&potionIcon);
318 hiPotion.SetUsableInBattle();
319 hiPotion.GetTargetingMode().TargetSingleAlly();
320 inventory.Add(&hiPotion, 4);
322 powerPotion.SetName("Power potion");
323 powerPotion.SetMenuIcon(&potionIcon);
324 inventory.Add(&powerPotion, 4);
326 escape.SetName("Escape");
327 inventory.Add(&escape, 2);
329 sleepBall.SetName("Sleep ball");
330 sleepBall.SetMenuIcon(&ballIcon);
331 sleepBall.SetUsableInBattle();
332 sleepBall.GetTargetingMode().TargetSingleEnemy();
333 inventory.Add(&sleepBall, 1);
335 multiBall.SetName("Multi-ball!");
336 multiBall.SetMenuIcon(&ballIcon);
337 multiBall.SetUsableInBattle();
338 multiBall.GetTargetingMode().TargetMultipleEnemies();
339 inventory.Add(&multiBall, 1);
341 figgoru.SetName("Figgoru");
342 figgoru.SetMenuIcon(&crankIcon);
343 figgoru.GetTargetingMode().TargetAllEnemies();
344 inventory.Add(&figgoru, 1);
345 battleRes.inventory = &inventory;
347 battleRes.itemMenuHeadline = "Please choose an item.";
348 battleRes.itemMenuPrototype = Menu<const common::Item *>(&normalFont, &disabledFont, &handCursorSprite, 15, 6, 8, 16, 1, 32, 2, ':');
351 zircoSword.SetName("Zirco sword");
352 zircoSword.SetMenuIcon(&swordIcon);
354 firestorm.SetName("Firestorm");
355 firestorm.SetCost(224);
356 firestorm.GetTargetingMode().TargetAllEnemies();
357 firestorm.SetPhysical();
358 zircoSword.SetIkari(&firestorm);
359 maxim.SetWeapon(&zircoSword);
361 zirconArmor.SetName("Zircon armor");
362 zirconArmor.SetMenuIcon(&armorIcon);
364 magicCure.SetName("Magic cure");
365 magicCure.SetCost(128);
366 magicCure.GetTargetingMode().TargetSingleAlly();
367 magicCure.SetMagical();
368 zirconArmor.SetIkari(&magicCure);
369 maxim.SetArmor(&zirconArmor);
371 holyShield.SetName("Holy shield");
372 holyShield.SetMenuIcon(&shieldIcon);
374 lightGuard.SetName("Light guard");
375 lightGuard.SetCost(128);
376 lightGuard.GetTargetingMode().TargetAllAllies(); // FIXME: actually only targets self
377 lightGuard.SetMagical();
378 holyShield.SetIkari(&lightGuard);
379 maxim.SetShield(&holyShield);
381 legendHelm.SetName("Legend helm");
382 legendHelm.SetMenuIcon(&helmetIcon);
384 boomerang.SetName("Boomerang");
385 boomerang.SetCost(164);
386 boomerang.GetTargetingMode().TargetAllAllies(); // FIXME: actually only targets self
387 boomerang.SetMagical();
388 legendHelm.SetIkari(&boomerang);
389 maxim.SetHelmet(&legendHelm);
391 sProRing.SetName("S-pro ring");
392 sProRing.SetMenuIcon(&ringIcon);
394 courage.SetName("Courage");
396 courage.GetTargetingMode().TargetMultipleAllies();
397 courage.SetMagical();
398 sProRing.SetIkari(&courage);
399 maxim.SetRing(&sProRing);
401 evilJewel.SetName("Evil jewel");
402 evilJewel.SetMenuIcon(&jewelIcon);
404 gloomy.SetName("Gloomy");
406 gloomy.GetTargetingMode().TargetAllEnemies();
408 evilJewel.SetIkari(&gloomy);
409 maxim.SetJewel(&evilJewel);
412 zircoWhip.SetName("Zirco whip");
413 zircoWhip.SetMenuIcon(&rodIcon);
415 thundershriek.SetName("Thundershriek");
416 thundershriek.SetCost(224);
417 thundershriek.GetTargetingMode().TargetAllEnemies();
418 thundershriek.SetPhysical();
419 zircoWhip.SetIkari(&thundershriek);
420 selan.SetWeapon(&zircoWhip);
422 zirconPlate.SetName("Zircon plate");
423 zirconPlate.SetMenuIcon(&armorIcon);
425 suddenCure.SetName("Sudden cure");
426 suddenCure.SetCost(96);
427 suddenCure.GetTargetingMode().TargetAllAllies();
428 suddenCure.SetMagical();
429 zirconPlate.SetIkari(&suddenCure);
430 selan.SetArmor(&zirconPlate);
432 zircoGloves.SetName("Zirco gloves");
433 zircoGloves.SetMenuIcon(&shieldIcon);
435 forcefield.SetName("Forcefield");
436 forcefield.SetCost(64);
437 forcefield.GetTargetingMode().TargetAllAllies();
438 forcefield.SetMagical();
439 zircoGloves.SetIkari(&forcefield);
440 selan.SetShield(&zircoGloves);
442 holyCap.SetName("Holy cap");
443 holyCap.SetMenuIcon(&helmetIcon);
445 vulnerable.SetName("Vulnerable");
446 vulnerable.SetCost(196);
447 vulnerable.GetTargetingMode().TargetAllEnemies();
448 vulnerable.SetPhysical();
449 holyCap.SetIkari(&vulnerable);
450 selan.SetHelmet(&holyCap);
452 ghostRing.SetName("Ghost ring");
453 ghostRing.SetMenuIcon(&ringIcon);
455 destroy.SetName("Destroy");
456 destroy.SetCost(128);
457 destroy.GetTargetingMode().TargetMultipleEnemies();
458 destroy.SetMagical();
459 ghostRing.SetIkari(&destroy);
460 selan.SetRing(&ghostRing);
462 eagleRock.SetName("Eagle rock");
463 eagleRock.SetMenuIcon(&jewelIcon);
465 dive.SetName("Dive");
467 dive.GetTargetingMode().TargetSingleEnemy();
469 eagleRock.SetIkari(&dive);
470 selan.SetJewel(&eagleRock);
473 zircoAx.SetName("Zirco ax");
474 zircoAx.SetMenuIcon(&axIcon);
476 torrent.SetName("Torrent");
477 torrent.SetCost(224);
478 torrent.GetTargetingMode().TargetAllEnemies();
479 torrent.SetPhysical();
480 zircoAx.SetIkari(&torrent);
481 guy.SetWeapon(&zircoAx);
482 guy.SetArmor(&zirconArmor);
484 megaShield.SetName("Mega shield");
485 megaShield.SetMenuIcon(&shieldIcon);
487 ironBarrier.SetName("Iron barrier");
488 ironBarrier.SetCost(255);
489 ironBarrier.GetTargetingMode().TargetAllAllies(); // FIXME: actually only targets self
490 ironBarrier.SetMagical();
491 megaShield.SetIkari(&ironBarrier);
492 guy.SetShield(&megaShield);
494 zircoHelmet.SetName("Zirco helmet");
495 zircoHelmet.SetMenuIcon(&helmetIcon);
497 slow.SetName("Slow");
499 slow.GetTargetingMode().TargetAllEnemies();
501 zircoHelmet.SetIkari(&slow);
502 guy.SetHelmet(&zircoHelmet);
504 powerRing.SetName("Power ring");
505 powerRing.SetMenuIcon(&ringIcon);
507 trick.SetName("Trick");
509 trick.GetTargetingMode().TargetAllEnemies();
511 zircoHelmet.SetIkari(&trick);
512 guy.SetRing(&powerRing);
513 guy.SetJewel(&evilJewel);
515 // NOTE: this is actually Artea equipment
517 lizardBlow.SetName("Lizard blow");
518 lizardBlow.SetMenuIcon(&swordIcon);
520 dragonRush.SetName("Dragon rush");
521 dragonRush.SetCost(164);
522 dragonRush.GetTargetingMode().TargetSingleEnemy();
523 dragonRush.SetPhysical();
524 lizardBlow.SetIkari(&dragonRush);
525 dekar.SetWeapon(&lizardBlow);
527 holyRobe.SetName("Holy robe");
528 holyRobe.SetMenuIcon(&armorIcon);
530 crisisCure.SetName("Crisis cure");
531 crisisCure.SetCost(164);
532 crisisCure.GetTargetingMode().TargetAllAllies();
533 crisisCure.SetMagical();
534 holyRobe.SetIkari(&crisisCure);
535 dekar.SetArmor(&holyRobe);
536 dekar.SetShield(&zircoGloves);
537 dekar.SetHelmet(&holyCap);
539 rocketRing.SetName("Rocket ring");
540 rocketRing.SetMenuIcon(&ringIcon);
542 fake.SetName("Fake");
544 fake.GetTargetingMode().TargetSingleAlly();
546 rocketRing.SetIkari(&fake);
547 dekar.SetRing(&rocketRing);
549 krakenRock.SetName("Kraken rock");
550 krakenRock.SetMenuIcon(&jewelIcon);
552 tenLegger.SetName("Ten-legger");
553 tenLegger.SetCost(164);
554 tenLegger.GetTargetingMode().TargetAllEnemies();
555 tenLegger.SetPhysical();
556 rocketRing.SetIkari(&tenLegger);
557 dekar.SetJewel(&krakenRock);
559 battleRes.ikariMenuHeadline = "Please choose equipment.";
560 battleRes.noEquipmentText = "No equip";
561 battleRes.ikariMenuPrototype = Menu<const Item *>(&normalFont, &disabledFont, &handCursorSprite, 12, 6, normalFont.CharHeight() / 2, normalFont.CharWidth(), 1, normalFont.CharWidth() * 2, 0, ':', 12, normalFont.CharWidth());
563 battleRes.escapeText = "Escapes.";
565 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &battleRes));
566 battleState->AddMonster(monster);
567 battleState->AddMonster(monster);
568 battleState->AddMonster(monster);
569 battleState->AddMonster(monster);
570 battleState->AddHero(maxim);
571 battleState->AddHero(selan);
572 battleState->AddHero(guy);
573 battleState->AddHero(dekar);
574 Application app(&screen, battleState);
575 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
576 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
577 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
578 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
579 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
580 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
581 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
582 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
583 app.Buttons().MapKey(SDLK_RETURN, Input::START);
584 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
585 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
586 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
590 } catch (exception &e) {
591 cerr << "exception in main(): " << e.what() << endl;