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");
177 inventory.Add(intp.GetItem("antidoteItem"), 9);
178 inventory.Add(intp.GetItem("magicJarItem"), 4);
179 inventory.Add(intp.GetItem("hiPotionItem"), 4);
180 inventory.Add(intp.GetItem("powerPotionItem"), 4);
181 inventory.Add(intp.GetItem("escapeItem"), 2);
182 inventory.Add(intp.GetItem("sleepBallItem"), 1);
183 battleRes.inventory = &inventory;
185 battleRes.itemMenuHeadline = intp.GetString("itemMenuHeadline");
186 battleRes.itemMenuPrototype = Menu<const common::Item *>(intp.GetFont("normalFont"), intp.GetFont("disabledFont"), intp.GetSprite("handCursor"), 15, 6, 8, 16, 1, 32, 2, ':');
188 SDL_Surface *swordAttackImg(IMG_Load("test-data/attack-sword.png"));
189 Sprite swordAttackSprite(swordAttackImg, 96, 96);
190 SimpleAnimation swordAttackAnimation(&swordAttackSprite, 2 * framerate, 4);
192 maxim.SetWeapon(intp.GetItem("zircoSwordItem"));
193 maxim.SetArmor(intp.GetItem("zirconArmorItem"));
195 holyShield.SetName("Holy shield");
196 holyShield.SetMenuIcon(intp.GetSprite("shieldIcon"));
198 lightGuard.SetName("Light guard");
199 lightGuard.SetCost(128);
200 lightGuard.GetTargetingMode().TargetAllAllies(); // actually only targets self
201 lightGuard.SetMagical();
202 holyShield.SetIkari(&lightGuard);
203 maxim.SetShield(&holyShield);
205 legendHelm.SetName("Legend helm");
206 legendHelm.SetMenuIcon(intp.GetSprite("helmetIcon"));
208 boomerang.SetName("Boomerang");
209 boomerang.SetCost(164);
210 boomerang.GetTargetingMode().TargetAllAllies(); // actually only targets self
211 boomerang.SetMagical();
212 legendHelm.SetIkari(&boomerang);
213 maxim.SetHelmet(&legendHelm);
215 sProRing.SetName("S-pro ring");
216 sProRing.SetMenuIcon(intp.GetSprite("ringIcon"));
218 courage.SetName("Courage");
220 courage.GetTargetingMode().TargetMultipleAllies();
221 courage.SetMagical();
222 sProRing.SetIkari(&courage);
223 maxim.SetRing(&sProRing);
225 evilJewel.SetName("Evil jewel");
226 evilJewel.SetMenuIcon(intp.GetSprite("jewelIcon"));
228 gloomy.SetName("Gloomy");
230 gloomy.GetTargetingMode().TargetAllEnemies();
232 evilJewel.SetIkari(&gloomy);
233 maxim.SetJewel(&evilJewel);
236 zircoWhip.SetName("Zirco whip");
237 zircoWhip.SetMenuIcon(intp.GetSprite("rodIcon"));
238 zircoWhip.GetTargetingMode().TargetSingleEnemy();
240 thundershriek.SetName("Thundershriek");
241 thundershriek.SetCost(224);
242 thundershriek.GetTargetingMode().TargetAllEnemies();
243 thundershriek.SetPhysical();
244 zircoWhip.SetIkari(&thundershriek);
245 // selan.SetWeapon(&zircoWhip);
247 zirconPlate.SetName("Zircon plate");
248 zirconPlate.SetMenuIcon(intp.GetSprite("armorIcon"));
250 suddenCure.SetName("Sudden cure");
251 suddenCure.SetCost(96);
252 suddenCure.GetTargetingMode().TargetAllAllies();
253 suddenCure.SetMagical();
254 zirconPlate.SetIkari(&suddenCure);
255 selan.SetArmor(&zirconPlate);
257 zircoGloves.SetName("Zirco gloves");
258 zircoGloves.SetMenuIcon(intp.GetSprite("shieldIcon"));
260 forcefield.SetName("Forcefield");
261 forcefield.SetCost(64);
262 forcefield.GetTargetingMode().TargetAllAllies();
263 forcefield.SetMagical();
264 zircoGloves.SetIkari(&forcefield);
265 selan.SetShield(&zircoGloves);
267 holyCap.SetName("Holy cap");
268 holyCap.SetMenuIcon(intp.GetSprite("helmetIcon"));
270 vulnerable.SetName("Vulnerable");
271 vulnerable.SetCost(196);
272 vulnerable.GetTargetingMode().TargetAllEnemies();
273 vulnerable.SetPhysical();
274 holyCap.SetIkari(&vulnerable);
275 selan.SetHelmet(&holyCap);
277 ghostRing.SetName("Ghost ring");
278 ghostRing.SetMenuIcon(intp.GetSprite("ringIcon"));
280 destroy.SetName("Destroy");
281 destroy.SetCost(128);
282 destroy.GetTargetingMode().TargetMultipleEnemies();
283 destroy.SetMagical();
284 ghostRing.SetIkari(&destroy);
285 selan.SetRing(&ghostRing);
287 eagleRock.SetName("Eagle rock");
288 eagleRock.SetMenuIcon(intp.GetSprite("jewelIcon"));
290 dive.SetName("Dive");
292 dive.GetTargetingMode().TargetSingleEnemy();
294 eagleRock.SetIkari(&dive);
295 selan.SetJewel(&eagleRock);
298 zircoAx.SetName("Zirco ax");
299 zircoAx.SetMenuIcon(intp.GetSprite("axIcon"));
300 zircoAx.GetTargetingMode().TargetSingleEnemy();
302 torrent.SetName("Torrent");
303 torrent.SetCost(224);
304 torrent.GetTargetingMode().TargetAllEnemies();
305 torrent.SetPhysical();
306 zircoAx.SetIkari(&torrent);
307 // guy.SetWeapon(&zircoAx);
308 guy.SetArmor(intp.GetItem("zirconArmorItem"));
310 megaShield.SetName("Mega shield");
311 megaShield.SetMenuIcon(intp.GetSprite("shieldIcon"));
313 ironBarrier.SetName("Iron barrier");
314 ironBarrier.SetCost(255);
315 ironBarrier.GetTargetingMode().TargetAllAllies(); // actually only targets self
316 ironBarrier.SetMagical();
317 megaShield.SetIkari(&ironBarrier);
318 guy.SetShield(&megaShield);
320 zircoHelmet.SetName("Zirco helmet");
321 zircoHelmet.SetMenuIcon(intp.GetSprite("helmetIcon"));
323 slow.SetName("Slow");
325 slow.GetTargetingMode().TargetAllEnemies();
327 zircoHelmet.SetIkari(&slow);
328 guy.SetHelmet(&zircoHelmet);
330 powerRing.SetName("Power ring");
331 powerRing.SetMenuIcon(intp.GetSprite("ringIcon"));
333 trick.SetName("Trick");
335 trick.GetTargetingMode().TargetAllEnemies();
337 zircoHelmet.SetIkari(&trick);
338 guy.SetRing(&powerRing);
339 guy.SetJewel(&evilJewel);
341 // NOTE: this is actually Artea equipment
343 lizardBlow.SetName("Lizard blow");
344 lizardBlow.SetMenuIcon(intp.GetSprite("swordIcon"));
345 lizardBlow.GetTargetingMode().TargetSingleEnemy();
347 dragonRush.SetName("Dragon rush");
348 dragonRush.SetCost(164);
349 dragonRush.GetTargetingMode().TargetSingleEnemy();
350 dragonRush.SetPhysical();
351 lizardBlow.SetIkari(&dragonRush);
352 // dekar.SetWeapon(&lizardBlow);
354 holyRobe.SetName("Holy robe");
355 holyRobe.SetMenuIcon(intp.GetSprite("armorIcon"));
357 crisisCure.SetName("Crisis cure");
358 crisisCure.SetCost(164);
359 crisisCure.GetTargetingMode().TargetAllAllies();
360 crisisCure.SetMagical();
361 holyRobe.SetIkari(&crisisCure);
362 dekar.SetArmor(&holyRobe);
363 dekar.SetShield(&zircoGloves);
364 dekar.SetHelmet(&holyCap);
366 rocketRing.SetName("Rocket ring");
367 rocketRing.SetMenuIcon(intp.GetSprite("ringIcon"));
369 fake.SetName("Fake");
371 fake.GetTargetingMode().TargetSingleAlly();
373 rocketRing.SetIkari(&fake);
374 dekar.SetRing(&rocketRing);
376 krakenRock.SetName("Kraken rock");
377 krakenRock.SetMenuIcon(intp.GetSprite("jewelIcon"));
379 tenLegger.SetName("Ten-legger");
380 tenLegger.SetCost(164);
381 tenLegger.GetTargetingMode().TargetAllEnemies();
382 tenLegger.SetPhysical();
383 rocketRing.SetIkari(&tenLegger);
384 dekar.SetJewel(&krakenRock);
386 battleRes.ikariMenuHeadline = "Please choose equipment.";
387 battleRes.noEquipmentText = "No equip";
388 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());
390 battleRes.escapeText = "Escapes.";
392 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &battleRes));
393 battleState->AddMonster(monster);
394 battleState->AddMonster(monster);
395 battleState->AddMonster(monster);
396 battleState->AddMonster(monster);
397 battleState->AddHero(maxim);
398 battleState->AddHero(selan);
399 battleState->AddHero(guy);
400 battleState->AddHero(dekar);
401 Application app(&screen, battleState);
402 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
403 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
404 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
405 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
406 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
407 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
408 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
409 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
410 app.Buttons().MapKey(SDLK_RETURN, Input::START);
411 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
412 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
413 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
417 } catch (Parser::Error &e) {
418 cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl;
420 } catch (exception &e) {
421 cerr << "exception in main(): " << e.what() << endl;