Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson8_diy4
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
b38035f5
authored
Feb 25, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
16663e79
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
2 deletions
my_game.py
my_game.py
View file @
b38035f5
...
@@ -42,6 +42,7 @@ road_x = 0
...
@@ -42,6 +42,7 @@ road_x = 0
bg_x
=
0
bg_x
=
0
obstacle
=
Black
(
bush
,
stone
,
cacti
)
obstacle
=
Black
(
bush
,
stone
,
cacti
)
time
=
0
time
=
0
gamestate
=
True
block_list
=
pygame
.
sprite
.
Group
()
block_list
=
pygame
.
sprite
.
Group
()
while
True
:
while
True
:
for
event
in
pygame
.
event
.
get
():
for
event
in
pygame
.
event
.
get
():
...
@@ -52,10 +53,12 @@ while True:
...
@@ -52,10 +53,12 @@ while True:
if
jumpState
==
"runing"
:
if
jumpState
==
"runing"
:
if
event
.
key
==
locals
.
K_SPACE
:
if
event
.
key
==
locals
.
K_SPACE
:
jumpState
=
"up"
jumpState
=
"up"
if
gamestate
==
True
:
wukong
=
Player
(
hero
[
index
])
if
jumpState
==
"up"
:
# 起跳状态
if
jumpState
==
"up"
:
# 起跳状态
if
t
>
0
:
if
t
>
0
:
y
-=
t
y
-=
t
wukong
.
rect
.
y
=
y
t
-=
2
t
-=
2
else
:
else
:
jumpState
=
"down"
jumpState
=
"down"
...
@@ -69,7 +72,7 @@ while True:
...
@@ -69,7 +72,7 @@ while True:
t
=
30
t
=
30
# 悟空造型
# 悟空造型
wukong
=
Player
(
hero
[
index
])
if
jumpState
==
"runing"
:
# 跑步状态下
if
jumpState
==
"runing"
:
# 跑步状态下
index
+=
1
index
+=
1
if
index
>=
5
:
if
index
>=
5
:
...
@@ -86,6 +89,7 @@ while True:
...
@@ -86,6 +89,7 @@ while True:
screen
.
blit
(
road
,
(
road_x
,
500
))
# 路
screen
.
blit
(
road
,
(
road_x
,
500
))
# 路
screen
.
blit
(
wukong
.
image
,
(
150
,
y
))
# 悟空
screen
.
blit
(
wukong
.
image
,
(
150
,
y
))
# 悟空
if
obstacle
.
rect
.
x
<=
0
-
obstacle
.
rect
.
width
:
# 障碍物消失
if
obstacle
.
rect
.
x
<=
0
-
obstacle
.
rect
.
width
:
# 障碍物消失
# 创建障碍物对象
# 创建障碍物对象
obstacle
=
Black
(
bush
,
stone
,
cacti
)
obstacle
=
Black
(
bush
,
stone
,
cacti
)
time
+=
1
time
+=
1
...
@@ -104,6 +108,7 @@ while True:
...
@@ -104,6 +108,7 @@ while True:
gameover
=
pygame
.
image
.
load
(
'gameover.png'
)
gameover
=
pygame
.
image
.
load
(
'gameover.png'
)
screen
.
blit
(
gameover
,(
400
,
200
))
screen
.
blit
(
gameover
,(
400
,
200
))
gamestate
=
False
gamestate
=
False
# 刷新画面
# 刷新画面
pygame
.
display
.
update
()
pygame
.
display
.
update
()
FPS
.
tick
(
60
)
FPS
.
tick
(
60
)
\ 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