]> git.localhorst.tv Git - l2e.git/blob - src/battle/BattleState.cpp
added Hero class for battle state
[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 "../graphics/Sprite.h"
12
13 #include <stdexcept>
14
15 using app::Application;
16 using geometry::Point;
17
18 using std::vector;
19
20 namespace battle {
21
22 void BattleState::AddMonster(const Monster &m) {
23         if (monsters.size() >= monstersLayout->NumPositions()) {
24                 throw std::overflow_error("too many monsters for layout");
25         }
26         monsters.push_back(m);
27 }
28
29 void BattleState::AddHero(const Hero &h) {
30         if (heroes.size() >= heroesLayout->NumPositions()) {
31                 throw std::overflow_error("too many heroes for layout");
32         }
33         heroes.push_back(h);
34 }
35
36
37 void BattleState::Resize(int w, int h) {
38
39 }
40
41
42 void BattleState::EnterState(Application &ctrl, SDL_Surface *screen) {
43         monstersLayout->CalculatePositions(background->w, background->h, monsterPositions);
44         heroesLayout->CalculatePositions(background->w, background->h, heroesPositions);
45 }
46
47 void BattleState::ExitState() {
48
49 }
50
51
52 void BattleState::HandleEvent(const SDL_Event &) {
53
54 }
55
56 void BattleState::UpdateWorld(float deltaT) {
57
58 }
59
60 void BattleState::Render(SDL_Surface *screen) {
61         // black for now
62         SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
63         SDL_Rect destRect;
64         destRect.x = (screen->w - background->w) / 2;
65         destRect.y = (screen->h - background->h) / 2;
66         destRect.w = background->w;
67         destRect.h = background->h;
68
69         // TODO: center background if screen bigger
70         SDL_BlitSurface(background, 0, screen, &destRect);
71
72         for (vector<Monster>::size_type i(0), end(monsters.size()); i < end; ++i) {
73                 monsters[i].Sprite()->DrawCenterBottom(screen, Point<int>(monsterPositions[i].X() + destRect.x, monsterPositions[i].Y() + destRect.y));
74         }
75
76         for (vector<Hero>::size_type i(0), end(heroes.size()); i < end; ++i) {
77                 heroes[i].Sprite()->DrawCenterBottom(screen, Point<int>(heroesPositions[i].X() + destRect.x, heroesPositions[i].Y() + destRect.y));
78         }
79 }
80
81 }