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