]> git.localhorst.tv Git - l2e.git/blob - src/main.cpp
e2304337f11b3147340eed50338c0d71a718f892
[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/Frame.h"
16 #include "graphics/Gauge.h"
17 #include "graphics/Sprite.h"
18 #include "sdl/InitImage.h"
19 #include "sdl/InitScreen.h"
20 #include "sdl/InitSDL.h"
21
22 #include <exception>
23 #include <iostream>
24 #include <SDL.h>
25 #include <SDL_image.h>
26
27 using app::Application;
28 using app::Input;
29 using battle::BattleState;
30 using battle::Hero;
31 using battle::Monster;
32 using battle::PartyLayout;
33 using geometry::Point;
34 using graphics::Frame;
35 using graphics::Gauge;
36 using graphics::Sprite;
37 using sdl::InitImage;
38 using sdl::InitScreen;
39 using sdl::InitSDL;
40
41 using std::cerr;
42 using std::cout;
43 using std::endl;
44 using std::exception;
45
46 int main(int argc, char **argv) {
47         const int width = 800;
48         const int height = 480;
49
50         try {
51                 InitSDL sdl;
52                 InitImage image(IMG_INIT_PNG);
53                 InitScreen screen(width, height);
54
55                 // temporary test data
56                 SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
57                 PartyLayout monstersLayout;
58                 monstersLayout.AddPosition(Point<Uint8>(50, 100));
59                 monstersLayout.AddPosition(Point<Uint8>(100, 108));
60                 monstersLayout.AddPosition(Point<Uint8>(150, 100));
61                 monstersLayout.AddPosition(Point<Uint8>(200, 108));
62                 PartyLayout heroesLayout;
63                 heroesLayout.AddPosition(Point<Uint8>(27, 219));
64                 heroesLayout.AddPosition(Point<Uint8>(104, 227));
65                 heroesLayout.AddPosition(Point<Uint8>(66, 238));
66                 heroesLayout.AddPosition(Point<Uint8>(143, 246));
67
68                 SDL_Surface *monsterImg(IMG_Load("test-data/monster.png"));
69                 Sprite dummySprite(monsterImg, 96, 96);
70                 Monster monster;
71                 monster.SetSprite(&dummySprite);
72
73                 SDL_Surface *heroImg(IMG_Load("test-data/hero.png"));
74                 Sprite heroSprite(heroImg, 64, 64);
75                 Hero hero;
76                 hero.SetName("Name");
77                 hero.SetLevel(34);
78                 hero.SetSprite(&heroSprite);
79                 hero.SetMaxHealth(100);
80                 hero.SetHealth(50);
81                 hero.SetMaxMana(100);
82                 hero.SetMana(0);
83                 hero.SetIP(255);
84
85                 SDL_Surface *attackIcons(IMG_Load("test-data/attack-type-icons.png"));
86                 Sprite attackIconsSprite(attackIcons, 32, 32);
87                 SDL_Surface *moveIcons(IMG_Load("test-data/move-icons.png"));
88                 Sprite moveIconsSprite(moveIcons, 32, 32);
89                 SDL_Surface *tagFrames(IMG_Load("test-data/tag-frames.png"));
90                 Frame heroTagFrame(tagFrames, 16, 16, 1, 1, 0, 33);
91                 Frame activeHeroTagFrame(tagFrames, 16, 16);
92
93                 SDL_Surface *gauges(IMG_Load("test-data/gauges.png"));
94                 Gauge healthGauge(gauges, 0, 16, 0, 0, 16, 6, 1, 6);
95                 Gauge manaGauge(gauges, 0, 32, 0, 0, 16, 6, 1, 6);
96                 Gauge ikariGauge(gauges, 0, 48, 0, 0, 16, 6, 1, 6);
97
98                 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &attackIconsSprite, &moveIconsSprite, &heroTagFrame, &activeHeroTagFrame, &healthGauge, &manaGauge, &ikariGauge));
99                 battleState->AddMonster(monster);
100                 battleState->AddMonster(monster);
101                 battleState->AddMonster(monster);
102                 battleState->AddMonster(monster);
103                 battleState->AddHero(hero);
104                 battleState->AddHero(hero);
105                 battleState->AddHero(hero);
106                 battleState->AddHero(hero);
107                 Application app(&screen, battleState);
108                 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
109                 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
110                 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
111                 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
112                 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
113                 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
114                 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
115                 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
116                 app.Buttons().MapKey(SDLK_RETURN, Input::START);
117                 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
118                 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
119                 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
120                 app.Run();
121
122                 return 0;
123         } catch (exception &e) {
124                 cerr << "exception in main(): " << e.what() << endl;
125                 return 1;
126         }
127 }