from apcs import Window
#COMMAND S TO SAVE THEN YOU CAN RUN!!!!
#if you deleted terminal, then just do cd Desktop and cd Kavinaya and finally python3 bouncingball.py
x = 100
y = 100
dx = 5
dy = 3


def drawBall():  #def= define, you are not calling the function btw
    global x, y, dx, dy  #you can change the value of x and y, only in a function
    Window.out.circle(x, y, 10)

    x = x + dx  #dx is the change in the x value
    y = y + dy  #dy is the change in the y value

    if x > 500 or x < 0:
        dx = -1 * dx
    if y > 500 or y < 0:
        dy = -1 * dy


Window.size(500, 500)
Window.frame(drawBall)
Window.start()  #makes window show up, in java it is already given
Exemple #2
0
def checkPaddle():
    global dx, dy
    if abs(x - 740) <= 10 and abs(y - paddle2y) <= 50:
        dx = -dx
        dy = dy + (y - paddle2y) / 10
    if abs(x - 60) <= 10 and abs(y - paddle1y) <= 50:
        dx = -dx
        dy = dy + (y - paddle1y) / 10
    pass


def checkScore():
    pass


#set size
Window.size(800, 600)

#functions for drawing the Frame
Window.frame(drawBackground)
Window.frame(drawBall)
Window.frame(moveBall)
Window.frame(drawPaddle)
Window.frame(movePaddle)
Window.frame(checkBounce)
Window.frame(checkPaddle)
Window.frame(checkScore)

#start animation
Window.start()
Exemple #3
0
from apcs import Window

x = 50
dx = 5

def frame():
    global x, dx
    Window.out.circle(x, 200, 50)
    x = x + dx

    if x > 450:
        dx = -5
    if x < 50:
        dx = 5

    

Window.size(500, 500)
Window.frame(frame)
Window.start()