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 // std::srand(std::time(0));
81 InitImage image(IMG_INIT_PNG);
84 Parser parser("test-data/test.l2s", source);
86 Interpreter intp(source);
89 InitScreen screen(width, height);
91 // temporary test data
92 SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
93 PartyLayout monstersLayout(*intp.GetPartyLayout("monstersLayout"));
94 PartyLayout heroesLayout(*intp.GetPartyLayout("heroesLayout"));
96 Monster monster(*intp.GetMonster("lizard"));
97 Hero maxim(*intp.GetHero("maxim"));
98 Hero selan(*intp.GetHero("selan"));
99 Hero guy(*intp.GetHero("guy"));
100 Hero dekar(*intp.GetHero("dekar"));
102 battle::Resources battleRes;
104 battleRes.swapCursor = intp.GetSprite("swapCursor");
105 battleRes.attackIcons = intp.GetSprite("attackIcons");
106 battleRes.attackChoiceIcons = intp.GetSprite("attackChoiceIcons");
107 battleRes.moveIcons = intp.GetSprite("moveIcons");
108 battleRes.titleFrame = intp.GetFrame("titleFrame");
109 battleRes.titleFont = intp.GetFont("largeFont");
110 battleRes.numberAnimationPrototype = intp.GetAnimation("numberAnimationPrototype");
111 battleRes.bigNumberSprite = intp.GetSprite("bigNumbers");
112 battleRes.greenNumberSprite = intp.GetSprite("bigGreenNumbers");
114 battleRes.heroTagLabels = intp.GetSprite("heroTagLabels");
115 battleRes.levelLabelCol = 0;
116 battleRes.levelLabelRow = 0;
117 battleRes.healthLabelCol = 0;
118 battleRes.healthLabelRow = 1;
119 battleRes.manaLabelCol = 0;
120 battleRes.manaLabelRow = 2;
121 battleRes.moveLabelCol = 0;
122 battleRes.moveLabelRow = 3;
123 battleRes.ikariLabelCol = 0;
124 battleRes.ikariLabelRow = 4;
126 battleRes.heroTagFont = intp.GetFont("heroTagFont");
127 battleRes.heroTagFrame = intp.GetFrame("heroTagFrame");
128 battleRes.activeHeroTagFrame = intp.GetFrame("activeHeroTagFrame");
129 battleRes.smallHeroTagFrame = intp.GetFrame("smallHeroTagFrame");
130 battleRes.lastSmallHeroTagFrame = intp.GetFrame("lastSmallHeroTagFrame");
131 battleRes.heroesBgColor = intp.GetColor("heroesBgColor");
133 battleRes.healthGauge = intp.GetGauge("healthGauge");
134 battleRes.manaGauge = intp.GetGauge("manaGauge");
135 battleRes.ikariGauge = intp.GetGauge("ikariGauge");
137 battleRes.selectFrame = intp.GetFrame("selectFrame");
138 battleRes.normalFont = intp.GetFont("normalFont");
139 battleRes.disabledFont = intp.GetFont("disabledFont");
140 battleRes.menuCursor = intp.GetSprite("handCursor");
142 battleRes.weaponTargetCursor = intp.GetSprite("weaponTargetCursor");
143 battleRes.magicTargetCursor = intp.GetSprite("magicTargetCursor");
144 battleRes.itemTargetCursor = intp.GetSprite("itemTargetCursor");
146 maxim.AddSpell(intp.GetSpell("resetSpell"));
147 Spell *strongSpell(intp.GetSpell("strongSpell"));
148 maxim.AddSpell(strongSpell);
149 selan.AddSpell(strongSpell);
150 Spell *strongerSpell(intp.GetSpell("strongerSpell"));
151 maxim.AddSpell(strongerSpell);
152 selan.AddSpell(strongerSpell);
153 Spell *championSpell(intp.GetSpell("championSpell"));
154 maxim.AddSpell(championSpell);
155 selan.AddSpell(championSpell);
156 Spell *rallySpell(intp.GetSpell("rallySpell"));
157 maxim.AddSpell(rallySpell);
158 selan.AddSpell(rallySpell);
159 selan.AddSpell(intp.GetSpell("escapeSpell"));
160 Spell *valorSpell(intp.GetSpell("valorSpell"));
161 maxim.AddSpell(valorSpell);
162 selan.AddSpell(valorSpell);
164 battleRes.spellMenuHeadline = intp.GetString("spellMenuHeadline");
165 battleRes.spellMenuProperties = intp.GetMenuProperties("spellMenuPrototype");
167 battleRes.weaponMenuIcon = intp.GetSprite("swordIcon");
168 battleRes.armorMenuIcon = intp.GetSprite("armorIcon");
169 battleRes.shieldMenuIcon = intp.GetSprite("shieldIcon");
170 battleRes.helmetMenuIcon = intp.GetSprite("helmetIcon");
171 battleRes.ringMenuIcon = intp.GetSprite("ringIcon");
172 battleRes.jewelMenuIcon = intp.GetSprite("jewelIcon");
175 inventory.Add(intp.GetItem("antidoteItem"), 9);
176 inventory.Add(intp.GetItem("magicJarItem"), 4);
177 inventory.Add(intp.GetItem("hiPotionItem"), 4);
178 inventory.Add(intp.GetItem("powerPotionItem"), 4);
179 inventory.Add(intp.GetItem("escapeItem"), 2);
180 inventory.Add(intp.GetItem("sleepBallItem"), 1);
181 battleRes.inventory = &inventory;
183 battleRes.itemMenuHeadline = intp.GetString("itemMenuHeadline");
184 battleRes.itemMenuProperties = intp.GetMenuProperties("itemMenuPrototype");
186 maxim.SetWeapon(intp.GetItem("zircoSwordItem"));
187 maxim.SetArmor(intp.GetItem("zirconArmorItem"));
188 maxim.SetShield(intp.GetItem("holyShieldItem"));
189 maxim.SetHelmet(intp.GetItem("legendHelmItem"));
190 maxim.SetRing(intp.GetItem("sProRingItem"));
191 maxim.SetJewel(intp.GetItem("evilJewelItem"));
193 // selan.SetWeapon(intp.GetItem("zircoWhipItem"));
194 selan.SetArmor(intp.GetItem("zirconPlateItem"));
195 selan.SetShield(intp.GetItem("zircoGlovesItem"));
196 selan.SetHelmet(intp.GetItem("holyCapItem"));
197 selan.SetRing(intp.GetItem("ghostRingItem"));
198 selan.SetJewel(intp.GetItem("eagleRockItem"));
200 // guy.SetWeapon(intp.GetItem("zircoAxItem"));
201 guy.SetArmor(intp.GetItem("zirconArmorItem"));
202 guy.SetShield(intp.GetItem("megaShieldItem"));
203 guy.SetHelmet(intp.GetItem("zircoHelmetItem"));
204 guy.SetRing(intp.GetItem("powerRingItem"));
205 guy.SetJewel(intp.GetItem("evilJewelItem"));
207 // NOTE: this is actually Artea equipment
208 // dekar.SetWeapon(intp.GetItem("lizardBlowItem"));
209 dekar.SetArmor(intp.GetItem("holyRobeItem"));
210 dekar.SetShield(intp.GetItem("zircoGlovesItem"));
211 dekar.SetHelmet(intp.GetItem("holyCapItem"));
212 dekar.SetRing(intp.GetItem("rocketRingItem"));
213 dekar.SetJewel(intp.GetItem("krakenRockItem"));
215 battleRes.ikariMenuHeadline = intp.GetString("ikariMenuHeadline");
216 battleRes.noEquipmentText = intp.GetString("noEquipmentText");
217 battleRes.ikariMenuProperties = intp.GetMenuProperties("ikariMenuPrototype");
218 battleRes.escapeText = intp.GetString("escapeText");
220 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &battleRes));
221 battleState->AddMonster(monster);
222 battleState->AddMonster(monster);
223 battleState->AddMonster(monster);
224 battleState->AddMonster(monster);
225 battleState->AddHero(maxim);
226 battleState->AddHero(selan);
227 battleState->AddHero(guy);
228 battleState->AddHero(dekar);
229 Application app(&screen, battleState);
230 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
231 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
232 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
233 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
234 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
235 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
236 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
237 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
238 app.Buttons().MapKey(SDLK_RETURN, Input::START);
239 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
240 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
241 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
245 } catch (Parser::Error &e) {
246 cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl;
248 } catch (exception &e) {
249 cerr << "exception in main(): " << e.what() << endl;