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
d7fc96d1
authored
2 years ago
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
3d4729ee
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
8 deletions
my_game.py
my_game.py
View file @
d7fc96d1
...
...
@@ -27,15 +27,16 @@ hero = [pygame.image.load('hero1.png'),
pygame
.
image
.
load
(
'hero4.png'
),
pygame
.
image
.
load
(
'hero5.png'
)]
class
Player
(
Block
):
def
__init__
(
self
):
index
=
0
class
Player
(
pygame
.
sprite
.
Sprite
):
def
__init__
(
self
,
image
):
super
()
.
__init__
()
self
.
image
=
hero
[
index
]
self
.
image
=
image
self
.
rect
=
self
.
image
.
get_rect
()
self
.
rect
.
x
=
150
self
.
rect
.
y
=
500
-
self
.
rect
.
height
self
.
rect
.
y
=
400
# shan_x=0
index
=
0
y
=
400
jumpState
=
"runing"
t
=
30
...
...
@@ -53,18 +54,19 @@ while True:
if
event
.
key
==
locals
.
K_SPACE
:
jumpState
=
"up"
wukong
=
Player
()
wukong
=
Player
(
hero
[
index
])
print
(
wukong
.
image
)
if
jumpState
==
"up"
:
# 起跳状态
if
t
>
0
:
y
-=
t
wukong
.
rect
.
y
=
y
#
wukong.rect.y = y
t
-=
2
else
:
jumpState
=
"down"
if
jumpState
==
"down"
:
# 降落状态
if
t
<=
30
:
y
+=
t
wukong
.
rect
.
y
=
y
#
wukong.rect.y = y
t
+=
2
else
:
jumpState
=
"runing"
...
...
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