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
bd299c82
authored
3 years ago
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
1fde446e
c178104l1405p473a14330/wx673178
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
6 deletions
my_game.py
my_game.py
View file @
bd299c82
...
@@ -10,7 +10,8 @@ class Block(pygame.sprite.Sprite):
...
@@ -10,7 +10,8 @@ class Block(pygame.sprite.Sprite):
self
.
rect
=
self
.
image
.
get_rect
()
self
.
rect
=
self
.
image
.
get_rect
()
self
.
rect
.
x
=
1000
self
.
rect
.
x
=
1000
self
.
rect
.
y
=
500
-
self
.
rect
.
height
self
.
rect
.
y
=
500
-
self
.
rect
.
height
self
.
score
=
1
score
=
0
y
=
400
y
=
400
class
Block2
(
pygame
.
sprite
.
Sprite
):
class
Block2
(
pygame
.
sprite
.
Sprite
):
def
__init__
(
self
,
image
):
def
__init__
(
self
,
image
):
...
@@ -23,6 +24,8 @@ screen = pygame.display.set_mode((1000, 600))
...
@@ -23,6 +24,8 @@ screen = pygame.display.set_mode((1000, 600))
FPS
=
pygame
.
time
.
Clock
()
# pygame时钟,控制游戏速度(帧数)
FPS
=
pygame
.
time
.
Clock
()
# pygame时钟,控制游戏速度(帧数)
zaw_list
=
pygame
.
sprite
.
Group
()
zaw_list
=
pygame
.
sprite
.
Group
()
# 载入图片
# 载入图片
font
=
pygame
.
font
.
Font
(
'STKAITI.ttf'
,
18
)
background
=
pygame
.
image
.
load
(
'bg.png'
)
# 背景
background
=
pygame
.
image
.
load
(
'bg.png'
)
# 背景
road
=
pygame
.
image
.
load
(
'road.png'
)
# 路
road
=
pygame
.
image
.
load
(
'road.png'
)
# 路
stone
=
pygame
.
image
.
load
(
'stone.png'
)
# 石头
stone
=
pygame
.
image
.
load
(
'stone.png'
)
# 石头
...
@@ -63,7 +66,7 @@ while True:
...
@@ -63,7 +66,7 @@ while True:
if
a
>=
5
:
if
a
>=
5
:
a
=
0
a
=
0
if
wukong
==
'up'
:
if
wukong
==
'up'
:
if
t
>
0
:
if
t
>
0
:
y
-=
t
y
-=
t
wukong_1
.
rect
.
y
=
y
wukong_1
.
rect
.
y
=
y
t
-=
2
t
-=
2
...
@@ -84,9 +87,11 @@ while True:
...
@@ -84,9 +87,11 @@ while True:
screen
.
blit
(
background
,
(
bg_x
,
0
))
screen
.
blit
(
background
,
(
bg_x
,
0
))
screen
.
blit
(
road
,
(
road_x
,
500
))
screen
.
blit
(
road
,
(
road_x
,
500
))
screen
.
blit
(
wukong_1
.
image
,
(
150
,
y
))
screen
.
blit
(
wukong_1
.
image
,
(
150
,
y
))
#z_x-=8
#z_x-=8
road_x
-=
8
text
=
font
.
render
(
'分数:'
+
str
(
score
),
True
,(
255
,
255
,
255
))
screen
.
blit
(
text
,(
900
,
50
))
road_x
-=
10
bg_x
-=
1
bg_x
-=
1
#if zaw.rect.x<= 0-zaw.rect.width:
#if zaw.rect.x<= 0-zaw.rect.width:
time
+=
1
time
+=
1
...
@@ -97,7 +102,7 @@ while True:
...
@@ -97,7 +102,7 @@ while True:
zaw
=
Block
(
stone
,
cacti
,
apple
)
zaw
=
Block
(
stone
,
cacti
,
apple
)
zaw_list
.
add
(
zaw
)
zaw_list
.
add
(
zaw
)
for
i
in
zaw_list
:
for
i
in
zaw_list
:
i
.
rect
.
x
-=
8
i
.
rect
.
x
-=
10
screen
.
blit
(
i
.
image
,
(
i
.
rect
.
x
,
500
-
i
.
rect
.
height
))
screen
.
blit
(
i
.
image
,
(
i
.
rect
.
x
,
500
-
i
.
rect
.
height
))
if
i
.
rect
.
x
<=
0
-
i
.
rect
.
width
:
if
i
.
rect
.
x
<=
0
-
i
.
rect
.
width
:
i
.
kill
()
i
.
kill
()
...
@@ -105,7 +110,11 @@ while True:
...
@@ -105,7 +110,11 @@ while True:
gmover
=
pygame
.
image
.
load
(
'gameover.png'
)
gmover
=
pygame
.
image
.
load
(
'gameover.png'
)
screen
.
blit
(
gmover
,(
400
,
250
))
screen
.
blit
(
gmover
,(
400
,
250
))
gameover
=
True
gameover
=
True
else
:
if
i
.
rect
.
x
<
wukong_1
.
rect
.
x
:
score
+=
i
.
score
i
.
score
=
0
#z=random.choice([stone,cacti,apple])
#z=random.choice([stone,cacti,apple])
#rect=stone.get_rect()
#rect=stone.get_rect()
#z_x=1000
#z_x=1000
...
...
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