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 battleRes.healthGauge = intp.GetGauge("healthGauge");
136 battleRes.manaGauge = intp.GetGauge("manaGauge");
137 battleRes.ikariGauge = intp.GetGauge("ikariGauge");
139 battleRes.selectFrame = intp.GetFrame("selectFrame");
140 battleRes.normalFont = intp.GetFont("normalFont");
141 battleRes.disabledFont = intp.GetFont("disabledFont");
142 battleRes.menuCursor = intp.GetSprite("handCursor");
144 battleRes.weaponTargetCursor = intp.GetSprite("weaponTargetCursor");
145 battleRes.magicTargetCursor = intp.GetSprite("magicTargetCursor");
146 battleRes.itemTargetCursor = intp.GetSprite("itemTargetCursor");
148 maxim.AddSpell(intp.GetSpell("resetSpell"));
149 Spell *strongSpell(intp.GetSpell("strongSpell"));
150 maxim.AddSpell(strongSpell);
151 selan.AddSpell(strongSpell);
152 Spell *strongerSpell(intp.GetSpell("strongerSpell"));
153 maxim.AddSpell(strongerSpell);
154 selan.AddSpell(strongerSpell);
155 Spell *championSpell(intp.GetSpell("championSpell"));
156 maxim.AddSpell(championSpell);
157 selan.AddSpell(championSpell);
158 Spell *rallySpell(intp.GetSpell("rallySpell"));
159 maxim.AddSpell(rallySpell);
160 selan.AddSpell(rallySpell);
161 selan.AddSpell(intp.GetSpell("escapeSpell"));
162 Spell *valorSpell(intp.GetSpell("valorSpell"));
163 maxim.AddSpell(valorSpell);
164 selan.AddSpell(valorSpell);
166 battleRes.spellMenuHeadline = intp.GetString("spellMenuHeadline");
167 battleRes.spellMenuPrototype = Menu<const Spell *>(intp.GetFont("normalFont"), intp.GetFont("disabledFont"), intp.GetSprite("handCursor"), 9, 6, 8, 0, 2, 32, 2, ':');
169 battleRes.weaponMenuIcon = intp.GetSprite("swordIcon");
170 battleRes.armorMenuIcon = intp.GetSprite("armorIcon");
171 battleRes.shieldMenuIcon = intp.GetSprite("shieldIcon");
172 battleRes.helmetMenuIcon = intp.GetSprite("helmetIcon");
173 battleRes.ringMenuIcon = intp.GetSprite("ringIcon");
174 battleRes.jewelMenuIcon = intp.GetSprite("jewelIcon");
178 antidote.SetName("Antidote");
179 antidote.SetMenuIcon(intp.GetSprite("potionIcon"));
180 antidote.SetUsableInBattle();
181 antidote.GetTargetingMode().TargetSingleAlly();
182 inventory.Add(&antidote, 9);
184 magicJar.SetName("Magic jar");
185 magicJar.SetMenuIcon(intp.GetSprite("potionIcon"));
186 magicJar.SetUsableInBattle();
187 magicJar.GetTargetingMode().TargetSingleAlly();
188 inventory.Add(&magicJar, 4);
190 hiPotion.SetName("Hi-Potion");
191 hiPotion.SetMenuIcon(intp.GetSprite("potionIcon"));
192 hiPotion.SetUsableInBattle();
193 hiPotion.GetTargetingMode().TargetSingleAlly();
194 inventory.Add(&hiPotion, 4);
196 powerPotion.SetName("Power potion");
197 powerPotion.SetMenuIcon(intp.GetSprite("potionIcon"));
198 inventory.Add(&powerPotion, 4);
200 escape.SetName("Escape");
201 inventory.Add(&escape, 2);
203 sleepBall.SetName("Sleep ball");
204 sleepBall.SetMenuIcon(intp.GetSprite("ballIcon"));
205 sleepBall.SetUsableInBattle();
206 sleepBall.GetTargetingMode().TargetSingleEnemy();
207 inventory.Add(&sleepBall, 1);
209 multiBall.SetName("Multi-ball!");
210 multiBall.SetMenuIcon(intp.GetSprite("ballIcon"));
211 multiBall.SetUsableInBattle();
212 multiBall.GetTargetingMode().TargetMultipleEnemies();
213 inventory.Add(&multiBall, 1);
215 figgoru.SetName("Figgoru");
216 figgoru.SetMenuIcon(intp.GetSprite("crankIcon"));
217 figgoru.GetTargetingMode().TargetAllEnemies();
218 inventory.Add(&figgoru, 1);
219 battleRes.inventory = &inventory;
221 battleRes.itemMenuHeadline = "Please choose an item.";
222 battleRes.itemMenuPrototype = Menu<const common::Item *>(intp.GetFont("normalFont"), intp.GetFont("disabledFont"), intp.GetSprite("handCursor"), 15, 6, 8, 16, 1, 32, 2, ':');
224 SDL_Surface *swordAttackImg(IMG_Load("test-data/attack-sword.png"));
225 Sprite swordAttackSprite(swordAttackImg, 96, 96);
226 SimpleAnimation swordAttackAnimation(&swordAttackSprite, 2 * framerate, 4);
229 zircoSword.SetName("Zirco sword");
230 zircoSword.SetMenuIcon(intp.GetSprite("swordIcon"));
231 zircoSword.GetTargetingMode().TargetSingleEnemy();
233 firestorm.SetName("Firestorm");
234 firestorm.SetCost(224);
235 firestorm.GetTargetingMode().TargetAllEnemies();
236 firestorm.SetPhysical();
237 zircoSword.SetIkari(&firestorm);
238 zircoSword.SetAttackAnimation(&swordAttackAnimation);
239 maxim.SetWeapon(&zircoSword);
241 zirconArmor.SetName("Zircon armor");
242 zirconArmor.SetMenuIcon(intp.GetSprite("armorIcon"));
244 magicCure.SetName("Magic cure");
245 magicCure.SetCost(128);
246 magicCure.GetTargetingMode().TargetSingleAlly();
247 magicCure.SetMagical();
248 zirconArmor.SetIkari(&magicCure);
249 maxim.SetArmor(&zirconArmor);
251 holyShield.SetName("Holy shield");
252 holyShield.SetMenuIcon(intp.GetSprite("shieldIcon"));
254 lightGuard.SetName("Light guard");
255 lightGuard.SetCost(128);
256 lightGuard.GetTargetingMode().TargetAllAllies(); // actually only targets self
257 lightGuard.SetMagical();
258 holyShield.SetIkari(&lightGuard);
259 maxim.SetShield(&holyShield);
261 legendHelm.SetName("Legend helm");
262 legendHelm.SetMenuIcon(intp.GetSprite("helmetIcon"));
264 boomerang.SetName("Boomerang");
265 boomerang.SetCost(164);
266 boomerang.GetTargetingMode().TargetAllAllies(); // actually only targets self
267 boomerang.SetMagical();
268 legendHelm.SetIkari(&boomerang);
269 maxim.SetHelmet(&legendHelm);
271 sProRing.SetName("S-pro ring");
272 sProRing.SetMenuIcon(intp.GetSprite("ringIcon"));
274 courage.SetName("Courage");
276 courage.GetTargetingMode().TargetMultipleAllies();
277 courage.SetMagical();
278 sProRing.SetIkari(&courage);
279 maxim.SetRing(&sProRing);
281 evilJewel.SetName("Evil jewel");
282 evilJewel.SetMenuIcon(intp.GetSprite("jewelIcon"));
284 gloomy.SetName("Gloomy");
286 gloomy.GetTargetingMode().TargetAllEnemies();
288 evilJewel.SetIkari(&gloomy);
289 maxim.SetJewel(&evilJewel);
292 zircoWhip.SetName("Zirco whip");
293 zircoWhip.SetMenuIcon(intp.GetSprite("rodIcon"));
294 zircoWhip.GetTargetingMode().TargetSingleEnemy();
296 thundershriek.SetName("Thundershriek");
297 thundershriek.SetCost(224);
298 thundershriek.GetTargetingMode().TargetAllEnemies();
299 thundershriek.SetPhysical();
300 zircoWhip.SetIkari(&thundershriek);
301 // selan.SetWeapon(&zircoWhip);
303 zirconPlate.SetName("Zircon plate");
304 zirconPlate.SetMenuIcon(intp.GetSprite("armorIcon"));
306 suddenCure.SetName("Sudden cure");
307 suddenCure.SetCost(96);
308 suddenCure.GetTargetingMode().TargetAllAllies();
309 suddenCure.SetMagical();
310 zirconPlate.SetIkari(&suddenCure);
311 selan.SetArmor(&zirconPlate);
313 zircoGloves.SetName("Zirco gloves");
314 zircoGloves.SetMenuIcon(intp.GetSprite("shieldIcon"));
316 forcefield.SetName("Forcefield");
317 forcefield.SetCost(64);
318 forcefield.GetTargetingMode().TargetAllAllies();
319 forcefield.SetMagical();
320 zircoGloves.SetIkari(&forcefield);
321 selan.SetShield(&zircoGloves);
323 holyCap.SetName("Holy cap");
324 holyCap.SetMenuIcon(intp.GetSprite("helmetIcon"));
326 vulnerable.SetName("Vulnerable");
327 vulnerable.SetCost(196);
328 vulnerable.GetTargetingMode().TargetAllEnemies();
329 vulnerable.SetPhysical();
330 holyCap.SetIkari(&vulnerable);
331 selan.SetHelmet(&holyCap);
333 ghostRing.SetName("Ghost ring");
334 ghostRing.SetMenuIcon(intp.GetSprite("ringIcon"));
336 destroy.SetName("Destroy");
337 destroy.SetCost(128);
338 destroy.GetTargetingMode().TargetMultipleEnemies();
339 destroy.SetMagical();
340 ghostRing.SetIkari(&destroy);
341 selan.SetRing(&ghostRing);
343 eagleRock.SetName("Eagle rock");
344 eagleRock.SetMenuIcon(intp.GetSprite("jewelIcon"));
346 dive.SetName("Dive");
348 dive.GetTargetingMode().TargetSingleEnemy();
350 eagleRock.SetIkari(&dive);
351 selan.SetJewel(&eagleRock);
354 zircoAx.SetName("Zirco ax");
355 zircoAx.SetMenuIcon(intp.GetSprite("axIcon"));
356 zircoAx.GetTargetingMode().TargetSingleEnemy();
358 torrent.SetName("Torrent");
359 torrent.SetCost(224);
360 torrent.GetTargetingMode().TargetAllEnemies();
361 torrent.SetPhysical();
362 zircoAx.SetIkari(&torrent);
363 // guy.SetWeapon(&zircoAx);
364 guy.SetArmor(&zirconArmor);
366 megaShield.SetName("Mega shield");
367 megaShield.SetMenuIcon(intp.GetSprite("shieldIcon"));
369 ironBarrier.SetName("Iron barrier");
370 ironBarrier.SetCost(255);
371 ironBarrier.GetTargetingMode().TargetAllAllies(); // actually only targets self
372 ironBarrier.SetMagical();
373 megaShield.SetIkari(&ironBarrier);
374 guy.SetShield(&megaShield);
376 zircoHelmet.SetName("Zirco helmet");
377 zircoHelmet.SetMenuIcon(intp.GetSprite("helmetIcon"));
379 slow.SetName("Slow");
381 slow.GetTargetingMode().TargetAllEnemies();
383 zircoHelmet.SetIkari(&slow);
384 guy.SetHelmet(&zircoHelmet);
386 powerRing.SetName("Power ring");
387 powerRing.SetMenuIcon(intp.GetSprite("ringIcon"));
389 trick.SetName("Trick");
391 trick.GetTargetingMode().TargetAllEnemies();
393 zircoHelmet.SetIkari(&trick);
394 guy.SetRing(&powerRing);
395 guy.SetJewel(&evilJewel);
397 // NOTE: this is actually Artea equipment
399 lizardBlow.SetName("Lizard blow");
400 lizardBlow.SetMenuIcon(intp.GetSprite("swordIcon"));
401 lizardBlow.GetTargetingMode().TargetSingleEnemy();
403 dragonRush.SetName("Dragon rush");
404 dragonRush.SetCost(164);
405 dragonRush.GetTargetingMode().TargetSingleEnemy();
406 dragonRush.SetPhysical();
407 lizardBlow.SetIkari(&dragonRush);
408 // dekar.SetWeapon(&lizardBlow);
410 holyRobe.SetName("Holy robe");
411 holyRobe.SetMenuIcon(intp.GetSprite("armorIcon"));
413 crisisCure.SetName("Crisis cure");
414 crisisCure.SetCost(164);
415 crisisCure.GetTargetingMode().TargetAllAllies();
416 crisisCure.SetMagical();
417 holyRobe.SetIkari(&crisisCure);
418 dekar.SetArmor(&holyRobe);
419 dekar.SetShield(&zircoGloves);
420 dekar.SetHelmet(&holyCap);
422 rocketRing.SetName("Rocket ring");
423 rocketRing.SetMenuIcon(intp.GetSprite("ringIcon"));
425 fake.SetName("Fake");
427 fake.GetTargetingMode().TargetSingleAlly();
429 rocketRing.SetIkari(&fake);
430 dekar.SetRing(&rocketRing);
432 krakenRock.SetName("Kraken rock");
433 krakenRock.SetMenuIcon(intp.GetSprite("jewelIcon"));
435 tenLegger.SetName("Ten-legger");
436 tenLegger.SetCost(164);
437 tenLegger.GetTargetingMode().TargetAllEnemies();
438 tenLegger.SetPhysical();
439 rocketRing.SetIkari(&tenLegger);
440 dekar.SetJewel(&krakenRock);
442 battleRes.ikariMenuHeadline = "Please choose equipment.";
443 battleRes.noEquipmentText = "No equip";
444 battleRes.ikariMenuPrototype = Menu<const Item *>(intp.GetFont("normalFont"), intp.GetFont("disabledFont"), intp.GetSprite("handCursor"), 12, 6, intp.GetFont("normalFont")->CharHeight() / 2, intp.GetFont("normalFont")->CharWidth(), 1, intp.GetFont("normalFont")->CharWidth() * 2, 0, ':', 12, intp.GetFont("normalFont")->CharWidth());
446 battleRes.escapeText = "Escapes.";
448 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &battleRes));
449 battleState->AddMonster(monster);
450 battleState->AddMonster(monster);
451 battleState->AddMonster(monster);
452 battleState->AddMonster(monster);
453 battleState->AddHero(maxim);
454 battleState->AddHero(selan);
455 battleState->AddHero(guy);
456 battleState->AddHero(dekar);
457 Application app(&screen, battleState);
458 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
459 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
460 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
461 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
462 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
463 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
464 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
465 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
466 app.Buttons().MapKey(SDLK_RETURN, Input::START);
467 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
468 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
469 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
473 } catch (Parser::Error &e) {
474 cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl;
476 } catch (exception &e) {
477 cerr << "exception in main(): " << e.what() << endl;