# encoding: utf-8
import pygame
import sys
import random
# 全局定义
SCREEN_X = 600
SCREEN_Y = 600
# 蛇类
# 点以25为单位
class Snake(object):
# 初始化各种需要的属性 [开始时默认向右/身体块x5]
def __init__(self):
self.dirction = pygame.K_RIGHT
self.body = []
for x in range(5):
self.addnode()
# 无论何时 都在前端增加蛇块
def addnode(self):
lefttop = (00)
if self.body:
lefttop = (self.body[0].leftself.body[0].top)
node = pygame.Rect(lefttop2525)
if self.dirction == pygame.K_LEFT:
node.left -= 25
elif self.dirction == pygame.K_RIGHT:
node.left += 25
elif self.dirction == pygame.K_UP:
node.top -= 25
elif self.dirction == pygame.K_DOWN:
node.top += 25
self.body.insert(0node)
# 删除最后一个块
def delnode(self):
self.body.pop()
评论
共有 条评论