Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson3_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
a5cf5625
authored
Sep 04, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
a5133b7c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
5 deletions
PYG03-flower.png
ballgame.py
PYG03-flower.png
0 → 100644
View file @
a5cf5625
2.98 KB
ballgame.py
View file @
a5cf5625
import
pygame
pygame
.
init
()
size
=
width
,
height
=
600
,
400
v
=
pygame
.
display
.
Info
()
print
(
v
)
size
=
width
,
height
=
v
.
current_w
,
v
.
current_h
f
=
pygame
.
time
.
Clock
()
speed
=
[
1
,
1
]
BLACK
=
0
,
0
,
0
screen
=
pygame
.
display
.
set_mode
((
600
,
400
))
pygame
.
display
.
set_caption
(
"Pygame壁球"
)
# screen = pygame.display.set_mode(size,pygame.FULLSCREEN)#窗口全屏显示
# screen = pygame.display.set_mode(size,pygame.NOFRAME)
screen
=
pygame
.
display
.
set_mode
(
size
,
pygame
.
RESIZABLE
)
ball
=
pygame
.
image
.
load
(
"pyg02-ball.gif"
)
i
=
pygame
.
image
.
load
(
"PYG03-flower.png"
)
pygame
.
display
.
set_icon
(
i
)
pygame
.
display
.
set_caption
(
"Pygame壁球"
)
ball
=
pygame
.
image
.
load
(
"apple.png"
)
ballrect
=
ball
.
get_rect
()
while
True
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
pygame
.
QUIT
:
exit
()
elif
event
.
type
==
pygame
.
KEYDOWN
:
if
event
.
key
==
pygame
.
K_LEFT
:
if
speed
[
0
]
<
0
:
speed
[
0
]
=
speed
[
0
]
+
1
if
speed
[
0
]
>
0
:
speed
[
0
]
=
speed
[
0
]
-
1
elif
event
.
key
==
pygame
.
K_RIGHT
:
if
speed
[
0
]
>=
0
:
speed
[
0
]
=
speed
[
0
]
+
1
if
speed
[
0
]
<
0
:
speed
[
0
]
=
speed
[
0
]
-
1
elif
event
.
key
==
pygame
.
K_UP
:
if
speed
[
1
]
>
0
:
speed
[
1
]
=
speed
[
1
]
+
1
if
speed
[
1
]
<
0
:
speed
[
1
]
=
speed
[
1
]
-
1
elif
event
.
key
==
pygame
.
K_DOWN
:
if
speed
[
1
]
<
0
:
speed
[
1
]
=
speed
[
1
]
+
1
if
speed
[
1
]
>
0
:
speed
[
1
]
=
speed
[
1
]
-
1
elif
event
.
key
==
pygame
.
K_ESCAPE
:
exit
()
elif
event
.
type
==
pygame
.
VIDEORESIZE
:
size
=
width
,
height
=
event
.
size
[
0
],
event
.
size
[
1
]
screen
=
pygame
.
display
.
set_mode
(
size
,
pygame
.
RESIZABLE
)
if
pygame
.
display
.
get_active
():
ballrect
=
ballrect
.
move
(
speed
)
ballrect
=
ballrect
.
move
(
speed
[
0
],
speed
[
1
])
if
ballrect
.
left
<
0
or
ballrect
.
right
>
width
:
speed
[
0
]
=-
speed
[
0
]
...
...
@@ -26,6 +61,6 @@ while True:
screen
.
fill
(
BLACK
)
screen
.
blit
(
ball
,
ballrect
)
pygame
.
display
.
update
()
f
.
tick
(
4
00
)
f
.
tick
(
6
00
)
\ 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