• 大小: 0.01M
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2024-05-05
  • 语言: Python
  • 标签:

资源简介

打砖块小游戏

资源截图

代码片段和文件信息

#导入模块
import pygame
from pygame.locals import *
import sysrandomtimemath
 
class GameWindow(object):
    ‘‘‘创建游戏窗口类‘‘‘
    def __init__(self*args**kw):      
        self.window_length = 600
        self.window_wide = 500
        #绘制游戏窗口,设置窗口尺寸
        self.game_window = pygame.display.set_mode((self.window_lengthself.window_wide))
        #设置游戏窗口标题
        pygame.display.set_caption(“CatchBallGame“)
        #定义游戏窗口背景颜色参数
        self.window_color = (135206250)
 
    def backgroud(self):
        #绘制游戏窗口背景颜色
        self.game_window.fill(self.window_color)
 
class Ball(object):
    ‘‘‘创建球类‘‘‘
    def __init__(self*args**kw):
        #设置球的半径、颜色、移动速度参数
        self.ball_color = (2552150)       
        self.move_x = 1
        self.move_y = 1
        self.radius = 10
 
    def ballready(self):
        #设置球的初始位置、
        self.ball_x = self.mouse_x
        self.ball_y = self.window_wide-self.rect_wide-self.radius
        #绘制球,设置反弹触发条件           
        pygame.draw.circle(self.game_windowself.ball_color(self.ball_xself.ball_y)self.radius)
 
    def ballmove(self):
        #绘制球,设置反弹触发条件           
        pygame.draw.circle(self.game_windowself.ball_color(self.ball_xself.ball_y)self.radius)      
        self.ball_x += self.move_x
        self.ball_y -= self.move_y
        #调用碰撞检测函数
        self.ball_window()
        self.ball_rect()
        #每接5次球球速增加一倍
        if self.distance < self.radius:
            self.frequency += 1
            if self.frequency == 5:
                self.frequency = 0
                self.move_x += self.move_x
                self.move_y += self.move_y
                self.point += self.point
        #设置游戏失败条件
        if self.ball_y > 520:
            self.gameover = self.over_font.render(“Game Over“False(000))
            self.game_window.blit(self.gameover(100130))
            self.over_sign = 1
 
class Rect(object):
    ‘‘‘创建球拍类‘‘‘
    def __init__(self*args**kw):
        #设置球拍颜色参数
        self.rect_color = (25500)
        self.rect_length = 100
        self.rect_wide = 10
 
    def rectmove(self):
        #获取鼠标位置参数
        self.mouse_xself.mouse_y = pygame.mouse.get_pos()
        #绘制球拍,限定横向边界                    
        if self.mouse_x >= self.window_length-self.rect_length//2:
            self.mouse_x = self.window_length-self.rect_length//2
        if self.mouse_x <= self.rect_length//2:
            self.mouse_x = self.rect_length//2
        pygame.draw.rect(self.game_windowself.rect_color((self.mouse_x-self.rect_length//2)(self.window_wide-self.rect_wide)self.rect_lengthself.rect_wide))
 
class Brick(object):
    def __init__(self*args**kw):
        #设置砖块颜色参数
        self.brick_color = (139126102)
        self.brick_list = [[111111][111111][111111][111111][111111]]
        self.brick_length = 80
        self.brick_wide = 20
 
    def brickarrange(self):     
        for i in range(5):
            for j in range(6):
                self.brick_x = j*(sel

评论

共有 条评论