Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson8_diy4
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
622c39eb
authored
2 years ago
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
2efe68b4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
13 deletions
STKAITI.TTF
my_game.py
STKAITI.TTF
0 → 100644
View file @
622c39eb
File added
This diff is collapsed.
Click to expand it.
my_game.py
View file @
622c39eb
import
pygame
import
pygame
import
random
import
random
from
pygame
import
locals
from
pygame
import
locals
import
json
class
Block
(
pygame
.
sprite
.
Sprite
):
class
Block
(
pygame
.
sprite
.
Sprite
):
def
__init__
(
self
,
image1
,
image2
,
image3
):
def
__init__
(
self
,
image1
,
image2
,
image3
):
...
@@ -9,6 +10,7 @@ class Block(pygame.sprite.Sprite):
...
@@ -9,6 +10,7 @@ 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
self
.
sceor
=
1
class
Player
(
pygame
.
sprite
.
Sprite
):
class
Player
(
pygame
.
sprite
.
Sprite
):
def
__init__
(
self
,
image
):
def
__init__
(
self
,
image
):
...
@@ -34,22 +36,33 @@ hero =[pygame.image.load('hero1.png'),
...
@@ -34,22 +36,33 @@ hero =[pygame.image.load('hero1.png'),
pygame
.
image
.
load
(
'hero3.png'
),
pygame
.
image
.
load
(
'hero3.png'
),
pygame
.
image
.
load
(
'hero4.png'
),
pygame
.
image
.
load
(
'hero4.png'
),
pygame
.
image
.
load
(
'hero5.png'
)]
pygame
.
image
.
load
(
'hero5.png'
)]
b
=
pygame
.
font
.
Font
(
'STKAITI.TTF'
,
18
)
a
=
pygame
.
mixer
.
Sound
(
'score.wav'
)
index
=
0
index
=
0
jf
=
0
old_sceor
=
0
sceor
=
0
gamestat
=
True
gamestat
=
True
speed
=
8
road_x
=
0
road_x
=
0
time
=
0
time
=
0
background_x
=
0
background_x
=
0
t
=
3
5
t
=
3
6
jumpstat
=
'running'
jumpstat
=
'running'
y
=
400
y
=
400
obstacle
=
Block
(
stone
,
apple
,
cacti
)
obstacle
=
Block
(
stone
,
apple
,
cacti
)
Block_list
=
pygame
.
sprite
.
Group
()
Block_list
=
pygame
.
sprite
.
Group
()
with
open
(
'record.txt'
,
'r'
,
encoding
=
'utf-8'
)
as
f
:
content
=
f
.
read
()
recoud
=
json
.
loads
(
content
)
one
=
recoud
[
'第1名'
]
two
=
recoud
[
'第2名'
]
three
=
recoud
[
'第3名'
]
while
True
:
while
True
:
speed
=
8
+
sceor
//
3
wukong
=
Player
(
hero
[
index
])
wukong
=
Player
(
hero
[
index
])
if
jumpstat
==
'running'
:
if
jumpstat
==
'running'
:
index
+=
1
index
+=
1
...
@@ -65,7 +78,7 @@ while True:
...
@@ -65,7 +78,7 @@ while True:
exit
()
exit
()
if
gamestat
==
True
:
if
gamestat
==
True
:
road_x
-=
8
road_x
-=
speed
if
road_x
<=-
1000
:
#小路移动
if
road_x
<=-
1000
:
#小路移动
road_x
=
0
road_x
=
0
...
@@ -81,13 +94,13 @@ while True:
...
@@ -81,13 +94,13 @@ while True:
jumpstat
=
'jumpdown'
jumpstat
=
'jumpdown'
if
jumpstat
==
'jumpdown'
:
if
jumpstat
==
'jumpdown'
:
if
t
<=
3
5
:
if
t
<=
3
6
:
y
+=
t
y
+=
t
wukong
.
rect
.
y
=
y
wukong
.
rect
.
y
=
y
t
+=
2
t
+=
2
else
:
else
:
jumpstat
=
'running'
jumpstat
=
'running'
t
=
3
5
t
=
3
6
# 将背景图画上去
# 将背景图画上去
screen
.
blit
(
background
,
(
background_x
,
0
))
screen
.
blit
(
background
,
(
background_x
,
0
))
...
@@ -103,7 +116,7 @@ while True:
...
@@ -103,7 +116,7 @@ while True:
Block_list
.
add
(
obstacle
)
Block_list
.
add
(
obstacle
)
for
sprite
in
Block_list
:
for
sprite
in
Block_list
:
sprite
.
rect
.
x
-=
8
sprite
.
rect
.
x
-=
speed
screen
.
blit
(
sprite
.
image
,(
sprite
.
rect
.
x
,
sprite
.
rect
.
y
))
screen
.
blit
(
sprite
.
image
,(
sprite
.
rect
.
x
,
sprite
.
rect
.
y
))
if
sprite
.
rect
.
x
<
0
-
sprite
.
rect
.
width
:
if
sprite
.
rect
.
x
<
0
-
sprite
.
rect
.
width
:
sprite
.
kill
()
sprite
.
kill
()
...
@@ -112,9 +125,24 @@ while True:
...
@@ -112,9 +125,24 @@ while True:
screen
.
blit
(
gameover
,(
400
,
150
))
screen
.
blit
(
gameover
,(
400
,
150
))
gamestat
=
False
gamestat
=
False
else
:
else
:
if
if
sprite
.
rect
.
x
+
sprite
.
rect
.
width
<
wukong
.
rect
.
x
:
sceor
+=
sprite
.
sceor
screen
.
blit
(
obstacle
.
image
,(
obstacle
.
rect
.
x
,
obstacle
.
rect
.
y
))
sprite
.
sceor
=
0
old_sceor
=
sceor
if
sceor
>
old_sceor
:
a
.
Play
()
old_sceor
=
sceor
score
=
b
.
render
(
'分数'
+
str
(
sceor
),
True
,(
0
,
0
,
0
))
screen
.
blit
(
score
,(
880
,
20
))
score1
=
b
.
render
(
'第一名'
+
str
(
one
),
True
,(
0
,
0
,
0
))
score2
=
b
.
render
(
'第二名'
+
str
(
two
),
True
,(
0
,
0
,
0
))
score3
=
b
.
render
(
'第三名'
+
str
(
three
),
True
,(
0
,
0
,
0
))
screen
.
blit
(
score1
,(
880
,
40
))
screen
.
blit
(
score2
,(
880
,
60
))
screen
.
blit
(
score3
,(
880
,
80
))
# 刷新画面
# 刷新画面
pygame
.
display
.
update
()
pygame
.
display
.
update
()
FPS
.
tick
(
60
)
FPS
.
tick
(
90
)
\ 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