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
c94f94a9
authored
Oct 15, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
b4da62d0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
18 deletions
Mojangles.ttf
snake.py
Mojangles.ttf
0 → 100644
View file @
c94f94a9
File added
snake.py
View file @
c94f94a9
...
...
@@ -8,6 +8,7 @@ pygame.init()
# 创建一个窗口
screen
=
pygame
.
display
.
set_mode
((
660
,
480
))
FPSCLOCK
=
pygame
.
time
.
Clock
()
# pygame时钟,控制游戏速度(帧数)
text
=
pygame
.
font
.
Font
(
"Mojangles.ttf"
,
18
)
# 背景
background
=
pygame
.
image
.
load
(
'bg.png'
)
...
...
@@ -25,6 +26,7 @@ apple_x , apple_y = 360 , 330
setheading
=
"right"
snake_head
=
right
score
=
0
while
True
:
for
event
in
pygame
.
event
.
get
():
...
...
@@ -57,8 +59,9 @@ while True:
position
.
append
((
x
,
y
))
#贪吃蛇被吃了
if
x
==
apple_x
and
y
==
apple_y
:
apple_x
=
random
.
randint
(
0
,
22
)
*
30
-
30
apple_y
=
random
.
randint
(
0
,
16
)
*
30
-
30
apple_x
=
random
.
randint
(
1
,
22
)
*
30
-
30
apple_y
=
random
.
randint
(
1
,
16
)
*
30
-
30
score
+=
10
else
:
position
.
pop
(
0
)
# 将背景图画上去
...
...
@@ -70,22 +73,8 @@ while True:
screen
.
blit
(
body
,
position
[
i
])
# 将果实画上去
screen
.
blit
(
food
,
(
apple_x
,
apple_y
))
screen
.
blit
(
food
,
(
apple_x
,
apple_y
))
screen
.
blit
(
text
.
render
(
"Score:"
+
str
(
score
),
True
,(
0
,
0
,
0
)),(
540
,
10
))
# 刷新画面
pygame
.
display
.
update
()
FPSCLOCK
.
tick
(
5
)
\ 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