js桌球遊戲源碼,桌球遊戲源碼

本文目錄一覽:

求用C語言模擬簡單桌球運動的源代碼,不需要圖形化界面

這源代碼應該有個桌面類(Table),球類(Sphere),遊戲類等等。我用C++

#pragma once (Table.h)

#endif // _MSC_VER 1000

#include “Base.h”

#define MESH_D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1)

class CTable:public CBase

{

public:

DWORD Render();

CTable(LPDIRECT3DDEVICE8 pD3DDevice,LPSTR pFilename);

virtual ~CTable();

LPD3DXMESH GetMeshTablePointer();

private:

void TransformTable();

LPDIRECT3DDEVICE8 m_pD3DDevice;

DWORD m_dwNumMaterials;

LPD3DXMESH m_pMeshTable;

D3DMATERIAL8 *m_pMeshTableMaterials;

LPDIRECT3DTEXTURE8 *m_pMeshTableTextures;

};#endif

#include “Table.h” (Table.cpp)

CTable::CTable(LPDIRECT3DDEVICE8 pD3DDevice,LPSTR pFilename)

{

LPD3DXBUFFER pMaterialsBuffer=NULL;

LPD3DXMESH pMeshTable=NULL;

m_pD3DDevice=pD3DDevice;

if(FAILED(D3DXLoadMeshFromX(pFilename,D3DXMESH_MANAGED,m_pD3DDevice,NULL,

pMaterialsBuffer,m_dwNumMaterials,pMeshTable)))

{

m_pMeshTable=NULL;

m_pMeshTableMaterials=NULL;

m_pMeshTableTextures=NULL;

LogError(“liTable Mesh ‘%s’ failed to load”,pFilename);

return;

}

D3DXMATERIAL *matMaterials=(D3DXMATERIAL*)pMaterialsBuffer-GetBufferPointer();

//Create two arrays. One to hold the materials and one to hold the textures

m_pMeshTableMaterials=new D3DMATERIAL8[m_dwNumMaterials];

m_pMeshTableTextures=new LPDIRECT3DTEXTURE8[m_dwNumMaterials];

for(DWORD i=0;im_dwNumMaterials;i++)

{

//Copy the material

m_pMeshTableMaterials[i]=matMaterials[i].MatD3D;

//Set the ambient color for the material(D3DX does not do this)

m_pMeshTableMaterials[i].Ambient=m_pMeshTableMaterials[i].Diffuse;

D3DCOLORVALUE rgbaSpecular={0.0f,0.0f,0.0f,0.0f};

m_pMeshTableMaterials[i].Specular=rgbaSpecular;

m_pMeshTableMaterials[i].Power=50.0f;

//Create the texture

char buffer[255];

sprintf(buffer,”textures/%s”,matMaterials[i].pTextureFilename);

if(FAILED(D3DXCreateTextureFromFile(m_pD3DDevice,

buffer, m_pMeshTableTextures[i])))

{

m_pMeshTableTextures[i]=NULL;

}

}

//finished with the material buffer,so release it

SafeRelease(pMaterialsBuffer);

//Make sure that the normals are setup for mesh

pMeshTable-CloneMeshFVF(D3DXMESH_MANAGED,MESH_D3DFVF_CUSTOMVERTEX,m_pD3DDevice,m_pMeshTable);

SafeRelease(pMeshTable);

// D3DXComputeNormals(m_pMesh);

LogInfo(“liMesh ‘%s’ loaded OK”,pFilename);

}

CTable::~CTable()

{

SafeDelete(m_pMeshTableMaterials);

if(m_pMeshTableTextures != NULL)

{

for(DWORD i=0;im_dwNumMaterials;i++)

{

if(m_pMeshTableTextures[i])

SafeRelease(m_pMeshTableTextures[i]);

}

}

SafeDelete(m_pMeshTableTextures);

SafeRelease(m_pMeshTable);

LogInfo(“liTable Mesh destroyed OK”);

}

DWORD CTable::Render()

{

TransformTable();

if(m_pMeshTable!=NULL)

{

for(DWORD i=0;im_dwNumMaterials;i++)

{

m_pD3DDevice-SetMaterial(m_pMeshTableMaterials[i]);

m_pD3DDevice-SetTexture(0,m_pMeshTableTextures[i]);

m_pMeshTable-DrawSubset(i);

}

return m_pMeshTable-GetNumFaces();

}

else

return 0;

}

LPD3DXMESH CTable::GetMeshTablePointer()

{

return m_pMeshTable;

}

void CTable::TransformTable()

{

D3DXMATRIX matWorld;

D3DXMatrixTranslation(matWorld,0,0,0);

m_pD3DDevice-SetTransform(D3DTS_WORLD,matWorld);

}

(Sphere.h)

#if !defined (AFX_SPHERE_H__FC705F3B_568E_4973_B608_B8F7700D9ECE__INCLUDED_)

#define AFX_SPHERE_H__FC705F3B_568E_4973_B608_B8F7700D9ECE__INCLUDED_

#if _MSC_VER 1000

#pragma once

#endif // _MSC_VER 1000

#include “Base.h”

#define SPHERE_D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1)

class CSphere:public CBase

{

private:

struct SPHERE_CUSTOMVERTEX

{

float x,y,z; //Position of vertex in 3D space

float nx,ny,nz; //Lighting Normal

float tu,tv; //Texture coordinates

};

struct SPHERE_STATE

{

D3DXVECTOR3 sVector; //Position of Centigram in 3D space

D3DXVECTOR3 vVector; //Direction of Velocity in 3D space

float v; //Speed of Sphere

};

SPHERE_STATE *m_pSphereState;

D3DXVECTOR3 m_vecSavePosition; //Save sphere position for collision bar

D3DXVECTOR3 m_vecSavePosition2; //Save sphere position for collision sphere

public:

BOOL SetMaterial(D3DCOLORVALUE rgbaDiffuse,D3DCOLORVALUE rgbaAmbient,

D3DCOLORVALUE rgbaSpecular,D3DCOLORVALUE rgbaEmissive,float rPower);

BOOL SetTexture(const char* szTextureFilePath);

DWORD Render();

CSphere(LPDIRECT3DDEVICE8 pD3DDevice,int iRings=20,int iSegments=20);

void MoveSphere();

void MoveSphereForUser(float x,float z);

virtual ~CSphere();

inline void SetSpherePosition(float x,float y,float z)

{

m_pSphereState-sVector.x=x;

m_pSphereState-sVector.y=y;

m_pSphereState-sVector.z=z;

};

inline void GetSpherePosition(D3DXVECTOR3 vecSpherePos)

{

vecSpherePos=m_pSphereState-sVector;

};

inline void GetSavedSpherePosition(D3DXVECTOR3 vecSavedSpherePos)

{

vecSavedSpherePos=m_vecSavePosition;

};

inline void GetSavedSpherePosition2(D3DXVECTOR3 vecSavedSpherePos)

{

vecSavedSpherePos=m_vecSavePosition2;

};

inline void SaveSpherePosition()

{

m_vecSavePosition=m_pSphereState-sVector;

};

inline void SaveSpherePosition2()

{

m_vecSavePosition2=m_pSphereState-sVector;

};

inline void ContradictoryZv()

{

m_pSphereState-vVector.z=-m_pSphereState-vVector.z;

};

inline void ContradictoryXv()

{

m_pSphereState-vVector.x=-m_pSphereState-vVector.x;

};

void MirrorVAoubtAxis(D3DXVECTOR3 n);

inline void ReduceSphereVelocity(float percent)

{

m_pSphereState-v=m_pSphereState-v*percent;

};

inline float CheckSphereEnergy()

{

return m_pSphereState-v;

};

inline void SetSphereVelocityDir(const D3DXVECTOR3 vDir)

{

m_pSphereState-vVector=vDir;

};

inline void SetSphereVelocity(const float velocity)

{

m_pSphereState-v=velocity;

};

inline void GetSphereVelocityDir(D3DXVECTOR3 vDir)

{

vDir=m_pSphereState-vVector;

};

inline float GetSphereVelocity()

{

return m_pSphereState-v;

};

inline void SetSphereStateToFalse()

{

m_bSphereInUse=FALSE;

};

inline void SetSphereStateToTrue()

{

m_bSphereInUse=TRUE;

};

inline BOOL GetSphereState()

{

return m_bSphereInUse;

};

void SetSphereVelocityAt_Y_NegativeAxis();

inline float GetSpherePosAt_Y_Axis()

{

return m_pSphereState-sVector.y;

};

private:

BOOL CreateIndexBuffer();

BOOL UpdateVertices();

BOOL CreateVertexBuffer();

void TransformSphere();

void TransformSphereForUser();

void UpdateSpherePosition();

void FrictionReduseVelocity();

LPDIRECT3DDEVICE8 m_pD3DDevice;

LPDIRECT3DVERTEXBUFFER8 m_pVertexBuffer;

LPDIRECT3DTEXTURE8 m_pTexture;

D3DMATERIAL8 m_matMaterial;

LPDIRECT3DINDEXBUFFER8 m_pIndexBuffer;

int m_iRings;

int m_iSegments;

float m_fTotalDis;

D3DXVECTOR3 m_vecSphereRotationAxis;

BOOL m_bSphereInUse;

DWORD m_dwNumOfVertices;

DWORD m_dwNumOfIndices;

DWORD m_dwNumOfPolygons;

};#endif

nodejs棋牌源代碼怎麼寫

1、首先,nodejs棋牌是一款網頁在線對戰遊戲,其源代碼與普通程序的源代碼不同。

2、其次,用cd命令轉到功能包目錄中包含源代碼的目錄。

3、最後,並創建helloworldnodepp的文件,用gedit編輯器進行編寫即可。

關於桌球遊戲的C語言編程

#includestdio.h

#includegraphics.h

#includeconio.h

#include stdlib.h

#includemath.h

#includetime.h

#define PATH “D:\\tc30”

#define pi 3.14159265354

#define r 10.0

#define zero 0.01

#define BC 0

#define DISK 2

float R=r+0.5;

struct balltype

{

float x,y;

float dx,dy;

int flag;

}ball[16];

int cx=320-5*r,cy=240;

float power=15.0;

int flag=1,player=0,chang=0;

int hole[6][2]={{17,92},{320,92},{623,92},

{17,388},{320,388},{623,388}};

int plball[2]={0,0},ex=1;

void help()

{ char *fname = { “a/4:left d/6:right w/8:up s/2:down Space:shoot ,or.:power Esc:exit” };

setcolor(14);

outtextxy(8,460,fname);

}

void waittime(double t)

{

time_t t1,t2;

double a,b;

a=time(t1);

while(1)

{

b=time(t2);

if(b-at) break;

}

}

void drawhlep()

{

setbkcolor(9);

setcolor(14);

rectangle(50,50,550,400);

rectangle(50,100,550,145);

settextstyle(0, 0, 4);

outtextxy(150, 60, “Help You!”);

rectangle(250,100,400,145);

setcolor(4);

settextstyle(3,0,4);

outtextxy(270,102,”Player1″);

outtextxy(420,102,”Player2″);

setcolor(14);

rectangle(50,170,550,195);

rectangle(50,220,550,245);

rectangle(50,270,550,295);

rectangle(50,320,550,345);

rectangle(50,370,550,400);

rectangle(400,145,550,245);

rectangle(50,145,250,370);

setcolor(10);

settextstyle(3,0,1);

outtextxy(115,146,”Left”);

outtextxy(115,171,”Right”);

outtextxy(115,196,”Up”);

outtextxy(115,221,”Down”);

outtextxy(115,246,”Move Quick”);

outtextxy(115,271,”Add”);

outtextxy(115,296,”Subtrate”);

outtextxy(115,321,”Shoot”);

outtextxy(115,346,”Exit”);

setcolor(5);

settextstyle(7,0,4);

outtextxy(60,385,”Welcome to ZGQ’s Game. QQ:271111716 E-mail:zgq150@163.com”);

}

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/297383.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-12-28 12:15
下一篇 2024-12-28 12:15

相關推薦

  • 為什麼不用Python開發遊戲

    Python是一種高級編程語言,擁有簡單易學、代碼簡潔等優點。同時,Python也是一種多用途的語言,可以用於Web開發、數據分析以及機器學習等領域。然而,對於遊戲開發領域,Pyt…

    編程 2025-04-29
  • 雲智直聘 源碼分析

    本文將會對雲智直聘的源碼進行分析,包括前端頁面和後端代碼,幫助讀者了解其架構、技術實現以及對一些常見的問題進行解決。通過本文的閱讀,讀者將會了解到雲智直聘的特點、優勢以及不足之處,…

    編程 2025-04-29
  • 使用Python製作遊戲代碼

    Python是一種高級編程語言,因其簡潔明了的代碼風格、易於學習和使用而備受青睞。Python已經成為遊戲製作的熱門選擇之一,可以通過Pygame、Panda3D等工具來實現遊戲制…

    編程 2025-04-29
  • Python貪吃蛇遊戲設計報告

    本文將從遊戲設計的目標、實現思路、技術要點、代碼實現等多個方面對Python貪吃蛇遊戲進行詳細闡述。 一、遊戲設計的目標 貪吃蛇是一款經典的遊戲,我們的遊戲設計不僅要實現基本的玩法…

    編程 2025-04-28
  • Python網站源碼解析

    本文將從多個方面對Python網站源碼進行詳細解析,包括搭建網站、數據處理、安全性等內容。 一、搭建網站 Python是一種高級編程語言,適用於多種領域。它也可以用於搭建網站。最常…

    編程 2025-04-28
  • 用Python編寫推箱子遊戲並上傳至百度網盤

    本文將詳細闡述如何使用Python編寫一個推箱子遊戲,並將代碼上傳至百度網盤,以便大家學習和使用。 一、遊戲介紹 推箱子遊戲是一種非常經典的益智類遊戲,遊戲中,玩家需要將箱子推到指…

    編程 2025-04-28
  • 源碼是什麼

    源碼是一段計算機程序的原始代碼,它是程序員所編寫的可讀性高、理解性強的文本。在計算機中,源碼是指編寫的程序代碼,這些代碼按照一定規則排列,被計算機識別並執行。 一、源碼的組成 源碼…

    編程 2025-04-27
  • 如何製作一個簡單的換裝遊戲

    本文將從以下幾個方面,為大家介紹如何製作一個簡單的換裝遊戲: 1. 遊戲需求和界面設計 2. 使用HTML、CSS和JavaScript開發遊戲 3. 實現遊戲的基本功能:拖拽交互…

    編程 2025-04-27
  • Python做的遊戲可以導出嗎

    Python是一種高級編程語言,最初用於解決系統管理員的日常任務,具有易學、易用、高效的特點,因此在遊戲開發中也逐漸受到了廣泛的關注。那麼,Python做的遊戲可以導出嗎?答案是肯…

    編程 2025-04-27
  • Python猜字謎遊戲

    本文將從以下多個方面詳細闡述Python猜字謎遊戲的實現: 一、基本流程 1、定義一個包含多個單詞的列表,隨機選擇一個單詞作為題目。 2、為每個字母生成一個對應的下劃線並顯示給用戶…

    編程 2025-04-27

發表回復

登錄後才能評論