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
511c42a1
authored
Jan 08, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
59c76c3b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
3 deletions
snake.py
snake.py
View file @
511c42a1
...
...
@@ -3,7 +3,7 @@ from pygame import locals
# 初始化pygame,为使用硬件做准备
pygame
.
init
()
s
=
"right"
# 创建一个窗口
screen
=
pygame
.
display
.
set_mode
((
660
,
480
))
x
=
240
...
...
@@ -20,8 +20,27 @@ while True:
if
event
.
type
==
locals
.
QUIT
:
# 接收到退出事件后退出程序
exit
()
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
key
==
locals
.
K_UP
and
s
!=
"down"
:
s
=
"up"
if
event
.
key
==
locals
.
K_DOWN
and
s
!=
"up"
:
s
=
"down"
if
event
.
key
==
locals
.
K_LEFT
and
s
!=
"right"
:
s
=
"left"
if
event
.
key
==
locals
.
K_RIGHT
and
s
!=
"left"
:
s
=
"right"
x
=
x
+
30
if
s
==
"right"
:
x
=
x
+
30
if
s
==
"left"
:
x
=
x
-
30
if
s
==
"up"
:
y
=
y
-
30
if
s
==
"down"
:
y
=
y
+
30
zb
.
append
((
x
,
y
))
zb
.
pop
(
0
)
# 将背景图画上去
...
...
@@ -34,5 +53,5 @@ while True:
screen
.
blit
(
food
,
(
360
,
300
))
# 刷新画面
pygame
.
display
.
update
()
G
.
tick
(
3
)
\ No newline at end of file
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