Mario: add bouncing
This commit is contained in:
+34
-2
@@ -13,6 +13,7 @@ MarioBlock::MarioBlock( int x, int y,
|
||||
: RectangleRender( x * BLOCK_SIZE, 1 - ( 16 - y ) * BLOCK_SIZE,
|
||||
BLOCK_SIZE, BLOCK_SIZE, renderer, texture, src ) {
|
||||
_destructible = destructible;
|
||||
setMovementSpeed(1);
|
||||
}
|
||||
void MarioBlock::visit( SDLPP::Visitor &visitor ) {
|
||||
#ifdef EDITOR
|
||||
@@ -25,8 +26,13 @@ void MarioBlock::visit( SDLPP::Visitor &visitor ) {
|
||||
destroy();
|
||||
}
|
||||
#else
|
||||
if(visitor.getFromId() == MARIO_TOP_DETECT && _destructible && dynamic_cast<MarioVisitor&>(visitor).canDestroy()) {
|
||||
destroy();
|
||||
if(visitor.getFromId() == MARIO_TOP_DETECT && dynamic_cast<MarioVisitor&>(visitor).canDestroy()) {
|
||||
if( _destructible ) {
|
||||
destroy();
|
||||
} else {
|
||||
// TODO check if anything above
|
||||
bounce();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
visitor.visit( *this );
|
||||
@@ -38,6 +44,32 @@ void MarioBlock::setTerrain( bool terrain ) {
|
||||
_terrain = terrain;
|
||||
}
|
||||
|
||||
void MarioBlock::bounce() {
|
||||
if(_bouncing)
|
||||
return;
|
||||
_bouncing = true;
|
||||
og_pos = getPos();
|
||||
setMovement(0, -0.5);
|
||||
}
|
||||
|
||||
void MarioBlock::custom_move(int ticks) {
|
||||
if(!_bouncing)
|
||||
return;
|
||||
if(getMovement().getY() < 0) {
|
||||
ticks_to_bounce -= ticks;
|
||||
if(ticks_to_bounce < 0) {
|
||||
setMovement(0, 0.5);
|
||||
ticks_to_bounce = bounce_ticks;
|
||||
}
|
||||
} else {
|
||||
if(getPos().getY() >= og_pos.getY()) {
|
||||
setMovement(0, 0);
|
||||
setPos(og_pos);
|
||||
_bouncing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector< uint64_t > possibleBlocks = {
|
||||
FLOOR_ID,
|
||||
STEP_ID,
|
||||
|
||||
Reference in New Issue
Block a user