Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson7_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
192e9fbe
authored
Jun 04, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
be4d3fa5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
40 deletions
my_game.py
qinglong3.png
my_game.py
View file @
192e9fbe
...
...
@@ -10,6 +10,12 @@ class Books(pygame.sprite.Sprite):
self
.
rect
=
self
.
image
.
get_rect
()
self
.
rect
.
x
=
1000
self
.
rect
.
y
=
500
-
self
.
rect
.
height
class
wukong
(
pygame
.
sprite
.
Sprite
):
def
__init__
(
self
,
image
):
super
()
.
__init__
(
image
)
self
.
rect
=
self
.
get_rect
()
self
.
rect
.
x
=
150
self
.
rect
.
y
=
400
# 创建一个窗口
screen
=
pygame
.
display
.
set_mode
((
1000
,
600
))
pygame
.
display
.
set_caption
(
"悟空跑酷"
)
...
...
@@ -35,6 +41,7 @@ time = 0
jump
=
"running"
obstacle
=
Books
(
stone
,
cacti
,
apple
)
group
=
pygame
.
sprite
.
Group
()
game
=
0
while
True
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
...
...
@@ -43,58 +50,59 @@ while True:
if
jump
==
"running"
:
if
event
.
key
==
locals
.
K_SPACE
:
jump
=
"up"
wukong
=
wukong
(
hero
[
index
])
if
jump
==
"running"
:
index
+=
1
if
index
==
5
:
index
=
0
if
jump
==
"up"
:
if
t
>
0
:
y
-=
t
wukong
.
rect
.
y
=
y
t
-=
2
else
:
jump
=
"down"
if
jump
==
"down"
:
if
t
<=
35
:
y
+=
t
wukong
.
rect
.
y
=
y
t
+=
2
else
:
jump
=
"running"
t
=
35
wukong
=
hero
[
index
]
if
jump
==
"running"
:
index
+=
1
if
index
==
5
:
index
=
0
# 将背景图画上去
beijing_x
-=
4
if
beijing_x
<=
-
1000
:
beijing_x
=
0
screen
.
blit
(
background
,(
beijing_x
,
0
))
#路
road_x
-=
8
if
road_x
<=
-
1000
:
road_x
=
0
screen
.
blit
(
road
,
(
road_x
,
500
))
screen
.
blit
(
wukong
,
(
150
,
y
))
#障碍物
#if obstacle.rect.x < 0-obstacle.rect.width:
# obstacle = Books(stone,cacti,apple)
#else:
# obstacle.rect.x -= 8
#screen.blit(obstacle.image,(obstacle.rect.x, obstacle.rect.y))
time
+=
1
if
time
>=
60
:
time
=
0
time1
=
random
.
randint
(
0
,
50
)
if
time1
>
20
:
obstacle
=
Books
(
stone
,
cacti
,
apple
)
group
.
add
(
obstacle
)
for
sprite
in
group
:
sprite
.
rect
.
x
-=
8
screen
.
blit
(
sprite
.
image
,(
sprite
.
rect
.
x
,
sprite
.
rect
.
y
))
if
sprite
.
rect
.
x
<=
0
-
sprite
.
rect
.
width
:
sprite
.
kill
()
# 刷新画面
pygame
.
display
.
update
()
FPS
.
tick
(
60
)
\ No newline at end of file
if
game
==
0
:
# 将背景图画上去
beijing_x
-=
4
if
beijing_x
<=
-
1000
:
beijing_x
=
0
screen
.
blit
(
background
,(
beijing_x
,
0
))
#路
road_x
-=
8
if
road_x
<=
-
1000
:
road_x
=
0
screen
.
blit
(
road
,
(
road_x
,
500
))
screen
.
blit
(
image
,
(
150
,
y
))
#障碍物
time
+=
1
if
time
>=
60
:
time
=
0
time1
=
random
.
randint
(
0
,
50
)
if
time1
>
20
:
obstacle
=
Books
(
stone
,
cacti
,
apple
)
group
.
add
(
obstacle
)
for
sprite
in
group
:
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
pygame
.
sprite
.
collide_rect
(
wukong
,
sprite
):
qinglong3
=
pygame
.
image
.
load
(
'qinglong3.png'
)
#结束
game
=
1
# 刷新画面
pygame
.
display
.
update
()
FPS
.
tick
(
60
)
\ No newline at end of file
qinglong3.png
0 → 100644
View file @
192e9fbe
58.6 KB
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