前言-小游戏Demo
开发环境:win10
开发工具:pycharm + pyqt5
我这里就直接上代码了。。还有很多地方可以改进!欢迎大家多多指点
from pygame.locals import *
from random import randint
import pygame
import time
class Apple:
x = 0
y = 0
step = 44
def __init__(self, x, y):
self.x = x * self.step
self.y = y * self.step
def draw(self, surface, image):
surface.blit(image, (self.x, self.y))
class Player:
x = [0]
y = [0]
step = 44
direction = 0
length = 3
updateCountMax = 2
updateCount = 0
def __init__(self, length):
self.length = length
for i in range(0, 2000):
self.x.append(-100)
self.y.append(-100)
# 初始化位置
self.x[1] = 1 * 44
self.x[2] = 2 * 44
def update(self):
self.updateCount = self.updateCount + 1
if self.updateCount > self.updateCountMax:
# 更新以前的位置
for