Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
level3-lesson23-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
f806fa83
authored
May 15, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
412a3526
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
21 deletions
__pycache__/settings.cpython-37.pyc
lkl.py
settings.py
__pycache__/settings.cpython-37.pyc
0 → 100644
View file @
f806fa83
File added
lkl.py
View file @
f806fa83
import
sys
import
sys
import
pygame
import
pygame
import
settings
pygame
.
init
()
pygame
.
init
()
bg_color1
=
(
0
,
120
,
120
)
bg_color2
=
(
60
,
60
,
60
)
#主窗口
#主窗口
screen_image
=
pygame
.
display
.
set_mode
((
800
,
600
))
screen_image
=
pygame
.
display
.
set_mode
((
800
,
600
))
screen_rect
=
screen_image
.
get_rect
()
screen_rect
=
screen_image
.
get_rect
()
...
@@ -12,16 +12,12 @@ pygame.display.set_caption("飞机大战")
...
@@ -12,16 +12,12 @@ pygame.display.set_caption("飞机大战")
#飞机
#飞机
ship
=
pygame
.
image
.
load
(
"002.png"
)
ship
=
pygame
.
image
.
load
(
"002.png"
)
ship_rect
=
ship
.
get_rect
()
ship_rect
=
ship
.
get_rect
()
ship_rect
.
center
=
screen_rect
.
center
ship_rect
.
midbottom
=
screen_rect
.
midbottom
moving_left
=
False
moving_right
=
False
#子弹
#子弹
bullet_rect
=
pygame
.
Rect
(
0
,
0
,
3
,
15
)
bullets
=
[]
bullet_rect
.
midbottom
=
ship_rect
.
midtop
#文字
txt_font
=
pygame
.
font
.
SysFont
(
None
,
48
)
txt_image
=
txt_font
.
render
(
"50"
,
True
,
bg_color2
,
bg_color1
)
txt_rect
=
txt_image
.
get_rect
()
txt_rect
.
x
=
740
txt_rect
.
y
=
20
#死循环
#死循环
while
True
:
while
True
:
for
event
in
pygame
.
event
.
get
():
for
event
in
pygame
.
event
.
get
():
...
@@ -29,17 +25,34 @@ while True:
...
@@ -29,17 +25,34 @@ while True:
sys
.
exit
()
sys
.
exit
()
elif
event
.
type
==
pygame
.
KEYDOWN
:
elif
event
.
type
==
pygame
.
KEYDOWN
:
if
event
.
key
==
pygame
.
K_LEFT
:
if
event
.
key
==
pygame
.
K_LEFT
:
ship_rect
.
x
-=
10
moving_left
=
True
if
event
.
key
==
pygame
.
K_RIGHT
:
if
event
.
key
==
pygame
.
K_RIGHT
:
ship_rect
.
x
+=
10
moving_right
=
True
if
event
.
key
==
pygame
.
K_UP
:
if
event
.
key
==
pygame
.
K_SPACE
:
ship_rect
.
y
-=
10
if
len
(
bullets
)
<
5
:
if
event
.
key
==
pygame
.
K_DOWN
:
new_bullet_rect
=
pygame
.
Rect
(
0
,
0
,
3
,
15
)
ship_rect
.
y
+=
10
new_bullet_rect
.
midbottom
=
ship_rect
.
midtop
bullet_rect
.
y
-=
1
bullets
.
append
(
new_bullet_rect
)
elif
event
.
type
==
pygame
.
KEYUP
:
if
event
.
key
==
pygame
.
K_LEFT
:
moving_left
=
False
if
event
.
key
==
pygame
.
K_RIGHT
:
moving_right
=
False
if
moving_left
and
ship_rect
.
left
>
0
:
ship_rect
.
x
-=
settings
.
ship_speed
if
moving_right
and
ship_rect
.
right
<
screen_rect
.
right
:
ship_rect
.
x
+=
settings
.
ship_speed
#绘制图像
#绘制图像
screen_image
.
fill
(
bg_color1
)
screen_image
.
fill
(
settings
.
bg_color1
)
screen_image
.
blit
(
ship
,
ship_rect
)
screen_image
.
blit
(
ship
,
ship_rect
)
pygame
.
draw
.
rect
(
screen_image
,
bg_color2
,
bullet_rect
)
screen_image
.
blit
(
txt_image
,
txt_rect
)
for
bullet_rect
in
bullets
:
pygame
.
draw
.
rect
(
screen_image
,
settings
.
bg_color30
,
bullet_rect
)
bullet_rect
.
y
-=
1
if
bullet_rect
.
bottom
<
0
:
bullets
.
remove
(
bullet_rect
)
pygame
.
display
.
flip
()
pygame
.
display
.
flip
()
\ No newline at end of file
settings.py
0 → 100644
View file @
f806fa83
bg_color1
=
(
0
,
120
,
120
)
bg_color2
=
(
60
,
60
,
60
)
bg_color3
=
(
255
,
0
,
0
)
ship_speed
=
5
\ 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