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.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;
151 SDL_Surface *titleFrameImg(IMG_Load("test-data/title-frame.png"));
152 Frame titleFrame(titleFrameImg, 16, 16);
153 battleRes.titleFrame = &titleFrame;
155 SDL_Surface *largeFontImg(IMG_Load("test-data/large-font.png"));
156 Sprite largeFontSprite(largeFontImg, 16, 32);
157 Font largeFont(&largeFontSprite);
158 largeFont.MapRange('A', 'M', 0, 1);
159 largeFont.MapRange('N', 'Z', 0, 2);
160 largeFont.MapRange('a', 'm', 0, 3);
161 largeFont.MapRange('n', 'z', 0, 4);
162 largeFont.MapChar(':', 10, 0);
163 largeFont.MapChar('!', 11, 0);
164 largeFont.MapChar('?', 12, 0);
165 // TODO: add '.' and '-' characters
166 battleRes.titleFont = &largeFont;
168 SDL_Surface *heroTagImg(IMG_Load("test-data/hero-tag-sprites.png"));
169 Sprite heroTagSprite(heroTagImg, 32, 16);
170 battleRes.heroTagLabels = &heroTagSprite;
171 SDL_Surface *numbersImg(IMG_Load("test-data/numbers.png"));
172 Sprite numbersSprite(numbersImg, 16, 16);
173 Font heroTagFont(&numbersSprite);
174 battleRes.heroTagFont = &heroTagFont;
175 SDL_Surface *tagFramesImg(IMG_Load("test-data/tag-frames.png"));
176 Frame heroTagFrame(tagFramesImg, 16, 16, 1, 1, 0, 33);
177 battleRes.heroTagFrame = &heroTagFrame;
178 Frame activeHeroTagFrame(tagFramesImg, 16, 16);
179 battleRes.activeHeroTagFrame = &activeHeroTagFrame;
181 SDL_Surface *gauges(IMG_Load("test-data/gauges.png"));
182 Gauge healthGauge(gauges, 0, 16, 0, 0, 16, 6, 1, 6);
183 battleRes.healthGauge = &healthGauge;
184 Gauge manaGauge(gauges, 0, 32, 0, 0, 16, 6, 1, 6);
185 battleRes.manaGauge = &manaGauge;
186 Gauge ikariGauge(gauges, 0, 48, 0, 0, 16, 6, 1, 6);
187 battleRes.ikariGauge = &ikariGauge;
189 SDL_Surface *selectFrameImg(IMG_Load("test-data/select-frame.png"));
190 Frame selectFrame(selectFrameImg, 16, 16);
191 battleRes.selectFrame = &selectFrame;
193 SDL_Surface *normalFontImg(IMG_Load("test-data/normal-font.png"));
194 Sprite normalFontSprite(normalFontImg, 16, 16);
195 Font normalFont(&normalFontSprite);
196 normalFont.MapRange('A', 'M', 0, 1);
197 normalFont.MapRange('N', 'Z', 0, 2);
198 normalFont.MapRange('a', 'm', 0, 3);
199 normalFont.MapRange('n', 'z', 0, 4);
200 normalFont.MapChar(':', 10, 0);
201 normalFont.MapChar('!', 11, 0);
202 normalFont.MapChar('?', 12, 0);
203 // TODO: add '.' and '-' characters
204 battleRes.normalFont = &normalFont;
206 SDL_Surface *disabledFontImg(IMG_Load("test-data/disabled-font.png"));
207 Sprite disabledFontSprite(disabledFontImg, 16, 16);
208 Font disabledFont(&disabledFontSprite);
209 disabledFont.MapRange('A', 'M', 0, 1);
210 disabledFont.MapRange('N', 'Z', 0, 2);
211 disabledFont.MapRange('a', 'm', 0, 3);
212 disabledFont.MapRange('n', 'z', 0, 4);
213 disabledFont.MapChar(':', 10, 0);
214 disabledFont.MapChar('!', 11, 0);
215 disabledFont.MapChar('?', 12, 0);
216 // TODO: add '.' and '-' characters
217 battleRes.disabledFont = &disabledFont;
219 SDL_Surface *handCursorImg(IMG_Load("test-data/cursor-hand.png"));
220 Sprite handCursorSprite(handCursorImg, 32, 32);
221 battleRes.menuCursor = &handCursorSprite;
223 SDL_Surface *targetingIconsImg(IMG_Load("test-data/targeting-icons.png"));
224 Sprite weaponTargetCursor(targetingIconsImg, 32, 32);
225 Sprite magicTargetCursor(targetingIconsImg, 32, 32, 0, 32);
226 Sprite itemTargetCursor(targetingIconsImg, 32, 32, 0, 64);
227 battleRes.weaponTargetCursor = &weaponTargetCursor;
228 // TODO: add image for magic targeting cursor
229 battleRes.magicTargetCursor = &magicTargetCursor;
230 // TODO: add image for item targeting cursor
231 battleRes.itemTargetCursor = &itemTargetCursor;
234 resetSpell.SetName("Reset");
235 maxim.AddSpell(&resetSpell);
237 strongSpell.SetName("Strong");
238 strongSpell.SetCost(3);
239 strongSpell.SetUsableInBattle();
240 strongSpell.GetTargetingMode().TargetMultipleAllies();
241 maxim.AddSpell(&strongSpell);
242 selan.AddSpell(&strongSpell);
244 strongerSpell.SetName("Stronger");
245 strongerSpell.SetCost(8);
246 strongerSpell.SetUsableInBattle();
247 strongerSpell.GetTargetingMode().TargetMultipleAllies();
248 maxim.AddSpell(&strongerSpell);
249 selan.AddSpell(&strongerSpell);
251 championSpell.SetName("Champion");
252 championSpell.SetCost(16);
253 championSpell.SetUsableInBattle();
254 championSpell.GetTargetingMode().TargetMultipleAllies();
255 maxim.AddSpell(&championSpell);
256 selan.AddSpell(&championSpell);
258 rallySpell.SetName("Rally");
259 rallySpell.SetCost(10);
260 rallySpell.SetUsableInBattle();
261 rallySpell.GetTargetingMode().TargetMultipleAllies();
262 maxim.AddSpell(&rallySpell);
263 selan.AddSpell(&rallySpell);
265 escapeSpell.SetName("Escape");
266 escapeSpell.SetCost(8);
267 selan.AddSpell(&escapeSpell);
269 valorSpell.SetName("Valor");
270 valorSpell.SetCost(30);
271 valorSpell.SetUsableInBattle();
272 valorSpell.GetTargetingMode().TargetMultipleAllies();
273 maxim.AddSpell(&valorSpell);
274 selan.AddSpell(&valorSpell);
276 battleRes.spellMenuHeadline = "Please choose a spell.";
277 battleRes.spellMenuPrototype = Menu<const Spell *>(&normalFont, &disabledFont, &handCursorSprite, 9, 6, 8, 0, 2, 32, 2, ':');
279 SDL_Surface *itemIcons(IMG_Load("test-data/item-icons.png"));
280 Sprite potionIcon(itemIcons, 16, 16);
281 Sprite ballIcon(itemIcons, 16, 16, 0, 16);
282 Sprite crankIcon(itemIcons, 16, 16, 0, 32);
283 Sprite spearIcon(itemIcons, 16, 16, 0, 48);
284 Sprite swordIcon(itemIcons, 16, 16, 0, 64);
285 Sprite axIcon(itemIcons, 16, 16, 0, 80);
286 Sprite rodIcon(itemIcons, 16, 16, 0, 96);
287 Sprite armorIcon(itemIcons, 16, 16, 0, 112);
288 Sprite shieldIcon(itemIcons, 16, 16, 0, 128);
289 Sprite helmetIcon(itemIcons, 16, 16, 0, 144);
290 Sprite ringIcon(itemIcons, 16, 16, 0, 160);
291 Sprite jewelIcon(itemIcons, 16, 16, 0, 176);
293 battleRes.weaponMenuIcon = &swordIcon;
294 battleRes.armorMenuIcon = &armorIcon;
295 battleRes.shieldMenuIcon = &shieldIcon;
296 battleRes.helmetMenuIcon = &helmetIcon;
297 battleRes.ringMenuIcon = &ringIcon;
298 battleRes.jewelMenuIcon = &jewelIcon;
302 antidote.SetName("Antidote");
303 antidote.SetMenuIcon(&potionIcon);
304 antidote.SetUsableInBattle();
305 antidote.GetTargetingMode().TargetSingleAlly();
306 inventory.Add(&antidote, 9);
308 magicJar.SetName("Magic jar");
309 magicJar.SetMenuIcon(&potionIcon);
310 magicJar.SetUsableInBattle();
311 magicJar.GetTargetingMode().TargetSingleAlly();
312 inventory.Add(&magicJar, 4);
314 hiPotion.SetName("Hi-Potion");
315 hiPotion.SetMenuIcon(&potionIcon);
316 hiPotion.SetUsableInBattle();
317 hiPotion.GetTargetingMode().TargetSingleAlly();
318 inventory.Add(&hiPotion, 4);
320 powerPotion.SetName("Power potion");
321 powerPotion.SetMenuIcon(&potionIcon);
322 inventory.Add(&powerPotion, 4);
324 escape.SetName("Escape");
325 inventory.Add(&escape, 2);
327 sleepBall.SetName("Sleep ball");
328 sleepBall.SetMenuIcon(&ballIcon);
329 sleepBall.SetUsableInBattle();
330 sleepBall.GetTargetingMode().TargetSingleEnemy();
331 inventory.Add(&sleepBall, 1);
333 multiBall.SetName("Multi-ball!");
334 multiBall.SetMenuIcon(&ballIcon);
335 multiBall.SetUsableInBattle();
336 multiBall.GetTargetingMode().TargetMultipleEnemies();
337 inventory.Add(&multiBall, 1);
339 figgoru.SetName("Figgoru");
340 figgoru.SetMenuIcon(&crankIcon);
341 figgoru.GetTargetingMode().TargetAllEnemies();
342 inventory.Add(&figgoru, 1);
343 battleRes.inventory = &inventory;
345 battleRes.itemMenuHeadline = "Please choose an item.";
346 battleRes.itemMenuPrototype = Menu<const common::Item *>(&normalFont, &disabledFont, &handCursorSprite, 15, 6, 8, 16, 1, 32, 2, ':');
349 zircoSword.SetName("Zirco sword");
350 zircoSword.SetMenuIcon(&swordIcon);
352 firestorm.SetName("Firestorm");
353 firestorm.SetCost(224);
354 firestorm.GetTargetingMode().TargetAllEnemies();
355 firestorm.SetPhysical();
356 zircoSword.SetIkari(&firestorm);
357 maxim.SetWeapon(&zircoSword);
359 zirconArmor.SetName("Zircon armor");
360 zirconArmor.SetMenuIcon(&armorIcon);
362 magicCure.SetName("Magic cure");
363 magicCure.SetCost(128);
364 magicCure.GetTargetingMode().TargetSingleAlly();
365 magicCure.SetMagical();
366 zirconArmor.SetIkari(&magicCure);
367 maxim.SetArmor(&zirconArmor);
369 holyShield.SetName("Holy shield");
370 holyShield.SetMenuIcon(&shieldIcon);
372 lightGuard.SetName("Light guard");
373 lightGuard.SetCost(128);
374 lightGuard.GetTargetingMode().TargetAllAllies(); // FIXME: actually only targets self
375 lightGuard.SetMagical();
376 holyShield.SetIkari(&lightGuard);
377 maxim.SetShield(&holyShield);
379 legendHelm.SetName("Legend helm");
380 legendHelm.SetMenuIcon(&helmetIcon);
382 boomerang.SetName("Boomerang");
383 boomerang.SetCost(164);
384 boomerang.GetTargetingMode().TargetAllAllies(); // FIXME: actually only targets self
385 boomerang.SetMagical();
386 legendHelm.SetIkari(&boomerang);
387 maxim.SetHelmet(&legendHelm);
389 sProRing.SetName("S-pro ring");
390 sProRing.SetMenuIcon(&ringIcon);
392 courage.SetName("Courage");
394 courage.GetTargetingMode().TargetMultipleAllies();
395 courage.SetMagical();
396 sProRing.SetIkari(&courage);
397 maxim.SetRing(&sProRing);
399 evilJewel.SetName("Evil jewel");
400 evilJewel.SetMenuIcon(&jewelIcon);
402 gloomy.SetName("Gloomy");
404 gloomy.GetTargetingMode().TargetAllEnemies();
406 evilJewel.SetIkari(&gloomy);
407 maxim.SetJewel(&evilJewel);
410 zircoWhip.SetName("Zirco whip");
411 zircoWhip.SetMenuIcon(&rodIcon);
413 thundershriek.SetName("Thundershriek");
414 thundershriek.SetCost(224);
415 thundershriek.GetTargetingMode().TargetAllEnemies();
416 thundershriek.SetPhysical();
417 zircoWhip.SetIkari(&thundershriek);
418 selan.SetWeapon(&zircoWhip);
420 zirconPlate.SetName("Zircon plate");
421 zirconPlate.SetMenuIcon(&armorIcon);
423 suddenCure.SetName("Sudden cure");
424 suddenCure.SetCost(96);
425 suddenCure.GetTargetingMode().TargetAllAllies();
426 suddenCure.SetMagical();
427 zirconPlate.SetIkari(&suddenCure);
428 selan.SetArmor(&zirconPlate);
430 zircoGloves.SetName("Zirco gloves");
431 zircoGloves.SetMenuIcon(&shieldIcon);
433 forcefield.SetName("Forcefield");
434 forcefield.SetCost(64);
435 forcefield.GetTargetingMode().TargetAllAllies();
436 forcefield.SetMagical();
437 zircoGloves.SetIkari(&forcefield);
438 selan.SetShield(&zircoGloves);
440 holyCap.SetName("Holy cap");
441 holyCap.SetMenuIcon(&helmetIcon);
443 vulnerable.SetName("Vulnerable");
444 vulnerable.SetCost(196);
445 vulnerable.GetTargetingMode().TargetAllEnemies();
446 vulnerable.SetPhysical();
447 holyCap.SetIkari(&vulnerable);
448 selan.SetHelmet(&holyCap);
450 ghostRing.SetName("Ghost ring");
451 ghostRing.SetMenuIcon(&ringIcon);
453 destroy.SetName("Destroy");
454 destroy.SetCost(128);
455 destroy.GetTargetingMode().TargetMultipleEnemies();
456 destroy.SetMagical();
457 ghostRing.SetIkari(&destroy);
458 selan.SetRing(&ghostRing);
460 eagleRock.SetName("Eagle rock");
461 eagleRock.SetMenuIcon(&jewelIcon);
463 dive.SetName("Dive");
465 dive.GetTargetingMode().TargetSingleEnemy();
467 eagleRock.SetIkari(&dive);
468 selan.SetJewel(&eagleRock);
471 zircoAx.SetName("Zirco ax");
472 zircoAx.SetMenuIcon(&axIcon);
474 torrent.SetName("Torrent");
475 torrent.SetCost(224);
476 torrent.GetTargetingMode().TargetAllEnemies();
477 torrent.SetPhysical();
478 zircoAx.SetIkari(&torrent);
479 guy.SetWeapon(&zircoAx);
480 guy.SetArmor(&zirconArmor);
482 megaShield.SetName("Mega shield");
483 megaShield.SetMenuIcon(&shieldIcon);
485 ironBarrier.SetName("Iron barrier");
486 ironBarrier.SetCost(255);
487 ironBarrier.GetTargetingMode().TargetAllAllies(); // FIXME: actually only targets self
488 ironBarrier.SetMagical();
489 megaShield.SetIkari(&ironBarrier);
490 guy.SetShield(&megaShield);
492 zircoHelmet.SetName("Zirco helmet");
493 zircoHelmet.SetMenuIcon(&helmetIcon);
495 slow.SetName("Slow");
497 slow.GetTargetingMode().TargetAllEnemies();
499 zircoHelmet.SetIkari(&slow);
500 guy.SetHelmet(&zircoHelmet);
502 powerRing.SetName("Power ring");
503 powerRing.SetMenuIcon(&ringIcon);
505 trick.SetName("Trick");
507 trick.GetTargetingMode().TargetAllEnemies();
509 zircoHelmet.SetIkari(&trick);
510 guy.SetRing(&powerRing);
511 guy.SetJewel(&evilJewel);
513 // NOTE: this is actually Artea equipment
515 lizardBlow.SetName("Lizard blow");
516 lizardBlow.SetMenuIcon(&swordIcon);
518 dragonRush.SetName("Dragon rush");
519 dragonRush.SetCost(164);
520 dragonRush.GetTargetingMode().TargetSingleEnemy();
521 dragonRush.SetPhysical();
522 lizardBlow.SetIkari(&dragonRush);
523 dekar.SetWeapon(&lizardBlow);
525 holyRobe.SetName("Holy robe");
526 holyRobe.SetMenuIcon(&armorIcon);
528 crisisCure.SetName("Crisis cure");
529 crisisCure.SetCost(164);
530 crisisCure.GetTargetingMode().TargetAllAllies();
531 crisisCure.SetMagical();
532 holyRobe.SetIkari(&crisisCure);
533 dekar.SetArmor(&holyRobe);
534 dekar.SetShield(&zircoGloves);
535 dekar.SetHelmet(&holyCap);
537 rocketRing.SetName("Rocket ring");
538 rocketRing.SetMenuIcon(&ringIcon);
540 fake.SetName("Fake");
542 fake.GetTargetingMode().TargetSingleAlly();
544 rocketRing.SetIkari(&fake);
545 dekar.SetRing(&rocketRing);
547 krakenRock.SetName("Kraken rock");
548 krakenRock.SetMenuIcon(&jewelIcon);
550 tenLegger.SetName("Ten-legger");
551 tenLegger.SetCost(164);
552 tenLegger.GetTargetingMode().TargetAllEnemies();
553 tenLegger.SetPhysical();
554 rocketRing.SetIkari(&tenLegger);
555 dekar.SetJewel(&krakenRock);
557 battleRes.ikariMenuHeadline = "Please choose equipment.";
558 battleRes.noEquipmentText = "No equip";
559 battleRes.ikariMenuPrototype = Menu<const Item *>(&normalFont, &disabledFont, &handCursorSprite, 12, 6, normalFont.CharHeight() / 2, normalFont.CharWidth(), 1, normalFont.CharWidth() * 2, 0, ':', 12, normalFont.CharWidth());
561 battleRes.escapeText = "Escapes.";
563 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &battleRes));
564 battleState->AddMonster(monster);
565 battleState->AddMonster(monster);
566 battleState->AddMonster(monster);
567 battleState->AddMonster(monster);
568 battleState->AddHero(maxim);
569 battleState->AddHero(selan);
570 battleState->AddHero(guy);
571 battleState->AddHero(dekar);
572 Application app(&screen, battleState);
573 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
574 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
575 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
576 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
577 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
578 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
579 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
580 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
581 app.Buttons().MapKey(SDLK_RETURN, Input::START);
582 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
583 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
584 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
588 } catch (exception &e) {
589 cerr << "exception in main(): " << e.what() << endl;