For my intro to programming class i have to design a game where a ball is shot at an angle and hits squares that are worth points. I have two questions

1.How do you get the ball to move. I was given this code but I don't know if I am using it correctly:

``````for t in range(10000):
pinball.move(dx, dy)
sleep(0.05)``````

2.The black ball is worth 10 points, the green 3 and the blue 5. How do you get python to keep track of the score?

Here is the link to the original assignment:
https://eee.uci.edu/10y/18020/hw5.pdf

Any suggestions are appreciated. Thanks

Here is what i have so far:

``````from graphics import *
import time
from time import sleep
import math
def main():
Angle=input("Enter the angle: ")
win = GraphWin("Pinball game",500,400)
Text(Point(200,10), " Click on the window three times to draw the squares:").draw(win)
Text(Point(65,30), "Initial Angle:" ).draw(win)

Text(Point(45,50), "Score:").draw(win)
pinball=Circle(Point(20,370),5)
pinball.draw(win)
p = win.getMouse()
px = p.getX()
py = p.getY()
shape = Rectangle(Point(px-20,py-20), Point(px+20,py+20))
shape.setOutline("black")
shape.setFill("black")
shape.draw(win)
p2 = win.getMouse()
px2 = p2.getX()
py2 = p2.getY()
shape2 = Rectangle(Point(px2-20,py2-20), Point(px2+20,py2+20))
shape2.setOutline("black")
shape2.setFill("blue")
shape2.draw(win)

p3 = win.getMouse()
px3 = p3.getX()
py3 = p3.getY()
shape3 = Rectangle(Point(px3-20,py3-20), Point(px3+20,py3+20))
shape3.setOutline("black")
shape3.setFill("green")
shape3.draw(win)
for i in range(1):
p3 = win.getMouse()
c3 = shape3.getCenter()
dx3 = p.getX() - c3.getX()
dy3 = p.getY() - c3.getY()
shape3.move(dx3,dy3)

output = Text(Point(70,50),"")
output.draw(win)

for t in range(10000):
pinball.move(math.cos(Angle), math.sin(Angle))
sleep(0.05)

main()``````

its would be along the lines of defining contact for each colour square, and ud need a value called score

``````def OnContactBlack:
score +=10``````

this isnt perfect or the solutions, but that is a start along the right track, you would also have to define contact for the programme.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.