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
Jul 20, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
85a5d89e
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
...
@@ -2,15 +2,27 @@ import pygame
from
pygame
import
locals
from
pygame
import
locals
import
random
import
random
V
=
0
V
=
0
answer
=
input
(
'请选择难度:(简单,中等,困难)'
)
answer
=
input
(
'请选择难度:(简单,中等,困难
,反向
)'
)
if
answer
==
'简单'
:
if
answer
==
'简单'
:
V
=
1.33
V
=
1.33
elif
answer
==
'中等'
:
elif
answer
==
'中等'
:
V
=
1.5
V
=
1.5
elif
answer
==
'困难'
:
elif
answer
==
'困难'
:
V
=
2
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
:
else
:
V
=
0.1
V
=
0.1
print
(
'芜湖起飞!!!!'
)
pygame
.
init
()
# 初始化
pygame
.
init
()
# 初始化
# 创建一个窗口
# 创建一个窗口
screen
=
pygame
.
display
.
set_mode
((
1000
,
600
))
screen
=
pygame
.
display
.
set_mode
((
1000
,
600
))
...
@@ -39,9 +51,13 @@ class Block(pygame.sprite.Sprite):
...
@@ -39,9 +51,13 @@ class Block(pygame.sprite.Sprite):
super
()
.
__init__
()
super
()
.
__init__
()
self
.
image
=
random
.
choice
([
image1
,
image2
,
image3
])
self
.
image
=
random
.
choice
([
image1
,
image2
,
image3
])
self
.
rect
=
self
.
image
.
get_rect
()
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
self
.
rect
.
y
=
500
-
self
.
rect
.
height
obstacle
=
Block
(
bush
,
stone
,
cacti
)
obstacle
=
Block
(
bush
,
stone
,
cacti
)
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
:
...
@@ -79,20 +95,31 @@ while True:
...
@@ -79,20 +95,31 @@ while True:
if
road_x
<=
-
1000
:
if
road_x
<=
-
1000
:
road_x
=
0
road_x
=
0
time
+=
1
time
+=
1
if
time
>
60
if
time
>
60
:
time
=
0
time
=
0
num
=
random
(
0
,
50
)
num
=
random
.
randint
(
0
,
50
)
if
num
>
20
:
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
(
background
,
(
beijing_x
,
0
))
# 远处背景
screen
.
blit
(
road
,
(
road_x
,
500
))
# 路
screen
.
blit
(
road
,
(
road_x
,
500
))
# 路
screen
.
blit
(
wukong
,
(
150
,
y
))
# 悟空
if
answer
==
'反向'
:
block_list
=
pygame
.
sprite
.
Group
()
screen
.
blit
(
wukong
,(
600
,
y
))
block_list
.
append
(
sprite
)
else
:
screen
.
blit
(
wukong
,
(
150
,
y
))
# 悟空
for
sprite
in
block_list
:
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
))
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
()
pygame
.
display
.
update
()
FPS
.
tick
(
60
)
FPS
.
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