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 *moveIconsImg(IMG_Load("test-data/move-icons.png"));
132 Sprite moveIconsSprite(moveIconsImg, 32, 32);
133 battleRes.moveIcons = &moveIconsSprite;
134 SDL_Surface *heroTagImg(IMG_Load("test-data/hero-tag-sprites.png"));
135 Sprite heroTagSprite(heroTagImg, 32, 16);
136 battleRes.heroTagLabels = &heroTagSprite;
137 SDL_Surface *numbersImg(IMG_Load("test-data/numbers.png"));
138 Sprite numbersSprite(numbersImg, 16, 16);
139 Font heroTagFont(&numbersSprite);
140 battleRes.heroTagFont = &heroTagFont;
141 SDL_Surface *tagFramesImg(IMG_Load("test-data/tag-frames.png"));
142 Frame heroTagFrame(tagFramesImg, 16, 16, 1, 1, 0, 33);
143 battleRes.heroTagFrame = &heroTagFrame;
144 Frame activeHeroTagFrame(tagFramesImg, 16, 16);
145 battleRes.activeHeroTagFrame = &activeHeroTagFrame;
147 SDL_Surface *gauges(IMG_Load("test-data/gauges.png"));
148 Gauge healthGauge(gauges, 0, 16, 0, 0, 16, 6, 1, 6);
149 battleRes.healthGauge = &healthGauge;
150 Gauge manaGauge(gauges, 0, 32, 0, 0, 16, 6, 1, 6);
151 battleRes.manaGauge = &manaGauge;
152 Gauge ikariGauge(gauges, 0, 48, 0, 0, 16, 6, 1, 6);
153 battleRes.ikariGauge = &ikariGauge;
155 SDL_Surface *selectFrameImg(IMG_Load("test-data/select-frame.png"));
156 Frame selectFrame(selectFrameImg, 16, 16);
157 battleRes.selectFrame = &selectFrame;
159 SDL_Surface *normalFontImg(IMG_Load("test-data/normal-font.png"));
160 Sprite normalFontSprite(normalFontImg, 16, 16);
161 Font normalFont(&normalFontSprite);
162 normalFont.MapRange('A', 'M', 0, 1);
163 normalFont.MapRange('N', 'Z', 0, 2);
164 normalFont.MapRange('a', 'm', 0, 3);
165 normalFont.MapRange('n', 'z', 0, 4);
166 normalFont.MapChar(':', 10, 0);
167 normalFont.MapChar('!', 10, 0);
168 normalFont.MapChar('?', 10, 0);
169 battleRes.normalFont = &normalFont;
171 battleRes.spellMenuPrototype = Menu</* Spell */ void *>(&normalFont, 12, 6, 8, 2, 32);
173 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &battleRes));
174 battleState->AddMonster(monster);
175 battleState->AddMonster(monster);
176 battleState->AddMonster(monster);
177 battleState->AddMonster(monster);
178 battleState->AddHero(maxim);
179 battleState->AddHero(selan);
180 battleState->AddHero(guy);
181 battleState->AddHero(dekar);
182 Application app(&screen, battleState);
183 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
184 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
185 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
186 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
187 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
188 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
189 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
190 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
191 app.Buttons().MapKey(SDLK_RETURN, Input::START);
192 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
193 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
194 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
198 } catch (exception &e) {
199 cerr << "exception in main(): " << e.what() << endl;