Ejemplo n.º 1
0
	// Initializare
	void Init(CSprite *spr)
	{
		m_Sprite = spr;

		glm::vec3 pz = m_Sprite->GetPosition();
		m_Sprite->PlayAnimation("BugEye_Idle");

	}
Ejemplo n.º 2
0
	// In functia de update:
	// 1.Detectam directia de deplasare a player-ului in functie de tastele apasate
	// 2.Determinam animatia ce trebuie afisata
	// 3.Limitam din topor spatiul in care se poate deplasa player-ul
	void Update(float dt)
	{

		glm::vec3 pos;
		glm::vec3 dir(0.0f, 0.0f, 0.0f);
		bool recalculate_position = false;

		// Determinarea animatiilor si a directiei de deplasare
		if (GLFW_PRESS == glfwGetKey(window, GLFW_KEY_LEFT))
		{
			if (m_CurrentAnimType != LEFT)
			{
				m_Sprite->PlayAnimation("Left");
				m_CurrentAnimType = LEFT;
			}

			dir.x = -1.0f;
			recalculate_position = true;

		}
		if (GLFW_PRESS == glfwGetKey(window, GLFW_KEY_RIGHT))
		{
			if (m_CurrentAnimType != RIGHT)
			{
				m_Sprite->PlayAnimation("Right");
				m_CurrentAnimType = RIGHT;
			}

			dir.x = 1.0f;
			recalculate_position = true;
		}
		if (GLFW_PRESS == glfwGetKey(window, GLFW_KEY_UP))
		{
			if (m_CurrentAnimType != IDLE)
			{
				m_Sprite->PlayAnimation("Idle");
				m_CurrentAnimType = IDLE;
			}

			dir.y = 1.0f;
			recalculate_position = true;

		}
		if (GLFW_PRESS == glfwGetKey(window, GLFW_KEY_DOWN))
		{
			if (m_CurrentAnimType != IDLE)
			{
				m_Sprite->PlayAnimation("Idle");
				m_CurrentAnimType = IDLE;
			}

			dir.y = -1.0f;
			recalculate_position = true;
		}

		if (GLFW_PRESS == glfwGetKey(window, GLFW_KEY_SPACE) && semafor) {
			CSpriteManager::Get()->projectiles.push_back(CSpriteManager::Get()->AddSprite("projectile.png", player_proj));
			CSpriteManager::Get()->projectiles[CSpriteManager::Get()->projectiles.size() - 1]->SetPosition(glm::vec3(m_Sprite->GetPosition().x, m_Sprite->GetPosition().y+0.8f, -14));
			semafor = false;
		}

		if (GLFW_RELEASE == glfwGetKey(window, GLFW_KEY_SPACE) && !semafor) {
			semafor = true;
		}



		pos = m_Sprite->GetPosition();

		if (recalculate_position)
		{
			dir = glm::normalize(dir);
			pos = pos + dir * PLAYER_MOVE_SPEED * dt;
		}
		else
		{
			if (m_CurrentAnimType != IDLE)
			{
				m_Sprite->PlayAnimation("Idle");
				m_CurrentAnimType = IDLE;
			}

		}
		// END



		// Limitarea playerului 
		if (pos.x < SCREEN_LEFT)
		{
			pos.x = SCREEN_LEFT + 0.01f;
		}
		if (pos.x  > SCREEN_RIGHT - 0.4f)
		{
			pos.x = SCREEN_RIGHT - 0.4f;
		}
		if (pos.y < SCREEN_BOTTOM)
		{
			pos.y = SCREEN_BOTTOM + 0.01f;
		}
		if (pos.y > SCREEN_TOP - 1.0f)
		{
			pos.y = SCREEN_TOP - 1.0f;
		}
		// END

		// update pozitia spriteului
		m_Sprite->SetPosition(pos);

	}