Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson2_diy2
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
0af22f98
authored
Apr 11, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
9e28e649
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
2 deletions
snake.py
snake.py
View file @
0af22f98
...
...
@@ -6,19 +6,43 @@ pygame.init()
# 创建一个窗口
screen
=
pygame
.
display
.
set_mode
((
660
,
480
))
a
=
pygame
.
time
.
Clock
()
# 背景
background
=
pygame
.
image
.
load
(
'bg.png'
)
right
=
pygame
.
image
.
load
(
'right.png'
)
food
=
pygame
.
image
.
load
(
'apple.png'
)
body
=
pygame
.
image
.
load
(
'body.png'
)
x
,
y
=
210
,
120
lift
=
pygame
.
image
.
load
(
'lift.png'
)
up
=
pygame
.
image
.
load
(
'up.png'
)
down
=
pygame
.
image
.
load
(
'down.png'
)
right_a
=
'right'
right_b
=
right
x
,
y
=
240
,
120
a_b
=
[(
120
,
120
),(
150
,
120
),(
180
,
120
),(
x
,
y
)]
while
True
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
# 接收到退出事件后退出程序
exit
()
elif
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
key
==
locals
.
K_RIGHT
and
right_a
!=
'left'
:
right_a
==
'right'
right_b
=
right
if
event
.
key
==
locals
.
K_LEFT
and
right_a
!=
'right'
:
right_a
==
'left'
right_b
==
left
if
event
.
key
==
locals
.
K_DOWN
and
right_a
!=
'up'
:
right_a
==
'down'
right_b
==
down
if
event
.
key
==
locals
.
K_
and
right_a
!=
'down'
:
right_a
==
'up'
right_b
==
up
if
right_a
==
'light'
:
x
+=
30
if
left_a
==
'left'
:
x
-=
30
x
+=
30
a_b
.
append
((
x
,
y
))
a_b
.
pop
(
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