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
b0c1e74b
authored
3 years ago
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
f5d37d85
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
13 deletions
my_game.py
my_game.py
View file @
b0c1e74b
...
...
@@ -3,6 +3,14 @@ from pygame import locals
import
random
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
# 创建一个窗口
screen
=
pygame
.
display
.
set_mode
((
1000
,
600
))
FPS
=
pygame
.
time
.
Clock
()
# pygame时钟,控制游戏速度(帧数)
...
...
@@ -23,10 +31,10 @@ index = 0
y
=
400
jumpSatate
=
"running"
t
=
30
obstacle
=
random
.
choice
([
bush
,
stone
,
cacti
])
rect
=
obstacle
.
get_rect
()
rect
.
x
=
1000
rect
.
y
=
500
-
rect
.
height
rode_x
=
0
background_x
=
0
block_list
=
pygame
.
sprite
.
Group
()
while
True
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
...
...
@@ -56,16 +64,21 @@ while True:
if
index
==
5
:
index
=
0
# 将背景图画上去
screen
.
blit
(
background
,
(
0
,
0
))
screen
.
blit
(
road
,
(
0
,
500
))
if
rode_x
<=-
1000
:
rode_x
=
0
if
background_x
<=-
1000
:
background_x
=
0
background_x
-=
0.5
screen
.
blit
(
background
,
(
background_x
,
0
))
rode_x
-=
8
screen
.
blit
(
road
,
(
rode_x
,
500
))
screen
.
blit
(
wukong
,
(
150
,
y
))
# 刷新画面
if
rect
.
x
<=
0
-
rect
.
width
:
obstacle
=
choice
([
bush
,
stone
,
cacti
])
rect
=
obstacle
.
get_rect
()
rect
.
x
=
1000
rect
.
y
=
500
-
rect
.
height
rect
.
x
-=
8
screen
.
blit
(
obstacle
,(
rect
.
x
,
rect
.
y
))
obstacle
=
Block
(
bush
,
cacti
,
stone
)
block_list
.
add
(
obstacle
)
for
sprite
in
block_list
:
sprite
.
rect
.
x
-=
8
screen
.
blit
(
sprite
.
image
,(
sprite
.
rect
.
x
,
sprite
.
rect
.
y
))
screen
.
blit
(
obstacle
.
image
,(
obstacle
.
rect
.
x
,
obstacle
.
rect
.
y
))
pygame
.
display
.
update
()
FPS
.
tick
(
60
)
\ No newline at end of file
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