Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson3_diy4
This project
Loading...
Sign in
Toggle navigation
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
9968e41f
authored
Dec 25, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
ea7c485c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
3 deletions
snake.py
snake.py
View file @
9968e41f
import
pygame
from
pygame
import
locals
import
random
import
pygame
from
pygame
import
locals
import
random
import
sys
import
time
# 初始化pygame,为使用硬件做准备
pygame
.
init
()
...
...
@@ -21,7 +26,7 @@ down = pygame.image.load('down.png') # 头 朝下
x
,
y
=
240
,
120
position
=
[(
180
,
90
),
(
180
,
120
),
(
210
,
120
),
(
x
,
y
)]
random
#
random
setheading
=
"right"
snake_head
=
right
...
...
@@ -47,7 +52,11 @@ while True:
if
event
.
key
==
locals
.
K_DOWN
and
setheading
!=
"up"
:
setheading
=
'down'
snake_head
=
down
if
(
x
>
630
or
x
<
0
or
y
>
450
or
y
<
0
)
or
((
x
,
y
)
in
position
[:
-
1
]):
screen
.
blit
(
over
,(
60
,
60
))
pygame
.
display
.
flip
()
time
.
sleep
(
10
)
# 设置贪吃蛇的头部坐标
if
setheading
==
"right"
:
x
+=
30
...
...
@@ -68,7 +77,7 @@ while True:
apple_y
=
30
*
nun2
-
30
else
:
position
.
pop
(
0
)
if
x
<
0
and
x
>
630
and
y
<
0
and
y
>
450
# 将背景图画上去
screen
.
blit
(
background
,
(
0
,
0
))
# 将贪吃蛇的头画上去
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment