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 "common/Inventory.h"
16 #include "common/Item.h"
17 #include "common/Spell.h"
18 #include "geometry/Point.h"
19 #include "graphics/Font.h"
20 #include "graphics/Frame.h"
21 #include "graphics/Gauge.h"
22 #include "graphics/Menu.h"
23 #include "graphics/Sprite.h"
24 #include "sdl/InitImage.h"
25 #include "sdl/InitScreen.h"
26 #include "sdl/InitSDL.h"
31 #include <SDL_image.h>
33 using app::Application;
35 using battle::BattleState;
37 using battle::Monster;
38 using battle::PartyLayout;
39 using common::Inventory;
42 using geometry::Point;
44 using graphics::Frame;
45 using graphics::Gauge;
47 using graphics::Sprite;
49 using sdl::InitScreen;
57 int main(int argc, char **argv) {
58 const int width = 800;
59 const int height = 480;
63 InitImage image(IMG_INIT_PNG);
64 InitScreen screen(width, height);
66 // temporary test data
67 SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
68 PartyLayout monstersLayout;
69 monstersLayout.AddPosition(Point<Uint8>(88, 104));
70 monstersLayout.AddPosition(Point<Uint8>(128, 104));
71 monstersLayout.AddPosition(Point<Uint8>(168, 104));
72 monstersLayout.AddPosition(Point<Uint8>(208, 104));
73 PartyLayout heroesLayout;
74 heroesLayout.AddPosition(Point<Uint8>(27, 219));
75 heroesLayout.AddPosition(Point<Uint8>(104, 227));
76 heroesLayout.AddPosition(Point<Uint8>(66, 238));
77 heroesLayout.AddPosition(Point<Uint8>(143, 246));
79 SDL_Surface *monsterImg(IMG_Load("test-data/monster.png"));
80 Sprite dummySprite(monsterImg, 64, 64);
82 monster.SetSprite(&dummySprite);
83 monster.SetMaxHealth(10);
84 monster.SetHealth(10);
86 SDL_Surface *maximImg(IMG_Load("test-data/maxim.png"));
87 Sprite maximSprite(maximImg, 64, 64);
89 maxim.SetName("Maxim");
91 maxim.SetSprite(&maximSprite);
92 maxim.SetMaxHealth(33);
98 SDL_Surface *selanImg(IMG_Load("test-data/selan.png"));
99 Sprite selanSprite(selanImg, 64, 64);
101 selan.SetName("Selan");
103 selan.SetSprite(&selanSprite);
104 selan.SetMaxHealth(28);
106 selan.SetMaxMana(23);
110 SDL_Surface *guyImg(IMG_Load("test-data/guy.png"));
111 Sprite guySprite(guyImg, 64, 64);
115 guy.SetSprite(&guySprite);
116 guy.SetMaxHealth(38);
122 SDL_Surface *dekarImg(IMG_Load("test-data/dekar.png"));
123 Sprite dekarSprite(dekarImg, 64, 64);
125 dekar.SetName("Dekar");
127 dekar.SetSprite(&dekarSprite);
128 dekar.SetMaxHealth(38);
134 battle::Resources battleRes;
136 SDL_Surface *attackIconsImg(IMG_Load("test-data/attack-type-icons.png"));
137 Sprite attackIconsSprite(attackIconsImg, 32, 32);
138 battleRes.attackIcons = &attackIconsSprite;
139 SDL_Surface *attackChoiceIconsImg(IMG_Load("test-data/attack-choice-icons.png"));
140 Sprite attackChoiceIconsSprite(attackChoiceIconsImg, 16, 16);
141 battleRes.attackChoiceIcons = &attackChoiceIconsSprite;
142 SDL_Surface *moveIconsImg(IMG_Load("test-data/move-icons.png"));
143 Sprite moveIconsSprite(moveIconsImg, 32, 32);
144 battleRes.moveIcons = &moveIconsSprite;
145 SDL_Surface *heroTagImg(IMG_Load("test-data/hero-tag-sprites.png"));
146 Sprite heroTagSprite(heroTagImg, 32, 16);
147 battleRes.heroTagLabels = &heroTagSprite;
148 SDL_Surface *numbersImg(IMG_Load("test-data/numbers.png"));
149 Sprite numbersSprite(numbersImg, 16, 16);
150 Font heroTagFont(&numbersSprite);
151 battleRes.heroTagFont = &heroTagFont;
152 SDL_Surface *tagFramesImg(IMG_Load("test-data/tag-frames.png"));
153 Frame heroTagFrame(tagFramesImg, 16, 16, 1, 1, 0, 33);
154 battleRes.heroTagFrame = &heroTagFrame;
155 Frame activeHeroTagFrame(tagFramesImg, 16, 16);
156 battleRes.activeHeroTagFrame = &activeHeroTagFrame;
158 SDL_Surface *gauges(IMG_Load("test-data/gauges.png"));
159 Gauge healthGauge(gauges, 0, 16, 0, 0, 16, 6, 1, 6);
160 battleRes.healthGauge = &healthGauge;
161 Gauge manaGauge(gauges, 0, 32, 0, 0, 16, 6, 1, 6);
162 battleRes.manaGauge = &manaGauge;
163 Gauge ikariGauge(gauges, 0, 48, 0, 0, 16, 6, 1, 6);
164 battleRes.ikariGauge = &ikariGauge;
166 SDL_Surface *selectFrameImg(IMG_Load("test-data/select-frame.png"));
167 Frame selectFrame(selectFrameImg, 16, 16);
168 battleRes.selectFrame = &selectFrame;
170 SDL_Surface *normalFontImg(IMG_Load("test-data/normal-font.png"));
171 Sprite normalFontSprite(normalFontImg, 16, 16);
172 Font normalFont(&normalFontSprite);
173 normalFont.MapRange('A', 'M', 0, 1);
174 normalFont.MapRange('N', 'Z', 0, 2);
175 normalFont.MapRange('a', 'm', 0, 3);
176 normalFont.MapRange('n', 'z', 0, 4);
177 normalFont.MapChar(':', 10, 0);
178 normalFont.MapChar('!', 11, 0);
179 normalFont.MapChar('?', 12, 0);
180 // TODO: add '.' and '-' characters
181 battleRes.normalFont = &normalFont;
183 SDL_Surface *disabledFontImg(IMG_Load("test-data/disabled-font.png"));
184 Sprite disabledFontSprite(disabledFontImg, 16, 16);
185 Font disabledFont(&disabledFontSprite);
186 disabledFont.MapRange('A', 'M', 0, 1);
187 disabledFont.MapRange('N', 'Z', 0, 2);
188 disabledFont.MapRange('a', 'm', 0, 3);
189 disabledFont.MapRange('n', 'z', 0, 4);
190 disabledFont.MapChar(':', 10, 0);
191 disabledFont.MapChar('!', 11, 0);
192 disabledFont.MapChar('?', 12, 0);
193 // TODO: add '.' and '-' characters
194 battleRes.disabledFont = &disabledFont;
196 SDL_Surface *handCursorImg(IMG_Load("test-data/cursor-hand.png"));
197 Sprite handCursorSprite(handCursorImg, 32, 32);
198 battleRes.menuCursor = &handCursorSprite;
200 SDL_Surface *targetingIconsImg(IMG_Load("test-data/targeting-icons.png"));
201 Sprite weaponTargetCursor(targetingIconsImg, 32, 32);
202 Sprite magicTargetCursor(targetingIconsImg, 32, 32, 0, 32);
203 Sprite itemTargetCursor(targetingIconsImg, 32, 32, 0, 64);
204 battleRes.weaponTargetCursor = &weaponTargetCursor;
205 // TODO: add image for magic targeting cursor
206 battleRes.magicTargetCursor = &magicTargetCursor;
207 // TODO: add image for item targeting cursor
208 battleRes.itemTargetCursor = &itemTargetCursor;
211 resetSpell.SetName("Reset");
212 maxim.AddSpell(&resetSpell);
214 strongSpell.SetName("Strong");
215 strongSpell.SetCost(3);
216 strongSpell.SetUsableInBattle();
217 strongSpell.GetTargetingMode().TargetMultipleAllies();
218 maxim.AddSpell(&strongSpell);
219 selan.AddSpell(&strongSpell);
221 strongerSpell.SetName("Stronger");
222 strongerSpell.SetCost(8);
223 strongerSpell.SetUsableInBattle();
224 strongerSpell.GetTargetingMode().TargetMultipleAllies();
225 maxim.AddSpell(&strongerSpell);
226 selan.AddSpell(&strongerSpell);
228 championSpell.SetName("Champion");
229 championSpell.SetCost(16);
230 championSpell.SetUsableInBattle();
231 championSpell.GetTargetingMode().TargetMultipleAllies();
232 maxim.AddSpell(&championSpell);
233 selan.AddSpell(&championSpell);
235 rallySpell.SetName("Rally");
236 rallySpell.SetCost(10);
237 rallySpell.SetUsableInBattle();
238 rallySpell.GetTargetingMode().TargetMultipleAllies();
239 maxim.AddSpell(&rallySpell);
240 selan.AddSpell(&rallySpell);
242 escapeSpell.SetName("Escape");
243 escapeSpell.SetCost(8);
244 selan.AddSpell(&escapeSpell);
246 valorSpell.SetName("Valor");
247 valorSpell.SetCost(30);
248 valorSpell.SetUsableInBattle();
249 valorSpell.GetTargetingMode().TargetMultipleAllies();
250 maxim.AddSpell(&valorSpell);
251 selan.AddSpell(&valorSpell);
253 battleRes.spellMenuHeadline = "Please choose a spell.";
254 battleRes.spellMenuPrototype = Menu<const Spell *>(&normalFont, &disabledFont, &handCursorSprite, 9, 6, 8, 0, 2, 32, 2, ':');
256 SDL_Surface *itemIcons(IMG_Load("test-data/item-icons.png"));
257 Sprite potionIcon(itemIcons, 16, 16);
258 Sprite ballIcon(itemIcons, 16, 16, 0, 16);
259 Sprite crankIcon(itemIcons, 16, 16, 0, 32);
260 Sprite spearIcon(itemIcons, 16, 16, 0, 48);
261 Sprite swordIcon(itemIcons, 16, 16, 0, 64);
262 Sprite axIcon(itemIcons, 16, 16, 0, 80);
263 Sprite rodIcon(itemIcons, 16, 16, 0, 96);
264 Sprite armorIcon(itemIcons, 16, 16, 0, 112);
265 Sprite shieldIcon(itemIcons, 16, 16, 0, 128);
266 Sprite helmetIcon(itemIcons, 16, 16, 0, 144);
267 Sprite ringIcon(itemIcons, 16, 16, 0, 160);
268 Sprite jewelIcon(itemIcons, 16, 16, 0, 176);
272 antidote.SetName("Antidote");
273 antidote.SetMenuIcon(&potionIcon);
274 antidote.SetUsableInBattle();
275 antidote.GetTargetingMode().TargetSingleAlly();
276 inventory.Add(&antidote, 9);
278 magicJar.SetName("Magic jar");
279 magicJar.SetMenuIcon(&potionIcon);
280 magicJar.SetUsableInBattle();
281 magicJar.GetTargetingMode().TargetSingleAlly();
282 inventory.Add(&magicJar, 4);
284 hiPotion.SetName("Hi-Potion");
285 hiPotion.SetMenuIcon(&potionIcon);
286 hiPotion.SetUsableInBattle();
287 hiPotion.GetTargetingMode().TargetSingleAlly();
288 inventory.Add(&hiPotion, 4);
290 powerPotion.SetName("Power potion");
291 powerPotion.SetMenuIcon(&potionIcon);
292 inventory.Add(&powerPotion, 4);
294 escape.SetName("Escape");
295 inventory.Add(&escape, 2);
297 sleepBall.SetName("Sleep ball");
298 sleepBall.SetMenuIcon(&ballIcon);
299 sleepBall.SetUsableInBattle();
300 sleepBall.GetTargetingMode().TargetSingleEnemy();
301 inventory.Add(&sleepBall, 1);
303 multiBall.SetName("Multi-ball!");
304 multiBall.SetMenuIcon(&ballIcon);
305 multiBall.SetUsableInBattle();
306 multiBall.GetTargetingMode().TargetMultipleEnemies();
307 inventory.Add(&multiBall, 1);
309 figgoru.SetName("Figgoru");
310 figgoru.SetMenuIcon(&crankIcon);
311 figgoru.GetTargetingMode().TargetAllEnemies();
312 inventory.Add(&figgoru, 1);
313 battleRes.inventory = &inventory;
315 battleRes.itemMenuHeadline = "Please choose an item.";
316 battleRes.itemMenuPrototype = Menu<const common::Item *>(&normalFont, &disabledFont, &handCursorSprite, 15, 6, 8, 16, 1, 32, 2, ':');
319 zircoSword.SetName("Zirco sword");
320 zircoSword.SetMenuIcon(&swordIcon);
321 maxim.SetWeapon(&zircoSword);
323 zirconArmor.SetName("Zircon armor");
324 zirconArmor.SetMenuIcon(&armorIcon);
325 maxim.SetArmor(&zirconArmor);
327 holyShield.SetName("Holy shield");
328 holyShield.SetMenuIcon(&shieldIcon);
329 maxim.SetShield(&holyShield);
331 legendHelm.SetName("Legend helm");
332 legendHelm.SetMenuIcon(&helmetIcon);
333 maxim.SetHelmet(&legendHelm);
335 sProRing.SetName("S-pro ring");
336 sProRing.SetMenuIcon(&ringIcon);
337 maxim.SetRing(&sProRing);
339 evilJewel.SetName("Evil jewel");
340 evilJewel.SetMenuIcon(&jewelIcon);
341 maxim.SetJewel(&evilJewel);
344 zircoWhip.SetName("Zirco whip");
345 zircoWhip.SetMenuIcon(&rodIcon);
346 selan.SetWeapon(&zircoWhip);
348 zirconPlate.SetName("Zircon plate");
349 zirconPlate.SetMenuIcon(&armorIcon);
350 selan.SetArmor(&zirconPlate);
352 zircoGloves.SetName("Zirco gloves");
353 zircoGloves.SetMenuIcon(&shieldIcon);
354 selan.SetShield(&zircoGloves);
356 holyCap.SetName("Holy cap");
357 holyCap.SetMenuIcon(&helmetIcon);
358 selan.SetHelmet(&holyCap);
360 ghostRing.SetName("Ghost ring");
361 ghostRing.SetMenuIcon(&ringIcon);
362 selan.SetRing(&ghostRing);
364 eagleRock.SetName("Eagle rock");
365 eagleRock.SetMenuIcon(&jewelIcon);
366 selan.SetJewel(&eagleRock);
369 zircoAx.SetName("Zirco ax");
370 zircoAx.SetMenuIcon(&axIcon);
371 guy.SetWeapon(&zircoAx);
372 guy.SetArmor(&zirconArmor);
374 megaShield.SetName("Mega shield");
375 megaShield.SetMenuIcon(&shieldIcon);
376 guy.SetShield(&megaShield);
378 zircoHelmet.SetName("Zirco helmet");
379 zircoHelmet.SetMenuIcon(&helmetIcon);
380 guy.SetHelmet(&zircoHelmet);
382 powerRing.SetName("Power ring");
383 powerRing.SetMenuIcon(&ringIcon);
384 guy.SetRing(&powerRing);
385 guy.SetJewel(&evilJewel);
387 // NOTE: this is actually Artea equipment
389 lizardBlow.SetName("Lizard blow");
390 lizardBlow.SetMenuIcon(&swordIcon);
391 dekar.SetWeapon(&lizardBlow);
393 holyRobe.SetName("Holy robe");
394 holyRobe.SetMenuIcon(&armorIcon);
395 dekar.SetArmor(&holyRobe);
396 dekar.SetShield(&zircoGloves);
397 dekar.SetHelmet(&holyCap);
399 rocketRing.SetName("Rocket ring");
400 rocketRing.SetMenuIcon(&ringIcon);
401 dekar.SetRing(&rocketRing);
403 krakenRock.SetName("Kraken rock");
404 krakenRock.SetMenuIcon(&jewelIcon);
405 dekar.SetJewel(&krakenRock);
407 battleRes.ikariMenuHeadline = "Please choose equipment.";
408 battleRes.ikariMenuPrototype = Menu<const Item *>(&normalFont, &disabledFont, &handCursorSprite, 26, 6, 8, 16, 1, 32);
409 battleRes.ikariMenuPrototype.Add("Zirco whip Thundershriek", 0, false, &swordIcon);
410 battleRes.ikariMenuPrototype.Add("Zircon plate Sudden cure", 0, true, &armorIcon);
411 battleRes.ikariMenuPrototype.Add("Zirco gloves Forcefield", 0, true, &shieldIcon);
412 battleRes.ikariMenuPrototype.Add("Holy cap Vulnerable", 0, false, &helmetIcon);
413 battleRes.ikariMenuPrototype.Add("Ghost ring Destroy", 0, true, &ringIcon);
414 battleRes.ikariMenuPrototype.Add("Eagle rock Dive", 0, true, &jewelIcon);
416 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &battleRes));
417 battleState->AddMonster(monster);
418 battleState->AddMonster(monster);
419 battleState->AddMonster(monster);
420 battleState->AddMonster(monster);
421 battleState->AddHero(maxim);
422 battleState->AddHero(selan);
423 battleState->AddHero(guy);
424 battleState->AddHero(dekar);
425 Application app(&screen, battleState);
426 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
427 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
428 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
429 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
430 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
431 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
432 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
433 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
434 app.Buttons().MapKey(SDLK_RETURN, Input::START);
435 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
436 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
437 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
441 } catch (exception &e) {
442 cerr << "exception in main(): " << e.what() << endl;