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 "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"
31 #include <SDL_image.h>
33 using app::Application;
35 using battle::BattleState;
37 using battle::Monster;
38 using battle::PartyLayout;
39 using common::Inventory;
42 using geometry::Point;
44 using graphics::Frame;
45 using graphics::Gauge;
47 using graphics::Sprite;
49 using sdl::InitScreen;
57 int main(int argc, char **argv) {
58 const int width = 800;
59 const int height = 480;
63 InitImage image(IMG_INIT_PNG);
64 InitScreen screen(width, height);
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));
79 SDL_Surface *monsterImg(IMG_Load("test-data/monster.png"));
80 Sprite dummySprite(monsterImg, 64, 64);
82 monster.SetSprite(&dummySprite);
83 monster.SetMaxHealth(10);
84 monster.SetHealth(10);
86 SDL_Surface *maximImg(IMG_Load("test-data/maxim.png"));
87 Sprite maximSprite(maximImg, 64, 64);
89 maxim.SetName("Maxim");
91 maxim.SetSprite(&maximSprite);
92 maxim.SetMaxHealth(33);
98 SDL_Surface *selanImg(IMG_Load("test-data/selan.png"));
99 Sprite selanSprite(selanImg, 64, 64);
101 selan.SetName("Selan");
103 selan.SetSprite(&selanSprite);
104 selan.SetMaxHealth(28);
106 selan.SetMaxMana(23);
110 SDL_Surface *guyImg(IMG_Load("test-data/guy.png"));
111 Sprite guySprite(guyImg, 64, 64);
115 guy.SetSprite(&guySprite);
116 guy.SetMaxHealth(38);
122 SDL_Surface *dekarImg(IMG_Load("test-data/dekar.png"));
123 Sprite dekarSprite(dekarImg, 64, 64);
125 dekar.SetName("Dekar");
127 dekar.SetSprite(&dekarSprite);
128 dekar.SetMaxHealth(38);
134 battle::Resources battleRes;
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;
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;
166 SDL_Surface *selectFrameImg(IMG_Load("test-data/select-frame.png"));
167 Frame selectFrame(selectFrameImg, 16, 16);
168 battleRes.selectFrame = &selectFrame;
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;
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;
196 SDL_Surface *handCursorImg(IMG_Load("test-data/cursor-hand.png"));
197 Sprite handCursorSprite(handCursorImg, 32, 32);
198 battleRes.menuCursor = &handCursorSprite;
200 SDL_Surface *targetingIconsImg(IMG_Load("test-data/targeting-icons.png"));
201 Sprite weaponTargetCursor(targetingIconsImg, 32, 32);
202 Sprite magicTargetCursor(targetingIconsImg, 32, 32, 0, 32);
203 Sprite itemTargetCursor(targetingIconsImg, 32, 32, 0, 64);
204 battleRes.weaponTargetCursor = &weaponTargetCursor;
205 // TODO: add image for magic targeting cursor
206 battleRes.magicTargetCursor = &magicTargetCursor;
207 // TODO: add image for item targeting cursor
208 battleRes.itemTargetCursor = &itemTargetCursor;
211 resetSpell.SetName("Reset");
212 maxim.AddSpell(&resetSpell);
214 strongSpell.SetName("Strong");
215 strongSpell.SetCost(3);
216 strongSpell.SetUsableInBattle();
217 strongSpell.GetTargetingMode().TargetMultipleAllies();
218 maxim.AddSpell(&strongSpell);
219 selan.AddSpell(&strongSpell);
221 strongerSpell.SetName("Stronger");
222 strongerSpell.SetCost(8);
223 strongerSpell.SetUsableInBattle();
224 strongerSpell.GetTargetingMode().TargetMultipleAllies();
225 maxim.AddSpell(&strongerSpell);
226 selan.AddSpell(&strongerSpell);
228 championSpell.SetName("Champion");
229 championSpell.SetCost(16);
230 championSpell.SetUsableInBattle();
231 championSpell.GetTargetingMode().TargetMultipleAllies();
232 maxim.AddSpell(&championSpell);
233 selan.AddSpell(&championSpell);
235 rallySpell.SetName("Rally");
236 rallySpell.SetCost(10);
237 rallySpell.SetUsableInBattle();
238 rallySpell.GetTargetingMode().TargetMultipleAllies();
239 maxim.AddSpell(&rallySpell);
240 selan.AddSpell(&rallySpell);
242 escapeSpell.SetName("Escape");
243 escapeSpell.SetCost(8);
244 selan.AddSpell(&escapeSpell);
246 valorSpell.SetName("Valor");
247 valorSpell.SetCost(30);
248 valorSpell.SetUsableInBattle();
249 valorSpell.GetTargetingMode().TargetMultipleAllies();
250 maxim.AddSpell(&valorSpell);
251 selan.AddSpell(&valorSpell);
253 battleRes.spellMenuHeadline = "Please choose a spell.";
254 battleRes.spellMenuPrototype = Menu<const Spell *>(&normalFont, &disabledFont, &handCursorSprite, 9, 6, 8, 0, 2, 32, 2, ':');
256 SDL_Surface *itemIcons(IMG_Load("test-data/item-icons.png"));
257 Sprite potionIcon(itemIcons, 16, 16);
258 Sprite ballIcon(itemIcons, 16, 16, 0, 16);
259 Sprite crankIcon(itemIcons, 16, 16, 0, 32);
260 Sprite spearIcon(itemIcons, 16, 16, 0, 48);
261 Sprite swordIcon(itemIcons, 16, 16, 0, 64);
262 Sprite axIcon(itemIcons, 16, 16, 0, 80);
263 Sprite rodIcon(itemIcons, 16, 16, 0, 96);
264 Sprite armorIcon(itemIcons, 16, 16, 0, 112);
265 Sprite shieldIcon(itemIcons, 16, 16, 0, 128);
266 Sprite helmetIcon(itemIcons, 16, 16, 0, 144);
267 Sprite ringIcon(itemIcons, 16, 16, 0, 160);
268 Sprite stoneIcon(itemIcons, 16, 16, 0, 176);
272 antidote.SetName("Antidote");
273 antidote.SetMenuIcon(&potionIcon);
274 antidote.SetUsableInBattle();
275 antidote.GetTargetingMode().TargetSingleAlly();
276 inventory.Add(&antidote, 9);
278 magicJar.SetName("Magic jar");
279 magicJar.SetMenuIcon(&potionIcon);
280 magicJar.SetUsableInBattle();
281 antidote.GetTargetingMode().TargetSingleAlly();
282 inventory.Add(&magicJar, 4);
284 hiPotion.SetName("Hi-Potion");
285 hiPotion.SetMenuIcon(&potionIcon);
286 hiPotion.SetUsableInBattle();
287 antidote.GetTargetingMode().TargetSingleAlly();
288 inventory.Add(&hiPotion, 4);
290 powerPotion.SetName("Power potion");
291 powerPotion.SetMenuIcon(&potionIcon);
292 inventory.Add(&powerPotion, 4);
294 escape.SetName("Escape");
295 inventory.Add(&escape, 2);
297 sleepBall.SetName("Sleep ball");
298 sleepBall.SetMenuIcon(&ballIcon);
299 sleepBall.SetUsableInBattle();
300 antidote.GetTargetingMode().TargetSingleEnemy();
301 inventory.Add(&sleepBall, 1);
303 multiBall.SetName("Multi-ball!");
304 multiBall.SetMenuIcon(&ballIcon);
305 multiBall.SetUsableInBattle();
306 antidote.GetTargetingMode().TargetMultipleEnemies();
307 inventory.Add(&multiBall, 1);
309 figgoru.SetName("Figgoru");
310 figgoru.SetMenuIcon(&crankIcon);
311 antidote.GetTargetingMode().TargetAllEnemies();
312 inventory.Add(&figgoru, 1);
313 battleRes.inventory = &inventory;
315 battleRes.itemMenuHeadline = "Please choose an item.";
316 battleRes.itemMenuPrototype = Menu<const common::Item *>(&normalFont, &disabledFont, &handCursorSprite, 15, 6, 8, 16, 1, 32, 2, ':');
318 battleRes.ikariMenuHeadline = "Please choose equipment.";
319 battleRes.ikariMenuPrototype = Menu</* Item */ void *>(&normalFont, &disabledFont, &handCursorSprite, 26, 6, 8, 16, 1, 32);
320 battleRes.ikariMenuPrototype.Add("Zirco whip Thundershriek", 0, false, &swordIcon);
321 battleRes.ikariMenuPrototype.Add("Zircon plate Sudden cure", 0, true, &armorIcon);
322 battleRes.ikariMenuPrototype.Add("Zirco gloves Forcefield", 0, true, &shieldIcon);
323 battleRes.ikariMenuPrototype.Add("Holy cap Vulnerable", 0, false, &helmetIcon);
324 battleRes.ikariMenuPrototype.Add("Ghost ring Destroy", 0, true, &ringIcon);
325 battleRes.ikariMenuPrototype.Add("Eagle rock Dive", 0, true, &stoneIcon);
327 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &battleRes));
328 battleState->AddMonster(monster);
329 battleState->AddMonster(monster);
330 battleState->AddMonster(monster);
331 battleState->AddMonster(monster);
332 battleState->AddHero(maxim);
333 battleState->AddHero(selan);
334 battleState->AddHero(guy);
335 battleState->AddHero(dekar);
336 Application app(&screen, battleState);
337 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
338 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
339 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
340 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
341 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
342 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
343 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
344 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
345 app.Buttons().MapKey(SDLK_RETURN, Input::START);
346 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
347 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
348 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
352 } catch (exception &e) {
353 cerr << "exception in main(): " << e.what() << endl;