]> git.localhorst.tv Git - l2e.git/blob - src/main.cpp
added battle move menu
[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.SetName("Name");
77                 hero.SetLevel(34);
78                 hero.SetSprite(&dummySprite);
79                 hero.SetMaxHealth(100);
80                 hero.SetHealth(50);
81                 hero.SetMaxMana(100);
82                 hero.SetMana(66);
83                 hero.SetIP(160);
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
90                 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &attackIconsSprite, &moveIconsSprite));
91                 battleState->AddMonster(monster);
92                 battleState->AddMonster(monster);
93                 battleState->AddMonster(monster);
94                 battleState->AddMonster(monster);
95                 battleState->AddHero(hero);
96                 battleState->AddHero(hero);
97                 battleState->AddHero(hero);
98                 battleState->AddHero(hero);
99                 Application app(&screen, battleState);
100                 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
101                 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
102                 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
103                 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
104                 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
105                 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
106                 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
107                 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
108                 app.Buttons().MapKey(SDLK_RETURN, Input::START);
109                 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
110                 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
111                 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
112                 app.Run();
113
114                 return 0;
115         } catch (exception &e) {
116                 cerr << "exception in main(): " << e.what() << endl;
117                 return 1;
118         }
119 }