pygame.sprite.Sprite 中的wenti

这是一个关于使用Python的pygame库制作蛇形游戏的模板。文章通过类定义了蛇、蛇段和食物,并设置了游戏窗口大小、颜色、初始速度等参数。作者在代码中遇到一个问题:在同一红色食物方块上,rect.x和rect.y的值不一致,这可能是坐标计算或对象定位的错误。
摘要由CSDN通过智能技术生成

“”"
Snake Game template, using classes.

Derived from:
Sample Python/Pygame Programs
Simpson College Computer Science
http://programarcadegames.com/
http://simpson.edu/computer-science/

“”"

import pygame
import random

— Globals —

Colors

BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)

Screen size

height = 600
width = 600

Margin between each segment

segment_margin = 3

Set the width and height of each snake segment

segment_width = min(height, width) / 40 - segment_margin
segment_height = min(height, width) / 40 - segment_margin

Set initial speed

x_change = segment_width + segment_margin
y_change = 0
position=[ i for i in range(0, 600, 15)]

class Snake():
“”" Class to represent one snake. “”"

# Constructor
def __init__(self):

    # Food().__init__()
    # Sfoodlists = Food().foodlists
    # S
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值