Ejemplo n.º 1
0
void CBoard::Render()
{
    if (m_pBoard)
    {
        m_pBoard->Render();
    }

    for (int i = 0; i < 9; i++)
    {
        int x = i / 3;
        int y = i % 3;

        if ( IsTileFree( x, y ) )
        {
            continue;
        }

        CSprite *pIcon = m_iMatrix[x][y] == PLAYER_X ? m_pX : m_pO;

        if (!pIcon)
        {
            continue;
        }

        pIcon->SetPosition( (x-1)*DELTA_WIDTH, (y-1)*DELTA_HEIGHT );
        pIcon->SetScale( SCALE );

        pIcon->Render();
    }
}
Ejemplo n.º 2
0
// This is where the bones of the project are forged
// (loading sprites, for example)
BOOL CGameLogic::Init(CGame *game)
{
	// Initialize the combination
	m_combo = CreateCombination();
	m_nodes = m_combo;
	for (unsigned i = 0; i < m_nodes.size(); i++)
		m_nodes[i] = i;

	// Load sprites
	auto path = game->GetExecutablePath();

	// Slider (Mid-section)
	CSprite *spr = nullptr;
	if (!LoadSprite(path, L"sliderMid.png", game->GetRenderer(), &spr))
		return FALSE;
	m_sprites.push_back(spr);
	spr->SetPosition(0, 0);

	// Slider (nodes)
	for (auto i = 0; i < 5; i++) {
		spr = nullptr;
		if (!LoadSprite(path, L"sliderNode.png", game->GetRenderer(), &spr))
			return FALSE;
		m_sprites.push_back(spr);
	}

	return TRUE;
}
Ejemplo n.º 3
0
// ----------------------------------------------------------------
//	Render
// ----------------------------------------------------------------
void CAnimation::Render()
{
	CSprite * sprite;

	if( m_Fps == 0 )
		sprite = m_Sprites[0];
	else
		sprite = m_Sprites[m_FrameNumber];

	sprite->SetPosition( m_Position );
	sprite->Render();
}
Ejemplo n.º 4
0
int CLoader::LoadSprites()
{
	eRoot = xmlDoc.RootElement()->FirstChildElement( "Content" );
	if(eRoot == 00) return -1;

	eSprites = eRoot->FirstChildElement( "Sprites" );
	if(eSprites == 00) return -1;

	eSprite = eSprites->FirstChildElement( "Sprite" );
	if(eSprite == 00) return -1;

	string sTempSpriteName, sTempFilename, sSpriteStatus;
	int xPosTemp, yPosTemp, zPosTemp;
	bool bSpriteActive;

	while(eSprite != 00)
	{
		eContent = eSprite;

		eContent = eContent->FirstChildElement( "spriteName" );
		if(eContent == 00) break;
		sTempSpriteName = converter::CharToString( eContent->GetText() );

		eContent = eContent->NextSiblingElement( "filename" );
		if(eContent == 00) break;
		sTempFilename = converter::CharToString( eContent->GetText() );

		eContent = eContent->NextSiblingElement( "status" );
		if(eContent == 00) break;
		sSpriteStatus = converter::CharToString( eContent->GetText() );

		eContent = eContent->NextSiblingElement( "active" );
		if(eContent == 00) break;
		bSpriteActive = converter::IntToBool( static_cast<int>(atoi( eContent->GetText() )) );

		eContent = eContent->NextSiblingElement( "posX" );
		if(eContent == 00) break;
		xPosTemp = static_cast<int>(atoi( eContent->GetText() ));

		eContent = eContent->NextSiblingElement( "posY" );
		if(eContent == 00) break;
		yPosTemp = static_cast<int>(atoi( eContent->GetText() ));

		eContent = eContent->NextSiblingElement( "posZ" );
		if(eContent == 00) break;
		zPosTemp = static_cast<int>(atoi( eContent->GetText() ));

		CSprite* sprite = theSpriteManager->AddSprite( sTempFilename, sTempSpriteName );
		sprite->SetPosition( XMFLOAT3( xPosTemp, yPosTemp, zPosTemp ) );

		sprite->SetStatus( sSpriteStatus );
		sprite->SetActive( bSpriteActive );

		sprite = 00;
		eSprite = eSprite->NextSiblingElement( "Sprite" );
	}

	eContent = 00;
	eSprite = 00;
	eSprites = 00;
	eRoot = 00;

	return ERR_SUCCESS;
}
Ejemplo n.º 5
0
int main()
{
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
	
	glfwInit();
	
	glfwWindowHint(GLFW_SAMPLES, 4);
	window = glfwCreateWindow(WWIDTH, WHEIGHT, "GL Framework", NULL, NULL);
	glfwSetWindowSizeCallback(window, glfw_window_size_callback);
	
	glfwMakeContextCurrent(window);

	// start GLEW extension handler
	glewExperimental = GL_TRUE;
	glewInit();

	glViewport(0, 0, g_gl_width, g_gl_height);	

	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_BLEND);


	// Initializam spriteManagerul
	CSpriteManager::Get()->Init();

	// Initializam PlayerEntity si creem sprite-ul asociat
	PlayerTest PlayerEntity;


	CSprite *back = CSpriteManager::Get()->AddSprite("sky0000.png", background);

	
	for (int k = 0; k < 3; k++){
		lives.push_back(CSpriteManager::Get()->AddSprite("mini.png", mini));
		lives[lives.size() - 1]->SetPosition(glm::vec3(3 + k*0.3f, 3.4f, -19));
	}

	CSprite* lifeSprite = CSpriteManager::Get()->AddSprite("life.png", textLife);
	lifeSprite->SetPosition(glm::vec3(3 - 0.6f, 3.4f, -19));



	CSprite *playerSprite = CSpriteManager::Get()->AddSprite("player0000.png", player);
	
	back->SetPosition(glm::vec3(-4, -4, -20));

	assert(playerSprite);
	PlayerEntity.Init(playerSprite);
//	back->PlayAnimation("Sky");

	EnemyTest vec[100];
	int number_of_enemy =5;
	//vector de inamici
	vector<CSprite*> enemies;
	float x,y;
	for (int i = 0; i< number_of_enemy; i++)
	{
		
		CSprite *RandomRocket = CSpriteManager::Get()->AddSprite("PlayerRocket.png",enemy);
		x = -3.0f - i;
		y = RandomRocket->getFirstParabolaY(x);
		RandomRocket->SetPosition(glm::vec3(x, y, -11));
		vec[i].Init(RandomRocket);
		enemies.push_back(RandomRocket);


	}


	float t = 0.0f;
	float dt = 0.01f;

	float prevTime =(float) glfwGetTime();
	float accumulator = 0.0f;

	Collision *collide = new Collision();
	

	bool hit = false;
	bool hit2 = false;
	int i;
	while (!glfwWindowShouldClose(window))
	{

		_update_fps_counter(window);

		float newTime =(float) glfwGetTime();
		float deltaTime = (float)(newTime - prevTime);
		

		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glViewport(0, 0, g_gl_width, g_gl_height);


		if (deltaTime > 0.25f)
			deltaTime = 0.25f;
		prevTime = newTime;

		accumulator += deltaTime;

		while (accumulator >= dt)
		{
			// update logic pentru player
			PlayerEntity.Update(dt);

			// update animatie
			CSpriteManager::Get()->Update(dt);

			//update enemies
			int nr = 0;
			for (int i = 0; i < number_of_enemy; i++)
			{
				if (enemies[i]->life>0){
					vec[i].Update(dt, nr);
				}
			}
			t += dt;
			accumulator -= dt;
		}

		// desenare
		CSpriteManager::Get()->Draw();

		//verificare coliziune intre player si inamic
		for ( i = 0; i< number_of_enemy; i++)
		{
			collide->ResolveCollisionPlayer(playerSprite,enemies[i]);
			if (collide->getStatusPlayer() == true){
				if (playerSprite->life>=0){
					CSpriteManager::Get()->RemoveSprite(lives[lives.size() - 1]->index);
					lives.erase(lives.end() - 1);
				}
				

			}



			//verificare coliziune intre player si proiectile inamici
			vec[i].Collide(playerSprite, collide);

			if (playerSprite->life == 0){
				playerSprite->SetPosition(glm::vec3(-5.0f, -5.0f, playerSprite->GetPosition().z));
			}

			if (enemies[i]->life == 0){
				enemies[i]->life = 2;
			}

		}


		//verificare coliziune intre inamic si proiectilul player-ului
		collide->ResolveCollisionEnemy(CSpriteManager::Get()->projectiles, enemies );

		glfwPollEvents();
		glfwSwapBuffers(window);

		if (GLFW_PRESS == glfwGetKey(window, GLFW_KEY_ESCAPE))
		{
			glfwSetWindowShouldClose(window, 1);
		}

	}

	delete collide;
	glfwTerminate();
	return 0;
}
Ejemplo n.º 6
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);

	}
Ejemplo n.º 7
0
void SampleScene::Update(float dt)
{
	g_Keyboard->Update() ;
	g_Mouse->Update() ;
	g_Joystick->Update() ;
	g_MusicManager->Loop() ;

	static float x=0.0f, y=0.0f ;

	if(g_Keyboard->IsButtonDown(DIK_UP))
	{
		y += 1.5f ;
	}
	if(g_Keyboard->IsButtonDown(DIK_DOWN))
	{
		y -= 1.5f ;
	}
	if(g_Keyboard->IsButtonDown(DIK_RIGHT))
	{
		x += 1.5f ;
	}
	if(g_Keyboard->IsButtonDown(DIK_LEFT))
	{
		x -= 1.5f ;
	}

	if(g_Keyboard->IsButtonDown(DIK_1))
	{
		Sprite.SetTextureUV(0.0f, 0.0f, 50.0f, 50.0f) ;
	}
	if(g_Keyboard->IsButtonDown(DIK_2))
	{
		Sprite.SetTextureUV(50.0f, 0.0f, 100.0f, 50.0f) ;
	}
	if(g_Keyboard->IsButtonDown(DIK_3))
	{
		Sprite.SetTextureUV(0.0f, 50.0f, 50.0f, 100.0f) ;
	}
	if(g_Keyboard->IsButtonDown(DIK_4))
	{
		Sprite.SetTextureUV(50.0f, 50.0f, 100.0f, 100.0f) ;
	}

	if(g_Keyboard->IsButtonDown(DIK_8))
	{
		Sprite.SetPositionZ(0.0f) ;
	}
	if(g_Keyboard->IsButtonDown(DIK_9))
	{
		Sprite.SetPositionZ(1.0f) ;
	}
	if(g_Keyboard->IsButtonDown(DIK_0))
	{
		Sprite.SetPositionZ(0.5f) ;
	}

	if(g_Keyboard->IsButtonDown(DIK_5))
	{
		UISprite.SetPositionZ(0.0f) ;
		UISprite2.SetPositionZ(0.0f) ;
	}
	if(g_Keyboard->IsButtonDown(DIK_6))
	{
		UISprite.SetPositionZ(1.0f) ;
		UISprite2.SetPositionZ(0.0f) ;
	}
	if(g_Keyboard->IsButtonDown(DIK_7))
	{
		UISprite.SetPositionZ(0.0f) ;
		UISprite2.SetPositionZ(1.0f) ;
	}

	if(g_Keyboard->IsButtonDown(DIK_F1))
	{
		g_CameraManager->SetCamera(0) ;
	}
	if(g_Keyboard->IsButtonDown(DIK_F2))
	{
		g_CameraManager->SetCamera(1) ;
	}
	
	if(g_Mouse->IsMouse(g_Mouse->LBUTTON_DOWN))
	{
		g_MusicManager->PlayMusic(sound[0]) ;
	}
	if(g_Mouse->IsMouse(g_Mouse->RBUTTON_DOWN))
	{
		g_MusicManager->PlayMusic(sound[2]) ;
	}
	if(g_Keyboard->IsButtonDown(DIK_SPACE))
	{
		g_MusicManager->PlayMusic(sound[1]) ;
	}

	/*if(g_Mouse->IsMouse(g_Mouse->LBUTTON_DOWN))
	{
		MessageBox(NULL, "LBUTTON_DOWN", "LBUTTON_DOWN", MB_OK) ;
	}

	if(g_Joystick->IsButtonDown(0))
	{
		MessageBox(NULL, "0 Button", "0 BUtton", MB_OK) ;
	}
	if(g_Joystick->IsButtonDown(1))
	{
		MessageBox(NULL, "1 Button", "1 BUtton", MB_OK) ;
	}
	if(g_Joystick->IsButtonDown(3))
	{
		MessageBox(NULL, "3 Button", "3 BUtton", MB_OK) ;
	}
	if(g_Joystick->IsButtonDown(4))
	{
		MessageBox(NULL, "4 Button", "4 BUtton", MB_OK) ;
	}
	if(g_Joystick->IsAxisMin(1000, 'x'))
	{
		MessageBox(NULL, "X 1000", "X 1000", MB_OK) ;
	}
	if(g_Joystick->IsPov(22500))
	{
		MessageBox(NULL, "POV ¡ç", "POV ¡ç", MB_OK) ;
	}*/

	Sprite.SetPosition(x, y) ;
	Sprite2.SetPosition(100.0f, 100.0f) ;
	UISprite.SetPosition(100.0f, 100.0f) ;
	UISprite2.SetPosition(50.0f, 50.0f) ;
}