Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson3-3_DIY1
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
aff6b4f6
authored
Oct 15, 2023
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
c97b323a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
7 deletions
diy1.py
diy1.py
View file @
aff6b4f6
imprt
pygame
from
pygame
import
locals
pygame
.
init
()
screen
=
pygame
.
display
.
set_mode
((
1000
,
600
))
FPS
=
pygame
.
time
.
Clock
()
pygame
.
dispplay
.
set_caption
(
"悟空跑酷"
)
backpround
=
pygame
.
image
.
load
(
'bg.png'
)
road
=
pygame
.
image
.
load
(
'road.png'
)
stond
=
pygame
.
image
.
load
(
'stomd.png'
)
cacti
=
pygame
.
image
.
load
(
'cacty.png'
)
apple
=
pygame
.
image
.
load
(
'apple.png'
)
hero
=
[
pygame
.
image
.
load
(
'hero1.png'
)
pygame
.
image
.
load
(
'hero2.png'
)
...
...
@@ -5,31 +15,48 @@ hero = [pygame.image.load('hero1.png')
pygame
.
image
.
load
(
'hero4.png'
)
pygame
.
image
.
load
(
'hero5.png'
)]
index
=
0
jumpState
=
"runing"
y
=
400
jumpState
=
"runing"
t
=
30
obstacle
=
random
.
choice
([
bush
,
stond
,
cacti
])
rect
=
obstacle
.
get_rect
()
rect
.
x
=
1000
rect
.
y
=
500
-
rect
.
height
while
True
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
exit
()
if
event
.
type
==
locaols
.
K_SPACE
:
if
jumpState
==
"runing"
if
event
.
key
==
locals
.
K_SPAE
:
jumpState
=
"up"
if
jumpStare
==
"up"
:
if
y
>
150
:
y
-=
5
if
t
>
0
:
y
-=
t
t
-=
2
else
:
jumpState
=
"down"
:
if
jumState
==
"down"
:
if
y
<
400
:
y
+=
5
if
t
<
30
:
y
+=
t
t
+=
2
else
:
jumpState
=
"runing"
t
=
30
wukon
=
hero
[
index
]
index
+=
1
if
index
==
5
:
index
=
0
screen
.
blit
(
background
,(
0
,
0
))
screen
.
blit
(
road
,(
0
,
500
))
screen
.
blit
(
wukong
,(
150
,
400
))
screen
.
blit
(
wukong
,(
150
,
t
))
if
rect
.
x
<=
0
-
rect
.
width
:
obstacle
=
random
.
choice
([
bush
,
stone
,
cacti
])
rect
=
obstacle
.
get_rect
()
rect
.
x
=
1000
rect
.
y
=
500
-
rect
.
height
rect
.
x
-=
8
screen
.
blit
(
obstacle
,(
rect
.
x
,
rect
.
y
))
pygame
.
display
.
update
()
FPS
.
tick
(
60
)
FPS
.
tick
(
30
)
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