]> git.localhorst.tv Git - l2e.git/blob - src/main.cpp
added spells
[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 "common/Inventory.h"
16 #include "common/Item.h"
17 #include "common/Spell.h"
18 #include "geometry/Point.h"
19 #include "graphics/Font.h"
20 #include "graphics/Frame.h"
21 #include "graphics/Gauge.h"
22 #include "graphics/Menu.h"
23 #include "graphics/Sprite.h"
24 #include "sdl/InitImage.h"
25 #include "sdl/InitScreen.h"
26 #include "sdl/InitSDL.h"
27
28 #include <exception>
29 #include <iostream>
30 #include <SDL.h>
31 #include <SDL_image.h>
32
33 using app::Application;
34 using app::Input;
35 using battle::BattleState;
36 using battle::Hero;
37 using battle::Monster;
38 using battle::PartyLayout;
39 using common::Inventory;
40 using common::Item;
41 using common::Spell;
42 using geometry::Point;
43 using graphics::Font;
44 using graphics::Frame;
45 using graphics::Gauge;
46 using graphics::Menu;
47 using graphics::Sprite;
48 using sdl::InitImage;
49 using sdl::InitScreen;
50 using sdl::InitSDL;
51
52 using std::cerr;
53 using std::cout;
54 using std::endl;
55 using std::exception;
56
57 int main(int argc, char **argv) {
58         const int width = 800;
59         const int height = 480;
60
61         try {
62                 InitSDL sdl;
63                 InitImage image(IMG_INIT_PNG);
64                 InitScreen screen(width, height);
65
66                 // temporary test data
67                 SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
68                 PartyLayout monstersLayout;
69                 monstersLayout.AddPosition(Point<Uint8>(88, 104));
70                 monstersLayout.AddPosition(Point<Uint8>(128, 104));
71                 monstersLayout.AddPosition(Point<Uint8>(168, 104));
72                 monstersLayout.AddPosition(Point<Uint8>(208, 104));
73                 PartyLayout heroesLayout;
74                 heroesLayout.AddPosition(Point<Uint8>(27, 219));
75                 heroesLayout.AddPosition(Point<Uint8>(104, 227));
76                 heroesLayout.AddPosition(Point<Uint8>(66, 238));
77                 heroesLayout.AddPosition(Point<Uint8>(143, 246));
78
79                 SDL_Surface *monsterImg(IMG_Load("test-data/monster.png"));
80                 Sprite dummySprite(monsterImg, 64, 64);
81                 Monster monster;
82                 monster.SetSprite(&dummySprite);
83                 monster.SetMaxHealth(10);
84                 monster.SetHealth(10);
85
86                 SDL_Surface *maximImg(IMG_Load("test-data/maxim.png"));
87                 Sprite maximSprite(maximImg, 64, 64);
88                 Hero maxim;
89                 maxim.SetName("Maxim");
90                 maxim.SetLevel(1);
91                 maxim.SetSprite(&maximSprite);
92                 maxim.SetMaxHealth(33);
93                 maxim.SetHealth(33);
94                 maxim.SetMaxMana(20);
95                 maxim.SetMana(20);
96                 maxim.SetIP(0);
97
98                 SDL_Surface *selanImg(IMG_Load("test-data/selan.png"));
99                 Sprite selanSprite(selanImg, 64, 64);
100                 Hero selan;
101                 selan.SetName("Selan");
102                 selan.SetLevel(1);
103                 selan.SetSprite(&selanSprite);
104                 selan.SetMaxHealth(28);
105                 selan.SetHealth(28);
106                 selan.SetMaxMana(23);
107                 selan.SetMana(23);
108                 selan.SetIP(0);
109
110                 SDL_Surface *guyImg(IMG_Load("test-data/guy.png"));
111                 Sprite guySprite(guyImg, 64, 64);
112                 Hero guy;
113                 guy.SetName("Guy");
114                 guy.SetLevel(1);
115                 guy.SetSprite(&guySprite);
116                 guy.SetMaxHealth(38);
117                 guy.SetHealth(38);
118                 guy.SetMaxMana(0);
119                 guy.SetMana(0);
120                 guy.SetIP(0);
121
122                 SDL_Surface *dekarImg(IMG_Load("test-data/dekar.png"));
123                 Sprite dekarSprite(dekarImg, 64, 64);
124                 Hero dekar;
125                 dekar.SetName("Dekar");
126                 dekar.SetLevel(1);
127                 dekar.SetSprite(&dekarSprite);
128                 dekar.SetMaxHealth(38);
129                 dekar.SetHealth(38);
130                 dekar.SetMaxMana(0);
131                 dekar.SetMana(0);
132                 dekar.SetIP(0);
133
134                 battle::Resources battleRes;
135
136                 SDL_Surface *attackIconsImg(IMG_Load("test-data/attack-type-icons.png"));
137                 Sprite attackIconsSprite(attackIconsImg, 32, 32);
138                 battleRes.attackIcons = &attackIconsSprite;
139                 SDL_Surface *attackChoiceIconsImg(IMG_Load("test-data/attack-choice-icons.png"));
140                 Sprite attackChoiceIconsSprite(attackChoiceIconsImg, 16, 16);
141                 battleRes.attackChoiceIcons = &attackChoiceIconsSprite;
142                 SDL_Surface *moveIconsImg(IMG_Load("test-data/move-icons.png"));
143                 Sprite moveIconsSprite(moveIconsImg, 32, 32);
144                 battleRes.moveIcons = &moveIconsSprite;
145                 SDL_Surface *heroTagImg(IMG_Load("test-data/hero-tag-sprites.png"));
146                 Sprite heroTagSprite(heroTagImg, 32, 16);
147                 battleRes.heroTagLabels = &heroTagSprite;
148                 SDL_Surface *numbersImg(IMG_Load("test-data/numbers.png"));
149                 Sprite numbersSprite(numbersImg, 16, 16);
150                 Font heroTagFont(&numbersSprite);
151                 battleRes.heroTagFont = &heroTagFont;
152                 SDL_Surface *tagFramesImg(IMG_Load("test-data/tag-frames.png"));
153                 Frame heroTagFrame(tagFramesImg, 16, 16, 1, 1, 0, 33);
154                 battleRes.heroTagFrame = &heroTagFrame;
155                 Frame activeHeroTagFrame(tagFramesImg, 16, 16);
156                 battleRes.activeHeroTagFrame = &activeHeroTagFrame;
157
158                 SDL_Surface *gauges(IMG_Load("test-data/gauges.png"));
159                 Gauge healthGauge(gauges, 0, 16, 0, 0, 16, 6, 1, 6);
160                 battleRes.healthGauge = &healthGauge;
161                 Gauge manaGauge(gauges, 0, 32, 0, 0, 16, 6, 1, 6);
162                 battleRes.manaGauge = &manaGauge;
163                 Gauge ikariGauge(gauges, 0, 48, 0, 0, 16, 6, 1, 6);
164                 battleRes.ikariGauge = &ikariGauge;
165
166                 SDL_Surface *selectFrameImg(IMG_Load("test-data/select-frame.png"));
167                 Frame selectFrame(selectFrameImg, 16, 16);
168                 battleRes.selectFrame = &selectFrame;
169
170                 SDL_Surface *normalFontImg(IMG_Load("test-data/normal-font.png"));
171                 Sprite normalFontSprite(normalFontImg, 16, 16);
172                 Font normalFont(&normalFontSprite);
173                 normalFont.MapRange('A', 'M', 0, 1);
174                 normalFont.MapRange('N', 'Z', 0, 2);
175                 normalFont.MapRange('a', 'm', 0, 3);
176                 normalFont.MapRange('n', 'z', 0, 4);
177                 normalFont.MapChar(':', 10, 0);
178                 normalFont.MapChar('!', 11, 0);
179                 normalFont.MapChar('?', 12, 0);
180                 // TODO: add '.' and '-' characters
181                 battleRes.normalFont = &normalFont;
182
183                 SDL_Surface *disabledFontImg(IMG_Load("test-data/disabled-font.png"));
184                 Sprite disabledFontSprite(disabledFontImg, 16, 16);
185                 Font disabledFont(&disabledFontSprite);
186                 disabledFont.MapRange('A', 'M', 0, 1);
187                 disabledFont.MapRange('N', 'Z', 0, 2);
188                 disabledFont.MapRange('a', 'm', 0, 3);
189                 disabledFont.MapRange('n', 'z', 0, 4);
190                 disabledFont.MapChar(':', 10, 0);
191                 disabledFont.MapChar('!', 11, 0);
192                 disabledFont.MapChar('?', 12, 0);
193                 // TODO: add '.' and '-' characters
194                 battleRes.disabledFont = &disabledFont;
195
196                 SDL_Surface *handCursorImg(IMG_Load("test-data/cursor-hand.png"));
197                 Sprite handCursorSprite(handCursorImg, 32, 32);
198                 battleRes.menuCursor = &handCursorSprite;
199
200                 SDL_Surface *targetingIconsImg(IMG_Load("test-data/targeting-icons.png"));
201                 Sprite weaponTargetCursor(targetingIconsImg, 32, 32);
202                 Sprite itemTargetCursor(targetingIconsImg, 32, 32, 0, 64);
203                 battleRes.weaponTargetCursor = &weaponTargetCursor;
204                 // TODO: add image for magic targeting cursor
205                 battleRes.magicTargetCursor = &weaponTargetCursor;
206                 // TODO: add image for item targeting cursor
207                 battleRes.itemTargetCursor = &itemTargetCursor;
208
209                 Spell resetSpell;
210                 resetSpell.SetName("Reset");
211                 maxim.AddSpell(&resetSpell);
212                 Spell strongSpell;
213                 strongSpell.SetName("Strong");
214                 strongSpell.SetCost(3);
215                 strongSpell.SetUsableInBattle();
216                 maxim.AddSpell(&strongSpell);
217                 selan.AddSpell(&strongSpell);
218                 Spell strongerSpell;
219                 strongerSpell.SetName("Stronger");
220                 strongerSpell.SetCost(8);
221                 strongerSpell.SetUsableInBattle();
222                 maxim.AddSpell(&strongerSpell);
223                 selan.AddSpell(&strongerSpell);
224                 Spell championSpell;
225                 championSpell.SetName("Champion");
226                 championSpell.SetCost(16);
227                 championSpell.SetUsableInBattle();
228                 maxim.AddSpell(&championSpell);
229                 selan.AddSpell(&championSpell);
230                 Spell rallySpell;
231                 rallySpell.SetName("Rally");
232                 rallySpell.SetCost(10);
233                 rallySpell.SetUsableInBattle();
234                 maxim.AddSpell(&rallySpell);
235                 selan.AddSpell(&rallySpell);
236                 Spell escapeSpell;
237                 escapeSpell.SetName("Escape");
238                 escapeSpell.SetCost(8);
239                 selan.AddSpell(&escapeSpell);
240                 Spell valorSpell;
241                 valorSpell.SetName("Valor");
242                 valorSpell.SetCost(30);
243                 valorSpell.SetUsableInBattle();
244                 maxim.AddSpell(&valorSpell);
245                 selan.AddSpell(&valorSpell);
246
247                 battleRes.spellMenuHeadline = "Please choose a spell.";
248                 battleRes.spellMenuPrototype = Menu<const Spell *>(&normalFont, &disabledFont, &handCursorSprite, 9, 6, 8, 0, 2, 32, 2, ':');
249                 battleRes.spellMenuPrototype.Add("Poison   : 2", 0);
250                 battleRes.spellMenuPrototype.Add("Warp     : 8", 0, false);
251                 battleRes.spellMenuPrototype.Add("Release  : 2", 0);
252                 battleRes.spellMenuPrototype.Add("Waken    : 4", 0);
253                 battleRes.spellMenuPrototype.Add("Light    : 0", 0, false);
254                 battleRes.spellMenuPrototype.Add("Fake     : 4", 0);
255                 battleRes.spellMenuPrototype.Add("Trick    : 5", 0);
256                 battleRes.spellMenuPrototype.Add("Flash    : 5", 0);
257                 battleRes.spellMenuPrototype.Add("Fireball : 6", 0);
258                 battleRes.spellMenuPrototype.Add("Vortex   : 7", 0);
259                 battleRes.spellMenuPrototype.Add("Blizzard : 8", 0);
260                 battleRes.spellMenuPrototype.Add("Spark    : 3", 0);
261
262                 SDL_Surface *itemIcons(IMG_Load("test-data/item-icons.png"));
263                 Sprite potionIcon(itemIcons, 16, 16);
264                 Sprite ballIcon(itemIcons, 16, 16, 0, 16);
265                 Sprite crankIcon(itemIcons, 16, 16, 0, 32);
266                 Sprite spearIcon(itemIcons, 16, 16, 0, 48);
267                 Sprite swordIcon(itemIcons, 16, 16, 0, 64);
268                 Sprite axIcon(itemIcons, 16, 16, 0, 80);
269                 Sprite rodIcon(itemIcons, 16, 16, 0, 96);
270                 Sprite armorIcon(itemIcons, 16, 16, 0, 112);
271                 Sprite shieldIcon(itemIcons, 16, 16, 0, 128);
272                 Sprite helmetIcon(itemIcons, 16, 16, 0, 144);
273                 Sprite ringIcon(itemIcons, 16, 16, 0, 160);
274                 Sprite stoneIcon(itemIcons, 16, 16, 0, 176);
275
276                 Inventory inventory;
277                 Item antidote;
278                 antidote.SetName("Antidote");
279                 antidote.SetMenuIcon(&potionIcon);
280                 antidote.SetUsableInBattle();
281                 antidote.GetTargetingMode().TargetSingleAlly();
282                 inventory.Add(&antidote, 9);
283                 Item magicJar;
284                 magicJar.SetName("Magic jar");
285                 magicJar.SetMenuIcon(&potionIcon);
286                 magicJar.SetUsableInBattle();
287                 antidote.GetTargetingMode().TargetSingleAlly();
288                 inventory.Add(&magicJar, 4);
289                 Item hiPotion;
290                 hiPotion.SetName("Hi-Potion");
291                 hiPotion.SetMenuIcon(&potionIcon);
292                 hiPotion.SetUsableInBattle();
293                 antidote.GetTargetingMode().TargetSingleAlly();
294                 inventory.Add(&hiPotion, 4);
295                 Item powerPotion;
296                 powerPotion.SetName("Power potion");
297                 powerPotion.SetMenuIcon(&potionIcon);
298                 inventory.Add(&powerPotion, 4);
299                 Item escape;
300                 escape.SetName("Escape");
301                 inventory.Add(&escape, 2);
302                 Item sleepBall;
303                 sleepBall.SetName("Sleep ball");
304                 sleepBall.SetMenuIcon(&ballIcon);
305                 sleepBall.SetUsableInBattle();
306                 antidote.GetTargetingMode().TargetSingleEnemy();
307                 inventory.Add(&sleepBall, 1);
308                 Item multiBall;
309                 multiBall.SetName("Multi-ball!");
310                 multiBall.SetMenuIcon(&ballIcon);
311                 multiBall.SetUsableInBattle();
312                 antidote.GetTargetingMode().TargetMultipleEnemies();
313                 inventory.Add(&multiBall, 1);
314                 Item figgoru;
315                 figgoru.SetName("Figgoru");
316                 figgoru.SetMenuIcon(&crankIcon);
317                 antidote.GetTargetingMode().TargetAllEnemies();
318                 inventory.Add(&figgoru, 1);
319                 battleRes.inventory = &inventory;
320
321                 battleRes.itemMenuHeadline = "Please choose an item.";
322                 battleRes.itemMenuPrototype = Menu<const common::Item *>(&normalFont, &disabledFont, &handCursorSprite, 15, 6, 8, 16, 1, 32, 2, ':');
323
324                 battleRes.ikariMenuHeadline = "Please choose equipment.";
325                 battleRes.ikariMenuPrototype = Menu</* Item */ void *>(&normalFont, &disabledFont, &handCursorSprite, 26, 6, 8, 16, 1, 32);
326                 battleRes.ikariMenuPrototype.Add("Zirco whip   Thundershriek", 0, false, &swordIcon);
327                 battleRes.ikariMenuPrototype.Add("Zircon plate Sudden cure", 0, true, &armorIcon);
328                 battleRes.ikariMenuPrototype.Add("Zirco gloves Forcefield", 0, true, &shieldIcon);
329                 battleRes.ikariMenuPrototype.Add("Holy cap     Vulnerable", 0, false, &helmetIcon);
330                 battleRes.ikariMenuPrototype.Add("Ghost ring   Destroy", 0, true, &ringIcon);
331                 battleRes.ikariMenuPrototype.Add("Eagle rock   Dive", 0, true, &stoneIcon);
332
333                 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &battleRes));
334                 battleState->AddMonster(monster);
335                 battleState->AddMonster(monster);
336                 battleState->AddMonster(monster);
337                 battleState->AddMonster(monster);
338                 battleState->AddHero(maxim);
339                 battleState->AddHero(selan);
340                 battleState->AddHero(guy);
341                 battleState->AddHero(dekar);
342                 Application app(&screen, battleState);
343                 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
344                 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
345                 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
346                 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
347                 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
348                 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
349                 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
350                 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
351                 app.Buttons().MapKey(SDLK_RETURN, Input::START);
352                 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
353                 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
354                 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
355                 app.Run();
356
357                 return 0;
358         } catch (exception &e) {
359                 cerr << "exception in main(): " << e.what() << endl;
360                 return 1;
361         }
362 }