Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson8_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
482b1407
authored
May 22, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
da1f0bb9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
35 deletions
my_game.py
my_game.py
View file @
482b1407
...
...
@@ -42,7 +42,7 @@ jumpState = "runing"
t
=
30
time
=
0
changex
=
0
gamestate
=
Fals
e
gamestate
=
Tru
e
while
True
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
...
...
@@ -52,11 +52,12 @@ while True:
if
jumpState
==
"runing"
:
if
event
.
key
==
locals
.
K_SPACE
:
jumpState
=
"up"
if
changex
<=-
1000
:
# 路的移动
changex
=
0
else
:
changex
-=
8
if
gamestate
==
False
:
wukong
=
Player
(
hero
[
index
])
if
jumpState
==
"runing"
:
# 跑步状态下
index
+=
1
if
index
>=
5
:
index
=
0
if
gamestate
==
True
:
if
jumpState
==
"up"
:
# 起跳状态
if
t
>
0
:
y
-=
t
...
...
@@ -72,31 +73,32 @@ while True:
else
:
jumpState
=
"runing"
t
=
30
# 悟空造型
wukong
=
Player
(
hero
[
index
])
if
jumpState
==
"runing"
:
# 跑步状态下
index
+=
1
if
index
>=
5
:
index
=
0
# 将背景图画上去
time
+=
1
if
time
>=
60
:
time
=
0
number
=
random
.
randint
(
0
,
50
)
if
number
>
20
:
obstacle
=
Block
(
stone
,
cacti
,
bush
)
group
.
add
(
obstacle
)
screen
.
blit
(
background
,
(
0
,
0
))
# 远处背景
screen
.
blit
(
road
,
(
changex
,
500
))
# 路
screen
.
blit
(
wukong
.
image
,
(
150
,
y
))
# 悟空
for
sprite
in
group
:
screen
.
blit
(
sprite
.
image
,
(
sprite
.
rect
.
x
,
sprite
.
rect
.
y
))
sprite
.
rect
.
x
-=
8
if
sprite
.
rect
.
x
<=
0
-
sprite
.
rect
.
width
:
# 障碍物消失
sprite
.
kill
()
# 刷新画面
pygame
.
display
.
update
()
FPS
.
tick
(
30
)
pygame
.
sprite
.
collide_rect
()
\ No newline at end of file
if
changex
<=-
1000
:
# 路的移动
changex
=
0
else
:
changex
-=
8
# 悟空造型
# 将背图画上去
time
+=
1
if
time
>=
60
:
time
=
0
number
=
random
.
randint
(
0
,
50
)
if
number
>
20
:
obstacle
=
Block
(
stone
,
cacti
,
bush
)
group
.
add
(
obstacle
)
screen
.
blit
(
background
,
(
0
,
0
))
# 远处背景
screen
.
blit
(
road
,
(
changex
,
500
))
# 路
screen
.
blit
(
wukong
.
image
,
(
150
,
y
))
# 悟空
for
sprite
in
group
:
screen
.
blit
(
sprite
.
image
,
(
sprite
.
rect
.
x
,
sprite
.
rect
.
y
))
sprite
.
rect
.
x
-=
8
if
sprite
.
rect
.
x
<=
0
-
sprite
.
rect
.
width
:
# 障碍物消失
sprite
.
kill
()
if
pygame
.
sprite
.
collide_rect
(
wukong
,
sprite
):
gameover
=
pygame
.
image
.
load
(
'gameover.png'
)
screen
.
blit
(
gameover
,(
400
,
200
))
gamestate
=
False
# 刷新画面
pygame
.
display
.
update
()
FPS
.
tick
(
30
)
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