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
fb87f6c7
authored
Dec 18, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
e13bc487
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
13 deletions
my_game.py
my_game.py
View file @
fb87f6c7
...
...
@@ -17,17 +17,25 @@ hero = [pygame.image.load('hero1.png'),
pygame
.
image
.
load
(
'hero3.png'
),
pygame
.
image
.
load
(
'hero4.png'
),
pygame
.
image
.
load
(
'hero5.png'
)]
abc
=
random
.
choice
([
bush
,
cacti
,
stone
])
rect
=
abc
.
get_rect
()
rect
.
x
=
1000
rect
.
y
=
500
-
rect
.
height
class
Block
(
pygame
.
sprite
.
Sprite
):
def
__init__
(
self
,
image1
,
image2
,
image3
):
super
()
.
__init__
()
self
.
image
=
random
.
choice
([
image1
,
image2
,
image3
])
self
.
rect
=
self
.
image
.
get_rect
()
self
.
rect
.
x
=
1000
self
.
rect
.
y
=
500
-
self
.
rect
.
height
abc
=
Block
(
bush
,
cacti
,
stone
)
rect2
=
road
.
get_rect
()
rect2
.
x
=
0
rect2
.
y
=
500
-
rect
.
height
rect2
.
y
=
500
-
abc
.
rect
.
height
rect3
=
road
.
get_rect
()
rect3
.
x
=
0
index
=
0
y
=
400
mode
=
0
g
=
20
while
True
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
KEYDOWN
:
...
...
@@ -46,21 +54,21 @@ while True:
mode
=
0
if
mode
==
0
:
g
=
20
screen
.
blit
(
background
,
(
0
,
0
))
screen
.
blit
(
background
,
(
rect3
.
x
,
0
))
screen
.
blit
(
road
,
(
rect2
.
x
,
500
))
screen
.
blit
(
abc
,
(
rect
.
x
,
rect
.
y
))
screen
.
blit
(
abc
.
image
,
(
abc
.
rect
.
x
,
abc
.
rect
.
y
))
if
mode
==
0
:
i
+=
1
screen
.
blit
(
hero
[
i
%
5
],
(
150
,
y
))
if
rect
.
x
<=
0
-
rect
.
width
:
abc
=
random
.
choice
([
bush
,
cacti
,
stone
])
rect
=
abc
.
get_rect
()
rect
.
x
=
1000
rect
.
y
=
500
-
rect
.
height
rect
.
x
-=
10
if
abc
.
rect
.
x
<=
0
-
abc
.
rect
.
width
:
abc
=
Block
(
bush
,
cacti
,
stone
)
abc
.
rect
.
x
-=
10
if
rect2
.
x
<=
-
1000
:
rect2
.
x
=
0
rect2
.
x
-=
10
if
rect3
.
x
<=
-
1000
:
rect3
.
x
=
0
rect3
.
x
-=
2
pygame
.
display
.
set_caption
(
'悟空酷跑'
)
# 刷新画面
pygame
.
display
.
update
()
...
...
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