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 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;
210 resetSpell.SetName("Reset");
211 maxim.AddSpell(&resetSpell);
213 strongSpell.SetName("Strong");
214 strongSpell.SetCost(3);
215 strongSpell.SetUsableInBattle();
216 maxim.AddSpell(&strongSpell);
217 selan.AddSpell(&strongSpell);
219 strongerSpell.SetName("Stronger");
220 strongerSpell.SetCost(8);
221 strongerSpell.SetUsableInBattle();
222 maxim.AddSpell(&strongerSpell);
223 selan.AddSpell(&strongerSpell);
225 championSpell.SetName("Champion");
226 championSpell.SetCost(16);
227 championSpell.SetUsableInBattle();
228 maxim.AddSpell(&championSpell);
229 selan.AddSpell(&championSpell);
231 rallySpell.SetName("Rally");
232 rallySpell.SetCost(10);
233 rallySpell.SetUsableInBattle();
234 maxim.AddSpell(&rallySpell);
235 selan.AddSpell(&rallySpell);
237 escapeSpell.SetName("Escape");
238 escapeSpell.SetCost(8);
239 selan.AddSpell(&escapeSpell);
241 valorSpell.SetName("Valor");
242 valorSpell.SetCost(30);
243 valorSpell.SetUsableInBattle();
244 maxim.AddSpell(&valorSpell);
245 selan.AddSpell(&valorSpell);
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);
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);
278 antidote.SetName("Antidote");
279 antidote.SetMenuIcon(&potionIcon);
280 antidote.SetUsableInBattle();
281 antidote.GetTargetingMode().TargetSingleAlly();
282 inventory.Add(&antidote, 9);
284 magicJar.SetName("Magic jar");
285 magicJar.SetMenuIcon(&potionIcon);
286 magicJar.SetUsableInBattle();
287 antidote.GetTargetingMode().TargetSingleAlly();
288 inventory.Add(&magicJar, 4);
290 hiPotion.SetName("Hi-Potion");
291 hiPotion.SetMenuIcon(&potionIcon);
292 hiPotion.SetUsableInBattle();
293 antidote.GetTargetingMode().TargetSingleAlly();
294 inventory.Add(&hiPotion, 4);
296 powerPotion.SetName("Power potion");
297 powerPotion.SetMenuIcon(&potionIcon);
298 inventory.Add(&powerPotion, 4);
300 escape.SetName("Escape");
301 inventory.Add(&escape, 2);
303 sleepBall.SetName("Sleep ball");
304 sleepBall.SetMenuIcon(&ballIcon);
305 sleepBall.SetUsableInBattle();
306 antidote.GetTargetingMode().TargetSingleEnemy();
307 inventory.Add(&sleepBall, 1);
309 multiBall.SetName("Multi-ball!");
310 multiBall.SetMenuIcon(&ballIcon);
311 multiBall.SetUsableInBattle();
312 antidote.GetTargetingMode().TargetMultipleEnemies();
313 inventory.Add(&multiBall, 1);
315 figgoru.SetName("Figgoru");
316 figgoru.SetMenuIcon(&crankIcon);
317 antidote.GetTargetingMode().TargetAllEnemies();
318 inventory.Add(&figgoru, 1);
319 battleRes.inventory = &inventory;
321 battleRes.itemMenuHeadline = "Please choose an item.";
322 battleRes.itemMenuPrototype = Menu<const common::Item *>(&normalFont, &disabledFont, &handCursorSprite, 15, 6, 8, 16, 1, 32, 2, ':');
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);
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);
358 } catch (exception &e) {
359 cerr << "exception in main(): " << e.what() << endl;