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

Administrator / pygame_lesson3_diy1

  • 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
Commit 18f35973 authored 3 years ago by BellCodeEditor's avatar BellCodeEditor
Browse files
Options
  • Browse Files
  • Download
  • Email Patches
  • Plain Diff

save project

parent d5739bd2
Hide whitespace changes
Inline Side-by-side
Showing with 8 additions and 4 deletions
  • snake.py
snake.py
View file @ 18f35973
import pygame
from pygame import locals
import random
# 初始化pygame,为使用硬件做准备
pygame.init()
......@@ -19,7 +19,8 @@ down = pygame.image.load('down.png') # 头 朝下
x, y = 240, 120
position = [(180, 90), (180, 120), (210, 120), (x, y)]
ax=360
ay=300
setheading = "right"
snake_head = right
......@@ -41,7 +42,9 @@ while True:
if event.key == locals.K_DOWN and setheading != "up":
setheading = 'down'
snake_head = down
if ax==x and ay==y:
ax=random.randint(0,660)
ay=random.randint(0,480)
# 设置贪吃蛇的头部坐标
if setheading == "right":
x += 30
......@@ -62,7 +65,7 @@ while True:
screen.blit(body, position[i])
# 将果实画上去
screen.blit(food, (360, 300))
screen.blit(food, (ax, ay))
# 刷新画面
pygame.display.update()
FPSCLOCK.tick(3)
\ No newline at end of file
This diff is collapsed. Click to expand it.
  • Write
  • Preview
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment