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
3e19ca65
authored
Jun 08, 2024
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
09a3b034
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
10 deletions
my_game.py
my_game.py
View file @
3e19ca65
...
...
@@ -10,8 +10,7 @@ class Block(pygame.sprite.Sprite):
self
.
image
=
random
.
choice
([
image1
,
image2
,
image3
])
self
.
rect
=
self
.
image
.
get_rect
()
self
.
rect
.
x
=
1000
self
.
rect
.
y
=
500
-
rect
.
height
self
.
rect
.
y
=
500
-
self
.
rect
.
height
pygame
.
display
.
set_caption
(
"悟空酷跑"
)
# 创建一个窗口
screen
=
pygame
.
display
.
set_mode
((
1000
,
600
))
...
...
@@ -33,7 +32,7 @@ wukong_y=400
rode_x
=
0
background_x
=
0
t
=
30
obstacle
=
Block
(
[
bush
,
cacti
,
stone
]
)
obstacle
=
Block
(
bush
,
cacti
,
stone
)
while
True
:
for
event
in
pygame
.
event
.
get
():
...
...
@@ -43,6 +42,9 @@ while True:
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
key
==
locals
.
K_SPACE
and
jumpState
==
"runing"
:
jumpState
=
"up"
if
event
.
type
==
locals
.
MOUSEBUTTONDOWN
:
if
jumpState
==
"runing"
:
#event.m == locals.BUTTON_LEFT and
jumpState
=
"up"
if
jumpState
==
"up"
:
if
t
>
0
:
...
...
@@ -71,13 +73,11 @@ while True:
screen
.
blit
(
road
,
(
rode_x
,
500
))
screen
.
blit
(
wukong
,
(
150
,
wukong_y
))
if
rect
.
x
<=
0
-
rect
.
width
:
obstacle
=
random
.
choice
([
bush
,
cacti
,
stone
])
rect
=
obstacle
.
get_rect
()
rect
.
x
=
1000
rect
.
y
=
500
-
rect
.
height
screen
.
blit
(
obstacle
,
(
rect
.
x
,
rect
.
y
))
rect
.
x
-=
8
if
obstacle
.
rect
.
x
<=
0
-
obstacle
.
rect
.
width
:
obstacle
=
Block
(
bush
,
cacti
,
stone
)
screen
.
blit
(
obstacle
.
image
,
(
obstacle
.
rect
.
x
,
obstacle
.
rect
.
y
))
obstacle
.
rect
.
x
-=
8
rode_x
=
rode_x
-
8
background_x
-=
5
# 刷新画面
...
...
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