Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson2_diy3
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
881fac9b
authored
Dec 06, 2020
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
0d2abe4b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
8 deletions
snake.py
snake.py
View file @
881fac9b
...
@@ -25,25 +25,25 @@ while True:
...
@@ -25,25 +25,25 @@ while True:
# 接收到退出事件后退出程序
# 接收到退出事件后退出程序
exit
()
exit
()
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
key
==
locals
.
k
_RIGHT
and
setheading
!=
"left"
:
if
event
.
key
==
locals
.
K
_RIGHT
and
setheading
!=
"left"
:
setheading
=
"right"
setheading
=
"right"
snake_h
=
right
snake_h
=
right
if
event
.
key
==
locals
.
k_RIGH
T
and
setheading
!=
"right"
:
if
event
.
key
==
locals
.
K_LEF
T
and
setheading
!=
"right"
:
setheading
=
"left"
setheading
=
"left"
snake_h
=
left
snake_h
=
left
if
event
.
key
==
locals
.
k_RIGHT
and
setheading
!=
"up"
:
if
event
.
key
==
locals
.
K_DOWN
and
setheading
!=
"up"
:
setheading
=
"down"
setheading
=
"down"
snake_h
=
down
snake_h
=
down
if
event
.
key
==
locals
.
k_RIGHT
and
setheading
!=
"down"
:
if
event
.
key
==
locals
.
K_UP
and
setheading
!=
"down"
:
setheading
=
"up"
setheading
=
"up"
snake_h
=
up
snake_h
=
up
if
setheading
==
"right"
:
if
setheading
==
"right"
:
x
+=
30
x
+=
30
if
setheading
==
"left"
:
el
if
setheading
==
"left"
:
x
-=
30
x
-=
30
if
setheading
==
"down"
:
el
if
setheading
==
"down"
:
y
+=
30
y
+=
30
if
setheading
==
"up"
:
el
if
setheading
==
"up"
:
y
-=
30
y
-=
30
position
.
append
((
x
,
y
))
position
.
append
((
x
,
y
))
position
.
pop
(
0
)
position
.
pop
(
0
)
...
@@ -51,7 +51,7 @@ while True:
...
@@ -51,7 +51,7 @@ while True:
# 将背景图画上去
# 将背景图画上去
screen
.
blit
(
background
,
(
0
,
0
))
screen
.
blit
(
background
,
(
0
,
0
))
# 将贪吃蛇画上去
# 将贪吃蛇画上去
screen
.
blit
(
right
,
(
x
,
y
))
screen
.
blit
(
snake_h
,
(
x
,
y
))
# 将贪吃蛇的身体画上去
# 将贪吃蛇的身体画上去
for
i
in
range
(
len
(
position
)
-
1
):
for
i
in
range
(
len
(
position
)
-
1
):
screen
.
blit
(
body
,
position
[
i
])
screen
.
blit
(
body
,
position
[
i
])
...
...
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