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
Sep 30, 2022
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'),
...
@@ -27,15 +27,16 @@ hero = [pygame.image.load('hero1.png'),
pygame
.
image
.
load
(
'hero4.png'
),
pygame
.
image
.
load
(
'hero4.png'
),
pygame
.
image
.
load
(
'hero5.png'
)]
pygame
.
image
.
load
(
'hero5.png'
)]
class
Player
(
Block
):
index
=
0
def
__init__
(
self
):
class
Player
(
pygame
.
sprite
.
Sprite
):
def
__init__
(
self
,
image
):
super
()
.
__init__
()
super
()
.
__init__
()
self
.
image
=
hero
[
index
]
self
.
image
=
image
self
.
rect
=
self
.
image
.
get_rect
()
self
.
rect
=
self
.
image
.
get_rect
()
self
.
rect
.
x
=
150
self
.
rect
.
x
=
150
self
.
rect
.
y
=
500
-
self
.
rect
.
height
self
.
rect
.
y
=
400
# shan_x=0
# shan_x=0
index
=
0
y
=
400
y
=
400
jumpState
=
"runing"
jumpState
=
"runing"
t
=
30
t
=
30
...
@@ -53,18 +54,19 @@ while True:
...
@@ -53,18 +54,19 @@ while True:
if
event
.
key
==
locals
.
K_SPACE
:
if
event
.
key
==
locals
.
K_SPACE
:
jumpState
=
"up"
jumpState
=
"up"
wukong
=
Player
()
wukong
=
Player
(
hero
[
index
])
print
(
wukong
.
image
)
if
jumpState
==
"up"
:
# 起跳状态
if
jumpState
==
"up"
:
# 起跳状态
if
t
>
0
:
if
t
>
0
:
y
-=
t
y
-=
t
wukong
.
rect
.
y
=
y
#
wukong.rect.y = y
t
-=
2
t
-=
2
else
:
else
:
jumpState
=
"down"
jumpState
=
"down"
if
jumpState
==
"down"
:
# 降落状态
if
jumpState
==
"down"
:
# 降落状态
if
t
<=
30
:
if
t
<=
30
:
y
+=
t
y
+=
t
wukong
.
rect
.
y
=
y
#
wukong.rect.y = y
t
+=
2
t
+=
2
else
:
else
:
jumpState
=
"runing"
jumpState
=
"runing"
...
...
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