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
f52aa511
authored
Apr 07, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
15ec5fbf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
4 deletions
snake.py
test.py
snake.py
View file @
f52aa511
...
...
@@ -4,9 +4,50 @@ from pygame import locals
pygame
.
init
()
#pygame初始化
screen
=
pygame
.
display
.
set_mode
((
660
,
480
))
#创建游戏窗口
fpsclock
=
pygame
.
time
.
Clock
()
background
=
pygame
.
image
.
load
(
'bg.png'
)
#载入背景图片
food
=
pygame
.
image
.
load
(
'apple.png'
)
right
=
pygame
.
image
.
load
(
'right.png'
)
body
=
pygame
.
image
.
load
(
'body.png'
)
setheading
=
'right'
x
,
y
=
13
*
30
,
9
*
30
position
=
[(
9
*
30
,
8
*
30
),(
9
*
30
,
9
*
30
),(
10
*
30
,
9
*
30
),(
x
,
y
)]
while
True
:
for
event
in
pygame
.
event
.
get
():
print
(
event
)
if
event
.
type
==
locals
.
QUIT
:
exit
()
\ No newline at end of file
print
(
event
)
#窗口监听测试
if
event
.
type
==
locals
.
QUIT
:
#利用locals库简介监听类型
exit
()
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
type
==
locals
.
K_UP
and
setheading
!=
'down'
:
setheading
=
'up'
print
(
"wwwwww"
)
# if event.type == locals.K_DOWN and setheading != 'up':
# setheading = 'down'
# if event.type == locals.K_RIGHT and setheading != 'left':
# setheading = 'right'
# if event.type == locals.K_LEFT and setheading != 'right':
# setheading = 'left'
position
.
append
((
x
,
y
))
#利用列表排布坐标
position
.
pop
(
0
)
if
setheading
==
'right'
:
x
+=
30
# elif setheading == 'left':
# x-=30
# elif setheading == 'up':
# y-=30
else
:
y
+=
30
screen
.
blit
(
background
,(
0
,
0
))
#将图片资源布置到窗口中
screen
.
blit
(
right
,
position
[
-
1
])
for
i
in
range
(
len
(
position
)
-
1
):
screen
.
blit
(
body
,
position
[
i
])
screen
.
blit
(
food
,(
13
*
30
,
9
*
30
))
pygame
.
display
.
update
()
#刷新窗口
fpsclock
.
tick
(
3
)
\ No newline at end of file
test.py
0 → 100644
View file @
f52aa511
test
=
[
1
,
2
,
3
,
4
,
5
]
test
.
append
(
6
)
test
.
pop
(
0
)
print
(
test
)
\ 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