Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson9_diy2
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
576951a8
authored
2 years ago
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
a20fbe30
c110812l1437p256a14521/wx921447
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
10 deletions
my_game.py
my_game.py
View file @
576951a8
...
@@ -43,8 +43,9 @@ hero = [pygame.image.load('hero1.png'),
...
@@ -43,8 +43,9 @@ hero = [pygame.image.load('hero1.png'),
#basic_font = pygame.font.Font('STKAITI.TTF',32)
#basic_font = pygame.font.Font('STKAITI.TTF',32)
index
=
0
index
=
0
y
=
400
y
=
400
score
=
0
jumpState
=
"runing"
jumpState
=
"runing"
t
=
30
t
=
4
road_x
=
0
road_x
=
0
bg_x
=
0
bg_x
=
0
time
=
0
time
=
0
...
@@ -62,7 +63,7 @@ while True:
...
@@ -62,7 +63,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
=
8
+
s
peed
//
3
speed
=
8
+
s
core
//
3
# 悟空造型
# 悟空造型
wukong
=
Player
(
hero
[
index
])
wukong
=
Player
(
hero
[
index
])
if
jumpState
==
"runing"
:
# 跑步状态下
if
jumpState
==
"runing"
:
# 跑步状态下
...
@@ -75,17 +76,17 @@ while True:
...
@@ -75,17 +76,17 @@ while True:
if
t
>
0
:
if
t
>
0
:
y
-=
t
y
-=
t
wukong
.
rect
.
y
=
y
wukong
.
rect
.
y
=
y
t
-=
2
t
-=
0.01
else
:
else
:
jumpState
=
"down"
jumpState
=
"down"
if
jumpState
==
"down"
:
# 降落状态
if
jumpState
==
"down"
:
# 降落状态
if
t
<=
30
:
if
t
<=
4
:
y
+=
t
y
+=
t
wukong
.
rect
.
y
=
y
wukong
.
rect
.
y
=
y
t
+=
2
t
+=
0.01
else
:
else
:
jumpState
=
"runing"
jumpState
=
"runing"
t
=
30
t
=
4
# 将背景图画上去
# 将背景图画上去
bg_x
-=
1
bg_x
-=
1
...
@@ -93,7 +94,7 @@ while True:
...
@@ -93,7 +94,7 @@ while True:
bg_x
=
0
bg_x
=
0
screen
.
blit
(
background
,
(
bg_x
,
0
))
# 远景
screen
.
blit
(
background
,
(
bg_x
,
0
))
# 远景
road_x
-=
8
road_x
-=
speed
if
road_x
<=-
1000
:
if
road_x
<=-
1000
:
road_x
=
0
road_x
=
0
screen
.
blit
(
road
,
(
road_x
,
500
))
# 道路
screen
.
blit
(
road
,
(
road_x
,
500
))
# 道路
...
@@ -117,10 +118,11 @@ while True:
...
@@ -117,10 +118,11 @@ while True:
screen
.
blit
(
gameover
,
(
400
,
200
))
screen
.
blit
(
gameover
,
(
400
,
200
))
gamestate
=
False
gamestate
=
False
else
:
else
:
score
+=
1
score
+=
1
0
#scoreSurf = basic_font.render("分数:"+str(score),True,(255,0,0))
#scoreSurf = basic_font.render("分数:"+str(score),True,(255,0,0))
#screen.blit(scoreSurf,(850,20))
#screen.blit(scoreSurf,(850,20))
# 刷新画面
# 刷新画面
pygame
.
display
.
update
()
pygame
.
display
.
update
()
FPS
.
tick
(
60
)
FPS
.
tick
(
60
)
\ No newline at end of file
print
(
score
)
\ 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