Python写捕鱼达人
当今最火的莫过于用Python写出捕鱼达人的效果了。啥都不用说,亮代码~~~
# coding:utf-8
# 导入模块
import pygame,sys,time,random
from pygame.locals import *
# 初始化pygame环境
pygame.init()
# 创建一个长宽分别为800/480的窗口
canvas = pygame.display.set_mode((800,480))
canvas.fill((255,255,255))
# 设置窗口标题
pygame.display.set_caption('捕鱼达人')
# 加载图片
bg = pygame.image.load("./images/bg.jpg")
fish1 = pygame.image.load("./images/fish1_0.png")
fish2 = pygame.image.load("./images/fish2_0.png")
fish3 = pygame.image.load("./images/fish3_0.png")
fish4 = pygame.image.load("./images/fish4_0.png")
fish5 = pygame.image.load("./images/fish5_0.png")
fish6 = pygame.image.load("./images/fish6_0.png")
fish7 = pygame.image.load("./images/fish7_0.png")
fish8 = pygame.image.load("./images/fish8_0.png")
fish9 = pygame.image.load("./images/fish9_0.png")
fish10 = pygame.image.load("./images/fish10_0.png")
fish11 = pygame.image.load("./images/fish11_0.png")
net = pygame.image.load("./images/net.png")
gameover = pygame.image.load("./images/gameover.jpg")
# 定义事件监听函数
def handleEvent():
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
# 添加鼠标移动事件,让鼠标控制网的移动
if event.type == MOUSEMOTION:
Game.net.x = event.pos[0] - Game.net.width/2
Game.net.y = event.pos[1] - Game.net.height/2
# 定义时间间隔判断函数
def isActionTime(lastTime,interval):
if lastTime == 0:
return True
currentTime = time.time()
return currentTime - lastTime >= interval
# 定义鱼类
用Python实现捕鱼达人

本文展示了如何使用Python编程实现捕鱼达人的效果,涉及到基础语法如事件、函数、循环、判断和类的使用,以及常用库的导入。作者分享了源码和图片,供读者参考学习,并邀请读者留言互动。
最低0.47元/天 解锁文章
5147





