Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson1_4
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
1d81c87e
authored
Jan 21, 2024
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
781e00c6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
2 deletions
snake.py
snake.py
View file @
1d81c87e
...
@@ -12,16 +12,20 @@ snake_head_r = pygame.image.load("right.png")
...
@@ -12,16 +12,20 @@ snake_head_r = pygame.image.load("right.png")
apple
=
pygame
.
image
.
load
(
"apple.png"
)
apple
=
pygame
.
image
.
load
(
"apple.png"
)
# 加载蛇身图片
# 加载蛇身图片
snake_body
=
pygame
.
image
.
load
(
"body.png"
)
snake_body
=
pygame
.
image
.
load
(
"body.png"
)
x
=
210
while
True
:
while
True
:
# 监测事件(玩家操作)
# 监测事件(玩家操作)
for
event
in
pygame
.
event
.
get
():
for
event
in
pygame
.
event
.
get
():
print
(
event
)
if
event
.
type
==
2
:
if
event
.
key
==
275
:
x
+=
30
if
event
.
type
==
locals
.
QUIT
:
if
event
.
type
==
locals
.
QUIT
:
exit
()
exit
()
# 渲染背景图片
# 渲染背景图片
screen
.
blit
(
background
,(
0
,
0
))
screen
.
blit
(
background
,(
0
,
0
))
# 渲染蛇头图片
# 渲染蛇头图片
screen
.
blit
(
snake_head_r
,(
210
,
90
))
screen
.
blit
(
snake_head_r
,(
x
,
90
))
# 渲染苹果图片
# 渲染苹果图片
screen
.
blit
(
apple
,(
300
,
450
))
screen
.
blit
(
apple
,(
300
,
450
))
# 渲染蛇身图片
# 渲染蛇身图片
...
...
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