Repository navigation
Expand file tree
/
Copy pathUnitSprite.cpp
More file actions
143 lines (127 loc) · 4.11 KB
/
Copy pathUnitSprite.cpp
File metadata and controls
143 lines (127 loc) · 4.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
* Copyright 2010 OpenXcom Developers.
*
* This file is part of OpenXcom.
*
* OpenXcom is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenXcom is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
*/
#define _USE_MATH_DEFINES
#include <cmath>
#include "UnitSprite.h"
#include "../Engine/SurfaceSet.h"
#include "../Battlescape/Position.h"
#include "../Resource/ResourcePack.h"
#include "../Ruleset/RuleUnitSprite.h"
#include "../Savegame/BattleUnit.h"
#include "../Savegame/Soldier.h"
namespace OpenXcom
{
/**
* Sets up a UnitSprite with the specified size and position.
* @param width Width in pixels.
* @param height Height in pixels.
* @param x X position in pixels.
* @param y Y position in pixels.
*/
UnitSprite::UnitSprite(int width, int height, int x, int y) : Surface(width, height, x, y)
{
}
/**
* Deletes the UnitSprite.
*/
UnitSprite::~UnitSprite()
{
}
/**
* Changes the pack for the UnitSprite to get resources for rendering.
* @param res Pointer to the resource pack.
*/
void UnitSprite::setResourcePack(ResourcePack *res)
{
_res = res;
}
/**
* Links this sprite to a BattleUnit to get the data for rendering.
* @param unit Pointer to the BattleUnit.
*/
void UnitSprite::setBattleUnit(BattleUnit *unit)
{
_unit = unit;
}
/**
* Draws a unit, using the drawing rules of the unit.
* This function is called by Map, for each unit on the screen.
*/
void UnitSprite::draw()
{
RuleUnitSprite *rules = _unit->getRenderRules();
std::string sheet = rules->getSpriteSheet();
Surface *torso = 0, *legs = 0, *bottomArm = 0, *topArm = 0;
clear();
if (rules->getTorso() > -1)
{
if (_unit != 0 && _unit->getGender() == GENDER_FEMALE)
{
torso = _res->getSurfaceSet(sheet)->getFrame(rules->getFemaleTorso() + _unit->getDirection());
}
else
{
torso = _res->getSurfaceSet(sheet)->getFrame(rules->getTorso() + _unit->getDirection());
}
}
if (_unit->getStatus() == STATUS_STANDING)
{
legs = _res->getSurfaceSet(sheet)->getFrame(rules->getLegsStand() + _unit->getDirection());
if (_unit->getDirection() < 4)
{
bottomArm = _res->getSurfaceSet(sheet)->getFrame(rules->getLeftArmStand() + _unit->getDirection());
topArm = _res->getSurfaceSet(sheet)->getFrame(rules->getRightArmStand() + _unit->getDirection());
}
else
{
topArm = _res->getSurfaceSet(sheet)->getFrame(rules->getLeftArmStand() + _unit->getDirection());
bottomArm = _res->getSurfaceSet(sheet)->getFrame(rules->getRightArmStand() + _unit->getDirection());
}
}
else
{
legs = _res->getSurfaceSet(sheet)->getFrame(rules->getLegsWalk(_unit->getDirection()) + _unit->getWalkingPhase());
legs->setY(rules->getLegsWalkOffset(_unit->getWalkingPhase()));
if (_unit->getDirection() < 4)
{
bottomArm = _res->getSurfaceSet(sheet)->getFrame(rules->getLeftArmWalk(_unit->getDirection()) + _unit->getWalkingPhase());
topArm = _res->getSurfaceSet(sheet)->getFrame(rules->getRightArmWalk(_unit->getDirection()) + _unit->getWalkingPhase());
}
else
{
topArm = _res->getSurfaceSet(sheet)->getFrame(rules->getLeftArmWalk(_unit->getDirection()) + _unit->getWalkingPhase());
bottomArm = _res->getSurfaceSet(sheet)->getFrame(rules->getRightArmWalk(_unit->getDirection()) + _unit->getWalkingPhase());
}
topArm->setY(rules->getWalkArmsOffset(_unit->getWalkingPhase()));
bottomArm->setY(rules->getWalkArmsOffset(_unit->getWalkingPhase()));
}
if (bottomArm) bottomArm->blit(this);
if (torso) torso->blit(this);
if (legs) legs->blit(this);
if (topArm) topArm->blit(this);
}
/**
* Blits the unit onto another surface.
* @param surface Pointer to another surface.
*/
void UnitSprite::blit(Surface *surface)
{
Surface::blit(surface);
}
}