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"));
206 // guy.SetWeapon(intp.GetItem("zircoAxItem"));
207 guy.SetArmor(intp.GetItem("zirconArmorItem"));
208 guy.SetShield(intp.GetItem("megaShieldItem"));
209 guy.SetHelmet(intp.GetItem("zircoHelmetItem"));
210 guy.SetRing(intp.GetItem("powerRingItem"));
211 guy.SetJewel(intp.GetItem("evilJewelItem"));
213 // NOTE: this is actually Artea equipment
215 lizardBlow.SetName("Lizard blow");
216 lizardBlow.SetMenuIcon(intp.GetSprite("swordIcon"));
217 lizardBlow.GetTargetingMode().TargetSingleEnemy();
219 dragonRush.SetName("Dragon rush");
220 dragonRush.SetCost(164);
221 dragonRush.GetTargetingMode().TargetSingleEnemy();
222 dragonRush.SetPhysical();
223 lizardBlow.SetIkari(&dragonRush);
224 // dekar.SetWeapon(&lizardBlow);
226 holyRobe.SetName("Holy robe");
227 holyRobe.SetMenuIcon(intp.GetSprite("armorIcon"));
229 crisisCure.SetName("Crisis cure");
230 crisisCure.SetCost(164);
231 crisisCure.GetTargetingMode().TargetAllAllies();
232 crisisCure.SetMagical();
233 holyRobe.SetIkari(&crisisCure);
234 dekar.SetArmor(&holyRobe);
235 dekar.SetShield(intp.GetItem("zircoGlovesItem"));
236 dekar.SetHelmet(intp.GetItem("holyCapItem"));
238 rocketRing.SetName("Rocket ring");
239 rocketRing.SetMenuIcon(intp.GetSprite("ringIcon"));
241 fake.SetName("Fake");
243 fake.GetTargetingMode().TargetSingleAlly();
245 rocketRing.SetIkari(&fake);
246 dekar.SetRing(&rocketRing);
248 krakenRock.SetName("Kraken rock");
249 krakenRock.SetMenuIcon(intp.GetSprite("jewelIcon"));
251 tenLegger.SetName("Ten-legger");
252 tenLegger.SetCost(164);
253 tenLegger.GetTargetingMode().TargetAllEnemies();
254 tenLegger.SetPhysical();
255 rocketRing.SetIkari(&tenLegger);
256 dekar.SetJewel(&krakenRock);
258 battleRes.ikariMenuHeadline = "Please choose equipment.";
259 battleRes.noEquipmentText = "No equip";
260 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());
262 battleRes.escapeText = "Escapes.";
264 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &battleRes));
265 battleState->AddMonster(monster);
266 battleState->AddMonster(monster);
267 battleState->AddMonster(monster);
268 battleState->AddMonster(monster);
269 battleState->AddHero(maxim);
270 battleState->AddHero(selan);
271 battleState->AddHero(guy);
272 battleState->AddHero(dekar);
273 Application app(&screen, battleState);
274 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
275 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
276 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
277 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
278 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
279 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
280 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
281 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
282 app.Buttons().MapKey(SDLK_RETURN, Input::START);
283 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
284 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
285 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
289 } catch (Parser::Error &e) {
290 cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl;
292 } catch (exception &e) {
293 cerr << "exception in main(): " << e.what() << endl;