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