]> git.localhorst.tv Git - l2e.git/blob - src/battle/BattleState.cpp
removed debug output from 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
30 void BattleState::Resize(int w, int h) {
31         width = w;
32         height = h;
33 }
34
35
36 void BattleState::EnterState(Application &ctrl, SDL_Surface *screen) {
37         monstersLayout->CalculatePositions(background->w, background->h, monsterPositions);
38         width = screen->w;
39         height = screen->h;
40 }
41
42 void BattleState::ExitState() {
43
44 }
45
46
47 void BattleState::HandleEvent(const SDL_Event &) {
48
49 }
50
51 void BattleState::UpdateWorld(float deltaT) {
52
53 }
54
55 void BattleState::Render(SDL_Surface *screen) {
56         // black for now
57         SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
58         SDL_Rect destRect;
59         destRect.x = (width - background->w) / 2;
60         destRect.y = (height - background->h) / 2;
61         destRect.w = background->w;
62         destRect.h = background->h;
63
64         // TODO: center background if screen bigger
65         SDL_BlitSurface(background, 0, screen, &destRect);
66
67         for (vector<Monster>::size_type i(0), end(monsters.size()); i < end; ++i) {
68                 monsters[i].Sprite()->DrawCenterBottom(screen, Point<int>(monsterPositions[i].X() + destRect.x, monsterPositions[i].Y() + destRect.y));
69         }
70 }
71
72 }