Example #1
0
void cMushroom :: Update( void )
{
	if( !visible )
	{
		return;
	}

	if( CollideBoundingBox( &rect, &pPlayer->rect ) )
	{
		visible = 0;
		pPlayer->Get_Item( type );
		
		if( type == TYPE_MUSHROOM_DEFAULT ) 
		{
			pointsdisplay->AddPoints( 500, (int)posx + image->w/2, (int)posy + 3 );
		}
		else if( type == TYPE_MUSHROOM_LIVE_1 ) 
		{
			pointsdisplay->AddPoints( 1000, (int)posx + image->w/2,(int)posy + 3 );
		}
	}

	onGround = !PosValid( (int)posx, (int)posy + 1 );

	if( !onGround && vely < 50 )
	{
		if( vely > 0 )
		{
			AddVel( 0, 0.5 + vely*0.05 );
		}
		else
		{
			AddVel( 0, 2.5 );
		}
	}
	else
	{
		vely = 0;
	}
	
	if( CollideMove() != DIR_NOTHING )
	{
		SDL_Rect r2 = Get_Collision_rect();
		
		if( ( iCollisionType == 1 || iCollisionType == 2 ) && ( col_dir == DIR_LEFT || col_dir == DIR_RIGHT ) )
		{
			velx *= -1;
			Move( velx, vely );
		}
		else if( posx == 0 && col_dir == DIR_LEFT ) 
		{
			velx *= -1;
			Move( velx, vely );
		}
	}

   	Draw( screen );
}
Example #2
0
void cGoomba :: Update( void )
{
	if( dead )
	{
		if( visible )
		{
			DieStep();
		}

		return;
	}

	walk_count += Framerate.speedfactor;
	
	if( walk_count > anispeed )
	{
		walk_count = 1;
	}
	
	if( walk_count > anispeed/2 )
	{
		SetImage( 0 );
	}
	else
	{
		SetImage( 1 );
	}
	
	CheckOnground();

	if( !onGround && vely < 25 )
	{
		AddVel( 0,2 + ( vely * 0.05 ) );
	}
	else if( onGround && vely > 0 )
	{
		vely = 0;
	}
	
	if( CollideMove() != DIR_NOTHING )
	{
		SDL_Rect r2 = Get_Collision_rect();
		
		if( iCollisionType && iCollisionType != 4 )
		{
			if( col_dir == DIR_RIGHT || col_dir == DIR_LEFT )
			{
				velx *= -1;
				Move( velx, vely );
			}
		}
		else if( posx < 1 )
		{
			velx *= -1;
			Move( velx, vely );
		}

		if( iCollisionType == 4 && massive )
		{
			PlayerCollision( col_dir );

   			if( EnemyObjects.size() && !dead && image )
			{
				if( col_dir != -1 ) 
				{
					velx *= -1;
				}

				Move( velx, vely );
			}
		}
	}

   	if( EnemyObjects.size() && !dead && image )
	{
		Draw( screen );
	}
}