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