Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson3_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
b2603901
authored
Dec 30, 2023
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
9cd0652a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
3 deletions
snake.py
snake.py
View file @
b2603901
import
pygame
from
pygame
import
locals
#locals为pygame子模块(必写)
from
random
import
*
import
random
#初始化pygame,为使用硬件做准备
pygame
.
init
()
#创建一个窗口
...
...
@@ -14,7 +14,7 @@ body=pygame.image.load('body.png')
left
=
pygame
.
image
.
load
(
'left.png'
)
up
=
pygame
.
image
.
load
(
'up.png'
)
down
=
pygame
.
image
.
load
(
'down.png'
)
my_font
=
pygame
.
image
.
Font
(
'neuropol.ttf'
,
18
)
#字体
my_font
=
pygame
.
font
.
Font
(
'neuropol.ttf'
,
18
)
#字体
x
,
y
=
240
,
120
position
=
[(
180
,
90
),
(
180
,
120
),
(
210
,
120
),
(
x
,
y
)]
...
...
@@ -42,12 +42,16 @@ while True:
#设置贪吃蛇的头部坐标
if
setheading
==
'right'
:
x
+=
30
snake_head
=
right
elif
setheading
==
'left'
:
x
-=
30
snake_head
=
left
elif
setheading
==
'up'
:
y
-=
30
snake_head
=
up
else
:
y
+=
30
snake_head
=
down
position
.
append
((
x
,
y
))
#刷新苹果
if
x
==
a_x
and
y
==
a_y
:
...
...
@@ -71,7 +75,7 @@ while True:
screen
.
blit
(
food
,(
a_x
,
a_y
))
#绘制分数
info
=
'Score:'
+
str
(
score
)
text
=
my_font
.
render
(
info
,
T
ur
e
,(
0
,
0
,
0
))
text
=
my_font
.
render
(
info
,
T
ru
e
,(
0
,
0
,
0
))
screen
.
blit
(
text
,(
540
,
10
))
#刷新画面
pygame
.
display
.
update
()
...
...
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