2 #include "globalfunc.h"
13 Tileset
Robot::ROBOTS_TILESET( "robots.png" );
15 Robot::Robot( Uint8 X
, Uint8 Y
) : LivingMapObject( X
, Y
),
16 ani_walking( 0, 3, 10 )
18 ani_player
= new DAnimation( &ROBOTS_TILESET
);
20 ani_player
->load( &ani_walking
);
29 float Robot::SPEED() { return ROBOT_SPEED
; }
31 void Robot::StartMovement()
34 Map::transformM2S( mapX
, mapY
, sx
, sy
);
35 movementX
= (float)sx
;
36 movementY
= (float)sy
;
38 if( !isWalkable( mapX
+vX
, mapY
+vY
) )
43 if( isBitSet( Game::getMap()->tileAt( mapX
, mapY
)->typeMask
, Tile::TILE_SLOW
) )
44 speed
= SPEED() * 0.5f
;
52 bool Robot::isWalkable( Uint8 X
, Uint8 Y
)
54 Tile
*t
= Game::getMap()->tileAt(X
, Y
);
56 (isBitSet( t
->typeMask
, Tile::TILE_WALKABLE
) ||
57 isBitSet( t
->typeMask
, Tile::TILE_EFENCE
)) &&
58 !Game::getMap()->isRobotOn(X
, Y
)
61 if( isBitSet( t
->typeMask
, Tile::TILE_EFENCE
) )
72 void Robot::OnTile( Tile
*t
)
74 if( isBitSet( t
->typeMask
, Tile::TILE_EFENCE
) )
76 Game::getMap()->RemoveTile( mapX
, mapY
);
80 if( mapX
== Game::getPlayer()->getMapX() &&
81 mapY
== Game::getPlayer()->getMapY() )
83 if( Game::getPlayer()->Walking() )
87 Game::getPlayer()->Die();
91 Game::getPlayer()->Die();
100 void Robot::MakeNewDir()
102 vX
= sign( Game::getPlayer()->getMapX() - mapX
);
103 vY
= sign( Game::getPlayer()->getMapY() - mapY
);
105 if( !isWalkable( mapX
+vX
, mapY
+vY
) )
107 if( isWalkable( mapX
, mapY
+vY
) )
109 else if( isWalkable( mapX
+vX
, mapY
) )
114 for( Uint8 y
= mapY
-1; y
<= mapY
+1; y
++ )
116 for( Uint8 x
= mapX
-1; x
<= mapX
+1; x
++ )
118 if( isWalkable( x
, y
) )
120 vX
= sign( x
- mapX
);
121 vY
= sign( y
- mapY
);