python pygame 复刻小游戏 躲避方块

本文介绍了作者使用Python的pygame库制作的一个躲避方块小游戏。玩家需控制黑色方块避开四色方块,生存时间即为得分。文章提到了碰撞检测的实现方法,以及对pygame库学习的一些心得,并警告《python游戏编程入门》一书存在不少错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

新上手pygame,断断续续学习python也有一短时间了,心血来潮复刻一个小游戏(其实差的不少再见)。

界面就是这样:


游戏目标也很简单:四色方框来回碰撞移动,控制黑色方框躲避他们,得分是坚持多少的秒数。


贴代码,新手水平,可以打磨的地方还有很多

import sys,pygame,time
from pygame.locals import *

pygame.init()


class box(object):
    """this produce a box which may block the controller"""

    def __init__(self, x, y, color, hor, ver, box_len):
        """x and y as the position of box. ver is for vertical, hor is for horizontal. those are the moving speed of box.
        box_len is the size"""
        self.x = x
        self.y = y
        self.color = color
        self.ver = ver
        self.hor = hor
        self.length = box_len
        pygame.dra
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值