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