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"));
194 maxim.SetShield(intp.GetItem("holyShieldItem"));
195 maxim.SetHelmet(intp.GetItem("legendHelmItem"));
196 maxim.SetRing(intp.GetItem("sProRingItem"));
197 maxim.SetJewel(intp.GetItem("evilJewelItem"));
199 // selan.SetWeapon(intp.GetItem("zircoWhipItem"));
200 selan.SetArmor(intp.GetItem("zirconPlateItem"));
201 selan.SetShield(intp.GetItem("zircoGlovesItem"));
202 selan.SetHelmet(intp.GetItem("holyCapItem"));
203 selan.SetRing(intp.GetItem("ghostRingItem"));
204 selan.SetJewel(intp.GetItem("eagleRockItem"));
207 zircoAx.SetName("Zirco ax");
208 zircoAx.SetMenuIcon(intp.GetSprite("axIcon"));
209 zircoAx.GetTargetingMode().TargetSingleEnemy();
211 torrent.SetName("Torrent");
212 torrent.SetCost(224);
213 torrent.GetTargetingMode().TargetAllEnemies();
214 torrent.SetPhysical();
215 zircoAx.SetIkari(&torrent);
216 // guy.SetWeapon(&zircoAx);
217 guy.SetArmor(intp.GetItem("zirconArmorItem"));
219 megaShield.SetName("Mega shield");
220 megaShield.SetMenuIcon(intp.GetSprite("shieldIcon"));
222 ironBarrier.SetName("Iron barrier");
223 ironBarrier.SetCost(255);
224 ironBarrier.GetTargetingMode().TargetAllAllies(); // actually only targets self
225 ironBarrier.SetMagical();
226 megaShield.SetIkari(&ironBarrier);
227 guy.SetShield(&megaShield);
229 zircoHelmet.SetName("Zirco helmet");
230 zircoHelmet.SetMenuIcon(intp.GetSprite("helmetIcon"));
232 slow.SetName("Slow");
234 slow.GetTargetingMode().TargetAllEnemies();
236 zircoHelmet.SetIkari(&slow);
237 guy.SetHelmet(&zircoHelmet);
239 powerRing.SetName("Power ring");
240 powerRing.SetMenuIcon(intp.GetSprite("ringIcon"));
242 trick.SetName("Trick");
244 trick.GetTargetingMode().TargetAllEnemies();
246 zircoHelmet.SetIkari(&trick);
247 guy.SetRing(&powerRing);
248 guy.SetJewel(intp.GetItem("evilJewelItem"));
250 // NOTE: this is actually Artea equipment
252 lizardBlow.SetName("Lizard blow");
253 lizardBlow.SetMenuIcon(intp.GetSprite("swordIcon"));
254 lizardBlow.GetTargetingMode().TargetSingleEnemy();
256 dragonRush.SetName("Dragon rush");
257 dragonRush.SetCost(164);
258 dragonRush.GetTargetingMode().TargetSingleEnemy();
259 dragonRush.SetPhysical();
260 lizardBlow.SetIkari(&dragonRush);
261 // dekar.SetWeapon(&lizardBlow);
263 holyRobe.SetName("Holy robe");
264 holyRobe.SetMenuIcon(intp.GetSprite("armorIcon"));
266 crisisCure.SetName("Crisis cure");
267 crisisCure.SetCost(164);
268 crisisCure.GetTargetingMode().TargetAllAllies();
269 crisisCure.SetMagical();
270 holyRobe.SetIkari(&crisisCure);
271 dekar.SetArmor(&holyRobe);
272 dekar.SetShield(intp.GetItem("zircoGlovesItem"));
273 dekar.SetHelmet(intp.GetItem("holyCapItem"));
275 rocketRing.SetName("Rocket ring");
276 rocketRing.SetMenuIcon(intp.GetSprite("ringIcon"));
278 fake.SetName("Fake");
280 fake.GetTargetingMode().TargetSingleAlly();
282 rocketRing.SetIkari(&fake);
283 dekar.SetRing(&rocketRing);
285 krakenRock.SetName("Kraken rock");
286 krakenRock.SetMenuIcon(intp.GetSprite("jewelIcon"));
288 tenLegger.SetName("Ten-legger");
289 tenLegger.SetCost(164);
290 tenLegger.GetTargetingMode().TargetAllEnemies();
291 tenLegger.SetPhysical();
292 rocketRing.SetIkari(&tenLegger);
293 dekar.SetJewel(&krakenRock);
295 battleRes.ikariMenuHeadline = "Please choose equipment.";
296 battleRes.noEquipmentText = "No equip";
297 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());
299 battleRes.escapeText = "Escapes.";
301 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &battleRes));
302 battleState->AddMonster(monster);
303 battleState->AddMonster(monster);
304 battleState->AddMonster(monster);
305 battleState->AddMonster(monster);
306 battleState->AddHero(maxim);
307 battleState->AddHero(selan);
308 battleState->AddHero(guy);
309 battleState->AddHero(dekar);
310 Application app(&screen, battleState);
311 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
312 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
313 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
314 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
315 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
316 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
317 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
318 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
319 app.Buttons().MapKey(SDLK_RETURN, Input::START);
320 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
321 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
322 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
326 } catch (Parser::Error &e) {
327 cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl;
329 } catch (exception &e) {
330 cerr << "exception in main(): " << e.what() << endl;