Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
13680905
Break the Stones3
Commits
922654d7
Commit
922654d7
authored
Oct 30, 2020
by
13680905
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
b4e21983
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
96 additions
and
0 deletions
+96
-0
pppppp.py
pppppp.py
+96
-0
No files found.
pppppp.py
0 → 100644
View file @
922654d7
import
pygame
from
planes_sprites
import
*
pygame
.
init
()
#创建游戏窗口大小
screen
=
pygame
.
display
.
set_mode
((
480
,
700
))
#创建背景图像
bg
=
pygame
.
image
.
load
(
"./images/background.png"
)
screen
.
blit
(
bg
,(
0
,
0
))
pygame
.
display
.
update
()
#创建英雄飞机
hero
=
pygame
.
image
.
load
(
"./images/me1.png"
)
hero2
=
pygame
.
image
.
load
(
"./images/me2.png"
)
screen
.
blit
(
hero
,(
150
,
500
))
hero_rect
=
pygame
.
Rect
(
150
,
500
,
102
,
126
)
#在所有绘制工作完成后,统一调用update方法
pygame
.
display
.
update
()
#创建时钟对象
clock
=
pygame
.
time
.
Clock
()
i
=
0
l
=
0
#建立精灵组和精灵
enemy
=
GameSprite
(
"./images/enemy1.png"
)
#创建敌机
enemy2
=
GameSprite
(
"./images/enemy2.png"
,
2
)
#创建敌机2
enemy_group
=
pygame
.
sprite
.
Group
(
enemy
,
enemy2
)
#创建游戏内循环
p
=
0
#控制水平控制的可控变量
o
=
2
#控制垂直控制的可控变量
while
True
:
#1.创建动画的英雄飞机
if
i
==
1
:
k
=
hero2
i
=
0
else
:
k
=
hero
i
=
1
clock
.
tick
(
60
)
for
event
in
pygame
.
event
.
get
():
print
(
event
)
#英雄飞机的水平运动控制
if
event
.
type
==
pygame
.
QUIT
:
print
(
"游戏退出"
)
if
event
.
type
==
pygame
.
KEYDOWN
:
if
event
.
key
==
276
:
print
(
"英雄飞机向左移动"
)
p
=-
o
if
event
.
key
==
275
:
print
(
"英雄飞机向左移动"
)
p
=
o
if
event
.
type
==
pygame
.
KEYUP
:
if
p
==
o
:
if
event
.
key
==
275
:
p
=
0
if
p
==-
o
:
if
event
.
key
==
276
:
p
=
0
#英雄飞机的垂直运动控制
if
event
.
type
==
pygame
.
KEYDOWN
:
if
event
.
key
==
273
:
print
(
"英雄飞机向上移动"
)
l
=
-
o
if
event
.
key
==
274
:
print
(
"英雄飞机向下移动"
)
l
=
o
if
event
.
type
==
pygame
.
KEYUP
:
if
l
==
o
:
if
event
.
key
==
274
:
l
=
0
if
l
==
-
o
:
if
event
.
key
==
273
:
l
=
0
hero_rect
.
x
+=
p
hero_rect
.
y
+=
l
screen
.
blit
(
bg
,
(
0
,
0
))
if
enemy
.
rect
.
y
>
700
:
print
(
"5555"
)
enemy
.
rect
.
y
=
0
elif
enemy2
.
rect
.
y
>
700
:
enemy2
.
rect
.
y
=
0
# 创建游戏内逻辑边界
if
hero_rect
.
y
<
-
102
:
hero_rect
=
pygame
.
Rect
(
150
,
700
,
102
,
126
)
#检测碰撞效果
if
enemy
.
rect
.
y
>
hero_rect
.
y
or
enemy2
.
rect
.
y
>
hero_rect
.
y
:
print
(
"碰撞"
)
if
pygame
.
sprite
.
collide_mask
(
hero
,
enemy
):
print
(
"Collision occurred"
)
enemy_group
.
update
()
enemy_group
.
draw
(
screen
)
screen
.
blit
(
k
,
hero_rect
)
pygame
.
display
.
update
()
\ 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