Пример #1
0
bool GameWindow::Init(HINSTANCE hInstance, int nCmdShow){
	//initialize window settings
    WNDCLASSEX wc;
    wc.cbSize = sizeof(WNDCLASSEX); 
    wc.style         = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc   = (WNDPROC)WinProc;
    wc.cbClsExtra	 = 0;
    wc.cbWndExtra	 = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = NULL;
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = kApplicationTitle;
    wc.hIconSm       = NULL;
    RegisterClassEx(&wc);

	//create a new window
    m_Window = CreateWindow(kApplicationTitle, kApplicationTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 
							CW_USEDEFAULT, kScreenWidth, kScreenHeight, NULL, NULL, hInstance, NULL);

    //was there an error creating the window?
    if (!m_Window) 
		return false;

    //display the window
    ShowWindow(m_Window, nCmdShow);
    UpdateWindow(m_Window);			// TODO: should I call this every update?  The name certainly suggests that...

	//initialize Direct3D
    m_d3d = Direct3DCreate9(D3D_SDK_VERSION);
    if (!m_d3d){
        MessageBox(m_Window, L"Error initializing Direct3D", L"Error", MB_OK);
        return false;
    }

    //set Direct3D presentation parameters
    D3DPRESENT_PARAMETERS d3dpp; 
    ZeroMemory(&d3dpp, sizeof(d3dpp));
    d3dpp.Windowed = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    d3dpp.BackBufferCount = 1;
    d3dpp.BackBufferWidth = kScreenWidth;
    d3dpp.BackBufferHeight = kScreenHeight;
    d3dpp.hDeviceWindow = m_Window;

    //create Direct3D device
    m_d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_Window,
						D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &m_d3ddev);

    if (!m_d3ddev){
        MessageBox(m_Window, L"Error creating Direct3D device", L"Error", MB_OK);
        return 0;
    }

    //clear the m_Backbuffer to black
    m_d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);
    
    //create m_Surface
    HRESULT result = m_d3ddev->CreateOffscreenPlainSurface(
        kScreenWidth,			//width of the m_Surface
        kScreenHeight,			//height of the m_Surface
        D3DFMT_X8R8G8B8,		//m_Surface format
        D3DPOOL_DEFAULT,		//memory pool to use
        &m_Surface,				//pointer to the m_Surface
        NULL);					//reserved (always NULL)
    
	if (!SUCCEEDED(result)) 
		return false;

    //load m_Surface from file into newly created m_Surface
    result = D3DXLoadSurfaceFromFile(
        m_Surface,				//destination m_Surface
        NULL,					//destination palette
        NULL,					//destination rectangle
        kBackground,		//source filename
        NULL,					//source rectangle
        D3DX_DEFAULT,			//controls how image is filtered
        0,						//for transparency (0 for none)
        NULL);					//source image info (usually NULL)

    //make sure file was loaded okay
    if (!SUCCEEDED(result)) 
		return false;
	
	//create sprite
	D3DXCreateSprite(m_d3ddev, &m_Sprite);
	//create font for scores
	D3DXCreateFont(m_d3ddev, 45, 0, FW_BOLD, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,	DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
	TEXT("OCR A Std"), &m_Font);

	//load startgame texture
	m_StartGameTexture = Load_Texture(kStartGame);
	//load hp texture
	m_HpTexture = Load_Texture(m_HpImg);
	//powerup texture- static image
	m_pPowerup.m_Texture = Load_Texture(m_pPowerup.m_Image);
	//for respawn rate
	m_Frame = 0;

	//create sound
	m_cSound = new CSoundManager();
	m_cSound->Initialize(m_Window, DSSCL_PRIORITY);
	m_cSound->SetPrimaryBufferFormat(2, 22050, 16);
	//sound effects
	m_cSound->Create(&m_pJump, L"sounds\\jump.wav");
	m_cSound->Create(&m_pKill, L"sounds\\kill.wav");
	m_cSound->Create(&m_pDamaged, L"sounds\\damaged.wav");
	m_cSound->Create(&m_pShoot, L"sounds\\shoot.wav");
	m_cSound->Create(&m_pMusic, L"sounds\\music.wav");
	m_cSound->Create(&m_pSelect, L"sounds\\select.wav");
	m_cSound->Create(&m_pPickup, L"sounds\\pickup.wav");
	//play music loop
	m_pMusic->Play(0, DSBPLAY_LOOPING);

    return true;
}
Пример #2
0
// An Update() helper that draws the image.
void GameWindow::Draw()
{
    //make sure the Direct3D device is valid
    if (!m_d3ddev) return;

    //create pointer to the back buffer
    m_d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &m_Backbuffer);
	//if in game
	if(m_bInGame){
		//load sprite textures
		m_wPlayer.m_Texture = Load_Texture(m_wPlayer.m_Image);
		for(int i = 0; i < 7; i++){
			if(m_eAllEnemies[i].m_bOnScreen){
				m_eAllEnemies[i].m_Texture = Load_Texture(m_eAllEnemies[i].m_Image);
				m_eAllEnemies[i].m_HPTexture = Load_Texture(m_eAllEnemies[i].m_HPimg);
			}
		}
		for(int i = 0; i < 7; i++){
			if(m_pProjectileList[i].m_bOnScreen){
				m_pProjectileList[i].m_Texture = Load_Texture(m_pProjectileList[i].m_Image);
			}
		}
	}
    //start rendering
    if (m_d3ddev->BeginScene())
    {
		
        //draw m_Surface to the m_Backbuffer
		m_d3ddev->StretchRect(m_Surface, NULL, m_Backbuffer, NULL, D3DTEXF_NONE);
		//begin drawing sprites
		m_Sprite->Begin(D3DXSPRITE_ALPHABLEND);
		//if in game
		if(m_bInGame){
			
			//Turn x and y into a vector. Eventually I will set all coordinates to be vectors
			D3DXVECTOR3 pos1(m_wPlayer.m_X, m_wPlayer.m_Y, 0);
			
			//draw player
			m_Sprite->Draw(m_wPlayer.m_Texture, NULL, NULL, &pos1, D3DCOLOR_XRGB(255,255,255));
			
			//draw player's spell icon
			m_wPlayer.m_Texture = Load_Texture(m_wPlayer.m_SpellImage);
			D3DXVECTOR3 spellpos(m_wPlayer.m_X+0.25f*m_wPlayer.m_Width, m_wPlayer.m_Y-48, 0);
			m_Sprite->Draw(m_wPlayer.m_Texture, NULL, NULL, &spellpos, D3DCOLOR_XRGB(255,255,255));
			
			//draw all enemies
			for(int i = 0; i < 7; i++){
				if(m_eAllEnemies[i].m_bOnScreen){
					D3DXVECTOR3 pos2(m_eAllEnemies[i].m_X, m_eAllEnemies[i].m_Y, 0);
					m_Sprite->Draw(m_eAllEnemies[i].m_Texture, NULL, NULL, &pos2, D3DCOLOR_XRGB(255,255,255));
					//draw hp icons
					D3DXVECTOR3 pos4(m_eAllEnemies[i].m_X, m_eAllEnemies[i].m_Y- 32, 0);
					m_Sprite->Draw(m_eAllEnemies[i].m_HPTexture, NULL, NULL, &pos4, D3DCOLOR_XRGB(255,255,255));
				}
			}
			
			//draw projectile spells 
			for(int i = 0; i < 10; i++){
				if(m_pProjectileList[i].m_bOnScreen){
					D3DXVECTOR3 pos3(m_pProjectileList[i].m_X, m_pProjectileList[i].m_Y, 0);
					m_Sprite->Draw(m_pProjectileList[i].m_Texture, NULL, NULL, &pos3, D3DCOLOR_XRGB(255,255,255));
				}
			}

			//draw powerups
			D3DXVECTOR3 pos5(m_pPowerup.m_X, m_pPowerup.m_Y, 0);
			m_Sprite->Draw(m_pPowerup.m_Texture, NULL, NULL, &pos5, D3DCOLOR_XRGB(255, 255, 255));
			//draw hp ui
			D3DXVECTOR3 HpPos(16, 684, 0);
			m_Sprite->Draw(m_HpTexture, NULL, NULL, &HpPos, D3DCOLOR_XRGB(255,255,255));
			if(m_wPlayer.m_Health > 1){
				D3DXVECTOR3 HpPos(48, 684, 0);
				m_Sprite->Draw(m_HpTexture, NULL, NULL, &HpPos, D3DCOLOR_XRGB(255,255,255));
			}
			if(m_wPlayer.m_Health > 2){
				D3DXVECTOR3 HpPos(80, 684, 0);
				m_Sprite->Draw(m_HpTexture, NULL, NULL, &HpPos, D3DCOLOR_XRGB(255,255,255));
			}
		}
		else{
			//write title
			m_Font->DrawTextA(NULL, "Snape Simulator 2012", -1, &m_rTitle, DT_RIGHT, D3DCOLOR_XRGB(0, 0, 70));
			//draw "press space to start" in center of screen
			D3DXVECTOR3 StartPos(356, 256, 0);
			m_Sprite->Draw(m_StartGameTexture, NULL, NULL, &StartPos, D3DCOLOR_XRGB(255, 255, 255));
		}
		//UI- draw scores
		std::stringstream ss;//create a stringstream
		ss << m_Score;//add number to the stream
		std::string j = ss.str();
		m_Font->DrawTextA(NULL, j.c_str(), -1, &m_rCurrScore, DT_RIGHT, D3DCOLOR_ARGB(255, 255, 255, 255));

		std::stringstream ss2;
		ss2 << m_Highscore;
		j = ss2.str();
		m_Font->DrawTextA(NULL, j.c_str(), -1, &m_rBest, DT_RIGHT, D3DCOLOR_ARGB(255, 255, 255, 255));

        //stop rendering
        m_Sprite->End();
		m_d3ddev->EndScene();
        m_d3ddev->Present(NULL, NULL, NULL, NULL);

	}
}
Пример #3
0
int main(int argc,char **argv){
	Init();
	//sndoggvorbis_start("/pc/billy.ogg",-1);
	Lights[0].z = 10.0;
	Lights[0].x = 0.0;
	Lights[0].y = 0.0;
	Lights[0].w = 1.0;
	Lights[0].r = 5.0;
	Lights[0].g = 0.0;
	Lights[0].b = 0.0;
	Lights[0].a = 1.0;
	Lights[0].aa = 0.0;
	Lights[0].ab = 0.0;
	Lights[0].ac = 1.0;
	Lights[0].dummy = 1.0;
	
	Lights[1].z = 10.0;
	Lights[1].x = 100.0;
	Lights[1].y = 100.0;
	Lights[1].w = 1.0;
	Lights[1].r = 0.0;
	Lights[1].g = 5.0;
	Lights[1].b = 0.0;
	Lights[1].a = 1.0;
	Lights[1].aa = 0.0;
	Lights[1].ab = 0.0;
	Lights[1].ac = 1.0;
	Lights[1].dummy = 1.0;
	
	Lights[2].z = 10.0;
	Lights[2].x = 400.0;
	Lights[2].y = 400.0;
	Lights[2].w = 1.0;
	Lights[2].r = 0.0;
	Lights[2].g = 0.0;
	Lights[2].b = 5.0;
	Lights[2].a = 1.0;
	Lights[2].aa = 0.0;
	Lights[2].ab = 0.0;
	Lights[2].ac = 1.0;
	Lights[2].dummy = 1.0;

	
	vid_border_color(255,0,0);
	Load_Texture("/rd/bumpmap.raw",&GlobalNormal);
	Load_Texture("/rd/text.raw",&GlobalTex);
	vid_border_color(0,0,255);
	Init_Layer();
	
	
	
	int q = 0;
	int x = 0;
	int pushed = 0;
	int bumpenabled = 1;
	int display_fps = 0;
	bfont_set_encoding(BFONT_CODE_ISO8859_1);
	while(q == 0){
		mat_identity();

		
		vid_border_color(255,0,0);
		pvr_wait_ready();
		vid_border_color(0,255,0);
		pvr_scene_begin();
		pvr_list_begin(PVR_LIST_OP_POLY);
			Draw_Layer();
		pvr_list_finish();
		
		pvr_list_begin(PVR_LIST_TR_POLY);
		if(bumpenabled)
			Draw_Layer_Bump();
		pvr_list_finish();
		
		pvr_scene_finish();
		vid_border_color(0,0,255);
	
		MAPLE_FOREACH_BEGIN(MAPLE_FUNC_CONTROLLER, cont_state_t, st);
			if(st->buttons & CONT_START)
				q = 1;
			
			if(st->joyx > 32){
				Lights[x].x += 4.0f;
			}
			if(st->joyx < -32){
				Lights[x].x -= 4.0f;
			}
			if(st->joyy < -32){
				Lights[x].y -= 4.0f;
			}
			if(st->joyy > 32){
				Lights[x].y += 4.0f;
			}
			
			
			if(st->buttons & CONT_DPAD_LEFT){
				Lights[x].x -= 4.0f;
			}
			if(st->buttons & CONT_DPAD_RIGHT){
				Lights[x].x += 4.0f;
			}
			if(st->buttons & CONT_DPAD_UP){
				Lights[x].y -= 4;
			}
			if(st->buttons & CONT_DPAD_DOWN){
				Lights[x].y += 4;
			}
				
			if(st->buttons & CONT_A && pushed == 0){
				pushed = 1;
				x++;
				if(x == LIGHTS){
					x = 0;
				}
			} 
			
			if(st->buttons & CONT_Y && pushed == 0){
				LIGHTS--;
				pushed = 1;
				if(LIGHTS < 0){
					LIGHTS = MAX_LIGHTS;
				}
			}
			
			if(st->buttons & CONT_B && pushed == 0){
				display_fps ^= 0x01;
				pushed = 1;
			}
			
			if(st->buttons & CONT_X && pushed == 0){
				bumpenabled ^= 0x01;
				pushed = 1;
			}
			
			if(!(st->buttons & CONT_A) && !(st->buttons & CONT_B) && !(st->buttons & CONT_X) && !(st->buttons & CONT_Y)){
				pushed = 0;
			}
			
		
		MAPLE_FOREACH_END();
		running_stats();
		sprintf(buf,"FPS:%f",avgfps);
		if(display_fps){
				//printf("%s\n",buf);
			bfont_draw_str(vram_s + (640*24),640,1,buf);
		}
		
	}
	DeleteTexture(&GlobalNormal);
	DeleteTexture(&GlobalTex);
	//sndoggvorbis_stop();
	//sndoggvorbis_shutdown();
	pvr_shutdown();
	return 0;
}