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
8312a34b
authored
Nov 19, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
672e21f2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
5 deletions
snake.py
snake.py
View file @
8312a34b
...
@@ -53,6 +53,7 @@ while True:
...
@@ -53,6 +53,7 @@ while True:
if
event
.
key
==
locals
.
K_DOWN
and
setheading
!=
"up"
:
if
event
.
key
==
locals
.
K_DOWN
and
setheading
!=
"up"
:
setheading
=
"down"
setheading
=
"down"
snake_tou
=
down
snake_tou
=
down
# 蛇头根据方向变换
# 蛇头根据方向变换
if
snake_tou
==
right
:
if
snake_tou
==
right
:
x
+=
30
x
+=
30
...
@@ -62,20 +63,32 @@ while True:
...
@@ -62,20 +63,32 @@ while True:
y
-=
30
y
-=
30
else
:
else
:
y
+=
30
y
+=
30
# 根据位置更改列表
position
.
append
((
x
,
y
))
position
.
append
((
x
,
y
))
position
.
pop
(
0
)
position
.
pop
(
0
)
# FPSCLOCK方法
FPSCLOCK
.
tick
(
3
)
FPSCLOCK
.
tick
(
3
)
# 将背景图画上去
# 渲染背景
screen
.
blit
(
background
,
(
0
,
0
))
screen
.
blit
(
background
,
(
0
,
0
))
# 将贪吃蛇画上去
# 渲染蛇头
screen
.
blit
(
snake_tou
,
position
[
-
1
])
screen
.
blit
(
snake_tou
,
position
[
-
1
])
# 将贪吃蛇的身体画上去
# 渲染蛇身
# 通过列表遍历渲染蛇身
for
i
in
range
(
len
(
position
)
-
1
):
for
i
in
range
(
len
(
position
)
-
1
):
screen
.
blit
(
body
,
position
[
i
])
screen
.
blit
(
body
,
position
[
i
])
# 以下为调试方法
#screen.blit(body, (x-30, y))
#screen.blit(body, (x-30, y))
#screen.blit(body, (x-60, y))
#screen.blit(body, (x-60, y))
#screen.blit(body, (x-60, y-30))
#screen.blit(body, (x-60, y-30))
# 将果实画上去
# 渲染食物
screen
.
blit
(
food
,
(
360
,
180
))
screen
.
blit
(
food
,
(
360
,
180
))
# 刷新画面
# 更新画面
pygame
.
display
.
update
()
pygame
.
display
.
update
()
\ 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