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 "geometry/Point.h"
18 #include "graphics/Font.h"
19 #include "graphics/Frame.h"
20 #include "graphics/Gauge.h"
21 #include "graphics/Menu.h"
22 #include "graphics/Sprite.h"
23 #include "sdl/InitImage.h"
24 #include "sdl/InitScreen.h"
25 #include "sdl/InitSDL.h"
30 #include <SDL_image.h>
32 using app::Application;
34 using battle::BattleState;
36 using battle::Monster;
37 using battle::PartyLayout;
38 using common::Inventory;
40 using geometry::Point;
42 using graphics::Frame;
43 using graphics::Gauge;
45 using graphics::Sprite;
47 using sdl::InitScreen;
55 int main(int argc, char **argv) {
56 const int width = 800;
57 const int height = 480;
61 InitImage image(IMG_INIT_PNG);
62 InitScreen screen(width, height);
64 // temporary test data
65 SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
66 PartyLayout monstersLayout;
67 monstersLayout.AddPosition(Point<Uint8>(88, 104));
68 monstersLayout.AddPosition(Point<Uint8>(128, 104));
69 monstersLayout.AddPosition(Point<Uint8>(168, 104));
70 monstersLayout.AddPosition(Point<Uint8>(208, 104));
71 PartyLayout heroesLayout;
72 heroesLayout.AddPosition(Point<Uint8>(27, 219));
73 heroesLayout.AddPosition(Point<Uint8>(104, 227));
74 heroesLayout.AddPosition(Point<Uint8>(66, 238));
75 heroesLayout.AddPosition(Point<Uint8>(143, 246));
77 SDL_Surface *monsterImg(IMG_Load("test-data/monster.png"));
78 Sprite dummySprite(monsterImg, 64, 64);
80 monster.SetSprite(&dummySprite);
81 monster.SetMaxHealth(10);
82 monster.SetHealth(10);
84 SDL_Surface *maximImg(IMG_Load("test-data/maxim.png"));
85 Sprite maximSprite(maximImg, 64, 64);
87 maxim.SetName("Maxim");
89 maxim.SetSprite(&maximSprite);
90 maxim.SetMaxHealth(33);
96 SDL_Surface *selanImg(IMG_Load("test-data/selan.png"));
97 Sprite selanSprite(selanImg, 64, 64);
99 selan.SetName("Selan");
101 selan.SetSprite(&selanSprite);
102 selan.SetMaxHealth(28);
104 selan.SetMaxMana(23);
108 SDL_Surface *guyImg(IMG_Load("test-data/guy.png"));
109 Sprite guySprite(guyImg, 64, 64);
113 guy.SetSprite(&guySprite);
114 guy.SetMaxHealth(38);
120 SDL_Surface *dekarImg(IMG_Load("test-data/dekar.png"));
121 Sprite dekarSprite(dekarImg, 64, 64);
123 dekar.SetName("Dekar");
125 dekar.SetSprite(&dekarSprite);
126 dekar.SetMaxHealth(38);
132 battle::Resources battleRes;
134 SDL_Surface *attackIconsImg(IMG_Load("test-data/attack-type-icons.png"));
135 Sprite attackIconsSprite(attackIconsImg, 32, 32);
136 battleRes.attackIcons = &attackIconsSprite;
137 SDL_Surface *attackChoiceIconsImg(IMG_Load("test-data/attack-choice-icons.png"));
138 Sprite attackChoiceIconsSprite(attackChoiceIconsImg, 16, 16);
139 battleRes.attackChoiceIcons = &attackChoiceIconsSprite;
140 SDL_Surface *moveIconsImg(IMG_Load("test-data/move-icons.png"));
141 Sprite moveIconsSprite(moveIconsImg, 32, 32);
142 battleRes.moveIcons = &moveIconsSprite;
143 SDL_Surface *heroTagImg(IMG_Load("test-data/hero-tag-sprites.png"));
144 Sprite heroTagSprite(heroTagImg, 32, 16);
145 battleRes.heroTagLabels = &heroTagSprite;
146 SDL_Surface *numbersImg(IMG_Load("test-data/numbers.png"));
147 Sprite numbersSprite(numbersImg, 16, 16);
148 Font heroTagFont(&numbersSprite);
149 battleRes.heroTagFont = &heroTagFont;
150 SDL_Surface *tagFramesImg(IMG_Load("test-data/tag-frames.png"));
151 Frame heroTagFrame(tagFramesImg, 16, 16, 1, 1, 0, 33);
152 battleRes.heroTagFrame = &heroTagFrame;
153 Frame activeHeroTagFrame(tagFramesImg, 16, 16);
154 battleRes.activeHeroTagFrame = &activeHeroTagFrame;
156 SDL_Surface *gauges(IMG_Load("test-data/gauges.png"));
157 Gauge healthGauge(gauges, 0, 16, 0, 0, 16, 6, 1, 6);
158 battleRes.healthGauge = &healthGauge;
159 Gauge manaGauge(gauges, 0, 32, 0, 0, 16, 6, 1, 6);
160 battleRes.manaGauge = &manaGauge;
161 Gauge ikariGauge(gauges, 0, 48, 0, 0, 16, 6, 1, 6);
162 battleRes.ikariGauge = &ikariGauge;
164 SDL_Surface *selectFrameImg(IMG_Load("test-data/select-frame.png"));
165 Frame selectFrame(selectFrameImg, 16, 16);
166 battleRes.selectFrame = &selectFrame;
168 SDL_Surface *normalFontImg(IMG_Load("test-data/normal-font.png"));
169 Sprite normalFontSprite(normalFontImg, 16, 16);
170 Font normalFont(&normalFontSprite);
171 normalFont.MapRange('A', 'M', 0, 1);
172 normalFont.MapRange('N', 'Z', 0, 2);
173 normalFont.MapRange('a', 'm', 0, 3);
174 normalFont.MapRange('n', 'z', 0, 4);
175 normalFont.MapChar(':', 10, 0);
176 normalFont.MapChar('!', 11, 0);
177 normalFont.MapChar('?', 12, 0);
178 // TODO: add '.' and '-' characters
179 battleRes.normalFont = &normalFont;
181 SDL_Surface *disabledFontImg(IMG_Load("test-data/disabled-font.png"));
182 Sprite disabledFontSprite(disabledFontImg, 16, 16);
183 Font disabledFont(&disabledFontSprite);
184 disabledFont.MapRange('A', 'M', 0, 1);
185 disabledFont.MapRange('N', 'Z', 0, 2);
186 disabledFont.MapRange('a', 'm', 0, 3);
187 disabledFont.MapRange('n', 'z', 0, 4);
188 disabledFont.MapChar(':', 10, 0);
189 disabledFont.MapChar('!', 11, 0);
190 disabledFont.MapChar('?', 12, 0);
191 // TODO: add '.' and '-' characters
192 battleRes.disabledFont = &disabledFont;
194 SDL_Surface *handCursorImg(IMG_Load("test-data/cursor-hand.png"));
195 Sprite handCursorSprite(handCursorImg, 32, 32);
196 battleRes.menuCursor = &handCursorSprite;
198 SDL_Surface *targetingIconsImg(IMG_Load("test-data/targeting-icons.png"));
199 Sprite weaponTargetCursor(targetingIconsImg, 32, 32);
200 Sprite itemTargetCursor(targetingIconsImg, 32, 32, 0, 64);
201 battleRes.weaponTargetCursor = &weaponTargetCursor;
202 // TODO: add image for magic targeting cursor
203 battleRes.magicTargetCursor = &weaponTargetCursor;
204 // TODO: add image for item targeting cursor
205 battleRes.itemTargetCursor = &itemTargetCursor;
207 battleRes.spellMenuHeadline = "Please choose a spell.";
208 battleRes.spellMenuPrototype = Menu</* Spell */ void *>(&normalFont, &disabledFont, &handCursorSprite, 12, 6, 8, 0, 2, 32);
209 battleRes.spellMenuPrototype.Add("Reset : 0", 0, false);
210 battleRes.spellMenuPrototype.Add("Strong : 3", 0);
211 battleRes.spellMenuPrototype.Add("Stronger : 8", 0);
212 battleRes.spellMenuPrototype.Add("Champion :16", 0);
213 battleRes.spellMenuPrototype.Add("Rally :10", 0);
214 battleRes.spellMenuPrototype.Add("Escape : 8", 0, false);
215 battleRes.spellMenuPrototype.Add("Valor :30", 0);
216 battleRes.spellMenuPrototype.Add("Poison : 2", 0);
217 battleRes.spellMenuPrototype.Add("Warp : 8", 0, false);
218 battleRes.spellMenuPrototype.Add("Release : 2", 0);
219 battleRes.spellMenuPrototype.Add("Waken : 4", 0);
220 battleRes.spellMenuPrototype.Add("Light : 0", 0, false);
221 battleRes.spellMenuPrototype.Add("Fake : 4", 0);
222 battleRes.spellMenuPrototype.Add("Trick : 5", 0);
223 battleRes.spellMenuPrototype.Add("Flash : 5", 0);
224 battleRes.spellMenuPrototype.Add("Fireball : 6", 0);
225 battleRes.spellMenuPrototype.Add("Vortex : 7", 0);
226 battleRes.spellMenuPrototype.Add("Blizzard : 8", 0);
227 battleRes.spellMenuPrototype.Add("Spark : 3", 0);
229 SDL_Surface *itemIcons(IMG_Load("test-data/item-icons.png"));
230 Sprite potionIcon(itemIcons, 16, 16);
231 Sprite ballIcon(itemIcons, 16, 16, 0, 16);
232 Sprite crankIcon(itemIcons, 16, 16, 0, 32);
233 Sprite spearIcon(itemIcons, 16, 16, 0, 48);
234 Sprite swordIcon(itemIcons, 16, 16, 0, 64);
235 Sprite axIcon(itemIcons, 16, 16, 0, 80);
236 Sprite rodIcon(itemIcons, 16, 16, 0, 96);
237 Sprite armorIcon(itemIcons, 16, 16, 0, 112);
238 Sprite shieldIcon(itemIcons, 16, 16, 0, 128);
239 Sprite helmetIcon(itemIcons, 16, 16, 0, 144);
240 Sprite ringIcon(itemIcons, 16, 16, 0, 160);
241 Sprite stoneIcon(itemIcons, 16, 16, 0, 176);
245 antidote.SetName("Antidote");
246 antidote.SetMenuIcon(&potionIcon);
247 antidote.SetUsableInBattle();
248 antidote.SetTargettingMode(Item::TARGETTING_MODE_ALLY | Item::TARGETTING_MODE_ONE);
249 inventory.Add(&antidote, 9);
251 magicJar.SetName("Magic jar");
252 magicJar.SetMenuIcon(&potionIcon);
253 magicJar.SetUsableInBattle();
254 magicJar.SetTargettingMode(Item::TARGETTING_MODE_ALLY | Item::TARGETTING_MODE_ONE);
255 inventory.Add(&magicJar, 4);
257 hiPotion.SetName("Hi-Potion");
258 hiPotion.SetMenuIcon(&potionIcon);
259 hiPotion.SetUsableInBattle();
260 hiPotion.SetTargettingMode(Item::TARGETTING_MODE_ALLY | Item::TARGETTING_MODE_ONE);
261 inventory.Add(&hiPotion, 4);
263 powerPotion.SetName("Power potion");
264 powerPotion.SetMenuIcon(&potionIcon);
265 inventory.Add(&powerPotion, 4);
267 escape.SetName("Escape");
268 inventory.Add(&escape, 2);
270 sleepBall.SetName("Sleep ball");
271 sleepBall.SetMenuIcon(&ballIcon);
272 sleepBall.SetUsableInBattle();
273 sleepBall.SetTargettingMode(Item::TARGETTING_MODE_ENEMY | Item::TARGETTING_MODE_ONE);
274 inventory.Add(&sleepBall, 1);
276 multiBall.SetName("Multi-ball!");
277 multiBall.SetMenuIcon(&ballIcon);
278 multiBall.SetUsableInBattle();
279 multiBall.SetTargettingMode(Item::TARGETTING_MODE_ENEMY | Item::TARGETTING_MODE_MULTIPLE);
280 inventory.Add(&multiBall, 1);
282 figgoru.SetName("Figgoru");
283 figgoru.SetMenuIcon(&crankIcon);
284 figgoru.SetTargettingMode(Item::TARGETTING_MODE_ENEMY | Item::TARGETTING_MODE_ALL);
285 inventory.Add(&figgoru, 1);
286 battleRes.inventory = &inventory;
288 battleRes.itemMenuHeadline = "Please choose an item.";
289 battleRes.itemMenuPrototype = Menu<const common::Item *>(&normalFont, &disabledFont, &handCursorSprite, 15, 6, 8, 16, 1, 32, 2, ':');
291 battleRes.ikariMenuHeadline = "Please choose equipment.";
292 battleRes.ikariMenuPrototype = Menu</* Item */ void *>(&normalFont, &disabledFont, &handCursorSprite, 26, 6, 8, 16, 1, 32);
293 battleRes.ikariMenuPrototype.Add("Zirco whip Thundershriek", 0, false, &swordIcon);
294 battleRes.ikariMenuPrototype.Add("Zircon plate Sudden cure", 0, true, &armorIcon);
295 battleRes.ikariMenuPrototype.Add("Zirco gloves Forcefield", 0, true, &shieldIcon);
296 battleRes.ikariMenuPrototype.Add("Holy cap Vulnerable", 0, false, &helmetIcon);
297 battleRes.ikariMenuPrototype.Add("Ghost ring Destroy", 0, true, &ringIcon);
298 battleRes.ikariMenuPrototype.Add("Eagle rock Dive", 0, true, &stoneIcon);
300 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &battleRes));
301 battleState->AddMonster(monster);
302 battleState->AddMonster(monster);
303 battleState->AddMonster(monster);
304 battleState->AddMonster(monster);
305 battleState->AddHero(maxim);
306 battleState->AddHero(selan);
307 battleState->AddHero(guy);
308 battleState->AddHero(dekar);
309 Application app(&screen, battleState);
310 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
311 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
312 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
313 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
314 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
315 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
316 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
317 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
318 app.Buttons().MapKey(SDLK_RETURN, Input::START);
319 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
320 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
321 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
325 } catch (exception &e) {
326 cerr << "exception in main(): " << e.what() << endl;