Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson1_3
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
a3c1b8fc
authored
Mar 11, 2023
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
6de8de98
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
6 deletions
bg.png
snake.py
bg.png
View file @
a3c1b8fc
This diff is collapsed.
Click to expand it.
snake.py
View file @
a3c1b8fc
...
...
@@ -8,17 +8,35 @@ pygame.init()
beijing
=
pygame
.
image
.
load
(
'bg.png'
)
apple
=
pygame
.
image
.
load
(
'apple.png'
)
juese
=
pygame
.
image
.
load
(
'right.png'
)
shenti
=
pygame
.
image
.
load
(
'body.png'
)
# 创建一个窗口
screen
=
pygame
.
display
.
set_mode
((
1080
,
1361
))
screen
=
pygame
.
display
.
set_mode
((
660
,
480
))
FPS
=
pygame
.
time
.
Clock
()
#pygame时钟,设置游戏速度(帧数)
x
,
y
=
240
,
120
zuobiao
=
[(
180
,
90
),(
180
,
120
),(
210
,
120
),(
x
,
y
)]
#身体和头的坐标库
while
True
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
# 退出程序
exit
()
#向右走
x
+=
30
zuobiao
.
append
((
x
,
y
))
#增加一个头的坐标进入列表
zuobiao
.
pop
(
0
)
#删掉第一个坐标
#将背景画上去
screen
.
blit
(
beijing
,(
0
,
0
))
screen
.
blit
(
juese
,(
0
,
0
))
screen
.
blit
(
apple
,(
0
,
50
))
#把头画上去
screen
.
blit
(
juese
,
zuobiao
[
-
1
])
#把身体画上去
for
i
in
range
(
len
(
zuobiao
)
-
1
):
screen
.
blit
(
shenti
,
zuobiao
[
i
])
#把苹果画上去
screen
.
blit
(
apple
,(
0
,
60
))
#刷新画面
pygame
.
display
.
update
()
\ No newline at end of file
pygame
.
display
.
update
()
FPS
.
tick
(
2
)
\ 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