4 * Created on: Aug 1, 2012
8 #include "app/Application.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"
28 #include <SDL_image.h>
30 using app::Application;
32 using battle::BattleState;
34 using battle::Monster;
35 using battle::PartyLayout;
36 using geometry::Point;
38 using graphics::Frame;
39 using graphics::Gauge;
41 using graphics::Sprite;
43 using sdl::InitScreen;
51 int main(int argc, char **argv) {
52 const int width = 800;
53 const int height = 480;
57 InitImage image(IMG_INIT_PNG);
58 InitScreen screen(width, height);
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));
73 SDL_Surface *monsterImg(IMG_Load("test-data/monster.png"));
74 Sprite dummySprite(monsterImg, 64, 64);
76 monster.SetSprite(&dummySprite);
78 SDL_Surface *maximImg(IMG_Load("test-data/maxim.png"));
79 Sprite maximSprite(maximImg, 64, 64);
81 maxim.SetName("Maxim");
83 maxim.SetSprite(&maximSprite);
84 maxim.SetMaxHealth(33);
90 SDL_Surface *selanImg(IMG_Load("test-data/selan.png"));
91 Sprite selanSprite(selanImg, 64, 64);
93 selan.SetName("Selan");
95 selan.SetSprite(&selanSprite);
96 selan.SetMaxHealth(28);
102 SDL_Surface *guyImg(IMG_Load("test-data/guy.png"));
103 Sprite guySprite(guyImg, 64, 64);
107 guy.SetSprite(&guySprite);
108 guy.SetMaxHealth(38);
114 SDL_Surface *dekarImg(IMG_Load("test-data/dekar.png"));
115 Sprite dekarSprite(dekarImg, 64, 64);
117 dekar.SetName("Dekar");
119 dekar.SetSprite(&dekarSprite);
120 dekar.SetMaxHealth(38);
126 battle::Resources battleRes;
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 *attackChoiceIconsImg(IMG_Load("test-data/attack-choice-icons.png"));
132 Sprite attackChoiceIconsSprite(attackChoiceIconsImg, 16, 16);
133 battleRes.attackChoiceIcons = &attackChoiceIconsSprite;
134 SDL_Surface *moveIconsImg(IMG_Load("test-data/move-icons.png"));
135 Sprite moveIconsSprite(moveIconsImg, 32, 32);
136 battleRes.moveIcons = &moveIconsSprite;
137 SDL_Surface *heroTagImg(IMG_Load("test-data/hero-tag-sprites.png"));
138 Sprite heroTagSprite(heroTagImg, 32, 16);
139 battleRes.heroTagLabels = &heroTagSprite;
140 SDL_Surface *numbersImg(IMG_Load("test-data/numbers.png"));
141 Sprite numbersSprite(numbersImg, 16, 16);
142 Font heroTagFont(&numbersSprite);
143 battleRes.heroTagFont = &heroTagFont;
144 SDL_Surface *tagFramesImg(IMG_Load("test-data/tag-frames.png"));
145 Frame heroTagFrame(tagFramesImg, 16, 16, 1, 1, 0, 33);
146 battleRes.heroTagFrame = &heroTagFrame;
147 Frame activeHeroTagFrame(tagFramesImg, 16, 16);
148 battleRes.activeHeroTagFrame = &activeHeroTagFrame;
150 SDL_Surface *gauges(IMG_Load("test-data/gauges.png"));
151 Gauge healthGauge(gauges, 0, 16, 0, 0, 16, 6, 1, 6);
152 battleRes.healthGauge = &healthGauge;
153 Gauge manaGauge(gauges, 0, 32, 0, 0, 16, 6, 1, 6);
154 battleRes.manaGauge = &manaGauge;
155 Gauge ikariGauge(gauges, 0, 48, 0, 0, 16, 6, 1, 6);
156 battleRes.ikariGauge = &ikariGauge;
158 SDL_Surface *selectFrameImg(IMG_Load("test-data/select-frame.png"));
159 Frame selectFrame(selectFrameImg, 16, 16);
160 battleRes.selectFrame = &selectFrame;
162 SDL_Surface *normalFontImg(IMG_Load("test-data/normal-font.png"));
163 Sprite normalFontSprite(normalFontImg, 16, 16);
164 Font normalFont(&normalFontSprite);
165 normalFont.MapRange('A', 'M', 0, 1);
166 normalFont.MapRange('N', 'Z', 0, 2);
167 normalFont.MapRange('a', 'm', 0, 3);
168 normalFont.MapRange('n', 'z', 0, 4);
169 normalFont.MapChar(':', 10, 0);
170 normalFont.MapChar('!', 10, 0);
171 normalFont.MapChar('?', 10, 0);
172 // TODO: add '.' and '-' characters
173 battleRes.normalFont = &normalFont;
175 SDL_Surface *disabledFontImg(IMG_Load("test-data/disabled-font.png"));
176 Sprite disabledFontSprite(disabledFontImg, 16, 16);
177 Font disabledFont(&disabledFontSprite);
178 disabledFont.MapRange('A', 'M', 0, 1);
179 disabledFont.MapRange('N', 'Z', 0, 2);
180 disabledFont.MapRange('a', 'm', 0, 3);
181 disabledFont.MapRange('n', 'z', 0, 4);
182 disabledFont.MapChar(':', 10, 0);
183 disabledFont.MapChar('!', 10, 0);
184 disabledFont.MapChar('?', 10, 0);
185 // TODO: add '.' and '-' characters
186 battleRes.disabledFont = &disabledFont;
188 SDL_Surface *handCursorImg(IMG_Load("test-data/cursor-hand.png"));
189 Sprite handCursorSprite(handCursorImg, 32, 32);
190 battleRes.menuCursor = &handCursorSprite;
192 battleRes.spellMenuHeadline = "Please choose a spell.";
193 battleRes.spellMenuPrototype = Menu</* Spell */ void *>(&normalFont, &disabledFont, &handCursorSprite, 12, 6, 8, 0, 2, 32);
194 battleRes.spellMenuPrototype.Add("Reset : 0", 0, false);
195 battleRes.spellMenuPrototype.Add("Strong : 3", 0);
196 battleRes.spellMenuPrototype.Add("Stronger : 8", 0);
197 battleRes.spellMenuPrototype.Add("Champion :16", 0);
198 battleRes.spellMenuPrototype.Add("Rally :10", 0);
199 battleRes.spellMenuPrototype.Add("Escape : 8", 0, false);
200 battleRes.spellMenuPrototype.Add("Valor :30", 0);
201 battleRes.spellMenuPrototype.Add("Poison : 2", 0);
202 battleRes.spellMenuPrototype.Add("Warp : 8", 0, false);
203 battleRes.spellMenuPrototype.Add("Release : 2", 0);
204 battleRes.spellMenuPrototype.Add("Waken : 4", 0);
205 battleRes.spellMenuPrototype.Add("Light : 0", 0, false);
206 battleRes.spellMenuPrototype.Add("Fake : 4", 0);
207 battleRes.spellMenuPrototype.Add("Trick : 5", 0);
208 battleRes.spellMenuPrototype.Add("Flash : 5", 0);
209 battleRes.spellMenuPrototype.Add("Fireball : 6", 0);
210 battleRes.spellMenuPrototype.Add("Vortex : 7", 0);
211 battleRes.spellMenuPrototype.Add("Blizzard : 8", 0);
212 battleRes.spellMenuPrototype.Add("Spark : 3", 0);
214 SDL_Surface *itemIcons(IMG_Load("test-data/item-icons.png"));
215 Sprite potionIcon(itemIcons, 16, 16);
216 Sprite ballIcon(itemIcons, 16, 16, 0, 16);
217 Sprite crankIcon(itemIcons, 16, 16, 0, 32);
218 Sprite spearIcon(itemIcons, 16, 16, 0, 48);
219 Sprite swordIcon(itemIcons, 16, 16, 0, 64);
220 Sprite axIcon(itemIcons, 16, 16, 0, 80);
221 Sprite rodIcon(itemIcons, 16, 16, 0, 96);
222 Sprite armorIcon(itemIcons, 16, 16, 0, 112);
223 Sprite shieldIcon(itemIcons, 16, 16, 0, 128);
224 Sprite helmetIcon(itemIcons, 16, 16, 0, 144);
225 Sprite ringIcon(itemIcons, 16, 16, 0, 160);
226 Sprite stoneIcon(itemIcons, 16, 16, 0, 176);
228 battleRes.itemMenuHeadline = "Please choose an item.";
229 battleRes.itemMenuPrototype = Menu</* Item */ void *>(&normalFont, &disabledFont, &handCursorSprite, 15, 6, 8, 16, 1, 32);
230 battleRes.itemMenuPrototype.Add("Antidote : 9", 0, true, &potionIcon);
231 battleRes.itemMenuPrototype.Add("Magic jar : 4", 0, true, &potionIcon);
232 battleRes.itemMenuPrototype.Add("Miracle : 4", 0, true, &potionIcon);
233 battleRes.itemMenuPrototype.Add("Hi-Potion : 6", 0, true, &potionIcon);
234 battleRes.itemMenuPrototype.Add("Hi-Magic : 7", 0, true, &potionIcon);
235 battleRes.itemMenuPrototype.Add("Regain : 4", 0, true, &potionIcon);
236 battleRes.itemMenuPrototype.Add("Power potion: 4", 0, false, &potionIcon);
237 battleRes.itemMenuPrototype.Add("Life potion : 1", 0, false, &potionIcon);
238 battleRes.itemMenuPrototype.Add("Escape : 2", 0, false);
239 battleRes.itemMenuPrototype.Add("Power gourd : 3", 0, true, &potionIcon);
240 battleRes.itemMenuPrototype.Add("Mystery pin : 2", 0, true, &potionIcon);
241 battleRes.itemMenuPrototype.Add("Sleep ball : 1", 0, false, &ballIcon);
242 battleRes.itemMenuPrototype.Add("Figgoru : 1", 0, false, &crankIcon);
243 battleRes.itemMenuPrototype.Add("Spear : 1", 0, false, &spearIcon);
244 battleRes.itemMenuPrototype.Add("Silvo rapier: 1", 0, false, &swordIcon);
245 battleRes.itemMenuPrototype.Add("Rainy ax : 1", 0, false, &axIcon);
246 battleRes.itemMenuPrototype.Add("Pounder rod : 2", 0, false, &rodIcon);
247 battleRes.itemMenuPrototype.Add("Silver mail : 2", 0, false, &armorIcon);
248 battleRes.itemMenuPrototype.Add("Slash shield: 2", 0, false, &shieldIcon);
249 battleRes.itemMenuPrototype.Add("Golden helm : 1", 0, false, &helmetIcon);
250 battleRes.itemMenuPrototype.Add("Protect ring: 1", 0, false, &ringIcon);
251 battleRes.itemMenuPrototype.Add("Mysto jewel : 1", 0, false, &stoneIcon);
253 battleRes.ikariMenuHeadline = "Please choose equipment.";
254 battleRes.ikariMenuPrototype = Menu</* Item */ void *>(&normalFont, &disabledFont, &handCursorSprite, 26, 6, 8, 16, 1, 32);
255 battleRes.ikariMenuPrototype.Add("Zirco whip Thundershriek", 0, false, &swordIcon);
256 battleRes.ikariMenuPrototype.Add("Zircon plate Sudden cure", 0, true, &armorIcon);
257 battleRes.ikariMenuPrototype.Add("Zirco gloves Forcefield", 0, true, &shieldIcon);
258 battleRes.ikariMenuPrototype.Add("Holy cap Vulnerable", 0, false, &helmetIcon);
259 battleRes.ikariMenuPrototype.Add("Ghost ring Destroy", 0, true, &ringIcon);
260 battleRes.ikariMenuPrototype.Add("Eagle rock Dive", 0, true, &stoneIcon);
262 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &battleRes));
263 battleState->AddMonster(monster);
264 battleState->AddMonster(monster);
265 battleState->AddMonster(monster);
266 battleState->AddMonster(monster);
267 battleState->AddHero(maxim);
268 battleState->AddHero(selan);
269 battleState->AddHero(guy);
270 battleState->AddHero(dekar);
271 Application app(&screen, battleState);
272 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
273 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
274 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
275 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
276 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
277 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
278 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
279 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
280 app.Buttons().MapKey(SDLK_RETURN, Input::START);
281 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
282 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
283 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
287 } catch (exception &e) {
288 cerr << "exception in main(): " << e.what() << endl;