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");
110 battleRes.titleFrame = intp.GetFrame("titleFrame");
111 battleRes.titleFont = intp.GetFont("largeFont");
112 battleRes.numberAnimationPrototype = intp.GetAnimation("numberAnimationPrototype");
113 battleRes.bigNumberSprite = intp.GetSprite("bigNumbers");
114 battleRes.greenNumberSprite = intp.GetSprite("bigGreenNumbers");
116 battleRes.heroTagLabels = intp.GetSprite("heroTagLabels");
117 battleRes.levelLabelCol = 0;
118 battleRes.levelLabelRow = 0;
119 battleRes.healthLabelCol = 0;
120 battleRes.healthLabelRow = 1;
121 battleRes.manaLabelCol = 0;
122 battleRes.manaLabelRow = 2;
123 battleRes.moveLabelCol = 0;
124 battleRes.moveLabelRow = 3;
125 battleRes.ikariLabelCol = 0;
126 battleRes.ikariLabelRow = 4;
128 battleRes.heroTagFont = intp.GetFont("heroTagFont");
129 battleRes.heroTagFrame = intp.GetFrame("heroTagFrame");
130 battleRes.activeHeroTagFrame = intp.GetFrame("activeHeroTagFrame");
131 battleRes.smallHeroTagFrame = intp.GetFrame("smallHeroTagFrame");
132 battleRes.lastSmallHeroTagFrame = intp.GetFrame("lastSmallHeroTagFrame");
133 battleRes.heroesBgColor = SDL_MapRGB(screen.Screen()->format, 0x18, 0x28, 0x31);
135 SDL_Surface *gauges(IMG_Load("test-data/gauges.png"));
136 Gauge healthGauge(gauges, 0, 16, 0, 0, 16, 6, 1, 6);
137 battleRes.healthGauge = &healthGauge;
138 Gauge manaGauge(gauges, 0, 32, 0, 0, 16, 6, 1, 6);
139 battleRes.manaGauge = &manaGauge;
140 Gauge ikariGauge(gauges, 0, 48, 0, 0, 16, 6, 1, 6);
141 battleRes.ikariGauge = &ikariGauge;
143 SDL_Surface *selectFrameImg(IMG_Load("test-data/select-frame.png"));
144 Frame selectFrame(selectFrameImg, 16, 16);
145 battleRes.selectFrame = &selectFrame;
147 SDL_Surface *normalFontImg(IMG_Load("test-data/normal-font.png"));
148 Sprite normalFontSprite(normalFontImg, 16, 16);
149 Font normalFont(&normalFontSprite, 0, -2);
150 battleRes.normalFont = &normalFont;
152 SDL_Surface *disabledFontImg(IMG_Load("test-data/disabled-font.png"));
153 Sprite disabledFontSprite(disabledFontImg, 16, 16);
154 Font disabledFont(&disabledFontSprite, 0, -2);
155 battleRes.disabledFont = &disabledFont;
157 SDL_Surface *handCursorImg(IMG_Load("test-data/cursor-hand.png"));
158 Sprite handCursorSprite(handCursorImg, 32, 32);
159 battleRes.menuCursor = &handCursorSprite;
161 SDL_Surface *targetingIconsImg(IMG_Load("test-data/targeting-icons.png"));
162 Sprite weaponTargetCursor(targetingIconsImg, 32, 32);
163 Sprite magicTargetCursor(targetingIconsImg, 32, 32, 0, 32);
164 Sprite itemTargetCursor(targetingIconsImg, 32, 32, 0, 64);
165 battleRes.weaponTargetCursor = &weaponTargetCursor;
166 battleRes.magicTargetCursor = &magicTargetCursor;
167 battleRes.itemTargetCursor = &itemTargetCursor;
170 resetSpell.SetName("Reset");
171 maxim.AddSpell(&resetSpell);
173 strongSpell.SetName("Strong");
174 strongSpell.SetCost(3);
175 strongSpell.SetUsableInBattle();
176 strongSpell.GetTargetingMode().TargetMultipleAllies();
177 maxim.AddSpell(&strongSpell);
178 selan.AddSpell(&strongSpell);
180 strongerSpell.SetName("Stronger");
181 strongerSpell.SetCost(8);
182 strongerSpell.SetUsableInBattle();
183 strongerSpell.GetTargetingMode().TargetMultipleAllies();
184 maxim.AddSpell(&strongerSpell);
185 selan.AddSpell(&strongerSpell);
187 championSpell.SetName("Champion");
188 championSpell.SetCost(16);
189 championSpell.SetUsableInBattle();
190 championSpell.GetTargetingMode().TargetMultipleAllies();
191 maxim.AddSpell(&championSpell);
192 selan.AddSpell(&championSpell);
194 rallySpell.SetName("Rally");
195 rallySpell.SetCost(10);
196 rallySpell.SetUsableInBattle();
197 rallySpell.GetTargetingMode().TargetMultipleAllies();
198 maxim.AddSpell(&rallySpell);
199 selan.AddSpell(&rallySpell);
201 escapeSpell.SetName("Escape");
202 escapeSpell.SetCost(8);
203 selan.AddSpell(&escapeSpell);
205 valorSpell.SetName("Valor");
206 valorSpell.SetCost(30);
207 valorSpell.SetUsableInBattle();
208 valorSpell.GetTargetingMode().TargetMultipleAllies();
209 maxim.AddSpell(&valorSpell);
210 selan.AddSpell(&valorSpell);
212 battleRes.spellMenuHeadline = "Please choose a spell.";
213 battleRes.spellMenuPrototype = Menu<const Spell *>(&normalFont, &disabledFont, &handCursorSprite, 9, 6, 8, 0, 2, 32, 2, ':');
215 SDL_Surface *itemIcons(IMG_Load("test-data/item-icons.png"));
216 Sprite potionIcon(itemIcons, 16, 16);
217 Sprite ballIcon(itemIcons, 16, 16, 0, 16);
218 Sprite crankIcon(itemIcons, 16, 16, 0, 32);
219 Sprite spearIcon(itemIcons, 16, 16, 0, 48);
220 Sprite swordIcon(itemIcons, 16, 16, 0, 64);
221 Sprite axIcon(itemIcons, 16, 16, 0, 80);
222 Sprite rodIcon(itemIcons, 16, 16, 0, 96);
223 Sprite armorIcon(itemIcons, 16, 16, 0, 112);
224 Sprite shieldIcon(itemIcons, 16, 16, 0, 128);
225 Sprite helmetIcon(itemIcons, 16, 16, 0, 144);
226 Sprite ringIcon(itemIcons, 16, 16, 0, 160);
227 Sprite jewelIcon(itemIcons, 16, 16, 0, 176);
229 battleRes.weaponMenuIcon = &swordIcon;
230 battleRes.armorMenuIcon = &armorIcon;
231 battleRes.shieldMenuIcon = &shieldIcon;
232 battleRes.helmetMenuIcon = &helmetIcon;
233 battleRes.ringMenuIcon = &ringIcon;
234 battleRes.jewelMenuIcon = &jewelIcon;
238 antidote.SetName("Antidote");
239 antidote.SetMenuIcon(&potionIcon);
240 antidote.SetUsableInBattle();
241 antidote.GetTargetingMode().TargetSingleAlly();
242 inventory.Add(&antidote, 9);
244 magicJar.SetName("Magic jar");
245 magicJar.SetMenuIcon(&potionIcon);
246 magicJar.SetUsableInBattle();
247 magicJar.GetTargetingMode().TargetSingleAlly();
248 inventory.Add(&magicJar, 4);
250 hiPotion.SetName("Hi-Potion");
251 hiPotion.SetMenuIcon(&potionIcon);
252 hiPotion.SetUsableInBattle();
253 hiPotion.GetTargetingMode().TargetSingleAlly();
254 inventory.Add(&hiPotion, 4);
256 powerPotion.SetName("Power potion");
257 powerPotion.SetMenuIcon(&potionIcon);
258 inventory.Add(&powerPotion, 4);
260 escape.SetName("Escape");
261 inventory.Add(&escape, 2);
263 sleepBall.SetName("Sleep ball");
264 sleepBall.SetMenuIcon(&ballIcon);
265 sleepBall.SetUsableInBattle();
266 sleepBall.GetTargetingMode().TargetSingleEnemy();
267 inventory.Add(&sleepBall, 1);
269 multiBall.SetName("Multi-ball!");
270 multiBall.SetMenuIcon(&ballIcon);
271 multiBall.SetUsableInBattle();
272 multiBall.GetTargetingMode().TargetMultipleEnemies();
273 inventory.Add(&multiBall, 1);
275 figgoru.SetName("Figgoru");
276 figgoru.SetMenuIcon(&crankIcon);
277 figgoru.GetTargetingMode().TargetAllEnemies();
278 inventory.Add(&figgoru, 1);
279 battleRes.inventory = &inventory;
281 battleRes.itemMenuHeadline = "Please choose an item.";
282 battleRes.itemMenuPrototype = Menu<const common::Item *>(&normalFont, &disabledFont, &handCursorSprite, 15, 6, 8, 16, 1, 32, 2, ':');
284 SDL_Surface *swordAttackImg(IMG_Load("test-data/attack-sword.png"));
285 Sprite swordAttackSprite(swordAttackImg, 96, 96);
286 SimpleAnimation swordAttackAnimation(&swordAttackSprite, 2 * framerate, 4);
289 zircoSword.SetName("Zirco sword");
290 zircoSword.SetMenuIcon(&swordIcon);
291 zircoSword.GetTargetingMode().TargetSingleEnemy();
293 firestorm.SetName("Firestorm");
294 firestorm.SetCost(224);
295 firestorm.GetTargetingMode().TargetAllEnemies();
296 firestorm.SetPhysical();
297 zircoSword.SetIkari(&firestorm);
298 zircoSword.SetAttackAnimation(&swordAttackAnimation);
299 maxim.SetWeapon(&zircoSword);
301 zirconArmor.SetName("Zircon armor");
302 zirconArmor.SetMenuIcon(&armorIcon);
304 magicCure.SetName("Magic cure");
305 magicCure.SetCost(128);
306 magicCure.GetTargetingMode().TargetSingleAlly();
307 magicCure.SetMagical();
308 zirconArmor.SetIkari(&magicCure);
309 maxim.SetArmor(&zirconArmor);
311 holyShield.SetName("Holy shield");
312 holyShield.SetMenuIcon(&shieldIcon);
314 lightGuard.SetName("Light guard");
315 lightGuard.SetCost(128);
316 lightGuard.GetTargetingMode().TargetAllAllies(); // actually only targets self
317 lightGuard.SetMagical();
318 holyShield.SetIkari(&lightGuard);
319 maxim.SetShield(&holyShield);
321 legendHelm.SetName("Legend helm");
322 legendHelm.SetMenuIcon(&helmetIcon);
324 boomerang.SetName("Boomerang");
325 boomerang.SetCost(164);
326 boomerang.GetTargetingMode().TargetAllAllies(); // actually only targets self
327 boomerang.SetMagical();
328 legendHelm.SetIkari(&boomerang);
329 maxim.SetHelmet(&legendHelm);
331 sProRing.SetName("S-pro ring");
332 sProRing.SetMenuIcon(&ringIcon);
334 courage.SetName("Courage");
336 courage.GetTargetingMode().TargetMultipleAllies();
337 courage.SetMagical();
338 sProRing.SetIkari(&courage);
339 maxim.SetRing(&sProRing);
341 evilJewel.SetName("Evil jewel");
342 evilJewel.SetMenuIcon(&jewelIcon);
344 gloomy.SetName("Gloomy");
346 gloomy.GetTargetingMode().TargetAllEnemies();
348 evilJewel.SetIkari(&gloomy);
349 maxim.SetJewel(&evilJewel);
352 zircoWhip.SetName("Zirco whip");
353 zircoWhip.SetMenuIcon(&rodIcon);
354 zircoWhip.GetTargetingMode().TargetSingleEnemy();
356 thundershriek.SetName("Thundershriek");
357 thundershriek.SetCost(224);
358 thundershriek.GetTargetingMode().TargetAllEnemies();
359 thundershriek.SetPhysical();
360 zircoWhip.SetIkari(&thundershriek);
361 // selan.SetWeapon(&zircoWhip);
363 zirconPlate.SetName("Zircon plate");
364 zirconPlate.SetMenuIcon(&armorIcon);
366 suddenCure.SetName("Sudden cure");
367 suddenCure.SetCost(96);
368 suddenCure.GetTargetingMode().TargetAllAllies();
369 suddenCure.SetMagical();
370 zirconPlate.SetIkari(&suddenCure);
371 selan.SetArmor(&zirconPlate);
373 zircoGloves.SetName("Zirco gloves");
374 zircoGloves.SetMenuIcon(&shieldIcon);
376 forcefield.SetName("Forcefield");
377 forcefield.SetCost(64);
378 forcefield.GetTargetingMode().TargetAllAllies();
379 forcefield.SetMagical();
380 zircoGloves.SetIkari(&forcefield);
381 selan.SetShield(&zircoGloves);
383 holyCap.SetName("Holy cap");
384 holyCap.SetMenuIcon(&helmetIcon);
386 vulnerable.SetName("Vulnerable");
387 vulnerable.SetCost(196);
388 vulnerable.GetTargetingMode().TargetAllEnemies();
389 vulnerable.SetPhysical();
390 holyCap.SetIkari(&vulnerable);
391 selan.SetHelmet(&holyCap);
393 ghostRing.SetName("Ghost ring");
394 ghostRing.SetMenuIcon(&ringIcon);
396 destroy.SetName("Destroy");
397 destroy.SetCost(128);
398 destroy.GetTargetingMode().TargetMultipleEnemies();
399 destroy.SetMagical();
400 ghostRing.SetIkari(&destroy);
401 selan.SetRing(&ghostRing);
403 eagleRock.SetName("Eagle rock");
404 eagleRock.SetMenuIcon(&jewelIcon);
406 dive.SetName("Dive");
408 dive.GetTargetingMode().TargetSingleEnemy();
410 eagleRock.SetIkari(&dive);
411 selan.SetJewel(&eagleRock);
414 zircoAx.SetName("Zirco ax");
415 zircoAx.SetMenuIcon(&axIcon);
416 zircoAx.GetTargetingMode().TargetSingleEnemy();
418 torrent.SetName("Torrent");
419 torrent.SetCost(224);
420 torrent.GetTargetingMode().TargetAllEnemies();
421 torrent.SetPhysical();
422 zircoAx.SetIkari(&torrent);
423 // guy.SetWeapon(&zircoAx);
424 guy.SetArmor(&zirconArmor);
426 megaShield.SetName("Mega shield");
427 megaShield.SetMenuIcon(&shieldIcon);
429 ironBarrier.SetName("Iron barrier");
430 ironBarrier.SetCost(255);
431 ironBarrier.GetTargetingMode().TargetAllAllies(); // actually only targets self
432 ironBarrier.SetMagical();
433 megaShield.SetIkari(&ironBarrier);
434 guy.SetShield(&megaShield);
436 zircoHelmet.SetName("Zirco helmet");
437 zircoHelmet.SetMenuIcon(&helmetIcon);
439 slow.SetName("Slow");
441 slow.GetTargetingMode().TargetAllEnemies();
443 zircoHelmet.SetIkari(&slow);
444 guy.SetHelmet(&zircoHelmet);
446 powerRing.SetName("Power ring");
447 powerRing.SetMenuIcon(&ringIcon);
449 trick.SetName("Trick");
451 trick.GetTargetingMode().TargetAllEnemies();
453 zircoHelmet.SetIkari(&trick);
454 guy.SetRing(&powerRing);
455 guy.SetJewel(&evilJewel);
457 // NOTE: this is actually Artea equipment
459 lizardBlow.SetName("Lizard blow");
460 lizardBlow.SetMenuIcon(&swordIcon);
461 lizardBlow.GetTargetingMode().TargetSingleEnemy();
463 dragonRush.SetName("Dragon rush");
464 dragonRush.SetCost(164);
465 dragonRush.GetTargetingMode().TargetSingleEnemy();
466 dragonRush.SetPhysical();
467 lizardBlow.SetIkari(&dragonRush);
468 // dekar.SetWeapon(&lizardBlow);
470 holyRobe.SetName("Holy robe");
471 holyRobe.SetMenuIcon(&armorIcon);
473 crisisCure.SetName("Crisis cure");
474 crisisCure.SetCost(164);
475 crisisCure.GetTargetingMode().TargetAllAllies();
476 crisisCure.SetMagical();
477 holyRobe.SetIkari(&crisisCure);
478 dekar.SetArmor(&holyRobe);
479 dekar.SetShield(&zircoGloves);
480 dekar.SetHelmet(&holyCap);
482 rocketRing.SetName("Rocket ring");
483 rocketRing.SetMenuIcon(&ringIcon);
485 fake.SetName("Fake");
487 fake.GetTargetingMode().TargetSingleAlly();
489 rocketRing.SetIkari(&fake);
490 dekar.SetRing(&rocketRing);
492 krakenRock.SetName("Kraken rock");
493 krakenRock.SetMenuIcon(&jewelIcon);
495 tenLegger.SetName("Ten-legger");
496 tenLegger.SetCost(164);
497 tenLegger.GetTargetingMode().TargetAllEnemies();
498 tenLegger.SetPhysical();
499 rocketRing.SetIkari(&tenLegger);
500 dekar.SetJewel(&krakenRock);
502 battleRes.ikariMenuHeadline = "Please choose equipment.";
503 battleRes.noEquipmentText = "No equip";
504 battleRes.ikariMenuPrototype = Menu<const Item *>(&normalFont, &disabledFont, &handCursorSprite, 12, 6, normalFont.CharHeight() / 2, normalFont.CharWidth(), 1, normalFont.CharWidth() * 2, 0, ':', 12, normalFont.CharWidth());
506 battleRes.escapeText = "Escapes.";
508 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &battleRes));
509 battleState->AddMonster(monster);
510 battleState->AddMonster(monster);
511 battleState->AddMonster(monster);
512 battleState->AddMonster(monster);
513 battleState->AddHero(maxim);
514 battleState->AddHero(selan);
515 battleState->AddHero(guy);
516 battleState->AddHero(dekar);
517 Application app(&screen, battleState);
518 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
519 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
520 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
521 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
522 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
523 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
524 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
525 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
526 app.Buttons().MapKey(SDLK_RETURN, Input::START);
527 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
528 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
529 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
533 } catch (Parser::Error &e) {
534 cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl;
536 } catch (exception &e) {
537 cerr << "exception in main(): " << e.what() << endl;