]> git.localhorst.tv Git - l2e.git/blob - src/main.cpp
added Input class for handling user input
[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/Sprite.h"
16 #include "sdl/InitScreen.h"
17 #include "sdl/InitSDL.h"
18
19 #include <exception>
20 #include <iostream>
21
22 using app::Application;
23 using app::Input;
24 using battle::BattleState;
25 using battle::Hero;
26 using battle::Monster;
27 using battle::PartyLayout;
28 using geometry::Point;
29 using graphics::Sprite;
30 using sdl::InitScreen;
31 using sdl::InitSDL;
32
33 using std::cerr;
34 using std::cout;
35 using std::endl;
36 using std::exception;
37
38 int main(int argc, char **argv) {
39         const int width = 800;
40         const int height = 480;
41
42         // temporary test data
43         SDL_Surface *bg(SDL_CreateRGBSurface(0, width, height, 32, 0xFF000000, 0xFF0000, 0xFF00, 0xFF));
44         SDL_FillRect(bg, 0, SDL_MapRGB(bg->format, 0xFF, 0xFF, 0xFF));
45         SDL_Rect r;
46         r.x = 1;
47         r.y = 1;
48         r.w = width - 2;
49         r.h = height - 2;
50         SDL_FillRect(bg, &r, SDL_MapRGB(bg->format, 0, 0, 0));
51         PartyLayout monstersLayout;
52         monstersLayout.AddPosition(Point<Uint8>(50, 100));
53         monstersLayout.AddPosition(Point<Uint8>(100, 100));
54         monstersLayout.AddPosition(Point<Uint8>(150, 100));
55         monstersLayout.AddPosition(Point<Uint8>(200, 100));
56         PartyLayout heroesLayout;
57         heroesLayout.AddPosition(Point<Uint8>(27, 219));
58         heroesLayout.AddPosition(Point<Uint8>(104, 227));
59         heroesLayout.AddPosition(Point<Uint8>(66, 238));
60         heroesLayout.AddPosition(Point<Uint8>(143, 246));
61         SDL_Surface *white96(SDL_CreateRGBSurface(0, 96, 96, 32, 0xFF000000, 0xFF0000, 0xFF00, 0xFF));
62         SDL_FillRect(white96, 0, SDL_MapRGB(bg->format, 0xFF, 0xFF, 0xFF));
63         Sprite dummySprite(white96, 96, 96);
64         Monster monster;
65         monster.SetSprite(&dummySprite);
66         Hero hero;
67         hero.SetSprite(&dummySprite);
68
69         try {
70                 InitSDL sdl;
71                 InitScreen screen(width, height);
72
73                 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout));
74                 battleState->AddMonster(monster);
75                 battleState->AddMonster(monster);
76                 battleState->AddMonster(monster);
77                 battleState->AddMonster(monster);
78                 battleState->AddHero(hero);
79                 battleState->AddHero(hero);
80                 battleState->AddHero(hero);
81                 battleState->AddHero(hero);
82                 Application app(&screen, battleState);
83                 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
84                 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
85                 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
86                 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
87                 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
88                 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
89                 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
90                 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
91                 app.Buttons().MapKey(SDLK_RETURN, Input::START);
92                 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
93                 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
94                 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
95                 app.Run();
96
97                 return 0;
98         } catch (exception &e) {
99                 cerr << "exception in main(): " << e.what() << endl;
100                 return 1;
101         }
102 }