Exemplo n.º 1
0
 void cEnemy::Update_Late(void)
 {
     if (m_state == STA_OBJ_LINKED)
     {
         Move(pPlayer->m_velx, pPlayer->m_vely);
         
         m_massive_type = MASS_MASSIVE;
         cObjectCollisionType* col_list = Collision_Check(&m_col_rect);
         Add_Collisions(col_list, 1);
         delete col_list;
         Handle_Collisions();
         m_massive_type = MASS_PASSIVE;
     }
 }
Exemplo n.º 2
0
void cMovingSprite :: Update_Anti_Stuck( void )
{
	// collision count
	cObjectCollisionType *col_list = Collision_Check( &m_col_rect, COLLIDE_ONLY_BLOCKING );

	// check collisions
	for( cObjectCollision_List::iterator itr = col_list->objects.begin(), itr_end = col_list->objects.end(); itr != itr_end; ++itr )
	{
		cObjectCollision *collision = (*itr);
		cSprite *col_obj = collision->obj;

		if( collision->m_array == ARRAY_ENEMY || ( collision->m_array == ARRAY_ACTIVE && ( col_obj->m_massive_type == MASS_HALFMASSIVE || col_obj->m_massive_type == MASS_CLIMBABLE ) ) )
		{
			continue;
		}

		debug_print( "Anti Stuck detected object %s on %s side\n", col_obj->m_name.c_str(), Get_Direction_Name( collision->direction ).c_str() );

		if( collision->direction == DIR_LEFT ) 
		{
			Col_Move( 1.0f, 0.0f, 0, 1 );
		}
		else if( collision->direction == DIR_RIGHT ) 
		{
			Col_Move( -1.0f, 0.0f, 0, 1 );
		}
		else if( collision->direction == DIR_UP ) 
		{
			Col_Move( 0.0f, 1.0f, 0, 1 );
		}
		else if( collision->direction == DIR_DOWN ) 
		{
			Col_Move( 0.0f, -1.0f, 0, 1 );
		}
	}

	delete col_list;
}
Exemplo n.º 3
0
void MechanicHandler::Update(Player& player1, Player& player2, sf::RenderWindow& window, sf::Time delta_time)
{

	sf::Vector2f bullet_velocity;

	cooldown += delta_time.asSeconds();

	sf::Vector2f d_position = sf::Vector2f(0, 0);
	float rotation = 0.0f;

	switch(game_state)
	{
	case GameState::PAUSED:

		game_state = GameState::PLAYER1_AIMING;
		std::cout << player1.Get_Player_Name() << "'s turn" << std::endl;
		break;

	case GameState::PLAYER1_AIMING:
	
		d_position = sf::Vector2f(player1.Get_Mouse_Position(window).x - player1.Get_Center_Position().x, player1.Get_Mouse_Position(window).y - player1.Get_Center_Position().y);
		rotation = atan2f(d_position.x, d_position.y) * 180 / PI + 270;
		player1.Set_Cannon_Rotation(-rotation);

		if (player1.Get_Mouse_Click())
		{	
			bullet_velocity = Normalize_Vector(sf::Vector2f(player1.Get_Mouse_Position(window).x, player1.Get_Mouse_Position(window).y) - player1.Get_Position());

			bullet.Set_Position(player1.Get_Center_Position());
			bullet.Set_Velocity(bullet_velocity);
			bullet.Set_Bullet_Status(true);
			game_state = GameState::PLAYER1_SHOT;
			
			std::cout << player1.Get_Player_Name() <<" shot a bullet! " << std::endl;
		}

		break;

	case GameState::PLAYER1_SHOT:
		
		timer += delta_time.asSeconds();
		Collision_Check(player2);
		if (timer > 8)
		{
			timer += delta_time.asSeconds();
			cooldown += delta_time.asSeconds();

			std::cout << player2.Get_Player_Name() << "'s turn" << std::endl;
			game_state = GameState::PLAYER2_AIMING;
			bullet.Set_Bullet_Status(false);
			timer = 0;
		}
		break;

	case GameState::PLAYER2_AIMING:

		d_position = sf::Vector2f(player2.Get_Mouse_Position(window).x - player2.Get_Center_Position().x, player2.Get_Mouse_Position(window).y - player2.Get_Center_Position().y);
		rotation = atan2f(d_position.x, d_position.y) * 180 / PI + 270;
		player2.Set_Cannon_Rotation(-rotation);

		if (player2.Get_Mouse_Click())
		{
			std::cout << player2.Get_Player_Name() << " shot a bullet! " << std::endl;
			bullet_velocity = Normalize_Vector(sf::Vector2f(player2.Get_Mouse_Position(window).x, player2.Get_Mouse_Position(window).y) - player2.Get_Center_Position());
			bullet.Set_Position(player2.Get_Center_Position());
			bullet.Set_Velocity(bullet_velocity);
			bullet.Set_Bullet_Status(true);
			game_state = GameState::PLAYER2_SHOT;
			
		}
		
		break;

	case GameState::PLAYER2_SHOT:

		timer += delta_time.asSeconds();
		Collision_Check(player1);

		if (timer > 8)
		{
			std::cout << player1.Get_Player_Name() <<"'s turn" << std::endl;
			game_state = GameState::PLAYER1_AIMING;
			bullet.Set_Bullet_Status(false);
			timer = 0;
		}

		break;
	}

	bullet.Update(delta_time);
	bullet.Draw(window);

	client->Update(bullet.Get_Position());
}
Exemplo n.º 4
0
void cSpinBox :: Update( void )
{
	if( !m_valid_update || !Is_In_Range() )
	{
		return;
	}

	cBaseBox::Update();

	if( m_spin )
	{
		m_spin_counter += pFramerate->m_speed_factor;

		// spinning animation finished
		if( m_curr_img == 1 )
		{
			// spinning time finished
			if( m_spin_counter > speedfactor_fps * 5 )
			{
				// reset spin counter
				m_spin_counter = 0.0f;
				// set to massive for collision check
				m_massive_type = MASS_MASSIVE;
				// collision data
				cObjectCollisionType *col_list = Collision_Check( &m_col_rect, COLLIDE_ONLY_BLOCKING );
				
				// check if spinning should continue
				bool spin_again = 0;

				// colliding with player or enemy
				if( col_list->Is_Included( TYPE_PLAYER ) || col_list->Is_Included( ARRAY_ENEMY ) )
				{
					spin_again = 1;
				}
				// colliding with an active object
				else if( col_list->Is_Included( ARRAY_ACTIVE ) )
				{
					cSprite *col_obj = col_list->Find_First( ARRAY_ACTIVE )->m_obj;
					
					// check for items
					if( col_obj->m_type == TYPE_MUSHROOM_LIVE_1 || col_obj->m_type == TYPE_MUSHROOM_DEFAULT || 
						col_obj->m_type == TYPE_MUSHROOM_POISON || col_obj->m_type == TYPE_MUSHROOM_BLUE || col_obj->m_type == TYPE_MUSHROOM_GHOST || 
						col_obj->m_type == TYPE_FIREPLANT || col_obj->m_type == TYPE_STAR || col_obj->m_type == TYPE_FALLING_GOLDPIECE )
					{
						// found blocking active object
						spin_again = 1;
					}
				}

				delete col_list;

				// continue spinning
				if( spin_again )
				{
					// spin some time again
					m_spin_counter = speedfactor_fps * 2;
					// passive for spinning
					m_massive_type = MASS_PASSIVE;
				}
				// finished spinning
				else
				{
					Stop();
				}
			}
		}
	}
}
Exemplo n.º 5
0
cObjectCollisionType *cMovingSprite :: Collision_Check_Absolute( const float x, const float y, const float w /* = 0 */, const float h /* = 0 */, const ColCheckType check_type /* = COLLIDE_COMPLETE */, cSprite_List *objects /* = NULL */ )
{
	// save original rect
	GL_rect new_rect;

	// if given use x position
	if( !Is_Float_Equal( x, 0.0f ) )
	{
		new_rect.m_x = x;
	}
	else
	{
		new_rect.m_x = m_col_rect.m_x;
	}

	// if given use y position
	if( !Is_Float_Equal( y, 0.0f ) )
	{
		new_rect.m_y = y;
	}
	else
	{
		new_rect.m_y = m_col_rect.m_y;
	}

	// if given use width
	if( w > 0.0f )
	{
		new_rect.m_w = w;
	}
	else
	{
		new_rect.m_w = m_col_rect.m_w;
	}

	// if given use height
	if( h > 0.0f )
	{
		new_rect.m_h = h;
	}
	else
	{
		new_rect.m_h = m_col_rect.m_h;
	}

	// visual debugging
	if( game_debug )
	{
		// create request
		cRect_Request *request = new cRect_Request();

		pVideo->Draw_Rect( &new_rect, m_pos_z + 0.00001f, &green, request );
		request->no_camera = 0;

		request->blend_sfactor = GL_SRC_COLOR;
		request->blend_dfactor = GL_DST_ALPHA;


		// add request
		pRenderer->Add( request );
	}

	// return collisions list
	return Collision_Check( &new_rect, check_type, objects );
}