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