目录
1 前言
2 系统环境
3 代码分析
4 源代码
5 结尾
一 前言
最近在网上冲浪的时候,发现有一些好玩的Python游戏,我就浅浅的学习了一下,现在将我学到的分享给大家,但是实话实说看看隔壁的HTML5,比Python好学因为HTML平常用的插件也就那几个,但Python用时候pip下载还有问题,当时刚刚接触Python的时候根本就不会修pip,废话不说了
二 系统环境
系统:window11
Python系统:Python3.9
编译器:pycharm
模块:pygame panda3d pip下载后用不了<点击此处>
pip install pygame/panda3d #python2点多版本
pip3 install pygame/panda3d #python3点多版本
三 代码分析
因为我们是简约型的所以我们设置鼠标操作
# 禁用鼠标
self.disableMouse()
#隐藏鼠标
props = WindowProperties()
props.setCursorHidden(True)
base.win.requestProperties(props)
接下来该设置场景
# 创建四幕
PosInterval1 = self.pandaActor.posInterval(13,
Point3(0, -10, 0),
startPos=Point3(0, 10, 0))
PosInterval2 = self.pandaActor.posInterval(13,
Point3(0, 10, 0),
startPos=Point3(0, -10, 0))
HprInterval1 = self.pandaActor.hprInterval(3,
Point3(180, 0, 0),
startHpr=Point3(0, 0, 0))
HprInterval2 = self.pandaActor.hprInterval(3,
Point3(0, 0, 0),
startHpr=Point3(180, 0, 0))
# 创建情节并运行四幕2
self.pandaPace = Sequence(PosInterval1,
HprInterval1,
PosInterval2,
HprInterval2,
name="pandaPace")
self.pandaPace.loop()
#创建HUD
global X1,X2,text,text2,L1,L2l,L2r
text=OnscreenText(fg=(255,255,0,255),pos=(-0.1,-0.1),scale=0.1,mayChange=True)
text2=OnscreenText(pos=(-0.7,0),scale=0.1,mayChange=True)
DirectFrame(frameColor=(255,255,0,255),frameSize=(-0.04,0.04,-0.002,0.002),pos=(0,0,0))
DirectFrame(frameColor=(255,255,0,255),frameSize=(-0.002,0.002,-0.04,0.04),pos=(0,0,0))
X1=DirectFrame(frameColor=(0,0,0,255),frameSize=(-0.04,0.04,-0.002,0.002),pos=(0,0,0))
X2=DirectFrame(frameColor=(0,0,0,255),frameSize=(-0.002,0.002,-0.04,0.04),pos=(0,0,0))
DirectFrame(frameColor=(255,255,0,255),frameSize=(-0.5,-0.51,0.5,-0.5),pos=(0,0,0))
L1=DirectFrame(frameColor=(255,255,0,255),frameSize=(0.2,0.11,0.005,-0.005),pos=(0,0,0))
L2l=DirectFrame(frameColor=(255,255,0,255),frameSize=(-0.1,-0.04,0.002,-0.002),pos=(0,0,0))
L2r=DirectFrame(frameColor=(255,255,0,255),frameSize=(0.04,0.1,0.002,-0.002),pos=(0,0,0))
DirectFrame(frameColor=(255,255,0,255),frameSize=(-0.1,0.1,0.002,-0.002),pos=(0,0,0.5))
DirectFrame(frameColor=(255,255,0,255),frameSize=(-0.1,0.1,0.002,-0.002),pos=(0,0,-0.5