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
7ce2dc6b
authored
Sep 25, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
0245f4e3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
14 deletions
my_game.py
my_game.py
View file @
7ce2dc6b
...
...
@@ -3,11 +3,25 @@ import random
from
pygame
import
locals
pygame
.
init
()
# 初始化
# 创建一个窗口
class
Block
(
pygame
.
sprite
.
Sprite
):
def
__init__
(
self
,
image1
,
image2
,
image3
):
super
()
.
__init__
()
self
.
image
=
random
.
choice
([
image1
,
image2
,
image3
])
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
):
self
.
image
=
image
self
.
rect
=
self
.
image
.
get_rect
()
self
.
rect
.
x
=
150
self
.
rect
.
y
=
400
screen
=
pygame
.
display
.
set_mode
((
1000
,
600
))
FPS
=
pygame
.
time
.
Clock
()
# pygame时钟,控制游戏速度(帧数)
pygame
.
display
.
set_caption
(
'悟空酷跑'
)
class
Block
(
pygame
.
sprite
.
Sprite
):
# 载入图片
background
=
pygame
.
image
.
load
(
'bg.png'
)
# 背景
road
=
pygame
.
image
.
load
(
'road.png'
)
# 路
...
...
@@ -26,10 +40,7 @@ y = 400
bg_x
=
0
road_x
=
0
time
=
0
obstable
=
random
.
choice
([
apple
,
stone
,
cacti
])
rect
=
obstable
.
get_rect
()
rect
.
x
=
1000
rect
.
y
=
500
-
rect
.
height
block_list
=
pygame
.
sprite
.
Group
()
while
True
:
...
...
@@ -77,7 +88,7 @@ while True:
if
time
>=
60
:
r
=
random
.
randint
(
0
,
100
)
if
r
>
40
:
obstable
=
Block
(
bush
,
cacti
,
stone
)
obstable
=
Block
(
apple
,
cacti
,
stone
)
block_list
.
add
(
obstable
)
time
=
0
for
prop
in
block_list
:
...
...
@@ -85,13 +96,8 @@ while True:
screen
.
blit
(
prop
.
image
,(
prop
.
rect
.
x
,
prop
.
rect
.
y
))
if
prop
.
rect
.
x
<
0
-
prop
.
rect
.
width
:
prop
.
kill
()
if
rect
.
x
<=
0
-
rect
.
width
:
obstable
=
random
.
choice
([
apple
,
stone
,
cacti
])
rect
=
obstable
.
get_rect
()
rect
.
x
=
1000
rect
.
y
=
500
-
rect
.
height
rect
.
x
-=
10
screen
.
blit
(
obstable
,(
rect
.
x
,
rect
.
y
))
# 刷新画面
...
...
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