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 *attackIconsImg(IMG_Load("test-data/attack-type-icons.png"));
139 Sprite attackIconsSprite(attackIconsImg, 32, 32);
140 battleRes.attackIcons = &attackIconsSprite;
141 SDL_Surface *attackChoiceIconsImg(IMG_Load("test-data/attack-choice-icons.png"));
142 Sprite attackChoiceIconsSprite(attackChoiceIconsImg, 16, 16);
143 battleRes.attackChoiceIcons = &attackChoiceIconsSprite;
144 SDL_Surface *moveIconsImg(IMG_Load("test-data/move-icons.png"));
145 Sprite moveIconsSprite(moveIconsImg, 32, 32);
146 battleRes.moveIcons = &moveIconsSprite;
147 SDL_Surface *heroTagImg(IMG_Load("test-data/hero-tag-sprites.png"));
148 Sprite heroTagSprite(heroTagImg, 32, 16);
149 battleRes.heroTagLabels = &heroTagSprite;
150 SDL_Surface *numbersImg(IMG_Load("test-data/numbers.png"));
151 Sprite numbersSprite(numbersImg, 16, 16);
152 Font heroTagFont(&numbersSprite);
153 battleRes.heroTagFont = &heroTagFont;
154 SDL_Surface *tagFramesImg(IMG_Load("test-data/tag-frames.png"));
155 Frame heroTagFrame(tagFramesImg, 16, 16, 1, 1, 0, 33);
156 battleRes.heroTagFrame = &heroTagFrame;
157 Frame activeHeroTagFrame(tagFramesImg, 16, 16);
158 battleRes.activeHeroTagFrame = &activeHeroTagFrame;
160 SDL_Surface *gauges(IMG_Load("test-data/gauges.png"));
161 Gauge healthGauge(gauges, 0, 16, 0, 0, 16, 6, 1, 6);
162 battleRes.healthGauge = &healthGauge;
163 Gauge manaGauge(gauges, 0, 32, 0, 0, 16, 6, 1, 6);
164 battleRes.manaGauge = &manaGauge;
165 Gauge ikariGauge(gauges, 0, 48, 0, 0, 16, 6, 1, 6);
166 battleRes.ikariGauge = &ikariGauge;
168 SDL_Surface *selectFrameImg(IMG_Load("test-data/select-frame.png"));
169 Frame selectFrame(selectFrameImg, 16, 16);
170 battleRes.selectFrame = &selectFrame;
172 SDL_Surface *normalFontImg(IMG_Load("test-data/normal-font.png"));
173 Sprite normalFontSprite(normalFontImg, 16, 16);
174 Font normalFont(&normalFontSprite);
175 normalFont.MapRange('A', 'M', 0, 1);
176 normalFont.MapRange('N', 'Z', 0, 2);
177 normalFont.MapRange('a', 'm', 0, 3);
178 normalFont.MapRange('n', 'z', 0, 4);
179 normalFont.MapChar(':', 10, 0);
180 normalFont.MapChar('!', 11, 0);
181 normalFont.MapChar('?', 12, 0);
182 // TODO: add '.' and '-' characters
183 battleRes.normalFont = &normalFont;
185 SDL_Surface *disabledFontImg(IMG_Load("test-data/disabled-font.png"));
186 Sprite disabledFontSprite(disabledFontImg, 16, 16);
187 Font disabledFont(&disabledFontSprite);
188 disabledFont.MapRange('A', 'M', 0, 1);
189 disabledFont.MapRange('N', 'Z', 0, 2);
190 disabledFont.MapRange('a', 'm', 0, 3);
191 disabledFont.MapRange('n', 'z', 0, 4);
192 disabledFont.MapChar(':', 10, 0);
193 disabledFont.MapChar('!', 11, 0);
194 disabledFont.MapChar('?', 12, 0);
195 // TODO: add '.' and '-' characters
196 battleRes.disabledFont = &disabledFont;
198 SDL_Surface *handCursorImg(IMG_Load("test-data/cursor-hand.png"));
199 Sprite handCursorSprite(handCursorImg, 32, 32);
200 battleRes.menuCursor = &handCursorSprite;
202 SDL_Surface *targetingIconsImg(IMG_Load("test-data/targeting-icons.png"));
203 Sprite weaponTargetCursor(targetingIconsImg, 32, 32);
204 Sprite magicTargetCursor(targetingIconsImg, 32, 32, 0, 32);
205 Sprite itemTargetCursor(targetingIconsImg, 32, 32, 0, 64);
206 battleRes.weaponTargetCursor = &weaponTargetCursor;
207 // TODO: add image for magic targeting cursor
208 battleRes.magicTargetCursor = &magicTargetCursor;
209 // TODO: add image for item targeting cursor
210 battleRes.itemTargetCursor = &itemTargetCursor;
213 resetSpell.SetName("Reset");
214 maxim.AddSpell(&resetSpell);
216 strongSpell.SetName("Strong");
217 strongSpell.SetCost(3);
218 strongSpell.SetUsableInBattle();
219 strongSpell.GetTargetingMode().TargetMultipleAllies();
220 maxim.AddSpell(&strongSpell);
221 selan.AddSpell(&strongSpell);
223 strongerSpell.SetName("Stronger");
224 strongerSpell.SetCost(8);
225 strongerSpell.SetUsableInBattle();
226 strongerSpell.GetTargetingMode().TargetMultipleAllies();
227 maxim.AddSpell(&strongerSpell);
228 selan.AddSpell(&strongerSpell);
230 championSpell.SetName("Champion");
231 championSpell.SetCost(16);
232 championSpell.SetUsableInBattle();
233 championSpell.GetTargetingMode().TargetMultipleAllies();
234 maxim.AddSpell(&championSpell);
235 selan.AddSpell(&championSpell);
237 rallySpell.SetName("Rally");
238 rallySpell.SetCost(10);
239 rallySpell.SetUsableInBattle();
240 rallySpell.GetTargetingMode().TargetMultipleAllies();
241 maxim.AddSpell(&rallySpell);
242 selan.AddSpell(&rallySpell);
244 escapeSpell.SetName("Escape");
245 escapeSpell.SetCost(8);
246 selan.AddSpell(&escapeSpell);
248 valorSpell.SetName("Valor");
249 valorSpell.SetCost(30);
250 valorSpell.SetUsableInBattle();
251 valorSpell.GetTargetingMode().TargetMultipleAllies();
252 maxim.AddSpell(&valorSpell);
253 selan.AddSpell(&valorSpell);
255 battleRes.spellMenuHeadline = "Please choose a spell.";
256 battleRes.spellMenuPrototype = Menu<const Spell *>(&normalFont, &disabledFont, &handCursorSprite, 9, 6, 8, 0, 2, 32, 2, ':');
258 SDL_Surface *itemIcons(IMG_Load("test-data/item-icons.png"));
259 Sprite potionIcon(itemIcons, 16, 16);
260 Sprite ballIcon(itemIcons, 16, 16, 0, 16);
261 Sprite crankIcon(itemIcons, 16, 16, 0, 32);
262 Sprite spearIcon(itemIcons, 16, 16, 0, 48);
263 Sprite swordIcon(itemIcons, 16, 16, 0, 64);
264 Sprite axIcon(itemIcons, 16, 16, 0, 80);
265 Sprite rodIcon(itemIcons, 16, 16, 0, 96);
266 Sprite armorIcon(itemIcons, 16, 16, 0, 112);
267 Sprite shieldIcon(itemIcons, 16, 16, 0, 128);
268 Sprite helmetIcon(itemIcons, 16, 16, 0, 144);
269 Sprite ringIcon(itemIcons, 16, 16, 0, 160);
270 Sprite jewelIcon(itemIcons, 16, 16, 0, 176);
272 battleRes.weaponMenuIcon = &swordIcon;
273 battleRes.armorMenuIcon = &armorIcon;
274 battleRes.shieldMenuIcon = &shieldIcon;
275 battleRes.helmetMenuIcon = &helmetIcon;
276 battleRes.ringMenuIcon = &ringIcon;
277 battleRes.jewelMenuIcon = &jewelIcon;
281 antidote.SetName("Antidote");
282 antidote.SetMenuIcon(&potionIcon);
283 antidote.SetUsableInBattle();
284 antidote.GetTargetingMode().TargetSingleAlly();
285 inventory.Add(&antidote, 9);
287 magicJar.SetName("Magic jar");
288 magicJar.SetMenuIcon(&potionIcon);
289 magicJar.SetUsableInBattle();
290 magicJar.GetTargetingMode().TargetSingleAlly();
291 inventory.Add(&magicJar, 4);
293 hiPotion.SetName("Hi-Potion");
294 hiPotion.SetMenuIcon(&potionIcon);
295 hiPotion.SetUsableInBattle();
296 hiPotion.GetTargetingMode().TargetSingleAlly();
297 inventory.Add(&hiPotion, 4);
299 powerPotion.SetName("Power potion");
300 powerPotion.SetMenuIcon(&potionIcon);
301 inventory.Add(&powerPotion, 4);
303 escape.SetName("Escape");
304 inventory.Add(&escape, 2);
306 sleepBall.SetName("Sleep ball");
307 sleepBall.SetMenuIcon(&ballIcon);
308 sleepBall.SetUsableInBattle();
309 sleepBall.GetTargetingMode().TargetSingleEnemy();
310 inventory.Add(&sleepBall, 1);
312 multiBall.SetName("Multi-ball!");
313 multiBall.SetMenuIcon(&ballIcon);
314 multiBall.SetUsableInBattle();
315 multiBall.GetTargetingMode().TargetMultipleEnemies();
316 inventory.Add(&multiBall, 1);
318 figgoru.SetName("Figgoru");
319 figgoru.SetMenuIcon(&crankIcon);
320 figgoru.GetTargetingMode().TargetAllEnemies();
321 inventory.Add(&figgoru, 1);
322 battleRes.inventory = &inventory;
324 battleRes.itemMenuHeadline = "Please choose an item.";
325 battleRes.itemMenuPrototype = Menu<const common::Item *>(&normalFont, &disabledFont, &handCursorSprite, 15, 6, 8, 16, 1, 32, 2, ':');
328 zircoSword.SetName("Zirco sword");
329 zircoSword.SetMenuIcon(&swordIcon);
331 firestorm.SetName("Firestorm");
332 firestorm.SetCost(224);
333 firestorm.GetTargetingMode().TargetAllEnemies();
334 firestorm.SetPhysical();
335 zircoSword.SetIkari(&firestorm);
336 maxim.SetWeapon(&zircoSword);
338 zirconArmor.SetName("Zircon armor");
339 zirconArmor.SetMenuIcon(&armorIcon);
341 magicCure.SetName("Magic cure");
342 magicCure.SetCost(128);
343 magicCure.GetTargetingMode().TargetSingleAlly();
344 magicCure.SetMagical();
345 zirconArmor.SetIkari(&magicCure);
346 maxim.SetArmor(&zirconArmor);
348 holyShield.SetName("Holy shield");
349 holyShield.SetMenuIcon(&shieldIcon);
351 lightGuard.SetName("Light guard");
352 lightGuard.SetCost(128);
353 lightGuard.GetTargetingMode().TargetAllAllies(); // FIXME: actually only targets self
354 lightGuard.SetMagical();
355 holyShield.SetIkari(&lightGuard);
356 maxim.SetShield(&holyShield);
358 legendHelm.SetName("Legend helm");
359 legendHelm.SetMenuIcon(&helmetIcon);
361 boomerang.SetName("Boomerang");
362 boomerang.SetCost(164);
363 boomerang.GetTargetingMode().TargetAllAllies(); // FIXME: actually only targets self
364 boomerang.SetMagical();
365 legendHelm.SetIkari(&boomerang);
366 maxim.SetHelmet(&legendHelm);
368 sProRing.SetName("S-pro ring");
369 sProRing.SetMenuIcon(&ringIcon);
371 courage.SetName("Courage");
373 courage.GetTargetingMode().TargetMultipleAllies();
374 courage.SetMagical();
375 sProRing.SetIkari(&courage);
376 maxim.SetRing(&sProRing);
378 evilJewel.SetName("Evil jewel");
379 evilJewel.SetMenuIcon(&jewelIcon);
381 gloomy.SetName("Gloomy");
383 gloomy.GetTargetingMode().TargetAllEnemies();
385 evilJewel.SetIkari(&gloomy);
386 maxim.SetJewel(&evilJewel);
389 zircoWhip.SetName("Zirco whip");
390 zircoWhip.SetMenuIcon(&rodIcon);
392 thundershriek.SetName("Thundershriek");
393 thundershriek.SetCost(224);
394 thundershriek.GetTargetingMode().TargetAllEnemies();
395 thundershriek.SetPhysical();
396 zircoWhip.SetIkari(&thundershriek);
397 selan.SetWeapon(&zircoWhip);
399 zirconPlate.SetName("Zircon plate");
400 zirconPlate.SetMenuIcon(&armorIcon);
402 suddenCure.SetName("Sudden cure");
403 suddenCure.SetCost(96);
404 suddenCure.GetTargetingMode().TargetAllAllies();
405 suddenCure.SetMagical();
406 zirconPlate.SetIkari(&suddenCure);
407 selan.SetArmor(&zirconPlate);
409 zircoGloves.SetName("Zirco gloves");
410 zircoGloves.SetMenuIcon(&shieldIcon);
412 forcefield.SetName("Forcefield");
413 forcefield.SetCost(64);
414 forcefield.GetTargetingMode().TargetAllAllies();
415 forcefield.SetMagical();
416 zircoGloves.SetIkari(&forcefield);
417 selan.SetShield(&zircoGloves);
419 holyCap.SetName("Holy cap");
420 holyCap.SetMenuIcon(&helmetIcon);
422 vulnerable.SetName("Vulnerable");
423 vulnerable.SetCost(196);
424 vulnerable.GetTargetingMode().TargetAllEnemies();
425 vulnerable.SetPhysical();
426 holyCap.SetIkari(&vulnerable);
427 selan.SetHelmet(&holyCap);
429 ghostRing.SetName("Ghost ring");
430 ghostRing.SetMenuIcon(&ringIcon);
432 destroy.SetName("Destroy");
433 destroy.SetCost(128);
434 destroy.GetTargetingMode().TargetMultipleEnemies();
435 destroy.SetMagical();
436 ghostRing.SetIkari(&destroy);
437 selan.SetRing(&ghostRing);
439 eagleRock.SetName("Eagle rock");
440 eagleRock.SetMenuIcon(&jewelIcon);
442 dive.SetName("Dive");
444 dive.GetTargetingMode().TargetSingleEnemy();
446 eagleRock.SetIkari(&dive);
447 selan.SetJewel(&eagleRock);
450 zircoAx.SetName("Zirco ax");
451 zircoAx.SetMenuIcon(&axIcon);
453 torrent.SetName("Torrent");
454 torrent.SetCost(224);
455 torrent.GetTargetingMode().TargetAllEnemies();
456 torrent.SetPhysical();
457 zircoAx.SetIkari(&torrent);
458 guy.SetWeapon(&zircoAx);
459 guy.SetArmor(&zirconArmor);
461 megaShield.SetName("Mega shield");
462 megaShield.SetMenuIcon(&shieldIcon);
464 ironBarrier.SetName("Iron barrier");
465 ironBarrier.SetCost(255);
466 ironBarrier.GetTargetingMode().TargetAllAllies(); // FIXME: actually only targets self
467 ironBarrier.SetMagical();
468 megaShield.SetIkari(&ironBarrier);
469 guy.SetShield(&megaShield);
471 zircoHelmet.SetName("Zirco helmet");
472 zircoHelmet.SetMenuIcon(&helmetIcon);
474 slow.SetName("Slow");
476 slow.GetTargetingMode().TargetAllEnemies();
478 zircoHelmet.SetIkari(&slow);
479 guy.SetHelmet(&zircoHelmet);
481 powerRing.SetName("Power ring");
482 powerRing.SetMenuIcon(&ringIcon);
484 trick.SetName("Trick");
486 trick.GetTargetingMode().TargetAllEnemies();
488 zircoHelmet.SetIkari(&trick);
489 guy.SetRing(&powerRing);
490 guy.SetJewel(&evilJewel);
492 // NOTE: this is actually Artea equipment
494 lizardBlow.SetName("Lizard blow");
495 lizardBlow.SetMenuIcon(&swordIcon);
497 dragonRush.SetName("Dragon rush");
498 dragonRush.SetCost(164);
499 dragonRush.GetTargetingMode().TargetSingleEnemy();
500 dragonRush.SetPhysical();
501 lizardBlow.SetIkari(&dragonRush);
502 dekar.SetWeapon(&lizardBlow);
504 holyRobe.SetName("Holy robe");
505 holyRobe.SetMenuIcon(&armorIcon);
507 crisisCure.SetName("Crisis cure");
508 crisisCure.SetCost(164);
509 crisisCure.GetTargetingMode().TargetAllAllies();
510 crisisCure.SetMagical();
511 holyRobe.SetIkari(&crisisCure);
512 dekar.SetArmor(&holyRobe);
513 dekar.SetShield(&zircoGloves);
514 dekar.SetHelmet(&holyCap);
516 rocketRing.SetName("Rocket ring");
517 rocketRing.SetMenuIcon(&ringIcon);
519 fake.SetName("Fake");
521 fake.GetTargetingMode().TargetSingleAlly();
523 rocketRing.SetIkari(&fake);
524 dekar.SetRing(&rocketRing);
526 krakenRock.SetName("Kraken rock");
527 krakenRock.SetMenuIcon(&jewelIcon);
529 tenLegger.SetName("Ten-legger");
530 tenLegger.SetCost(164);
531 tenLegger.GetTargetingMode().TargetAllEnemies();
532 tenLegger.SetPhysical();
533 rocketRing.SetIkari(&tenLegger);
534 dekar.SetJewel(&krakenRock);
536 battleRes.ikariMenuHeadline = "Please choose equipment.";
537 battleRes.noEquipmentText = "No equip";
538 battleRes.ikariMenuPrototype = Menu<const Item *>(&normalFont, &disabledFont, &handCursorSprite, 12, 6, normalFont.CharHeight() / 2, normalFont.CharWidth(), 1, normalFont.CharWidth() * 2, 0, ':', 12, normalFont.CharWidth());
540 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &battleRes));
541 battleState->AddMonster(monster);
542 battleState->AddMonster(monster);
543 battleState->AddMonster(monster);
544 battleState->AddMonster(monster);
545 battleState->AddHero(maxim);
546 battleState->AddHero(selan);
547 battleState->AddHero(guy);
548 battleState->AddHero(dekar);
549 Application app(&screen, battleState);
550 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
551 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
552 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
553 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
554 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
555 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
556 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
557 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
558 app.Buttons().MapKey(SDLK_RETURN, Input::START);
559 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
560 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
561 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
565 } catch (exception &e) {
566 cerr << "exception in main(): " << e.what() << endl;