Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson1_4
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
04ee1487
authored
Nov 27, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
d3ad8ed7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
7 deletions
snake.py
snake.py
View file @
04ee1487
...
@@ -2,26 +2,31 @@ import pygame
...
@@ -2,26 +2,31 @@ import pygame
from
pygame
import
locals
from
pygame
import
locals
pygame
.
init
()
#初始化pygame
pygame
.
init
()
#初始化pygame
screen
=
pygame
.
display
.
set_mode
((
660
,
480
))
#创建窗口
screen
=
pygame
.
display
.
set_mode
((
660
,
480
))
#创建窗口
FPSCLOCK
=
pygame
.
time
.
Clock
()
FPSCLOCK
=
pygame
.
time
.
Clock
()
#设置计时器
#导入图片
#导入图片
background
=
pygame
.
image
.
load
(
'bg.png'
)
background
=
pygame
.
image
.
load
(
'bg.png'
)
right
=
pygame
.
image
.
load
(
'right.png'
)
right
=
pygame
.
image
.
load
(
'right.png'
)
apple
=
pygame
.
image
.
load
(
'apple.png'
)
apple
=
pygame
.
image
.
load
(
'apple.png'
)
body
=
pygame
.
image
.
load
(
'body.png'
)
body
=
pygame
.
image
.
load
(
'body.png'
)
x
=
210
x
=
210
#设置定量
y
=
120
y
=
120
weizhi
=
[(
180
,
120
),(
150
,
120
),(
150
,
90
),(
x
,
y
)]
#创建列表
while
True
:
#永久存在
while
True
:
#永久存在
for
event
in
pygame
.
event
.
get
():
#遍历pygame中的事件
for
event
in
pygame
.
event
.
get
():
#遍历pygame中的事件
if
event
.
type
==
locals
.
QUIT
:
#如果是退出事件,QUIT其实是一个常量,ctcl+鼠标点locals可以查看
if
event
.
type
==
locals
.
QUIT
:
#如果是退出事件,QUIT其实是一个常量,ctcl+鼠标点locals可以查看
exit
()
#退出
exit
()
#退出
x
+=
30
x
+=
30
weizhi
.
append
((
x
,
y
))
#增加新坐标,是坐标不是索引
weizhi
.
pop
(
0
)
#删除旧坐标
#渲染图片,后为坐标,左上角为0,0,一小格左上角坐标为30的倍数
#渲染图片,后为坐标,左上角为0,0,一小格左上角坐标为30的倍数
screen
.
blit
(
background
,(
0
,
0
))
screen
.
blit
(
background
,(
0
,
0
))
screen
.
blit
(
right
,(
x
,
y
))
screen
.
blit
(
right
,(
x
,
y
))
screen
.
blit
(
apple
,(
30
,
30
))
screen
.
blit
(
apple
,(
30
,
30
))
screen
.
blit
(
body
,(
180
,
120
))
for
i
in
range
(
len
(
weizhi
)
-
1
):
screen
.
blit
(
body
,(
150
,
120
))
screen
.
blit
(
body
,
weizhi
[
i
])
screen
.
blit
(
body
,(
150
,
90
))
#screen.blit(body,(180,120))
#screen.blit(body,(150,120))
#screen.blit(body,(150,90))
#刷新窗口
#刷新窗口
pygame
.
display
.
update
()
pygame
.
display
.
update
()
FPSCLOCK
.
tick
(
3
)
FPSCLOCK
.
tick
(
3
)
#控制帧数不超过3
\ No newline at end of file
\ 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