资源简介
新手通过上手Python的pygame模块,可以更好上手学些新Python

代码片段和文件信息
import pygame
import sys
import math
import traceback
from pygame.locals import *
from random import *
#球类继承自Sprite类
class Ball(pygame.sprite.Sprite):
def __init__(selfgrayball_imagegreenball_imagepositionspeedbg_sizetarget):
#初始化动画精灵
pygame.sprite.Sprite.__init__(self)
self.grayball_image=pygame.image.load(grayball_image).convert_alpha()
self.greenball_image=pygame.image.load(greenball_image).convert_alpha()
self.rect=self.grayball_image.get_rect()
#将小球放在指定位置
self.rect.leftself.top=position
self.speed=speed
self.side=[choice([-11])choice([-11])]
self.collide=False
self.target=target
self.control=False
self.widthself.height=bg_size[0] bg_size[1]
self.radius=self.rect.width /2
def move(self):
if self.control:
self.rect=self.rect.move(self.speed)
else:
self.rect=self.rect.move(self.side[0]*self.speed[0]\
self.side[1]*self.speed[1])
#如果小球的左侧出了边界,那么将小球左侧的位置改为右侧的边界
#这样便实现了从左边进入,右边出来的效果
if self.rect.right<=0:
self.rect.right=self.width
elif self.rect.left>=self.width:
self.rect.right=0
elif self.rect.bottom<=0:
self.rect.top=self.height
elif self.rect.top>=self.height:
self.rect.bottom=0
#为小球添加一个check方法,用于判断鼠标在一秒钟时间内产生的事件数是否匹配次目标
def check(selfmotion):
if self.target<=motion<=self.target+5:
return True
else:
return False
#定义玻璃面板类
class Glass(pygame.sprite.Sprite):
def __init__(selfglass_imagemouse_imagebg_size):
#初始化动画精灵
pygame.sprite.Sprite.__init__(self)
self.glass_image=pygame.image.load(glass_image).convert_alpha()
self.glass_rect=self.glass_image.get_rect()
self.glass_rect.leftself.glass_rect.top=\
(bg_size[0]-self.glass_rect.width) //2\
(bg_size[1]-self.glass_rect.height)
self.mouse_image=pygame.image.load(mouse_image).convert_alpha()
self.mouse_rect=self.mouse_image.get_rect()
self.mouse_rect.leftself.mouse_rect.top=\
self.glass_rect.leftself.glass_rect.top
pygame.mouse.set_visible(False)
def main():
pygame.init()
grayball_image=‘gray_ball.png‘
greenball_image=‘green_ball.png‘
bg_image=‘bg.png‘
glass_image=‘glass.png‘
mouse_image=‘hand.png‘
bg_size=widthheight=1024681
screen=pygame.display.set_mode(bg_size)
pygame.display.set_caption(‘Play the ball -FishC Demo‘)
background=pygame.image.load(bg_image).convert_alpha()
hole=[(112122198204)\
(222
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 176490 2018-09-06 09:23 play the ball+plus music\bg.png
文件 518065 2018-12-18 15:59 play the ball+plus music\bg_music.ogg
文件 1360044 2018-12-18 15:38 play the ball+plus music\bg_music.wav
文件 3424615 2018-12-18 16:09 play the ball+plus music\bg_music_1.mp3
文件 20652 2018-12-18 15:17 play the ball+plus music\dog.wav
文件 77501 2018-12-18 21:07 play the ball+plus music\glass.png
文件 10197 2018-09-06 09:23 play the ball+plus music\gray_ball.png
文件 12362 2018-12-18 22:10 play the ball+plus music\green_ball.png
文件 2774 2018-12-18 21:30 play the ball+plus music\hand.png
文件 350044 2018-12-18 15:27 play the ball+plus music\hole.wav
文件 130044 2018-12-18 16:18 play the ball+plus music\laugh.wav
文件 440044 2018-12-18 15:24 play the ball+plus music\loser.wav
文件 10240 2018-12-19 16:35 play the ball+plus music\main.py
文件 1620 2018-12-18 16:10 play the ball+plus music\music.py
文件 4969 2018-12-18 15:43 play the ball+plus music\pause.png
文件 120044 2018-12-18 16:07 play the ball+plus music\pigeon.wav
文件 6097 2018-12-18 15:44 play the ball+plus music\play.png
文件 14734 2018-12-19 11:59 play the ball+plus music\win.png
文件 140044 2018-12-18 15:23 play the ball+plus music\winner.wav
文件 48821 2018-12-18 22:10 play the ball+plus music\新建 Microsoft PowerPoint 演示文稿.pptx
目录 0 2018-12-19 11:59 play the ball+plus music
----------- --------- ---------- ----- ----
6869401 21
相关资源
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
评论
共有 条评论