安装Pygame库。如果你还没有安装,可以使用以下命令:
bash
pip install pygame
- 游戏代码:
python
import pygame
import random
# 初始化Pygame
pygame.init()
# 屏幕尺寸
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("天天酷跑简化版")
# 颜色定义
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
# 玩家类
class Player(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.image = pygame.Surface((50, 50))
self.image.fill(RED)
self.rect = self.image.get_rect()
self.rect.center = (SCREEN_WIDTH // 2,