Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson8_diy3
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
b09a9a2c
authored
Oct 29, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
1a2919f4
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
19 deletions
my_game.py
my_game.py
View file @
b09a9a2c
...
@@ -28,17 +28,16 @@ hero = [pygame.image.load('hero1.png'),
...
@@ -28,17 +28,16 @@ hero = [pygame.image.load('hero1.png'),
pygame
.
image
.
load
(
'hero4.png'
),
pygame
.
image
.
load
(
'hero4.png'
),
pygame
.
image
.
load
(
'hero5.png'
)]
pygame
.
image
.
load
(
'hero5.png'
)]
#变量初始化
#变量初始化
lu_x
=
0
shan_x
=
0
index
=
0
index
=
0
y
=
400
y
=
400
jumpState
=
"runing"
jumpState
=
"runing"
t
=
30
t
=
30
zhangaiwu
=
choice
([
bush
,
cacti
,
stone
])
#随机获得一个障碍物
xingzhuang
=
zhangaiwu
.
get_rect
()
#获得障碍物的坐标和宽,高
xingzhuang
.
x
=
1000
#使障碍物的x为1000
xingzhuang
.
y
=
500
-
xingzhuang
.
height
#初始化障碍物的坐标
bg_x
=
0
road_x
=
0
time
=
0
block_list
=
pygame
.
sprite
.
Group
()
while
True
:
while
True
:
for
event
in
pygame
.
event
.
get
():
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
if
event
.
type
==
locals
.
QUIT
:
...
@@ -70,27 +69,27 @@ while True:
...
@@ -70,27 +69,27 @@ while True:
if
index
>=
5
:
if
index
>=
5
:
index
=
0
index
=
0
# 将背景图画上去
# 将背景图画上去
shan
_x
-=
2
bg
_x
-=
2
if
shan
_x
<-
1000
:
if
bg
_x
<-
1000
:
shan
_x
=
0
bg
_x
=
0
screen
.
blit
(
background
,
(
shan
_x
,
0
))
# 远处背景
screen
.
blit
(
background
,
(
bg
_x
,
0
))
# 远处背景
lu
_x
-=
8
road
_x
-=
8
if
lu
_x
<-
1000
:
if
road
_x
<-
1000
:
lu
_x
=
0
road
_x
=
0
screen
.
blit
(
road
,
(
lu
_x
,
500
))
# 路
screen
.
blit
(
road
,
(
road
_x
,
500
))
# 路
screen
.
blit
(
wukong
,
(
150
,
y
))
# 悟空
screen
.
blit
(
wukong
,
(
150
,
y
))
# 悟空
zhangaiwu
=
Block
(
bush
,
cacti
,
stone
)
xingzhuang
.
x
-=
8
block_list
.
add
(
zhangaiwu
)
if
xingzhuang
.
x
<
0
-
xingzhuang
.
width
:
if
xingzhuang
.
x
<
0
-
xingzhuang
.
width
:
zhangaiwu
=
choice
([
bush
.
cacti
,
stone
])
zhangaiwu
=
choice
([
bush
.
cacti
,
stone
])
zhangaiwu
=
choice
([
bush
,
cacti
,
stone
])
#随机获得一个障碍物
zhangaiwu
=
choice
([
bush
,
cacti
,
stone
])
#随机获得一个障碍物
xingzhuang
=
zhangaiwu
.
gut_rest
()
#获得障碍物的坐标和宽,高
xingzhuang
=
zhangaiwu
.
gut_rest
()
#获得障碍物的坐标和宽,高
xingzhuang
.
x
=
1000
#使障碍物的x为1000
xingzhuang
.
x
=
1000
#使障碍物的x为1000
xingzhuang
.
y
=
500
-
xingzhuang
.
height
#初始化障碍物的坐标
xingzhuang
.
y
=
500
-
xingzhuang
.
height
#初始化障碍物的坐标
time
+=
1
if
time
>=
60
screen
.
blit
(
zhangaiwu
,(
xingzhuang
.
x
,
xingzhuang
.
y
))
for
sprite
in
block_list
:
sprite
.
rect
.
x
-=
8
screen
.
blit
(
sprite
.
image
,(
sprite
.
rect
.
x
,
sprite
.
rect
.
y
))
# 刷新画面
# 刷新画面
pygame
.
display
.
update
()
pygame
.
display
.
update
()
...
...
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