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 = "Please choose a spell.";
167 battleRes.spellMenuPrototype = Menu<const Spell *>(intp.GetFont("normalFont"), intp.GetFont("disabledFont"), intp.GetSprite("handCursor"), 9, 6, 8, 0, 2, 32, 2, ':');
169 SDL_Surface *itemIcons(IMG_Load("test-data/item-icons.png"));
170 Sprite potionIcon(itemIcons, 16, 16);
171 Sprite ballIcon(itemIcons, 16, 16, 0, 16);
172 Sprite crankIcon(itemIcons, 16, 16, 0, 32);
173 Sprite spearIcon(itemIcons, 16, 16, 0, 48);
174 Sprite swordIcon(itemIcons, 16, 16, 0, 64);
175 Sprite axIcon(itemIcons, 16, 16, 0, 80);
176 Sprite rodIcon(itemIcons, 16, 16, 0, 96);
177 Sprite armorIcon(itemIcons, 16, 16, 0, 112);
178 Sprite shieldIcon(itemIcons, 16, 16, 0, 128);
179 Sprite helmetIcon(itemIcons, 16, 16, 0, 144);
180 Sprite ringIcon(itemIcons, 16, 16, 0, 160);
181 Sprite jewelIcon(itemIcons, 16, 16, 0, 176);
183 battleRes.weaponMenuIcon = &swordIcon;
184 battleRes.armorMenuIcon = &armorIcon;
185 battleRes.shieldMenuIcon = &shieldIcon;
186 battleRes.helmetMenuIcon = &helmetIcon;
187 battleRes.ringMenuIcon = &ringIcon;
188 battleRes.jewelMenuIcon = &jewelIcon;
192 antidote.SetName("Antidote");
193 antidote.SetMenuIcon(&potionIcon);
194 antidote.SetUsableInBattle();
195 antidote.GetTargetingMode().TargetSingleAlly();
196 inventory.Add(&antidote, 9);
198 magicJar.SetName("Magic jar");
199 magicJar.SetMenuIcon(&potionIcon);
200 magicJar.SetUsableInBattle();
201 magicJar.GetTargetingMode().TargetSingleAlly();
202 inventory.Add(&magicJar, 4);
204 hiPotion.SetName("Hi-Potion");
205 hiPotion.SetMenuIcon(&potionIcon);
206 hiPotion.SetUsableInBattle();
207 hiPotion.GetTargetingMode().TargetSingleAlly();
208 inventory.Add(&hiPotion, 4);
210 powerPotion.SetName("Power potion");
211 powerPotion.SetMenuIcon(&potionIcon);
212 inventory.Add(&powerPotion, 4);
214 escape.SetName("Escape");
215 inventory.Add(&escape, 2);
217 sleepBall.SetName("Sleep ball");
218 sleepBall.SetMenuIcon(&ballIcon);
219 sleepBall.SetUsableInBattle();
220 sleepBall.GetTargetingMode().TargetSingleEnemy();
221 inventory.Add(&sleepBall, 1);
223 multiBall.SetName("Multi-ball!");
224 multiBall.SetMenuIcon(&ballIcon);
225 multiBall.SetUsableInBattle();
226 multiBall.GetTargetingMode().TargetMultipleEnemies();
227 inventory.Add(&multiBall, 1);
229 figgoru.SetName("Figgoru");
230 figgoru.SetMenuIcon(&crankIcon);
231 figgoru.GetTargetingMode().TargetAllEnemies();
232 inventory.Add(&figgoru, 1);
233 battleRes.inventory = &inventory;
235 battleRes.itemMenuHeadline = "Please choose an item.";
236 battleRes.itemMenuPrototype = Menu<const common::Item *>(intp.GetFont("normalFont"), intp.GetFont("disabledFont"), intp.GetSprite("handCursor"), 15, 6, 8, 16, 1, 32, 2, ':');
238 SDL_Surface *swordAttackImg(IMG_Load("test-data/attack-sword.png"));
239 Sprite swordAttackSprite(swordAttackImg, 96, 96);
240 SimpleAnimation swordAttackAnimation(&swordAttackSprite, 2 * framerate, 4);
243 zircoSword.SetName("Zirco sword");
244 zircoSword.SetMenuIcon(&swordIcon);
245 zircoSword.GetTargetingMode().TargetSingleEnemy();
247 firestorm.SetName("Firestorm");
248 firestorm.SetCost(224);
249 firestorm.GetTargetingMode().TargetAllEnemies();
250 firestorm.SetPhysical();
251 zircoSword.SetIkari(&firestorm);
252 zircoSword.SetAttackAnimation(&swordAttackAnimation);
253 maxim.SetWeapon(&zircoSword);
255 zirconArmor.SetName("Zircon armor");
256 zirconArmor.SetMenuIcon(&armorIcon);
258 magicCure.SetName("Magic cure");
259 magicCure.SetCost(128);
260 magicCure.GetTargetingMode().TargetSingleAlly();
261 magicCure.SetMagical();
262 zirconArmor.SetIkari(&magicCure);
263 maxim.SetArmor(&zirconArmor);
265 holyShield.SetName("Holy shield");
266 holyShield.SetMenuIcon(&shieldIcon);
268 lightGuard.SetName("Light guard");
269 lightGuard.SetCost(128);
270 lightGuard.GetTargetingMode().TargetAllAllies(); // actually only targets self
271 lightGuard.SetMagical();
272 holyShield.SetIkari(&lightGuard);
273 maxim.SetShield(&holyShield);
275 legendHelm.SetName("Legend helm");
276 legendHelm.SetMenuIcon(&helmetIcon);
278 boomerang.SetName("Boomerang");
279 boomerang.SetCost(164);
280 boomerang.GetTargetingMode().TargetAllAllies(); // actually only targets self
281 boomerang.SetMagical();
282 legendHelm.SetIkari(&boomerang);
283 maxim.SetHelmet(&legendHelm);
285 sProRing.SetName("S-pro ring");
286 sProRing.SetMenuIcon(&ringIcon);
288 courage.SetName("Courage");
290 courage.GetTargetingMode().TargetMultipleAllies();
291 courage.SetMagical();
292 sProRing.SetIkari(&courage);
293 maxim.SetRing(&sProRing);
295 evilJewel.SetName("Evil jewel");
296 evilJewel.SetMenuIcon(&jewelIcon);
298 gloomy.SetName("Gloomy");
300 gloomy.GetTargetingMode().TargetAllEnemies();
302 evilJewel.SetIkari(&gloomy);
303 maxim.SetJewel(&evilJewel);
306 zircoWhip.SetName("Zirco whip");
307 zircoWhip.SetMenuIcon(&rodIcon);
308 zircoWhip.GetTargetingMode().TargetSingleEnemy();
310 thundershriek.SetName("Thundershriek");
311 thundershriek.SetCost(224);
312 thundershriek.GetTargetingMode().TargetAllEnemies();
313 thundershriek.SetPhysical();
314 zircoWhip.SetIkari(&thundershriek);
315 // selan.SetWeapon(&zircoWhip);
317 zirconPlate.SetName("Zircon plate");
318 zirconPlate.SetMenuIcon(&armorIcon);
320 suddenCure.SetName("Sudden cure");
321 suddenCure.SetCost(96);
322 suddenCure.GetTargetingMode().TargetAllAllies();
323 suddenCure.SetMagical();
324 zirconPlate.SetIkari(&suddenCure);
325 selan.SetArmor(&zirconPlate);
327 zircoGloves.SetName("Zirco gloves");
328 zircoGloves.SetMenuIcon(&shieldIcon);
330 forcefield.SetName("Forcefield");
331 forcefield.SetCost(64);
332 forcefield.GetTargetingMode().TargetAllAllies();
333 forcefield.SetMagical();
334 zircoGloves.SetIkari(&forcefield);
335 selan.SetShield(&zircoGloves);
337 holyCap.SetName("Holy cap");
338 holyCap.SetMenuIcon(&helmetIcon);
340 vulnerable.SetName("Vulnerable");
341 vulnerable.SetCost(196);
342 vulnerable.GetTargetingMode().TargetAllEnemies();
343 vulnerable.SetPhysical();
344 holyCap.SetIkari(&vulnerable);
345 selan.SetHelmet(&holyCap);
347 ghostRing.SetName("Ghost ring");
348 ghostRing.SetMenuIcon(&ringIcon);
350 destroy.SetName("Destroy");
351 destroy.SetCost(128);
352 destroy.GetTargetingMode().TargetMultipleEnemies();
353 destroy.SetMagical();
354 ghostRing.SetIkari(&destroy);
355 selan.SetRing(&ghostRing);
357 eagleRock.SetName("Eagle rock");
358 eagleRock.SetMenuIcon(&jewelIcon);
360 dive.SetName("Dive");
362 dive.GetTargetingMode().TargetSingleEnemy();
364 eagleRock.SetIkari(&dive);
365 selan.SetJewel(&eagleRock);
368 zircoAx.SetName("Zirco ax");
369 zircoAx.SetMenuIcon(&axIcon);
370 zircoAx.GetTargetingMode().TargetSingleEnemy();
372 torrent.SetName("Torrent");
373 torrent.SetCost(224);
374 torrent.GetTargetingMode().TargetAllEnemies();
375 torrent.SetPhysical();
376 zircoAx.SetIkari(&torrent);
377 // guy.SetWeapon(&zircoAx);
378 guy.SetArmor(&zirconArmor);
380 megaShield.SetName("Mega shield");
381 megaShield.SetMenuIcon(&shieldIcon);
383 ironBarrier.SetName("Iron barrier");
384 ironBarrier.SetCost(255);
385 ironBarrier.GetTargetingMode().TargetAllAllies(); // actually only targets self
386 ironBarrier.SetMagical();
387 megaShield.SetIkari(&ironBarrier);
388 guy.SetShield(&megaShield);
390 zircoHelmet.SetName("Zirco helmet");
391 zircoHelmet.SetMenuIcon(&helmetIcon);
393 slow.SetName("Slow");
395 slow.GetTargetingMode().TargetAllEnemies();
397 zircoHelmet.SetIkari(&slow);
398 guy.SetHelmet(&zircoHelmet);
400 powerRing.SetName("Power ring");
401 powerRing.SetMenuIcon(&ringIcon);
403 trick.SetName("Trick");
405 trick.GetTargetingMode().TargetAllEnemies();
407 zircoHelmet.SetIkari(&trick);
408 guy.SetRing(&powerRing);
409 guy.SetJewel(&evilJewel);
411 // NOTE: this is actually Artea equipment
413 lizardBlow.SetName("Lizard blow");
414 lizardBlow.SetMenuIcon(&swordIcon);
415 lizardBlow.GetTargetingMode().TargetSingleEnemy();
417 dragonRush.SetName("Dragon rush");
418 dragonRush.SetCost(164);
419 dragonRush.GetTargetingMode().TargetSingleEnemy();
420 dragonRush.SetPhysical();
421 lizardBlow.SetIkari(&dragonRush);
422 // dekar.SetWeapon(&lizardBlow);
424 holyRobe.SetName("Holy robe");
425 holyRobe.SetMenuIcon(&armorIcon);
427 crisisCure.SetName("Crisis cure");
428 crisisCure.SetCost(164);
429 crisisCure.GetTargetingMode().TargetAllAllies();
430 crisisCure.SetMagical();
431 holyRobe.SetIkari(&crisisCure);
432 dekar.SetArmor(&holyRobe);
433 dekar.SetShield(&zircoGloves);
434 dekar.SetHelmet(&holyCap);
436 rocketRing.SetName("Rocket ring");
437 rocketRing.SetMenuIcon(&ringIcon);
439 fake.SetName("Fake");
441 fake.GetTargetingMode().TargetSingleAlly();
443 rocketRing.SetIkari(&fake);
444 dekar.SetRing(&rocketRing);
446 krakenRock.SetName("Kraken rock");
447 krakenRock.SetMenuIcon(&jewelIcon);
449 tenLegger.SetName("Ten-legger");
450 tenLegger.SetCost(164);
451 tenLegger.GetTargetingMode().TargetAllEnemies();
452 tenLegger.SetPhysical();
453 rocketRing.SetIkari(&tenLegger);
454 dekar.SetJewel(&krakenRock);
456 battleRes.ikariMenuHeadline = "Please choose equipment.";
457 battleRes.noEquipmentText = "No equip";
458 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());
460 battleRes.escapeText = "Escapes.";
462 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &battleRes));
463 battleState->AddMonster(monster);
464 battleState->AddMonster(monster);
465 battleState->AddMonster(monster);
466 battleState->AddMonster(monster);
467 battleState->AddHero(maxim);
468 battleState->AddHero(selan);
469 battleState->AddHero(guy);
470 battleState->AddHero(dekar);
471 Application app(&screen, battleState);
472 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
473 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
474 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
475 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
476 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
477 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
478 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
479 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
480 app.Buttons().MapKey(SDLK_RETURN, Input::START);
481 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
482 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
483 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
487 } catch (Parser::Error &e) {
488 cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl;
490 } catch (exception &e) {
491 cerr << "exception in main(): " << e.what() << endl;