Ejemplo n.º 1
0
void InClassProj::DrawParticles()
{
	XMVECTOR eyePos = m2DCam->GetPos();
	XMMATRIX proj = XMLoadFloat4x4(&mProj);
	XMMATRIX view = m2DCam->GetView();

	XMMATRIX vp = view * proj;

	mParticleEffect->SetPerFrameParams(eyePos);
	mParticleEffect->SetPerObjectParams(vp, mParticleTexture);

	md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
	md3dImmediateContext->IASetInputLayout(Vertex::GetParticleVertLayout());
	
	UINT stride = sizeof(Vertex::ParticleVertex);
	UINT offset = 0;

	md3dImmediateContext->IASetVertexBuffers(0, 1, &mParticleVB, &stride, &offset);
	
	md3dImmediateContext->OMSetDepthStencilState(mNoDepthDS, 0);
	float blendFactor[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
	md3dImmediateContext->OMSetBlendState(mAdditiveBS, blendFactor, 0xffffffff);

	D3DX11_TECHNIQUE_DESC techDesc; 
	mParticleEffect->GetTech()->GetDesc(&techDesc);
	for (UINT p = 0; p < techDesc.Passes; ++p)
	{
		mParticleEffect->GetTech()->GetPassByIndex(p)->Apply(0, md3dImmediateContext);
		md3dImmediateContext->Draw(mParticles.size(), 0);
	}

	md3dImmediateContext->OMSetBlendState(0, blendFactor, 0xffffffff);
	md3dImmediateContext->OMSetDepthStencilState(NULL, 0);
}
Ejemplo n.º 2
0
bool InClassProj::Init()
{
	if(!D3DApp::Init())
		return false;

	//FMOD sounds
	result = FMOD::System_Create(&sys);
	result = sys->getVersion(&version);
	if (version < FMOD_VERSION)
	{
		OutputDebugString(L"FMOD lib version doesn't match header version");
	}
	result = sys->init(32, FMOD_INIT_NORMAL, extradriverdata);
	result = sys->createSound("Sounds/choo.ogg", FMOD_DEFAULT, 0, &sound1);  //fire arrow sfx (placeholder?)
	result = sound1->setMode(FMOD_LOOP_OFF);

 	mLitTexEffect = new LitTexEffect();
	mLitTexEffect->LoadEffect(L"FX/lighting.fx", md3dDevice);

	mParticleEffect = new ParticleEffect();
	mParticleEffect->LoadEffect(L"FX/ParticleEffect.fx", md3dDevice);

	Vertex::InitLitTexLayout(md3dDevice, mLitTexEffect->GetTech());

	//camera
	m2DCam = new BaseCamera(XMVectorSet(0.0f, 0.0f, -0.5f, 0.0f), XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f), XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f));
	m2DCam->Update();

	BuildSceneLights();

	Vertex::InitParticleVertLayout(md3dDevice, mParticleEffect->GetTech());

	BuildParticleVB();

	D3DX11CreateShaderResourceViewFromFile(md3dDevice, L"Textures/TestAdditive.png", 0, 0, &mParticleTexture, 0);

	BuildBlendStates();
	BuildDSStates();

	//font
	ID3D11ShaderResourceView* font;
	D3DX11CreateShaderResourceViewFromFile(md3dDevice, L"Textures/font.png", 0, 0, &font, 0);
	mFont = new FontRasterizer(m2DCam, XMLoadFloat4x4(&m2DProj), mLitTexEffect, 10, 10, font, md3dDevice);

	//projectile image
	ID3D11ShaderResourceView* projImage;
	D3DX11CreateShaderResourceViewFromFile(md3dDevice, L"Textures/arrow.png", 0, 0, &projImage, 0);
	//projectile frame
	projectileFrame->imageWidth = 22;
	projectileFrame->imageHeight = 9;
	projectileFrame->x = 0;
	projectileFrame->y = 0;
	projectileFrame->image = projImage;
	projFrame.push_back(projectileFrame);

	//bg image
	Sprite::Frame* BGFrame = new Sprite::Frame();
	ID3D11ShaderResourceView* BGimage;
	D3DX11CreateShaderResourceViewFromFile(md3dDevice, L"Textures/TFAbgTiled.png", 0, 0, &BGimage, 0);
	//bg frame
	BGFrame->imageWidth = 1024;
	BGFrame->imageHeight = 768;
	BGFrame->x = 0;
	BGFrame->y = 0;
	BGFrame->image = BGimage;
	std::vector<Sprite::Frame*> bgFrame;
	bgFrame.push_back(BGFrame);

	//Player spritesheet image
	Sprite::Frame* newFrame = new Sprite::Frame();
	ID3D11ShaderResourceView* image;
	D3DX11CreateShaderResourceViewFromFile(md3dDevice, L"Textures/player.png", 0, 0, &image, 0);
	//player frame1
	newFrame->imageWidth = 96;
	newFrame->imageHeight = 96;
	newFrame->x = 0;
	newFrame->y = 0;
	newFrame->image = image;
	std::vector<Sprite::Frame*> frames;
	frames.push_back(newFrame);
	//player frame2
	newFrame = new Sprite::Frame();
	newFrame->imageWidth = 96;
	newFrame->imageHeight = 96;
	newFrame->x = 32;
	newFrame->y = 0;
	newFrame->image = image;
	frames.push_back(newFrame);
	//player frame3
	newFrame = new Sprite::Frame();
	newFrame->imageWidth = 96;
	newFrame->imageHeight = 96;
	newFrame->x = 64;
	newFrame->y = 0;
	newFrame->image = image;
	frames.push_back(newFrame);

	//Enemy1 spritesheet image
	Sprite::Frame* enemyFrame1 = new Sprite::Frame();
	ID3D11ShaderResourceView* enemyImage1;
	D3DX11CreateShaderResourceViewFromFile(md3dDevice, L"Textures/enemyStrip1.png", 0, 0, &enemyImage1, 0);
	//Enemy1 frame1
	enemyFrame1->imageWidth = 96;
	enemyFrame1->imageHeight = 32;
	enemyFrame1->x = 0;
	enemyFrame1->y = 0;
	enemyFrame1->image = enemyImage1;
	std::vector<Sprite::Frame*> enemyFrames1;
	enemyFrames1.push_back(enemyFrame1);
	//Enemy1 frame2
	enemyFrame1 = new Sprite::Frame();
	enemyFrame1->imageWidth = 96;
	enemyFrame1->imageHeight = 32;
	enemyFrame1->x = 32;
	enemyFrame1->y = 0;
	enemyFrame1->image = enemyImage1;
	enemyFrames1.push_back(enemyFrame1);
	//Enemy1 frame3
	enemyFrame1 = new Sprite::Frame();
	enemyFrame1->imageWidth = 96;
	enemyFrame1->imageHeight = 32;
	enemyFrame1->x = 64;
	enemyFrame1->y = 0;
	enemyFrame1->image = enemyImage1;
	enemyFrames1.push_back(enemyFrame1);

	//Enemy2 spritesheet image
	Sprite::Frame* enemyFrame2 = new Sprite::Frame();
	ID3D11ShaderResourceView* enemyImage2;
	D3DX11CreateShaderResourceViewFromFile(md3dDevice, L"Textures/enemyStrip2.png", 0, 0, &enemyImage2, 0);
	//Enemy2 frame1
	enemyFrame2->imageWidth = 96;
	enemyFrame2->imageHeight = 32;
	enemyFrame2->x = 0;
	enemyFrame2->y = 0;
	enemyFrame2->image = enemyImage2;
	std::vector<Sprite::Frame*> enemyFrames2;
	enemyFrames2.push_back(enemyFrame2);
	//Enemy2 frame2
	enemyFrame2 = new Sprite::Frame();
	enemyFrame2->imageWidth = 96;
	enemyFrame2->imageHeight = 32;
	enemyFrame2->x = 32;
	enemyFrame2->y = 0;
	enemyFrame2->image = enemyImage2;
	enemyFrames2.push_back(enemyFrame2);
	//Enemy2 frame3
	enemyFrame2 = new Sprite::Frame();
	enemyFrame2->imageWidth = 96;
	enemyFrame2->imageHeight = 32;
	enemyFrame2->x = 64;
	enemyFrame2->y = 0;
	enemyFrame2->image = enemyImage2;
	enemyFrames2.push_back(enemyFrame2);

	//Enemy3 spritesheet image
	Sprite::Frame* enemyFrame3 = new Sprite::Frame();
	ID3D11ShaderResourceView* enemyImage3;
	D3DX11CreateShaderResourceViewFromFile(md3dDevice, L"Textures/enemyStrip3.png", 0, 0, &enemyImage3, 0);
	//Enemy3 frame1
	enemyFrame3->imageWidth = 96;
	enemyFrame3->imageHeight = 32;
	enemyFrame3->x = 0;
	enemyFrame3->y = 0;
	enemyFrame3->image = enemyImage3;
	std::vector<Sprite::Frame*> enemyFrames3;
	enemyFrames3.push_back(enemyFrame3);
	//Enemy3 frame2
	enemyFrame3 = new Sprite::Frame();
	enemyFrame3->imageWidth = 96;
	enemyFrame3->imageHeight = 32;
	enemyFrame3->x = 32;
	enemyFrame3->y = 0;
	enemyFrame3->image = enemyImage3;
	enemyFrames3.push_back(enemyFrame3);
	//Enemy3 frame3
	enemyFrame3 = new Sprite::Frame();
	enemyFrame3->imageWidth = 96;
	enemyFrame3->imageHeight = 32;
	enemyFrame3->x = 64;
	enemyFrame3->y = 0;
	enemyFrame3->image = enemyImage3;
	enemyFrames3.push_back(enemyFrame3);

	//enemy green health bar image
	Sprite::Frame* greenHBFrame = new Sprite::Frame();
	ID3D11ShaderResourceView* greenHBimage;
	D3DX11CreateShaderResourceViewFromFile(md3dDevice, L"Textures/greenHealth.png", 0, 0, &greenHBimage, 0);
	greenHBFrame->imageWidth = 32;
	greenHBFrame->imageHeight = 8;
	greenHBFrame->x = 0;
	greenHBFrame->y = 0;
	greenHBFrame->image = greenHBimage;
	hbFrameG.push_back(greenHBFrame);
	//enemy red health bar image
	Sprite::Frame* redHBFrame = new Sprite::Frame();
	ID3D11ShaderResourceView* redHBimage;
	D3DX11CreateShaderResourceViewFromFile(md3dDevice, L"Textures/redHealth.png", 0, 0, &redHBimage, 0);
	redHBFrame->imageWidth = 32;
	redHBFrame->imageHeight = 8;
	redHBFrame->x = 0;
	redHBFrame->y = 0;
	redHBFrame->image = redHBimage;
	hbFrameR.push_back(redHBFrame);

	//end of level object image
	Sprite::Frame* EOLobjFrame = new Sprite::Frame();
	ID3D11ShaderResourceView* EOLobjImg;
	D3DX11CreateShaderResourceViewFromFile(md3dDevice, L"Textures/EOLobj.png", 0, 0, &EOLobjImg, 0);
	//EOLobj frame1
	EOLobjFrame->imageWidth = 192;
	EOLobjFrame->imageHeight = 64;
	EOLobjFrame->x = 0;
	EOLobjFrame->y = 0;
	EOLobjFrame->image = EOLobjImg;
	EOLobjFrames.push_back(EOLobjFrame);
	//EOLobj frame2
	EOLobjFrame = new Sprite::Frame();
	EOLobjFrame->imageWidth = 192;
	EOLobjFrame->imageHeight = 64;
	EOLobjFrame->x = 64;
	EOLobjFrame->y = 0;
	EOLobjFrame->image = EOLobjImg;
	EOLobjFrames.push_back(EOLobjFrame);
	//EOLobj frame3
	EOLobjFrame = new Sprite::Frame();
	EOLobjFrame->imageWidth = 192;
	EOLobjFrame->imageHeight = 64;
	EOLobjFrame->x = 128;
	EOLobjFrame->y = 0;
	EOLobjFrame->image = EOLobjImg;
	EOLobjFrames.push_back(EOLobjFrame);

	//background
	mBG = new Sprite(XMVectorSet(mClientWidth / 2.0f, mClientHeight / 2.0f, 0.0f, 0.0f), XMVectorSet(1.0f, 1.0f, 1.0f, 0.0f), 
		1024.0f, 768.0f, 1.0f, bgFrame, 0.25f, md3dDevice, 0.0f);
	//player
	mPlayer = new Player(XMVectorSet(mClientWidth / 2.0f, mClientHeight / 2.0f, 0.0f, 0.0f), XMVectorSet(1.0f, 1.0f, 1.0f, 0.0f),
		32, 32, 0.1f, frames, 0.25f, md3dDevice, 5.0f);
	//enemy1
	mEnemy1 = new Enemy(XMVectorSet(800.0f, 500.0f, 0.0f, 0.0f), XMVectorSet(1.0f, 1.0f, 1.0f, 0.0f), 
		32.0f, 32.0f, 0.1f, enemyFrames1, 0.25f, md3dDevice, 1.0f);
	enemies.push_back(mEnemy1);
	//enemy2
	mEnemy2 = new Enemy(XMVectorSet(600.0f, 700.0f, 0.0f, 0.0f), XMVectorSet(1.0f, 1.0f, 1.0f, 0.0f),
		32.0f, 32.0f, 0.1f, enemyFrames2, 0.25f, md3dDevice, 1.0f);
	enemies.push_back(mEnemy2);
	//enemy3
	mEnemy3 = new Enemy(XMVectorSet(800, 200.0f, 0.0f, 0.0f), XMVectorSet(1.0f, 1.0f, 1.0f, 0.0f),
		32.0f, 32.0f, 0.1f, enemyFrames3, 0.25f, md3dDevice, 1.0f);
	enemies.push_back(mEnemy3);
	//enemy health bars
	for (int i = 0; i < enemies.size(); ++i)
	{
		mGreenHBar = new Sprite(XMVectorSet(enemies[i]->GetPos().m128_f32[0], enemies[i]->GetPos().m128_f32[1] + 32, 0.0f, 0.0f),
			XMVectorSet(1.0f, 1.0f, 1.0f, 0.0f), 32.0f, 8.0f, 1.0f, hbFrameG, 0.25f, md3dDevice, 0.0f);
		greenBarVec.push_back(mGreenHBar);
		mRedHBar = new Sprite(XMVectorSet(redXPos, enemies[i]->GetPos().m128_f32[1] + 32, 0.0f, 0.0f),
			XMVectorSet(1.0f, 1.0f, 1.0f, 0.0f), 32.0f, 8.0f, 1.0f, hbFrameR, 0.25f, md3dDevice, 0.0f);
		redBarVec.push_back(mRedHBar);
	}
	//end of level object
	EOLobj = new Sprite(XMVectorSet(mClientWidth / 2.0f, mClientHeight - 64.0f, 0.0f, 0.0f), XMVectorSet(1.0f, 1.0f, 1.0f, 0.0f),
		64.0f, 64.0f, 1.0f, EOLobjFrames, 0.25f, md3dDevice, 0.0f);

	mPlayer->Play(true);

	for (int i = 0; i < enemies.size(); ++i)
	{
		enemies[i]->Play(true);
	}

	//result = sys->playSound(sound1, 0, false, &channel);

	InitBoundingBoxes();

	return true;
}