Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson1_2
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
1da0a4a1
authored
Apr 16, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
b60ff27c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
5 deletions
snake.py
snake.py
View file @
1da0a4a1
import
pygame
import
pygame
from
pygame
import
locals
#asd=pygame.display.set_mode((660,480))
# 初始化pygame,为使用pygame做准备
# 初始化pygame,为使用pygame做准备
pygame
.
init
()
pygame
.
init
()
screen
=
pygame
.
display
.
set_mode
((
660
,
480
))
x
,
y
=
240
,
120
F
=
pygame
.
time
.
Clock
()
breakgrade
=
pygame
.
image
.
load
(
'bg.png'
)
right
=
pygame
.
image
.
load
(
'right.png'
)
food
=
pygame
.
image
.
load
(
'apple.png'
)
body
=
pygame
.
image
.
load
(
'body.png'
)
left
=
pygame
.
image
.
load
(
'left.png'
)
up
=
pygame
.
image
.
load
(
'up.png'
)
down
=
pygame
.
image
.
load
(
'down.png'
)
# 创建一个窗口
# 创建一个窗口
asd
=
pygame
.
display
.
set_mode
()
pygame
.
time
.
Clock
()
p
=
[(
180
,
90
),(
180
,
120
),(
210
,
120
),(
x
,
y
)]
\ No newline at end of file
s
=
'right'
w
=
right
while
True
:
for
i
in
pygame
.
event
.
get
():
print
(
i
)
if
i
.
type
==
locals
.
QUIT
:
exit
()
elif
i
.
type
==
locals
.
KEYDOWN
:
if
i
.
key
==
locals
.
K_RIGHT
and
s
!=
'left'
:
s
=
'right'
w
=
right
if
i
.
key
==
locals
.
K_LEFT
and
s
!=
'right'
:
s
=
'left'
w
=
left
if
i
.
key
==
locals
.
K_DOWN
and
s
!=
'up'
:
s
=
'down'
w
=
down
if
i
.
key
==
locals
.
K_UP
and
s
!=
'down'
:
s
=
'up'
w
=
up
if
s
==
'right'
:
x
+=
30
elif
s
==
'left'
:
x
-=
30
elif
s
==
'up'
:
y
-=
30
else
:
y
+=
30
p
.
append
((
x
,
y
))
p
.
pop
(
0
)
screen
.
blit
(
breakgrade
,(
0
,
0
))
screen
.
blit
(
food
,(
360
,
300
))
screen
.
blit
(
w
,
p
[
-
1
])
for
i
in
range
(
len
(
p
)
-
1
):
screen
.
blit
(
body
,
p
[
i
])
pygame
.
display
.
update
()
F
.
tick
(
3
)
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