Exemplo n.º 1
0
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;
  }
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
bool CRoboRed::isNearby(CSpriteObject &theObject)
{
    if( dynamic_cast<CPlayerLevel*>(&theObject) )
    {
        mLookTimer++;
        if(mLookTimer < TIME_UNTIL_LOOK)
            return true;

        mLookTimer = 0;

        mKeenNearby = false;

        const int objX = theObject.getXMidPos();
        const int roboX = getXMidPos();
        const int dx = objX - roboX;

        if( theObject.getYDownPos() > getYUpPos() && theObject.getYUpPos() < getYDownPos() )
        {
            if(getActionNumber(A_RED_PAUSE))
            {
                if( theObject.getXMidPos() < getXMidPos() )
                    xDirection = LEFT;
                else
                    xDirection = RIGHT;
            }

            if( std::abs(dx) < CSF_DISTANCE_TO_SHOOT )
            {
                mKeenNearby = true;
            }
        }
    }

    return true;
}
Exemplo n.º 4
0
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;
}
Exemplo n.º 5
0
bool CGarg::isNearby(CVorticonSpriteObject &theObject)
{       
    if(CPlayer *player = dynamic_cast<CPlayer*>(&theObject))
    {
	if( state == GARG_LOOK )
	{
		if (looktimes>GARG_NUM_LOOKS)
		{
			// try to head towards Keen...
			if (player->getXPosition() < getXPosition())
				movedir = LEFT;
			else
				movedir = RIGHT;
		}		
	}
	
	else if( state == GARG_MOVE )
	{
		// is keen on same level?
		if ( player->getYDownPos() >= getYDownPos()-(16<<STC) )
		{
		    if ( player->getYDownPos() <= getYDownPos()+(16<<STC) )
		    {
			keenonsameleveltimer++;
			if (keenonsameleveltimer > GARG_SAME_LEVEL_TIME)
			{ // charge!!
				keenonsameleveltimer = 0;
				timer = 0;
				looktimes = 1;
				about_to_charge = 1;
				state = GARG_LOOK;
			}
			
			return true;
		    }
		}
		keenonsameleveltimer = 0;
	}	
    }
    return true;
}
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);
	}
}
Exemplo n.º 7
0
bool CPlayer::checkObjSolid()
{
	if(pSupportedbyobject)
	{
		pfalling = false;
		if(pjumping == PJUMPLAND)
		    pjumping = PNOJUMP;
		
		int dy = pSupportedbyobject->getYPosition() - getYDownPos()+3;
		if(pjumping == PNOJUMP)
		{
		    moveYDir(dy);
		}
		blockedd = true;		
	}
	
	return true;
}
Exemplo n.º 8
0
bool CFoob::isNearby(CVorticonSpriteObject &theObject)
{
    if(CPlayer *player = dynamic_cast<CPlayer*>(&theObject))
    {
        if ( (player->getYDownPos() >= getYUpPos()-(2<<CSF)) &&
             (player->getYDownPos() <= getYDownPos()+(1<<CSF)) )
        {
            onsamelevel = true;
            SpookedByWho = player->m_index;
        }

        if(state == FOOB_SPOOK)
        {
            mSpriteIdx = FOOB_SPOOK_FRAME;

            if (spooktimer > FOOB_SPOOK_SHOW_TIME)
            {
                state = FOOB_FLEE;
                OffOfSameLevelTime = 0;
                // run away from the offending player

                if (player->getXPosition() < getXPosition())
                    dir = RIGHT;
                else
                    dir = LEFT;

                // in hard mode run TOWARDS the player (he's deadly in hard mode)
                if (gBehaviorEngine.mDifficulty == HARD)
                {
                    dir = (dir==LEFT) ? RIGHT : LEFT;
                }

            }
            else spooktimer++;
        }
    }
    
    return true;
}
Exemplo n.º 9
0
void CYorp::getTouchedBy(CVorticonSpriteObject &theObject)
{
	if(CPlayer *player = dynamic_cast<CPlayer*>(&theObject))
	{
		// code for the yorps to push keen, and code for them to get stunned
		if (state != YORP_STUNNED && state != YORP_DYING  && !player->pdie)
		{
			if ( player->getYDownPos() < getYDownPos()-(1<<CSF) )
			{
				if (!m_hardmode)
				{
					playSound(SOUND_YORP_STUN);
					state = YORP_STUNNED;
					looktimes = 0;
					timer = 0;
					lookposition = 0;
					player->ppogostick = false;
				}

				// make the yorp look a little less "soft" by
				// offering a bit of resistance
				// (actually, having keen do a small jump)
				player->pjumptime = 0;
				player->pjumpupdecreaserate = 0;
				player->pjumpupspeed = 7;
				player->pjumping = PJUMPUP;
				player->pjustjumped = true;
			}
			else
			{
				// if yorp is moving, also push in direction he's moving
				// in. this allows walking through a yorp if he is walking
				// away from Keen
				player->bump( movedir );
			}
		}
	}
}
Exemplo n.º 10
0
void CPoisonSlug::processCrawling()
{

    if( m_timer < SLUG_MOVE_TIMER )
    {
        m_timer++;
        return;
    }
    else
    {
        m_timer = 0;
    }

    // Chance to poo
    if( getProbability(30) )
    {
        m_timer = 0;
        setAction( A_SLUG_POOING );
        playSound( SOUND_SLUG_DEFECATE );
        CSlugSlime *slime = new CSlugSlime(mp_Map, 0, getXMidPos(), getYDownPos()-(1<<(CSF-1)), 0);
        gEventManager.add( new EventSpawnObject( slime ) );

        xDirection = -xDirection;
        return;
    }

    // Move normally in the direction
    if( xDirection == RIGHT )
    {
        moveRight( 2*m_Action.h_anim_move );
    }
    else
    {
        moveLeft( 2*m_Action.h_anim_move );
    }
}
Exemplo n.º 11
0
void CPoisonSlug::processCrawling()
{

    if( m_timer < SLUG_MOVE_TIMER )
    {
	m_timer++;
	return;
    }
    else
    {
	m_timer = 0;
    }

	// Chance to poo
	if( getProbability(30) )
	{
		m_timer = 0;
		setAction( A_SLUG_POOING );
		playSound( SOUND_SLUG_DEFECATE );
		CSlugSlime *slime = new CSlugSlime(mp_Map, 0, getXMidPos(), getYDownPos()-(1<<CSF));
		g_pBehaviorEngine->m_EventList.add( new EventSpawnObject( slime ) );
		
		xDirection = -xDirection;
		return;		
	}

	// Move normally in the direction
	if( xDirection == RIGHT )
	{
		moveRight( m_Action.velX<<1 );
	}
	else
	{
		moveLeft( m_Action.velX<<1 );
	}
}
Exemplo n.º 12
0
/**
 * Called when Flag is flying to the pole
 */
void CFlag::processFlipping()
{
	if(m_Pos != m_destination)
	{        
        Vector2D<int> dir = m_destination - m_Pos;
        const float length = dir.GetLength();
        Vector2D<float> base_dir( dir.x/length, dir.y/length );

		if( fabs(length) < SPEED )
		{
			moveTo(m_destination);
		}
		else
		{
			moveDir(base_dir*SPEED);
		}
	}
	else
	{
	    setAction(A_FLAG_WAVE);        
	    setActionSprite();
	    g_pSound->playSound( SOUND_FLAG_LAND );
	    
	    const auto episode = gpBehaviorEngine->getEpisode();
        if(episode == 6)
        {
            Vector2D<int> tilePos = m_Pos;

            tilePos.y = getYDownPos();

            Uint32 new_tile_no = mp_Map->getPlaneDataAt(1, tilePos)+1;
            tilePos = tilePos>>CSF;
            mp_Map->setTile(tilePos.x, tilePos.y, new_tile_no, true);
        }
        mp_Map->unlock();
	}
Exemplo n.º 13
0
void CRocket::processFlying()
{
    int xBlockPos = target.x - getXPosition();
    int yBlockPos = target.y - getYPosition();
    
    const int xBlockPosAbs = (xBlockPos<0) ? -xBlockPos : xBlockPos;
    const int yBlockPosAbs = (yBlockPos<0) ? -yBlockPos : yBlockPos;
    
    
    if( xBlockPosAbs < MOVE_SPEED && yBlockPosAbs < MOVE_SPEED )
    {
	const Uint16 object = mp_Map->getPlaneDataAt(2, target.x, target.y);
	
	Vector2D<int> speed(xBlockPos, yBlockPos);	    
	moveDir(speed);
	playSound(SOUND_ROCKET_DRIVE);
	
	// Happens when the rocket find a place where to stop
	if(object == 0x6A || object == 0x69)
	{
	    xDirection = CENTER;
	    yDirection = UP;
	    setAction(A_ROCKET_SIT);
	    detectNextTarget(target, xDirection, yDirection);
	    
	    Vector2D<int> newPlayerPos = m_Pos;
	    
	    newPlayerPos.y = getYDownPos();
	    newPlayerPos.x = getXRightPos();
	    
	    mpCarriedPlayer->moveToForce(newPlayerPos);
	    mpCarriedPlayer->solid = true;
	    mpCarriedPlayer->dontdraw = false;
	    mpCarriedPlayer = nullptr;
	    return;
	}

	readDirection(object, xDirection, yDirection );
	
	// If there is an object that changes the direction of the rocket, apply it!	
	detectNextTarget(target, xDirection, yDirection);		
    }
    
    Vector2D<int> speed;
    
    if(yDirection == UP)
    {
	speed.y = -MOVE_SPEED;
    }
    else if(yDirection == DOWN)
    {
	speed.y = MOVE_SPEED;
    }    
    
    if(xDirection == RIGHT)
    {
	speed.x = MOVE_SPEED;
    }
    else if(xDirection == LEFT)
    {
	speed.x = -MOVE_SPEED;
    }
    
    if(mpCarriedPlayer != nullptr)
    {
	mpCarriedPlayer->moveDir(speed);
    }
    moveDir(speed);
}
Exemplo n.º 14
0
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 );
  }   
}
Exemplo n.º 15
0
void CGarg::process()
{
	// kill player on touch
	if (state!=GARG_DYING && touchPlayer)
		m_Player[touchedBy].kill();

	// did the garg get shot?
	if (HealthPoints <= 0 && state != GARG_DYING )
	{
		// die, you stupid garg, die!
		state = GARG_DYING;
		dying = true;
		sprite = GARG_DYING_FRAME;
		yinertia = GARGDIE_START_INERTIA;
		playSound(SOUND_GARG_DIE);
	}

	// Check, if Garg is moving and collides and change directions whenever needed
	if(state != GARG_LOOK &&  state != GARG_CHARGE && state != GARG_DYING)
	{
		// Set the proper frame
		sprite = (movedir==LEFT) ? GARG_WALK_LEFT : GARG_WALK_RIGHT;
		sprite += walkframe;

		// collides? Change direction
		if( movedir==LEFT && blockedl )
			movedir = RIGHT;
		else if( movedir==RIGHT && blockedr )
			movedir = LEFT;

		// Compute the speed
		xinertia = (m_hardmode) ? GARG_WALK_SPEED_FAST : GARG_WALK_SPEED;

		// Set the correct speed according to direction
		if(movedir == LEFT)
			xinertia = -xinertia;
		dist_traveled++;
	}

	switch(state)
	{
	case GARG_DYING:
		if ( blockedd && yinertia >= 0 )
		{
			sprite = GARG_DEAD_FRAME;
			dead = true;
		}
		break;
	case GARG_LOOK:
		if (looktimes>GARG_NUM_LOOKS)
		{
			// try to head towards Keen...
			if (m_Player[detectedPlayerIndex].getXPosition() < getXPosition())
				movedir = LEFT;
			else
				movedir = RIGHT;

			if (!about_to_charge && rnd()%3==1)
				// 25% prob, go the other way (but always charge towards player)
				movedir ^= 1;

			// however if we're blocked on one side we must go the other way
			if (blockedl)
				movedir = RIGHT;
			else if (blockedr)
				movedir = LEFT;

			timer = 0;
			walkframe = 0;
			dist_traveled = 0;
			if (about_to_charge)
			{
				state = GARG_CHARGE;
				about_to_charge = 0;
			}
			else state = GARG_MOVE;
		}

		// look animation
		if (!timer)
		{
			sprite = GARG_STAND + lookframe;
			looktimes++;

			if (++lookframe>3)
			{
				lookframe=0;
			}
			timer = GARG_LOOK_TIME;
		} else timer--;
		break;
	case GARG_MOVE:
	{
		// is keen on same level?
		detectedPlayer = 0;

		std::vector<CPlayer>::iterator it = m_Player.begin();
		for( size_t i=0 ; it != m_Player.end() ; it++ )
		{
			if ( it->getYDownPos() >= getYDownPos()-(16<<STC) )
			{
				if ( it->getYDownPos() <= getYDownPos()+(16<<STC) )
				{
					detectedPlayer = 1;
					detectedPlayerIndex = i;
					break;
				}
			}
			i++;
		}

		if (detectedPlayer)
		{
			keenonsameleveltimer++;
			if (keenonsameleveltimer > GARG_SAME_LEVEL_TIME)
			{ // charge!!
				keenonsameleveltimer = 0;
				timer = 0;
				looktimes = 1;
				about_to_charge = 1;
				state = GARG_LOOK;
			}
		} else keenonsameleveltimer = 0;

		// every now and then go back to look state
		if (dist_traveled > GARG_MINTRAVELDIST)
		{
			if (rnd()%GARG_LOOK_PROB==(GARG_LOOK_PROB/2))
			{
				looktimes = 0;
				timer = 0;
				state = GARG_LOOK;
				break;
			}
		}

		// walk animation
		if (timer > GARG_WALK_ANIM_TIME ||
				(timer > GARG_WALK_ANIM_TIME && m_hardmode))
		{
			walkframe ^= 1;
			timer = 0;
		} else timer++;
	}
	break;
	case GARG_JUMP:
		if( jumptime > 0 )
			jumptime--;
		else
			state = GARG_CHARGE;

		if( blockedd ) // There is floor
			state = GARG_CHARGE;

		charge();
		break;
	case GARG_CHARGE:
		charge();

		// if Garg is about to fall while charged make him jump
		if( !blockedd )
		{
			state = GARG_JUMP;
			yinertia = -(GARG_JUMP_SPEED);
			jumptime = GARG_JUMP_TIME;
		}

		break;
	default: break;
	}
}
Exemplo n.º 16
0
// Process the touching of certain tile, like items and hazards...
void CPlayerBase::processLevelMiscFlagsCheck()
{
	// Item which are taken must go into a data structure
	// animation should also be triggered

	stItemGalaxy &m_Item = m_Inventory.Item;

	int l_x = getXLeftPos();
	int l_y = getYUpPos();
	int l_w = getXRightPos() - getXLeftPos();
	int l_h = getYDownPos() - getYUpPos();


	// Deadly hazards! Here Keen dying routine will be triggered
	if(hitdetectWithTilePropertyRect(3, l_x, l_y, l_w, l_h, 2<<STC))
	{
		kill();
        return;
	}

	// Another property of the tiles may kill keen, also in god mode
	std::vector<CTileProperties> &Tile = g_pBehaviorEngine->getTileProperties(1);
	// TODO: Workaround! It seems that the deadly tiles are 17 tiles behind. Not sure, why!
	const int tileIDl = mp_Map->getPlaneDataAt(1, l_x, (l_y+l_h)+(1<<STC));
	const int tileIDr = mp_Map->getPlaneDataAt(1, l_x+l_w, (l_y+l_h)+(1<<STC));
	if(Tile[tileIDl].bup == 9 && Tile[tileIDr].bup == 9 )
	{
	    if(!m_Cheatmode.god)
	    {
		kill(true);
	    }
	}


	if(hitdetectWithTilePropertyRect(4, l_x, l_y, l_w, l_h, 2<<STC))
	{
	  int dropanimation_sprite = 215;	  
	  const int ep = g_pBehaviorEngine->getEpisode();
	  
	  if(ep == 5)
	  {
	    dropanimation_sprite = 225;
	  }
	  else if(ep == 6)
	  {
	    dropanimation_sprite = 224;
	  }	    
	  
	  const int lc_x = l_x>>CSF;
	  const int lc_y = l_y>>CSF;
	  mp_Map->setTile( lc_x, lc_y, 0, true, 1 );
	  CItemEffect *iEffect = new CItemEffect(mp_Map, 0, lc_x<<CSF, lc_y<<CSF, dropanimation_sprite, ANIMATE);
	  g_pBehaviorEngine->m_EventList.spawnObj( iEffect );
	  m_Item.m_drops++;
	  
	  if(m_Item.m_drops >= 100)
	  {
	    m_Item.m_drops = 0;
	    getAnotherLife(lc_x, lc_y, true, true);
	  }
	  
	  g_pSound->playSound( SOUND_GET_DROP );
	}
Exemplo n.º 17
0
void CVortiNinja::process()
{
	bool onsamelevel;

	if (touchPlayer && !m_Player[touchedBy].pdie && \
			state != NINJA_DYING)
		m_Player[touchedBy].kill();

	if (HealthPoints <= 0 && !dying)
	{
		dying = true;
		dietimer = 0;
		playSound(SOUND_VORT_DIE);
	}


	if (dying)
	{
		if (state == NINJA_STAND)
			state = NINJA_DYING;

		dietimer++;
		if (dietimer > NINJA_DYING_SHOW_TIME)
		{
			sprite = NINJA_DEAD_FRAME;
			dead = true;
		}
	}

	switch(state)
	{

	case NINJA_STAND:
		if (m_Player[0].getXPosition() < getXPosition()+(8<<STC))
			dir = LEFT;
		else
			dir = RIGHT;

		if (!timetillkick)
		{
			state = NINJA_KICK;

			if (rnd()&1)
			{
				// high, short jump
				longjump = false;
				yinertia = -120;
			}
			else
			{
				// low, long jump
				longjump = true;
				yinertia = -30;
			}

		}
		else
		{
			// find out if a player is on the same level
			onsamelevel = false;

			std::vector<CPlayer>::iterator it_player = m_Player.begin();
			for( ; it_player != m_Player.end() ; it_player++ )
			{
				if ((it_player->getYPosition() >= getYPosition()-(96<<STC)) &&
					(it_player->getYDownPos() <= (getYDownPos()+(96<<STC))))
				{
					onsamelevel = true;
					break;
				}
			}

			if (onsamelevel)
				timetillkick--;
		}

		sprite = (dir==LEFT) ? NINJA_STAND_LEFT_FRAME : NINJA_STAND_RIGHT_FRAME;
		sprite += animframe;

		if (animtimer > NINJA_STAND_ANIM_RATE)
		{
			animframe ^= 1;
			animtimer = 0;
		}
		else
			animtimer++;
		break;

	case NINJA_KICK:
		if (!dying)
			sprite = (dir==LEFT) ? NINJA_KICK_LEFT_FRAME : NINJA_KICK_RIGHT_FRAME;
		else
			state = NINJA_DYING;

		if (blockedd && yinertia == 0)
		{
			if (!dying)
				init();
			else
				state = NINJA_DYING;

			break;
		}

		if(longjump)
			xinertia = (mp_Map->m_Difficulty>1) ? 150 : 120;
		else
			xinertia = (mp_Map->m_Difficulty>1) ? 95 : 75;

		if (dir==LEFT)
			xinertia = -xinertia;

		break;

	case NINJA_DYING:
		sprite = NINJA_DYING_FRAME;

		if (dietimer > NINJA_DYING_SHOW_TIME)
		{
			sprite = NINJA_DEAD_FRAME;
			dead = true;
		}
		break;
	default: break;
	}
}
Exemplo n.º 18
0
void CVorticonElite::process()
{
	if (HealthPoints <= 0 && state != VORTELITE_DYING)
	{
		animtimer = 0;
		frame = 0;
		state = VORTELITE_DYING;
		dying = true;

		if (onscreen)
			playSound(SOUND_VORT_DIE);
	}

	if(state == VORTELITE_CHARGE)
	{
		m_speed = CHARGE_SPEED;
	}
	else if(state == VORTELITE_WALK)
	{
		m_speed = WALK_SPEED;
	}

	reprocess: ;
	switch(state)
	{
	case VORTELITE_CHARGE:
	case VORTELITE_WALK:
		dist_traveled++;

		state = VORTELITE_WALK;

		// If Player is nearby, make vorticon go faster
		if(getYDownPos() > m_Player[0].getYDownPos()-(1<<CSF) and
		   getYDownPos() < m_Player[0].getYDownPos()+(1<<CSF) )
		{
			int dist;
			if(getXMidPos() > m_Player[0].getXMidPos())
				dist = getXMidPos()-m_Player[0].getXMidPos();
			else
				dist = m_Player[0].getXMidPos()-getXMidPos();

			if(dist < PLAYER_DISTANCE)
				state = VORTELITE_CHARGE;
		}


		if (getProbability(VORTELITE_JUMP_PROB) && !mp_Map->m_Dark && !blockedu)
		{  // let's jump.
			initiatejump();
			goto reprocess;
		}
		else
		{
			if (timesincefire > VORTELITE_MIN_TIME_BETWEEN_FIRE)
			{
				if (getProbability(VORTELITE_FIRE_PROB))
				{  	// let's fire
					// usually shoot toward keen
					if (rand()%5 != 0)
					{
						if (getXPosition() < m_Player[0].getXPosition())
						{
							movedir = RIGHT;
						}
						else
						{
							movedir = LEFT;
						}
					}
					timer = 0;
					state = VORTELITE_ABOUTTOFIRE;
				}
			}
			else timesincefire++;
		}

		if (movedir==LEFT)
		{  // move left
			sprite = VORTELITE_WALK_LEFT_FRAME + frame;
			if (!blockedl)
			{
				xinertia = -m_speed;
			}
			else
			{
				movedir = RIGHT;

				// if we only traveled a tiny amount before hitting a wall, we've
				// probably fallen into a small narrow area, and we need to try
				// to jump out of it
				if (dist_traveled < VORTELITE_TRAPPED_DIST && !mp_Map->m_Dark && blockedd)
				{
					initiatejump();
					goto reprocess;
				}
				else dist_traveled = 0;
			}
		}
		else
		{  // move right
			sprite = VORTELITE_WALK_RIGHT_FRAME + frame;
			if (!blockedr)
			{
				xinertia = m_speed;
			}
			else
			{
				movedir = LEFT;

				// if we only traveled a tiny amount before hitting a wall, we've
				// probably fallen into a small narrow area, and we need to try
				// to jump out of it
				if (dist_traveled < VORTELITE_TRAPPED_DIST && !mp_Map->m_Dark && blockedd)
				{
					initiatejump();
					goto reprocess;
				}
				else dist_traveled = 0;
			}
		}

		// walk animation
		if (animtimer > VORTELITE_WALK_ANIM_TIME)
		{
			if (frame>=3) frame=0;
			else frame++;
			animtimer = 0;
		} else animtimer++;
		break;

	case VORTELITE_JUMP:
		if (movedir == RIGHT)
		{ if (!blockedr) moveRight(m_speed); }
		else
		{ if (!blockedl) moveLeft(m_speed); }

		if (blockedd && yinertia >= 0)
		{  // The Vorticon Has landed after the jump!
			state = VORTELITE_WALK;
			goto reprocess;
		}

		break;
	case VORTELITE_ABOUTTOFIRE:
		if (movedir==RIGHT)
		{ sprite = VORTELITE_FIRE_RIGHT_FRAME; }
		else
		{ sprite = VORTELITE_FIRE_LEFT_FRAME; }
		if (timer > VORTELITE_HOLD_GUN_OUT_TIME)
		{
			timer = 0;
			state = VORTELITE_FIRED;

			CRay *newobject;
			if (movedir==RIGHT)
				newobject = new CRay(mp_Map, getXRightPos()+1, getYPosition()+(9<<STC), RIGHT);
			else
				newobject = new CRay(mp_Map, getXLeftPos()-1, getYPosition()+(9<<STC), LEFT);
			newobject->setOwner( m_type, m_index);
			newobject->sprite = ENEMYRAYEP2;
			// don't shoot other vorticon elite
			m_Object.push_back(newobject);

			if (onscreen)
				playSound(SOUND_KEEN_FIRE);
		}
		else timer++;
		break;
	case VORTELITE_FIRED:
		if (movedir==RIGHT)
		{ sprite = VORTELITE_FIRE_RIGHT_FRAME; }
		else
		{ sprite = VORTELITE_FIRE_LEFT_FRAME; }

		if (timer > VORTELITE_HOLD_GUN_AFTER_FIRE_TIME)
		{
			timer = 0;
			frame = 0;
			timesincefire = 0;
			state = VORTELITE_WALK;
			// head toward keen
			if (getXPosition() < m_Player[0].getXPosition())
			{
				movedir = RIGHT;
			}
			else
			{
				movedir = LEFT;
			}
		}
		else timer++;
		break;
	case VORTELITE_DYING:
		sprite = VORTELITE_DYING_FRAME;
		if (animtimer > VORTELITE_DIE_ANIM_TIME)
		{
			sprite = VORTELITE_DEAD_FRAME;
			dead = true;
		}
		else
		{
			animtimer++;
		}
		break;
	default: break;
	}
}
bool CVorticonElite::isNearby(CVorticonSpriteObject &theObject)
{
    if( CPlayer *player = dynamic_cast<CPlayer*>(&theObject) )
    {
        if(state == VORTELITE_WALK)
        {

            if(getYDownPos() > player->getYDownPos()-(2<<CSF) and
                    getYDownPos() < player->getYDownPos()+(2<<CSF) )
            {
                int dist;
                if(getXMidPos() > player->getXMidPos())
                {
                    if (rand()%10 != 0)
                        movedir = LEFT;

                    dist = getXMidPos()-player->getXMidPos();
                }
                else
                {
                    if (rand()%10 != 0)
                        movedir = RIGHT;

                    dist = player->getXMidPos()-getXMidPos();
                }

                // If Player is nearby, make vorticon go faster
                if(dist < PLAYER_DISTANCE)
                    state = VORTELITE_CHARGE;
            }

            dist_traveled++;


            if (getProbability(VORTELITE_JUMP_PROB) && !mp_Map->m_Dark && !blockedu)
            {  // let's jump.
                initiatejump();
                return true;
            }
            else
            {
                if (timesincefire > VORTELITE_MIN_TIME_BETWEEN_FIRE)
                {
                    if (getProbability(VORTELITE_FIRE_PROB))
                    {  	// let's fire
                        // usually shoot toward keen
                        if (rand()%5 != 0)
                        {
                            if (getXPosition() < player->getXPosition())
                                movedir = RIGHT;
                            else
                                movedir = LEFT;
                        }
                        timer = 0;
                        state = VORTELITE_ABOUTTOFIRE;
                    }
                }
                else timesincefire++;
            }
        }
    }
    
    return true;
}