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 "battle/Stats.h"
16 #include "common/Ikari.h"
17 #include "common/Inventory.h"
18 #include "common/Item.h"
19 #include "common/Spell.h"
20 #include "geometry/Vector.h"
21 #include "graphics/ComplexAnimation.h"
22 #include "graphics/Font.h"
23 #include "graphics/Frame.h"
24 #include "graphics/Gauge.h"
25 #include "graphics/Menu.h"
26 #include "graphics/SimpleAnimation.h"
27 #include "graphics/Sprite.h"
28 #include "loader/Interpreter.h"
29 #include "loader/ParsedSource.h"
30 #include "loader/Parser.h"
31 #include "sdl/InitImage.h"
32 #include "sdl/InitScreen.h"
33 #include "sdl/InitSDL.h"
40 #include <SDL_image.h>
42 using app::Application;
44 using battle::BattleState;
46 using battle::Monster;
47 using battle::PartyLayout;
50 using common::Inventory;
53 using geometry::Vector;
54 using graphics::ComplexAnimation;
56 using graphics::Frame;
57 using graphics::Gauge;
59 using graphics::SimpleAnimation;
60 using graphics::Sprite;
61 using loader::Interpreter;
62 using loader::ParsedSource;
65 using sdl::InitScreen;
73 int main(int argc, char **argv) {
74 const int width = 800;
75 const int height = 480;
77 const int framerate = 33;
79 // std::srand(std::time(0));
83 InitImage image(IMG_INIT_PNG);
86 Parser parser("test-data/test.l2s", source);
88 Interpreter intp(source);
91 InitScreen screen(width, height);
93 // temporary test data
94 SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
95 PartyLayout monstersLayout(*intp.GetPartyLayout("monstersLayout"));
96 PartyLayout heroesLayout(*intp.GetPartyLayout("heroesLayout"));
98 Monster monster(*intp.GetMonster("lizard"));
99 Hero maxim(*intp.GetHero("maxim"));
100 Hero selan(*intp.GetHero("selan"));
101 Hero guy(*intp.GetHero("guy"));
102 Hero dekar(*intp.GetHero("dekar"));
104 battle::Resources battleRes;
106 battleRes.swapCursor = intp.GetSprite("swapCursor");
107 battleRes.attackIcons = intp.GetSprite("attackIcons");
108 battleRes.attackChoiceIcons = intp.GetSprite("attackChoiceIcons");
109 battleRes.moveIcons = intp.GetSprite("moveIcons");
111 SDL_Surface *titleFrameImg(IMG_Load("test-data/title-frame.png"));
112 Frame titleFrame(titleFrameImg, 16, 16);
113 battleRes.titleFrame = &titleFrame;
115 SDL_Surface *largeFontImg(IMG_Load("test-data/large-font.png"));
116 Sprite largeFontSprite(largeFontImg, 16, 32);
117 Font largeFont(&largeFontSprite, 0, -2);
118 battleRes.titleFont = &largeFont;
120 battleRes.numberAnimationPrototype = intp.GetAnimation("numberAnimationPrototype");
121 battleRes.bigNumberSprite = intp.GetSprite("bigNumbers");
122 battleRes.greenNumberSprite = intp.GetSprite("bigGreenNumbers");
124 battleRes.heroTagLabels = intp.GetSprite("heroTagLabels");
125 battleRes.levelLabelCol = 0;
126 battleRes.levelLabelRow = 0;
127 battleRes.healthLabelCol = 0;
128 battleRes.healthLabelRow = 1;
129 battleRes.manaLabelCol = 0;
130 battleRes.manaLabelRow = 2;
131 battleRes.moveLabelCol = 0;
132 battleRes.moveLabelRow = 3;
133 battleRes.ikariLabelCol = 0;
134 battleRes.ikariLabelRow = 4;
136 SDL_Surface *numbersImg(IMG_Load("test-data/numbers.png"));
137 Sprite numbersSprite(numbersImg, 16, 16);
138 Font heroTagFont(&numbersSprite, 0, -3);
139 battleRes.heroTagFont = &heroTagFont;
140 SDL_Surface *tagFramesImg(IMG_Load("test-data/tag-frames.png"));
141 Frame heroTagFrame(tagFramesImg, 16, 16, 1, 1, 0, 33);
142 battleRes.heroTagFrame = &heroTagFrame;
143 Frame activeHeroTagFrame(tagFramesImg, 16, 16);
144 battleRes.activeHeroTagFrame = &activeHeroTagFrame;
145 SDL_Surface *smallTagFrameImg(IMG_Load("test-data/small-tag-frame.png"));
146 Frame smallTagFrame(smallTagFrameImg, 8, 16);
147 battleRes.smallHeroTagFrame = &smallTagFrame;
148 Frame lastSmallTagFrame(smallTagFrameImg, 8, 16, 1, 1, 0, 33);
149 battleRes.lastSmallHeroTagFrame = &lastSmallTagFrame;
150 battleRes.heroesBgColor = SDL_MapRGB(screen.Screen()->format, 0x18, 0x28, 0x31);
152 SDL_Surface *gauges(IMG_Load("test-data/gauges.png"));
153 Gauge healthGauge(gauges, 0, 16, 0, 0, 16, 6, 1, 6);
154 battleRes.healthGauge = &healthGauge;
155 Gauge manaGauge(gauges, 0, 32, 0, 0, 16, 6, 1, 6);
156 battleRes.manaGauge = &manaGauge;
157 Gauge ikariGauge(gauges, 0, 48, 0, 0, 16, 6, 1, 6);
158 battleRes.ikariGauge = &ikariGauge;
160 SDL_Surface *selectFrameImg(IMG_Load("test-data/select-frame.png"));
161 Frame selectFrame(selectFrameImg, 16, 16);
162 battleRes.selectFrame = &selectFrame;
164 SDL_Surface *normalFontImg(IMG_Load("test-data/normal-font.png"));
165 Sprite normalFontSprite(normalFontImg, 16, 16);
166 Font normalFont(&normalFontSprite, 0, -2);
167 battleRes.normalFont = &normalFont;
169 SDL_Surface *disabledFontImg(IMG_Load("test-data/disabled-font.png"));
170 Sprite disabledFontSprite(disabledFontImg, 16, 16);
171 Font disabledFont(&disabledFontSprite, 0, -2);
172 battleRes.disabledFont = &disabledFont;
174 SDL_Surface *handCursorImg(IMG_Load("test-data/cursor-hand.png"));
175 Sprite handCursorSprite(handCursorImg, 32, 32);
176 battleRes.menuCursor = &handCursorSprite;
178 SDL_Surface *targetingIconsImg(IMG_Load("test-data/targeting-icons.png"));
179 Sprite weaponTargetCursor(targetingIconsImg, 32, 32);
180 Sprite magicTargetCursor(targetingIconsImg, 32, 32, 0, 32);
181 Sprite itemTargetCursor(targetingIconsImg, 32, 32, 0, 64);
182 battleRes.weaponTargetCursor = &weaponTargetCursor;
183 battleRes.magicTargetCursor = &magicTargetCursor;
184 battleRes.itemTargetCursor = &itemTargetCursor;
187 resetSpell.SetName("Reset");
188 maxim.AddSpell(&resetSpell);
190 strongSpell.SetName("Strong");
191 strongSpell.SetCost(3);
192 strongSpell.SetUsableInBattle();
193 strongSpell.GetTargetingMode().TargetMultipleAllies();
194 maxim.AddSpell(&strongSpell);
195 selan.AddSpell(&strongSpell);
197 strongerSpell.SetName("Stronger");
198 strongerSpell.SetCost(8);
199 strongerSpell.SetUsableInBattle();
200 strongerSpell.GetTargetingMode().TargetMultipleAllies();
201 maxim.AddSpell(&strongerSpell);
202 selan.AddSpell(&strongerSpell);
204 championSpell.SetName("Champion");
205 championSpell.SetCost(16);
206 championSpell.SetUsableInBattle();
207 championSpell.GetTargetingMode().TargetMultipleAllies();
208 maxim.AddSpell(&championSpell);
209 selan.AddSpell(&championSpell);
211 rallySpell.SetName("Rally");
212 rallySpell.SetCost(10);
213 rallySpell.SetUsableInBattle();
214 rallySpell.GetTargetingMode().TargetMultipleAllies();
215 maxim.AddSpell(&rallySpell);
216 selan.AddSpell(&rallySpell);
218 escapeSpell.SetName("Escape");
219 escapeSpell.SetCost(8);
220 selan.AddSpell(&escapeSpell);
222 valorSpell.SetName("Valor");
223 valorSpell.SetCost(30);
224 valorSpell.SetUsableInBattle();
225 valorSpell.GetTargetingMode().TargetMultipleAllies();
226 maxim.AddSpell(&valorSpell);
227 selan.AddSpell(&valorSpell);
229 battleRes.spellMenuHeadline = "Please choose a spell.";
230 battleRes.spellMenuPrototype = Menu<const Spell *>(&normalFont, &disabledFont, &handCursorSprite, 9, 6, 8, 0, 2, 32, 2, ':');
232 SDL_Surface *itemIcons(IMG_Load("test-data/item-icons.png"));
233 Sprite potionIcon(itemIcons, 16, 16);
234 Sprite ballIcon(itemIcons, 16, 16, 0, 16);
235 Sprite crankIcon(itemIcons, 16, 16, 0, 32);
236 Sprite spearIcon(itemIcons, 16, 16, 0, 48);
237 Sprite swordIcon(itemIcons, 16, 16, 0, 64);
238 Sprite axIcon(itemIcons, 16, 16, 0, 80);
239 Sprite rodIcon(itemIcons, 16, 16, 0, 96);
240 Sprite armorIcon(itemIcons, 16, 16, 0, 112);
241 Sprite shieldIcon(itemIcons, 16, 16, 0, 128);
242 Sprite helmetIcon(itemIcons, 16, 16, 0, 144);
243 Sprite ringIcon(itemIcons, 16, 16, 0, 160);
244 Sprite jewelIcon(itemIcons, 16, 16, 0, 176);
246 battleRes.weaponMenuIcon = &swordIcon;
247 battleRes.armorMenuIcon = &armorIcon;
248 battleRes.shieldMenuIcon = &shieldIcon;
249 battleRes.helmetMenuIcon = &helmetIcon;
250 battleRes.ringMenuIcon = &ringIcon;
251 battleRes.jewelMenuIcon = &jewelIcon;
255 antidote.SetName("Antidote");
256 antidote.SetMenuIcon(&potionIcon);
257 antidote.SetUsableInBattle();
258 antidote.GetTargetingMode().TargetSingleAlly();
259 inventory.Add(&antidote, 9);
261 magicJar.SetName("Magic jar");
262 magicJar.SetMenuIcon(&potionIcon);
263 magicJar.SetUsableInBattle();
264 magicJar.GetTargetingMode().TargetSingleAlly();
265 inventory.Add(&magicJar, 4);
267 hiPotion.SetName("Hi-Potion");
268 hiPotion.SetMenuIcon(&potionIcon);
269 hiPotion.SetUsableInBattle();
270 hiPotion.GetTargetingMode().TargetSingleAlly();
271 inventory.Add(&hiPotion, 4);
273 powerPotion.SetName("Power potion");
274 powerPotion.SetMenuIcon(&potionIcon);
275 inventory.Add(&powerPotion, 4);
277 escape.SetName("Escape");
278 inventory.Add(&escape, 2);
280 sleepBall.SetName("Sleep ball");
281 sleepBall.SetMenuIcon(&ballIcon);
282 sleepBall.SetUsableInBattle();
283 sleepBall.GetTargetingMode().TargetSingleEnemy();
284 inventory.Add(&sleepBall, 1);
286 multiBall.SetName("Multi-ball!");
287 multiBall.SetMenuIcon(&ballIcon);
288 multiBall.SetUsableInBattle();
289 multiBall.GetTargetingMode().TargetMultipleEnemies();
290 inventory.Add(&multiBall, 1);
292 figgoru.SetName("Figgoru");
293 figgoru.SetMenuIcon(&crankIcon);
294 figgoru.GetTargetingMode().TargetAllEnemies();
295 inventory.Add(&figgoru, 1);
296 battleRes.inventory = &inventory;
298 battleRes.itemMenuHeadline = "Please choose an item.";
299 battleRes.itemMenuPrototype = Menu<const common::Item *>(&normalFont, &disabledFont, &handCursorSprite, 15, 6, 8, 16, 1, 32, 2, ':');
301 SDL_Surface *swordAttackImg(IMG_Load("test-data/attack-sword.png"));
302 Sprite swordAttackSprite(swordAttackImg, 96, 96);
303 SimpleAnimation swordAttackAnimation(&swordAttackSprite, 2 * framerate, 4);
306 zircoSword.SetName("Zirco sword");
307 zircoSword.SetMenuIcon(&swordIcon);
308 zircoSword.GetTargetingMode().TargetSingleEnemy();
310 firestorm.SetName("Firestorm");
311 firestorm.SetCost(224);
312 firestorm.GetTargetingMode().TargetAllEnemies();
313 firestorm.SetPhysical();
314 zircoSword.SetIkari(&firestorm);
315 zircoSword.SetAttackAnimation(&swordAttackAnimation);
316 maxim.SetWeapon(&zircoSword);
318 zirconArmor.SetName("Zircon armor");
319 zirconArmor.SetMenuIcon(&armorIcon);
321 magicCure.SetName("Magic cure");
322 magicCure.SetCost(128);
323 magicCure.GetTargetingMode().TargetSingleAlly();
324 magicCure.SetMagical();
325 zirconArmor.SetIkari(&magicCure);
326 maxim.SetArmor(&zirconArmor);
328 holyShield.SetName("Holy shield");
329 holyShield.SetMenuIcon(&shieldIcon);
331 lightGuard.SetName("Light guard");
332 lightGuard.SetCost(128);
333 lightGuard.GetTargetingMode().TargetAllAllies(); // actually only targets self
334 lightGuard.SetMagical();
335 holyShield.SetIkari(&lightGuard);
336 maxim.SetShield(&holyShield);
338 legendHelm.SetName("Legend helm");
339 legendHelm.SetMenuIcon(&helmetIcon);
341 boomerang.SetName("Boomerang");
342 boomerang.SetCost(164);
343 boomerang.GetTargetingMode().TargetAllAllies(); // actually only targets self
344 boomerang.SetMagical();
345 legendHelm.SetIkari(&boomerang);
346 maxim.SetHelmet(&legendHelm);
348 sProRing.SetName("S-pro ring");
349 sProRing.SetMenuIcon(&ringIcon);
351 courage.SetName("Courage");
353 courage.GetTargetingMode().TargetMultipleAllies();
354 courage.SetMagical();
355 sProRing.SetIkari(&courage);
356 maxim.SetRing(&sProRing);
358 evilJewel.SetName("Evil jewel");
359 evilJewel.SetMenuIcon(&jewelIcon);
361 gloomy.SetName("Gloomy");
363 gloomy.GetTargetingMode().TargetAllEnemies();
365 evilJewel.SetIkari(&gloomy);
366 maxim.SetJewel(&evilJewel);
369 zircoWhip.SetName("Zirco whip");
370 zircoWhip.SetMenuIcon(&rodIcon);
371 zircoWhip.GetTargetingMode().TargetSingleEnemy();
373 thundershriek.SetName("Thundershriek");
374 thundershriek.SetCost(224);
375 thundershriek.GetTargetingMode().TargetAllEnemies();
376 thundershriek.SetPhysical();
377 zircoWhip.SetIkari(&thundershriek);
378 // selan.SetWeapon(&zircoWhip);
380 zirconPlate.SetName("Zircon plate");
381 zirconPlate.SetMenuIcon(&armorIcon);
383 suddenCure.SetName("Sudden cure");
384 suddenCure.SetCost(96);
385 suddenCure.GetTargetingMode().TargetAllAllies();
386 suddenCure.SetMagical();
387 zirconPlate.SetIkari(&suddenCure);
388 selan.SetArmor(&zirconPlate);
390 zircoGloves.SetName("Zirco gloves");
391 zircoGloves.SetMenuIcon(&shieldIcon);
393 forcefield.SetName("Forcefield");
394 forcefield.SetCost(64);
395 forcefield.GetTargetingMode().TargetAllAllies();
396 forcefield.SetMagical();
397 zircoGloves.SetIkari(&forcefield);
398 selan.SetShield(&zircoGloves);
400 holyCap.SetName("Holy cap");
401 holyCap.SetMenuIcon(&helmetIcon);
403 vulnerable.SetName("Vulnerable");
404 vulnerable.SetCost(196);
405 vulnerable.GetTargetingMode().TargetAllEnemies();
406 vulnerable.SetPhysical();
407 holyCap.SetIkari(&vulnerable);
408 selan.SetHelmet(&holyCap);
410 ghostRing.SetName("Ghost ring");
411 ghostRing.SetMenuIcon(&ringIcon);
413 destroy.SetName("Destroy");
414 destroy.SetCost(128);
415 destroy.GetTargetingMode().TargetMultipleEnemies();
416 destroy.SetMagical();
417 ghostRing.SetIkari(&destroy);
418 selan.SetRing(&ghostRing);
420 eagleRock.SetName("Eagle rock");
421 eagleRock.SetMenuIcon(&jewelIcon);
423 dive.SetName("Dive");
425 dive.GetTargetingMode().TargetSingleEnemy();
427 eagleRock.SetIkari(&dive);
428 selan.SetJewel(&eagleRock);
431 zircoAx.SetName("Zirco ax");
432 zircoAx.SetMenuIcon(&axIcon);
433 zircoAx.GetTargetingMode().TargetSingleEnemy();
435 torrent.SetName("Torrent");
436 torrent.SetCost(224);
437 torrent.GetTargetingMode().TargetAllEnemies();
438 torrent.SetPhysical();
439 zircoAx.SetIkari(&torrent);
440 // guy.SetWeapon(&zircoAx);
441 guy.SetArmor(&zirconArmor);
443 megaShield.SetName("Mega shield");
444 megaShield.SetMenuIcon(&shieldIcon);
446 ironBarrier.SetName("Iron barrier");
447 ironBarrier.SetCost(255);
448 ironBarrier.GetTargetingMode().TargetAllAllies(); // actually only targets self
449 ironBarrier.SetMagical();
450 megaShield.SetIkari(&ironBarrier);
451 guy.SetShield(&megaShield);
453 zircoHelmet.SetName("Zirco helmet");
454 zircoHelmet.SetMenuIcon(&helmetIcon);
456 slow.SetName("Slow");
458 slow.GetTargetingMode().TargetAllEnemies();
460 zircoHelmet.SetIkari(&slow);
461 guy.SetHelmet(&zircoHelmet);
463 powerRing.SetName("Power ring");
464 powerRing.SetMenuIcon(&ringIcon);
466 trick.SetName("Trick");
468 trick.GetTargetingMode().TargetAllEnemies();
470 zircoHelmet.SetIkari(&trick);
471 guy.SetRing(&powerRing);
472 guy.SetJewel(&evilJewel);
474 // NOTE: this is actually Artea equipment
476 lizardBlow.SetName("Lizard blow");
477 lizardBlow.SetMenuIcon(&swordIcon);
478 lizardBlow.GetTargetingMode().TargetSingleEnemy();
480 dragonRush.SetName("Dragon rush");
481 dragonRush.SetCost(164);
482 dragonRush.GetTargetingMode().TargetSingleEnemy();
483 dragonRush.SetPhysical();
484 lizardBlow.SetIkari(&dragonRush);
485 // dekar.SetWeapon(&lizardBlow);
487 holyRobe.SetName("Holy robe");
488 holyRobe.SetMenuIcon(&armorIcon);
490 crisisCure.SetName("Crisis cure");
491 crisisCure.SetCost(164);
492 crisisCure.GetTargetingMode().TargetAllAllies();
493 crisisCure.SetMagical();
494 holyRobe.SetIkari(&crisisCure);
495 dekar.SetArmor(&holyRobe);
496 dekar.SetShield(&zircoGloves);
497 dekar.SetHelmet(&holyCap);
499 rocketRing.SetName("Rocket ring");
500 rocketRing.SetMenuIcon(&ringIcon);
502 fake.SetName("Fake");
504 fake.GetTargetingMode().TargetSingleAlly();
506 rocketRing.SetIkari(&fake);
507 dekar.SetRing(&rocketRing);
509 krakenRock.SetName("Kraken rock");
510 krakenRock.SetMenuIcon(&jewelIcon);
512 tenLegger.SetName("Ten-legger");
513 tenLegger.SetCost(164);
514 tenLegger.GetTargetingMode().TargetAllEnemies();
515 tenLegger.SetPhysical();
516 rocketRing.SetIkari(&tenLegger);
517 dekar.SetJewel(&krakenRock);
519 battleRes.ikariMenuHeadline = "Please choose equipment.";
520 battleRes.noEquipmentText = "No equip";
521 battleRes.ikariMenuPrototype = Menu<const Item *>(&normalFont, &disabledFont, &handCursorSprite, 12, 6, normalFont.CharHeight() / 2, normalFont.CharWidth(), 1, normalFont.CharWidth() * 2, 0, ':', 12, normalFont.CharWidth());
523 battleRes.escapeText = "Escapes.";
525 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &battleRes));
526 battleState->AddMonster(monster);
527 battleState->AddMonster(monster);
528 battleState->AddMonster(monster);
529 battleState->AddMonster(monster);
530 battleState->AddHero(maxim);
531 battleState->AddHero(selan);
532 battleState->AddHero(guy);
533 battleState->AddHero(dekar);
534 Application app(&screen, battleState);
535 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
536 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
537 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
538 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
539 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
540 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
541 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
542 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
543 app.Buttons().MapKey(SDLK_RETURN, Input::START);
544 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
545 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
546 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
550 } catch (Parser::Error &e) {
551 cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl;
553 } catch (exception &e) {
554 cerr << "exception in main(): " << e.what() << endl;