python小游戏源代码pygame_python抓娃娃小游戏源码(pygame)
【实例简介】
【实例截图】
【核心代码】
from PIL import Image
import math,pygame,sys,mod
from mod import Hook
from mod import Mine,Time_countdown
from mod import screen
clock = pygame.time.Clock()
#窗口设置
pygame.init()
pygame.display.set_caption("黄金矿工")
screen_size=(800,600)
screen=pygame.display.set_mode(screen_size)
backcolour=(255,255,255)
screen.fill(backcolour)
FPS=60
fclock=pygame.time.Clock()
#图标初始化
hook=Hook()
man=mod.Matchman(hook.rect.top-80,hook.rect.left hook.rect.width/2-50)
news_group=pygame.sprite.Group()
for i in range(3):
news_group.add(mod.Button(i))
screens=0
goals=[100,150,300]
time_limited=[20,30,20]
#积分
scores=mod.Scores(0)
#clock=pygame.time.Clock()
pygame.mixer.init()
bgm=pygame.mixer.Sound("bgm.wav")
bgm.play()
while 1:
screen.fill(backcolour)
if screens==0: #开始界面
mod.show_back(0)
for spr in news_group:
spr.show()
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
pygame.QUIT
if event.type == pygame.MOUSEMOTION:
for spr in news_group:
if spr.rect.collidepoint(event.pos):
spr.check = 0
else:
spr.check = 1
if event.type == pygame.MOUSEBUTTONDOWN:
for spr in news_group:
if spr.rect.collidepoint(event.pos):
if spr.index==0: #点击开始按钮
level = 0
first_draw = 1
timee = Time_countdown(time_limited[level])
event_count_time = pygame.USEREVENT 1
matchmen_change = pygame.USEREVENT 2
pygame.time.set_timer(event_count_time, 1000)
pygame.time.set_timer(matchmen_change, 200)
rotate = 1
run = 0
wait = 0
miner_back = 0
special_change_speed = 0
change_man = True
hook.reset()
screens=1
finish=0
scores.score=0
elif spr.index==1:
screens=2
elif spr.index==2:
sys.exit()
pygame.QUIT
elif screens==1: #游戏主界面
mod.show_back(1)
if first_draw:
timee.reset(time_limited[level])
first_draw=0
miner_group = mod.set(level)
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
pygame.QUIT
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_DOWN:
run = 1
rotate = 0
if event.type == event_count_time:
timee.miner()
if event.type == matchmen_change:
if run:
man.change()
#碰撞后物体与钩子衔接
if pygame.sprite.spritecollide(hook, miner_group, False, pygame.sprite.collide_mask):
miner = pygame.sprite.spritecollide(hook, miner_group, False, pygame.sprite.collide_mask)[0]
if miner.first:
miner.first = False
ayis = (hook.rect.top hook.rect.height / 2) (miner.rect.height/2)* math.sin(math.radians(hook.angle))
axis = (hook.rect.left hook.rect.width / 2) - (miner.rect.height/2)* math.cos(math.radians(hook.angle))
miner.rect.top = ayis - miner.rect.height / 2
miner.rect.left = axis - miner.rect.width / 2
hook.direction = [-hook.direction[0], -hook.direction[1]]
miner.direction = hook.direction
if miner.speed >= 1:
FPS *= miner.speed
else:
special_change_speed = 1
hook.speed = miner.speed
miner_back = 1
if rotate:
if hook.angle == 170:
hook.turn_direct = -1
elif hook.angle == 10:
hook.turn_direct = 1
hook.rotate(hook.turn_direct)
if run:
if hook.rect.left <= 0 or hook.rect.left hook.rect.width >= screen_size[
0] or hook.rect.top hook.rect.height >= screen_size[1]:
hook.direction = [-hook.direction[0], -hook.direction[1]]
elif hook.rect.top < hook.ini_top:
run = 0
rotate = 1
hook.reset()
if miner_back:
miner_back = 0
scores.score = int(miner.value)
miner_group.remove(miner)
FPS = 60
special_change_speed = 0
continue
elif miner_back and special_change_speed:
if (-hook.rect.left hook.ini_left) != 0:
r = math.atan((hook.rect.top - hook.ini_top) / (-hook.rect.left hook.ini_left))
hook.direction = [10 * math.cos(r), -10 * math.sin(r)]
if (r < 0):
hook.direction = [-hook.direction[0], -hook.direction[1]]
hook.move()
pygame.draw.line(screen, (0, 0, 0),
(hook.rect.left hook.rect.width / 2, hook.rect.top hook.rect.height / 2),
(hook.ini_left hook.rect.width / 2,hook.ini_top hook.rect.height / 2), 4)
if miner_back:
miner.direction = hook.direction
miner.move(hook.speed)
miner.rect = screen.blit(miner.img, miner.rect)
for i in miner_group:
if i.index!=4:
break
else:
finish=1
if len(miner_group) == 0 or timee.now==0 or finish:
if scores.score >= goals[level] and level<=2:
level = 1
screens = 4
if level==3:
continue
else:
screens = 3
timee.reset(time_limited[0])
finish=0
for spr in miner_group:
spr.rect = screen.blit(spr.img, spr.rect)
mod.show_txt(str(goals[level]),screen_size[0]/19*14,screen_size[1]/15)
timee.show()
#man.show()
scores.show()
hook.rect = screen.blit(hook.load, hook.rect)
man.show()
elif screens==2: #规则界面
mod.show_back(2)
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
screens = 0
if event.type == pygame.QUIT:
sys.exit()
pygame.QUIT
elif screens==3: #失败界面
mod.show_back(3)
for event in pygame.event.get():
if event.type == (pygame.MOUSEBUTTONDOWN or pygame.KEYDOWN):
screens = 0
if event.type == pygame.QUIT:
sys.exit()
pygame.QUIT
if screens==4: #成功界面
mod.show_back(4)
for event in pygame.event.get():
if event.type == (pygame.MOUSEBUTTONDOWN or pygame.KEYDOWN):
if level>=3:
screens=0
else:
screens = 1
first_draw = 1
hook.reset()
scores.score=0
if event.type == pygame.QUIT:
sys.exit()
pygame.QUIT
pygame.display.update()
fclock.tick(FPS)
bgm.stop()
python小游戏源代码pygame_python抓娃娃小游戏源码(pygame)相关推荐
- python金融实战 源代码_Python金融股票爬虫实战源码大全
Stock [1]- 终端实时获取股票价格,实时查询股票价格,默认查询了沪指.深指.需要安装requests库,通过调用新浪股票API,实时查询股票价格,支持查询多支股票,通过threading多线程 ...
- 用requests获取网页源代码 python-Python3使用requests包抓取并保存网页源码的方法
本文实例讲述了Python3使用requests包抓取并保存网页源码的方法.分享给大家供大家参考,具体如下: 使用Python 3的requests模块抓取网页源码并保存到文件示例: import r ...
- 小福利,django搭建个人网站的源码公开(一)
大家好,我是天空之城,今天给大家带来小福利,django搭建个人网站的源码公开(一) **django框架的原理:**它采用的是MVT架构,m就是model数据模型,就是数据的结构和字段,比如是个人博 ...
- WoShop多商户直播短视频APP小程序商城全开源无加密商城源码
WoShop多商户直播短视频APP小程序商城全开源无加密商城源码 基于现场直播+购物模式,用户可以"边看边买"现场直播商城平台,全终端支持,统一管理后台,传播更强,管理更方便,支持 ...
- WoShop多商户直播电商系统APP+小程序+H5全开源无加密商城源码
WoShop多商户直播电商系统APP+小程序+H5全开源无加密商城源码 随着多商户直播电商系统的市场走向兴盛,不止直播电商系统的使用越来越广泛,寻求多商户直播电商系统源码的人也越来越多.但源码市场混乱 ...
- 仿小皮手游网帝国CMS模板源码 大型手游门户网站系统源码+手机版+火车头采集
csdn下载地址: https://download.csdn.net/download/dujiangdu123/13919533 好久没分享92game的资源了,92game一般都是采用帝国CMS ...
- 微擎小程序怎么配置服务器域名,随便撸源码源码微擎小程序通用配置图文教程,教会你怎么配置微擎小程序!...
最近很多网友都在问站长微擎小程序如何配置使用,微擎小程序配置 查看更多关于 微擎小程序配置 的文章 主要分几类,之前已经写过人人商城小程序的配置教程了,大家反响非常好,简单就学会了配置人人商城小程序. ...
- 微信小程序:云开发表情包制作源码
该款小程序是一个表情包制作 内容毕竟丰富,另外自定义制作方面也是特别的自由 支持自主上传图片,自定义文章,另外拥有多种素材模板以供选择 这是一款云开发的小程序,但是安装还是挺简单的 搭建教程: 首先使 ...
- 最新小程序授权+php后端(附demo源码)
参考博客:小程序授权+php后端(附demo源码)_流情的博客-CSDN博客_php小程序 正所谓计划永远赶不上变化,鉴于小程序端已经更改了微信授权登录的接口,因此特来补充一下.原先的wx.getUs ...
最新文章
- 依赖注入与Unity
- Windows Azure Cloud Service (4) Windows Azure 平台高可用性的实现
- 73 Zabbix 微信告警
- 太相信书的人,格局不会太大
- Linux IPC / 分类
- html5游戏面试题及答案,HTML5常见面试题及答案(二)
- mysql合集_Mysql数据库知识点合集
- 10参数_荣耀V40屏幕参数:10亿色视网膜级超感屏
- 微信小程序——极点日历使用方法
- 067、如何部署Calico网络 (2019-04-10 周三)
- JSON——JavaScript 中的使用
- Atitit.软件开发的几大规则,法则,与原则Principle v3
- k8s pod部署到不同node_应用部署演进(二)
- QT绘制同心扇形(Paintevent实现)
- fileuploads
- tx2上装scikit-image
- 安卓系统格式化SD卡
- 泊松过程2 | 泊松过程扩展
- windows 下的CACTI的安装方法
- Rose出现 “relation from A to B would cause an Invalid circular inheritance解决方法。