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
15a7aed2
authored
Dec 12, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
4127e0fa
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
4 deletions
my_game.py
my_game.py
View file @
15a7aed2
...
...
@@ -2,7 +2,7 @@ import pygame
from
pygame
import
locals
from
pygame.time
import
Clock
as
TIME
from
pygame.display
import
set_mode
,
set_caption
,
update
from
pygame.image
import
from
pygame.image
import
load
from
random
import
choice
pygame
.
init
()
# 初始化
...
...
@@ -14,7 +14,7 @@ background = load('bg.png') # 背景
road_img
=
load
(
'road.png'
)
# 路
stone_img
=
load
(
'stone.png'
)
# 石头
cacti_img
=
load
(
'cacti.png'
)
# 仙人掌
apple
_img
=
load
(
'bush.png'
)
# 灌木丛
bush
_img
=
load
(
'bush.png'
)
# 灌木丛
hero_img
=
[
load
(
'hero1.png'
),
load
(
'hero2.png'
),
load
(
'hero3.png'
),
...
...
@@ -24,10 +24,11 @@ index = 0
jumpState
=
"runing"
y
=
400
t
=
30
obstacle
=
choice
([
stone_img
,
cacti_img
,
bush_img
])
obstacle_list
=
[
stone_img
,
cacti_img
,
bush_img
]
obstacle
=
choice
(
obstacle_list
)
rect
=
obstacle
.
get_rect
()
rect
.
x
=
1000
rect
.
y
=
500
-
rect
.
wid
g
h
rect
.
y
=
500
-
rect
.
wid
t
h
while
True
:
for
event
in
pygame
.
event
.
get
():
...
...
@@ -60,10 +61,18 @@ while True:
else
:
index
=
4
hero
=
hero_img
[
index
]
if
rect
.
x
<=
0
-
rect
.
width
:
obstacle
=
choice
(
obstacle_list
)
rect
=
obstacle
.
get_rect
()
rect
.
x
=
1000
rect
.
y
=
500
-
rect
.
height
rect
.
x
-=
8
# 将背景图画上去
screen
.
blit
(
background
,
(
0
,
0
))
screen
.
blit
(
road_img
,
(
0
,
500
))
screen
.
blit
(
hero
,
(
150
,
y
))
screen
.
blit
(
obstacle
,(
rect
.
x
,
rect
.
y
))
# 刷新画面
update
()
TIME
()
.
tick
(
60
)
\ No newline at end of file
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