4 #include "globalfunc.h"
16 Tileset
Robot::ROBOTS_TILESET( "robots.png" );
18 Robot::Robot( Uint8 X
, Uint8 Y
) : LivingMapObject( X
, Y
),
19 ani_walking( 0, 3, 10 )
21 ani_player
= new DAnimation( &ROBOTS_TILESET
);
23 ani_player
->load( &ani_walking
);
32 float Robot::SPEED() { return ROBOT_SPEED
; }
34 void Robot::StartMovement()
37 Map::transformM2S( mapX
, mapY
, sx
, sy
);
38 movementX
= (float)sx
;
39 movementY
= (float)sy
;
41 if( !isWalkable( mapX
+vX
, mapY
+vY
) )
46 if( isBitSet( Game::getMap()->tileAt( mapX
, mapY
)->typeMask
, Tile::TILE_SLOW
) )
47 speed
= SPEED() * 0.5f
;
55 bool Robot::isWalkable( Uint8 X
, Uint8 Y
)
57 Tile
*t
= Game::getMap()->tileAt(X
, Y
);
59 (isBitSet( t
->typeMask
, Tile::TILE_WALKABLE
) ||
60 isBitSet( t
->typeMask
, Tile::TILE_EFENCE
)) &&
61 !Game::getMap()->isRobotOn(X
, Y
) &&
62 !Game::getMap()->getObject( X
, Y
)
65 if( isBitSet( t
->typeMask
, Tile::TILE_EFENCE
) )
76 void Robot::OnTile( Tile
*t
)
78 if( isBitSet( t
->typeMask
, Tile::TILE_EFENCE
) )
80 Game::getMap()->RemoveTile( mapX
, mapY
);
84 if( mapX
== Game::getPlayer()->getMapX() &&
85 mapY
== Game::getPlayer()->getMapY() )
87 if( Game::getPlayer()->Walking() )
91 Game::getPlayer()->Die();
95 Game::getPlayer()->Die();
104 void Robot::MakeNewDir()
106 vX
= sign( Game::getPlayer()->getMapX() - mapX
);
107 vY
= sign( Game::getPlayer()->getMapY() - mapY
);
109 if( !isWalkable( mapX
+vX
, mapY
+vY
) )
111 if( isWalkable( mapX
, mapY
+vY
) )
113 else if( isWalkable( mapX
+vX
, mapY
) )
118 for( Uint8 y
= mapY
-1; y
<= mapY
+1; y
++ )
120 for( Uint8 x
= mapX
-1; x
<= mapX
+1; x
++ )
122 if( isWalkable( x
, y
) )
124 vX
= sign( x
- mapX
);
125 vY
= sign( y
- mapY
);