]> git.localhorst.tv Git - l2e.git/blob - src/main.cpp
added some test sprites
[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(IMG_Load("test-data/battle-bg.png"));
53                 PartyLayout monstersLayout;
54                 monstersLayout.AddPosition(Point<Uint8>(50, 100));
55                 monstersLayout.AddPosition(Point<Uint8>(100, 108));
56                 monstersLayout.AddPosition(Point<Uint8>(150, 100));
57                 monstersLayout.AddPosition(Point<Uint8>(200, 108));
58                 PartyLayout heroesLayout;
59                 heroesLayout.AddPosition(Point<Uint8>(27, 219));
60                 heroesLayout.AddPosition(Point<Uint8>(104, 227));
61                 heroesLayout.AddPosition(Point<Uint8>(66, 238));
62                 heroesLayout.AddPosition(Point<Uint8>(143, 246));
63
64                 SDL_Surface *monsterImg(IMG_Load("test-data/monster.png"));
65                 Sprite dummySprite(monsterImg, 96, 96);
66                 Monster monster;
67                 monster.SetSprite(&dummySprite);
68
69                 SDL_Surface *heroImg(IMG_Load("test-data/hero.png"));
70                 Sprite heroSprite(heroImg, 96, 96);
71                 Hero hero;
72                 hero.SetName("Name");
73                 hero.SetLevel(34);
74                 hero.SetSprite(&heroSprite);
75                 hero.SetMaxHealth(100);
76                 hero.SetHealth(50);
77                 hero.SetMaxMana(100);
78                 hero.SetMana(66);
79                 hero.SetIP(160);
80
81                 SDL_Surface *attackIcons(IMG_Load("test-data/attack-type-icons.png"));
82                 Sprite attackIconsSprite(attackIcons, 32, 32);
83                 SDL_Surface *moveIcons(IMG_Load("test-data/move-icons.png"));
84                 Sprite moveIconsSprite(moveIcons, 32, 32);
85
86                 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &attackIconsSprite, &moveIconsSprite));
87                 battleState->AddMonster(monster);
88                 battleState->AddMonster(monster);
89                 battleState->AddMonster(monster);
90                 battleState->AddMonster(monster);
91                 battleState->AddHero(hero);
92                 battleState->AddHero(hero);
93                 battleState->AddHero(hero);
94                 battleState->AddHero(hero);
95                 Application app(&screen, battleState);
96                 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
97                 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
98                 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
99                 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
100                 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
101                 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
102                 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
103                 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
104                 app.Buttons().MapKey(SDLK_RETURN, Input::START);
105                 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
106                 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
107                 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
108                 app.Run();
109
110                 return 0;
111         } catch (exception &e) {
112                 cerr << "exception in main(): " << e.what() << endl;
113                 return 1;
114         }
115 }