栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python做简易太阳系(仅供参考)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python做简易太阳系(仅供参考)

用python3.7做了一个小游戏——见缝插针
基于pgzrun的库
PySimleGUI的库可有可无,加上可使程序更加丰富一点

import pgzrun as pz
import PySimpleGUI as sg
sun = Actor('太阳.png')

sun.x = 400
sun.y = 300
#TITLE 程序标题
TITLE = '见缝插针'

WIDTH = 800
HEIGHT = 600

#创建针的列表
zhens = []
#导入针的图片,设置锚点相对坐标
startZhen = Actor('needle.jpg',anchor = (170+50,1.5))

startZhen.x = 200
startZhen.y = 300

#将新的针放入列表中
layout = [[sg.Text('选择难度'),sg.Radio("A.简单","RADIO"),sg.Radio("B.中等","RADIO"),sg.Radio("C.较难","RADIO"),sg.Radio("D.极难","RADIO"),sg.Radio("E.变态","RADIO")],
          [sg.Button("提交")]
]
window = sg.Window('shi',layout, finalize=True)
my_windows_size = window.Size
button, values = window.Read()
window.close()
if values[0] ==True :
    rotateSpeed = 1
if values[1] ==True :
    rotateSpeed = 2
if values[2] ==True :
    rotateSpeed = 3
if values[3] ==True :
    rotateSpeed = 4
if values[4] ==True :
    rotateSpeed = 6

#设置分数为0
fenshu = 0

def draw():
    screen.fill('white')
    sun.draw()
   #历变zhen里面所有的zhen
    startZhen.draw()
    for zhen in zhens:
        zhen.draw()
    screen.draw.text(str(fenshu),(50,250),fontsize = 50,color = 'red')

def update():
    #(当针的坐标达到400,针开始做饶圆心圆周运动)
    for zhen in zhens: #对列表中每根针历遍处理 
        zhen.angle = zhen.angle + rotateSpeed

#当任意键被按下的方法
def on_key_down():
    global rotateSpeed,fenshu
    newZhen = Actor('needle.jpg',anchor = (170+50,1.5))
    newZhen.x = 400
    newZhen.y = 300

    for zhen in zhens:
        if newZhen.colliderect(zhen):
        #collicede:碰撞,如果新针撞到列表里的针
            rotateSpeed = 0
            if fenshu <= 35 and fenshu >= 0:
                sg.Popup("c")
            if fenshu <= 55 and fenshu >= 36 :
                sg.Popup("B")
            if fenshu <= 80 and fenshu >= 56:
                sg.Popup("A")
            #打印 游戏失败
    if rotateSpeed != 0:
        fenshu = fenshu+1
    zhens.append(newZhen)


pz.go()

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/958445.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号