Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson7_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
0245f4e3
authored
Sep 25, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
1f6e57ef
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
0 deletions
my_game.py
my_game.py
View file @
0245f4e3
...
...
@@ -6,6 +6,8 @@ pygame.init() # 初始化
screen
=
pygame
.
display
.
set_mode
((
1000
,
600
))
FPS
=
pygame
.
time
.
Clock
()
# pygame时钟,控制游戏速度(帧数)
pygame
.
display
.
set_caption
(
'悟空酷跑'
)
class
Block
(
pygame
.
sprite
.
Sprite
):
# 载入图片
background
=
pygame
.
image
.
load
(
'bg.png'
)
# 背景
road
=
pygame
.
image
.
load
(
'road.png'
)
# 路
...
...
@@ -23,10 +25,13 @@ jumpState = 'runing'
y
=
400
bg_x
=
0
road_x
=
0
time
=
0
obstable
=
random
.
choice
([
apple
,
stone
,
cacti
])
rect
=
obstable
.
get_rect
()
rect
.
x
=
1000
rect
.
y
=
500
-
rect
.
height
block_list
=
pygame
.
sprite
.
Group
()
while
True
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
...
...
@@ -68,6 +73,18 @@ while True:
screen
.
blit
(
background
,
(
bg_x
,
0
))
screen
.
blit
(
road
,
(
road_x
,
500
))
screen
.
blit
(
wukong
,
(
150
,
y
))
time
+=
1
if
time
>=
60
:
r
=
random
.
randint
(
0
,
100
)
if
r
>
40
:
obstable
=
Block
(
bush
,
cacti
,
stone
)
block_list
.
add
(
obstable
)
time
=
0
for
prop
in
block_list
:
prop
.
rect
.
x
-=
8
screen
.
blit
(
prop
.
image
,(
prop
.
rect
.
x
,
prop
.
rect
.
y
))
if
prop
.
rect
.
x
<
0
-
prop
.
rect
.
width
:
prop
.
kill
()
if
rect
.
x
<=
0
-
rect
.
width
:
obstable
=
random
.
choice
([
apple
,
stone
,
cacti
])
rect
=
obstable
.
get_rect
()
...
...
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