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
99ccecfb
authored
Sep 05, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
ee72422e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
3 deletions
snake.py
snake.py
View file @
99ccecfb
import
pygame
pygame
.
init
()
screen
=
pygame
.
display
.
set_mode
((
660
,
480
))
#创建一个660*480的窗口
from
pygame
import
locals
pygame
.
init
()
#初始化pygame
screen
=
pygame
.
display
.
set_mode
((
660
,
480
))
#创建一个660*480的窗口
FPSCLOCK
=
pygame
.
time
.
Clock
()
#控制游戏速度
#背景
background
=
pygame
.
image
.
load
(
"bg.png"
)
#将图片"bg.png"导入到图片中
apple
=
pygame
.
image
.
load
(
"apple.png"
)
head
=
pygame
.
image
.
load
(
"right.png"
)
body
=
pygame
.
image
.
load
(
"body.png"
)
#头的坐标
x
,
y
=
(
240
,
120
)
position
=
[(
180
,
90
),(
180
,
120
),(
210
,
120
),(
x
,
y
)]
while
True
:
for
event
in
pygame
.
event
.
get
():
#遍历/监听
#退出程序
if
event
.
type
==
locals
.
QUIT
:
exit
()
#停止游戏
x
+=
30
position
.
append
((
x
,
y
))
position
.
pop
(
0
)
screen
.
blit
(
background
,(
0
,
0
))
#渲染图片
screen
.
blit
(
apple
,(
600
,
60
))
screen
.
blit
(
head
,(
x
,
y
))
for
i
in
range
(
len
(
position
)
-
1
):
screen
.
blit
(
body
,
position
[
i
])
#screen.blit(body,(210,120))
#screen.blit(body,(180,120))
#screen.blit(body,(180,90))
#刷新页面
pygame
.
display
.
update
()
FPSCLOCK
.
tick
(
3
)
\ 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