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
90e2733e
authored
Dec 12, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
80718b16
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
8 deletions
my_game.py
my_game.py
View file @
90e2733e
...
...
@@ -11,9 +11,9 @@ class Block (pygame.sprite.Sprite):
self
.
rect
.
y
=
500
-
self
.
rect
.
height
class
Wukong
(
pygame
.
sprite
.
Sprite
):
def
__init__
(
self
,
image
):
def
__init__
(
self
,
image
1
):
super
()
.
__init__
()
self
.
image
=
image
self
.
image
=
image
1
self
.
rect
=
self
.
image
.
get_rect
()
self
.
rect
.
x
=
150
self
.
rect
.
y
=
400
...
...
@@ -41,7 +41,8 @@ block_lite = pygame.sprite.Group()
time
=
0
road_x
=
0
bg_x
=
0
Wukong
=
Wukong
(
hero
[
1
])
wukong
=
Wukong
(
hero
[
1
])
gameState
=
True
while
True
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
...
...
@@ -54,20 +55,20 @@ while True:
if
jumpState
==
"up"
:
# 起跳状态
if
t
>
0
:
y
-=
t
wukong
.
rect
.
y
-=
t
t
-=
2
else
:
jumpState
=
"down"
if
jumpState
==
"down"
:
# 降落状态
if
t
<=
30
:
y
+=
t
wukong
.
rect
.
y
+=
t
t
+=
2
else
:
jumpState
=
"runing"
t
=
30
if
gameState
==
True
:
# 悟空造型
wukong
=
hero
[
index
]
wukong
.
image
=
hero
[
index
]
if
jumpState
==
"runing"
:
# 跑步状态下
index
+=
1
if
index
>=
5
:
...
...
@@ -75,7 +76,7 @@ while True:
# 将背景图画上去
screen
.
blit
(
background
,
(
bg_x
,
0
))
# 远处背景
screen
.
blit
(
road
,
(
road_x
,
500
))
# 路
screen
.
blit
(
wukong
,
(
150
,
y
))
# 悟空
screen
.
blit
(
wukong
.
image
,
(
wukong
.
rect
.
x
,
wukong
.
rect
.
y
))
# 悟空
bg_x
-=
1
if
bg_x
<=
-
1000
:
...
...
@@ -91,11 +92,16 @@ while True:
if
gai
>
2
:
obstacle
=
Block
(
stone
,
cacti
,
bush
)
block_lite
.
add
(
obstacle
)
for
sprit
in
block_lite
:
sprit
.
rect
.
x
-=
8
screen
.
blit
(
sprit
.
image
,
(
sprit
.
rect
.
x
,
sprit
.
rect
.
y
))
if
sprit
.
rect
.
x
<=
0
-
sprit
.
rect
.
width
:
sprit
.
kill
()
if
pygame
.
sprite
.
collide_rect
(
wukong
,
obstacle
):
over
=
pygame
.
image
.
load
(
'gameover.png'
)
screen
.
blit
(
over
,
(
400
,
200
))
gameState
=
False
# 刷新画面
pygame
.
display
.
update
()
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