Exemplo n.º 1
0
 void cMushroom::Handle_Collision_Box(ObjectDirection cdirection, GL_rect* r2)
 {
     if (cdirection == DIR_DOWN)
     {
         m_vely = -30.0f;
         
         if (m_pos_x > r2->m_x && m_velx < 0.0f)
         {
             Turn_Around(DIR_LEFT);
         }
         else if (m_pos_x < r2->m_x && m_velx > 0.0f)
         {
             Turn_Around(DIR_RIGHT);
         }
     }
     else if (cdirection == DIR_LEFT || cdirection == DIR_RIGHT)
     {
         m_vely = -13.0f;
         Turn_Around(cdirection);
     }
     else
     {
         return;
     }
     
     Reset_On_Ground();
 }
Exemplo n.º 2
0
void cMovingSprite :: Check_on_Ground( void )
{
	// can't be on ground
	if( !m_can_be_on_ground )
	{
		return;
	}

	if( m_type != TYPE_PLAYER && m_sprite_array != ARRAY_ENEMY && m_sprite_array != ARRAY_ACTIVE )
	{
		return;
	}

	// if ground object
	if( m_ground_object )
	{
		GL_rect rect2( m_col_rect.m_x, m_col_rect.m_y + m_col_rect.m_h, m_col_rect.m_w, 1.0f );

		// if on ground object
		if( m_ground_object->m_col_rect.Intersects( rect2 ) && m_ground_object->m_can_be_ground )
		{
			return;
		}
	}

	// don't check if flying or linked
	if( m_state == STA_FLY || m_state == STA_OBJ_LINKED )
	{
		return;
	}

	// new onground check
	cObjectCollisionType *col_list = Collision_Check_Relative( 0.0f, m_col_rect.m_h, 0.0f, 1.0f, COLLIDE_ONLY_BLOCKING );

	Reset_On_Ground();

	// possible ground objects
	for( cObjectCollision_List::iterator itr = col_list->objects.begin(), itr_end = col_list->objects.end(); itr != itr_end; ++itr )
	{
		cObjectCollision *col = (*itr);

		// ground collision found
		if( col->direction == DIR_BOTTOM )
		{
			if( Set_On_Ground( col->obj ) )
			{
				// send collision ( needed for falling platform )
				Send_Collision( col );
				break;
			}
		}
	}

	delete col_list;
}
Exemplo n.º 3
0
void cSpikeball :: Handle_Collision_Box( ObjectDirection cdirection, GL_rect *r2 )
{
	if( cdirection == DIR_DOWN )
	{
		m_vely = -10.0f;

		// left
		if( m_pos_x > r2->m_x )
		{
			m_velx += 3.0f;
		}
		// right
		else if( m_pos_x < r2->m_x )
		{
			m_velx -= 3.0f;
		}

		Reset_On_Ground();
	}
}
Exemplo n.º 4
0
void cMovingSprite :: Move_With_Ground( void )
{
	if( !m_ground_object || ( m_ground_object->m_sprite_array != ARRAY_ACTIVE && m_ground_object->m_sprite_array != ARRAY_ENEMY ) ) // || m_ground_object->sprite_array == ARRAY_MASSIVE
	{
		return;
	}

	cMovingSprite *moving_ground_object = dynamic_cast<cMovingSprite *>(m_ground_object);

	// invalid moving sprite
	if( !moving_ground_object )
	{
		return;
	}

	// does not move
	if( Is_Float_Equal( moving_ground_object->m_velx, 0.0f ) && Is_Float_Equal( moving_ground_object->m_vely, 0.0f ) )
	{
		return;
	}

	// check ground first because of the moving object velocity
	Check_on_Ground();
	// save posx for possible can not move test
	float posy_orig = m_pos_y;
	/* stop object from getting stopped of the moving object which did not yet move itself
	 * for example the player always moves as last
	*/
	bool is_massive = 0;
	if( moving_ground_object->m_massive_type == MASS_MASSIVE )
	{
		moving_ground_object->m_massive_type = MASS_PASSIVE;
		is_massive = 1;
	}
	// move
	Col_Move( moving_ground_object->m_velx, moving_ground_object->m_vely, 0, 0, 0 );

	if( is_massive )
	{
		moving_ground_object->m_massive_type = MASS_MASSIVE;
	}
	// if ground object is moving up
	if( moving_ground_object->m_vely < -0.01f )
	{
		// test if we could not move upwards because something did block us in Col_Move()
		if( Is_Float_Equal( m_pos_y, posy_orig ) )
		{
			// massive
			if( moving_ground_object->m_massive_type == MASS_MASSIVE )
			{
				// got crunched
				DownGrade( 1 );
			}
			// halfmassive
			else if( moving_ground_object->m_massive_type == MASS_HALFMASSIVE )
			{
				// lost ground
				Move( 0.0f, 1.9f, 1 );
				Reset_On_Ground();
			}
		}
	}
}