]> git.localhorst.tv Git - l2e.git/blob - src/main.cpp
write hero's name on tag
[l2e.git] / src / main.cpp
1 /*
2  * main.cpp
3  *
4  *  Created on: Aug 1, 2012
5  *      Author: holy
6  */
7
8 #include "app/Application.h"
9 #include "app/Input.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"
23
24 #include <exception>
25 #include <iostream>
26 #include <SDL.h>
27 #include <SDL_image.h>
28
29 using app::Application;
30 using app::Input;
31 using battle::BattleState;
32 using battle::Hero;
33 using battle::Monster;
34 using battle::PartyLayout;
35 using geometry::Point;
36 using graphics::Font;
37 using graphics::Frame;
38 using graphics::Gauge;
39 using graphics::Sprite;
40 using sdl::InitImage;
41 using sdl::InitScreen;
42 using sdl::InitSDL;
43
44 using std::cerr;
45 using std::cout;
46 using std::endl;
47 using std::exception;
48
49 int main(int argc, char **argv) {
50         const int width = 800;
51         const int height = 480;
52
53         try {
54                 InitSDL sdl;
55                 InitImage image(IMG_INIT_PNG);
56                 InitScreen screen(width, height);
57
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));
70
71                 SDL_Surface *monsterImg(IMG_Load("test-data/monster.png"));
72                 Sprite dummySprite(monsterImg, 64, 64);
73                 Monster monster;
74                 monster.SetSprite(&dummySprite);
75
76                 SDL_Surface *maximImg(IMG_Load("test-data/maxim.png"));
77                 Sprite maximSprite(maximImg, 64, 64);
78                 Hero maxim;
79                 maxim.SetName("Maxim");
80                 maxim.SetLevel(1);
81                 maxim.SetSprite(&maximSprite);
82                 maxim.SetMaxHealth(33);
83                 maxim.SetHealth(33);
84                 maxim.SetMaxMana(20);
85                 maxim.SetMana(20);
86                 maxim.SetIP(0);
87
88                 SDL_Surface *selanImg(IMG_Load("test-data/selan.png"));
89                 Sprite selanSprite(selanImg, 64, 64);
90                 Hero selan;
91                 selan.SetName("Selan");
92                 selan.SetLevel(1);
93                 selan.SetSprite(&selanSprite);
94                 selan.SetMaxHealth(28);
95                 selan.SetHealth(28);
96                 selan.SetMaxMana(23);
97                 selan.SetMana(23);
98                 selan.SetIP(0);
99
100                 SDL_Surface *guyImg(IMG_Load("test-data/guy.png"));
101                 Sprite guySprite(guyImg, 64, 64);
102                 Hero guy;
103                 guy.SetName("Guy");
104                 guy.SetLevel(1);
105                 guy.SetSprite(&guySprite);
106                 guy.SetMaxHealth(38);
107                 guy.SetHealth(38);
108                 guy.SetMaxMana(0);
109                 guy.SetMana(0);
110                 guy.SetIP(0);
111
112                 SDL_Surface *dekarImg(IMG_Load("test-data/dekar.png"));
113                 Sprite dekarSprite(dekarImg, 64, 64);
114                 Hero dekar;
115                 dekar.SetName("Dekar");
116                 dekar.SetLevel(1);
117                 dekar.SetSprite(&dekarSprite);
118                 dekar.SetMaxHealth(38);
119                 dekar.SetHealth(38);
120                 dekar.SetMaxMana(0);
121                 dekar.SetMana(0);
122                 dekar.SetIP(0);
123
124                 battle::Resources battleRes;
125
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;
144
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;
152
153                 SDL_Surface *selectFrameImg(IMG_Load("test-data/select-frame.png"));
154                 Frame selectFrame(selectFrameImg, 16, 16);
155                 battleRes.selectFrame = &selectFrame;
156
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;
165
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);
188                 app.Run();
189
190                 return 0;
191         } catch (exception &e) {
192                 cerr << "exception in main(): " << e.what() << endl;
193                 return 1;
194         }
195 }