Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson3_diy4
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
4c156670
authored
Jul 17, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
a0c8c9ed
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
10 deletions
snake.py
snake.py
View file @
4c156670
...
@@ -49,37 +49,46 @@ while True:
...
@@ -49,37 +49,46 @@ while True:
# 设置贪吃蛇的头部坐标
# 设置贪吃蛇的头部坐标
if
setheading
==
"right"
:
if
setheading
==
"right"
:
x
+=
3
0
x
+=
1
0
elif
setheading
==
"left"
:
elif
setheading
==
"left"
:
x
-=
3
0
x
-=
1
0
elif
setheading
==
"up"
:
elif
setheading
==
"up"
:
y
-=
3
0
y
-=
1
0
else
:
else
:
y
+=
3
0
y
+=
1
0
position
.
append
((
x
,
y
))
position
.
append
((
x
,
y
))
# 将背景图画上去
# 将背景图画上去
screen
.
blit
(
background
,
(
0
,
0
))
screen
.
blit
(
background
,
(
0
,
0
))
# 将贪吃蛇的头画上去
# 将贪吃蛇的头画上去
screen
.
blit
(
snake_head
,
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
(
snake_head
,
position
[
-
1
])
info
=
'SOCRE:'
+
str
(
s
)
+
'!'
info
=
'SOCRE:'
+
str
(
s
)
+
'!'
text
=
mf
.
render
(
info
,
True
,(
0
,
0
,
0
))
text
=
mf
.
render
(
info
,
True
,(
0
,
0
,
0
))
screen
.
blit
(
text
,(
540
,
10
))
screen
.
blit
(
text
,(
540
,
10
))
# 将果实画上去
# 将果实画上去
screen
.
blit
(
food
,
(
apple_x
,
apple_y
))
screen
.
blit
(
food
,
(
apple_x
,
apple_y
))
if
x
==
apple_x
and
y
==
apple_y
:
if
x
==
apple_x
and
y
==
apple_y
:
t
+=
0.2
if
s
<
5
:
t
+=
0.2
if
s
>=
5
and
s
<
10
:
t
+=
0.5
if
s
>=
10
and
s
<
20
:
t
+=
0.7
if
s
>=
20
:
t
+=
1
s
+=
1
s
+=
1
long
=
1
long
=
1
apple_x
=
random
.
randint
(
1
,
22
)
*
30
-
30
apple_x
=
random
.
randint
(
2
,
22
)
*
30
-
30
apple_y
=
random
.
randint
(
1
,
16
)
*
30
-
30
apple_y
=
random
.
randint
(
2
,
16
)
*
30
-
30
if
long
==
0
:
if
long
==
0
:
position
.
pop
(
0
)
position
.
pop
(
0
)
if
x
<
0
or
y
<
0
or
x
>
630
or
y
>
450
:
exit
()
# 刷新画面
# 刷新画面
pygame
.
display
.
update
()
pygame
.
display
.
update
()
FPSCLOCK
.
tick
(
t
)
FPSCLOCK
.
tick
(
t
)
\ 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