예제 #1
0
파일: move.c 프로젝트: nsvir/Wolf3D
void		move(t_event *event, float i)
{
  t_data	*data;
  float		x;
  float		y;
  float		c_x;
  float		c_y;
  float		angle;

  data = event->data;
  angle = data->a / 180 * PI;
  x = data->x_p + (Y_SENSITIVE * cos(angle) * i);
  c_x = data->x_p + ((Y_SENSITIVE * 4) * cos(angle) * i);
  y = data->y_p + (Y_SENSITIVE * sin(angle) * i);
  c_y = data->y_p + ((Y_SENSITIVE * 4) * sin(angle) * i);
  if (x < 0 || y < 0 || (int)y >= my_tablen(data->map) ||
      (int)x >= my_strlen(data->map[(int)y]))
    return;
  if (c_y >= 0 && c_y < my_tablen(data->map) &&
      c_x >= 0 && c_x < my_strlen(data->map[(int)c_y]) &&
      data->map[(int)c_y][(int)c_x] == '3')
    get_new_map(event);
  else
    hitbox('0', data, x, y);
}
예제 #2
0
	void TextField2::render(float dt)
	{
		if (!mVisible || mFont == NULL || !mFont->isLoaded())
		{
			return;
		}

		mCurrentLine = 0;
		preRender(dt);
		mFont->getAsset()->getTexture()->bindTexture();
		glBegin(GL_QUADS);
		while (mCurrentNode.get() != NULL)
		{
			if (mNewLineDirty)
			{
				Node::NodeHitboxList &list = mCurrentNode->getHitboxes();
				list.clear();
				Handle<NodeHitbox> hitbox(new NodeHitbox(mCurrentNode));
				mTextHitboxes->addChild(hitbox.get());
				hitbox->setPosition(mCurrXpos, mCurrYpos - mTextHitboxes->getPositionY());
				hitbox->setHeight(mFont->getCharHeight());
				hitbox->addEventListener(MOUSE_UP, this);
				list.push_back(hitbox);
			}
			TextStyle currentStyle = mCurrentNode->getTextStyle();
			GfxEngine::getEngine()->popColourStack();
			if (currentStyle.hasColour())
			{
				GfxEngine::getEngine()->pushColourStack(currentStyle.getColour());
			}
			else
			{
				if (mGfxComponent)
				{
					GfxEngine::getEngine()->pushColourStack(mGfxComponent->getColour());
				}
				else
				{
					GfxEngine::getEngine()->pushColourStack(Colour::WHITE);
				}
			}
			GfxEngine::getEngine()->applyColourStack();
			renderText(mCurrentNode->getText());
			mCurrentNode = mCurrentNode->nextSibling();
		}
		glEnd();
		mScrollbar->setMaxValue(getTotalNumLines() - mDisplayNumLines - 1);
		mNewLineDirty = false;

		for (ChildList::iterator iter = mChildren.begin(); iter != mChildren.end(); ++iter)
		{
			if (mGfxComponent)
			{
				mGfxComponent->getColour().applyColour();
			}
			(*iter)->render(dt);
		}

		postRender(dt);
	}
예제 #3
0
파일: shape.cpp 프로젝트: erik/blocks
bool pointIntersectsShape(int x, int y, sf::Shape shape) {
  // TODO: Hardcoding this is pretty much the dumbest 
  // thing in the history of forever.

  sf::Vector2<float> ltop = shape.GetPointPosition(0);
  sf::Vector2<float> rbot = shape.GetPointPosition(2);

  sf::Rect<float> hitbox(ltop.x, ltop.y, rbot.x, rbot.y);

  return hitbox.Contains(x, y);

}
예제 #4
0
	void TextField2::newLine()
	{
		mCurrXpos = 0.0f;
		mCurrentLine++;
		mCurrYpos += mFont->getCharHeight() + mFont->getLeading();
		if (mNewLineDirty)
		{
			mNewLinePositions.push_back(mTextPosition);

			Handle<NodeHitbox> hitbox(new NodeHitbox(mCurrentNode));
			mTextHitboxes->addChild(hitbox);
			hitbox->setWidth(0);
			hitbox->setHeight(mFont->getCharHeight());
			hitbox->setPosition(mCurrXpos, mCurrYpos - mTextHitboxes->getPositionY());
			hitbox->addEventListener(MOUSE_UP, this);
			mCurrentNode->getHitboxes().push_back(hitbox);
		}
	}
예제 #5
0
void Character::loadEntityFromNode(Node& root)
{
    DrawableEntity::loadEntityFromNode(root);

    Hitbox* hitbox(NULL);
    try
    {
        Node& areaNode = root.firstChild("hitbox");
        sf::FloatRect area = static_cast<sf::FloatRect>(loadAreaFromNode(areaNode));
        hitbox = new BoundingBoxHitbox(getPosition(), area);
        Log::write(Log::LOG_INFO, "Entity's hitbox creation : " + toString(area));
    }
    catch(std::runtime_error& e)
    {
        Log::write(Log::LOG_WARNING, "No hitbox defined for Entity : " + toString(e.what()));
        // when there isn't hitbox, we assign the entity's global bounds as a hitbox
        hitbox = new BoundingBoxHitbox(getPosition(), getGlobalBounds());
        Log::write(Log::LOG_INFO, "Entity's hitbox creation : " + toString(getGlobalBounds()));
    }
    setHitbox(hitbox);
}
예제 #6
0
void Camera3::Update(double dt)
{

	static const float CAMERA_SPEED = 100.f;
	prevPosition = position;
	Vector3 view = (target - position).Normalized();
	Vector3 right = view.Cross(up);
	//if (Application::IsKeyPressed('Q') && mouseControl == false && delay2 == 0)
	//{
	//	mouseControl = true;
	//	glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
	//	delay2 = 10;
	//}
	//else if (Application::IsKeyPressed('Q') && mouseControl == true && delay2 == 0)
	//{
	//	mouseControl = false;
	//	glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
	//	delay2 = 10;
	//}
	/*if (delay2 > 0)
	{
		delay2--;
	}*/
	Mtx44 rotation;
	if (mouseControl == true && Application::IsKeyPressed(VK_RBUTTON) && inBase == false)
	{
		xpos, ypos = a.Mouse(xpos, ypos);

		if (xpos < 399)
		{
			directionRotation.y += .5;
		}
		if (xpos > 401)
		{
			directionRotation.y -= .5;
		}
		if (ypos < 299)
		{
			if (directionRotation.x > -30)
			{
				directionRotation.x -= .5;
			}
		}
		if (ypos > 301)
		{
			if (directionRotation.x < 30)
			{
				directionRotation.x += .5;
			}
		}
	}
	else if (mouseControl == true)
	{
		xpos, ypos = a.Mouse(xpos, ypos);

		if (xpos < 399)
		{
			directionRotation.y += 2;
		}
		if (xpos > 401)
		{
			directionRotation.y -= 2;
		}
		if (ypos < 299)
		{
			if (directionRotation.x > -30)
			{
				directionRotation.x -= 2;
			}
		}
		if (ypos > 301)
		{
			if (directionRotation.x < 30)
			{
				directionRotation.x += 2;
			}
		}
	}
		else
		{
			if (Application::IsKeyPressed(VK_LEFT))
			{
				directionRotation.y += 3;
			}
			if (Application::IsKeyPressed(VK_RIGHT))
			{
				directionRotation.y -= 3;
			}
			if (Application::IsKeyPressed(VK_UP))
			{
				if (directionRotation.x > -45)
				{
					directionRotation.x -= 3;
				}
			}
			if (Application::IsKeyPressed(VK_DOWN))
			{
				if (directionRotation.x < 45)
				{
					directionRotation.x += 3;
				}
			}
		}
		if (recoil > 20)
		{
			recoil = 20;
		}
		gunRecoil.x = recoil;
		if (Application::IsKeyPressed(VK_LBUTTON))
		{
			cRecoilCd = 20;
		}
		if (cRecoilCd > 0)
		{
			cRecoilCd--;
		}
		if (gunRecoil.x > 0 && cRecoilCd == 0)
		{
			gunRecoil.x -= 0.2;
		}
		if (recoil > 0 && cRecoilCd == 0)
		{
			recoil -= 0.2;
		}

		camerarotation = directionRotation - gunRecoil;

		if (stamina < 100 && staminaDelay == 0)
		{
			stamina++;
		}

		if (staminaDelay > 0)
		{
			staminaDelay--;
		}

		location2 = position + view*dt*speed;
		location = position;
		direction = (view*dt*speed) * 2;
		if (inBase == true || inMenu == true)
		{
			if (Application::IsKeyPressed('W'))
			{
				Vector3 view = (target - position).Normalized();
				if (position.x + (view.x * dt * speed) / 2 <= 48 && position.x + (view.x * dt * speed) / 2 >= -48 && hitbox((position.x * dt * speed) / 2) == false && checkcollisionwithObject((view.x * dt * speed) / 2) == false)
				{
					position.x += (view.x * dt * speed) / 2;
					target.x += (view.x * dt * speed) / 2;
				}
				if (position.z + (view.z * dt * speed) / 2 <= 48 && position.z + (view.z * dt * speed) / 2 >= -48 && hitbox((view.z * dt * speed) / 2) == false && checkcollisionwithObject((view.z * dt * speed) / 2) == false)
				{
					position.z += (view.z * dt * speed) / 2;
					target.z += (view.z * dt * speed) / 2;
				}
				/*if (Application::IsKeyPressed(VK_SPACE) && position.y + (view.y * dt * speed) / 2 <= 48 && position.y + (view.y * dt * speed) / 2 >= 10 && hitbox((position.y * dt * speed) / 2) == false && checkcollisionwithObject((view.y * dt * speed) / 2) == false)
				{
					position.y += (view.y * dt * speed) / 2;
					target.y += (view.y * dt * speed) / 2;
				}*/
			}
			if (Application::IsKeyPressed('S'))
			{
				Vector3 view = (target - position).Normalized();

				if (position.x - (view.x * dt * speed) / 2 <= 48 && position.x - (view.x * dt * speed) / 2 >= -48 && hitbox(-(view.x * dt * speed) / 2) == false && checkcollisionwithObject(-(view.x * dt * speed) / 2) == false)
				{
					position.x -= (view.x * dt * speed) / 2;
					target.x -= (view.x * dt * speed) / 2;
				}

				if (position.z - (view.z * dt * speed) / 2 <= 48 && position.z - (view.z * dt * speed) / 2 >= -48 && hitbox(-(view.z * dt * speed) / 2) == false && checkcollisionwithObject(-(view.z * dt * speed) / 2) == false)
				{
					position.z -= (view.z * dt * speed) / 2;
					target.z -= (view.z * dt * speed) / 2;
				}

				/*if (Application::IsKeyPressed(VK_SPACE) && position.y - (view.y * dt * speed) / 2 <= 48 && position.y - (view.y * dt * speed) / 2 >= 10 && hitbox(-(view.y * dt * speed) / 2) == false && checkcollisionwithObject(-(view.y * dt * speed) / 2) == false)
				{
					position.y -= (view.y * dt * speed) / 2;
					target.y -= (view.y * dt * speed) / 2;
				}*/
			}
			if (Application::IsKeyPressed('D'))
			{
				Vector3 view = (target - position).Normalized();
				Vector3 right = view.Cross(up);

				if (position.x + (right.x * dt * speed) / 2 <= 48 && position.x + (right.x * dt * speed) / 2 >= -48 && hitbox((right.x * dt * speed) / 2) == false && checkcollisionwithObject((right.x * dt * speed) / 2) == false)
				{
					position.x += (right.x * dt * speed) / 2;
					target.x += (right.x * dt * speed) / 2;
				}

				if (position.z + (right.z * dt * speed) / 2 <= 48 && position.z + (right.z * dt * speed) / 2 >= -48 && hitbox((right.z * dt * speed) / 2) == false && checkcollisionwithObject((right.z * dt * speed) / 2) == false)
				{
					position.z += (right.z * dt * speed) / 2;
					target.z += (right.z * dt * speed) / 2;
				}

				if (position.y - (right.y * dt * speed) / 2 <= 48 && position.y - (right.y * dt * speed) / 2 >= -48 && hitbox(-(right.y * dt * speed) / 2) == false && checkcollisionwithObject((right.y * dt * speed) / 2) == false)
				{
					position.z -= (right.y * dt * speed) / 2;
					target.z -= (right.y * dt * speed) / 2;
				}
			}
			if (Application::IsKeyPressed('A'))
			{
				Vector3 view = (target - position).Normalized();
				Vector3 right = view.Cross(up);

				if (position.x - (right.x * dt * speed) / 2 <= 48 && position.x - (right.x * dt * speed) / 2 >= -48 && hitbox(-(right.x * dt * speed) / 2) == false && checkcollisionwithObject(-(right.x * dt * speed) / 2) == false)
				{
					position.x -= (right.x * dt * speed) / 2;
					target.x -= (right.x * dt * speed) / 2;
				}

				if (position.z - (right.z * dt * speed) / 2 <= 48 && position.z - (right.z * dt * speed) / 2 >= -48 && hitbox(-(right.z * dt * speed) / 2) == false && checkcollisionwithObject(-(right.z * dt * speed) / 2) == false)
				{
					position.z -= (right.z * dt * speed) / 2;
					target.z -= (right.z * dt * speed) / 2;
				}

				if (position.y - (right.y * dt * speed) / 2 <= 48 && position.y - (right.y * dt * speed) / 2 >= -48 && hitbox(-(right.y * dt * speed) / 2) == false && checkcollisionwithObject((right.y * dt * speed) / 2) == false)
				{
					position.z -= (right.y * dt * speed) / 2;
					target.z -= (right.y * dt * speed) / 2;
				}
			}
		}
		else if (inBase == false)
		{

			if (Application::IsKeyPressed(VK_RBUTTON) && scopedWep == true)
			{
				if (Application::IsKeyPressed('W'))
				{
					Vector3 view = (target - position).Normalized();
					if (position.x + (view.x * dt * speed) / 5 <= 990 && position.x + (view.x * dt * speed) / 5 >= -990 && hitbox((position.x * dt * speed) / 5) == false && checkcollisionwithObject((view.x * dt * speed) / 5) == false)
					{
						position.x += (view.x * dt * speed) / 5;
						target.x += (view.x * dt * speed) / 5;

					}

					if (position.z + (view.z * dt * speed) / 5 <= 990 && position.z + (view.z * dt * speed) / 5 >= -990 && hitbox((view.z * dt * speed) / 5) == false && checkcollisionwithObject((view.z * dt * speed) / 5) == false)
					{
						position.z += (view.z * dt * speed) / 5;
						target.z += (view.z * dt * speed) / 5;
					}

					/*if (Application::IsKeyPressed(VK_SPACE) && position.y + (view.y * dt * speed) / 5 <= 990 && position.y + (view.y * dt * speed) / 5 >= 10 && hitbox((position.y * dt * speed) / 5) == false && checkcollisionwithObject((view.y * dt * speed) / 5) == false && stamina > 0)
					{
						position.y += (view.y * dt * speed) / 5;
						target.y += (view.y * dt * speed) / 5;
						stamina--;
						staminaDelay = 100;
					}*/
				}
				if (Application::IsKeyPressed('S'))
				{
					Vector3 view = (target - position).Normalized();

					if (position.x - (view.x * dt * speed) / 5 <= 990 && position.x - (view.x * dt * speed) / 5 >= -990 && hitbox(-(view.x * dt * speed) / 5) == false && checkcollisionwithObject(-(view.x * dt * speed) / 5) == false)
					{
						position.x -= (view.x * dt * speed) / 5;
						target.x -= (view.x * dt * speed) / 5;
					}

					if (position.z - (view.z * dt * speed) / 5 <= 990 && position.z - (view.z * dt * speed) / 5 >= -990 && hitbox(-(view.z * dt * speed) / 5) == false && checkcollisionwithObject(-(view.z * dt * speed) / 5) == false)
					{
						position.z -= (view.z * dt * speed) / 5;
						target.z -= (view.z * dt * speed) / 5;
					}

					/*if (Application::IsKeyPressed(VK_SPACE) && position.y - (view.y * dt * speed) / 5 <= 990 && position.y - (view.y * dt * speed) / 5 >= 10 && hitbox(-(view.y * dt * speed) / 5) == false && checkcollisionwithObject(-(view.y * dt * speed) / 5) == false && stamina > 0)
					{
						position.y -= (view.y * dt * speed) / 5;
						target.y -= (view.y * dt * speed) / 5;
						stamina--;
						staminaDelay = 100;
					}*/
				}
				if (Application::IsKeyPressed('D'))
				{
					Vector3 view = (target - position).Normalized();
					Vector3 right = view.Cross(up);

					if (position.x + (right.x * dt * speed) / 5 <= 990 && position.x + (right.x * dt * speed) / 5 >= -990 && hitbox((right.x * dt * speed) / 5) == false && checkcollisionwithObject((right.x * dt * speed) / 5) == false)
					{
						position.x += (right.x * dt * speed) / 5;
						target.x += (right.x * dt * speed) / 5;
					}

					if (position.z + (right.z * dt * speed) / 5 <= 990 && position.z + (right.z * dt * speed) / 5 >= -990 && hitbox((right.z * dt * speed) / 5) == false && checkcollisionwithObject((right.z * dt * speed) / 5) == false)
					{
						position.z += (right.z * dt * speed) / 5;
						target.z += (right.z * dt * speed) / 5;
					}

					if (position.y - (right.y * dt * speed) / 5 <= 990 && position.y - (right.y * dt * speed) / 5 >= -990 && hitbox(-(right.y * dt * speed) / 5) == false && checkcollisionwithObject((right.y * dt * speed) / 5) == false)
					{
						position.z -= (right.y * dt * speed) / 5;
						target.z -= (right.y * dt * speed) / 5;
					}
				}
				if (Application::IsKeyPressed('A'))
				{
					Vector3 view = (target - position).Normalized();
					Vector3 right = view.Cross(up);

					if (position.x - (right.x * dt * speed) / 5 <= 990 && position.x - (right.x * dt * speed) / 5 >= -990 && hitbox(-(right.x * dt * speed) / 5) == false && checkcollisionwithObject(-(right.x * dt * speed) / 5) == false)
					{
						position.x -= (right.x * dt * speed) / 5;
						target.x -= (right.x * dt * speed) / 5;
					}
					if (position.z - (right.z * dt * speed) / 5 <= 990 && position.z - (right.z * dt * speed) / 5 >= -990 && hitbox(-(right.z * dt * speed) / 5) == false && checkcollisionwithObject(-(right.z * dt * speed) / 5) == false)
					{
						position.z -= (right.z * dt * speed) / 5;
						target.z -= (right.z * dt * speed) / 5;
					}
					if (position.y - (right.y * dt * speed) / 5 <= 990 && position.y - (right.y * dt * speed) / 5 >= -990 && hitbox(-(right.y * dt * speed) / 5) == false && checkcollisionwithObject(-(right.y * dt * speed) / 5) == false)
					{
						position.z -= (right.y * dt * speed) / 5;
						target.z -= (right.y * dt * speed) / 5;
					}
				}
			}
			else if (Application::IsKeyPressed(VK_SHIFT) && stamina > 0)
			{
				if (Application::IsKeyPressed('W'))
				{
					Vector3 view = (target - position).Normalized();
					if (position.x + (view.x * dt * speed) <= 990 && position.x + (view.x * dt * speed) >= -990 && hitbox((position.x * dt * speed)) == false && checkcollisionwithObject((view.x * dt * speed)) == false)
					{
						position.x += (view.x * dt * speed);
						target.x += (view.x * dt * speed);
					}
					if (position.z + (view.z * dt * speed) <= 990 && position.z + (view.z * dt * speed) >= -990 && hitbox((view.z * dt * speed)) == false && checkcollisionwithObject((view.z * dt * speed)) == false)
					{
						position.z += (view.z * dt * speed);
						target.z += (view.z * dt * speed);
					}
					/*if (Application::IsKeyPressed(VK_SPACE) && position.y + (view.y * dt * speed) <= 990 && position.y + (view.y * dt * speed) >= 10 && hitbox((position.y * dt * speed)) == false && checkcollisionwithObject((view.y * dt * speed)) == false)
					{
						position.y += (view.y * dt * speed);
						target.y += (view.y * dt * speed);
					}*/
				}
				if (Application::IsKeyPressed('S'))
				{
					Vector3 view = (target - position).Normalized();
					if (position.x - (view.x * dt * speed) <= 990 && position.x - (view.x * dt * speed) >= -990 && hitbox(-(view.x * dt * speed)) == false && checkcollisionwithObject(-(view.x * dt * speed)) == false)
					{
						position.x -= (view.x * dt * speed);
						target.x -= (view.x * dt * speed);
					}
					if (position.z - (view.z * dt * speed) <= 990 && position.z - (view.z * dt * speed) >= -990 && hitbox(-(view.z * dt * speed)) == false && checkcollisionwithObject(-(view.z * dt * speed)) == false)
					{
						position.z -= (view.z * dt * speed);
						target.z -= (view.z * dt * speed);
					}
					/*if (Application::IsKeyPressed(VK_SPACE) && position.y - (view.y * dt * speed) <= 990 && position.y - (view.y * dt * speed) >= 10 && hitbox(-(view.y * dt * speed)) == false && checkcollisionwithObject(-(view.y * dt * speed)) == false)
					{
						position.y -= (view.y * dt * speed);
						target.y -= (view.y * dt * speed);
					}*/
				}
				if (Application::IsKeyPressed('D'))
				{
					Vector3 view = (target - position).Normalized();
					Vector3 right = view.Cross(up);
					if (position.x + (right.x * dt * speed) <= 990 && position.x + (right.x * dt * speed) >= -990 && hitbox((right.x * dt * speed)) == false && checkcollisionwithObject((right.x * dt * speed)) == false)
					{
						position.x += (right.x * dt * speed);
						target.x += (right.x * dt * speed);
					}
					if (position.z + (right.z * dt * speed) <= 990 && position.z + (right.z * dt * speed) >= -990 && hitbox((right.z * dt * speed)) == false && checkcollisionwithObject((right.z * dt * speed)) == false)
					{
						position.z += (right.z * dt * speed);
						target.z += (right.z * dt * speed);
					}
					if (position.y - (right.y * dt * speed) <= 990 && position.y - (right.y * dt * speed) >= -990 && hitbox(-(right.y * dt * speed)) == false && checkcollisionwithObject((right.y * dt * speed)) == false)
					{
						position.z -= (right.y * dt * speed);
						target.z -= (right.y * dt * speed);
					}
				}
				if (Application::IsKeyPressed('A'))
				{
					Vector3 view = (target - position).Normalized();
					Vector3 right = view.Cross(up);
					if (position.x - (right.x * dt * speed) <= 990 && position.x - (right.x * dt * speed) >= -990 && hitbox(-(right.x * dt * speed)) == false && checkcollisionwithObject(-(right.x * dt * speed)) == false)
					{
						position.x -= (right.x * dt * speed);
						target.x -= (right.x * dt * speed);
					}
					if (position.z - (right.z * dt * speed) <= 990 && position.z - (right.z * dt * speed) >= -990 && hitbox(-(right.z * dt * speed)) == false && checkcollisionwithObject(-(right.z * dt * speed)) == false)
					{
						position.z -= (right.z * dt * speed);
						target.z -= (right.z * dt * speed);
					}
					if (position.y - (right.y * dt * speed) <= 990 && position.y - (right.y * dt * speed) >= -990 && hitbox(-(right.y * dt * speed)) == false && checkcollisionwithObject((right.y * dt * speed)) == false)
					{
						position.z -= (right.y * dt * speed);
						target.z -= (right.y * dt * speed);
					}
				}
				stamina--;
				staminaDelay = 100;
			}
			else
			{
				if (Application::IsKeyPressed('W'))
				{
					Vector3 view = (target - position).Normalized();
					if (position.x + (view.x * dt * speed) / 2 <= 990 && position.x + (view.x * dt * speed) / 2 >= -990 && hitbox((position.x * dt * speed) / 2) == false && checkcollisionwithObject((view.x * dt * speed) / 2) == false)
					{
						position.x += (view.x * dt * speed) / 2;
						target.x += (view.x * dt * speed) / 2;
					}
					if (position.z + (view.z * dt * speed) / 2 <= 990 && position.z + (view.z * dt * speed) / 2 >= -990 && hitbox((view.z * dt * speed) / 2) == false && checkcollisionwithObject((view.z * dt * speed) / 2) == false)
					{
						position.z += (view.z * dt * speed) / 2;
						target.z += (view.z * dt * speed) / 2;
					}
					/*if (Application::IsKeyPressed(VK_SPACE) && position.y + (view.y * dt * speed) / 2 <= 990 && position.y + (view.y * dt * speed) / 2 >= 10 && hitbox((position.y * dt * speed) / 2) == false && checkcollisionwithObject((view.y * dt * speed) / 2) == false && stamina > 0)
					{
						position.y += (view.y * dt * speed) / 2;
						target.y += (view.y * dt * speed) / 2;
						stamina--;
						staminaDelay = 100;
					}*/
				}
				if (Application::IsKeyPressed('S'))
				{
					Vector3 view = (target - position).Normalized();

					if (position.x - (view.x * dt * speed) / 2 <= 990 && position.x - (view.x * dt * speed) / 2 >= -990 && hitbox(-(view.x * dt * speed) / 2) == false && checkcollisionwithObject(-(view.x * dt * speed) / 2) == false)
					{
						position.x -= (view.x * dt * speed) / 2;
						target.x -= (view.x * dt * speed) / 2;
					}

					if (position.z - (view.z * dt * speed) / 2 <= 990 && position.z - (view.z * dt * speed) / 2 >= -990 && hitbox(-(view.z * dt * speed) / 2) == false && checkcollisionwithObject(-(view.z * dt * speed) / 2) == false)
					{
						position.z -= (view.z * dt * speed) / 2;
						target.z -= (view.z * dt * speed) / 2;
					}

					/*if (Application::IsKeyPressed(VK_SPACE) && position.y - (view.y * dt * speed) / 2 <= 990 && position.y - (view.y * dt * speed) / 2 >= 10 && hitbox(-(view.y * dt * speed) / 2) == false && checkcollisionwithObject(-(view.y * dt * speed) / 2) == false && stamina > 0)
					{
						position.y -= (view.y * dt * speed) / 2;
						target.y -= (view.y * dt * speed) / 2;
						stamina--;
						staminaDelay = 100;
					}*/
				}
				if (Application::IsKeyPressed('D'))
				{
					Vector3 view = (target - position).Normalized();
					Vector3 right = view.Cross(up);

					if (position.x + (right.x * dt * speed) / 2 <= 990 && position.x + (right.x * dt * speed) / 2 >= -990 && hitbox((right.x * dt * speed) / 2) == false && checkcollisionwithObject((right.x * dt * speed) / 2) == false)
					{
						position.x += (right.x * dt * speed) / 2;
						target.x += (right.x * dt * speed) / 2;
					}

					if (position.z + (right.z * dt * speed) / 2 <= 990 && position.z + (right.z * dt * speed) / 2 >= -990 && hitbox((right.z * dt * speed) / 2) == false && checkcollisionwithObject((right.z * dt * speed) / 2) == false)
					{
						position.z += (right.z * dt * speed) / 2;
						target.z += (right.z * dt * speed) / 2;
					}

					if (position.y - (right.y * dt * speed) / 2 <= 990 && position.y - (right.y * dt * speed) / 2 >= -990 && hitbox(-(right.y * dt * speed) / 2) == false && checkcollisionwithObject((right.y * dt * speed) / 2) == false)
					{
						position.z -= (right.y * dt * speed) / 2;
						target.z -= (right.y * dt * speed) / 2;
					}
				}
				if (Application::IsKeyPressed('A'))
				{
					Vector3 view = (target - position).Normalized();
					Vector3 right = view.Cross(up);

					if (position.x - (right.x * dt * speed) / 2 <= 990 && position.x - (right.x * dt * speed) / 2 >= -990 && hitbox(-(right.x * dt * speed) / 2) == false && checkcollisionwithObject(-(right.x * dt * speed) / 2) == false)
					{
						position.x -= (right.x * dt * speed) / 2;
						target.x -= (right.x * dt * speed) / 2;
					}

					if (position.z - (right.z * dt * speed) / 2 <= 990 && position.z - (right.z * dt * speed) / 2 >= -990 && hitbox(-(right.z * dt * speed) / 2) == false && checkcollisionwithObject(-(right.z * dt * speed) / 2) == false)
					{
						position.z -= (right.z * dt * speed) / 2;
						target.z -= (right.z * dt * speed) / 2;
					}

					if (position.y - (right.y * dt * speed) / 2 <= 990 && position.y - (right.y * dt * speed) / 2 >= -990 && hitbox(-(right.y * dt * speed) / 2) == false && checkcollisionwithObject((right.y * dt * speed) / 2) == false)
					{
						position.z -= (right.y * dt * speed) / 2;
						target.z -= (right.y * dt * speed) / 2;
					}
				}
			}
		}
		if (knockback == true)
		{
			knockback = false;
			if (position.x - (view.x * dt * speed)*10 <= 990 && position.x - (view.x * dt * speed)*10 >= -990 && hitbox(-(view.x * dt * speed)*10) == false && checkcollisionwithObject(-(view.x * dt * speed)*10) == false)
			{
				position.x -= (view.x * dt * speed) * 10;
			}
			if (position.z - (view.z * dt * speed) * 10 <= 990 && position.z - (view.z * dt * speed) * 10 >= -990 && hitbox(-(view.z * dt * speed) * 10) == false && checkcollisionwithObject(-(view.z * dt * speed) * 10) == false)
			{
				position.z -= (view.z * dt * speed) * 10;
			}
		}
		if (inMenu == false)
		{
			teleport();
		}
	

	kb = (right * dt * speed);
	if (camerarotation.x > maxCameraX)
	{
		camerarotation.x = maxCameraX;
	}
	else if (camerarotation.x < -maxCameraX)
	{
		camerarotation.x = -maxCameraX;
	}

	std::cout << inMenu << std::endl;

	//Changing target
	target = Vector3(sin(DegreeToRadian(camerarotation.y))*cos(DegreeToRadian(camerarotation.x)) + this->position.x, -sin(DegreeToRadian(camerarotation.x)) + this->position.y,
		cos(DegreeToRadian(camerarotation.y))*cos(DegreeToRadian(camerarotation.x)) + this->position.z);

}
예제 #7
0
bool PolyQtAnnotation::contains(const QPointF & point) const {
  if (shape().controlPointRect().contains(point)) {
    QPointF imgPoint = this->mapToScene(point) / _scale;
    double curSelectionSensitivity = (_selectionSensitivity * _lineAnnotationSelectedThickness / _currentLoD);
    double curSelectionSensitivitySquared = curSelectionSensitivity * curSelectionSensitivity;
    double imgX = imgPoint.x();
    double imgY = imgPoint.y();
    std::vector<Point> coords = _annotation->getCoordinates();
    double minDist = std::numeric_limits<double>::max();
    _lastClickedFirstCoordinateIndex = -1;
    _lastClickedSecondCoordinateIndex = -1;

    // Quickly check if a seed point was hit
    for (unsigned int i = 0; i < coords.size(); ++i) {
      Point pt1 = coords[i];
      double coord1X = pt1.getX(); double coord1Y = pt1.getY();
      double distSquared = pow(imgX - coord1X, 2) + pow(imgY - coord1Y, 2);
      if (distSquared < curSelectionSensitivitySquared && distSquared < minDist) {
        _lastClickedFirstCoordinateIndex = i;
        _lastClickedSecondCoordinateIndex = -1;
        _lastClickedLinePoint = QPointF();
        minDist = distSquared;
      }
    }
    if (_lastClickedFirstCoordinateIndex >= 0) {
      return true;
    }

    minDist = std::numeric_limits<double>::max();
    // If not, check if a line was hit
    std::vector<QPointF> polyInImgCoords;
    unsigned int polyIndex = 0;
    if (_type == "spline") {
      for (QPolygonF::const_iterator it = _polys.begin(); it != _polys.end(); ++it) {
        polyInImgCoords.push_back(this->mapToScene(*it) / _scale);
      }
    }
    for (unsigned int i = 0; i < coords.size(); ++i) {
      Point pt1 = coords[i];
      Point pt2 = i == coords.size() -1 ? coords[0] : coords[i + 1];
      double coord1X = pt1.getX(); double coord1Y = pt1.getY();
      double coord2X = pt2.getX(); double coord2Y = pt2.getY();
      QRectF hitbox(imgX - curSelectionSensitivity / 2., imgY - curSelectionSensitivity / 2., curSelectionSensitivity * 2., curSelectionSensitivity * 2.);
      QRectF lineBox(QPointF(std::min(coord1X, coord2X), std::max(coord1Y, coord2Y)), QPointF(std::max(coord1X, coord2X), std::min(coord1Y, coord2Y)));       
      if (hitbox.intersects(lineBox)) {
        if (_type == "spline") {
          for (unsigned int j = 0; j < polyInImgCoords.size(); ++j) {
            QPointF polyPt1 = polyInImgCoords[polyIndex];
            QPointF polyPt2 = polyIndex == polyInImgCoords.size() - 1 ? polyInImgCoords[0] : polyInImgCoords[polyIndex + 1];
            if (QPoint(polyPt1.x(), polyPt1.y()) == QPoint(coord2X, coord2Y)) {
              break;
            }
            double polyCoord1X = polyPt1.x(); double polyCoord1Y = polyPt1.y();
            double polyCoord2X = polyPt2.x(); double polyCoord2Y = polyPt2.y();
            QRectF polyBox(QPointF(std::min(polyCoord1X, polyCoord2X), std::max(polyCoord1Y, polyCoord2Y)), QPointF(std::max(polyCoord1X, polyCoord2X), std::min(polyCoord1Y, polyCoord2Y)));
            if (hitbox.intersects(polyBox)) {
              double lineLengthSquared = pow(polyCoord1X - polyCoord2X, 2) + pow(polyCoord1Y - polyCoord2Y, 2);
              double t = ((imgX - polyCoord2X) * (polyCoord1X - polyCoord2X) + (imgY - polyCoord2Y) * (polyCoord1Y - polyCoord2Y)) / lineLengthSquared;
              double projX = polyCoord2X + t * (polyCoord1X - polyCoord2X);
              double projY = polyCoord2Y + t * (polyCoord1Y - polyCoord2Y);
              double distSquared = pow(imgX - projX, 2) + pow(imgY - projY, 2);
              if (distSquared < curSelectionSensitivitySquared && distSquared < minDist) {
                _lastClickedFirstCoordinateIndex = i;
                _lastClickedSecondCoordinateIndex = i + 1 == coords.size() ? 0 : i + 1;
                _lastClickedLinePoint = QPointF(projX, projY);
              }
            }
            ++polyIndex;
          }
        }
        else {
          double lineLengthSquared = pow(coord1X - coord2X, 2) + pow(coord1Y - coord2Y, 2);
          double t = ((imgX - coord2X) * (coord1X - coord2X) + (imgY - coord2Y) * (coord1Y - coord2Y)) / lineLengthSquared;
          double projX = coord2X + t * (coord1X - coord2X);
          double projY = coord2Y + t * (coord1Y - coord2Y);
          double distSquared = pow(imgX - projX, 2) + pow(imgY - projY, 2);
          if (distSquared < curSelectionSensitivitySquared && distSquared < minDist) {
            _lastClickedFirstCoordinateIndex = i;
            _lastClickedSecondCoordinateIndex = i + 1 == coords.size() ? 0 : i + 1;
            _lastClickedLinePoint = QPointF(projX, projY);
          }
        }
      }
    }
    if (_lastClickedFirstCoordinateIndex < 0) {
      return false;
    }
    else {
      return true;
    }
  }
  return false;
}
예제 #8
0
void Enemy10::Update(const Player *PlayerPtr)
{
	// if the enemy has been inactive, activate it
	if( m_Active == false )
	{
		if( m_Timer.GetElapsedTime() >= (Uint32)(m_Pause * 500) )
		{
			Spawn();
		}
	}
	else
	{
		m_Sprite->Animate();

		AABB hitbox(glm::vec2(m_Position.x - m_Sprite->GetSize().x / 2.f, m_Position.y - m_Sprite->GetSize().y), m_Sprite->GetSize());

		// animation transitions
		switch( m_CurrentState )
		{
			// spawning --> moving
			case SPAWNING :
			{
				if( m_Sprite->FinishedCurrentSequence() )
				{
					SetState(MOVING);
					m_Timer.Reset();
				}
				
				// just to place the sprite on top of the ground
				m_Level->MoveAABB(hitbox, glm::vec2(0.f, 1.f), m_CDResult, true, false, false, false);
				hitbox.m_Position = m_CDResult.NewPosition;
				m_Position.x = hitbox.m_Position.x + hitbox.m_Size.x / 2.f;
				m_Position.y = hitbox.m_Position.y + hitbox.m_Size.y;

				break;
			}
			// moving --> disappearing
			case MOVING :
			{
				if( m_Timer.GetElapsedTime() >= (Uint32)(m_Pause * 500) )
				{
					SetState(DISAPPEARING);
					break;
				}
				
				// move around
				m_Level->MoveAABB(hitbox, glm::vec2(0.5f * m_Direction, 1.f), m_CDResult, true, false, false, false);
				hitbox.m_Position = m_CDResult.NewPosition;
				m_Position.x = hitbox.m_Position.x + hitbox.m_Size.x / 2.f;
				m_Position.y = hitbox.m_Position.y + hitbox.m_Size.y;

				// change direction when hitting wall
				if( m_CDResult.ObstacleTileX )
				{
					SetDirection((m_Direction == LEFT) ? (RIGHT) : (LEFT));
				}

				break;
			}
			// disappearing --> deactivated
			case DISAPPEARING :
			{
				if( m_Sprite->FinishedCurrentSequence() )
				{
					Deactivate();
					m_Timer.Reset();
				}
				
				// pull down the sprite to make it disappear downwards
				m_Level->MoveAABB(hitbox, glm::vec2(0.f, 50.f), m_CDResult, true, false, false, false);
				hitbox.m_Position = m_CDResult.NewPosition;
				m_Position.x = hitbox.m_Position.x + hitbox.m_Size.x / 2.f;
				m_Position.y = hitbox.m_Position.y + hitbox.m_Size.y;

				break;
			}
		}

		m_Sprite->SetPosition(glm::vec2(m_Position.x - m_Sprite->GetSize().x / 2.f, m_Position.y - m_Sprite->GetSize().y));
	}
}
예제 #9
0
void
TouchableComponent::Process()
{
    glm::mat4 hitbox(mCurrentHitbox);
    glm::mat4 mvp(mCurrentPMat * mCurrentMVMat);

    //TouchEvent* e  = (TouchEvent*)mCurrentEvent;
    auto t = mCurrentEvent.GetData();


    // TODO:  We need to do a raycast hit test rather than this current hit test in order to work properly with 3D.
    // Unproject touch pos and cast ray from zNear to zFar, test intersection with hit boxes.
    {
        auto touches = t.touches;

        glm::vec4 low(hitbox * glm::vec4(-0.5f,-0.5f,-0.5f,1.f)), high(hitbox * glm::vec4(0.5f,0.5f,0.5f,1.f));

        // Translate based on model-view * projection
        low = mvp * low;
        high = mvp * high;

        // homogenous divide to get normalized device coordinates
        low.x /= low.w;
        low.y /= low.w;
        low.z /= low.w;
        high.x /= high.w;
        high.y /= high.w;
        high.z /= high.w;

        int screenX, screenY, screenW, screenH;
        mOwner.GetOwner()->GetViewport(screenX,screenY,screenW,screenH);


        // convert the normalized device coordinates from [-1,1] back to screen-space coordinates
        short hw = screenW>>1;
        short hh = screenH>>1;
        low.x = low.x * hw + hw;
        low.y = low.y * hh + hh;
        low.z = low.z * 0.5 + 0.5;
        high.x = high.x * hw + hw;
        high.y = high.y * hh + hh;
        high.z = high.z * 0.5 + 0.5;

        //
        // Hit-test
        for (auto it = touches.begin() ; it != touches.end() ; ++it)
        {

            //          D_PRINT("Touch: (%d, %d) Low: (%lf, %lf, %lf) High: (%lf, %lf, %lf)", (*it).x, (*it).y, low.x, low.y, low.z, high.x, high.y, high.z);

            (*it).flags |= 0x10 * ((*it).x > low.x && (*it).x < high.x && (*it).y > low.y && (*it).y < high.y); // hit

            if( (*it).flags & 0x10 ) {

                mCurrentEvent.SetTarget(e::kEventTargetTouchHit);
            }

        }

    }

}
예제 #10
0
파일: player.cpp 프로젝트: gingeralesy/ld33
void Player::update(const float &delta)
{
  const sf::Vector2f pos = getPosition();

  float
      xSpeed = m_vector.x * m_speed * delta,
      ySpeed = m_vector.y * m_speed * delta;

  if (m_vector.x != 0.f)
    ySpeed /= 2.f;
  if (m_vector.y != 0.f)
    xSpeed /= 2.f;

  float x = pos.x + xSpeed;
  float y = pos.y + ySpeed;
  const sf::Vector2f stopPoint(x, y);
  setPosition(stopPoint);

  std::list<Entity *> entities;
  m_game->level()->entities(&entities);

  std::list<Entity *>::iterator it;
  for (it = entities.begin(); it != entities.end(); it++)
  {
    Entity *en = (*it);
    if (en->id() != id())
    {
      sf::IntRect mHitbox = hitbox();
      sf::IntRect eHitbox = en->hitbox();
      if (mHitbox.intersects(eHitbox))
      {
        // TODO: make it "slide"
        /*
    Vector normal = objects[i].CheckCollision(newPos.x, newPos.y, newPos.z, direction.x, direction.y, direction.z);
    if(normal != Vector::NullVector())
    {
        Vector invNormal = normal.Negative();
        invNormal = invNormal * (direction * normal).Length(); // Change normal to direction's length and normal's axis
        Vector wallDir = direction - invNormal;
        newPos = oldPos + wallDir;
        direction = newPos - oldPos;
    }
         */
        sf::Vector2f eTopLeft(eHitbox.left, eHitbox.top);
        sf::Vector2f eBotRight(eHitbox.left + eHitbox.width,
                               eHitbox.top + eHitbox.height);

        sf::Vector2f intersection;
        if (Util::linesCollide(eTopLeft, sf::Vector2f(eTopLeft.x, eBotRight.y),
                               pos, stopPoint, &intersection))
        {
          // From left
          x = eHitbox.left - mHitbox.width;
          setPosition(x, y);
        }
        else
        {
          setPosition(pos.x, pos.y);
        }
        break;
      }
    }
  }

  Animation *animation = m_animations.at(m_facing * 10 + 0);
  if (m_vector.x != 0.f || m_vector.y != 0.f)
    animation = m_animations.at(m_facing * 10 + 1);

  setTextureRect(animation->getFrame(delta));
}