
Definition at line 18 of file Unit.h.
Public Member Functions | |
| Unit (const KeyControl &buttons, const ControlSym &symbols, bool startActive=false) | |
| Create new driveable unit. | |
| void | takeModel (Cube *model) |
| bool | startActive () |
| bool | canDrive () const |
| bool | willMove () const |
| Return true when we can move in future. | |
| char | drive (const InputProvider *input) |
| Test keys and try move. | |
| char | driveBorrowed (const InputProvider *input, const KeyControl &buttons) |
| Test keys and try move, use borrowed controls. | |
| void | activate () |
| Greet the player. | |
| char | mySymbol (SDLKey key) const |
| Translate this key to symbol. | |
| char | mySymbolBorrowed (SDLKey key, const KeyControl &buttons) const |
| Translate this key to symbol, compare with borrowed buttons. | |
| char | myOrder (Dir::eDir dir) const |
| Returns symbol for this direction. | |
| char | driveOrder (char move) |
| Make move. | |
| bool | isMoving () const |
| bool | isTurning () const |
| bool | isPushing () const |
| bool | equalsModel (const Cube *other) const |
| Returns true when models are equal. | |
| V2 | getLoc () const |
| int | getW () const |
| int | getH () const |
| bool | isFreePlace (const V2 &loc) const |
| int | countAnimPhases (const std::string &anim) const |
| bool | isPowerful () const |
|
||||||||||||||||
|
Create new driveable unit.
Definition at line 26 of file Unit.cpp. 00028 : m_buttons(buttons), m_symbols(symbols)
00029 {
00030 m_model = NULL;
00031 m_startActive = a_startActive;
00032 }
|
|
|
Greet the player.
Definition at line 90 of file Unit.cpp. 00091 {
00092 m_model->rules()->actionActivate();
00093 }
|
|
|
Definition at line 35 of file Unit.cpp. 00036 {
00037 return m_model->isAlive()
00038 && !m_model->isLost()
00039 && !m_model->isBusy();
00040 }
|
|
|
Definition at line 285 of file Unit.cpp. 00286 {
00287 return m_model->anim()->countAnimPhases(anim);
00288 }
|
|
|
Test keys and try move.
Definition at line 57 of file Unit.cpp. 00058 {
00059 return driveBorrowed(input, m_buttons);
00060 }
|
|
||||||||||||
|
Test keys and try move, use borrowed controls.
Definition at line 67 of file Unit.cpp. 00068 {
00069 if (canDrive()) {
00070 if (input->isPressed(buttons.getLeft())) {
00071 return goLeft();
00072 }
00073 if (input->isPressed(buttons.getRight())) {
00074 return goRight();
00075 }
00076 if (input->isPressed(buttons.getUp())) {
00077 return goUp();
00078 }
00079 if (input->isPressed(buttons.getDown())) {
00080 return goDown();
00081 }
00082 }
00083 return ControlSym::SYM_NONE;
00084 }
|
|
|
Make move.
Definition at line 153 of file Unit.cpp. 00154 {
00155 if (canDrive()) {
00156 if (m_symbols.getLeft() == move) {
00157 return goLeft();
00158 }
00159 if (m_symbols.getRight() == move) {
00160 return goRight();
00161 }
00162 if (m_symbols.getUp() == move) {
00163 return goUp();
00164 }
00165 if (m_symbols.getDown() == move) {
00166 return goDown();
00167 }
00168 }
00169 return ControlSym::SYM_NONE;
00170 }
|
|
|
Returns true when models are equal.
Definition at line 255 of file Unit.cpp. 00256 {
00257 return m_model == other;
00258 }
|
|
|
Definition at line 273 of file Unit.cpp. 00274 {
00275 return m_model->shape()->getH();
00276 }
|
|
|
Definition at line 261 of file Unit.cpp. 00262 {
00263 return m_model->getLocation();
00264 }
|
|
|
Definition at line 267 of file Unit.cpp. 00268 {
00269 return m_model->shape()->getW();
00270 }
|
|
|
Definition at line 279 of file Unit.cpp. 00280 {
00281 return m_model->const_rules()->isFreePlace(loc);
00282 }
|
|
|
Definition at line 226 of file Unit.cpp. 00227 {
00228 bool result = false;
00229 if (canDrive()) {
00230 std::string action = m_model->rules()->getAction();
00231 result = action == "move_left" || action == "move_right"
00232 || action == "move_up" || action == "move_down"
00233 || action == "turn";
00234 }
00235 return result;
00236 }
|
|
|
Definition at line 291 of file Unit.cpp. 00291 {
00292 return m_model->getPower() >= Cube::HEAVY;
00293 }
|
|
|
Definition at line 246 of file Unit.cpp. 00247 {
00248 return m_model->rules()->getState() == "pushing";
00249 }
|
|
|
Definition at line 239 of file Unit.cpp. 00240 {
00241 std::string action = m_model->rules()->getAction();
00242 return action == "turn";
00243 }
|
|
|
Returns symbol for this direction.
Definition at line 131 of file Unit.cpp. 00132 {
00133 switch (dir) {
00134 case Dir::DIR_LEFT:
00135 return m_symbols.getLeft();
00136 case Dir::DIR_RIGHT:
00137 return m_symbols.getRight();
00138 case Dir::DIR_UP:
00139 return m_symbols.getUp();
00140 case Dir::DIR_DOWN:
00141 return m_symbols.getDown();
00142 default:
00143 assert(!"unknown dir");
00144 }
00145 return ControlSym::SYM_NONE;
00146 }
|
|
|
Translate this key to symbol.
Definition at line 100 of file Unit.cpp. 00101 {
00102 return mySymbolBorrowed(key, m_buttons);
00103 }
|
|
||||||||||||
|
Translate this key to symbol, compare with borrowed buttons.
Definition at line 110 of file Unit.cpp. 00111 {
00112 if (key == buttons.getLeft()) {
00113 return m_symbols.getLeft();
00114 }
00115 if (key == buttons.getRight()) {
00116 return m_symbols.getRight();
00117 }
00118 if (key == buttons.getUp()) {
00119 return m_symbols.getUp();
00120 }
00121 if (key == buttons.getDown()) {
00122 return m_symbols.getDown();
00123 }
00124 return ControlSym::SYM_NONE;
00125 }
|
|
|
Definition at line 33 of file Unit.h. 00033 { return m_startActive; }
|
|
|
Definition at line 32 of file Unit.h. 00032 { m_model = model; }
|
|
|
Return true when we can move in future.
Definition at line 46 of file Unit.cpp.
|
1.4.2