stage.set_background("halfcourt")
sprite = codesters.Sprite("player4")
sprite.go_to(215, -175)
net = codesters.Sprite("basketballnet")
net.go_to(215, 175)
ball = codesters.Sprite("basketball")
x = random.randint(-100, 150)
ball.go_to(x, -25)
stage.set_gravity(10)
stage.set_bounce(.8)
ball.set_gravity_off()
net.set_gravity_off()
left_count = 0
down_count = 0
def left_key():
ball.move_left(10)
global left_count
left_count += 1
# add other actions...
stage.event_key("left", left_key)
def down_key():
ball.move_down(10)
global down_count
down_count += 1
# add other actions...
stage.event_key("down", down_key)
def space_bar():
ball.set_gravity_on()
ball.set_x_speed(left_count)
ball.set_y_speed(down_count)
# add other actions...
stage.event_key("space", space_bar)
def collision(ball, hit_sprite):
my_var = hit_sprite.get_name()
if my_var == "codesters":
sprite.say("I hit something!")
# add any other actions...
ball.event_collision(collision)
t = codesters.Teacher()
try:
tval1 = t.find_block('if')[0][1]
tval2 = t.find_block('if')[0][0]
tval2 = t.get_indent_at_line(tval2)
except:
tval1 = "DNE"
tval2 = "DNE"
try:
tval3 = t.find_function('say')[0][1]
tval4 = t.find_function('say')[0][0]
tval4 = t.get_indent_at_line(tval4)
except:
tval3 = "DNE"
tval4 = "DNE"
t1 = TestObjective()
t1.add_success(tval1.replace(' ', '') == 'ifmy_var=="basketballnet":' and tval2 == 4, "Great job!")
t1.add_failure(tval1 == "DNE", "Oops! Did you delete the if statement in your Collision Event?")
t1.add_failure('"basketballnet"' not in tval1, 'Make sure you change the string in the if statement to "basketballnet".')
t1.add_failure(tval2 < 4, "Make sure your if statement stays indented in the Collision Event!")
t1.add_failure(tval2 > 4, "Oops! You indented too far! Make sure your if statement is only 4 spaces inside the event.")
t2 = TestObjective()
t2.add_success('score' in tval3.lower() and tval4 == 8, "Great job!")
t2.add_failure(tval3 == "DNE", "Oops! Did you delete the .say() command?")
t2.add_failure('something' in tval3, 'Did you replace the text inside the Say command with "Score!"?')
t2.add_failure(tval4 < 8, "Make sure your say command stays indented inside the if statement!")
t2.add_failure(tval4 > 8, "Oops! You indented too far! Make sure your say command is only 8 spaces inside the if statement.")
tester = TestManager()
tester.add_test_list([t1, t2])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
Submit Work
-
Next Activity
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)