2 #include "globalfunc.h"
12 Robot::Robot( Uint8 X
, Uint8 Y
) : LivingMapObject( X
, Y
)
19 float Robot::SPEED() { return ROBOT_SPEED
; }
21 void Robot::StartMovement()
24 Map::transformM2S( mapX
, mapY
, sx
, sy
);
25 movementX
= (float)sx
;
26 movementY
= (float)sy
;
28 if( !isWalkable( mapX
+vX
, mapY
+vY
) )
33 if( isBitSet( Game::getMap()->tileAt( mapX
, mapY
)->typeMask
, Tile::TILE_SLOW
) )
34 speed
= SPEED() * 0.5f
;
42 bool Robot::isWalkable( Uint8 X
, Uint8 Y
)
44 Tile
*t
= Game::getMap()->tileAt(X
, Y
);
46 (isBitSet( t
->typeMask
, Tile::TILE_WALKABLE
) ||
47 isBitSet( t
->typeMask
, Tile::TILE_EFENCE
)) &&
48 !Game::getMap()->isRobotOn(X
, Y
)
51 if( isBitSet( t
->typeMask
, Tile::TILE_EFENCE
) )
62 void Robot::OnTile( Tile
*t
)
64 if( isBitSet( t
->typeMask
, Tile::TILE_EFENCE
) )
66 Game::getMap()->RemoveTile( mapX
, mapY
);
70 if( mapX
== Game::getPlayer()->getMapX() &&
71 mapY
== Game::getPlayer()->getMapY() )
73 if( Game::getPlayer()->Walking() )
77 Game::getPlayer()->Die();
81 Game::getPlayer()->Die();
90 void Robot::MakeNewDir()
92 vX
= sign( Game::getPlayer()->getMapX() - mapX
);
93 vY
= sign( Game::getPlayer()->getMapY() - mapY
);
95 if( !isWalkable( mapX
+vX
, mapY
+vY
) )
97 if( isWalkable( mapX
, mapY
+vY
) )
99 else if( isWalkable( mapX
+vX
, mapY
) )
104 for( Uint8 y
= mapY
-1; y
<= mapY
+1; y
++ )
106 for( Uint8 x
= mapX
-1; x
<= mapX
+1; x
++ )
108 if( isWalkable( x
, y
) )
110 vX
= sign( x
- mapX
);
111 vY
= sign( y
- mapY
);