Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson7_diy1
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
1e23e9d8
authored
3 years ago
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
b1df6cd9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
6 deletions
my_game.py
my_game.py
View file @
1e23e9d8
...
@@ -11,6 +11,7 @@ class Block(pygame.sprite.Sprite):
...
@@ -11,6 +11,7 @@ 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
class
player
(
pygame
.
sprite
.
Sprite
):
class
player
(
pygame
.
sprite
.
Sprite
):
def
__init__
(
self
,
image
):
def
__init__
(
self
,
image
):
...
@@ -31,6 +32,7 @@ road = pygame.image.load('road.png') # 路
...
@@ -31,6 +32,7 @@ road = pygame.image.load('road.png') # 路
stone
=
pygame
.
image
.
load
(
'stone.png'
)
# 石头
stone
=
pygame
.
image
.
load
(
'stone.png'
)
# 石头
cacti
=
pygame
.
image
.
load
(
'cacti.png'
)
# 仙人掌
cacti
=
pygame
.
image
.
load
(
'cacti.png'
)
# 仙人掌
bush
=
pygame
.
image
.
load
(
'bush.png'
)
# 灌木丛
bush
=
pygame
.
image
.
load
(
'bush.png'
)
# 灌木丛
basic_font
=
pygame
.
font
.
Font
(
'STKAITI.TTF'
,
18
)
hero
=
[
pygame
.
image
.
load
(
'hero1.png'
),
hero
=
[
pygame
.
image
.
load
(
'hero1.png'
),
pygame
.
image
.
load
(
'hero2.png'
),
pygame
.
image
.
load
(
'hero2.png'
),
pygame
.
image
.
load
(
'hero3.png'
),
pygame
.
image
.
load
(
'hero3.png'
),
...
@@ -44,9 +46,9 @@ nu = 30
...
@@ -44,9 +46,9 @@ nu = 30
road_x
=
0
road_x
=
0
bg_x
=
0
bg_x
=
0
time
=
0
time
=
0
#zhuangzhe = Block(stone,cacti,bush)
block_list
=
pygame
.
sprite
.
Group
()
block_list
=
pygame
.
sprite
.
Group
()
huabu
=
True
huabu
=
True
score
=
0
while
True
:
while
True
:
for
event
in
pygame
.
event
.
get
():
for
event
in
pygame
.
event
.
get
():
...
@@ -96,10 +98,6 @@ while True:
...
@@ -96,10 +98,6 @@ while True:
screen
.
blit
(
wukong
.
image
,
(
150
,
y
))
screen
.
blit
(
wukong
.
image
,
(
150
,
y
))
# 刷新画面
# 刷新画面
#if zhuangzhe.rect.x <= 0-zhuangzhe.rect.width:
#zhuangzhe = Block(stone,cacti,bush)
#zhuangzhe.rect.x -= 8
time
+=
1
time
+=
1
if
time
>=
60
:
if
time
>=
60
:
time
=
0
time
=
0
...
@@ -116,8 +114,13 @@ while True:
...
@@ -116,8 +114,13 @@ while True:
gameover
=
pygame
.
image
.
load
(
'gameover.png'
)
gameover
=
pygame
.
image
.
load
(
'gameover.png'
)
screen
.
blit
(
gameover
,(
400
,
200
))
screen
.
blit
(
gameover
,(
400
,
200
))
huabu
=
False
huabu
=
False
else
:
if
(
prop
.
rect
.
x
+
prop
.
rect
.
width
)
<
wukong
.
rect
.
x
:
score
+=
sprite
.
score
scoreSurf
=
basic_font
.
render
(
"分数"
+
str
(
score
),
True
,(
255
,
255
,
255
))
screen
.
blit
(
scoreSurf
,(
880
,
20
))
#screen.blit(zhuangzhe.image, (zhuangzhe.rect.x, zhuangzhe.rect.y))
pygame
.
display
.
update
()
pygame
.
display
.
update
()
FPS
.
tick
(
60
)
FPS
.
tick
(
60
)
...
...
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