Advertisement

Hit bar?

Started by January 31, 2009 06:34 PM
9 comments, last by Antonym 15 years, 11 months ago
I'll go with simply drawing a rectangle of solid color and just changing its size depending on health(Trying to get things done as simple as possible since I am learning).

How do you draw this sort of rectangle with directX? Right now I am only familiar with sprites :S.

I tried like this just to show a triangle but nothing shows up.
#define CustomFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)struct CustomVertex {	FLOAT X, Y, Z, RHW; 	DWORD COLOR;};//This one gets run on every iteration of the game loopvoid Direct3D::draw_primitive(){	d3d_device->SetFVF(CustomFVF);	d3d_device->SetStreamSource(0, t_buffer, 0, sizeof(CustomFVF));	d3d_device->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);}//This one is only run during game initialization.void Direct3D::init_primitives(){	CustomVertex t_vert[] =    {        { 320.0f, 50.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },        { 520.0f, 400.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },        { 120.0f, 400.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },    };		d3d_device->CreateVertexBuffer(3*sizeof(CustomVertex),								   0,								   CustomFVF,								   D3DPOOL_MANAGED,								   &t_buffer,								   NULL);	void* void_pointer;	t_buffer->Lock(0, 0, (void**)&void_pointer, 0);	memcpy(void_pointer, t_vert, sizeof(t_vert));	t_buffer->Unlock();								   }void Game::run(){	//Seed random number	DWORD time = timeGetTime();	srand(time);	//Load sprites	load_graphics();	//Loop	main_loop();}void Game::load_graphics(){	direct3d->init_primitives();}void Game::main_loop(){	init_game();	float32 timeStep = 1.0f / 60.0f;	int32 iterations = 10;	while(application->handle_messages())	{		world->Step(timeStep, iterations);		update();		render();	}}void Game::render(){	direct3d->start_render();	std::vector<Object*>::iterator it = game_objects.begin();	for( ; it != game_objects.end(); it++)	{		direct3d->draw_sprite(**it);	}	direct3d->draw_primitive();	direct3d->draw_font(score);	direct3d->end_render();}


[Edited by - Antonym on February 1, 2009 9:20:36 PM]

This topic is closed to new replies.

Advertisement