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
d876d15a
authored
May 22, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
9b7a8e32
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
6 deletions
my_game.py
my_game.py
View file @
d876d15a
...
@@ -20,7 +20,9 @@ hero = [pygame.image.load('hero1.png'),
...
@@ -20,7 +20,9 @@ hero = [pygame.image.load('hero1.png'),
number
=
0
number
=
0
y
=
400
y
=
400
t
=
30
t
=
30
score
=
0
new_score
=
0
old_score
=
0
score_music
=
pygame
.
mixer
.
Sound
(
'score.wav'
)
sss
=
pygame
.
font
.
Font
(
'STKAITI.TTF'
,
20
)
sss
=
pygame
.
font
.
Font
(
'STKAITI.TTF'
,
20
)
class
Block
(
pygame
.
sprite
.
Sprite
):
class
Block
(
pygame
.
sprite
.
Sprite
):
def
__init__
(
self
,
image1
,
image2
,
image3
):
def
__init__
(
self
,
image1
,
image2
,
image3
):
...
@@ -46,6 +48,8 @@ t = 30
...
@@ -46,6 +48,8 @@ t = 30
time
=
0
time
=
0
changex
=
0
changex
=
0
gamestate
=
True
gamestate
=
True
speed
=
8
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
:
...
@@ -55,6 +59,7 @@ while True:
...
@@ -55,6 +59,7 @@ while True:
if
jumpState
==
"runing"
:
if
jumpState
==
"runing"
:
if
event
.
key
==
locals
.
K_SPACE
:
if
event
.
key
==
locals
.
K_SPACE
:
jumpState
=
"up"
jumpState
=
"up"
speed
=
speed
+
new_score
//
30
# 加速
wukong
=
Player
(
hero
[
index
])
wukong
=
Player
(
hero
[
index
])
if
jumpState
==
"runing"
:
# 跑步状态下
if
jumpState
==
"runing"
:
# 跑步状态下
index
+=
1
index
+=
1
...
@@ -79,7 +84,7 @@ while True:
...
@@ -79,7 +84,7 @@ while True:
if
changex
<=-
1000
:
# 路的移动
if
changex
<=-
1000
:
# 路的移动
changex
=
0
changex
=
0
else
:
else
:
changex
-=
8
changex
-=
speed
# 悟空造型
# 悟空造型
# 将背图画上去
# 将背图画上去
time
+=
1
time
+=
1
...
@@ -95,7 +100,7 @@ while True:
...
@@ -95,7 +100,7 @@ while True:
for
sprite
in
group
:
for
sprite
in
group
:
screen
.
blit
(
sprite
.
image
,
(
sprite
.
rect
.
x
,
sprite
.
rect
.
y
))
screen
.
blit
(
sprite
.
image
,
(
sprite
.
rect
.
x
,
sprite
.
rect
.
y
))
sprite
.
rect
.
x
-=
8
sprite
.
rect
.
x
-=
speed
if
sprite
.
rect
.
x
<=
0
-
sprite
.
rect
.
width
:
# 障碍物消失
if
sprite
.
rect
.
x
<=
0
-
sprite
.
rect
.
width
:
# 障碍物消失
sprite
.
kill
()
sprite
.
kill
()
if
pygame
.
sprite
.
collide_rect
(
wukong
,
sprite
):
if
pygame
.
sprite
.
collide_rect
(
wukong
,
sprite
):
...
@@ -104,10 +109,12 @@ while True:
...
@@ -104,10 +109,12 @@ while True:
gamestate
=
False
gamestate
=
False
else
:
else
:
if
sprite
.
rect
.
x
+
sprite
.
rect
.
width
<
wukong
.
rect
.
x
:
if
sprite
.
rect
.
x
+
sprite
.
rect
.
width
<
wukong
.
rect
.
x
:
score
+=
sprite
.
score
new_
score
+=
sprite
.
score
sprite
.
score
=
0
sprite
.
score
=
0
if
new_score
>
old_score
:
text
=
sss
.
render
(
'SCORE:'
+
str
(
score
),
True
,(
0
,
0
,
0
))
old_score
=
new_score
score_music
.
play
()
text
=
sss
.
render
(
'SCORE:'
+
str
(
new_score
),
True
,(
0
,
0
,
0
))
screen
.
blit
(
text
,(
0
,
0
))
screen
.
blit
(
text
,(
0
,
0
))
pygame
.
display
.
update
()
# 刷新画面
pygame
.
display
.
update
()
# 刷新画面
FPS
.
tick
(
50
)
FPS
.
tick
(
50
)
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