Original Post
// DX1.cpp :
#include <stdafx.h>
#include <windowsx.h>
#include <d3d9.h>
#include <string>
using namespace std;
// define the screen resolution and keyboard macros
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)
// include the Direct3D Library file
#pragma comment (lib, "d3d9.lib")
// global declarations
LPDIRECT3D9 d3d; // the pointer to our Direct3D interface
LPDIRECT3DDEVICE9 d3ddev; // the pointer to the device class
LPDIRECT3DVERTEXBUFFER9 t_buffer = NULL; // the pointer to the vertex buffer
LPDIRECT3DVERTEXBUFFER9 t_bufferc= NULL,t_bufferh=NULL;
VOID* pVoid; // a void pointer
// function prototypes
void initD3D(HWND hWnd); // sets up and initializes Direct3D
void render_frame(void); // renders a single frame
void cleanD3D(void); // closes Direct3D and releases memory
void init_graphics(void); // 3D declarations
struct CUSTOMVERTEX {FLOAT X, Y, Z, RHW; DWORD COLOR;};
#define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)
// the WindowProc function prototype
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
CUSTOMVERTEX t_vert[] =
{ //tri 1
{ 0.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },//0
{ 26.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },//1
{ 13.0f, 30.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },//2
//tri 2
{ 27.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },//3
{ 53.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },//4
{ 40.0f, 30.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },//5
//tri 3
{ 54.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },//6
{ 80.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },//7
{ 67.0f, 30.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },//8
//tri 4
{ 81.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },//9
{ 107.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },//10
{ 94.0f, 30.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },//11
//tri 5
{ 108.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },//12
{ 134.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },//13
{ 121.0f, 30.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },//14
//tri 6
{ 135.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },//15
{ 161.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },//16
{ 148.0f, 30.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },//17
//tri 7
{ 162.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },//18
{ 188.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },//19
{ 175.0f, 30.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },//20
//tri 8
{ 189.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },//21
{ 215.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },//22
{ 201.5f, 30.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },//23
//tri 9
{ 216.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },//24
{ 242.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },//25
{ 229.0f, 30.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },//26
//tri 10
{ 243.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },//27
{ 269.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },//28
{ 256.0f, 30.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },//29
//tri 11
{ 270.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },//30
{ 296.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },//31
{ 283.0f, 30.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },//32
//tri 12
{ 297.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },//33
{ 323.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },//34
{ 310.0f, 30.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },//35
//tri 13
{ 324.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },//36
{ 350.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },//37
{ 337.0f, 30.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },//38
//tri 14
{ 351.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },//39
{ 377.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },//40
{ 364.0f, 30.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },//41
//tri 15
{ 378.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },//42
{ 404.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },//43
{ 390.0f, 30.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },//44
//tri 16
{ 405.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },//45
{ 431.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },//46
{ 418.0f, 30.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },//47
//tri 17
{ 432.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },//48
{ 458.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },//49
{ 445.0f, 30.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },//50
//tri 18
{ 459.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },//51
{ 485.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },//52
{ 472.0f, 30.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },//53
//tri 19
{ 486.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },//54
{ 512.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },//55
{ 499.0f, 30.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },//56
//tri 20
{ 513.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },//57
{ 539.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },//58
{ 526.0f, 30.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },//59
//tri 21
{ 540.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },//60
{ 566.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },//61
{ 553.0f, 30.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },//62
//tri 22
{ 567.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },//63
{ 593.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },//64
{ 580.0f, 30.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },//65
//tri 23
{ 594.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },//66
{ 620.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },//67
{ 607.0f, 30.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },//68
//tri 24
{ 621.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },//69
{ 647.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },//70
{ 634.0f, 30.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },//71
};
CUSTOMVERTEX com_vert[] =
{
{ 13.0f, 31.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//0
{ 13.0f, 51.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//1
{ 40.0f, 31.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//2
{ 40.0f, 51.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//3
{ 67.0f, 31.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//4
{ 67.0f, 51.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//5
{ 94.0f, 31.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//6
{ 94.0f, 51.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//7
{ 121.0f, 31.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//8
{ 121.0f, 51.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//9
{ 148.0f, 31.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//10
{ 148.0f, 51.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//11
{ 175.0f, 31.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//12
{ 175.0f, 51.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//13
{ 201.0f, 31.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//14
{ 201.0f, 51.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//15
{ 229.0f, 31.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//16
{ 229.0f, 51.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//17
{ 256.0f, 31.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//18
{ 256.0f, 51.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//19
{ 283.0f, 31.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//20
{ 283.0f, 51.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//21
{ 310.0f, 31.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//22
{ 310.0f, 51.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//23
{ 337.0f, 31.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//24
{ 337.0f, 51.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//25
{ 364.0f, 31.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//26
{ 364.0f, 51.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//27
{ 390.0f, 31.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//28
{ 390.0f, 51.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//29
{ 418.0f, 31.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//30
{ 418.0f, 51.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//31
{ 445.0f, 31.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//32
{ 445.0f, 51.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//33
{ 472.0f, 31.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//34
{ 472.0f, 51.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//35
{ 499.0f, 31.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//36
{ 499.0f, 51.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//37
{ 526.0f, 31.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//38
{ 526.0f, 51.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//39
{ 553.0f, 31.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//40
{ 553.0f, 51.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//41
{ 580.0f, 31.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//42
{ 580.0f, 51.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//43
{ 607.0f, 31.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//44
{ 607.0f, 51.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//45
{ 634.0f, 31.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//46
{ 634.0f, 51.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },//47
};
CUSTOMVERTEX hum_vert[]={
{ 0.0f, 449.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//0
{ 0.0f, 429.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//1
{ 0.0f, 449.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//2
{ 0.0f, 429.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//3
{ 0.0f, 449.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//4
{ 0.0f, 429.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//5
{ 0.0f, 449.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//6
{ 0.0f, 429.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//7
{ 0.0f, 449.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//8
{ 0.0f, 429.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//9
{ 0.0f, 449.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//10
{ 0.0f, 429.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//11
{ 0.0f, 449.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//12
{ 0.0f, 429.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//13
{ 0.0f, 449.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//14
{ 0.0f, 429.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//15
{ 0.0f, 449.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//16
{ 0.0f, 429.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//17
{ 0.0f, 449.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//18
{ 0.0f, 429.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//19
{ 0.0f, 449.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//20
{ 0.0f, 429.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//21
{ 0.0f, 449.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//22
{ 0.0f, 429.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//23
{ 0.0f, 449.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//24
{ 0.0f, 429.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//25
{ 0.0f, 449.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//26
{ 0.0f, 429.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//27
{ 0.0f, 449.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//28
{ 0.0f, 429.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//29
{ 0.0f, 449.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//30
{ 0.0f, 429.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//31
{ 0.0f, 449.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//32
{ 0.0f, 429.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//33
{ 0.0f, 449.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//34
{ 0.0f, 429.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//35
{ 0.0f, 449.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//36
{ 0.0f, 429.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//37
{ 0.0f, 449.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//38
{ 0.0f, 429.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//39
{ 0.0f, 449.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//40
{ 0.0f, 429.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//41
{ 0.0f, 449.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//42
{ 0.0f, 429.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//43
{ 0.0f, 449.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//44
{ 0.0f, 429.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//45
{ 0.0f, 449.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//46
{ 0.0f, 429.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(100, 100, 255), },//47
{ 304.0f, 479.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(1, 100, 255), },//48
{ 337.0f, 479.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(1, 100, 255), },//49
{ 320.0f, 449.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(1, 100, 255), },//50
};
int ctr=0;
int com_ammo[24]={0};
int com_stat[24]={0};
int hum_ammo[24]={0};
int hum_pos[24]={0};
void upgrade()
{
for(int x=0;x<24;++x)
{
if(com_ammo[x]==1)
{
//com_vert[x*2].Y+=4.0f;
//com_vert[(x*2)+1].Y+=4.0f;
}
if(hum_ammo[x]==1)
{
hum_vert[(x*2)].Y-=2.0f;
hum_vert[(x*2)+1].Y-=2.0f;
}
}
}
void hum_shot()
{
for(ctr=0;ctr<24;ctr++)
if(hum_ammo[ctr]==0)
break;
hum_ammo[ctr]=1;
hum_vert[(ctr*2)].X=320.0f;
hum_vert[(ctr*2)+1].X=320.0f;
}
void com_shot()
{
int s=0;
for(int i=0;i<24;++i,++s)
if(hum_pos==1)
break;
int ctr=1;
com_ammo[s]=1;
for(int j=1;ctr<14;++j)
{
if(s-j>-1)
{
com_ammo[s-j]=1;
ctr++;
}
if(s+j<24)
{
com_ammo[s+j]=1;
ctr++;
}
}
}
void clean()
{
for(int x=0;x<24;++x)
{
if(com_vert[x*2].Y>480.0f)
{
com_vert[x*2].Y=31.0f;
com_vert[(x*2)+1].Y=51.0f;
com_ammo[x]=0;
}
if(hum_vert[x*2].Y<0.0f)
{
hum_vert[x*2].Y=449.0f;
hum_vert[(x*2)+1].Y=429.0f;
hum_ammo[x]=0;
}
}
}
// the entry point for any Windows program
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HWND hWnd;
WNDCLASSEX wc;
ZeroMemory(&wc, sizeof(WNDCLASSEX));
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WindowProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.lpszClassName = "WindowClass";
RegisterClassEx(&wc);
hWnd = CreateWindowEx(NULL,
"WindowClass",
"Our Direct3D Program",
WS_EX_TOPMOST | WS_POPUP, // fullscreen values
0, 0, // the starting x and y positions should be 0
SCREEN_WIDTH, SCREEN_HEIGHT, // set the window to 640 x 480
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hWnd, nCmdShow);
// set up and initialize Direct3D
initD3D(hWnd);
// enter the main loop:
MSG msg;
while(TRUE)
{
DWORD starting_point = GetTickCount();
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
hum_pos[0]=1;
clean();
com_shot();
render_frame();
upgrade();
// check the 'escape' key
if(KEY_DOWN(VK_ESCAPE))
PostMessage(hWnd, WM_DESTROY, 0, 0);
if(KEY_DOWN(VK_SPACE))
hum_shot();
if(KEY_DOWN(VK_RIGHT))
{
for(int x=48;x<51;++x)
hum_vert[x].X+=2.0f;
}
if(KEY_DOWN(VK_LEFT))
{
for(int x=48;x<51;++x)
hum_vert[x].X-=2.0f;
}
while ((GetTickCount() - starting_point) < 10);
}
// clean up DirectX and COM
cleanD3D();
return msg.wParam;
}
// this is the main message handler for the program
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
} break;
}
return DefWindowProc (hWnd, message, wParam, lParam);
}
// this function initializes and prepares Direct3D for use
void initD3D(HWND hWnd)
{
d3d = Direct3DCreate9(D3D_SDK_VERSION);
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = FALSE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hWnd;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.BackBufferWidth = SCREEN_WIDTH;
d3dpp.BackBufferHeight = SCREEN_HEIGHT;
// create a device class using this information and the info from the d3dpp stuct
d3d->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&d3ddev);
d3ddev->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE);
init_graphics(); // call the function to initialize the graphics
return;
}
// this is the function used to render a single frame
void render_frame(void)
{
d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
d3ddev->BeginScene();
t_bufferc->Lock(0, 0, (void**)&pVoid, 0);
memcpy(pVoid, com_vert, sizeof(com_vert));
t_bufferc->Unlock();
t_bufferh->Lock(0, 0, (void**)&pVoid, 0);
memcpy(pVoid, hum_vert, sizeof(hum_vert));
t_bufferh->Unlock();
// select which vertex format we are using
d3ddev->SetFVF(CUSTOMFVF);
// select the vertex buffer to display
d3ddev->SetStreamSource(0, t_buffer, 0, sizeof(CUSTOMVERTEX));
// copy the vertex buffer to the back buffer
for(DWORD x=0;x<72;x=x+3)
d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, x, 1);
d3ddev->SetStreamSource(0, t_bufferc, 0, sizeof(CUSTOMVERTEX));
// copy the vertex buffer to the back buffer
for(DWORD y=0;y<24;++y)
if(com_ammo[y]==1)
d3ddev->DrawPrimitive(D3DPT_LINELIST, (y*2), 1);
d3ddev->SetStreamSource(0, t_bufferh, 0, sizeof(CUSTOMVERTEX));
d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 48, 1);
for(DWORD z=0;z<24;++z)
if(hum_ammo[z]==1)
d3ddev->DrawPrimitive(D3DPT_LINELIST, (z*2), 1);
d3ddev->EndScene();
d3ddev->Present(NULL, NULL, NULL, NULL);
return;
}
// this is the function that cleans up Direct3D and COM
void cleanD3D(void)
{
t_buffer->Release(); // close and release the vertex buffer
d3ddev->Release(); // close and release the 3D device
d3d->Release(); // close and release Direct3D
return;
}
// this is the function that puts the 3D models into video RAM
void init_graphics(void)
{
// create a vertex buffer interface called t_buffer
d3ddev->CreateVertexBuffer(sizeof(t_vert),
0,
CUSTOMFVF,
D3DPOOL_MANAGED,
&t_buffer,
NULL);
// lock t_buffer and load the vertices into it
t_buffer->Lock(0, 0, (void**)&pVoid, 0);
memcpy(pVoid, t_vert, sizeof(t_vert));
t_buffer->Unlock();
// create a vertex buffer interface called t_buffer
d3ddev->CreateVertexBuffer(sizeof(com_vert),
0,
CUSTOMFVF,
D3DPOOL_MANAGED,
&t_bufferc,
NULL);
d3ddev->CreateVertexBuffer(sizeof(hum_vert),
0,
CUSTOMFVF,
D3DPOOL_MANAGED,
&t_bufferh,
NULL);
return;
}