Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson3_diy1
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
1fe7b89f
authored
Jul 16, 2023
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
0f4da355
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
17 deletions
5cf41a52c76757fc9a6333a36e6f3fba.jpg
kk.jpg
snake.py
5cf41a52c76757fc9a6333a36e6f3fba.jpg
0 → 100644
View file @
1fe7b89f
67.4 KB
kk.jpg
0 → 100644
View file @
1fe7b89f
67.4 KB
snake.py
View file @
1fe7b89f
...
@@ -6,11 +6,11 @@ score=0
...
@@ -6,11 +6,11 @@ score=0
pygame
.
init
()
pygame
.
init
()
# 创建一个窗口
# 创建一个窗口
screen
=
pygame
.
display
.
set_mode
((
660
,
4
80
))
screen
=
pygame
.
display
.
set_mode
((
1080
,
10
80
))
FPSCLOCK
=
pygame
.
time
.
Clock
()
# pygame时钟,控制游戏速度(帧数)
FPSCLOCK
=
pygame
.
time
.
Clock
()
# pygame时钟,控制游戏速度(帧数)
# 背景
# 背景
background
=
pygame
.
image
.
load
(
'
bg.pn
g'
)
background
=
pygame
.
image
.
load
(
'
kk.jp
g'
)
right
=
pygame
.
image
.
load
(
'right.png'
)
# 头 朝右
right
=
pygame
.
image
.
load
(
'right.png'
)
# 头 朝右
food
=
pygame
.
image
.
load
(
'apple.png'
)
# 食物 苹果
food
=
pygame
.
image
.
load
(
'apple.png'
)
# 食物 苹果
body
=
pygame
.
image
.
load
(
'body.png'
)
# 身体
body
=
pygame
.
image
.
load
(
'body.png'
)
# 身体
...
@@ -34,29 +34,25 @@ while True:
...
@@ -34,29 +34,25 @@ while True:
# 接收到退出事件后退出程序
# 接收到退出事件后退出程序
exit
()
exit
()
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
key
==
locals
.
K_RIGHT
and
setheading
!=
"left"
:
if
event
.
key
==
locals
.
K_RIGHT
and
setheading
!=
"left"
:
setheading
=
'right'
setheading
=
"right"
snake_head
=
right
if
event
.
key
==
locals
.
K_LEFT
and
setheading
!=
"right"
:
if
event
.
key
==
locals
.
K_LEFT
and
setheading
!=
"right"
:
setheading
=
'left'
setheading
=
"left"
snake_head
=
left
if
event
.
key
==
locals
.
K_UP
and
setheading
!=
"down"
:
if
event
.
key
==
locals
.
K_UP
and
setheading
!=
"down"
:
setheading
=
'up'
setheading
=
"up"
snake_head
=
up
if
event
.
key
==
locals
.
K_DOWN
and
setheading
!=
"up"
:
if
event
.
key
==
locals
.
K_DOWN
and
setheading
!=
"up"
:
setheading
=
'down'
setheading
=
"down"
snake_head
=
down
# 设置贪吃蛇的头部坐标
if
setheading
==
"right"
:
if
setheading
==
"right"
:
x
+=
30
x
+=
30
elif
setheading
==
"left"
:
elif
setheading
==
"left"
:
x
-=
30
x
-=
30
elif
setheading
==
"up"
:
elif
setheading
==
"up"
:
y
-=
30
y
-=
30
else
:
else
:
y
+=
30
y
+=
30
position
.
append
((
x
,
y
))
position
.
append
((
x
,
y
))
if
x
==
food_x
and
y
==
food_y
:
if
x
==
food_x
and
y
==
food_y
:
d_x
=
random
.
randint
(
1
,
22
)
d_x
=
random
.
randint
(
1
,
22
)
d_y
=
random
.
randint
(
1
,
16
)
d_y
=
random
.
randint
(
1
,
16
)
...
@@ -76,4 +72,6 @@ while True:
...
@@ -76,4 +72,6 @@ while True:
fen
=
font
.
render
(
text
,
True
,(
0
,
0
,
0
))
fen
=
font
.
render
(
text
,
True
,(
0
,
0
,
0
))
screen
.
blit
(
fen
,(
540
,
0
))
screen
.
blit
(
fen
,(
540
,
0
))
# 将果实画上去
# 将果实画上去
screen
.
blit
(
food
,
(
food_x
,
food_y
))
screen
.
blit
(
food
,
(
food_x
,
food_y
))
\ No newline at end of file
pygame
.
display
.
update
()
FPSCLOCK
.
tick
(
20
)
\ 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