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/Sprite.h"
20 #include "sdl/InitImage.h"
21 #include "sdl/InitScreen.h"
22 #include "sdl/InitSDL.h"
27 #include <SDL_image.h>
29 using app::Application;
31 using battle::BattleState;
33 using battle::Monster;
34 using battle::PartyLayout;
35 using geometry::Point;
37 using graphics::Frame;
38 using graphics::Gauge;
39 using graphics::Sprite;
41 using sdl::InitScreen;
49 int main(int argc, char **argv) {
50 const int width = 800;
51 const int height = 480;
55 InitImage image(IMG_INIT_PNG);
56 InitScreen screen(width, height);
58 // temporary test data
59 SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
60 PartyLayout monstersLayout;
61 monstersLayout.AddPosition(Point<Uint8>(88, 104));
62 monstersLayout.AddPosition(Point<Uint8>(128, 104));
63 monstersLayout.AddPosition(Point<Uint8>(168, 104));
64 monstersLayout.AddPosition(Point<Uint8>(208, 104));
65 PartyLayout heroesLayout;
66 heroesLayout.AddPosition(Point<Uint8>(27, 219));
67 heroesLayout.AddPosition(Point<Uint8>(104, 227));
68 heroesLayout.AddPosition(Point<Uint8>(66, 238));
69 heroesLayout.AddPosition(Point<Uint8>(143, 246));
71 SDL_Surface *monsterImg(IMG_Load("test-data/monster.png"));
72 Sprite dummySprite(monsterImg, 64, 64);
74 monster.SetSprite(&dummySprite);
76 SDL_Surface *maximImg(IMG_Load("test-data/maxim.png"));
77 Sprite maximSprite(maximImg, 64, 64);
79 maxim.SetName("Maxim");
81 maxim.SetSprite(&maximSprite);
82 maxim.SetMaxHealth(33);
88 SDL_Surface *selanImg(IMG_Load("test-data/selan.png"));
89 Sprite selanSprite(selanImg, 64, 64);
91 selan.SetName("Selan");
93 selan.SetSprite(&selanSprite);
94 selan.SetMaxHealth(28);
100 SDL_Surface *guyImg(IMG_Load("test-data/guy.png"));
101 Sprite guySprite(guyImg, 64, 64);
105 guy.SetSprite(&guySprite);
106 guy.SetMaxHealth(38);
112 SDL_Surface *dekarImg(IMG_Load("test-data/dekar.png"));
113 Sprite dekarSprite(dekarImg, 64, 64);
115 dekar.SetName("Dekar");
117 dekar.SetSprite(&dekarSprite);
118 dekar.SetMaxHealth(38);
124 battle::Resources battleRes;
126 SDL_Surface *attackIconsImg(IMG_Load("test-data/attack-type-icons.png"));
127 Sprite attackIconsSprite(attackIconsImg, 32, 32);
128 battleRes.attackIcons = &attackIconsSprite;
129 SDL_Surface *moveIconsImg(IMG_Load("test-data/move-icons.png"));
130 Sprite moveIconsSprite(moveIconsImg, 32, 32);
131 battleRes.moveIcons = &moveIconsSprite;
132 SDL_Surface *heroTagImg(IMG_Load("test-data/hero-tag-sprites.png"));
133 Sprite heroTagSprite(heroTagImg, 32, 16);
134 battleRes.heroTagLabels = &heroTagSprite;
135 SDL_Surface *numbersImg(IMG_Load("test-data/numbers.png"));
136 Sprite numbersSprite(numbersImg, 16, 16);
137 Font heroTagFont(&numbersSprite);
138 battleRes.heroTagFont = &heroTagFont;
139 SDL_Surface *tagFramesImg(IMG_Load("test-data/tag-frames.png"));
140 Frame heroTagFrame(tagFramesImg, 16, 16, 1, 1, 0, 33);
141 battleRes.heroTagFrame = &heroTagFrame;
142 Frame activeHeroTagFrame(tagFramesImg, 16, 16);
143 battleRes.activeHeroTagFrame = &activeHeroTagFrame;
145 SDL_Surface *gauges(IMG_Load("test-data/gauges.png"));
146 Gauge healthGauge(gauges, 0, 16, 0, 0, 16, 6, 1, 6);
147 battleRes.healthGauge = &healthGauge;
148 Gauge manaGauge(gauges, 0, 32, 0, 0, 16, 6, 1, 6);
149 battleRes.manaGauge = &manaGauge;
150 Gauge ikariGauge(gauges, 0, 48, 0, 0, 16, 6, 1, 6);
151 battleRes.ikariGauge = &ikariGauge;
153 SDL_Surface *selectFrameImg(IMG_Load("test-data/select-frame.png"));
154 Frame selectFrame(selectFrameImg, 16, 16);
155 battleRes.selectFrame = &selectFrame;
157 SDL_Surface *normalFontImg(IMG_Load("test-data/normal-font.png"));
158 Sprite normalFontSprite(normalFontImg, 16, 16);
159 Font normalFont(&normalFontSprite);
160 normalFont.MapRange('A', 'M', 0, 1);
161 normalFont.MapRange('N', 'Z', 0, 2);
162 normalFont.MapRange('a', 'm', 0, 3);
163 normalFont.MapRange('n', 'z', 0, 4);
164 battleRes.normalFont = &normalFont;
166 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &battleRes));
167 battleState->AddMonster(monster);
168 battleState->AddMonster(monster);
169 battleState->AddMonster(monster);
170 battleState->AddMonster(monster);
171 battleState->AddHero(maxim);
172 battleState->AddHero(selan);
173 battleState->AddHero(guy);
174 battleState->AddHero(dekar);
175 Application app(&screen, battleState);
176 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
177 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
178 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
179 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
180 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
181 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
182 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
183 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
184 app.Buttons().MapKey(SDLK_RETURN, Input::START);
185 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
186 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
187 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
191 } catch (exception &e) {
192 cerr << "exception in main(): " << e.what() << endl;