from graphics import * def figure_left(figure): figure.move(-15, 0) def figure_right(figure): figure.move(15, 0) def figure_up(figure): figure.move(0, -15) def figure_down(figure): figure.move(0, 15) def window(): #Window win = GraphWin("Loose Ball", 400, 400) win.setBackground("green") return win def main(): win = window() #figure figure = Rectangle(Point(150,150), Point(150, 150)) figure.setOutline("blue") figure.setFill("blue") figure.draw(win) figure.move(170, 5) figure.setWidth(40) #Ball radius = 40 ball = Circle(Point(300, 200), radius) ball.setOutline("red") ball.setFill("red") ball.draw(win) dx = 1 dy = 1 yFloor = radius yCieling = win.getHeight() - radius xFloor = radius xCieling = win.getHeight() - radius while True: time.sleep(.01) ball.move(dx, dy) key = win.checkKey() if key == "o": break elif key == "Left": figure_left(figure) elif key == "Right": figure_right(figure) elif key == "Up": figure_up(figure) elif key == "Down": figure_down(figure) #Move Ball if ball.getCenter().getY() <= yFloor or ball.getCenter().getY() >= yCieling: dy = -dy elif ball.getCenter().getX() <= xFloor or ball.getCenter().getX() >= xCieling: dx = -dx #Ball Collision with figure elif ball.getCenter().getY() <= figure.getCenter().getY() or ball.getCenter().getX() >= figure.getCenter().getX(): text = Text(Point(200, 200), "GAME OVER !!!!") text.draw(win) break
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)