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
5e618b4c
authored
Dec 26, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
13fb4abb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
49 deletions
my_game.py
record.txt
my_game.py
View file @
5e618b4c
import
pygame
from
pygame
import
locals
,
display
,
init
from
pygame
import
event
as
_event
from
pygame.time
import
Clock
as
TIME
from
pygame.image
import
load
from
pygame.sprite
import
*
from
pygame.sprite
import
Sprite
,
Group
,
collide_rect
from
random
import
choice
,
randint
init
()
# 初始化
...
...
@@ -56,7 +57,7 @@ block_list = Group()
game_state
=
True
while
True
:
for
event
in
pygame
.
event
.
get
():
for
event
in
_
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
# 接收到退出事件后退出程序
exit
()
...
...
@@ -66,49 +67,52 @@ while True:
jumpState
=
"up"
# 悟空造型
wukong
=
Player
(
hero
[
index
])
if
jumpState
==
"runing"
:
# 跑步状态下
index
+=
1
if
index
>=
5
:
index
=
0
if
game_state
==
True
:
pass
if
jumpState
==
"up"
:
# 起跳状态
if
t
>
0
:
y
-=
t
t
-=
2
else
:
jumpState
=
"down"
if
jumpState
==
"down"
:
# 降落状态
if
t
<=
30
:
y
+=
t
t
+=
2
else
:
jumpState
=
"runing"
t
=
30
if
game_state
:
if
jumpState
==
"runing"
:
# 跑步状态下
index
+=
1
if
index
>=
5
:
index
=
0
if
jumpState
==
"up"
:
# 起跳状态
if
t
>
0
:
y
-=
t
t
-=
2
else
:
jumpState
=
"down"
if
jumpState
==
"down"
:
# 降落状态
if
t
<=
30
:
y
+=
t
t
+=
2
else
:
jumpState
=
"runing"
t
=
30
bg_x
-=
2
road_x
-=
8
# 将背景图画上去
if
bg_x
<
-
1000
:
bg_x
=
0
if
road_x
<
-
1000
:
road_x
=
0
screen
.
blit
(
background
,
(
bg_x
,
0
))
# 远处背景
screen
.
blit
(
road
,
(
road_x
,
500
))
# 路
screen
.
blit
(
wukong
.
image
,
(
wukong
.
rect
.
x
,
wukong
.
rect
.
y
))
# 悟空
time
+=
1
if
time
>=
60
:
i
=
randint
(
0
,
60
)
if
i
>
35
:
obstacle
=
Block
(
stone
,
cacti
,
bush
)
block_list
.
add
(
obstacle
)
time
=
0
for
sprite
in
block_list
:
sprite
.
rect
.
x
-=
8
screen
.
blit
(
sprite
.
image
,(
sprite
.
rect
.
x
,
sprite
.
rect
.
y
))
if
sprite
.
rect
.
x
<=
0
-
sprite
.
rect
.
width
:
sprite
.
kill
()
# 刷新画面
display
.
update
()
TIME
()
.
tick
()
\ No newline at end of file
bg_x
-=
2
road_x
-=
8
# 将背景图画上去
if
bg_x
<
-
1000
:
bg_x
=
0
if
road_x
<
-
1000
:
road_x
=
0
screen
.
blit
(
background
,
(
bg_x
,
0
))
# 远处背景
screen
.
blit
(
road
,
(
road_x
,
500
))
# 路
screen
.
blit
(
wukong
.
image
,
(
wukong
.
rect
.
x
,
wukong
.
rect
.
y
))
# 悟空
time
+=
1
if
time
>=
60
:
i
=
randint
(
0
,
60
)
if
i
>
35
:
obstacle
=
Block
(
stone
,
cacti
,
bush
)
block_list
.
add
(
obstacle
)
time
=
0
for
sprite
in
block_list
:
sprite
.
rect
.
x
-=
8
screen
.
blit
(
sprite
.
image
,(
sprite
.
rect
.
x
,
sprite
.
rect
.
y
))
if
sprite
.
rect
.
x
<=
0
-
sprite
.
rect
.
width
:
sprite
.
kill
()
if
collide_rect
(
wukong
,
sprite
):
screen
.
blit
(
gameover
,(
400
,
200
))
game_state
=
False
# 刷新画面
display
.
update
()
TIME
()
.
tick
()
\ No newline at end of file
record.txt
deleted
100644 → 0
View file @
13fb4abb
{"第1名": 0, "第2名": 0, "第3名": 0}
\ 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