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