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
1d3cfc38
authored
3 years ago
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
c4bf1e9d
c158559l1412p256a14377/wx698721
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
14 deletions
my_game.py
my_game.py
View file @
1d3cfc38
...
@@ -9,10 +9,10 @@ class Block (pygame.sprite.Sprite):
...
@@ -9,10 +9,10 @@ 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
Wu
(
pygame
.
sprite
.
Sprite
):
class
Wu
kong
(
pygame
.
sprite
.
Sprite
):
def
__init__
(
self
,
image
):
def
__init__
(
self
,
image
1
):
super
()
.
__init__
()
super
()
.
__init__
()
self
.
image
=
image
self
.
image
=
image
1
self
.
rect
=
self
.
image
.
get_rect
()
self
.
rect
=
self
.
image
.
get_rect
()
self
.
rect
.
x
=
150
self
.
rect
.
x
=
150
self
.
rect
.
y
=
400
self
.
rect
.
y
=
400
...
@@ -36,14 +36,15 @@ pygame.display.set_caption("一只猴的回家路")
...
@@ -36,14 +36,15 @@ pygame.display.set_caption("一只猴的回家路")
index
=
0
index
=
0
heroLength
=
len
(
hero
)
heroLength
=
len
(
hero
)
state
=
"runing"
state
=
"runing"
y
=
400
t
=
30
t
=
30
d
=
30
d
=
30
f
=
30
f
=
30
v
=
30
block_list
=
pygame
.
sprite
.
Group
()
block_list
=
pygame
.
sprite
.
Group
()
time
=
0
time
=
0
road_x
=
0
road_x
=
0
bg_x
=
0
bg_x
=
0
wukong
=
Wukong
(
hero
[
0
])
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
:
...
@@ -61,13 +62,13 @@ while True:
...
@@ -61,13 +62,13 @@ while True:
#w
#w
if
state
==
"up"
:
if
state
==
"up"
:
if
t
>
0
:
if
t
>
0
:
y
-=
t
wukong
.
rect
.
y
-=
t
t
-=
2
t
-=
2
else
:
else
:
state
=
"down"
state
=
"down"
if
state
==
"down"
:
if
state
==
"down"
:
if
t
<=
30
:
if
t
<=
30
:
y
+=
t
wukong
.
rect
.
y
+=
t
t
+=
2
t
+=
2
else
:
else
:
state
=
"runing"
state
=
"runing"
...
@@ -75,28 +76,28 @@ while True:
...
@@ -75,28 +76,28 @@ while True:
#s
#s
if
state
==
"s"
:
if
state
==
"s"
:
if
d
>
0
:
if
d
>
0
:
y
+=
d
wukong
.
rect
.
y
+=
d
d
-=
2
d
-=
2
else
:
else
:
state
=
"e"
state
=
"e"
if
state
==
"e"
:
if
state
==
"e"
:
if
d
<=
30
:
if
d
<=
30
:
y
-=
t
wukong
.
rect
.
y
-=
t
d
+=
2
d
+=
2
f
-=
2
f
-=
2
else
:
else
:
state
=
"f"
state
=
"f"
if
state
==
"f"
:
if
state
==
"f"
:
if
f
<=
30
:
if
f
<=
30
:
y
+=
f
wukong
.
rect
.
y
+=
f
f
+=
2
f
+=
2
else
:
else
:
y
=
400
wukong
.
rect
.
y
=
400
state
=
"runing"
state
=
"runing"
#d
#d
if
state
==
"d"
:
if
state
==
"d"
:
if
d
>
0
:
if
d
>
0
:
y
-=
d
wukong
.
rect
.
y
-=
d
d
-=
2
d
-=
2
else
:
else
:
state
=
"q"
state
=
"q"
...
@@ -108,15 +109,17 @@ while True:
...
@@ -108,15 +109,17 @@ while True:
state
=
"o"
state
=
"o"
if
state
==
"o"
:
if
state
==
"o"
:
if
f
<=
30
:
if
f
<=
30
:
y
+=
f
wukong
.
rect
.
y
+=
f
f
+=
2
f
+=
2
else
:
else
:
y
=
400
wukong
.
rect
.
y
=
400
state
=
"runing"
state
=
"runing"
#
#
if
gameState
==
True
:
wukong
.
image
=
hero
[
index
]
screen
.
blit
(
background
,
(
bg_x
,
0
))
screen
.
blit
(
background
,
(
bg_x
,
0
))
screen
.
blit
(
road
,
(
road_x
,
500
))
screen
.
blit
(
road
,
(
road_x
,
500
))
screen
.
blit
(
hero
[
index
],
(
150
,
y
))
screen
.
blit
(
wukong
.
image
,
(
wukong
.
rect
.
x
,
wukong
.
rect
.
y
))
bg_x
-=
1
bg_x
-=
1
...
@@ -137,6 +140,11 @@ while True:
...
@@ -137,6 +140,11 @@ while True:
screen
.
blit
(
sprit
.
image
,(
sprit
.
rect
.
x
,
sprit
.
rect
.
y
))
screen
.
blit
(
sprit
.
image
,(
sprit
.
rect
.
x
,
sprit
.
rect
.
y
))
if
sprit
.
rect
.
x
<=
0
-
sprit
.
rect
.
width
:
if
sprit
.
rect
.
x
<=
0
-
sprit
.
rect
.
width
:
sprit
.
kill
()
sprit
.
kill
()
if
pygame
.
sprite
.
collide_rect
(
wukong
,
sprit
):
over
=
pygame
.
image
.
load
(
'gameover.png'
)
screen
.
blit
(
over
,(
400
,
200
))
gameState
=
False
if
state
==
"runing"
:
if
state
==
"runing"
:
index
+=
1
index
+=
1
if
index
>
4
:
if
index
>
4
:
...
...
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