]> git.localhorst.tv Git - l2e.git/blob - src/main.cpp
987a985cc74083e76a29953a357b490ea12947fe
[l2e.git] / src / main.cpp
1 /*
2  * main.cpp
3  *
4  *  Created on: Aug 1, 2012
5  *      Author: holy
6  */
7
8 #include "app/Application.h"
9 #include "app/Input.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/Point.h"
21 #include "geometry/Vector.h"
22 #include "graphics/ComplexAnimation.h"
23 #include "graphics/Font.h"
24 #include "graphics/Frame.h"
25 #include "graphics/Gauge.h"
26 #include "graphics/Menu.h"
27 #include "graphics/SimpleAnimation.h"
28 #include "graphics/Sprite.h"
29 #include "sdl/InitImage.h"
30 #include "sdl/InitScreen.h"
31 #include "sdl/InitSDL.h"
32
33 #include <exception>
34 #include <iostream>
35 #include <SDL.h>
36 #include <SDL_image.h>
37
38 using app::Application;
39 using app::Input;
40 using battle::BattleState;
41 using battle::Hero;
42 using battle::Monster;
43 using battle::PartyLayout;
44 using battle::Stats;
45 using common::Ikari;
46 using common::Inventory;
47 using common::Item;
48 using common::Spell;
49 using geometry::Point;
50 using geometry::Vector;
51 using graphics::ComplexAnimation;
52 using graphics::Font;
53 using graphics::Frame;
54 using graphics::Gauge;
55 using graphics::Menu;
56 using graphics::SimpleAnimation;
57 using graphics::Sprite;
58 using sdl::InitImage;
59 using sdl::InitScreen;
60 using sdl::InitSDL;
61
62 using std::cerr;
63 using std::cout;
64 using std::endl;
65 using std::exception;
66
67 int main(int argc, char **argv) {
68         const int width = 800;
69         const int height = 480;
70
71         const int framerate = 33;
72
73         try {
74                 InitSDL sdl;
75                 InitImage image(IMG_INIT_PNG);
76                 InitScreen screen(width, height);
77
78                 // temporary test data
79                 SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
80                 PartyLayout monstersLayout;
81                 monstersLayout.AddPosition(Point<Uint8>(88, 88));
82                 monstersLayout.AddPosition(Point<Uint8>(128, 88));
83                 monstersLayout.AddPosition(Point<Uint8>(168, 88));
84                 monstersLayout.AddPosition(Point<Uint8>(208, 88));
85                 PartyLayout heroesLayout;
86                 heroesLayout.AddPosition(Point<Uint8>(48, 136));
87                 heroesLayout.AddPosition(Point<Uint8>(128, 136));
88                 heroesLayout.AddPosition(Point<Uint8>(80, 152));
89                 heroesLayout.AddPosition(Point<Uint8>(160, 152));
90
91                 SDL_Surface *monsterImg(IMG_Load("test-data/monster.png"));
92                 Sprite dummySprite(monsterImg, 64, 64);
93                 Monster monster;
94                 monster.SetName("Lizard");
95                 monster.SetSprite(&dummySprite);
96                 monster.SetLevel(1);
97                 monster.SetMaxHealth(8);
98                 monster.SetHealth(8);
99                 monster.SetStats(Stats(14, 6, 6, 6, 6, 6, 6));
100                 monster.SetReward(3, 5);
101
102                 SDL_Surface *maximImg(IMG_Load("test-data/maxim.png"));
103                 Sprite maximSprite(maximImg, 64, 64);
104                 Hero maxim;
105                 maxim.SetName("Maxim");
106                 maxim.SetLevel(1);
107                 maxim.SetSprite(&maximSprite);
108                 maxim.SetMaxHealth(33);
109                 maxim.SetHealth(33);
110                 maxim.SetMaxMana(20);
111                 maxim.SetMana(20);
112                 maxim.SetIP(0);
113                 maxim.SetStats(Stats(28, 22, 28, 17, 14, 100, 10));
114                 ComplexAnimation maximAttackAnimation(&maximSprite, framerate);
115                 // TODO: cross check double frames; could be related to differences in framerates
116                 maximAttackAnimation.AddFrames(1, 0, Vector<int>(0,  0), 7); // TODO: maybe this could also be a pause before the battle animation
117                 maximAttackAnimation.AddFrames(1, 0, Vector<int>(4, -1), 2);
118                 maximAttackAnimation.AddFrames(2, 0, Vector<int>(4, -2), 2);
119                 maximAttackAnimation.AddFrames(2, 0, Vector<int>(6, -2), 2);
120                 maximAttackAnimation.AddFrames(2, 1, Vector<int>(6, -1), 1);
121                 maximAttackAnimation.AddFrames(2, 1, Vector<int>(3, -1), 2);
122                 maximAttackAnimation.AddFrames(2, 1, Vector<int>(0,  0), 1);
123                 maximAttackAnimation.AddFrames(2, 2, Vector<int>(0,  0), 2);
124                 maximAttackAnimation.AddFrames(2, 2, Vector<int>(2,  0), 1);
125                 maximAttackAnimation.AddFrames(1, 0, Vector<int>(0,  0), 7); // TODO: maybe this could also be a pause between two animations
126                 maxim.SetAttackAnimation(&maximAttackAnimation);
127                 ComplexAnimation maximSpellAnimation(&maximSprite, 5 * framerate);
128                 maximSpellAnimation.AddFrames(3, 0, Vector<int>(), 2);
129                 maximSpellAnimation.AddFrame(3, 1);
130                 maxim.SetSpellAnimation(&maximSpellAnimation);
131                 SDL_Surface *maximMeleeImg(IMG_Load("test-data/melee-maxim.png"));
132                 Sprite maximMeleeSprite(maximMeleeImg, 96, 96);
133                 SimpleAnimation maximMeleeAnimation(&maximMeleeSprite, 2 * framerate, 4);
134                 maxim.SetMeleeAnimation(&maximMeleeAnimation);
135
136                 SDL_Surface *selanImg(IMG_Load("test-data/selan.png"));
137                 Sprite selanSprite(selanImg, 64, 64);
138                 Hero selan;
139                 selan.SetName("Selan");
140                 selan.SetLevel(1);
141                 selan.SetSprite(&selanSprite);
142                 selan.SetMaxHealth(28);
143                 selan.SetHealth(28);
144                 selan.SetMaxMana(23);
145                 selan.SetMana(23);
146                 selan.SetIP(0);
147                 selan.SetStats(Stats(23, 21, 23, 19, 22, 80, 13));
148                 ComplexAnimation selanAttackAnimation(&selanSprite, framerate);
149                 selanAttackAnimation.AddFrames(1, 0, Vector<int>(4, 0), 2);
150                 selanAttackAnimation.AddFrame(1, 0, Vector<int>(8, 2));
151                 selanAttackAnimation.AddFrame(2, 0, Vector<int>(10, 4));
152                 selanAttackAnimation.AddFrame(2, 0, Vector<int>(14, 4));
153                 selanAttackAnimation.AddFrames(2, 0, Vector<int>(12, 2), 3);
154                 selanAttackAnimation.AddFrames(2, 1, Vector<int>(14, 2), 2);
155                 selanAttackAnimation.AddFrame(2, 1, Vector<int>(2, 0));
156                 selanAttackAnimation.AddFrame(2, 2, Vector<int>(-2, -4));
157                 selanAttackAnimation.AddFrame(2, 2, Vector<int>(-8, -8));
158                 selanAttackAnimation.AddFrame(2, 2);
159                 selan.SetAttackAnimation(&selanAttackAnimation);
160                 ComplexAnimation selanSpellAnimation(&selanSprite, framerate);
161                 selanSpellAnimation.AddFrames(2, 0, Vector<int>(), 3);
162                 selanSpellAnimation.AddFrames(2, 1, Vector<int>(), 2);
163                 selanSpellAnimation.AddFrames(2, 2, Vector<int>(), 3);
164                 selanSpellAnimation.AddFrames(2, 3, Vector<int>(), 2);
165                 selan.SetSpellAnimation(&selanSpellAnimation);
166                 SDL_Surface *selanMeleeImg(IMG_Load("test-data/melee-selan.png"));
167                 Sprite selanMeleeSprite(selanMeleeImg, 96, 96);
168                 SimpleAnimation selanMeleeAnimation(&selanMeleeSprite, 2 * framerate, 4);
169                 selan.SetMeleeAnimation(&selanMeleeAnimation);
170
171                 SDL_Surface *guyImg(IMG_Load("test-data/guy.png"));
172                 Sprite guySprite(guyImg, 64, 64);
173                 Hero guy;
174                 guy.SetName("Guy");
175                 guy.SetLevel(1);
176                 guy.SetSprite(&guySprite);
177                 guy.SetMaxHealth(38);
178                 guy.SetHealth(38);
179                 guy.SetMaxMana(0);
180                 guy.SetMana(0);
181                 guy.SetIP(0);
182                 guy.SetStats(Stats(38, 25, 38, 13, 8, 90, 8));
183                 ComplexAnimation guyAttackAnimation(&guySprite, framerate);
184                 guyAttackAnimation.AddFrames(1, 0, Vector<int>(-4, 0), 2);
185                 guyAttackAnimation.AddFrames(1, 0, Vector<int>(-8, 0), 2);
186                 guyAttackAnimation.AddFrames(2, 0, Vector<int>(-8, 0), 2);
187                 guyAttackAnimation.AddFrame(2, 0, Vector<int>(-4, 0));
188                 guyAttackAnimation.AddFrames(2, 0, Vector<int>(), 2);
189                 guyAttackAnimation.AddFrame(2, 1);
190                 guyAttackAnimation.AddFrame(2, 1, Vector<int>(4, 0));
191                 guyAttackAnimation.AddFrame(2, 1, Vector<int>(10, 0));
192                 guyAttackAnimation.AddFrame(2, 2, Vector<int>(10, 0));
193                 guyAttackAnimation.AddFrame(2, 2);
194                 guy.SetAttackAnimation(&guyAttackAnimation);
195                 SDL_Surface *guyMeleeImg(IMG_Load("test-data/melee-guy.png"));
196                 Sprite guyMeleeSprite(guyMeleeImg, 96, 96);
197                 SimpleAnimation guyMeleeAnimation(&guyMeleeSprite, 2 * framerate, 4);
198                 guy.SetMeleeAnimation(&guyMeleeAnimation);
199
200                 SDL_Surface *dekarImg(IMG_Load("test-data/dekar.png"));
201                 Sprite dekarSprite(dekarImg, 64, 64);
202                 Hero dekar;
203                 dekar.SetName("Dekar");
204                 dekar.SetLevel(1);
205                 dekar.SetSprite(&dekarSprite);
206                 dekar.SetMaxHealth(38);
207                 dekar.SetHealth(38);
208                 dekar.SetMaxMana(0);
209                 dekar.SetMana(0);
210                 dekar.SetIP(0);
211                 dekar.SetStats(Stats(46, 29, 46, 13, 7, 100, 5));
212                 ComplexAnimation dekarAttackAnimation(&dekarSprite, framerate);
213                 dekarAttackAnimation.AddFrame(1, 0, Vector<int>(4, 0));
214                 dekarAttackAnimation.AddFrame(1, 0, Vector<int>(8, 2));
215                 dekarAttackAnimation.AddFrame(2, 0, Vector<int>(12, 4));
216                 dekarAttackAnimation.AddFrame(2, 0, Vector<int>(16, 4));
217                 dekarAttackAnimation.AddFrames(2, 0, Vector<int>(10, 2), 4);
218                 dekarAttackAnimation.AddFrame(2, 1, Vector<int>(6, 2));
219                 dekarAttackAnimation.AddFrame(2, 1, Vector<int>());
220                 dekarAttackAnimation.AddFrame(2, 2, Vector<int>(-2, 0));
221                 dekarAttackAnimation.AddFrames(2, 2, Vector<int>(0, 0), 3);
222                 dekar.SetAttackAnimation(&dekarAttackAnimation);
223                 ComplexAnimation dekarSpellAnimation(&dekarSprite, framerate);
224                 dekarSpellAnimation.AddFrames(2, 0, Vector<int>(), 6);
225                 dekarSpellAnimation.AddFrames(2, 1, Vector<int>(), 2);
226                 dekarSpellAnimation.AddFrames(2, 2, Vector<int>(), 3);
227                 dekar.SetSpellAnimation(&dekarSpellAnimation);
228                 SDL_Surface *dekarMeleeImg(IMG_Load("test-data/melee-dekar.png"));
229                 Sprite dekarMeleeSprite(dekarMeleeImg, 96, 96);
230                 SimpleAnimation dekarMeleeAnimation(&dekarMeleeSprite, 2 * framerate, 4);
231                 dekar.SetMeleeAnimation(&dekarMeleeAnimation);
232
233                 battle::Resources battleRes;
234
235                 SDL_Surface *swapCursorImg(IMG_Load("test-data/swap-cursor.png"));
236                 Sprite swapCursorSprite(swapCursorImg, 32, 32);
237                 battleRes.swapCursor = &swapCursorSprite;
238                 SDL_Surface *attackIconsImg(IMG_Load("test-data/attack-type-icons.png"));
239                 Sprite attackIconsSprite(attackIconsImg, 32, 32);
240                 battleRes.attackIcons = &attackIconsSprite;
241                 SDL_Surface *attackChoiceIconsImg(IMG_Load("test-data/attack-choice-icons.png"));
242                 Sprite attackChoiceIconsSprite(attackChoiceIconsImg, 16, 16);
243                 battleRes.attackChoiceIcons = &attackChoiceIconsSprite;
244                 SDL_Surface *moveIconsImg(IMG_Load("test-data/move-icons.png"));
245                 Sprite moveIconsSprite(moveIconsImg, 32, 32);
246                 battleRes.moveIcons = &moveIconsSprite;
247
248                 SDL_Surface *titleFrameImg(IMG_Load("test-data/title-frame.png"));
249                 Frame titleFrame(titleFrameImg, 16, 16);
250                 battleRes.titleFrame = &titleFrame;
251
252                 SDL_Surface *largeFontImg(IMG_Load("test-data/large-font.png"));
253                 Sprite largeFontSprite(largeFontImg, 16, 32);
254                 Font largeFont(&largeFontSprite, 0, -2);
255                 battleRes.titleFont = &largeFont;
256
257                 battleRes.numberAnimationPrototype = ComplexAnimation(0, framerate);
258                 battleRes.numberAnimationPrototype.AddFrame(0, 0);
259                 battleRes.numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -26));
260                 battleRes.numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -42));
261                 battleRes.numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -48));
262                 battleRes.numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -42));
263                 battleRes.numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -26));
264                 battleRes.numberAnimationPrototype.AddFrame(0, 0);
265                 battleRes.numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -12));
266                 battleRes.numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -20));
267                 battleRes.numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -24));
268                 battleRes.numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -20));
269                 battleRes.numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -12));
270                 battleRes.numberAnimationPrototype.AddFrame(0, 0);
271                 battleRes.numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -6));
272                 battleRes.numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -10));
273                 battleRes.numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -12));
274                 battleRes.numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -10));
275                 battleRes.numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -6));
276                 battleRes.numberAnimationPrototype.AddFrames(0, 0, Vector<int>(), 14);
277                 battleRes.numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -36));
278                 battleRes.numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -32));
279                 battleRes.numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -18));
280
281                 SDL_Surface *bigNumbersImg(IMG_Load("test-data/big-numbers.png"));
282                 Sprite bigNumbersSprite(bigNumbersImg, 16, 32);
283                 battleRes.bigNumberSprite = &bigNumbersSprite;
284                 SDL_Surface *bigGreenNumbersImg(IMG_Load("test-data/big-green-numbers.png"));
285                 Sprite bigGreenNumbersSprite(bigGreenNumbersImg, 16, 32);
286                 battleRes.greenNumberSprite = &bigGreenNumbersSprite;
287
288                 SDL_Surface *heroTagImg(IMG_Load("test-data/hero-tag-sprites.png"));
289                 Sprite heroTagSprite(heroTagImg, 32, 16);
290                 battleRes.heroTagLabels = &heroTagSprite;
291                 battleRes.levelLabelCol = 0;
292                 battleRes.levelLabelRow = 0;
293                 battleRes.healthLabelCol = 0;
294                 battleRes.healthLabelRow = 1;
295                 battleRes.manaLabelCol = 0;
296                 battleRes.manaLabelRow = 2;
297                 battleRes.moveLabelCol = 0;
298                 battleRes.moveLabelRow = 3;
299                 battleRes.ikariLabelCol = 0;
300                 battleRes.ikariLabelRow = 4;
301
302                 SDL_Surface *numbersImg(IMG_Load("test-data/numbers.png"));
303                 Sprite numbersSprite(numbersImg, 16, 16);
304                 Font heroTagFont(&numbersSprite, 0, -3);
305                 battleRes.heroTagFont = &heroTagFont;
306                 SDL_Surface *tagFramesImg(IMG_Load("test-data/tag-frames.png"));
307                 Frame heroTagFrame(tagFramesImg, 16, 16, 1, 1, 0, 33);
308                 battleRes.heroTagFrame = &heroTagFrame;
309                 Frame activeHeroTagFrame(tagFramesImg, 16, 16);
310                 battleRes.activeHeroTagFrame = &activeHeroTagFrame;
311                 SDL_Surface *smallTagFrameImg(IMG_Load("test-data/small-tag-frame.png"));
312                 Frame smallTagFrame(smallTagFrameImg, 8, 16);
313                 battleRes.smallHeroTagFrame = &smallTagFrame;
314                 Frame lastSmallTagFrame(smallTagFrameImg, 8, 16, 1, 1, 0, 33);
315                 battleRes.lastSmallHeroTagFrame = &lastSmallTagFrame;
316                 battleRes.heroesBgColor = SDL_MapRGB(screen.Screen()->format, 0x18, 0x28, 0x31);
317
318                 SDL_Surface *gauges(IMG_Load("test-data/gauges.png"));
319                 Gauge healthGauge(gauges, 0, 16, 0, 0, 16, 6, 1, 6);
320                 battleRes.healthGauge = &healthGauge;
321                 Gauge manaGauge(gauges, 0, 32, 0, 0, 16, 6, 1, 6);
322                 battleRes.manaGauge = &manaGauge;
323                 Gauge ikariGauge(gauges, 0, 48, 0, 0, 16, 6, 1, 6);
324                 battleRes.ikariGauge = &ikariGauge;
325
326                 SDL_Surface *selectFrameImg(IMG_Load("test-data/select-frame.png"));
327                 Frame selectFrame(selectFrameImg, 16, 16);
328                 battleRes.selectFrame = &selectFrame;
329
330                 SDL_Surface *normalFontImg(IMG_Load("test-data/normal-font.png"));
331                 Sprite normalFontSprite(normalFontImg, 16, 16);
332                 Font normalFont(&normalFontSprite, 0, -2);
333                 battleRes.normalFont = &normalFont;
334
335                 SDL_Surface *disabledFontImg(IMG_Load("test-data/disabled-font.png"));
336                 Sprite disabledFontSprite(disabledFontImg, 16, 16);
337                 Font disabledFont(&disabledFontSprite, 0, -2);
338                 battleRes.disabledFont = &disabledFont;
339
340                 SDL_Surface *handCursorImg(IMG_Load("test-data/cursor-hand.png"));
341                 Sprite handCursorSprite(handCursorImg, 32, 32);
342                 battleRes.menuCursor = &handCursorSprite;
343
344                 SDL_Surface *targetingIconsImg(IMG_Load("test-data/targeting-icons.png"));
345                 Sprite weaponTargetCursor(targetingIconsImg, 32, 32);
346                 Sprite magicTargetCursor(targetingIconsImg, 32, 32, 0, 32);
347                 Sprite itemTargetCursor(targetingIconsImg, 32, 32, 0, 64);
348                 battleRes.weaponTargetCursor = &weaponTargetCursor;
349                 // TODO: add image for magic targeting cursor
350                 battleRes.magicTargetCursor = &magicTargetCursor;
351                 // TODO: add image for item targeting cursor
352                 battleRes.itemTargetCursor = &itemTargetCursor;
353
354                 Spell resetSpell;
355                 resetSpell.SetName("Reset");
356                 maxim.AddSpell(&resetSpell);
357                 Spell strongSpell;
358                 strongSpell.SetName("Strong");
359                 strongSpell.SetCost(3);
360                 strongSpell.SetUsableInBattle();
361                 strongSpell.GetTargetingMode().TargetMultipleAllies();
362                 maxim.AddSpell(&strongSpell);
363                 selan.AddSpell(&strongSpell);
364                 Spell strongerSpell;
365                 strongerSpell.SetName("Stronger");
366                 strongerSpell.SetCost(8);
367                 strongerSpell.SetUsableInBattle();
368                 strongerSpell.GetTargetingMode().TargetMultipleAllies();
369                 maxim.AddSpell(&strongerSpell);
370                 selan.AddSpell(&strongerSpell);
371                 Spell championSpell;
372                 championSpell.SetName("Champion");
373                 championSpell.SetCost(16);
374                 championSpell.SetUsableInBattle();
375                 championSpell.GetTargetingMode().TargetMultipleAllies();
376                 maxim.AddSpell(&championSpell);
377                 selan.AddSpell(&championSpell);
378                 Spell rallySpell;
379                 rallySpell.SetName("Rally");
380                 rallySpell.SetCost(10);
381                 rallySpell.SetUsableInBattle();
382                 rallySpell.GetTargetingMode().TargetMultipleAllies();
383                 maxim.AddSpell(&rallySpell);
384                 selan.AddSpell(&rallySpell);
385                 Spell escapeSpell;
386                 escapeSpell.SetName("Escape");
387                 escapeSpell.SetCost(8);
388                 selan.AddSpell(&escapeSpell);
389                 Spell valorSpell;
390                 valorSpell.SetName("Valor");
391                 valorSpell.SetCost(30);
392                 valorSpell.SetUsableInBattle();
393                 valorSpell.GetTargetingMode().TargetMultipleAllies();
394                 maxim.AddSpell(&valorSpell);
395                 selan.AddSpell(&valorSpell);
396
397                 battleRes.spellMenuHeadline = "Please choose a spell.";
398                 battleRes.spellMenuPrototype = Menu<const Spell *>(&normalFont, &disabledFont, &handCursorSprite, 9, 6, 8, 0, 2, 32, 2, ':');
399
400                 SDL_Surface *itemIcons(IMG_Load("test-data/item-icons.png"));
401                 Sprite potionIcon(itemIcons, 16, 16);
402                 Sprite ballIcon(itemIcons, 16, 16, 0, 16);
403                 Sprite crankIcon(itemIcons, 16, 16, 0, 32);
404                 Sprite spearIcon(itemIcons, 16, 16, 0, 48);
405                 Sprite swordIcon(itemIcons, 16, 16, 0, 64);
406                 Sprite axIcon(itemIcons, 16, 16, 0, 80);
407                 Sprite rodIcon(itemIcons, 16, 16, 0, 96);
408                 Sprite armorIcon(itemIcons, 16, 16, 0, 112);
409                 Sprite shieldIcon(itemIcons, 16, 16, 0, 128);
410                 Sprite helmetIcon(itemIcons, 16, 16, 0, 144);
411                 Sprite ringIcon(itemIcons, 16, 16, 0, 160);
412                 Sprite jewelIcon(itemIcons, 16, 16, 0, 176);
413
414                 battleRes.weaponMenuIcon = &swordIcon;
415                 battleRes.armorMenuIcon = &armorIcon;
416                 battleRes.shieldMenuIcon = &shieldIcon;
417                 battleRes.helmetMenuIcon = &helmetIcon;
418                 battleRes.ringMenuIcon = &ringIcon;
419                 battleRes.jewelMenuIcon = &jewelIcon;
420
421                 Inventory inventory;
422                 Item antidote;
423                 antidote.SetName("Antidote");
424                 antidote.SetMenuIcon(&potionIcon);
425                 antidote.SetUsableInBattle();
426                 antidote.GetTargetingMode().TargetSingleAlly();
427                 inventory.Add(&antidote, 9);
428                 Item magicJar;
429                 magicJar.SetName("Magic jar");
430                 magicJar.SetMenuIcon(&potionIcon);
431                 magicJar.SetUsableInBattle();
432                 magicJar.GetTargetingMode().TargetSingleAlly();
433                 inventory.Add(&magicJar, 4);
434                 Item hiPotion;
435                 hiPotion.SetName("Hi-Potion");
436                 hiPotion.SetMenuIcon(&potionIcon);
437                 hiPotion.SetUsableInBattle();
438                 hiPotion.GetTargetingMode().TargetSingleAlly();
439                 inventory.Add(&hiPotion, 4);
440                 Item powerPotion;
441                 powerPotion.SetName("Power potion");
442                 powerPotion.SetMenuIcon(&potionIcon);
443                 inventory.Add(&powerPotion, 4);
444                 Item escape;
445                 escape.SetName("Escape");
446                 inventory.Add(&escape, 2);
447                 Item sleepBall;
448                 sleepBall.SetName("Sleep ball");
449                 sleepBall.SetMenuIcon(&ballIcon);
450                 sleepBall.SetUsableInBattle();
451                 sleepBall.GetTargetingMode().TargetSingleEnemy();
452                 inventory.Add(&sleepBall, 1);
453                 Item multiBall;
454                 multiBall.SetName("Multi-ball!");
455                 multiBall.SetMenuIcon(&ballIcon);
456                 multiBall.SetUsableInBattle();
457                 multiBall.GetTargetingMode().TargetMultipleEnemies();
458                 inventory.Add(&multiBall, 1);
459                 Item figgoru;
460                 figgoru.SetName("Figgoru");
461                 figgoru.SetMenuIcon(&crankIcon);
462                 figgoru.GetTargetingMode().TargetAllEnemies();
463                 inventory.Add(&figgoru, 1);
464                 battleRes.inventory = &inventory;
465
466                 battleRes.itemMenuHeadline = "Please choose an item.";
467                 battleRes.itemMenuPrototype = Menu<const common::Item *>(&normalFont, &disabledFont, &handCursorSprite, 15, 6, 8, 16, 1, 32, 2, ':');
468
469                 SDL_Surface *swordAttackImg(IMG_Load("test-data/attack-sword.png"));
470                 Sprite swordAttackSprite(swordAttackImg, 96, 96);
471                 SimpleAnimation swordAttackAnimation(&swordAttackSprite, 2 * framerate, 4);
472
473                 Item zircoSword;
474                 zircoSword.SetName("Zirco sword");
475                 zircoSword.SetMenuIcon(&swordIcon);
476                 Ikari firestorm;
477                 firestorm.SetName("Firestorm");
478                 firestorm.SetCost(224);
479                 firestorm.GetTargetingMode().TargetAllEnemies();
480                 firestorm.SetPhysical();
481                 zircoSword.SetIkari(&firestorm);
482                 zircoSword.SetAttackAnimation(&swordAttackAnimation);
483                 maxim.SetWeapon(&zircoSword);
484                 Item zirconArmor;
485                 zirconArmor.SetName("Zircon armor");
486                 zirconArmor.SetMenuIcon(&armorIcon);
487                 Ikari magicCure;
488                 magicCure.SetName("Magic cure");
489                 magicCure.SetCost(128);
490                 magicCure.GetTargetingMode().TargetSingleAlly();
491                 magicCure.SetMagical();
492                 zirconArmor.SetIkari(&magicCure);
493                 maxim.SetArmor(&zirconArmor);
494                 Item holyShield;
495                 holyShield.SetName("Holy shield");
496                 holyShield.SetMenuIcon(&shieldIcon);
497                 Ikari lightGuard;
498                 lightGuard.SetName("Light guard");
499                 lightGuard.SetCost(128);
500                 lightGuard.GetTargetingMode().TargetAllAllies(); // FIXME: actually only targets self
501                 lightGuard.SetMagical();
502                 holyShield.SetIkari(&lightGuard);
503                 maxim.SetShield(&holyShield);
504                 Item legendHelm;
505                 legendHelm.SetName("Legend helm");
506                 legendHelm.SetMenuIcon(&helmetIcon);
507                 Ikari boomerang;
508                 boomerang.SetName("Boomerang");
509                 boomerang.SetCost(164);
510                 boomerang.GetTargetingMode().TargetAllAllies(); // FIXME: actually only targets self
511                 boomerang.SetMagical();
512                 legendHelm.SetIkari(&boomerang);
513                 maxim.SetHelmet(&legendHelm);
514                 Item sProRing;
515                 sProRing.SetName("S-pro ring");
516                 sProRing.SetMenuIcon(&ringIcon);
517                 Ikari courage;
518                 courage.SetName("Courage");
519                 courage.SetCost(64);
520                 courage.GetTargetingMode().TargetMultipleAllies();
521                 courage.SetMagical();
522                 sProRing.SetIkari(&courage);
523                 maxim.SetRing(&sProRing);
524                 Item evilJewel;
525                 evilJewel.SetName("Evil jewel");
526                 evilJewel.SetMenuIcon(&jewelIcon);
527                 Ikari gloomy;
528                 gloomy.SetName("Gloomy");
529                 gloomy.SetCost(164);
530                 gloomy.GetTargetingMode().TargetAllEnemies();
531                 gloomy.SetMagical();
532                 evilJewel.SetIkari(&gloomy);
533                 maxim.SetJewel(&evilJewel);
534
535                 Item zircoWhip;
536                 zircoWhip.SetName("Zirco whip");
537                 zircoWhip.SetMenuIcon(&rodIcon);
538                 Ikari thundershriek;
539                 thundershriek.SetName("Thundershriek");
540                 thundershriek.SetCost(224);
541                 thundershriek.GetTargetingMode().TargetAllEnemies();
542                 thundershriek.SetPhysical();
543                 zircoWhip.SetIkari(&thundershriek);
544 //              selan.SetWeapon(&zircoWhip);
545                 Item zirconPlate;
546                 zirconPlate.SetName("Zircon plate");
547                 zirconPlate.SetMenuIcon(&armorIcon);
548                 Ikari suddenCure;
549                 suddenCure.SetName("Sudden cure");
550                 suddenCure.SetCost(96);
551                 suddenCure.GetTargetingMode().TargetAllAllies();
552                 suddenCure.SetMagical();
553                 zirconPlate.SetIkari(&suddenCure);
554                 selan.SetArmor(&zirconPlate);
555                 Item zircoGloves;
556                 zircoGloves.SetName("Zirco gloves");
557                 zircoGloves.SetMenuIcon(&shieldIcon);
558                 Ikari forcefield;
559                 forcefield.SetName("Forcefield");
560                 forcefield.SetCost(64);
561                 forcefield.GetTargetingMode().TargetAllAllies();
562                 forcefield.SetMagical();
563                 zircoGloves.SetIkari(&forcefield);
564                 selan.SetShield(&zircoGloves);
565                 Item holyCap;
566                 holyCap.SetName("Holy cap");
567                 holyCap.SetMenuIcon(&helmetIcon);
568                 Ikari vulnerable;
569                 vulnerable.SetName("Vulnerable");
570                 vulnerable.SetCost(196);
571                 vulnerable.GetTargetingMode().TargetAllEnemies();
572                 vulnerable.SetPhysical();
573                 holyCap.SetIkari(&vulnerable);
574                 selan.SetHelmet(&holyCap);
575                 Item ghostRing;
576                 ghostRing.SetName("Ghost ring");
577                 ghostRing.SetMenuIcon(&ringIcon);
578                 Ikari destroy;
579                 destroy.SetName("Destroy");
580                 destroy.SetCost(128);
581                 destroy.GetTargetingMode().TargetMultipleEnemies();
582                 destroy.SetMagical();
583                 ghostRing.SetIkari(&destroy);
584                 selan.SetRing(&ghostRing);
585                 Item eagleRock;
586                 eagleRock.SetName("Eagle rock");
587                 eagleRock.SetMenuIcon(&jewelIcon);
588                 Ikari dive;
589                 dive.SetName("Dive");
590                 dive.SetCost(128);
591                 dive.GetTargetingMode().TargetSingleEnemy();
592                 dive.SetPhysical();
593                 eagleRock.SetIkari(&dive);
594                 selan.SetJewel(&eagleRock);
595
596                 Item zircoAx;
597                 zircoAx.SetName("Zirco ax");
598                 zircoAx.SetMenuIcon(&axIcon);
599                 Ikari torrent;
600                 torrent.SetName("Torrent");
601                 torrent.SetCost(224);
602                 torrent.GetTargetingMode().TargetAllEnemies();
603                 torrent.SetPhysical();
604                 zircoAx.SetIkari(&torrent);
605 //              guy.SetWeapon(&zircoAx);
606                 guy.SetArmor(&zirconArmor);
607                 Item megaShield;
608                 megaShield.SetName("Mega shield");
609                 megaShield.SetMenuIcon(&shieldIcon);
610                 Ikari ironBarrier;
611                 ironBarrier.SetName("Iron barrier");
612                 ironBarrier.SetCost(255);
613                 ironBarrier.GetTargetingMode().TargetAllAllies(); // FIXME: actually only targets self
614                 ironBarrier.SetMagical();
615                 megaShield.SetIkari(&ironBarrier);
616                 guy.SetShield(&megaShield);
617                 Item zircoHelmet;
618                 zircoHelmet.SetName("Zirco helmet");
619                 zircoHelmet.SetMenuIcon(&helmetIcon);
620                 Ikari slow;
621                 slow.SetName("Slow");
622                 slow.SetCost(196);
623                 slow.GetTargetingMode().TargetAllEnemies();
624                 slow.SetPhysical();
625                 zircoHelmet.SetIkari(&slow);
626                 guy.SetHelmet(&zircoHelmet);
627                 Item powerRing;
628                 powerRing.SetName("Power ring");
629                 powerRing.SetMenuIcon(&ringIcon);
630                 Ikari trick;
631                 trick.SetName("Trick");
632                 trick.SetCost(32);
633                 trick.GetTargetingMode().TargetAllEnemies();
634                 trick.SetMagical();
635                 zircoHelmet.SetIkari(&trick);
636                 guy.SetRing(&powerRing);
637                 guy.SetJewel(&evilJewel);
638
639                 // NOTE: this is actually Artea equipment
640                 Item lizardBlow;
641                 lizardBlow.SetName("Lizard blow");
642                 lizardBlow.SetMenuIcon(&swordIcon);
643                 Ikari dragonRush;
644                 dragonRush.SetName("Dragon rush");
645                 dragonRush.SetCost(164);
646                 dragonRush.GetTargetingMode().TargetSingleEnemy();
647                 dragonRush.SetPhysical();
648                 lizardBlow.SetIkari(&dragonRush);
649 //              dekar.SetWeapon(&lizardBlow);
650                 Item holyRobe;
651                 holyRobe.SetName("Holy robe");
652                 holyRobe.SetMenuIcon(&armorIcon);
653                 Ikari crisisCure;
654                 crisisCure.SetName("Crisis cure");
655                 crisisCure.SetCost(164);
656                 crisisCure.GetTargetingMode().TargetAllAllies();
657                 crisisCure.SetMagical();
658                 holyRobe.SetIkari(&crisisCure);
659                 dekar.SetArmor(&holyRobe);
660                 dekar.SetShield(&zircoGloves);
661                 dekar.SetHelmet(&holyCap);
662                 Item rocketRing;
663                 rocketRing.SetName("Rocket ring");
664                 rocketRing.SetMenuIcon(&ringIcon);
665                 Ikari fake;
666                 fake.SetName("Fake");
667                 fake.SetCost(32);
668                 fake.GetTargetingMode().TargetSingleAlly();
669                 fake.SetMagical();
670                 rocketRing.SetIkari(&fake);
671                 dekar.SetRing(&rocketRing);
672                 Item krakenRock;
673                 krakenRock.SetName("Kraken rock");
674                 krakenRock.SetMenuIcon(&jewelIcon);
675                 Ikari tenLegger;
676                 tenLegger.SetName("Ten-legger");
677                 tenLegger.SetCost(164);
678                 tenLegger.GetTargetingMode().TargetAllEnemies();
679                 tenLegger.SetPhysical();
680                 rocketRing.SetIkari(&tenLegger);
681                 dekar.SetJewel(&krakenRock);
682
683                 battleRes.ikariMenuHeadline = "Please choose equipment.";
684                 battleRes.noEquipmentText = "No equip";
685                 battleRes.ikariMenuPrototype = Menu<const Item *>(&normalFont, &disabledFont, &handCursorSprite, 12, 6, normalFont.CharHeight() / 2, normalFont.CharWidth(), 1, normalFont.CharWidth() * 2, 0, ':', 12, normalFont.CharWidth());
686
687                 battleRes.escapeText = "Escapes.";
688
689                 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &battleRes));
690                 battleState->AddMonster(monster);
691                 battleState->AddMonster(monster);
692                 battleState->AddMonster(monster);
693                 battleState->AddMonster(monster);
694                 battleState->AddHero(maxim);
695                 battleState->AddHero(selan);
696                 battleState->AddHero(guy);
697                 battleState->AddHero(dekar);
698                 Application app(&screen, battleState);
699                 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
700                 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
701                 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
702                 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
703                 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
704                 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
705                 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
706                 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
707                 app.Buttons().MapKey(SDLK_RETURN, Input::START);
708                 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
709                 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
710                 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
711                 app.Run();
712
713                 return 0;
714         } catch (exception &e) {
715                 cerr << "exception in main(): " << e.what() << endl;
716                 return 1;
717         }
718 }