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
95c852c0
authored
2 years ago
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
acb06362
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
5 deletions
my_game.py
my_game.py
View file @
95c852c0
import
pygame
import
pygame
from
pygame
import
locals
from
pygame
import
locals
import
random
pygame
.
init
()
# 初始化
pygame
.
init
()
# 初始化
...
@@ -18,10 +19,16 @@ hero = [pygame.image.load('hero1.png'),
...
@@ -18,10 +19,16 @@ hero = [pygame.image.load('hero1.png'),
pygame
.
image
.
load
(
'hero3.png'
),
pygame
.
image
.
load
(
'hero3.png'
),
pygame
.
image
.
load
(
'hero4.png'
),
pygame
.
image
.
load
(
'hero4.png'
),
pygame
.
image
.
load
(
'hero5.png'
)]
pygame
.
image
.
load
(
'hero5.png'
)]
index
=
0
index
=
0
jumpState
=
"runing"
jumpState
=
"runing"
y
=
400
y
=
400
t
=
30
t
=
30
x
=
1
a
=
random
.
choice
([
apple
,
cacti
,
stone
])
rect
=
a
.
get_rect
()
rect
.
x
=
1000
rect
.
y
=
500
-
rect
.
height
while
True
:
while
True
:
for
event
in
pygame
.
event
.
get
():
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
if
event
.
type
==
locals
.
QUIT
:
...
@@ -31,7 +38,8 @@ while True:
...
@@ -31,7 +38,8 @@ while True:
if
jumpState
==
"runing"
:
if
jumpState
==
"runing"
:
if
event
.
key
==
locals
.
K_SPACE
:
if
event
.
key
==
locals
.
K_SPACE
:
jumpState
=
"up"
jumpState
=
"up"
if
jumpState
==
"up"
:
# 起跳
if
jumpState
==
"up"
:
# 起跳
if
t
>
0
:
if
t
>
0
:
y
-=
t
y
-=
t
...
@@ -49,14 +57,26 @@ while True:
...
@@ -49,14 +57,26 @@ while True:
wukong
=
hero
[
index
]
wukong
=
hero
[
index
]
index
+=
1
if
jumpState
==
"runing"
:
index
+=
1
else
:
x
+=
1
if
index
==
5
:
if
index
==
5
:
index
=
0
index
=
0
# 将背景图画上去
# 将背景图画上去
screen
.
blit
(
background
,
(
0
,
0
))
screen
.
blit
(
background
,
(
0
,
0
))
screen
.
blit
(
road
,
(
0
,
500
))
screen
.
blit
(
road
,
(
0
,
500
))
screen
.
blit
(
wukong
,
(
150
,
y
))
screen
.
blit
(
wukong
,
(
150
,
y
))
# 刷新画面
rect
.
x
-=
5
pygame
.
display
.
update
()
if
rect
.
x
>
0
-
rect
.
width
:
screen
.
blit
(
a
,(
rect
.
x
,
rect
.
y
))
else
:
a
=
random
.
choice
([
apple
,
cacti
,
stone
])
rect
=
a
.
get_rect
()
rect
.
x
=
1000
rect
.
y
=
500
-
rect
.
height
pygame
.
display
.
update
()
FPS
.
tick
(
30
)
FPS
.
tick
(
30
)
\ 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