Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson9_diy1
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
6770fbf5
authored
Jul 17, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
0c19e969
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
10 deletions
my_game.py
my_game.py
View file @
6770fbf5
...
@@ -18,7 +18,7 @@ class Block(pygame.sprite.Sprite): # 障碍物精灵类
...
@@ -18,7 +18,7 @@ class Block(pygame.sprite.Sprite): # 障碍物精灵类
self
.
rect
.
y
=
500
-
self
.
rect
.
height
self
.
rect
.
y
=
500
-
self
.
rect
.
height
class
Player
(
pygame
.
sprite
.
Sprite
):
# 悟空
class
Player
(
pygame
.
sprite
.
Sprite
):
# 悟空
def
__init__
(
self
,
image
):
def
__init__
(
self
,
image
):
super
()
.
__init__
()
super
()
.
__init__
()
# 加载悟空精灵图像
# 加载悟空精灵图像
self
.
image
=
image
self
.
image
=
image
...
@@ -52,15 +52,15 @@ bg_x = 0
...
@@ -52,15 +52,15 @@ bg_x = 0
time
=
0
time
=
0
gamestate
=
True
gamestate
=
True
score
=
0
score
=
0
ol
e
_score
=
score
ol
d
_score
=
score
block_list
=
pygame
.
sprite
.
Group
()
# 创建精灵组
block_list
=
pygame
.
sprite
.
Group
()
# 创建精灵组
with
open
(
'score.txt'
,
'r'
,
encoding
=
'utf-8'
)
as
f
:
with
open
(
'score.txt'
,
'r'
,
encoding
=
'utf-8'
)
as
f
:
concert
=
f
.
read
()
concert
=
f
.
read
()
recond
=
json
.
loads
(
con
ten
t
)
recond
=
json
.
loads
(
con
cer
t
)
one
=
content
[
'第一
名'
]
one
=
recond
[
'第1
名'
]
two
=
content
[
'第二
名'
]
two
=
recond
[
'第2
名'
]
thr
=
content
[
'第三
名'
]
thr
ee
=
recond
[
'第3
名'
]
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
:
...
@@ -124,10 +124,23 @@ while True:
...
@@ -124,10 +124,23 @@ 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
if
score
>
three
:
if
score
>
one
:
recond
[
'第1名'
]
=
score
recond
[
'第2名'
]
=
one
record
[
'第3名'
]
=
two
elif
score
>
two
:
recond
[
'第2名'
]
=
score
recond
[
'第3名'
]
=
two
else
:
recond
[
'第3名'
]
=
score
recond
=
json
.
dumps
(
recond
,
ensure_ascii
=
False
)
with
open
(
'record.txt'
,
'w'
,
encoding
=
'utf_8'
)
as
f
:
f
.
write
(
recond
)
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
score
+=
sprite
.
score
sprite
.
score
+
0
if
score
>
old_score
:
if
score
>
old_score
:
score_audio
.
play
()
score_audio
.
play
()
old_score
=
score
old_score
=
score
...
@@ -142,5 +155,4 @@ while True:
...
@@ -142,5 +155,4 @@ while True:
screen
.
blit
(
scoreSurf
,(
880
,
110
))
screen
.
blit
(
scoreSurf
,(
880
,
110
))
# 刷新画面
# 刷新画面
pygame
.
display
.
update
()
FPS
.
tick
(
60
)
\ No newline at end of file
\ 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