Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
level3-lesson24-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
41eebcf9
authored
3 years ago
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
d2824a47
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
45 additions
and
18 deletions
3.py
background.png
gray_ball.png
laofanqie.py
q/main.py
render.html
3.py
View file @
41eebcf9
...
...
@@ -21,8 +21,17 @@ while True:
if
event
.
type
==
pygame
.
QUIT
:
sys
.
exit
()
if
event
.
type
==
pygame
.
KEYDOWN
:
if
event
.
key
==
pygame
.
K_ESCAPE
:
exit
()
if
event
.
key
==
pygame
.
K_LEFT
:
speed
[
0
]
=
speed
[
0
]
if
speed
[
0
]
==
0
else
(
abs
(
speed
[
0
])
-
1
)
if
event
.
key
==
pygame
.
K_RIGHT
:
speed
[
0
]
=
speed
[
0
]
+
1
if
speed
[
0
]
>
0
else
speed
[
0
]
-
1
if
event
.
key
==
pygame
.
K_UP
:
speed
[
1
]
=
speed
[
1
]
+
1
if
speed
[
1
]
>
0
else
speed
[
1
]
-
1
if
event
.
key
==
pygame
.
K_DOWN
:
speed
[
1
]
=
speed
[
1
]
if
speed
[
1
]
==
0
else
(
abs
(
speed
[
1
])
-
1
)
ballrect
=
ballrect
.
move
(
speed
[
0
],
speed
[
1
])
if
event
.
type
==
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
)
...
...
This diff is collapsed.
Click to expand it.
background.png
0 → 100644
View file @
41eebcf9
172 KB
This diff is collapsed.
Click to expand it.
gray_ball.png
0 → 100644
View file @
41eebcf9
9.96 KB
This diff is collapsed.
Click to expand it.
laofanqie.py
deleted
100644 → 0
View file @
d2824a47
xxx
=
1000
while
xxx
==
1
or
xxx
<
1
:
print
(
xxx
)
xxx
=
xxx
-
1
This diff is collapsed.
Click to expand it.
q/main.py
View file @
41eebcf9
...
...
@@ -2,10 +2,11 @@ import pygame
import
sys
from
pygame.locals
import
*
from
random
import
*
import
math
class
Ball
(
pygame
.
sprite
.
Sprite
):
def
__init__
(
self
,
image
,
position
,
speed
,
bg_size
):
pygame
.
sprite
.
Sprite
.
__init__
(
self
)
self
.
image
=
=
pygame
.
image
.
load
(
image
)
.
convert_alpha
()
self
.
image
=
pygame
.
image
.
load
(
image
)
.
convert_alpha
()
self
.
rect
=
self
.
image
.
get_rect
()
self
.
rect
.
left
,
self
.
rect
.
top
=
position
self
.
speed
=
speed
...
...
@@ -20,21 +21,33 @@ class Ball(pygame.sprite.Sprite):
self
.
rect
.
top
=
self
.
height
elif
self
.
rect
.
top
>
self
.
height
:
self
.
rect
.
bottom
=
0
def
collide_check
(
item
,
target
):
col_balls
=
[]
for
each
in
target
:
distance
=
math
.
sqrt
(
math
.
pow
((
item
.
rect
.
center
[
0
]
-
each
.
rect
.
center
[
0
]),
2
)
+
math
.
pow
((
item
.
rect
.
center
[
1
]
-
each
.
rect
.
center
[
1
]),
2
))
if
distance
<=
(
item
.
rect
.
width
+
each
.
rect
.
width
)
/
2
:
col_balls
.
append
(
each
)
return
col_balls
def
main
():
pygame
.
init
()
ball
=
'
gray_ball.png'
bg_image
=
'backg
ound.png'
ball
_image
=
r'C:\Users\Administrator\Documents\level3-lesson24-diy3\q\
gray_ball.png'
bg_image
=
r'C:\Users\Administrator\Documents\level3-lesson24-diy3\q\backgr
ound.png'
running
=
True
bg_size
=
width
,
height
=
1048
,
681
screen
=
pygame
.
display
.
set_mode
(
bg_size
)
pygame
.
display
.
set_caption
(
'Play the ball demo'
)
background
=
pygame
.
image
.
load
(
bg_image
)
.
convert_alpha
()
balls
=
[]
for
i
in
range
(
5
):
group
=
pygame
.
sprite
.
Group
()
ballnum
=
5
for
i
in
range
(
ballnum
):
position
=
randint
(
0
,
width
-
100
),
randint
(
0
,
height
-
100
)
speed
=
[
randint
(
-
10
,
10
),
randint
(
-
10
,
10
)]
ball
=
Ball
(
ball_image
,
position
,
speed
,
bg_size
)
while
pygame
.
sprite
.
spritecollide
(
ball
,
group
,
False
,
pygame
.
sprite
.
collide_circle
):
ball
.
rect
.
left
,
ball
.
rect
.
top
=
randint
(
0
,
width
-
100
),
randint
(
0
,
height
-
100
)
balls
.
append
(
ball
)
group
.
add
(
ball
)
clock
=
pygame
.
time
.
Clock
()
while
running
:
for
event
in
pygame
.
event
.
get
():
...
...
@@ -44,6 +57,18 @@ def main():
for
each
in
balls
:
each
.
move
()
screen
.
blit
(
each
.
image
,
each
.
rect
)
# for i in range(ballnum):
# item=balls.pop(i)
# if collide_check(item,balls):
# item.speed[0]=-item.speed[0]
# item.speed[1]=-item.speed[1]
# balls.insert(i,item)
for
each
in
group
:
group
.
remove
(
each
)
if
pygame
.
sprite
.
spritecollide
(
each
,
group
,
False
,
pygame
.
sprite
.
collide_circle
):
each
.
speed
[
0
]
=-
each
.
speed
[
0
]
each
.
speed
[
1
]
=-
each
.
speed
[
1
]
group
.
add
(
each
)
pygame
.
display
.
flip
()
clock
.
tick
(
30
)
main
()
This diff is collapsed.
Click to expand it.
render.html
View file @
41eebcf9
...
...
@@ -7,11 +7,11 @@
</head>
<body>
<div
id=
"
eded43a60fc7485aaff3468a66ef3900
"
class=
"chart-container"
style=
"width:900px; height:500px;"
></div>
<div
id=
"
acd35138ed03410eb4a791040990d2ad
"
class=
"chart-container"
style=
"width:900px; height:500px;"
></div>
<script>
var
chart_
eded43a60fc7485aaff3468a66ef3900
=
echarts
.
init
(
document
.
getElementById
(
'
eded43a60fc7485aaff3468a66ef3900
'
),
'white'
,
{
renderer
:
'canvas'
});
var
option_
eded43a60fc7485aaff3468a66ef3900
=
{
var
chart_
acd35138ed03410eb4a791040990d2ad
=
echarts
.
init
(
document
.
getElementById
(
'
acd35138ed03410eb4a791040990d2ad
'
),
'white'
,
{
renderer
:
'canvas'
});
var
option_
acd35138ed03410eb4a791040990d2ad
=
{
"animation"
:
true
,
"animationThreshold"
:
2000
,
"animationDuration"
:
1000
,
...
...
@@ -357,7 +357,7 @@
"subtext"
:
"\u6210\u7ee9"
}
};
chart_
eded43a60fc7485aaff3468a66ef3900
.
setOption
(
option_eded43a60fc7485aaff3468a66ef3900
);
chart_
acd35138ed03410eb4a791040990d2ad
.
setOption
(
option_acd35138ed03410eb4a791040990d2ad
);
</script>
</body>
</html>
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