]> git.localhorst.tv Git - l2e.git/blob - src/main.cpp
c8668dca1145f8c3da24bca4d50691be768b9c02
[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 "geometry/Point.h"
15 #include "graphics/Font.h"
16 #include "graphics/Frame.h"
17 #include "graphics/Gauge.h"
18 #include "graphics/Sprite.h"
19 #include "sdl/InitImage.h"
20 #include "sdl/InitScreen.h"
21 #include "sdl/InitSDL.h"
22
23 #include <exception>
24 #include <iostream>
25 #include <SDL.h>
26 #include <SDL_image.h>
27
28 using app::Application;
29 using app::Input;
30 using battle::BattleState;
31 using battle::Hero;
32 using battle::Monster;
33 using battle::PartyLayout;
34 using geometry::Point;
35 using graphics::Font;
36 using graphics::Frame;
37 using graphics::Gauge;
38 using graphics::Sprite;
39 using sdl::InitImage;
40 using sdl::InitScreen;
41 using sdl::InitSDL;
42
43 using std::cerr;
44 using std::cout;
45 using std::endl;
46 using std::exception;
47
48 int main(int argc, char **argv) {
49         const int width = 800;
50         const int height = 480;
51
52         try {
53                 InitSDL sdl;
54                 InitImage image(IMG_INIT_PNG);
55                 InitScreen screen(width, height);
56
57                 // temporary test data
58                 SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
59                 PartyLayout monstersLayout;
60                 monstersLayout.AddPosition(Point<Uint8>(88, 104));
61                 monstersLayout.AddPosition(Point<Uint8>(128, 104));
62                 monstersLayout.AddPosition(Point<Uint8>(168, 104));
63                 monstersLayout.AddPosition(Point<Uint8>(208, 104));
64                 PartyLayout heroesLayout;
65                 heroesLayout.AddPosition(Point<Uint8>(27, 219));
66                 heroesLayout.AddPosition(Point<Uint8>(104, 227));
67                 heroesLayout.AddPosition(Point<Uint8>(66, 238));
68                 heroesLayout.AddPosition(Point<Uint8>(143, 246));
69
70                 SDL_Surface *monsterImg(IMG_Load("test-data/monster.png"));
71                 Sprite dummySprite(monsterImg, 64, 64);
72                 Monster monster;
73                 monster.SetSprite(&dummySprite);
74
75                 SDL_Surface *maximImg(IMG_Load("test-data/maxim.png"));
76                 Sprite maximSprite(maximImg, 64, 64);
77                 Hero maxim;
78                 maxim.SetName("Maxim");
79                 maxim.SetLevel(1);
80                 maxim.SetSprite(&maximSprite);
81                 maxim.SetMaxHealth(33);
82                 maxim.SetHealth(33);
83                 maxim.SetMaxMana(20);
84                 maxim.SetMana(20);
85                 maxim.SetIP(0);
86
87                 SDL_Surface *selanImg(IMG_Load("test-data/selan.png"));
88                 Sprite selanSprite(selanImg, 64, 64);
89                 Hero selan;
90                 selan.SetName("Selan");
91                 selan.SetLevel(1);
92                 selan.SetSprite(&selanSprite);
93                 selan.SetMaxHealth(28);
94                 selan.SetHealth(28);
95                 selan.SetMaxMana(23);
96                 selan.SetMana(23);
97                 selan.SetIP(0);
98
99                 SDL_Surface *guyImg(IMG_Load("test-data/guy.png"));
100                 Sprite guySprite(guyImg, 64, 64);
101                 Hero guy;
102                 guy.SetName("Guy");
103                 guy.SetLevel(1);
104                 guy.SetSprite(&guySprite);
105                 guy.SetMaxHealth(38);
106                 guy.SetHealth(38);
107                 guy.SetMaxMana(0);
108                 guy.SetMana(0);
109                 guy.SetIP(0);
110
111                 SDL_Surface *dekarImg(IMG_Load("test-data/dekar.png"));
112                 Sprite dekarSprite(dekarImg, 64, 64);
113                 Hero dekar;
114                 dekar.SetName("Dekar");
115                 dekar.SetLevel(1);
116                 dekar.SetSprite(&dekarSprite);
117                 dekar.SetMaxHealth(38);
118                 dekar.SetHealth(38);
119                 dekar.SetMaxMana(0);
120                 dekar.SetMana(0);
121                 dekar.SetIP(0);
122
123                 SDL_Surface *attackIcons(IMG_Load("test-data/attack-type-icons.png"));
124                 Sprite attackIconsSprite(attackIcons, 32, 32);
125                 SDL_Surface *moveIcons(IMG_Load("test-data/move-icons.png"));
126                 Sprite moveIconsSprite(moveIcons, 32, 32);
127                 SDL_Surface *heroTagSprites(IMG_Load("test-data/hero-tag-sprites.png"));
128                 Sprite heroTagSprite(heroTagSprites, 32, 16);
129                 SDL_Surface *numbers(IMG_Load("test-data/numbers.png"));
130                 Sprite numbersSprite(numbers, 16, 16);
131                 Font heroTagFont(&numbersSprite);
132                 SDL_Surface *tagFrames(IMG_Load("test-data/tag-frames.png"));
133                 Frame heroTagFrame(tagFrames, 16, 16, 1, 1, 0, 33);
134                 Frame activeHeroTagFrame(tagFrames, 16, 16);
135
136                 SDL_Surface *gauges(IMG_Load("test-data/gauges.png"));
137                 Gauge healthGauge(gauges, 0, 16, 0, 0, 16, 6, 1, 6);
138                 Gauge manaGauge(gauges, 0, 32, 0, 0, 16, 6, 1, 6);
139                 Gauge ikariGauge(gauges, 0, 48, 0, 0, 16, 6, 1, 6);
140
141                 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &attackIconsSprite, &moveIconsSprite, &heroTagFrame, &activeHeroTagFrame, &healthGauge, &manaGauge, &ikariGauge, &heroTagSprite, &heroTagFont));
142                 battleState->AddMonster(monster);
143                 battleState->AddMonster(monster);
144                 battleState->AddMonster(monster);
145                 battleState->AddMonster(monster);
146                 battleState->AddHero(maxim);
147                 battleState->AddHero(selan);
148                 battleState->AddHero(guy);
149                 battleState->AddHero(dekar);
150                 Application app(&screen, battleState);
151                 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
152                 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
153                 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
154                 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
155                 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
156                 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
157                 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
158                 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
159                 app.Buttons().MapKey(SDLK_RETURN, Input::START);
160                 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
161                 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
162                 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
163                 app.Run();
164
165                 return 0;
166         } catch (exception &e) {
167                 cerr << "exception in main(): " << e.what() << endl;
168                 return 1;
169         }
170 }