Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson1_2
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
32f39f10
authored
May 22, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
c6188a1e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
2 deletions
bg.png
body.png
snake.py
bg.png
View file @
32f39f10
22.5 KB
|
W:
|
H:
6.93 KB
|
W:
|
H:
2-up
Swipe
Onion skin
body.png
View file @
32f39f10
1.4 KB
|
W:
|
H:
663 Bytes
|
W:
|
H:
2-up
Swipe
Onion skin
snake.py
View file @
32f39f10
import
pygame
import
pygame
from
pygame
import
locals
# 初始化pygame,为使用pygame做准备
# 初始化pygame,为使用pygame做准备
pygame
.
init
()
pygame
.
init
()
# 创建一个窗口
# 创建一个窗口
??
screen
=
pygame
.
display
.
set_mode
((
800
,
600
))
\ No newline at end of file
clock
=
pygame
.
time
.
Clock
()
#设置随机刻
#载入图片
bg
=
pygame
.
image
.
load
(
'bg.png'
)
up
=
pygame
.
image
.
load
(
'up.png'
)
body
=
pygame
.
image
.
load
(
'body.png'
)
apple
=
pygame
.
image
.
load
(
'apple.png'
)
x
,
y
=
240
,
360
position
=
[(
240
,
360
),(
240
,
390
),(
240
,
420
),(
x
,
y
)]
#存储三个身体和蛇头的位置
while
True
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
exit
()
y
-=
30
position
.
append
((
x
,
y
))
#把xy追加到列表末尾
position
.
pop
(
0
)
#删除列表第一项
#图片渲染
screen
.
blit
(
bg
,(
0
,
0
))
screen
.
blit
(
up
,
position
[
-
1
])
for
i
in
range
(
len
(
position
)
-
1
):
screen
.
blit
(
body
,
position
[
i
])
screen
.
blit
(
apple
,(
0
,
30
))
#渲染苹果
pygame
.
display
.
update
()
#刷新画面
clock
.
tick
(
1
)
#控制随机刻
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