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/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

发表回复

登录后才能评论