Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson8_diy2
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
f9c0297d
authored
Apr 16, 2023
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
f6da6f5f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
4 deletions
my_game.py
my_game.py
View file @
f9c0297d
...
...
@@ -9,6 +9,13 @@ class Block(pygame.sprite.Sprite):
self
.
rect
=
self
.
image
.
get_rect
()
self
.
rect
.
x
=
1000
self
.
rect
.
y
=
500
-
self
.
rect
.
height
class
Player
(
pygame
.
sprite
.
Sprite
):
def
__init__
(
self
,
image
):
super
()
.
__init__
()
self
.
image
=
image
self
.
rect
=
self
.
image
.
get_rect
()
self
.
rect
.
x
=
150
self
.
rect
.
y
=
450
pygame
.
init
()
# 初始化
# 创建一个窗口
screen
=
pygame
.
display
.
set_mode
((
1000
,
600
))
...
...
@@ -35,7 +42,7 @@ time=0
sprites
=
pygame
.
sprite
.
Group
()
aa
=
Block
(
bush
,
cacti
,
stone
)
sprites
.
add
(
aa
)
gamestatue
=
True
while
True
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
...
...
@@ -45,7 +52,8 @@ while True:
if
jumpState
==
"runing"
:
if
event
.
key
==
locals
.
K_SPACE
:
jumpState
=
"up"
if
gamestatue
!=
True
:
continue
if
jumpState
==
"up"
:
# 起跳状态
if
t
>
0
:
y
-=
t
...
...
@@ -61,11 +69,14 @@ while True:
t
=
30
# 悟空造型
wukong
=
hero
[
index
]
if
jumpState
==
"runing"
:
# 跑步状态下
index
+=
1
if
index
>=
5
:
index
=
0
wukong
=
Player
(
hero
[
index
])
wukong
.
rect
.
y
=
y
# 将背景图画上去
shan_x
-=
2
if
shan_x
<-
1000
:
...
...
@@ -75,7 +86,7 @@ while True:
if
lu_x
<-
1000
:
lu_x
=
0
screen
.
blit
(
road
,
(
lu_x
,
500
))
# 路
screen
.
blit
(
wukong
,
(
150
,
y
))
screen
.
blit
(
wukong
.
image
,
(
wukong
.
rect
.
x
,
wukong
.
rect
.
y
))
time
+=
1
if
time
>
60
:
time
=
0
...
...
@@ -86,6 +97,9 @@ while True:
for
sprite
in
sprites
:
sprite
.
rect
.
x
-=
8
screen
.
blit
(
sprite
.
image
,
(
sprite
.
rect
.
x
,
sprite
.
rect
.
y
))
if
pygame
.
sprite
.
collide_rect
(
wukong
,
sprite
):
screen
.
blit
(
pygame
.
image
.
load
(
"gameover.png"
),
(
0
,
0
))
gamestatue
=
False
if
sprite
.
rect
.
x
<=
0
-
sprite
.
rect
.
width
:
sprite
.
kill
()
# 悟空
# 刷新画面
...
...
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