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);
82 SDL_Surface *maximImg(IMG_Load("test-data/maxim.png"));
83 Sprite maximSprite(maximImg, 64, 64);
85 maxim.SetName("Maxim");
87 maxim.SetSprite(&maximSprite);
88 maxim.SetMaxHealth(33);
94 SDL_Surface *selanImg(IMG_Load("test-data/selan.png"));
95 Sprite selanSprite(selanImg, 64, 64);
97 selan.SetName("Selan");
99 selan.SetSprite(&selanSprite);
100 selan.SetMaxHealth(28);
102 selan.SetMaxMana(23);
106 SDL_Surface *guyImg(IMG_Load("test-data/guy.png"));
107 Sprite guySprite(guyImg, 64, 64);
111 guy.SetSprite(&guySprite);
112 guy.SetMaxHealth(38);
118 SDL_Surface *dekarImg(IMG_Load("test-data/dekar.png"));
119 Sprite dekarSprite(dekarImg, 64, 64);
121 dekar.SetName("Dekar");
123 dekar.SetSprite(&dekarSprite);
124 dekar.SetMaxHealth(38);
130 battle::Resources battleRes;
132 SDL_Surface *attackIconsImg(IMG_Load("test-data/attack-type-icons.png"));
133 Sprite attackIconsSprite(attackIconsImg, 32, 32);
134 battleRes.attackIcons = &attackIconsSprite;
135 SDL_Surface *attackChoiceIconsImg(IMG_Load("test-data/attack-choice-icons.png"));
136 Sprite attackChoiceIconsSprite(attackChoiceIconsImg, 16, 16);
137 battleRes.attackChoiceIcons = &attackChoiceIconsSprite;
138 SDL_Surface *moveIconsImg(IMG_Load("test-data/move-icons.png"));
139 Sprite moveIconsSprite(moveIconsImg, 32, 32);
140 battleRes.moveIcons = &moveIconsSprite;
141 SDL_Surface *heroTagImg(IMG_Load("test-data/hero-tag-sprites.png"));
142 Sprite heroTagSprite(heroTagImg, 32, 16);
143 battleRes.heroTagLabels = &heroTagSprite;
144 SDL_Surface *numbersImg(IMG_Load("test-data/numbers.png"));
145 Sprite numbersSprite(numbersImg, 16, 16);
146 Font heroTagFont(&numbersSprite);
147 battleRes.heroTagFont = &heroTagFont;
148 SDL_Surface *tagFramesImg(IMG_Load("test-data/tag-frames.png"));
149 Frame heroTagFrame(tagFramesImg, 16, 16, 1, 1, 0, 33);
150 battleRes.heroTagFrame = &heroTagFrame;
151 Frame activeHeroTagFrame(tagFramesImg, 16, 16);
152 battleRes.activeHeroTagFrame = &activeHeroTagFrame;
154 SDL_Surface *gauges(IMG_Load("test-data/gauges.png"));
155 Gauge healthGauge(gauges, 0, 16, 0, 0, 16, 6, 1, 6);
156 battleRes.healthGauge = &healthGauge;
157 Gauge manaGauge(gauges, 0, 32, 0, 0, 16, 6, 1, 6);
158 battleRes.manaGauge = &manaGauge;
159 Gauge ikariGauge(gauges, 0, 48, 0, 0, 16, 6, 1, 6);
160 battleRes.ikariGauge = &ikariGauge;
162 SDL_Surface *selectFrameImg(IMG_Load("test-data/select-frame.png"));
163 Frame selectFrame(selectFrameImg, 16, 16);
164 battleRes.selectFrame = &selectFrame;
166 SDL_Surface *normalFontImg(IMG_Load("test-data/normal-font.png"));
167 Sprite normalFontSprite(normalFontImg, 16, 16);
168 Font normalFont(&normalFontSprite);
169 normalFont.MapRange('A', 'M', 0, 1);
170 normalFont.MapRange('N', 'Z', 0, 2);
171 normalFont.MapRange('a', 'm', 0, 3);
172 normalFont.MapRange('n', 'z', 0, 4);
173 normalFont.MapChar(':', 10, 0);
174 normalFont.MapChar('!', 10, 0);
175 normalFont.MapChar('?', 10, 0);
176 // TODO: add '.' and '-' characters
177 battleRes.normalFont = &normalFont;
179 SDL_Surface *disabledFontImg(IMG_Load("test-data/disabled-font.png"));
180 Sprite disabledFontSprite(disabledFontImg, 16, 16);
181 Font disabledFont(&disabledFontSprite);
182 disabledFont.MapRange('A', 'M', 0, 1);
183 disabledFont.MapRange('N', 'Z', 0, 2);
184 disabledFont.MapRange('a', 'm', 0, 3);
185 disabledFont.MapRange('n', 'z', 0, 4);
186 disabledFont.MapChar(':', 10, 0);
187 disabledFont.MapChar('!', 10, 0);
188 disabledFont.MapChar('?', 10, 0);
189 // TODO: add '.' and '-' characters
190 battleRes.disabledFont = &disabledFont;
192 SDL_Surface *handCursorImg(IMG_Load("test-data/cursor-hand.png"));
193 Sprite handCursorSprite(handCursorImg, 32, 32);
194 battleRes.menuCursor = &handCursorSprite;
196 battleRes.spellMenuHeadline = "Please choose a spell.";
197 battleRes.spellMenuPrototype = Menu</* Spell */ void *>(&normalFont, &disabledFont, &handCursorSprite, 12, 6, 8, 0, 2, 32);
198 battleRes.spellMenuPrototype.Add("Reset : 0", 0, false);
199 battleRes.spellMenuPrototype.Add("Strong : 3", 0);
200 battleRes.spellMenuPrototype.Add("Stronger : 8", 0);
201 battleRes.spellMenuPrototype.Add("Champion :16", 0);
202 battleRes.spellMenuPrototype.Add("Rally :10", 0);
203 battleRes.spellMenuPrototype.Add("Escape : 8", 0, false);
204 battleRes.spellMenuPrototype.Add("Valor :30", 0);
205 battleRes.spellMenuPrototype.Add("Poison : 2", 0);
206 battleRes.spellMenuPrototype.Add("Warp : 8", 0, false);
207 battleRes.spellMenuPrototype.Add("Release : 2", 0);
208 battleRes.spellMenuPrototype.Add("Waken : 4", 0);
209 battleRes.spellMenuPrototype.Add("Light : 0", 0, false);
210 battleRes.spellMenuPrototype.Add("Fake : 4", 0);
211 battleRes.spellMenuPrototype.Add("Trick : 5", 0);
212 battleRes.spellMenuPrototype.Add("Flash : 5", 0);
213 battleRes.spellMenuPrototype.Add("Fireball : 6", 0);
214 battleRes.spellMenuPrototype.Add("Vortex : 7", 0);
215 battleRes.spellMenuPrototype.Add("Blizzard : 8", 0);
216 battleRes.spellMenuPrototype.Add("Spark : 3", 0);
218 SDL_Surface *itemIcons(IMG_Load("test-data/item-icons.png"));
219 Sprite potionIcon(itemIcons, 16, 16);
220 Sprite ballIcon(itemIcons, 16, 16, 0, 16);
221 Sprite crankIcon(itemIcons, 16, 16, 0, 32);
222 Sprite spearIcon(itemIcons, 16, 16, 0, 48);
223 Sprite swordIcon(itemIcons, 16, 16, 0, 64);
224 Sprite axIcon(itemIcons, 16, 16, 0, 80);
225 Sprite rodIcon(itemIcons, 16, 16, 0, 96);
226 Sprite armorIcon(itemIcons, 16, 16, 0, 112);
227 Sprite shieldIcon(itemIcons, 16, 16, 0, 128);
228 Sprite helmetIcon(itemIcons, 16, 16, 0, 144);
229 Sprite ringIcon(itemIcons, 16, 16, 0, 160);
230 Sprite stoneIcon(itemIcons, 16, 16, 0, 176);
234 antidote.SetName("Antidote");
235 antidote.SetMenuIcon(&potionIcon);
236 antidote.SetUsableInBattle();
237 inventory.Add(&antidote, 9);
239 magicJar.SetName("Magic jar");
240 magicJar.SetMenuIcon(&potionIcon);
241 magicJar.SetUsableInBattle();
242 inventory.Add(&magicJar, 4);
244 hiPotion.SetName("Hi-Potion");
245 hiPotion.SetMenuIcon(&potionIcon);
246 hiPotion.SetUsableInBattle();
247 inventory.Add(&hiPotion, 4);
249 powerPotion.SetName("Power potion");
250 powerPotion.SetMenuIcon(&potionIcon);
251 inventory.Add(&powerPotion, 4);
253 escape.SetName("Escape");
254 inventory.Add(&escape, 2);
256 sleepBall.SetName("Sleep ball");
257 sleepBall.SetMenuIcon(&ballIcon);
258 sleepBall.SetUsableInBattle();
259 inventory.Add(&sleepBall, 1);
261 figgoru.SetName("Figgoru");
262 figgoru.SetMenuIcon(&crankIcon);
263 inventory.Add(&figgoru, 1);
264 battleRes.inventory = &inventory;
266 battleRes.itemMenuHeadline = "Please choose an item.";
267 battleRes.itemMenuPrototype = Menu<const common::Item *>(&normalFont, &disabledFont, &handCursorSprite, 15, 6, 8, 16, 1, 32, 2, ':');
269 battleRes.ikariMenuHeadline = "Please choose equipment.";
270 battleRes.ikariMenuPrototype = Menu</* Item */ void *>(&normalFont, &disabledFont, &handCursorSprite, 26, 6, 8, 16, 1, 32);
271 battleRes.ikariMenuPrototype.Add("Zirco whip Thundershriek", 0, false, &swordIcon);
272 battleRes.ikariMenuPrototype.Add("Zircon plate Sudden cure", 0, true, &armorIcon);
273 battleRes.ikariMenuPrototype.Add("Zirco gloves Forcefield", 0, true, &shieldIcon);
274 battleRes.ikariMenuPrototype.Add("Holy cap Vulnerable", 0, false, &helmetIcon);
275 battleRes.ikariMenuPrototype.Add("Ghost ring Destroy", 0, true, &ringIcon);
276 battleRes.ikariMenuPrototype.Add("Eagle rock Dive", 0, true, &stoneIcon);
278 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &battleRes));
279 battleState->AddMonster(monster);
280 battleState->AddMonster(monster);
281 battleState->AddMonster(monster);
282 battleState->AddMonster(monster);
283 battleState->AddHero(maxim);
284 battleState->AddHero(selan);
285 battleState->AddHero(guy);
286 battleState->AddHero(dekar);
287 Application app(&screen, battleState);
288 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
289 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
290 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
291 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
292 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
293 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
294 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
295 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
296 app.Buttons().MapKey(SDLK_RETURN, Input::START);
297 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
298 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
299 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
303 } catch (exception &e) {
304 cerr << "exception in main(): " << e.what() << endl;