Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson3_diy3
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
a3d77790
authored
4 years ago
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
3e42cb6f
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
45 deletions
snake.py
snake.py
View file @
a3d77790
fekheljsvbeskrfdv
,
sed
import
pygame
rekhsfdljkeajsfdnkjejwafsmcrkjdfkjsef
from
pygame
import
locals
ghvjfjh
jfvjffvjrlf
# 初始化pygame,为使用硬件做准备
hjhgjkshghgsjgljreksdjgj
;
oiu
'oi;os
pygame
.
init
()
kgjdjbkjawijflk/jrealjlkj;lambdanvankjhejjalkj
jjkvjlijejrlkjlkvjl'
# 创建一个窗口
bvjakhkhkvjhkjhjhkjsjjj
screen
=
pygame
.
display
.
set_mode
((
660
,
480
))
hkjvjijtssfosurghvvnx
,
fjxlf
FPSCLOCK
=
pygame
.
time
.
Clock
()
# pygame时钟,控制游戏速度(帧数)
kjwefje
;
jsjrsbkjtskjsxhkkjr
jsjdkrjkvjkjhhvdfh
# 背景
vsjjrvkjsevkjshfslhvlhflec
background
=
pygame
.
image
.
load
(
'bg.png'
)
sejkjvwe
;
ljvsksefjwerjkjf
right
=
pygame
.
image
.
load
(
'right.png'
)
# 头 朝右
;
lwjlkwe
.
hkthkwej
.
welwel
food
=
pygame
.
image
.
load
(
'apple.png'
)
# 食物 苹果
jvlkjekjf
.
jvsejfsejjkjlkjjvlkj
\
ks
body
=
pygame
.
image
.
load
(
'body.png'
)
# 身体
jvsejfsejjkjlkjjvlkjjvj
left
=
pygame
.
image
.
load
(
'left.png'
)
# 头 朝左
jcj
up
=
pygame
.
image
.
load
(
'up.png'
)
# 头 朝上
咳咳咳看看我
down
=
pygame
.
image
.
load
(
'down.png'
)
# 头 朝下
jflkwdjw
ijlejvejvejjle
x
,
y
=
240
,
120
iuiweljkwkvlevjekvjev
position
=
[(
180
,
90
),
(
180
,
120
),
(
210
,
120
),
(
x
,
y
)]
愿意为此哦佛问佛覅
apple
-
x
=
300
闻绯闻丑闻
apple
-
y
=
360
热尔俄而热
热呃呃呃
j
;
jjkjvlwjvjw
setheading
=
"right"
jjljwevjlkj
/
lkeqwe
snake_head
=
right
kgjdjbkjawijflkg
getattr
(
g
while
True
:
g
for
event
in
pygame
.
event
.
get
():
g
if
event
.
type
==
locals
.
QUIT
:
g
# 接收到退出事件后退出程序
g
exit
()
ytt
if
event
.
type
==
locals
.
KEYDOWN
:
m
if
event
.
key
==
locals
.
K_RIGHT
and
setheading
!=
"left"
:
t
setheading
=
'right'
tdjtm
snake_head
=
right
n
if
event
.
key
==
locals
.
K_LEFT
and
setheading
!=
"right"
:
)
setheading
=
'left'
tkrgljelsjtrlkwjflkrejgjlk
snake_head
=
left
kg
;
tkblrb
;
lekkbk
;
if
event
.
key
==
locals
.
K_UP
and
setheading
!=
"down"
:
knyl
;
ltkdk
;
lMT
setheading
=
'up'
';mt
snake_head
=
up
;d;K'
;
d
,
j
.
kdnjmektdlkjtf
'
if
event
.
key
==
locals
.
K_DOWN
and
setheading
!=
"up"
:
eoor[ijtf'
ryitk
']
setheading
=
'down'
\ No newline at end of file
snake_head
=
down
# 设置贪吃蛇的头部坐标
if
setheading
==
"right"
:
x
+=
30
elif
setheading
==
"left"
:
x
-=
30
elif
setheading
==
"up"
:
y
-=
30
else
:
y
+=
30
position
.
append
((
x
,
y
))
if
x
==
apple
-
x
and
y
==
apple
-
y
:
apple
-
x
=
random
.
randin
(
0
,
660
)
apple
-
y
=
random
.
randin
(
0
,
440
)
position
.
pop
(
0
)
# 将背景图画上去
screen
.
blit
(
background
,
(
0
,
0
))
# 将贪吃蛇的头画上去
screen
.
blit
(
snake_head
,
position
[
-
1
])
# 将贪吃蛇的身体画上去
for
i
in
range
(
len
(
position
)
-
1
):
screen
.
blit
(
body
,
position
[
i
])
# 将果实画上去
screen
.
blit
(
food
,
(
360
,
300
))
# 刷新画面
pygame
.
display
.
update
()
FPSCLOCK
.
tick
(
3
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
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