]> git.localhorst.tv Git - l2e.git/blob - src/battle/BattleState.cpp
added Input class for handling user input
[l2e.git] / src / battle / BattleState.cpp
1 /*
2  * BattleState.cpp
3  *
4  *  Created on: Aug 5, 2012
5  *      Author: holy
6  */
7
8 #include "BattleState.h"
9
10 #include "PartyLayout.h"
11 #include "../app/Application.h"
12 #include "../app/Input.h"
13 #include "../geometry/operators.h"
14 #include "../graphics/Sprite.h"
15
16 #include <stdexcept>
17
18 using app::Application;
19 using app::Input;
20 using geometry::Point;
21 using geometry::Vector;
22
23 using std::vector;
24
25 namespace battle {
26
27 void BattleState::AddMonster(const Monster &m) {
28         if (monsters.size() >= monstersLayout->NumPositions()) {
29                 throw std::overflow_error("too many monsters for layout");
30         }
31         monsters.push_back(m);
32 }
33
34 void BattleState::AddHero(const Hero &h) {
35         if (heroes.size() >= heroesLayout->NumPositions()) {
36                 throw std::overflow_error("too many heroes for layout");
37         }
38         heroes.push_back(h);
39 }
40
41
42 void BattleState::Resize(int w, int h) {
43
44 }
45
46
47 void BattleState::EnterState(Application &ctrl, SDL_Surface *screen) {
48         monstersLayout->CalculatePositions(background->w, background->h, monsterPositions);
49         heroesLayout->CalculatePositions(background->w, background->h, heroesPositions);
50 }
51
52 void BattleState::ExitState() {
53
54 }
55
56
57 void BattleState::HandleInput(const Input &input) {
58
59 }
60
61 void BattleState::UpdateWorld(float deltaT) {
62
63 }
64
65 void BattleState::Render(SDL_Surface *screen) {
66         Vector<int> offset(
67                         (screen->w - background->w) / 2,
68                         (screen->h - background->h) / 2);
69
70         RenderBackground(screen, offset);
71         RenderMonsters(screen, offset);
72         RenderHeroes(screen, offset);
73 }
74
75 void BattleState::RenderBackground(SDL_Surface *screen, const Vector<int> &offset) {
76         // black for now
77         SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
78         SDL_Rect destRect;
79         destRect.x = offset.X();
80         destRect.y = offset.Y();
81         destRect.w = background->w;
82         destRect.h = background->h;
83         SDL_BlitSurface(background, 0, screen, &destRect);
84 }
85
86 void BattleState::RenderMonsters(SDL_Surface *screen, const Vector<int> &offset) {
87         for (vector<Monster>::size_type i(0), end(monsters.size()); i < end; ++i) {
88                 monsters[i].Sprite()->DrawCenterBottom(screen, monsterPositions[i] + offset);
89         }
90 }
91
92 void BattleState::RenderHeroes(SDL_Surface *screen, const Vector<int> &offset) {
93         for (vector<Hero>::size_type i(0), end(heroes.size()); i < end; ++i) {
94                 heroes[i].Sprite()->DrawCenterBottom(screen, heroesPositions[i] + offset);
95         }
96 }
97
98 }