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
781e00c6
authored
Jan 19, 2024
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
7332c175
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
2 deletions
snake.py
snake.py
View file @
781e00c6
import
pygame
import
pygame
from
pygame
import
locals
#初始化
pygame
.
init
()
pygame
.
init
()
#创建一个窗口(640*480)
screen
=
pygame
.
display
.
set_mode
((
640
,
480
))
screen
=
pygame
.
display
.
set_mode
((
640
,
480
))
#加载背景图片
background
=
pygame
.
image
.
load
(
"bg.png"
)
# 加载蛇头图片
snake_head_r
=
pygame
.
image
.
load
(
"right.png"
)
# 加载苹果图片
apple
=
pygame
.
image
.
load
(
"apple.png"
)
# 加载蛇身图片
snake_body
=
pygame
.
image
.
load
(
"body.png"
)
while
True
:
# 监测事件(玩家操作)
for
event
in
pygame
.
event
.
get
():
print
(
event
)
if
event
.
type
==
locals
.
QUIT
:
exit
()
# 渲染背景图片
screen
.
blit
(
background
,(
0
,
0
))
# 渲染蛇头图片
screen
.
blit
(
snake_head_r
,(
210
,
90
))
# 渲染苹果图片
screen
.
blit
(
apple
,(
300
,
450
))
# 渲染蛇身图片
screen
.
blit
(
snake_body
,(
180
,
90
))
# 刷新
pygame
.
display
.
update
()
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