void CWaterMine::processMove() { performCollisions(); if(yDirection) { const Uint16 blockerUp = mp_Map->getPlaneDataAt(2, getXMidPos(), getYUpPos()); const Uint16 blockerDown = mp_Map->getPlaneDataAt(2, getXMidPos(), getYDownPos()); // If there is a blocker, block the Watermine if( blockerUp == 31 ) blockedu = true; if( blockerDown == 31 ) blockedd = true; // If the mine is really blocked, change the direction if(blockedd) yDirection = UP; else if(blockedu) yDirection = DOWN; if(yDirection == DOWN) moveDown(MINE_SPEED); else moveUp(MINE_SPEED); } else { const Uint16 blockerLeft = mp_Map->getPlaneDataAt(2, getXLeftPos(), getYMidPos()); const Uint16 blockerRight = mp_Map->getPlaneDataAt(2, getXRightPos(), getYMidPos()); // If there is a blocker, block the Watermine if( blockerLeft == 31 ) blockedl = true; if( blockerRight == 31 ) blockedr = true; // If the mine is really blocked, change the direction if(blockedl) xDirection = RIGHT; else if(blockedr) xDirection = LEFT; if(xDirection == LEFT) moveLeft(MINE_SPEED); else moveRight(MINE_SPEED); } }
bool CBlooguard::isNearby(CSpriteObject& theObject) { if( CPlayerLevel *player = dynamic_cast<CPlayerLevel*>(&theObject) ) { const int objX = theObject.getXMidPos(); const int objY = theObject.getYMidPos(); const int blooguardX = getXMidPos(); const int blooguardY = getYMidPos(); // Code for setting player stunned here! if(mStubPlayer) { mStubPlayer = false; if(player->stun()) { player->m_camera.m_relcam.y = (8<<CSF); } return true; } mGoodClubChance = false; if( objX < blooguardX - CSF_DISTANCE_TO_CLUB || objX > blooguardX + CSF_DISTANCE_TO_CLUB ) return false; if( objY < blooguardY - CSF_DISTANCE_TO_CLUB || objY > blooguardY + CSF_DISTANCE_TO_CLUB ) return false; mGoodClubChance = true; } return true; }
void CAmpton::processPoleSlide() { int l_x_l = getXLeftPos(); int l_x = getXMidPos(); int l_x_r = getXRightPos(); int l_y_mid = getYMidPos(); int l_y_down = getYDownPos(); // Move normally in the direction if( yDirection == UP ) { // Check for the upper side and don't let him move if the pole ends if( hitdetectWithTileProperty(1, l_x_l, l_y_mid) || hitdetectWithTileProperty(1, l_x, l_y_mid) || hitdetectWithTileProperty(1, l_x_r, l_y_mid) ) { moveUp( SLIDE_SPEED ); } else { yDirection = DOWN; } } else // Down { // Check for the upper side and don't let him move if the pole ends if( hitdetectWithTileProperty(1, l_x_l, l_y_down) || hitdetectWithTileProperty(1, l_x, l_y_down) || hitdetectWithTileProperty(1, l_x_r, l_y_down) ) { moveDown( SLIDE_SPEED ); } else { yDirection = UP; } } mTimer++; if(mTimer < UMOUNT_TIME) return; mTimer = 0; // Check for Floor here! const int fall1 = mp_Map->getPlaneDataAt(1, l_x, l_y_down+(1<<CSF)); //const int fall1 = mp_Map->getPlaneDataAt(1, l_x, l_y_down); const CTileProperties &TileProp1 = g_pBehaviorEngine->getTileProperties(1)[fall1]; const bool leavePole = (TileProp1.bup != 0); if(leavePole) { setAction(A_AMPTON_STOP_POLE); moveXDir(2*xDirection*WALK_SPEED); moveUp(1<<CSF); solid = true; blockedd = true; } }
bool CShelly::isNearby(CSpriteObject &theObject) { if( CPlayerLevel *player = dynamic_cast<CPlayerLevel*>(&theObject) ) { if( player->getXMidPos() < getXMidPos() ) mKeenAlignment = LEFT; else mKeenAlignment = RIGHT; const int objX = theObject.getXMidPos(); const int objY = theObject.getYMidPos(); const int shellyX = getXMidPos(); const int shellyY = getYMidPos(); mGoodJumpChance = false; if( objX < shellyX - CSF_DISTANCE_TO_JUMP || objX > shellyX + CSF_DISTANCE_TO_JUMP ) return false; if( objY < shellyY - CSF_DISTANCE_TO_JUMP || objY > shellyY + CSF_DISTANCE_TO_JUMP ) return false; mGoodJumpChance = true; } return true; }
bool CWormmouth::isNearby(CSpriteObject &theObject) { if(dead || theObject.dead ) return false; if( CPlayerBase *player = dynamic_cast<CPlayerBase*>(&theObject) ) { const int playerX = player->getXMidPos(); const int playerY = player->getYMidPos(); const int wormmouthX = getXMidPos(); const int wormmouthY = getYMidPos(); if( getActionNumber(A_WORMMOUTH_LOOK) ) { if( playerX < wormmouthX && xDirection != LEFT ) mTurnAround = true; else if( playerX > wormmouthX && xDirection != RIGHT ) mTurnAround = true; } const int diffX = playerX - wormmouthX; const int diffY = playerY - wormmouthY; if( abs(diffX) < DIST_TO_EAT && abs(diffY) < DIST_TO_EAT && !getActionNumber(A_WORMMOUTH_EAT) ) { setAction(A_WORMMOUTH_EAT); playSound( SOUND_WORMOUTH_STRIKE ); } } return true; }
bool CBlueBird::isNearby(CSpriteObject &theObject) { if( !getProbability(20) ) return false; if( CPlayerLevel *player = dynamic_cast<CPlayerLevel*>(&theObject) ) { if( player->getXMidPos() < getXMidPos() ) xDirection = LEFT; else xDirection = RIGHT; if( player->getYMidPos() < getYMidPos() ) yDirection = UP; else yDirection = DOWN; // so the bottom of keen's box has to be >= 3 tiles above the bottom of the bird's box // and keen needs to be on the ground -> Quote by Lemm const int pYDown = player->getYDownPos(); const int bYDown = getYDownPos(); if( player->blockedd && pYDown <= bYDown-(3<<CSF) ) { setAction(A_EAGLE_FLYING); inhibitfall = true; } } return true; }
bool CSparky::isNearby(CSpriteObject &theObject) { if( !getProbability(10) ) return false; if( CPlayerLevel *player = dynamic_cast<CPlayerLevel*>(&theObject) ) { if( player->getXMidPos() < getXMidPos() ) mKeenAlignment = LEFT; else mKeenAlignment = RIGHT; const int objX = theObject.getXMidPos(); const int objY = theObject.getYMidPos(); const int sparkyX = getXMidPos(); const int sparkyY = getYMidPos(); mGoodChargeChance = false; if( objX < sparkyX - CSF_DISTANCE_TO_FOLLOW || objX > sparkyX + CSF_DISTANCE_TO_FOLLOW ) return false; if( objY < sparkyY - CSF_DISTANCE_TO_FOLLOW || objY > sparkyY + CSF_DISTANCE_TO_FOLLOW ) return false; mGoodChargeChance = true; } return true; }
bool CDevilSprite::isNearby(CSpriteObject &theObject) { if( CPlayerBase *player = dynamic_cast<CPlayerBase*>(&theObject) ) { const int dx = player->getXMidPos() - getXMidPos(); const int dy = player->getYMidPos() - getYMidPos(); if( dx<0 ) xDirection = LEFT; else xDirection = RIGHT; if(getActionNumber(A_SPRITE_MOVE)) { int absdx = (dx<0) ? -dx : dx; int absdy = (dy<0) ? -dy : dy; if( absdx < CSF_MIN_DISTANCE_X_TO_LOOK && absdy < CSF_MIN_DISTANCE_Y_TO_LOOK ) { setAction(A_SPRITE_LOOK); mp_processState = &CDevilSprite::processLook; m_timer = SPRITE_LOOK_DELAY; } } } return true; }
bool CThunderCloud::isNearby(CSpriteObject &theObject) { if( CPlayerLevel *player = dynamic_cast<CPlayerLevel*>(&theObject) ) { const unsigned int cloudX = getXMidPos(); const unsigned int playXLeft = player->getXMidPos() - DIST_TO_AWAKE; const unsigned int playXRight = player->getXMidPos() + DIST_TO_AWAKE; if( playXLeft < cloudX && playXRight > cloudX ) { if( getActionStatus(A_CLOUD_ASLEEP) && getProbability(180) ) setAction(A_CLOUD_WAKING); } else { if( !getActionStatus(A_CLOUD_ASLEEP) ) { setAction(A_CLOUD_ASLEEP); setActionSprite(); return true; } } if( getActionStatus(A_CLOUD_WAKING) ) { if( player->getXMidPos() < getXMidPos() ) xDirection = LEFT; else xDirection = RIGHT; } if( getActionStatus(A_CLOUD_MOVING) ) { if( mpBolt == nullptr && player->getYMidPos() > getYMidPos() ) { const unsigned int playXStrikeLeft = player->getXMidPos() - DIST_TO_STRIKE; const unsigned int playXStrikeRight = player->getXMidPos() + DIST_TO_STRIKE; if( playXStrikeLeft < cloudX && playXStrikeRight > cloudX && (mTimer>TIME_TO_STRIKE_2 || (mSecondTry && mTimer>TIME_TO_STRIKE_1) ) ) { mTimer = 0; mSecondTry = !mSecondTry; setAction(A_CLOUD_STRIKING); playSound(SOUND_THUNDERCLOUD_STRIKE); mpBolt = new CThunderBolt( mp_Map, getXLeftPos() + (12<<STC), getYDownPos() + (32<<STC), mSprVar ); spawnObj( mpBolt ); } } } } return true; }
void CScrub::process() { CCarrier::process(); if (canbezapped) { // die if shot if (mHealthPoints <= 0 && state!=SCRUB_DYING ) { solid=true; state = SCRUB_DYING; dietimer = 0; moveUp(10); scrubdie_inertia_y = SCRUBDIE_START_INERTIA; playSound(SOUND_SHOT_HIT); } } CPhysicsSettings &Physics = g_pBehaviorEngine->getPhysicsSettings(); switch(state) { case SCRUB_DYING: sprite = SCRUB_FRY_FRAME; moveYDir(scrubdie_inertia_y); if ( scrubdie_inertia_y < Physics.max_fallspeed ) scrubdie_inertia_y += Physics.fallspeed_increase; dietimer = 0; if (scrubdie_inertia_y >= 0 && blockedd) { sprite = SCRUB_DEAD_FRAME; state = SCRUB_DEAD; dead = true; } return; break; case SCRUB_WALK: if(xDirection < 0) walkLeft( (getXLeftPos())>>CSF, (getYMidPos())>>CSF); else if(xDirection > 0) walkRight( (getXRightPos())>>CSF, (getYMidPos())>>CSF); else if(yDirection < 0)
bool CArachnut::isNearby(CSpriteObject &theObject) { if( !getProbability(10) ) return false; if( CPlayerLevel *player = dynamic_cast<CPlayerLevel*>(&theObject) ) { xDirection = ( player->getXMidPos() < getXMidPos() ) ? LEFT : RIGHT; yDirection = ( player->getYMidPos() < getYMidPos() ) ? UP : DOWN; } return true; }
bool CDopeFish::isNearby(CSpriteObject &theObject) { if( dynamic_cast<CPlayerBase*>(&theObject) || dynamic_cast<CSchoolFish*>(&theObject) ) { const int objX = theObject.getXMidPos(); const int objY = theObject.getYMidPos(); const int fishX = getXMidPos(); const int fishY = getYMidPos(); const int dx = objX - fishX; const int dy = objY - fishY; if( objX < fishX - CSF_DISTANCE_TO_FOLLOW || objX > fishX + CSF_DISTANCE_TO_FOLLOW ) return false; if( objY < fishY - CSF_DISTANCE_TO_FOLLOW || objY > fishY + CSF_DISTANCE_TO_FOLLOW ) return false; if( dx<-CSF_DISTANCE_TO_FOLLOW_TOLERANCE ) xDirection = LEFT; else if( dx>+CSF_DISTANCE_TO_FOLLOW_TOLERANCE ) xDirection = RIGHT; if( dy<-CSF_DISTANCE_TO_FOLLOW_TOLERANCE ) yDirection = (rand()%5) ? UP : DOWN; else if( dy>+CSF_DISTANCE_TO_FOLLOW_TOLERANCE ) yDirection = (rand()%5) ? DOWN : UP; if(getActionNumber(A_DOPEFISH_SWIM)) { int absdx = (dx<0) ? -dx : dx; int absdy = (dy<0) ? -dy : dy; if( absdx < CSF_MIN_DISTANCE_TO_CHARGE && absdy < CSF_MIN_DISTANCE_TO_CHARGE ) { setAction(A_DOPEFISH_EAT); mp_processState = &CDopeFish::processEat; m_eatTimer = DOPE_EAT_TIMER; } } } return true; }
void CDopeFish::processBurp() { if(!m_burped && getActionStatus(A_DOPEFISH_BURPING)) { g_pSound->playSound(SOUND_DOPEFISH_BURP); CBubbles *Bubble = new CBubbles(mp_Map, 0, getXMidPos()+(1<<CSF), getYMidPos()+(1<<CSF), true); g_pBehaviorEngine->m_EventList.add( new EventSpawnObject( Bubble ) ); m_burped = true; } if(getActionStatus(A_DOPEFISH_BURP_FINISHED)) { setAction(A_DOPEFISH_SWIM); mp_processState = &CDopeFish::processSwim; } }
bool CSpirogrip::isNearby(CSpriteObject &theObject) { if( CPlayerLevel *player = dynamic_cast<CPlayerLevel*>(&theObject) ) { if( player->getXMidPos() < getXMidPos() ) mKeenAlignmentX = LEFT; else mKeenAlignmentX = RIGHT; if( player->getYMidPos() < getYMidPos() ) mKeenAlignmentY = UP; else mKeenAlignmentY = DOWN; } return true; }
bool CArachnut::isNearby(CSpriteObject &theObject) { if( !getProbability(80) ) return false; if( CPlayerLevel *player = dynamic_cast<CPlayerLevel*>(&theObject) ) { if( player->getXMidPos() < getXMidPos() ) xDirection = LEFT; else xDirection = RIGHT; if( player->getYMidPos() < getYMidPos() ) yDirection = UP; else yDirection = DOWN; } return true; }
void CDevilSprite::processShoot() { m_timer--; if( m_timer == SPRITE_SHOOT_DELAY/2 ) { gSound.playSound(SOUND_SPRITE_SHOT); int x_coord = getXMidPos(); x_coord += (xDirection == LEFT) ? -(8<<STC) : +(8<<STC); CEnemyShot *Spark = new CEnemyShot(mpMap, 0, x_coord, getYMidPos()-(8<<STC), 0x3818, xDirection, 0, 100, 0); gEventManager.add( new EventSpawnObject( Spark ) ); } if( m_timer <= 0 ) { m_timer = SPRITE_MOVE_DELAY; setAction(A_SPRITE_MOVE); mp_processState = &CDevilSprite::processMove; } }
bool CLick::isNearby(CSpriteObject &theObject) { const bool odd = getProbability(80); if( CPlayerBase *player = dynamic_cast<CPlayerBase*>(&theObject) ) { const int dy = abs(player->getYMidPos() - getYMidPos()); const int dx = player->getXMidPos() - getXMidPos(); if( dy > CSF_MIN_DISTANCE_TO_BREATHE ) return false; if( dx<-CSF_DISTANCE_TO_FOLLOW_TOLERANCE && odd ) xDirection = LEFT; else if( dx>+CSF_DISTANCE_TO_FOLLOW_TOLERANCE && odd ) xDirection = RIGHT; if(getActionNumber(A_LICK_LAND)) { int absdx = (dx<0) ? -dx : dx; if( absdx < CSF_DISTANCE_TO_FOLLOW_TOLERANCE ) keenNear = true; else keenNear = false; if( absdx < CSF_MIN_DISTANCE_TO_BREATHE && odd ) { setAction(A_LICK_BREATHE); playSound(SOUND_LICK_FIREBREATH); m_timer = LICK_BREATHE_TIMER; } } } return true; }
bool CSchoolFish::isNearby(CSpriteObject &theObject) { if( CPlayerBase *player = dynamic_cast<CPlayerBase*>(&theObject) ) { const int dx = player->getXMidPos() - getXMidPos(); const int dy = player->getYMidPos() - getYMidPos(); if( dx<-CSF_DISTANCE_TO_FOLLOW_TOLERANCE ) { xDirection = LEFT; } else if( dx>+CSF_DISTANCE_TO_FOLLOW_TOLERANCE ) { xDirection = RIGHT; } if( dy<-CSF_DISTANCE_TO_FOLLOW_TOLERANCE ) { yDirection = (rand()%5) ? UP : DOWN; } else if( dy>+CSF_DISTANCE_TO_FOLLOW_TOLERANCE ) { yDirection = (rand()%5) ? DOWN : UP; } int absdx = (dx<0) ? -dx : dx; int absdy = (dy<0) ? -dy : dy; if( absdx < CSF_MIN_DISTANCE_TO_FOLLOW && absdy < CSF_MIN_DISTANCE_TO_FOLLOW ) { m_moveSpeed = FISH_SPEED*(rand()%2+1); } } return true; }
// handles inertia and friction for the Y direction // (this is where the inertia is actually applied to playx) void CPlayer::InertiaAndFriction_Y() { if (hideplayer) { pinertia_y = 0; return; } // if we hit a solid object kill all inertia if (pinertia_y > 0 && blockedd) pinertia_y = 0; else if (pinertia_y < 0 && blockedu) pinertia_y = 0; else if( isWMSolid(getXMidPos(), getYMidPos()) ) pinertia_y = 0; // then apply pinertia_y if( (!blockedu && pinertia_y<0) || (!blockedd && pinertia_y>0) ) moveYDir(pinertia_y); // if we stopped walking (i.e. LRUD not held down) apply friction if (playcontrol[PA_Y] == 0) { // and apply friction to pinertia_y if (pinertia_y < 0) { pinertia_y += PFRICTION_RATE_WM<<4; if(pinertia_y > 0) pinertia_y = 0; } else if (pinertia_y > 0) { pinertia_y -= PFRICTION_RATE_WM<<4; if(pinertia_y < 0) pinertia_y = 0; } } }
void CPlayerDive::processDiving() { // In case noclipping was triggered, make it solid, or remove it... if(m_Cheatmode.noclipping) { solid = !solid; m_Cheatmode.noclipping = false; } // If Player presses Jump button, make Keen swim faster if(g_pInput->getPressedCommand(IC_JUMP)) { // Slow down the swim speed, by time if(getActionNumber(A_KEENSWIM_MOVE)) setActionForce(A_KEENSWIM_MOVE+1); else setActionForce(A_KEENSWIM_MOVE); if(m_swimupspeed<MAXMOVESPEED) m_swimupspeed = MAXMOVESPEED; } // Swimming - Left and Right if(g_pInput->getHoldedCommand(IC_LEFT)) { if(!g_pInput->getHoldedCommand(IC_UP) && !g_pInput->getHoldedCommand(IC_DOWN)) m_vDir = NONE; moveLeft(MOVESPEED+m_swimupspeed); m_hDir = LEFT; } else if(g_pInput->getHoldedCommand(IC_RIGHT)) { if(!g_pInput->getHoldedCommand(IC_UP) && !g_pInput->getHoldedCommand(IC_DOWN)) m_vDir = NONE; moveRight(MOVESPEED+m_swimupspeed); m_hDir = RIGHT; } // Up and down swimming if( m_swimupspeed>0 && g_pInput->getHoldedCommand(IC_UP)) { moveUp(MOVESPEED+m_swimupspeed); m_vDir = UP; } else if(g_pInput->getHoldedCommand(IC_DOWN)) { moveDown(MOVESPEED+m_swimupspeed); m_vDir = DOWN; } else { moveDown(WATERFALLSPEED+m_swimupspeed); m_vDir = DOWN; } // Slow down the swim speed, by time if(m_swimupspeed>0) { m_swimupspeed--; if(m_swimupspeed<0) m_swimupspeed = 0; } if( m_breathtimer >= BREATH_TIME ) { playSound(SOUND_BUBBLE); int dir_offset = (m_hDir==RIGHT) ? +(1<<CSF) : -(1<<CSF) ; CBubbles *Bubble = new CBubbles(mp_Map, getXMidPos()+dir_offset, getYMidPos(), false); g_pBehaviorEngine->m_EventList.add( new EventSpawnObject( Bubble ) ); m_breathtimer = 0; } else m_breathtimer++; m_camera.process(); m_camera.processEvents(); }
void CAmpton::processWalking() { //play tic toc sound if(getActionStatus(A_AMPTON_WALK)) playSound(SOUND_AMPTONWALK0); else if(getActionStatus(A_AMPTON_WALK+1)) playSound(SOUND_AMPTONWALK1); int l_x_l = getXLeftPos(); int l_x_r = getXRightPos(); int l_w = getXRightPos() - getXLeftPos(); int l_h = getYDownPos() - getYUpPos(); int l_y = getYMidPos(); int l_x_mid = getXMidPos(); if ( (l_x_mid & 0x1FF) <= WALK_SPEED) { if(hitdetectWithTilePropertyRectRO(31, l_x_mid, l_y, l_w, l_h, 1<<CSF)) { setAction(A_AMPTON_FLIP_SWITCH); } if(hitdetectWithTilePropertyRectRO(1, l_x_mid, l_y, l_w, l_h, 1<<CSF)) { if( getProbability(600) ) //if (rand() < 0xC4) { bool polebelow = hitdetectWithTilePropertyHor(1, l_x_l, l_x_r, getYDownPos(), 1<<CSF); bool poleabove = hitdetectWithTilePropertyHor(1, l_x_l, l_x_r, getYUpPos(), 1<<CSF); if( getProbability(400) ) //if (rand() < 0x80) poleabove = false; else polebelow = false; //climb up if (poleabove) { setAction(A_AMPTON_START_POLE); yDirection = UP; return; } else if (polebelow) { setAction(A_AMPTON_START_POLE); yDirection = DOWN; return; } } } } // Move normally in the direction if( xDirection == RIGHT ) { moveRight( WALK_SPEED ); } else { moveLeft( WALK_SPEED ); } }