Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.14 KB | None | 0 0
  1. // include the basic windows header files and the Direct3D header file
  2. #include <windows.h>
  3. #include <windowsx.h>
  4. #include <d3d9.h>
  5. #include <d3dx9.h>
  6. #include <iostream>
  7.  
  8. // define the screen resolution and keyboard macros
  9. #define SCREEN_WIDTH 640
  10. #define SCREEN_HEIGHT 480
  11. #define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
  12. #define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)
  13.  
  14. #define ENEMY_NUM 10
  15. #define ENEMY_NUM2 3
  16.  
  17. int Score = 0;
  18.  
  19. // include the Direct3D Library file
  20. #pragma comment (lib, "d3d9.lib")
  21. #pragma comment (lib, "d3dx9.lib")
  22.  
  23. // global declarations
  24. LPDIRECT3D9 d3d; // the pointer to our Direct3D interface
  25. LPDIRECT3DDEVICE9 d3ddev; // the pointer to the device class
  26. LPD3DXSPRITE d3dspt; // the pointer to our Direct3D Sprite interface
  27.  
  28.  
  29.  
  30. // sprite declarations
  31. LPDIRECT3DTEXTURE9 sprite; // the pointer to the sprite
  32. LPDIRECT3DTEXTURE9 sprite_hero; // the pointer to the sprite
  33. LPDIRECT3DTEXTURE9 sprite_enemy; // the pointer to the sprite
  34. LPDIRECT3DTEXTURE9 sprite_bullet; // the pointer to the sprite
  35. LPDIRECT3DTEXTURE9 sprite_bg;
  36. LPDIRECT3DTEXTURE9 sprite_flyenemy;
  37. LPDIRECT3DTEXTURE9 sprite_Score0;
  38. LPDIRECT3DTEXTURE9 sprite_Score1;
  39. LPDIRECT3DTEXTURE9 sprite_Score2;
  40. LPDIRECT3DTEXTURE9 sprite_Score3;
  41. LPDIRECT3DTEXTURE9 sprite_Score4;
  42. LPDIRECT3DTEXTURE9 sprite_Score5;
  43. LPDIRECT3DTEXTURE9 sprite_Score6;
  44. LPDIRECT3DTEXTURE9 sprite_Score7;
  45. LPDIRECT3DTEXTURE9 sprite_Score8;
  46. LPDIRECT3DTEXTURE9 sprite_Score9;
  47. LPDIRECT3DTEXTURE9 sprite_Boom;
  48.  
  49.  
  50.  
  51.  
  52. // function prototypes
  53. void initD3D(HWND hWnd); // sets up and initializes Direct3D
  54. void render_frame(void); // renders a single frame
  55. void cleanD3D(void); // closes Direct3D and releases memory
  56.  
  57. void init_game(void);
  58. void do_game_logic(void);
  59. bool sphere_collision_check(float x0, float y0, float size0, float x1, float y1, float size1);
  60.  
  61.  
  62. // the WindowProc function prototype
  63. LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
  64.  
  65. using namespace std;
  66.  
  67.  
  68. enum { MOVE_UP, MOVE_DOWN, MOVE_LEFT, MOVE_RIGHT };
  69.  
  70.  
  71. //기본 클래스
  72. class entity {
  73.  
  74. public:
  75. float x_pos;
  76. float y_pos;
  77. int status;
  78. int HP;
  79.  
  80. };
  81.  
  82.  
  83. bool sphere_collision_check(float x0, float y0, float size0, float x1, float y1, float size1)
  84. {
  85.  
  86. if ((x0 - x1)*(x0 - x1) + (y0 - y1)*(y0 - y1) < (size0 + size1) * (size0 + size1))
  87. return true;
  88. else
  89. return false;
  90.  
  91. }
  92.  
  93.  
  94.  
  95. //주인공 클래스
  96. class Hero :public entity {
  97.  
  98. public:
  99. void fire();
  100. void super_fire();
  101. void move(int i);
  102. void init(float x, float y);
  103.  
  104.  
  105. };
  106.  
  107. void Hero::init(float x, float y)
  108. {
  109.  
  110. x_pos = x;
  111. y_pos = y;
  112.  
  113. }
  114.  
  115. void Hero::move(int i)
  116. {
  117. switch (i)
  118. {
  119. case MOVE_UP:
  120. y_pos -= 3;
  121. break;
  122.  
  123. case MOVE_DOWN:
  124. y_pos += 3;
  125. break;
  126.  
  127.  
  128. case MOVE_LEFT:
  129. x_pos -= 3;
  130. break;
  131.  
  132.  
  133. case MOVE_RIGHT:
  134. x_pos += 3;
  135. break;
  136.  
  137. }
  138.  
  139. }
  140.  
  141.  
  142.  
  143.  
  144. // 적 클래스
  145. class Enemy :public entity {
  146.  
  147. public:
  148. void fire();
  149. void init(float x, float y);
  150. void move();
  151.  
  152. };
  153.  
  154. void Enemy::init(float x, float y)
  155. {
  156.  
  157. x_pos = x;
  158. y_pos = y;
  159.  
  160. }
  161.  
  162.  
  163. void Enemy::move()
  164. {
  165. x_pos += 2;
  166.  
  167. }
  168.  
  169. class FlyEnemy :public entity {
  170.  
  171. public:
  172. void fire();
  173. void init(float x, float y);
  174. void move();
  175. int hp = 2;
  176. };
  177.  
  178. void FlyEnemy::init(float x, float y)
  179. {
  180.  
  181. x_pos = x;
  182. y_pos = y;
  183.  
  184. }
  185.  
  186.  
  187. void FlyEnemy::move()
  188. {
  189. x_pos += 3;
  190.  
  191. }
  192.  
  193.  
  194.  
  195.  
  196. // 총알 클래스
  197. class Bullet :public entity {
  198.  
  199. public:
  200. bool bShow;
  201.  
  202. void init(float x, float y);
  203. void move();
  204. bool show();
  205. void hide();
  206. void active();
  207. bool check_collision(float x, float y);
  208.  
  209.  
  210. };
  211.  
  212.  
  213. bool Bullet::check_collision(float x, float y)
  214. {
  215.  
  216. //충돌 처리 시
  217. if (sphere_collision_check(x_pos, y_pos, 32, x, y, 32) == true)
  218. {
  219. bShow = false;
  220. return true;
  221.  
  222. }
  223. else {
  224.  
  225. return false;
  226. }
  227. }
  228.  
  229.  
  230.  
  231.  
  232. void Bullet::init(float x, float y)
  233. {
  234. x_pos = x;
  235. y_pos = y;
  236.  
  237. }
  238.  
  239.  
  240.  
  241. bool Bullet::show()
  242. {
  243. return bShow;
  244.  
  245. }
  246.  
  247.  
  248. void Bullet::active()
  249. {
  250. bShow = true;
  251.  
  252. }
  253.  
  254.  
  255.  
  256. void Bullet::move()
  257. {
  258. x_pos -= 8;
  259. }
  260.  
  261. void Bullet::hide()
  262. {
  263. bShow = false;
  264.  
  265. }
  266.  
  267.  
  268. class Boom :public entity {
  269.  
  270. public:
  271. bool bShow;
  272.  
  273. void init(float x, float y);
  274. bool show();
  275. void hide();
  276. void active();
  277. bool check_collision(float x, float y);
  278. int killCount=20;
  279.  
  280. };
  281.  
  282.  
  283. bool Boom::check_collision(float x, float y)
  284. {
  285.  
  286. //충돌 처리 시
  287. if (sphere_collision_check(x_pos, y_pos, 128, x, y,128) == true)
  288. {
  289. bShow = true;
  290. return true;
  291.  
  292. }
  293. else {
  294.  
  295. return false;
  296. }
  297. }
  298.  
  299.  
  300.  
  301.  
  302. void Boom::init(float x, float y)
  303. {
  304. x_pos = x;
  305. y_pos = y;
  306.  
  307. }
  308.  
  309.  
  310.  
  311. bool Boom::show()
  312. {
  313. return bShow;
  314.  
  315. }
  316.  
  317.  
  318. void Boom::active()
  319. {
  320. bShow = true;
  321.  
  322. }
  323.  
  324. void Boom::hide()
  325. {
  326. if (killCount <= 0) {
  327. bShow = false;
  328. }
  329.  
  330. }
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337. //객체 생성
  338. Hero hero;
  339. Enemy enemy[ENEMY_NUM];
  340. FlyEnemy flyenemy[ENEMY_NUM2];
  341. Bullet bullet;
  342. Boom boom;
  343.  
  344.  
  345.  
  346. // the entry point for any Windows program
  347. int WINAPI WinMain(HINSTANCE hInstance,
  348. HINSTANCE hPrevInstance,
  349. LPSTR lpCmdLine,
  350. int nCmdShow)
  351. {
  352. HWND hWnd;
  353. WNDCLASSEX wc;
  354.  
  355. ZeroMemory(&wc, sizeof(WNDCLASSEX));
  356.  
  357. wc.cbSize = sizeof(WNDCLASSEX);
  358. wc.style = CS_HREDRAW | CS_VREDRAW;
  359. wc.lpfnWndProc = (WNDPROC)WindowProc;
  360. wc.hInstance = hInstance;
  361. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  362. wc.lpszClassName = L"WindowClass";
  363.  
  364. RegisterClassEx(&wc);
  365.  
  366. hWnd = CreateWindowEx(NULL, L"WindowClass", L"Our Direct3D Program",
  367. WS_EX_TOPMOST | WS_POPUP, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
  368. NULL, NULL, hInstance, NULL);
  369.  
  370. ShowWindow(hWnd, nCmdShow);
  371.  
  372. // set up and initialize Direct3D
  373. initD3D(hWnd);
  374.  
  375.  
  376. //게임 오브젝트 초기화
  377. init_game();
  378.  
  379. // enter the main loop:
  380.  
  381. MSG msg;
  382.  
  383. while (TRUE)
  384. {
  385. DWORD starting_point = GetTickCount();
  386.  
  387. if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  388. {
  389. if (msg.message == WM_QUIT)
  390. break;
  391.  
  392. TranslateMessage(&msg);
  393. DispatchMessage(&msg);
  394. }
  395.  
  396. do_game_logic();
  397.  
  398. render_frame();
  399.  
  400. // check the 'escape' key
  401. if (KEY_DOWN(VK_ESCAPE))
  402. PostMessage(hWnd, WM_DESTROY, 0, 0);
  403.  
  404.  
  405.  
  406.  
  407. while ((GetTickCount() - starting_point) < 25);
  408. }
  409.  
  410. // clean up DirectX and COM
  411. cleanD3D();
  412.  
  413. return msg.wParam;
  414. }
  415.  
  416.  
  417. // this is the main message handler for the program
  418. LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  419. {
  420. switch (message)
  421. {
  422. case WM_DESTROY:
  423. {
  424. PostQuitMessage(0);
  425. return 0;
  426. } break;
  427. }
  428.  
  429. return DefWindowProc(hWnd, message, wParam, lParam);
  430. }
  431.  
  432.  
  433. // this function initializes and prepares Direct3D for use
  434. void initD3D(HWND hWnd)
  435. {
  436. d3d = Direct3DCreate9(D3D_SDK_VERSION);
  437.  
  438. D3DPRESENT_PARAMETERS d3dpp;
  439.  
  440. ZeroMemory(&d3dpp, sizeof(d3dpp));
  441. d3dpp.Windowed = TRUE;
  442. d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
  443. d3dpp.hDeviceWindow = hWnd;
  444. d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
  445. d3dpp.BackBufferWidth = SCREEN_WIDTH;
  446. d3dpp.BackBufferHeight = SCREEN_HEIGHT;
  447.  
  448.  
  449. // create a device class using this information and the info from the d3dpp stuct
  450. d3d->CreateDevice(D3DADAPTER_DEFAULT,
  451. D3DDEVTYPE_HAL,
  452. hWnd,
  453. D3DCREATE_SOFTWARE_VERTEXPROCESSING,
  454. &d3dpp,
  455. &d3ddev);
  456.  
  457. D3DXCreateSprite(d3ddev, &d3dspt); // create the Direct3D Sprite object
  458.  
  459. D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
  460. L"Panel3.png", // the file name
  461. D3DX_DEFAULT, // default width
  462. D3DX_DEFAULT, // default height
  463. D3DX_DEFAULT, // no mip mapping
  464. NULL, // regular usage
  465. D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
  466. D3DPOOL_MANAGED, // typical memory handling
  467. D3DX_DEFAULT, // no filtering
  468. D3DX_DEFAULT, // no mip filtering
  469. D3DCOLOR_XRGB(255, 0, 255), // the hot-pink color key
  470. NULL, // no image info struct
  471. NULL, // not using 256 colors
  472. &sprite); // load to sprite
  473.  
  474.  
  475. D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
  476. L"hero.png", // the file name
  477. D3DX_DEFAULT, // default width
  478. D3DX_DEFAULT, // default height
  479. D3DX_DEFAULT, // no mip mapping
  480. NULL, // regular usage
  481. D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
  482. D3DPOOL_MANAGED, // typical memory handling
  483. D3DX_DEFAULT, // no filtering
  484. D3DX_DEFAULT, // no mip filtering
  485. D3DCOLOR_XRGB(255, 255, 255), // the hot-pink color key
  486. NULL, // no image info struct
  487. NULL, // not using 256 colors
  488. &sprite_hero); // load to sprite
  489.  
  490. D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
  491. L"cow.png", // the file name
  492. D3DX_DEFAULT, // default width
  493. D3DX_DEFAULT, // default height
  494. D3DX_DEFAULT, // no mip mapping
  495. NULL, // regular usage
  496. D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
  497. D3DPOOL_MANAGED, // typical memory handling
  498. D3DX_DEFAULT, // no filtering
  499. D3DX_DEFAULT, // no mip filtering
  500. D3DCOLOR_XRGB(255, 255, 255), // the hot-pink color key
  501. NULL, // no image info struct
  502. NULL, // not using 256 colors
  503. &sprite_enemy); // load to sprite
  504.  
  505. D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
  506. L"crow.png", // the file name
  507. D3DX_DEFAULT, // default width
  508. D3DX_DEFAULT, // default height
  509. D3DX_DEFAULT, // no mip mapping
  510. NULL, // regular usage
  511. D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
  512. D3DPOOL_MANAGED, // typical memory handling
  513. D3DX_DEFAULT, // no filtering
  514. D3DX_DEFAULT, // no mip filtering
  515. D3DCOLOR_XRGB(255, 255, 255), // the hot-pink color key
  516. NULL, // no image info struct
  517. NULL, // not using 256 colors
  518. &sprite_flyenemy); // load to sprite
  519.  
  520. D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
  521. L"bullet.png", // the file name
  522. D3DX_DEFAULT, // default width
  523. D3DX_DEFAULT, // default height
  524. D3DX_DEFAULT, // no mip mapping
  525. NULL, // regular usage
  526. D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
  527. D3DPOOL_MANAGED, // typical memory handling
  528. D3DX_DEFAULT, // no filtering
  529. D3DX_DEFAULT, // no mip filtering
  530. D3DCOLOR_XRGB(255, 0, 255), // the hot-pink color key
  531. NULL, // no image info struct
  532. NULL, // not using 256 colors
  533. &sprite_bullet); // load to sprite
  534.  
  535. D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
  536. L"bg.png", // the file name
  537. D3DX_DEFAULT, // default width
  538. D3DX_DEFAULT, // default height
  539. D3DX_DEFAULT, // no mip mapping
  540. NULL, // regular usage
  541. D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
  542. D3DPOOL_MANAGED, // typical memory handling
  543. D3DX_DEFAULT, // no filtering
  544. D3DX_DEFAULT, // no mip filtering
  545. D3DCOLOR_XRGB(255, 0, 255), // the hot-pink color key
  546. NULL, // no image info struct
  547. NULL, // not using 256 colors
  548. &sprite_bg); // load to sprite
  549.  
  550. D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
  551. L"Score0점.png", // the file name
  552. D3DX_DEFAULT, // default width
  553. D3DX_DEFAULT, // default height
  554. D3DX_DEFAULT, // no mip mapping
  555. NULL, // regular usage
  556. D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
  557. D3DPOOL_MANAGED, // typical memory handling
  558. D3DX_DEFAULT, // no filtering
  559. D3DX_DEFAULT, // no mip filtering
  560. D3DCOLOR_XRGB(255, 255, 255), // the hot-pink color key
  561. NULL, // no image info struct
  562. NULL, // not using 256 colors
  563. &sprite_Score0); // load to sprite
  564.  
  565. D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
  566. L"Score1점.png", // the file name
  567. D3DX_DEFAULT, // default width
  568. D3DX_DEFAULT, // default height
  569. D3DX_DEFAULT, // no mip mapping
  570. NULL, // regular usage
  571. D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
  572. D3DPOOL_MANAGED, // typical memory handling
  573. D3DX_DEFAULT, // no filtering
  574. D3DX_DEFAULT, // no mip filtering
  575. D3DCOLOR_XRGB(255, 255, 255), // the hot-pink color key
  576. NULL, // no image info struct
  577. NULL, // not using 256 colors
  578. &sprite_Score1); // load to sprite
  579.  
  580. D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
  581. L"Score2점.png", // the file name
  582. D3DX_DEFAULT, // default width
  583. D3DX_DEFAULT, // default height
  584. D3DX_DEFAULT, // no mip mapping
  585. NULL, // regular usage
  586. D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
  587. D3DPOOL_MANAGED, // typical memory handling
  588. D3DX_DEFAULT, // no filtering
  589. D3DX_DEFAULT, // no mip filtering
  590. D3DCOLOR_XRGB(255, 255, 255), // the hot-pink color key
  591. NULL, // no image info struct
  592. NULL, // not using 256 colors
  593. &sprite_Score2); // load to sprite
  594.  
  595. D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
  596. L"Score3점.png", // the file name
  597. D3DX_DEFAULT, // default width
  598. D3DX_DEFAULT, // default height
  599. D3DX_DEFAULT, // no mip mapping
  600. NULL, // regular usage
  601. D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
  602. D3DPOOL_MANAGED, // typical memory handling
  603. D3DX_DEFAULT, // no filtering
  604. D3DX_DEFAULT, // no mip filtering
  605. D3DCOLOR_XRGB(255, 255, 255), // the hot-pink color key
  606. NULL, // no image info struct
  607. NULL, // not using 256 colors
  608. &sprite_Score3); // load to sprite
  609.  
  610. D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
  611. L"Score4점.png", // the file name
  612. D3DX_DEFAULT, // default width
  613. D3DX_DEFAULT, // default height
  614. D3DX_DEFAULT, // no mip mapping
  615. NULL, // regular usage
  616. D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
  617. D3DPOOL_MANAGED, // typical memory handling
  618. D3DX_DEFAULT, // no filtering
  619. D3DX_DEFAULT, // no mip filtering
  620. D3DCOLOR_XRGB(255, 255, 255), // the hot-pink color key
  621. NULL, // no image info struct
  622. NULL, // not using 256 colors
  623. &sprite_Score4); // load to sprite
  624.  
  625. D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
  626. L"Score5점.png", // the file name
  627. D3DX_DEFAULT, // default width
  628. D3DX_DEFAULT, // default height
  629. D3DX_DEFAULT, // no mip mapping
  630. NULL, // regular usage
  631. D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
  632. D3DPOOL_MANAGED, // typical memory handling
  633. D3DX_DEFAULT, // no filtering
  634. D3DX_DEFAULT, // no mip filtering
  635. D3DCOLOR_XRGB(255, 255, 255), // the hot-pink color key
  636. NULL, // no image info struct
  637. NULL, // not using 256 colors
  638. &sprite_Score5); // load to sprite
  639.  
  640. D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
  641. L"Score6점.png", // the file name
  642. D3DX_DEFAULT, // default width
  643. D3DX_DEFAULT, // default height
  644. D3DX_DEFAULT, // no mip mapping
  645. NULL, // regular usage
  646. D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
  647. D3DPOOL_MANAGED, // typical memory handling
  648. D3DX_DEFAULT, // no filtering
  649. D3DX_DEFAULT, // no mip filtering
  650. D3DCOLOR_XRGB(255, 255, 255), // the hot-pink color key
  651. NULL, // no image info struct
  652. NULL, // not using 256 colors
  653. &sprite_Score6); // load to sprite
  654.  
  655. D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
  656. L"Score7점.png", // the file name
  657. D3DX_DEFAULT, // default width
  658. D3DX_DEFAULT, // default height
  659. D3DX_DEFAULT, // no mip mapping
  660. NULL, // regular usage
  661. D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
  662. D3DPOOL_MANAGED, // typical memory handling
  663. D3DX_DEFAULT, // no filtering
  664. D3DX_DEFAULT, // no mip filtering
  665. D3DCOLOR_XRGB(255, 255, 255), // the hot-pink color key
  666. NULL, // no image info struct
  667. NULL, // not using 256 colors
  668. &sprite_Score7); // load to sprite
  669.  
  670. D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
  671. L"Score8점.png", // the file name
  672. D3DX_DEFAULT, // default width
  673. D3DX_DEFAULT, // default height
  674. D3DX_DEFAULT, // no mip mapping
  675. NULL, // regular usage
  676. D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
  677. D3DPOOL_MANAGED, // typical memory handling
  678. D3DX_DEFAULT, // no filtering
  679. D3DX_DEFAULT, // no mip filtering
  680. D3DCOLOR_XRGB(255, 255, 255), // the hot-pink color key
  681. NULL, // no image info struct
  682. NULL, // not using 256 colors
  683. &sprite_Score8); // load to sprite
  684.  
  685. D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
  686. L"Score9점.png", // the file name
  687. D3DX_DEFAULT, // default width
  688. D3DX_DEFAULT, // default height
  689. D3DX_DEFAULT, // no mip mapping
  690. NULL, // regular usage
  691. D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
  692. D3DPOOL_MANAGED, // typical memory handling
  693. D3DX_DEFAULT, // no filtering
  694. D3DX_DEFAULT, // no mip filtering
  695. D3DCOLOR_XRGB(255, 255, 255), // the hot-pink color key
  696. NULL, // no image info struct
  697. NULL, // not using 256 colors
  698. &sprite_Score9); // load to sprite
  699.  
  700. D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
  701. L"boom.jpg", // the file name
  702. D3DX_DEFAULT, // default width
  703. D3DX_DEFAULT, // default height
  704. D3DX_DEFAULT, // no mip mapping
  705. NULL, // regular usage
  706. D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
  707. D3DPOOL_MANAGED, // typical memory handling
  708. D3DX_DEFAULT, // no filtering
  709. D3DX_DEFAULT, // no mip filtering
  710. D3DCOLOR_XRGB(255, 255, 255), // the hot-pink color key
  711. NULL, // no image info struct
  712. NULL, // not using 256 colors
  713. &sprite_Boom); // load to sprite
  714.  
  715. return;
  716. }
  717.  
  718.  
  719. void init_game(void)
  720. {
  721. //객체 초기화
  722. hero.init(300, 300);
  723.  
  724.  
  725. //적들 초기화
  726. for (int i = 0; i<ENEMY_NUM; i++)
  727. {
  728.  
  729. enemy[i].init((float)(rand() % 200-300), (rand() % 350)+150);
  730. }
  731. for (int i = 0; i<ENEMY_NUM2; i++)
  732. {
  733.  
  734. flyenemy[i].init((float)(rand() % 200 - 300), rand() % 100);
  735. }
  736. //총알 초기화
  737. bullet.init(hero.x_pos, hero.y_pos);
  738. boom.init(150, 150);
  739. }
  740.  
  741.  
  742. void do_game_logic(void)
  743. {
  744.  
  745. //주인공 처리
  746. if (KEY_DOWN(VK_UP))
  747. hero.move(MOVE_UP);
  748.  
  749. if (KEY_DOWN(VK_DOWN))
  750. hero.move(MOVE_DOWN);
  751.  
  752. if (KEY_DOWN(VK_LEFT))
  753. hero.move(MOVE_LEFT);
  754.  
  755. if (KEY_DOWN(VK_RIGHT))
  756. hero.move(MOVE_RIGHT);
  757.  
  758.  
  759. //적들 처리
  760. for (int i = 0; i < ENEMY_NUM; i++)
  761. {
  762. if (enemy[i].x_pos > 800)
  763. enemy[i].init((float)(rand() % 200 - 300), (rand() % 350) + 150);
  764. else
  765. enemy[i].move();
  766. }
  767. for (int i = 0; i < ENEMY_NUM2; i++)
  768. {
  769. if (flyenemy[i].x_pos > 800)
  770. flyenemy[i].init((float)(rand() % 200 - 300), rand() % 100);
  771. else
  772. flyenemy[i].move();
  773. }
  774.  
  775.  
  776. //총알 처리
  777. if (bullet.show() == false)
  778. {
  779. if (KEY_DOWN(VK_SPACE))
  780. {
  781. bullet.active();
  782. bullet.init(hero.x_pos, hero.y_pos);
  783. }
  784.  
  785.  
  786. }
  787. if (boom.show() == false)
  788. {
  789. if (KEY_DOWN(VK_SHIFT))
  790. {
  791. boom.active();
  792. boom.init(150, 150);
  793. }
  794.  
  795.  
  796. }
  797. if (bullet.show() == true)
  798. {
  799. if (bullet.x_pos < -50)
  800. bullet.hide();
  801. else
  802. bullet.move();
  803.  
  804.  
  805. //충돌 처리
  806. for (int i = 0; i < ENEMY_NUM; i++)
  807. {
  808. if (bullet.check_collision(enemy[i].x_pos, enemy[i].y_pos) == true)
  809. {
  810. enemy[i].init((float)(rand() % 200 - 300), (rand() % 350) + 150);
  811. Score++;
  812. }
  813. }
  814. for (int i = 0; i < ENEMY_NUM2; i++)
  815. {
  816. if (bullet.check_collision(flyenemy[i].x_pos, flyenemy[i].y_pos) == true)
  817. {
  818.  
  819. flyenemy[i].init((float)(rand() % 200 - 300), rand() % 100);
  820. Score += 2;
  821.  
  822. }
  823. }
  824. }
  825. if (boom.show() == true)
  826. {
  827. if (boom.killCount <= 0)
  828. boom.hide();
  829.  
  830. //충돌 처리
  831. for (int i = 0; i < ENEMY_NUM; i++)
  832. {
  833. if (boom.check_collision(enemy[i].x_pos, enemy[i].y_pos) == true)
  834. {
  835. enemy[i].init((float)(rand() % 200 - 300), (rand() % 350) + 150);
  836. Score++;
  837. boom.killCount--;
  838. }
  839. }
  840. for (int i = 0; i < ENEMY_NUM2; i++)
  841. {
  842. if (boom.check_collision(flyenemy[i].x_pos, flyenemy[i].y_pos) == true)
  843. {
  844.  
  845. flyenemy[i].init((float)(rand() % 200 - 300), rand() % 100);
  846. Score += 2;
  847. boom.killCount--;
  848. }
  849. }
  850. }
  851. }
  852.  
  853.  
  854. // this is the function used to render a single frame
  855. void render_frame(void)
  856. {
  857. // clear the window to a deep blue
  858. d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
  859.  
  860. d3ddev->BeginScene(); // begins the 3D scene
  861.  
  862. d3dspt->Begin(D3DXSPRITE_ALPHABLEND); // // begin sprite drawing with transparency
  863.  
  864. //UI 창 렌더링
  865.  
  866.  
  867.  
  868. /* static int frame = 21; // start the program on the final frame
  869. if(KEY_DOWN(VK_SPACE)) frame=0; // when the space key is pressed, start at frame 0
  870. if(frame < 21) frame++; // if we aren't on the last frame, go to the next frame
  871.  
  872. // calculate the x-position
  873. int xpos = frame * 182 + 1;
  874.  
  875. RECT part7;
  876. SetRect(&part7, xpos, 0, xpos + 181, 128);
  877. D3DXVECTOR3 center7(0.0f, 0.0f, 0.0f); // center at the upper-left corner
  878. D3DXVECTOR3 position7(150.0f, 50.0f, 0.0f); // position at 50, 50 with no depth
  879. d3dspt->Draw(sprite, &part7, &center7, &position7, D3DCOLOR_ARGB(127, 255, 255, 255));*/
  880.  
  881.  
  882.  
  883. RECT part3;
  884. SetRect(&part3, 0, 0, 650, 500);
  885. D3DXVECTOR3 center3(0.0f, 0.0f, 0.0f); // center at the upper-left corner
  886. D3DXVECTOR3 position3(0, 0, 0.0f); // position at 50, 50 with no depth
  887. d3dspt->Draw(sprite_bg, &part3, &center3, &position3, D3DCOLOR_ARGB(255, 255, 255, 255));
  888. //주인공
  889. RECT part;
  890. SetRect(&part, 0, 0, 64, 64);
  891. D3DXVECTOR3 center(0.0f, 0.0f, 0.0f); // center at the upper-left corner
  892. D3DXVECTOR3 position(hero.x_pos, hero.y_pos, 0.0f); // position at 50, 50 with no depth
  893. d3dspt->Draw(sprite_hero, &part, &center, &position, D3DCOLOR_ARGB(255, 255, 255, 255));
  894.  
  895.  
  896. ////총알
  897.  
  898. if (bullet.bShow == true)
  899. {
  900. RECT part1;
  901. SetRect(&part1, 0, 0, 64, 64);
  902. D3DXVECTOR3 center1(0.0f, 0.0f, 0.0f); // center at the upper-left corner
  903. D3DXVECTOR3 position1(bullet.x_pos, bullet.y_pos, 0.0f); // position at 50, 50 with no depth
  904. d3dspt->Draw(sprite_bullet, &part1, &center1, &position1, D3DCOLOR_ARGB(255, 255, 255, 255));
  905. }
  906.  
  907. if (boom.bShow == true)
  908. {
  909. RECT part7;
  910. SetRect(&part7, 0, 0,256, 256);
  911. D3DXVECTOR3 center7(0.0f, 0.0f, 0.0f); // center at the upper-left corner
  912. D3DXVECTOR3 position7(150, 150, 0.0f); // position at 50, 50 with no depth
  913. d3dspt->Draw(sprite_Boom, &part7, &center7, &position7, D3DCOLOR_ARGB(255, 255, 255, 255));
  914. }
  915.  
  916.  
  917. ////에네미
  918. RECT part2;
  919. SetRect(&part2, 0, 0, 64, 64);
  920. D3DXVECTOR3 center2(0.0f, 0.0f, 0.0f); // center at the upper-left corner
  921.  
  922. for (int i = 0; i<ENEMY_NUM; i++)
  923. {
  924.  
  925. D3DXVECTOR3 position2(enemy[i].x_pos, enemy[i].y_pos, 0.0f); // position at 50, 50 with no depth
  926. d3dspt->Draw(sprite_enemy, &part2, &center2, &position2, D3DCOLOR_ARGB(255, 255, 255, 255));
  927. }
  928.  
  929. RECT part4;
  930. SetRect(&part4, 0, 0, 64, 64);
  931. D3DXVECTOR3 center4(0.0f, 0.0f, 0.0f); // center at the upper-left corner
  932.  
  933. for (int i = 0; i<ENEMY_NUM2; i++)
  934. {
  935.  
  936. D3DXVECTOR3 position4(flyenemy[i].x_pos, flyenemy[i].y_pos, 0.0f); // position at 50, 50 with no depth
  937. d3dspt->Draw(sprite_flyenemy, &part4, &center4, &position4, D3DCOLOR_ARGB(255, 255, 255, 255));
  938. }
  939. RECT part5;//10의 자리
  940. SetRect(&part, 0, 0, 64, 64);
  941. D3DXVECTOR3 center5(0.0f, 0.0f, 0.0f); // center at the upper-left corner
  942. D3DXVECTOR3 position5(10, 10, 0.0f); // position at 50, 50 with no depth
  943. if (Score / 10 == 0) {
  944. d3dspt->Draw(sprite_Score0, &part, &center5, &position5, D3DCOLOR_ARGB(255, 255, 255, 255));
  945. }
  946. if (Score / 10 == 1) {
  947. d3dspt->Draw(sprite_Score1, &part, &center5, &position5, D3DCOLOR_ARGB(255, 255, 255, 255));
  948. }
  949. if (Score / 10 == 2) {
  950. d3dspt->Draw(sprite_Score2, &part, &center5, &position5, D3DCOLOR_ARGB(255, 255, 255, 255));
  951. }
  952. if (Score / 10 == 3) {
  953. d3dspt->Draw(sprite_Score3, &part, &center5, &position5, D3DCOLOR_ARGB(255, 255, 255, 255));
  954. }
  955. if (Score / 10 == 4) {
  956. d3dspt->Draw(sprite_Score4, &part, &center5, &position5, D3DCOLOR_ARGB(255, 255, 255, 255));
  957. }
  958. if (Score / 10 == 5) {
  959. d3dspt->Draw(sprite_Score5, &part, &center5, &position5, D3DCOLOR_ARGB(255, 255, 255, 255));
  960. }
  961. if (Score / 10 == 6) {
  962. d3dspt->Draw(sprite_Score6, &part, &center5, &position5, D3DCOLOR_ARGB(255, 255, 255, 255));
  963. }
  964. if (Score / 10 == 7) {
  965. d3dspt->Draw(sprite_Score7, &part, &center5, &position5, D3DCOLOR_ARGB(255, 255, 255, 255));
  966. }
  967. if (Score / 10 == 8) {
  968. d3dspt->Draw(sprite_Score8, &part, &center5, &position5, D3DCOLOR_ARGB(255, 255, 255, 255));
  969. }
  970. if (Score / 10 == 9) {
  971. d3dspt->Draw(sprite_Score9, &part, &center5, &position5, D3DCOLOR_ARGB(255, 255, 255, 255));
  972. }
  973. RECT part6;//1의 자리
  974. SetRect(&part, 0, 0, 64, 64);
  975. D3DXVECTOR3 center6(0.0f, 0.0f, 0.0f); // center at the upper-left corner
  976. D3DXVECTOR3 position6(74, 10, 0.0f); // position at 50, 50 with no depth
  977. if (Score % 10 == 0) {
  978. d3dspt->Draw(sprite_Score0, &part, &center6, &position6, D3DCOLOR_ARGB(255, 255, 255, 255));
  979. }
  980. if (Score % 10 == 1) {
  981. d3dspt->Draw(sprite_Score1, &part, &center6, &position6, D3DCOLOR_ARGB(255, 255, 255, 255));
  982. }
  983. if (Score % 10 == 2) {
  984. d3dspt->Draw(sprite_Score2, &part, &center6, &position6, D3DCOLOR_ARGB(255, 255, 255, 255));
  985. }
  986. if (Score % 10 == 3) {
  987. d3dspt->Draw(sprite_Score3, &part, &center6, &position6, D3DCOLOR_ARGB(255, 255, 255, 255));
  988. }
  989. if (Score % 10 == 4) {
  990. d3dspt->Draw(sprite_Score4, &part, &center6, &position6, D3DCOLOR_ARGB(255, 255, 255, 255));
  991. }
  992. if (Score % 10 == 5) {
  993. d3dspt->Draw(sprite_Score5, &part, &center6, &position6, D3DCOLOR_ARGB(255, 255, 255, 255));
  994. }
  995. if (Score % 10 == 6) {
  996. d3dspt->Draw(sprite_Score6, &part, &center6, &position6, D3DCOLOR_ARGB(255, 255, 255, 255));
  997. }
  998. if (Score % 10 == 7) {
  999. d3dspt->Draw(sprite_Score7, &part, &center6, &position6, D3DCOLOR_ARGB(255, 255, 255, 255));
  1000. }
  1001. if (Score % 10 == 8) {
  1002. d3dspt->Draw(sprite_Score8, &part, &center6, &position6, D3DCOLOR_ARGB(255, 255, 255, 255));
  1003. }
  1004. if (Score % 10 == 9) {
  1005. d3dspt->Draw(sprite_Score9, &part, &center6, &position6, D3DCOLOR_ARGB(255, 255, 255, 255));
  1006. }
  1007.  
  1008.  
  1009. d3dspt->End(); // end sprite drawing
  1010.  
  1011. d3ddev->EndScene(); // ends the 3D scene
  1012.  
  1013. d3ddev->Present(NULL, NULL, NULL, NULL);
  1014.  
  1015. return;
  1016. }
  1017.  
  1018.  
  1019. // this is the function that cleans up Direct3D and COM
  1020. void cleanD3D(void)
  1021. {
  1022. sprite->Release();
  1023. d3ddev->Release();
  1024. d3d->Release();
  1025.  
  1026. //객체 해제
  1027. sprite_hero->Release();
  1028. sprite_enemy->Release();
  1029. sprite_bullet->Release();
  1030.  
  1031. return;
  1032. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement