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