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
ccbbc47a
authored
3 years ago
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
85a5d89e
c55519l1412p256a14377/wx412285
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
9 deletions
my_game.py
my_game.py
View file @
ccbbc47a
...
...
@@ -2,15 +2,27 @@ import pygame
from
pygame
import
locals
import
random
V
=
0
answer
=
input
(
'请选择难度:(简单,中等,困难)'
)
answer
=
input
(
'请选择难度:(简单,中等,困难
,反向
)'
)
if
answer
==
'简单'
:
V
=
1.33
elif
answer
==
'中等'
:
V
=
1.5
elif
answer
==
'困难'
:
V
=
2
elif
answer
==
'反向'
:
answer_2
=
input
(
'请再次选择难度:(简单,中等,困难)'
)
if
answer_2
==
'简单'
:
V
=
1.33
elif
answer_2
==
'中等'
:
V
=
1.5
elif
answer_2
==
'困难'
:
V
=
2
else
:
V
=
0.1
print
(
'芜湖起飞!!!!'
)
else
:
V
=
0.1
print
(
'芜湖起飞!!!!'
)
pygame
.
init
()
# 初始化
# 创建一个窗口
screen
=
pygame
.
display
.
set_mode
((
1000
,
600
))
...
...
@@ -39,9 +51,13 @@ class Block(pygame.sprite.Sprite):
super
()
.
__init__
()
self
.
image
=
random
.
choice
([
image1
,
image2
,
image3
])
self
.
rect
=
self
.
image
.
get_rect
()
self
.
rect
.
x
=
1000
if
answer
==
'反向'
:
self
.
rect
.
x
=
0
else
:
self
.
rect
.
x
=
1000
self
.
rect
.
y
=
500
-
self
.
rect
.
height
obstacle
=
Block
(
bush
,
stone
,
cacti
)
block_list
=
pygame
.
sprite
.
Group
()
while
True
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
...
...
@@ -79,20 +95,31 @@ while True:
if
road_x
<=
-
1000
:
road_x
=
0
time
+=
1
if
time
>
60
if
time
>
60
:
time
=
0
num
=
random
(
0
,
50
)
num
=
random
.
randint
(
0
,
50
)
if
num
>
20
:
screen
.
blit
(
sprite
.
image
,(
sprite
.
rect
.
x
,
sprite
.
rect
.
y
))
obstacle
=
Block
(
bush
,
cacti
,
stone
)
block_list
.
add
(
obstacle
)
# 将背景图画上去
screen
.
blit
(
background
,
(
beijing_x
,
0
))
# 远处背景
screen
.
blit
(
road
,
(
road_x
,
500
))
# 路
screen
.
blit
(
wukong
,
(
150
,
y
))
# 悟空
block_list
=
pygame
.
sprite
.
Group
()
block_list
.
append
(
sprite
)
if
answer
==
'反向'
:
screen
.
blit
(
wukong
,(
600
,
y
))
else
:
screen
.
blit
(
wukong
,
(
150
,
y
))
# 悟空
for
sprite
in
block_list
:
sprite
.
rect
.
x
-=
8
if
answer
==
'反向'
:
sprite
.
rect
.
x
+=
8
else
:
sprite
.
rect
.
x
-=
8
screen
.
blit
(
sprite
.
image
,(
sprite
.
rect
.
x
,
sprite
.
rect
.
y
))
if
answer
==
'反向'
:
if
sprite
.
rect
.
x
>=
1000
+
sprite
.
rect
.
width
:
sprite
.
kill
()
else
:
if
sprite
.
rect
.
x
<=
0
-
sprite
.
rect
.
width
:
sprite
.
kill
()
# 刷新画面
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