python画汤姆猫_python汤姆猫⼩游戏源代码免费下载'''
汤姆猫v2.0
'''
import pygame,sys
class Tom1(object):
''' 1.mian() 函数 '''
def main(self):
# 1.1设置标题
pygame.display.set_caption("汤姆猫2.0")
# 1.2 死循环
while True:
# 1.4 业务逻辑执⾏
self.action()
# 1.5 绘制图形
self.paint()
# 1.3 刷新屏幕
vbscript语法手册pygame.display.update()
''' 2. action() '''
def action(self):
# 2.1 事件迭代监听
for event in ():
# 2.2 退出
pe == pygame.QUIT:
# 2.3 ⿏标监听
pe == pygame.MOUSEBUTTONDOWN:
# 2.4获取⿏标信息
mouseX, mouseY = _pos()
# 2.5 获取⿏标点击
leftFlag = _pressed()[0]
# 2.6 判断吃鸟动作
if leftFlag and 30 < mouseX < 90\
and 300 < mouseY <360:
# 2.7设置图⽚总数
# 2.8 获取图⽚
# 2.9 设置图⽚集转换值
self.index = 0
# 2.7 判断喝⽜奶动作
elif leftFlag and 30 < mouseX < 90\ and 360 < mouseY <420:
网页显示Image("drink")
# 2.8 判断敲锣动作
elif leftFlag and 30 < mouseX < 90\ and 420 < mouseY <480:
elif leftFlag and 250 < mouseX < 310\ and 300 < mouseY <360:
elif leftFlag and 250 < mouseX < 310\ and 360 < mouseY <420:
elif leftFlag and 250 < mouseX < 310\ and 420 < mouseY <480:
elif leftFlag and 90 < mouseX < 200\ and 90 < mouseY <250:
elif leftFlag and 220 < mouseX < 280\ and 400 < mouseY <480:
elif leftFlag and 100 < mouseX < 180\
and 360 < mouseY <420:
elif leftFlag and 155 < mouseX < 205\
and 470 < mouseY <512:
elif leftFlag and 100 < mouseX < 150\
and 470 < mouseY <512:
''' 3. paint()'''
def paint(self):
# 3.1绘制背景图⽚python代码画图案
self.screen.ansform.scale(self.background, (320, 512)),(0, 0)) # 3.2 绘制吃鸟动作
self.screen.blit(self.eat,(30, 300))
# 3.3 绘制喝⽜奶动作
self.screen.blit(self.drink, (30, 360))
self.screen.bal, (30, 420))
self.screen.blit(self.fart, (250, 300))
self.screen.blit(self.pie, (250, 360))
self.screen.blit(self.scratch, (250, 420))
# 绘制头部
# 3.3 判断是否运⾏动画
在线手册系统源码# count = -1 index = 0
unt*10 > self.index:
self.index += 1
ix = self.index / 10 % len(self.images)
# 赋值
self.background = self.images[int(ix)]
else:
# 结束清空所有值
self.index = 0
# 列表的清空
self.images = []
''' 4. init() '''
def __init__(self):
# 4.1 背景
self.screen = pygame.display.set_mode((320, 512),0,0)
# 4.2 背景图
self.background = pygame.image.load("Animations/Eat/eat_00.jpg") # 4.3 吃鸟的动作
self.eat = pygame.image.load("Buttons/eat.png")
# 4.4 图⽚存储列表
self.images = []
# 4.5 图⽚集转换值
self.index = 0
# 4.6 图⽚数量
# 4.7 喝⽜奶
self.drink = pygame.image.load("Buttons/drink.png")
# 4.8 敲锣
# 4.9
self.fart = pygame.image.load("Buttons/fart.png")
# 4.10
self.pie = pygame.image.load("Buttons/pie.png")
# 4.11
self.scratch = pygame.image.load("Buttons/scratch.png")
''' 5. getImage() '''
def getImage(self, name):
# 5.1 获取图⽚
objective和object区别for i in range(0, unt):
# 5.2 判断路径地址
if i < 10:# name ==> "eat"
imgPath = "Animations/"+name+"/"+name+"_0"+str(i)+".jpg" else:
imgPath = "Animations/"+name+"/"+name+"_"+str(i)+".jpg" # 5.3 存储路径地址
self.images.append(pygame.image.load(imgPath))
if __name__ == '__main__':
tm = Tom1()
tm.main()
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论