]> git.localhorst.tv Git - l2e.git/blob - src/main.cpp
added icons for item select
[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 "geometry/Point.h"
16 #include "graphics/Font.h"
17 #include "graphics/Frame.h"
18 #include "graphics/Gauge.h"
19 #include "graphics/Menu.h"
20 #include "graphics/Sprite.h"
21 #include "sdl/InitImage.h"
22 #include "sdl/InitScreen.h"
23 #include "sdl/InitSDL.h"
24
25 #include <exception>
26 #include <iostream>
27 #include <SDL.h>
28 #include <SDL_image.h>
29
30 using app::Application;
31 using app::Input;
32 using battle::BattleState;
33 using battle::Hero;
34 using battle::Monster;
35 using battle::PartyLayout;
36 using geometry::Point;
37 using graphics::Font;
38 using graphics::Frame;
39 using graphics::Gauge;
40 using graphics::Menu;
41 using graphics::Sprite;
42 using sdl::InitImage;
43 using sdl::InitScreen;
44 using sdl::InitSDL;
45
46 using std::cerr;
47 using std::cout;
48 using std::endl;
49 using std::exception;
50
51 int main(int argc, char **argv) {
52         const int width = 800;
53         const int height = 480;
54
55         try {
56                 InitSDL sdl;
57                 InitImage image(IMG_INIT_PNG);
58                 InitScreen screen(width, height);
59
60                 // temporary test data
61                 SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
62                 PartyLayout monstersLayout;
63                 monstersLayout.AddPosition(Point<Uint8>(88, 104));
64                 monstersLayout.AddPosition(Point<Uint8>(128, 104));
65                 monstersLayout.AddPosition(Point<Uint8>(168, 104));
66                 monstersLayout.AddPosition(Point<Uint8>(208, 104));
67                 PartyLayout heroesLayout;
68                 heroesLayout.AddPosition(Point<Uint8>(27, 219));
69                 heroesLayout.AddPosition(Point<Uint8>(104, 227));
70                 heroesLayout.AddPosition(Point<Uint8>(66, 238));
71                 heroesLayout.AddPosition(Point<Uint8>(143, 246));
72
73                 SDL_Surface *monsterImg(IMG_Load("test-data/monster.png"));
74                 Sprite dummySprite(monsterImg, 64, 64);
75                 Monster monster;
76                 monster.SetSprite(&dummySprite);
77
78                 SDL_Surface *maximImg(IMG_Load("test-data/maxim.png"));
79                 Sprite maximSprite(maximImg, 64, 64);
80                 Hero maxim;
81                 maxim.SetName("Maxim");
82                 maxim.SetLevel(1);
83                 maxim.SetSprite(&maximSprite);
84                 maxim.SetMaxHealth(33);
85                 maxim.SetHealth(33);
86                 maxim.SetMaxMana(20);
87                 maxim.SetMana(20);
88                 maxim.SetIP(0);
89
90                 SDL_Surface *selanImg(IMG_Load("test-data/selan.png"));
91                 Sprite selanSprite(selanImg, 64, 64);
92                 Hero selan;
93                 selan.SetName("Selan");
94                 selan.SetLevel(1);
95                 selan.SetSprite(&selanSprite);
96                 selan.SetMaxHealth(28);
97                 selan.SetHealth(28);
98                 selan.SetMaxMana(23);
99                 selan.SetMana(23);
100                 selan.SetIP(0);
101
102                 SDL_Surface *guyImg(IMG_Load("test-data/guy.png"));
103                 Sprite guySprite(guyImg, 64, 64);
104                 Hero guy;
105                 guy.SetName("Guy");
106                 guy.SetLevel(1);
107                 guy.SetSprite(&guySprite);
108                 guy.SetMaxHealth(38);
109                 guy.SetHealth(38);
110                 guy.SetMaxMana(0);
111                 guy.SetMana(0);
112                 guy.SetIP(0);
113
114                 SDL_Surface *dekarImg(IMG_Load("test-data/dekar.png"));
115                 Sprite dekarSprite(dekarImg, 64, 64);
116                 Hero dekar;
117                 dekar.SetName("Dekar");
118                 dekar.SetLevel(1);
119                 dekar.SetSprite(&dekarSprite);
120                 dekar.SetMaxHealth(38);
121                 dekar.SetHealth(38);
122                 dekar.SetMaxMana(0);
123                 dekar.SetMana(0);
124                 dekar.SetIP(0);
125
126                 battle::Resources battleRes;
127
128                 SDL_Surface *attackIconsImg(IMG_Load("test-data/attack-type-icons.png"));
129                 Sprite attackIconsSprite(attackIconsImg, 32, 32);
130                 battleRes.attackIcons = &attackIconsSprite;
131                 SDL_Surface *moveIconsImg(IMG_Load("test-data/move-icons.png"));
132                 Sprite moveIconsSprite(moveIconsImg, 32, 32);
133                 battleRes.moveIcons = &moveIconsSprite;
134                 SDL_Surface *heroTagImg(IMG_Load("test-data/hero-tag-sprites.png"));
135                 Sprite heroTagSprite(heroTagImg, 32, 16);
136                 battleRes.heroTagLabels = &heroTagSprite;
137                 SDL_Surface *numbersImg(IMG_Load("test-data/numbers.png"));
138                 Sprite numbersSprite(numbersImg, 16, 16);
139                 Font heroTagFont(&numbersSprite);
140                 battleRes.heroTagFont = &heroTagFont;
141                 SDL_Surface *tagFramesImg(IMG_Load("test-data/tag-frames.png"));
142                 Frame heroTagFrame(tagFramesImg, 16, 16, 1, 1, 0, 33);
143                 battleRes.heroTagFrame = &heroTagFrame;
144                 Frame activeHeroTagFrame(tagFramesImg, 16, 16);
145                 battleRes.activeHeroTagFrame = &activeHeroTagFrame;
146
147                 SDL_Surface *gauges(IMG_Load("test-data/gauges.png"));
148                 Gauge healthGauge(gauges, 0, 16, 0, 0, 16, 6, 1, 6);
149                 battleRes.healthGauge = &healthGauge;
150                 Gauge manaGauge(gauges, 0, 32, 0, 0, 16, 6, 1, 6);
151                 battleRes.manaGauge = &manaGauge;
152                 Gauge ikariGauge(gauges, 0, 48, 0, 0, 16, 6, 1, 6);
153                 battleRes.ikariGauge = &ikariGauge;
154
155                 SDL_Surface *selectFrameImg(IMG_Load("test-data/select-frame.png"));
156                 Frame selectFrame(selectFrameImg, 16, 16);
157                 battleRes.selectFrame = &selectFrame;
158
159                 SDL_Surface *normalFontImg(IMG_Load("test-data/normal-font.png"));
160                 Sprite normalFontSprite(normalFontImg, 16, 16);
161                 Font normalFont(&normalFontSprite);
162                 normalFont.MapRange('A', 'M', 0, 1);
163                 normalFont.MapRange('N', 'Z', 0, 2);
164                 normalFont.MapRange('a', 'm', 0, 3);
165                 normalFont.MapRange('n', 'z', 0, 4);
166                 normalFont.MapChar(':', 10, 0);
167                 normalFont.MapChar('!', 10, 0);
168                 normalFont.MapChar('?', 10, 0);
169                 // TODO: add '.' and '-' characters
170                 battleRes.normalFont = &normalFont;
171
172                 SDL_Surface *disabledFontImg(IMG_Load("test-data/disabled-font.png"));
173                 Sprite disabledFontSprite(disabledFontImg, 16, 16);
174                 Font disabledFont(&disabledFontSprite);
175                 disabledFont.MapRange('A', 'M', 0, 1);
176                 disabledFont.MapRange('N', 'Z', 0, 2);
177                 disabledFont.MapRange('a', 'm', 0, 3);
178                 disabledFont.MapRange('n', 'z', 0, 4);
179                 disabledFont.MapChar(':', 10, 0);
180                 disabledFont.MapChar('!', 10, 0);
181                 disabledFont.MapChar('?', 10, 0);
182                 // TODO: add '.' and '-' characters
183                 battleRes.disabledFont = &disabledFont;
184
185                 SDL_Surface *handCursorImg(IMG_Load("test-data/cursor-hand.png"));
186                 Sprite handCursorSprite(handCursorImg, 32, 32);
187                 battleRes.menuCursor = &handCursorSprite;
188
189                 battleRes.spellMenuHeadline = "Please choose a spell.";
190                 battleRes.spellMenuPrototype = Menu</* Spell */ void *>(&normalFont, &disabledFont, &handCursorSprite, 12, 6, 8, 0, 2, 32);
191                 battleRes.spellMenuPrototype.Add("Reset    : 0", 0, false);
192                 battleRes.spellMenuPrototype.Add("Strong   : 3", 0);
193                 battleRes.spellMenuPrototype.Add("Stronger : 8", 0);
194                 battleRes.spellMenuPrototype.Add("Champion :16", 0);
195                 battleRes.spellMenuPrototype.Add("Rally    :10", 0);
196                 battleRes.spellMenuPrototype.Add("Escape   : 8", 0, false);
197                 battleRes.spellMenuPrototype.Add("Valor    :30", 0);
198                 battleRes.spellMenuPrototype.Add("Poison   : 2", 0);
199                 battleRes.spellMenuPrototype.Add("Warp     : 8", 0, false);
200                 battleRes.spellMenuPrototype.Add("Release  : 2", 0);
201                 battleRes.spellMenuPrototype.Add("Waken    : 4", 0);
202                 battleRes.spellMenuPrototype.Add("Light    : 0", 0, false);
203                 battleRes.spellMenuPrototype.Add("Fake     : 4", 0);
204                 battleRes.spellMenuPrototype.Add("Trick    : 5", 0);
205                 battleRes.spellMenuPrototype.Add("Flash    : 5", 0);
206                 battleRes.spellMenuPrototype.Add("Fireball : 6", 0);
207                 battleRes.spellMenuPrototype.Add("Vortex   : 7", 0);
208                 battleRes.spellMenuPrototype.Add("Blizzard : 8", 0);
209                 battleRes.spellMenuPrototype.Add("Spark    : 3", 0);
210
211                 SDL_Surface *itemIcons(IMG_Load("test-data/item-icons.png"));
212                 Sprite potionIcon(itemIcons, 16, 16);
213                 Sprite ballIcon(itemIcons, 16, 16, 0, 16);
214                 Sprite crankIcon(itemIcons, 16, 16, 0, 32);
215                 Sprite spearIcon(itemIcons, 16, 16, 0, 48);
216                 Sprite swordIcon(itemIcons, 16, 16, 0, 64);
217                 Sprite axIcon(itemIcons, 16, 16, 0, 80);
218                 Sprite rodIcon(itemIcons, 16, 16, 0, 96);
219                 Sprite armorIcon(itemIcons, 16, 16, 0, 112);
220                 Sprite shieldIcon(itemIcons, 16, 16, 0, 128);
221                 Sprite helmetIcon(itemIcons, 16, 16, 0, 144);
222                 Sprite ringIcon(itemIcons, 16, 16, 0, 160);
223                 Sprite stoneIcon(itemIcons, 16, 16, 0, 176);
224
225                 battleRes.itemMenuHeadline = "Please choose an item.";
226                 battleRes.itemMenuPrototype = Menu</* Item */ void *>(&normalFont, &disabledFont, &handCursorSprite, 15, 6, 8, 16, 1, 32);
227                 battleRes.itemMenuPrototype.Add("Antidote    : 9", 0, true, &potionIcon);
228                 battleRes.itemMenuPrototype.Add("Magic jar   : 4", 0, true, &potionIcon);
229                 battleRes.itemMenuPrototype.Add("Miracle     : 4", 0, true, &potionIcon);
230                 battleRes.itemMenuPrototype.Add("Hi-Potion   : 6", 0, true, &potionIcon);
231                 battleRes.itemMenuPrototype.Add("Hi-Magic    : 7", 0, true, &potionIcon);
232                 battleRes.itemMenuPrototype.Add("Regain      : 4", 0, true, &potionIcon);
233                 battleRes.itemMenuPrototype.Add("Power potion: 4", 0, false, &potionIcon);
234                 battleRes.itemMenuPrototype.Add("Life potion : 1", 0, false, &potionIcon);
235                 battleRes.itemMenuPrototype.Add("Escape      : 2", 0, false);
236                 battleRes.itemMenuPrototype.Add("Power gourd : 3", 0, true, &potionIcon);
237                 battleRes.itemMenuPrototype.Add("Mystery pin : 2", 0, true, &potionIcon);
238                 battleRes.itemMenuPrototype.Add("Sleep ball  : 1", 0, false, &ballIcon);
239                 battleRes.itemMenuPrototype.Add("Figgoru     : 1", 0, false, &crankIcon);
240                 battleRes.itemMenuPrototype.Add("Spear       : 1", 0, false, &spearIcon);
241                 battleRes.itemMenuPrototype.Add("Silvo rapier: 1", 0, false, &swordIcon);
242                 battleRes.itemMenuPrototype.Add("Rainy ax    : 1", 0, false, &axIcon);
243                 battleRes.itemMenuPrototype.Add("Pounder rod : 2", 0, false, &rodIcon);
244                 battleRes.itemMenuPrototype.Add("Silver mail : 2", 0, false, &armorIcon);
245                 battleRes.itemMenuPrototype.Add("Slash shield: 2", 0, false, &shieldIcon);
246                 battleRes.itemMenuPrototype.Add("Golden helm : 1", 0, false, &helmetIcon);
247                 battleRes.itemMenuPrototype.Add("Protect ring: 1", 0, false, &ringIcon);
248                 battleRes.itemMenuPrototype.Add("Mysto jewel : 1", 0, false, &stoneIcon);
249
250                 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &battleRes));
251                 battleState->AddMonster(monster);
252                 battleState->AddMonster(monster);
253                 battleState->AddMonster(monster);
254                 battleState->AddMonster(monster);
255                 battleState->AddHero(maxim);
256                 battleState->AddHero(selan);
257                 battleState->AddHero(guy);
258                 battleState->AddHero(dekar);
259                 Application app(&screen, battleState);
260                 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
261                 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
262                 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
263                 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
264                 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
265                 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
266                 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
267                 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
268                 app.Buttons().MapKey(SDLK_RETURN, Input::START);
269                 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
270                 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
271                 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
272                 app.Run();
273
274                 return 0;
275         } catch (exception &e) {
276                 cerr << "exception in main(): " << e.what() << endl;
277                 return 1;
278         }
279 }