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
3 years ago
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)
...
@@ -47,7 +47,7 @@ basic_font=pygame.font.Font("STKAITI.TTF",18)
index
=
0
index
=
0
y
=
400
y
=
400
jumpState
=
"runing"
jumpState
=
"runing"
t
=
30
t
=
30
road_x
=
0
road_x
=
0
bg_x
=
0
bg_x
=
0
...
@@ -116,7 +116,7 @@ while True:
...
@@ -116,7 +116,7 @@ while True:
time
=
0
time
=
0
num
=
random
.
randint
(
0
,
50
)
num
=
random
.
randint
(
0
,
50
)
if
num
>
20
:
if
num
>
20
:
obstacle
=
Block
(
bush
,
cacti
,
stone
)
obstacle
=
Block
(
bush
,
cacti
,
stone
)
block_list
.
add
(
obstacle
)
block_list
.
add
(
obstacle
)
for
sprite
in
block_list
:
# 遍历、展示障碍物精灵
for
sprite
in
block_list
:
# 遍历、展示障碍物精灵
sprite
.
rect
.
x
-=
speed
sprite
.
rect
.
x
-=
speed
...
@@ -127,22 +127,38 @@ while True:
...
@@ -127,22 +127,38 @@ 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
>
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
:
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
print
(
score
)
sprite
.
score
=
0
sprite
.
score
=
0
# 刷新画面
# 刷新画面
if
score
>
old_score
:
if
score
>
old_score
:
score_audio
.
play
()
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
))
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
))
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
))
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
))
screen
.
blit
(
scoresurf
,(
880
,
110
))
...
...
This diff is collapsed.
Click to expand it.
record.txt
View file @
24999950
{"第1名": 0, "第2名": 0, "第3名": 0}
{"第1名": 4, "第2名": 3, "第3名": 2}
\ No newline at end of file
\ No newline at end of file
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