@kaiserb1/

pygame bouncy

Pygame

No description

fork
loading
Files
  • main.py
  • nohup.out
  • requirements.txt
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import play

balls = []

@play.when_mouse_clicked
def make_ball():
    for ball in balls:
        if play.mouse.is_touching(ball):
            return
    ball = play.new_circle(color=play.random_color(), y=play.mouse.y, x=play.mouse.x, radius=20)
    ball.start_physics(bounciness=0.5, mass=100, friction=1)
    ball.is_being_dragged = False

    @ball.when_clicked
    def click_ball():
        ball.is_being_dragged = True
        ball.color = play.random_color()

    @play.mouse.when_click_released
    def release_ball():
        for ball in balls:
            ball.is_being_dragged = False

    balls.append(ball)

@play.when_key_pressed('z')
def press_space(key):
    for ball in balls:
        ball.physics.y_speed = play.random_number(80, 100)
        ball.physics.x_speed = play.random_number(-30, 30)

@play.repeat_forever
def loop():
    for ball in balls:
        if ball.is_being_dragged:
            ball.physics.x_speed = play.mouse.x - ball.x
            ball.physics.y_speed = play.mouse.y - ball.y


play.start_program()