Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson3_diy1
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
c19981f3
authored
Jun 11, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
8aac15a9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
6 deletions
snake.py
snake.py
View file @
c19981f3
...
@@ -45,11 +45,11 @@ while True:
...
@@ -45,11 +45,11 @@ while True:
setheading
=
'down'
setheading
=
'down'
snake_head
=
down
snake_head
=
down
if
x
==
a_x
and
y
==
a_y
:
if
x
==
a_x
and
y
==
a_y
:
a_x
=
random
.
randint
(
0
,
660
)
a_x
=
random
.
randint
(
0
,
33
)
*
30
a_y
=
random
.
randint
(
0
,
480
)
a_y
=
random
.
randint
(
0
,
16
)
*
30
pygame
.
display
.
update
()
screen
.
blit
(
food
,
(
a_x
,
a_y
))
screen
.
blit
(
food
,
(
a_x
,
a_y
))
# 设置贪吃蛇的头部坐标
# 苹果被吃后重新出现
if
setheading
==
"right"
:
if
setheading
==
"right"
:
x
+=
30
x
+=
30
elif
setheading
==
"left"
:
elif
setheading
==
"left"
:
...
@@ -58,11 +58,14 @@ while True:
...
@@ -58,11 +58,14 @@ while True:
y
-=
30
y
-=
30
else
:
else
:
y
+=
30
y
+=
30
#按键控制蛇移动
position
.
append
((
x
,
y
))
position
.
append
((
x
,
y
))
position
.
pop
(
0
)
position
.
pop
(
0
)
# 将背景图画上去
# 将蛇头的图画上去
screen
.
blit
(
background
,
(
0
,
0
))
screen
.
blit
(
background
,
(
0
,
0
))
# 将
贪吃蛇的头
画上去
# 将
背景图
画上去
screen
.
blit
(
snake_head
,
position
[
-
1
])
screen
.
blit
(
snake_head
,
position
[
-
1
])
# 将贪吃蛇的身体画上去
# 将贪吃蛇的身体画上去
for
i
in
range
(
len
(
position
)
-
1
):
for
i
in
range
(
len
(
position
)
-
1
):
...
...
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