Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // include the basic windows header files and the Direct3D header file
- #include <windows.h>
- #include <windowsx.h>
- #include <d3d9.h>
- #include <d3dx9.h>
- #include <iostream>
- // 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)
- #define ENEMY_NUM 10
- #define ENEMY_NUM2 3
- int Score = 0;
- // include the Direct3D Library file
- #pragma comment (lib, "d3d9.lib")
- #pragma comment (lib, "d3dx9.lib")
- // global declarations
- LPDIRECT3D9 d3d; // the pointer to our Direct3D interface
- LPDIRECT3DDEVICE9 d3ddev; // the pointer to the device class
- LPD3DXSPRITE d3dspt; // the pointer to our Direct3D Sprite interface
- // sprite declarations
- LPDIRECT3DTEXTURE9 sprite; // the pointer to the sprite
- LPDIRECT3DTEXTURE9 sprite_hero; // the pointer to the sprite
- LPDIRECT3DTEXTURE9 sprite_enemy; // the pointer to the sprite
- LPDIRECT3DTEXTURE9 sprite_bullet; // the pointer to the sprite
- LPDIRECT3DTEXTURE9 sprite_bg;
- LPDIRECT3DTEXTURE9 sprite_flyenemy;
- LPDIRECT3DTEXTURE9 sprite_Score0;
- LPDIRECT3DTEXTURE9 sprite_Score1;
- LPDIRECT3DTEXTURE9 sprite_Score2;
- LPDIRECT3DTEXTURE9 sprite_Score3;
- LPDIRECT3DTEXTURE9 sprite_Score4;
- LPDIRECT3DTEXTURE9 sprite_Score5;
- LPDIRECT3DTEXTURE9 sprite_Score6;
- LPDIRECT3DTEXTURE9 sprite_Score7;
- LPDIRECT3DTEXTURE9 sprite_Score8;
- LPDIRECT3DTEXTURE9 sprite_Score9;
- LPDIRECT3DTEXTURE9 sprite_Boom;
- // 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_game(void);
- void do_game_logic(void);
- bool sphere_collision_check(float x0, float y0, float size0, float x1, float y1, float size1);
- // the WindowProc function prototype
- LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
- using namespace std;
- enum { MOVE_UP, MOVE_DOWN, MOVE_LEFT, MOVE_RIGHT };
- //기본 클래스
- class entity {
- public:
- float x_pos;
- float y_pos;
- int status;
- int HP;
- };
- bool sphere_collision_check(float x0, float y0, float size0, float x1, float y1, float size1)
- {
- if ((x0 - x1)*(x0 - x1) + (y0 - y1)*(y0 - y1) < (size0 + size1) * (size0 + size1))
- return true;
- else
- return false;
- }
- //주인공 클래스
- class Hero :public entity {
- public:
- void fire();
- void super_fire();
- void move(int i);
- void init(float x, float y);
- };
- void Hero::init(float x, float y)
- {
- x_pos = x;
- y_pos = y;
- }
- void Hero::move(int i)
- {
- switch (i)
- {
- case MOVE_UP:
- y_pos -= 3;
- break;
- case MOVE_DOWN:
- y_pos += 3;
- break;
- case MOVE_LEFT:
- x_pos -= 3;
- break;
- case MOVE_RIGHT:
- x_pos += 3;
- break;
- }
- }
- // 적 클래스
- class Enemy :public entity {
- public:
- void fire();
- void init(float x, float y);
- void move();
- };
- void Enemy::init(float x, float y)
- {
- x_pos = x;
- y_pos = y;
- }
- void Enemy::move()
- {
- x_pos += 2;
- }
- class FlyEnemy :public entity {
- public:
- void fire();
- void init(float x, float y);
- void move();
- int hp = 2;
- };
- void FlyEnemy::init(float x, float y)
- {
- x_pos = x;
- y_pos = y;
- }
- void FlyEnemy::move()
- {
- x_pos += 3;
- }
- // 총알 클래스
- class Bullet :public entity {
- public:
- bool bShow;
- void init(float x, float y);
- void move();
- bool show();
- void hide();
- void active();
- bool check_collision(float x, float y);
- };
- bool Bullet::check_collision(float x, float y)
- {
- //충돌 처리 시
- if (sphere_collision_check(x_pos, y_pos, 32, x, y, 32) == true)
- {
- bShow = false;
- return true;
- }
- else {
- return false;
- }
- }
- void Bullet::init(float x, float y)
- {
- x_pos = x;
- y_pos = y;
- }
- bool Bullet::show()
- {
- return bShow;
- }
- void Bullet::active()
- {
- bShow = true;
- }
- void Bullet::move()
- {
- x_pos -= 8;
- }
- void Bullet::hide()
- {
- bShow = false;
- }
- class Boom :public entity {
- public:
- bool bShow;
- void init(float x, float y);
- bool show();
- void hide();
- void active();
- bool check_collision(float x, float y);
- int killCount=20;
- };
- bool Boom::check_collision(float x, float y)
- {
- //충돌 처리 시
- if (sphere_collision_check(x_pos, y_pos, 128, x, y,128) == true)
- {
- bShow = true;
- return true;
- }
- else {
- return false;
- }
- }
- void Boom::init(float x, float y)
- {
- x_pos = x;
- y_pos = y;
- }
- bool Boom::show()
- {
- return bShow;
- }
- void Boom::active()
- {
- bShow = true;
- }
- void Boom::hide()
- {
- if (killCount <= 0) {
- bShow = false;
- }
- }
- //객체 생성
- Hero hero;
- Enemy enemy[ENEMY_NUM];
- FlyEnemy flyenemy[ENEMY_NUM2];
- Bullet bullet;
- Boom boom;
- // 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 = L"WindowClass";
- RegisterClassEx(&wc);
- hWnd = CreateWindowEx(NULL, L"WindowClass", L"Our Direct3D Program",
- WS_EX_TOPMOST | WS_POPUP, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
- NULL, NULL, hInstance, NULL);
- ShowWindow(hWnd, nCmdShow);
- // set up and initialize Direct3D
- initD3D(hWnd);
- //게임 오브젝트 초기화
- init_game();
- // 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);
- }
- do_game_logic();
- render_frame();
- // check the 'escape' key
- if (KEY_DOWN(VK_ESCAPE))
- PostMessage(hWnd, WM_DESTROY, 0, 0);
- while ((GetTickCount() - starting_point) < 25);
- }
- // 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 = TRUE;
- 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);
- D3DXCreateSprite(d3ddev, &d3dspt); // create the Direct3D Sprite object
- D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
- L"Panel3.png", // the file name
- D3DX_DEFAULT, // default width
- D3DX_DEFAULT, // default height
- D3DX_DEFAULT, // no mip mapping
- NULL, // regular usage
- D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
- D3DPOOL_MANAGED, // typical memory handling
- D3DX_DEFAULT, // no filtering
- D3DX_DEFAULT, // no mip filtering
- D3DCOLOR_XRGB(255, 0, 255), // the hot-pink color key
- NULL, // no image info struct
- NULL, // not using 256 colors
- &sprite); // load to sprite
- D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
- L"hero.png", // the file name
- D3DX_DEFAULT, // default width
- D3DX_DEFAULT, // default height
- D3DX_DEFAULT, // no mip mapping
- NULL, // regular usage
- D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
- D3DPOOL_MANAGED, // typical memory handling
- D3DX_DEFAULT, // no filtering
- D3DX_DEFAULT, // no mip filtering
- D3DCOLOR_XRGB(255, 255, 255), // the hot-pink color key
- NULL, // no image info struct
- NULL, // not using 256 colors
- &sprite_hero); // load to sprite
- D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
- L"cow.png", // the file name
- D3DX_DEFAULT, // default width
- D3DX_DEFAULT, // default height
- D3DX_DEFAULT, // no mip mapping
- NULL, // regular usage
- D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
- D3DPOOL_MANAGED, // typical memory handling
- D3DX_DEFAULT, // no filtering
- D3DX_DEFAULT, // no mip filtering
- D3DCOLOR_XRGB(255, 255, 255), // the hot-pink color key
- NULL, // no image info struct
- NULL, // not using 256 colors
- &sprite_enemy); // load to sprite
- D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
- L"crow.png", // the file name
- D3DX_DEFAULT, // default width
- D3DX_DEFAULT, // default height
- D3DX_DEFAULT, // no mip mapping
- NULL, // regular usage
- D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
- D3DPOOL_MANAGED, // typical memory handling
- D3DX_DEFAULT, // no filtering
- D3DX_DEFAULT, // no mip filtering
- D3DCOLOR_XRGB(255, 255, 255), // the hot-pink color key
- NULL, // no image info struct
- NULL, // not using 256 colors
- &sprite_flyenemy); // load to sprite
- D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
- L"bullet.png", // the file name
- D3DX_DEFAULT, // default width
- D3DX_DEFAULT, // default height
- D3DX_DEFAULT, // no mip mapping
- NULL, // regular usage
- D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
- D3DPOOL_MANAGED, // typical memory handling
- D3DX_DEFAULT, // no filtering
- D3DX_DEFAULT, // no mip filtering
- D3DCOLOR_XRGB(255, 0, 255), // the hot-pink color key
- NULL, // no image info struct
- NULL, // not using 256 colors
- &sprite_bullet); // load to sprite
- D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
- L"bg.png", // the file name
- D3DX_DEFAULT, // default width
- D3DX_DEFAULT, // default height
- D3DX_DEFAULT, // no mip mapping
- NULL, // regular usage
- D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
- D3DPOOL_MANAGED, // typical memory handling
- D3DX_DEFAULT, // no filtering
- D3DX_DEFAULT, // no mip filtering
- D3DCOLOR_XRGB(255, 0, 255), // the hot-pink color key
- NULL, // no image info struct
- NULL, // not using 256 colors
- &sprite_bg); // load to sprite
- D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
- L"Score0점.png", // the file name
- D3DX_DEFAULT, // default width
- D3DX_DEFAULT, // default height
- D3DX_DEFAULT, // no mip mapping
- NULL, // regular usage
- D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
- D3DPOOL_MANAGED, // typical memory handling
- D3DX_DEFAULT, // no filtering
- D3DX_DEFAULT, // no mip filtering
- D3DCOLOR_XRGB(255, 255, 255), // the hot-pink color key
- NULL, // no image info struct
- NULL, // not using 256 colors
- &sprite_Score0); // load to sprite
- D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
- L"Score1점.png", // the file name
- D3DX_DEFAULT, // default width
- D3DX_DEFAULT, // default height
- D3DX_DEFAULT, // no mip mapping
- NULL, // regular usage
- D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
- D3DPOOL_MANAGED, // typical memory handling
- D3DX_DEFAULT, // no filtering
- D3DX_DEFAULT, // no mip filtering
- D3DCOLOR_XRGB(255, 255, 255), // the hot-pink color key
- NULL, // no image info struct
- NULL, // not using 256 colors
- &sprite_Score1); // load to sprite
- D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
- L"Score2점.png", // the file name
- D3DX_DEFAULT, // default width
- D3DX_DEFAULT, // default height
- D3DX_DEFAULT, // no mip mapping
- NULL, // regular usage
- D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
- D3DPOOL_MANAGED, // typical memory handling
- D3DX_DEFAULT, // no filtering
- D3DX_DEFAULT, // no mip filtering
- D3DCOLOR_XRGB(255, 255, 255), // the hot-pink color key
- NULL, // no image info struct
- NULL, // not using 256 colors
- &sprite_Score2); // load to sprite
- D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
- L"Score3점.png", // the file name
- D3DX_DEFAULT, // default width
- D3DX_DEFAULT, // default height
- D3DX_DEFAULT, // no mip mapping
- NULL, // regular usage
- D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
- D3DPOOL_MANAGED, // typical memory handling
- D3DX_DEFAULT, // no filtering
- D3DX_DEFAULT, // no mip filtering
- D3DCOLOR_XRGB(255, 255, 255), // the hot-pink color key
- NULL, // no image info struct
- NULL, // not using 256 colors
- &sprite_Score3); // load to sprite
- D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
- L"Score4점.png", // the file name
- D3DX_DEFAULT, // default width
- D3DX_DEFAULT, // default height
- D3DX_DEFAULT, // no mip mapping
- NULL, // regular usage
- D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
- D3DPOOL_MANAGED, // typical memory handling
- D3DX_DEFAULT, // no filtering
- D3DX_DEFAULT, // no mip filtering
- D3DCOLOR_XRGB(255, 255, 255), // the hot-pink color key
- NULL, // no image info struct
- NULL, // not using 256 colors
- &sprite_Score4); // load to sprite
- D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
- L"Score5점.png", // the file name
- D3DX_DEFAULT, // default width
- D3DX_DEFAULT, // default height
- D3DX_DEFAULT, // no mip mapping
- NULL, // regular usage
- D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
- D3DPOOL_MANAGED, // typical memory handling
- D3DX_DEFAULT, // no filtering
- D3DX_DEFAULT, // no mip filtering
- D3DCOLOR_XRGB(255, 255, 255), // the hot-pink color key
- NULL, // no image info struct
- NULL, // not using 256 colors
- &sprite_Score5); // load to sprite
- D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
- L"Score6점.png", // the file name
- D3DX_DEFAULT, // default width
- D3DX_DEFAULT, // default height
- D3DX_DEFAULT, // no mip mapping
- NULL, // regular usage
- D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
- D3DPOOL_MANAGED, // typical memory handling
- D3DX_DEFAULT, // no filtering
- D3DX_DEFAULT, // no mip filtering
- D3DCOLOR_XRGB(255, 255, 255), // the hot-pink color key
- NULL, // no image info struct
- NULL, // not using 256 colors
- &sprite_Score6); // load to sprite
- D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
- L"Score7점.png", // the file name
- D3DX_DEFAULT, // default width
- D3DX_DEFAULT, // default height
- D3DX_DEFAULT, // no mip mapping
- NULL, // regular usage
- D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
- D3DPOOL_MANAGED, // typical memory handling
- D3DX_DEFAULT, // no filtering
- D3DX_DEFAULT, // no mip filtering
- D3DCOLOR_XRGB(255, 255, 255), // the hot-pink color key
- NULL, // no image info struct
- NULL, // not using 256 colors
- &sprite_Score7); // load to sprite
- D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
- L"Score8점.png", // the file name
- D3DX_DEFAULT, // default width
- D3DX_DEFAULT, // default height
- D3DX_DEFAULT, // no mip mapping
- NULL, // regular usage
- D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
- D3DPOOL_MANAGED, // typical memory handling
- D3DX_DEFAULT, // no filtering
- D3DX_DEFAULT, // no mip filtering
- D3DCOLOR_XRGB(255, 255, 255), // the hot-pink color key
- NULL, // no image info struct
- NULL, // not using 256 colors
- &sprite_Score8); // load to sprite
- D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
- L"Score9점.png", // the file name
- D3DX_DEFAULT, // default width
- D3DX_DEFAULT, // default height
- D3DX_DEFAULT, // no mip mapping
- NULL, // regular usage
- D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
- D3DPOOL_MANAGED, // typical memory handling
- D3DX_DEFAULT, // no filtering
- D3DX_DEFAULT, // no mip filtering
- D3DCOLOR_XRGB(255, 255, 255), // the hot-pink color key
- NULL, // no image info struct
- NULL, // not using 256 colors
- &sprite_Score9); // load to sprite
- D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
- L"boom.jpg", // the file name
- D3DX_DEFAULT, // default width
- D3DX_DEFAULT, // default height
- D3DX_DEFAULT, // no mip mapping
- NULL, // regular usage
- D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
- D3DPOOL_MANAGED, // typical memory handling
- D3DX_DEFAULT, // no filtering
- D3DX_DEFAULT, // no mip filtering
- D3DCOLOR_XRGB(255, 255, 255), // the hot-pink color key
- NULL, // no image info struct
- NULL, // not using 256 colors
- &sprite_Boom); // load to sprite
- return;
- }
- void init_game(void)
- {
- //객체 초기화
- hero.init(300, 300);
- //적들 초기화
- for (int i = 0; i<ENEMY_NUM; i++)
- {
- enemy[i].init((float)(rand() % 200-300), (rand() % 350)+150);
- }
- for (int i = 0; i<ENEMY_NUM2; i++)
- {
- flyenemy[i].init((float)(rand() % 200 - 300), rand() % 100);
- }
- //총알 초기화
- bullet.init(hero.x_pos, hero.y_pos);
- boom.init(150, 150);
- }
- void do_game_logic(void)
- {
- //주인공 처리
- if (KEY_DOWN(VK_UP))
- hero.move(MOVE_UP);
- if (KEY_DOWN(VK_DOWN))
- hero.move(MOVE_DOWN);
- if (KEY_DOWN(VK_LEFT))
- hero.move(MOVE_LEFT);
- if (KEY_DOWN(VK_RIGHT))
- hero.move(MOVE_RIGHT);
- //적들 처리
- for (int i = 0; i < ENEMY_NUM; i++)
- {
- if (enemy[i].x_pos > 800)
- enemy[i].init((float)(rand() % 200 - 300), (rand() % 350) + 150);
- else
- enemy[i].move();
- }
- for (int i = 0; i < ENEMY_NUM2; i++)
- {
- if (flyenemy[i].x_pos > 800)
- flyenemy[i].init((float)(rand() % 200 - 300), rand() % 100);
- else
- flyenemy[i].move();
- }
- //총알 처리
- if (bullet.show() == false)
- {
- if (KEY_DOWN(VK_SPACE))
- {
- bullet.active();
- bullet.init(hero.x_pos, hero.y_pos);
- }
- }
- if (boom.show() == false)
- {
- if (KEY_DOWN(VK_SHIFT))
- {
- boom.active();
- boom.init(150, 150);
- }
- }
- if (bullet.show() == true)
- {
- if (bullet.x_pos < -50)
- bullet.hide();
- else
- bullet.move();
- //충돌 처리
- for (int i = 0; i < ENEMY_NUM; i++)
- {
- if (bullet.check_collision(enemy[i].x_pos, enemy[i].y_pos) == true)
- {
- enemy[i].init((float)(rand() % 200 - 300), (rand() % 350) + 150);
- Score++;
- }
- }
- for (int i = 0; i < ENEMY_NUM2; i++)
- {
- if (bullet.check_collision(flyenemy[i].x_pos, flyenemy[i].y_pos) == true)
- {
- flyenemy[i].init((float)(rand() % 200 - 300), rand() % 100);
- Score += 2;
- }
- }
- }
- if (boom.show() == true)
- {
- if (boom.killCount <= 0)
- boom.hide();
- //충돌 처리
- for (int i = 0; i < ENEMY_NUM; i++)
- {
- if (boom.check_collision(enemy[i].x_pos, enemy[i].y_pos) == true)
- {
- enemy[i].init((float)(rand() % 200 - 300), (rand() % 350) + 150);
- Score++;
- boom.killCount--;
- }
- }
- for (int i = 0; i < ENEMY_NUM2; i++)
- {
- if (boom.check_collision(flyenemy[i].x_pos, flyenemy[i].y_pos) == true)
- {
- flyenemy[i].init((float)(rand() % 200 - 300), rand() % 100);
- Score += 2;
- boom.killCount--;
- }
- }
- }
- }
- // this is the function used to render a single frame
- void render_frame(void)
- {
- // clear the window to a deep blue
- d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
- d3ddev->BeginScene(); // begins the 3D scene
- d3dspt->Begin(D3DXSPRITE_ALPHABLEND); // // begin sprite drawing with transparency
- //UI 창 렌더링
- /* static int frame = 21; // start the program on the final frame
- if(KEY_DOWN(VK_SPACE)) frame=0; // when the space key is pressed, start at frame 0
- if(frame < 21) frame++; // if we aren't on the last frame, go to the next frame
- // calculate the x-position
- int xpos = frame * 182 + 1;
- RECT part7;
- SetRect(&part7, xpos, 0, xpos + 181, 128);
- D3DXVECTOR3 center7(0.0f, 0.0f, 0.0f); // center at the upper-left corner
- D3DXVECTOR3 position7(150.0f, 50.0f, 0.0f); // position at 50, 50 with no depth
- d3dspt->Draw(sprite, &part7, ¢er7, &position7, D3DCOLOR_ARGB(127, 255, 255, 255));*/
- RECT part3;
- SetRect(&part3, 0, 0, 650, 500);
- D3DXVECTOR3 center3(0.0f, 0.0f, 0.0f); // center at the upper-left corner
- D3DXVECTOR3 position3(0, 0, 0.0f); // position at 50, 50 with no depth
- d3dspt->Draw(sprite_bg, &part3, ¢er3, &position3, D3DCOLOR_ARGB(255, 255, 255, 255));
- //주인공
- RECT part;
- SetRect(&part, 0, 0, 64, 64);
- D3DXVECTOR3 center(0.0f, 0.0f, 0.0f); // center at the upper-left corner
- D3DXVECTOR3 position(hero.x_pos, hero.y_pos, 0.0f); // position at 50, 50 with no depth
- d3dspt->Draw(sprite_hero, &part, ¢er, &position, D3DCOLOR_ARGB(255, 255, 255, 255));
- ////총알
- if (bullet.bShow == true)
- {
- RECT part1;
- SetRect(&part1, 0, 0, 64, 64);
- D3DXVECTOR3 center1(0.0f, 0.0f, 0.0f); // center at the upper-left corner
- D3DXVECTOR3 position1(bullet.x_pos, bullet.y_pos, 0.0f); // position at 50, 50 with no depth
- d3dspt->Draw(sprite_bullet, &part1, ¢er1, &position1, D3DCOLOR_ARGB(255, 255, 255, 255));
- }
- if (boom.bShow == true)
- {
- RECT part7;
- SetRect(&part7, 0, 0,256, 256);
- D3DXVECTOR3 center7(0.0f, 0.0f, 0.0f); // center at the upper-left corner
- D3DXVECTOR3 position7(150, 150, 0.0f); // position at 50, 50 with no depth
- d3dspt->Draw(sprite_Boom, &part7, ¢er7, &position7, D3DCOLOR_ARGB(255, 255, 255, 255));
- }
- ////에네미
- RECT part2;
- SetRect(&part2, 0, 0, 64, 64);
- D3DXVECTOR3 center2(0.0f, 0.0f, 0.0f); // center at the upper-left corner
- for (int i = 0; i<ENEMY_NUM; i++)
- {
- D3DXVECTOR3 position2(enemy[i].x_pos, enemy[i].y_pos, 0.0f); // position at 50, 50 with no depth
- d3dspt->Draw(sprite_enemy, &part2, ¢er2, &position2, D3DCOLOR_ARGB(255, 255, 255, 255));
- }
- RECT part4;
- SetRect(&part4, 0, 0, 64, 64);
- D3DXVECTOR3 center4(0.0f, 0.0f, 0.0f); // center at the upper-left corner
- for (int i = 0; i<ENEMY_NUM2; i++)
- {
- D3DXVECTOR3 position4(flyenemy[i].x_pos, flyenemy[i].y_pos, 0.0f); // position at 50, 50 with no depth
- d3dspt->Draw(sprite_flyenemy, &part4, ¢er4, &position4, D3DCOLOR_ARGB(255, 255, 255, 255));
- }
- RECT part5;//10의 자리
- SetRect(&part, 0, 0, 64, 64);
- D3DXVECTOR3 center5(0.0f, 0.0f, 0.0f); // center at the upper-left corner
- D3DXVECTOR3 position5(10, 10, 0.0f); // position at 50, 50 with no depth
- if (Score / 10 == 0) {
- d3dspt->Draw(sprite_Score0, &part, ¢er5, &position5, D3DCOLOR_ARGB(255, 255, 255, 255));
- }
- if (Score / 10 == 1) {
- d3dspt->Draw(sprite_Score1, &part, ¢er5, &position5, D3DCOLOR_ARGB(255, 255, 255, 255));
- }
- if (Score / 10 == 2) {
- d3dspt->Draw(sprite_Score2, &part, ¢er5, &position5, D3DCOLOR_ARGB(255, 255, 255, 255));
- }
- if (Score / 10 == 3) {
- d3dspt->Draw(sprite_Score3, &part, ¢er5, &position5, D3DCOLOR_ARGB(255, 255, 255, 255));
- }
- if (Score / 10 == 4) {
- d3dspt->Draw(sprite_Score4, &part, ¢er5, &position5, D3DCOLOR_ARGB(255, 255, 255, 255));
- }
- if (Score / 10 == 5) {
- d3dspt->Draw(sprite_Score5, &part, ¢er5, &position5, D3DCOLOR_ARGB(255, 255, 255, 255));
- }
- if (Score / 10 == 6) {
- d3dspt->Draw(sprite_Score6, &part, ¢er5, &position5, D3DCOLOR_ARGB(255, 255, 255, 255));
- }
- if (Score / 10 == 7) {
- d3dspt->Draw(sprite_Score7, &part, ¢er5, &position5, D3DCOLOR_ARGB(255, 255, 255, 255));
- }
- if (Score / 10 == 8) {
- d3dspt->Draw(sprite_Score8, &part, ¢er5, &position5, D3DCOLOR_ARGB(255, 255, 255, 255));
- }
- if (Score / 10 == 9) {
- d3dspt->Draw(sprite_Score9, &part, ¢er5, &position5, D3DCOLOR_ARGB(255, 255, 255, 255));
- }
- RECT part6;//1의 자리
- SetRect(&part, 0, 0, 64, 64);
- D3DXVECTOR3 center6(0.0f, 0.0f, 0.0f); // center at the upper-left corner
- D3DXVECTOR3 position6(74, 10, 0.0f); // position at 50, 50 with no depth
- if (Score % 10 == 0) {
- d3dspt->Draw(sprite_Score0, &part, ¢er6, &position6, D3DCOLOR_ARGB(255, 255, 255, 255));
- }
- if (Score % 10 == 1) {
- d3dspt->Draw(sprite_Score1, &part, ¢er6, &position6, D3DCOLOR_ARGB(255, 255, 255, 255));
- }
- if (Score % 10 == 2) {
- d3dspt->Draw(sprite_Score2, &part, ¢er6, &position6, D3DCOLOR_ARGB(255, 255, 255, 255));
- }
- if (Score % 10 == 3) {
- d3dspt->Draw(sprite_Score3, &part, ¢er6, &position6, D3DCOLOR_ARGB(255, 255, 255, 255));
- }
- if (Score % 10 == 4) {
- d3dspt->Draw(sprite_Score4, &part, ¢er6, &position6, D3DCOLOR_ARGB(255, 255, 255, 255));
- }
- if (Score % 10 == 5) {
- d3dspt->Draw(sprite_Score5, &part, ¢er6, &position6, D3DCOLOR_ARGB(255, 255, 255, 255));
- }
- if (Score % 10 == 6) {
- d3dspt->Draw(sprite_Score6, &part, ¢er6, &position6, D3DCOLOR_ARGB(255, 255, 255, 255));
- }
- if (Score % 10 == 7) {
- d3dspt->Draw(sprite_Score7, &part, ¢er6, &position6, D3DCOLOR_ARGB(255, 255, 255, 255));
- }
- if (Score % 10 == 8) {
- d3dspt->Draw(sprite_Score8, &part, ¢er6, &position6, D3DCOLOR_ARGB(255, 255, 255, 255));
- }
- if (Score % 10 == 9) {
- d3dspt->Draw(sprite_Score9, &part, ¢er6, &position6, D3DCOLOR_ARGB(255, 255, 255, 255));
- }
- d3dspt->End(); // end sprite drawing
- d3ddev->EndScene(); // ends the 3D scene
- d3ddev->Present(NULL, NULL, NULL, NULL);
- return;
- }
- // this is the function that cleans up Direct3D and COM
- void cleanD3D(void)
- {
- sprite->Release();
- d3ddev->Release();
- d3d->Release();
- //객체 해제
- sprite_hero->Release();
- sprite_enemy->Release();
- sprite_bullet->Release();
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement