Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson3_diy2
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
cc5b34e7
authored
Dec 25, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
df29608d
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
4 deletions
snake.py
snake.py
View file @
cc5b34e7
...
...
@@ -6,7 +6,7 @@ from pygame import locals
pygame
.
init
()
# 创建一个窗口
screen
=
pygame
.
display
.
set_mode
((
66
0
,
480
))
screen
=
pygame
.
display
.
set_mode
((
66
1
,
481
))
FPSCLOCK
=
pygame
.
time
.
Clock
()
# pygame时钟,控制游戏速度(帧数)
# 背景
...
...
@@ -17,9 +17,10 @@ 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
=
x2
=
330
y2
=
330
x2
,
x3
,
x4
,
x5
,
x6
,
x7
,
x8
,
x9
,
x10
,
x11
=
330
y2
,
y3
,
y4
,
y5
,
y6
,
y7
,
y8
,
y9
,
y10
,
y11
=
330
x
,
y
=
240
,
120
position
=
[(
180
,
90
),
(
180
,
120
),
(
210
,
120
),
(
x
,
y
)]
...
...
@@ -57,7 +58,7 @@ while True:
y
+=
30
position
.
append
((
x
,
y
))
if
x2
==
x
and
y2
==
y
:
if
x2
or
x3
or
x4
or
x5
or
x6
or
x7
or
x8
or
x9
or
x10
or
x11
==
x
and
y2
or
y3
or
y4
or
y5
or
y6
or
y7
or
y8
or
y9
or
y10
or
y11
==
y
:
x2
=
random
.
randint
(
0
,
21
)
y2
=
random
.
randint
(
0
,
15
)
x2
=
x2
*
30
...
...
@@ -74,6 +75,19 @@ while True:
# 将果实画上去
screen
.
blit
(
food
,
(
x2
,
y2
))
screen
.
blit
(
food
,
(
x3
,
y2
))
screen
.
blit
(
food
,
(
x4
,
y2
))
screen
.
blit
(
food
,
(
x5
,
y2
))
screen
.
blit
(
food
,
(
x6
,
y2
))
screen
.
blit
(
food
,
(
x7
,
y2
))
screen
.
blit
(
food
,
(
x8
,
y2
))
screen
.
blit
(
food
,
(
x9
,
y2
))
screen
.
blit
(
food
,
(
x2
,
y2
))
screen
.
blit
(
food
,
(
x2
,
y2
))
# 刷新画面
pygame
.
display
.
update
()
FPSCLOCK
.
tick
(
4
)
\ 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