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
5071298d
authored
2 years ago
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
79c04a49
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
4 deletions
my_game.py
my_game.py
View file @
5071298d
...
@@ -9,7 +9,15 @@ class Block(pygame.sprite.Sprite):
...
@@ -9,7 +9,15 @@ class Block(pygame.sprite.Sprite):
self
.
rect
=
self
.
image
.
get_rect
()
self
.
rect
=
self
.
image
.
get_rect
()
self
.
rect
.
x
=
1000
self
.
rect
.
x
=
1000
self
.
rect
.
y
=
500
-
self
.
rect
.
height
self
.
rect
.
y
=
500
-
self
.
rect
.
height
class
class
Wukong
(
pygame
.
sprite
.
Sprite
):
def
__init__
(
self
,
wk_image
):
super
()
.
__init__
()
self
.=
wk_image
self
.
rect
=
self
.
image
[
0
]
.
get_rect
()
self
.
rect
.
x
=
150
self
.
rect
.
y
=
400
pygame
.
init
()
# 初始化
pygame
.
init
()
# 初始化
# 创建一个窗口
# 创建一个窗口
...
@@ -42,6 +50,8 @@ obs.rect.y = 500 - obs.rect.height
...
@@ -42,6 +50,8 @@ obs.rect.y = 500 - obs.rect.height
block_list
=
pygame
.
sprite
.
Group
()
block_list
=
pygame
.
sprite
.
Group
()
block_list
.
add
(
obs
)
block_list
.
add
(
obs
)
time
=
0
time
=
0
wuk
=
Wukong
(
hero
)
while
True
:
while
True
:
for
event
in
pygame
.
event
.
get
():
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
if
event
.
type
==
locals
.
QUIT
:
...
@@ -67,7 +77,7 @@ while True:
...
@@ -67,7 +77,7 @@ while True:
t
=
30
t
=
30
# 悟空造型
# 悟空造型
wukong
=
hero
[
index
]
if
jumpState
==
"runing"
:
# 跑步状态下
if
jumpState
==
"runing"
:
# 跑步状态下
index
+=
1
index
+=
1
if
index
>=
5
:
if
index
>=
5
:
...
@@ -83,7 +93,7 @@ while True:
...
@@ -83,7 +93,7 @@ while True:
road_x
=
0
road_x
=
0
screen
.
blit
(
road
,
(
road_x
,
500
))
# 路
screen
.
blit
(
road
,
(
road_x
,
500
))
# 路
screen
.
blit
(
wuk
ong
,
(
150
,
y
))
# 悟空
screen
.
blit
(
wuk
.
image
[
index
]
,
(
150
,
y
))
# 悟空
time
+=
1
time
+=
1
if
time
>=
60
:
if
time
>=
60
:
time
=
0
time
=
0
...
@@ -94,7 +104,6 @@ while True:
...
@@ -94,7 +104,6 @@ while True:
for
i
in
block_list
:
for
i
in
block_list
:
i
.
rect
.
x
-=
8
i
.
rect
.
x
-=
8
screen
.
blit
(
i
.
image
,
(
i
.
rect
.
x
,
i
.
rect
.
y
))
screen
.
blit
(
i
.
image
,
(
i
.
rect
.
x
,
i
.
rect
.
y
))
if
pygame
.
sprite
.
col
if
i
.
rect
.
x
<
0
-
i
.
rect
.
width
:
if
i
.
rect
.
x
<
0
-
i
.
rect
.
width
:
i
.
kill
()
i
.
kill
()
# 刷新画面
# 刷新画面
...
...
This diff is collapsed.
Click to expand it.
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