• PUDN用户
    了解作者
  • Visual C++
    开发工具
  • 996KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 9
    下载次数
  • 2014-03-29 10:45
    上传日期
基于VC++,Directx开发工具包的3D飞机小游戏,主要功能碰撞检测和图形渲染
Minifly.zip
  • Minifly
  • background.jpg
    216.7KB
  • MiniPlane.h
    445B
  • Minifly.ncb
    121KB
  • Collide.cpp
    2.4KB
  • seafloor.x
    141.6KB
  • CMesh.cpp
    3.9KB
  • VertexBlend.cpp
    9.1KB
  • camera.h
    1.1KB
  • Collide.h
    1.2KB
  • Minifly.dsw
    522B
  • stdafx.h
    1.5KB
  • miniplane.txt
    5.3KB
  • start3.jpg
    11.2KB
  • cloud2.X
    292.3KB
  • GameStart.cpp
    8.4KB
  • airplane.x
    157.5KB
  • bihull.bmp
    65.1KB
  • Picture.cpp
    7.1KB
  • background.cpp
    5.4KB
  • CMesh.h
    1.1KB
  • Picture.h
    2KB
  • Minifly.exe
    396.1KB
  • GameStart.h
    555B
  • helpback.jpg
    28.8KB
  • camera.cpp
    4.9KB
  • start1.jpg
    14KB
  • Object.cpp
    8.4KB
  • guided.X
    113KB
  • help.jpg
    62.4KB
  • guided3.X
    112.8KB
  • cloud4.X
    292.7KB
  • start2.jpg
    11.2KB
  • Simple_Metal_Mtl_DiamondPlate_pattern.jpg
    77.5KB
  • cloud.X
    292.4KB
  • seafloor.bmp
    65.1KB
  • Object.h
    1.9KB
  • wings.bmp
    17.1KB
  • texture.jpg
    38.4KB
  • Minifly.opt
    52.5KB
  • 1.X
    55.8KB
  • Minifly.plg
    248B
  • background.h
    890B
  • start1.bbs
    14KB
  • Minifly.dsp
    4.9KB
  • could3.X
    292.8KB
内容介绍
#include "GameStart.h" CCamera g_Camera; CObject g_Object; CMesh *g_pPlane; CMesh *g_pfloor; CMesh *g_cloud; D3DXMATRIXA16 matWorld[5]; BoundingSphere *g_pCollideShpere; BoundingSphere *g_pCollideplane; LPDIRECT3DVERTEXBUFFER9 g_pVB = NULL; //顶点缓冲区对象 ID3DXFont* g_pFontCount = NULL; RECT rectCount; int count = 0; HRESULT GS_Init(LPDIRECT3DDEVICE9 &g_pd3dDevice) { D3DXVECTOR3 vector; rectCount.right = 450; rectCount.left = 400; rectCount.top = 300; rectCount.bottom = 320; g_cloud = new CMesh[5]; g_pCollideShpere = new BoundingSphere[5]; g_pCollideplane = new BoundingSphere; for (int i = 0 ;i < 5 ; i++) { g_cloud[i].GetDevice(g_pd3dDevice); D3DXMatrixTranslation(&matWorld[i],i*20,0, -i * 40); vector = D3DXVECTOR3(matWorld[i]._41,matWorld[i]._42,matWorld[i]._43); g_pCollideShpere[i].SetBoundingSphere(vector,1.0f); } g_cloud[0].Create("guided3.x"); g_cloud[1].Create("guided3.x"); g_cloud[2].Create("guided3.X"); g_cloud[3].Create("guided3.x"); g_cloud[4].Create("1.x"); //飞机模型 g_pPlane = new CMesh; g_pPlane->GetDevice(g_pd3dDevice); g_pPlane->Create("airplane.x"); g_Object.SetVelocity(0,0,-6.0f); //if(FAILED(g_Object.SetVertice(g_pd3dDevice, 5.1f , 4.0f , 1.3f ,0x00ff8844))) if(FAILED(g_Object.SetVertice(g_pd3dDevice, 4.5f ,0x00ff8844))) { return E_FAIL; } vector = g_Object.GetPosition(); g_pCollideplane->SetBoundingSphere(vector,5.0f); g_pfloor = new CMesh; g_pfloor->GetDevice(g_pd3dDevice); g_pfloor->Create("seafloor.x"); if(FAILED(D3DXCreateFont(g_pd3dDevice,15,15,0,0,0,0,0,0,0,"Arial",&g_pFontCount))) return E_FAIL; //创建坐标缓冲区 CUSTOMVERTEX vertices[] = { { -40.0f,-10.0f,0.0f, 0x00ff0000, }, { 40.0f, -10.0f,0.0f, 0x00ff0000, }, { -40.0f,-10.0f,0.0f, 0x0000ff00, }, { -40.0f, 30.0f,0.0f, 0x0000ff00, }, { -40.0f,30.0f,0.0f, 0x000000ff, }, { 40.0f, 30.0f,0.0f, 0x000000ff, }, { 40.0f, 30.0f,0.0f, 0x0000ffff, }, { 40.0f,-10.0f,0.0f, 0x0000ffff, } }; if( FAILED( g_pd3dDevice->CreateVertexBuffer(8*sizeof(CUSTOMVERTEX), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL ) ) ) { return E_FAIL; } //填充顶点缓冲区 VOID* pVertices; if( FAILED( g_pVB->Lock( 0, sizeof(vertices), (void**)&pVertices, 0 ) ) ) return E_FAIL; memcpy( pVertices, vertices, sizeof(vertices) ); g_pVB->Unlock(); return S_OK; } void GS_Render(LPDIRECT3DDEVICE9 &g_pd3dDevice) { GS_UpDate(); D3DXMATRIXA16 matW; for (int i = 0 ; i < 5 ;i++) { g_pd3dDevice->SetTransform(D3DTS_WORLD, &matWorld[i]); g_cloud[i].Render(); } //显示地板 D3DXMatrixTranslation(&matW,0,0, 0); g_pd3dDevice->SetTransform( D3DTS_WORLD, &matW); g_pfloor->Render(); //显示飞机 //g_Object.m_ShowCollider = false; //是否显示碰撞框架 g_Object.UpDate(g_pd3dDevice,0.01f); g_pPlane->Render(); //显示碰撞次数 char strText [20]; int charcount = sprintf(strText,"Count:%d",count); g_pFontCount->DrawText(NULL, strText, charcount, &rectCount, DT_SINGLELINE|DT_NOCLIP|DT_CENTER|DT_VCENTER, 0xff00ffff); g_Camera.UpData(g_pd3dDevice); //显示边框 g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, false); D3DXMATRIXA16 matWorld; D3DXVECTOR3 objectpos = g_Object.GetPosition(); D3DXMatrixTranslation(&matWorld,0, 0, objectpos.z); g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld); g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX ); g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(CUSTOMVERTEX) ); g_pd3dDevice->DrawPrimitive( D3DPT_LINELIST, 0, 4 ); } void GS_UpDate() { g_pCollideplane->ReplaceCentre(g_Object.GetPosition()); D3DXVECTOR3 camerapos = g_Camera.GetCameraPos(); srand((unsigned)time(NULL) * 10); for(int i = 0; i < 5 ; i++) { if((camerapos.z - matWorld[i]._43) < -60) { if(rand()%2 == 1) matWorld[i]._41 = rand() % 50 + i*10; else matWorld[i]._41 = -rand() % 50 - i*10; matWorld[i]._43 = camerapos.z - 200; } matWorld[i]._43 += 0.1; //碰撞检测及其相应的操作 g_pCollideShpere[i].ReplaceCentre(matWorld[i]); if(g_pCollideShpere[i].Overlaps(g_pCollideplane)) { count++; if(rand()%2 == 1) matWorld[i]._41 = rand() % 50 + i*10; else matWorld[i]._41 = -rand() % 50 - i*10; matWorld[i]._43 = camerapos.z - 200; } } g_Camera.GetLinkPosition(g_Object.GetPosition()); /* D3DXVECTOR3 pos = g_Object.GetPosition(); if(pos.y < -10) { MessageBox(NULL, "飞机坠毁", "massage" , MB_OK); exit(0); } */ } void GS_Clean() { if(g_pFontCount!=NULL) g_pFontCount->Release(); //释放顶点缓冲区对象 if( g_pVB != NULL ) g_pVB->Release(); for (int i = 0 ;i < 5 ; i++) { g_cloud[i].Destory(); } delete [] g_cloud; delete [] g_pCollideShpere; delete g_pCollideplane; } void GS_Reset() { } LRESULT GS_MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { switch( msg ) { case WM_KEYDOWN: g_Object.m_key[wParam] = 1; break; case WM_KEYUP: g_Object.m_key[wParam] = 0; break; } g_Camera.MsgProc( hWnd, msg, wParam, lParam ); return FALSE; }
评论
    相关推荐
    • RobotInScreen.rar
      这是一个采用OpenGL写的机器人在给定场所中运动,代码中实现了碰撞检测跟鼠标键盘事件驱动
    • BallTest.rar
      简单的碰撞检测程序源代码及演示,包含vc 2005 工程项目.
    • Collision-detection-program.zip
      VC编写的碰撞检测代码,非常有用的碰撞检测程序
    • collision-detection.rar
      用VC++编写的碰撞检测程序,同时也适用于多边形的碰撞问题
    • Collision-detection.rar
      基于VC++和OpenGL的碰撞检测程序,能够准确检测环境中的碰撞情况
    • Planets 2.rar
      VC++碰撞检测,如何判断两个运动中的物体已碰触,这在游戏应用中想当广泛
    • 4241326.rar
      简单的碰撞检测程序源代码及演示,包含vc 2005 工程项目.不错的
    • VC++碰撞检测,如何判断两个运动中的物体已碰触
      摘要:VC/C++源码,图形处理,碰撞检测 VC++碰撞检测,如何判断两个运动中的物体已碰触,这在游戏应用中想当广泛,在本例中,不管是物体自行运动或是用鼠标拖动他们,你会发现,他们都不能碰撞在一起,在距离非常近的...
    • opengl3d漫游引擎碰撞检测VC源码
      VC6.0源码,支持3D场景漫游和碰撞检测
    • llk.rar
      JavaScript 连连看游戏代码,相信大家对连连看游戏并不陌生,编程爱好者用vb、VC/DELPHI都编写过这款游戏,...里面有一些游戏控制的写法值得参考,比如记录图片位置、画线、碰撞检测、打乱次序、一些更细节的计算等。