Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

Administrator / lesson5_7

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Switch branch/tag
  • lesson5_7
  • snake2.py
Find file
BlameHistoryPermalink
  • BellCodeEditor's avatar
    auto save · 9d890fb2
    BellCodeEditor committed 2 years ago
    9d890fb2
snake2.py 891 Bytes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
import pygame
from pygame import locals

# 初始化pygame,为使用硬件做准备
pygame.init()

# 创建一个窗口
screen = pygame.display.set_mode((660, 480))

# 背景
background = pygame.image.load('bg.png')
right = pygame.image.load('right.png')
food = pygame.image.load('apple.png')
body = pygame.image.load('body.png')

while True:
    for event in pygame.event.get():
        if event.type == locals.QUIT:
            # 接收到退出事件后退出程序
            exit()
    # 将背景图画上去
    screen.blit(background, (0, 0))
    # 将贪吃蛇画上去
    screen.blit(right, (240, 120))
    # 将贪吃蛇的身体画上去
    screen.blit(body, (210, 120))
    screen.blit(body, (180, 120))
    screen.blit(body, (180, 90))
    # 将果实画上去
    screen.blit(food, (360, 300))
    # 刷新画面
    pygame.display.update()