以下是部分代码预览:
"""python的turtle模块制作的打地鼠小游戏,用pygame的混音器配音,此版本为2019/4/9修改。
海龟的图片造型不能旋转,解决方案是用多个造型,但是没有内置的碰撞检测,所以此版本没有加榔头,基本不再更新。
更好的版本应该用pygame或arcade等模块来制作,有需要制作的可以联系我。
"""
__author__ = "李兴球"
__date__ = "2019/4/9"
import os,sys
from turtle import *
from random import *
from time import sleep
import pygame
class Mouse(Turtle):
clicks = 0 # 统计单击数量
def __init__(self,image,position,sound):
Turtle.__init__(self,visible=choice([False,True]),shape=image)
self.penup()
self.speed(0) # 设定速度
self.goto(position)
self.sound = sound # 声音效果
def main():
pygame.mixer.init()
音乐文件= "My Musicfmusic1.wav"
pygame.mixer.music.load(音乐文件)
pygame.mixer.music.play(-1,0)
拍子声 =pygame.mixer.Sound("HandClap.wav")
mouse = "地鼠2.gif"
screen =Screen() # 新建屏幕对象
screen.delay(0) # 设置延时时间
screen.addshape(mouse) # 添加老鼠造型
screen.setup(480,360) # 设置屏幕宽高
screen .bgpic("tree.png") # 设置背景图片
screen.title("Python海龟画图制作的打地鼠小游戏") # 设置窗口标题
screen.mainloop()
if __name__ == "__main__":
main()
下载完整源代码与素材,请
需要浏览更多吗?
成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)

