Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson9_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
24999950
authored
Jul 26, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
fc354d65
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
11 deletions
my_game.py
record.txt
my_game.py
View file @
24999950
...
...
@@ -47,7 +47,7 @@ basic_font=pygame.font.Font("STKAITI.TTF",18)
index
=
0
y
=
400
jumpState
=
"runing"
t
=
30
t
=
30
road_x
=
0
bg_x
=
0
...
...
@@ -116,7 +116,7 @@ while True:
time
=
0
num
=
random
.
randint
(
0
,
50
)
if
num
>
20
:
obstacle
=
Block
(
bush
,
cacti
,
stone
)
obstacle
=
Block
(
bush
,
cacti
,
stone
)
block_list
.
add
(
obstacle
)
for
sprite
in
block_list
:
# 遍历、展示障碍物精灵
sprite
.
rect
.
x
-=
speed
...
...
@@ -127,22 +127,38 @@ while True:
gameover
=
pygame
.
image
.
load
(
'gameover.png'
)
# 游戏结束
screen
.
blit
(
gameover
,
(
400
,
200
))
gamestate
=
False
if
score
>
one
:
record
[
"第1名"
]
=
score
record
[
"第2名"
]
=
one
record
[
"第3名"
]
=
two
elif
score
>
two
:
record
[
"第2名"
]
=
score
record
[
"第3名"
]
=
two
elif
score
>
three
:
record
[
"第3名"
]
=
score
record
=
json
.
dumps
(
record
,
ensure_ascii
=
False
)
with
open
(
"record.txt"
,
"w"
,
encoding
=
"utf-8"
)
as
s
:
s
.
write
(
record
)
else
:
if
(
sprite
.
rect
.
x
+
sprite
.
rect
.
width
)
<
wukong
.
rect
.
x
:
score
+=
sprite
.
score
print
(
score
)
sprite
.
score
=
0
score
+=
sprite
.
score
sprite
.
score
=
0
# 刷新画面
if
score
>
old_score
:
score_audio
.
play
()
scoresurf
=
basic_font
.
render
(
"分数"
+
str
(
score
),
True
,(
255
,
255
,
255
))
scoresurf
=
basic_font
.
render
(
"分数
:
"
+
str
(
score
),
True
,(
255
,
255
,
255
))
screen
.
blit
(
scoresurf
,(
880
,
20
))
scoresurf
=
basic_font
.
render
(
"第1名"
+
str
(
one
),
True
,(
255
,
255
,
255
))
scoresurf
=
basic_font
.
render
(
"第1名
:
"
+
str
(
one
),
True
,(
255
,
255
,
255
))
screen
.
blit
(
scoresurf
,(
880
,
50
))
scoresurf
=
basic_font
.
render
(
"第2名"
+
str
(
two
),
True
,(
255
,
255
,
255
))
scoresurf
=
basic_font
.
render
(
"第2名
:
"
+
str
(
two
),
True
,(
255
,
255
,
255
))
screen
.
blit
(
scoresurf
,(
880
,
80
))
scoresurf
=
basic_font
.
render
(
"第3名"
+
str
(
three
),
True
,(
255
,
255
,
255
))
scoresurf
=
basic_font
.
render
(
"第3名
:
"
+
str
(
three
),
True
,(
255
,
255
,
255
))
screen
.
blit
(
scoresurf
,(
880
,
110
))
...
...
record.txt
View file @
24999950
{"第1名": 0, "第2名": 0, "第3名": 0}
\ No newline at end of file
{"第1名": 4, "第2名": 3, "第3名": 2}
\ 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