Give and angle and distance. Try to make a goal. If hits > misses by 5, you win. Misses > hits by 5 you lose.

from random import randint from math import sqrt stage.set_background_color("green") ball = codesters.Sprite("soccerball", -210, -210) net = codesters.Sprite("soccernet") net.hide() net.flip_right_left() net.set_size(0.9) net.turn_left(45) scoreboard = {} scoreboard['hits'] = 0 scoreboard['misses'] = 0 def say_score(): # sprite = codesters.Rectangle(x, y, width, height, "color") sprite = codesters.Rectangle(130, 220, 150, 100, "white") codesters.Text("Hits.... {:4d}".format(scoreboard['hits']), 150, 210) codesters.Text("Misses.. {:4d}".format(scoreboard['misses']), 150, 190) say_score() def place_net(): x = randint(-150, 220) y = randint(-220, 200) net.goto(x,y) net.show() def trial(): ball.goto(-210, -210) ball.setheading(0) ball.say("Ready...") place_net() angle = min(max(1, float(ball.ask("Angle? (0-90) "))), 90) distance = min(max(1, float(ball.ask("Distance? (0-550) "))),550) ball.turn_left(angle) ball.move_forward(distance) def how_close(A, B): # distance formula apart = sqrt( (A.x - B.x)**2 + (A.y - B.y)**2 ) return apart Playing = True while Playing: trial() if how_close(ball, net) < 50: ball.say("Super!!") scoreboard['hits'] += 2 elif how_close(ball, net) < 100: ball.say("Score!!") scoreboard['hits'] += 1 else: ball.say("Missed!!") scoreboard['misses'] += 1 say_score() if scoreboard['misses'] - scoreboard['hits'] >= 5: stage.set_background_color("black") codesters.Text("GAME OVER",0,0,"gold") Playing = False if scoreboard['hits'] - scoreboard['misses'] >= 5: stage.set_background_color("black") codesters.Text("YOU WIN!!",0,0,"gold") stage.remove_sprite(net) stage.remove_sprite(ball) trophy = codesters.Sprite("SoccerTrophy_bbc") trophy.set_size(0.5) Playing = False stage.wait(2)
  • Run Code
  • Show Console
  • Codesters How To (opens in a new tab)