1、弹弹球
#time:2020-3-17 22:20
#小球
import pygame
from pygame.locals import *
import sys
import random
import time
#画布初始化,生成,填充颜色,和名字
pygame.init()
canvas = pygame.display.set_mode((380,600))
canvas.fill((255,255,255))
pygame.display.set_caption(("飞机大战"))
# 定义小球类
class ball():
#小球进行初始化,颜色,坐标,状态,上下方向self.rale
def __init__(self):
self.ball_color = (0,0,255)
self.ball_x = random.randint(10,370)
self.ball_y = 20
self.start = 0
self.rale = 7
#定义小球移动
def move(self):
ball.test(self)
if self.ball_x >= 360:
self.start = 1
if self.ball_x <= 20:
self.start = 0
if self.start:
ball.move_left(self)
else:
ball.move_right(self)
#检测小球有没有碰到长方体,有没有超出顶部。
def test(self):
mouse_x,_ =