stage.set_background("halfcourt") troy = codesters.Sprite("person6",0,-100) troy.say("I really need to get my head in the game!") stage.wait(2) troy.say("Can you help me?") stage.wait(2) troy.hide() text = codesters.Text("Help Troy get his head in the game", 0, 100, "red") stage.wait(2) text.hide() text2 = codesters.Text("To play use the left,right,up and down keys!",0, 100,"red") stage.wait(2) text2.hide() text3 = codesters.Text("and get the basketball in the hoop",0,100,"red") stage.wait(2) text3.hide() text4 = codesters.Text("Get over 50 points to win!",0,100,"red") stage.wait(2) text4.hide() score = 0 score_board = codesters.Display(score) timer = 30 timer_display = codesters.Display(timer,-215,-200) stage.enable_physics() stage.set_gravity(0) stage.set_bounce(1) net = codesters.Sprite("basketballnet",10,200) ball = codesters.Sprite("basketball",0,20) def left_key(): ball.move_left(20) # add other actions... stage.event_key("left", left_key) def right_key(): ball.move_right(20) # add other actions... stage.event_key("right", right_key) def up_key(): ball.move_up(20) # add other actions... stage.event_key("up", up_key) def down_key(): ball.move_down(20) # add other actions... stage.event_key("down", down_key) def collision(sprite, hit_sprite): global score sprite_img = hit_sprite.get_image_name() if sprite_img == "basketballnet": sprite.go_to(-200,-100) score += 1 score_board.update(score) ball.event_collision(collision) def interval(): x = random.randint(-200, 200) y = random.randint(-200, 200) net.glide_to(x, y) global timer timer -= 1 timer_display.update(timer) if score > 50: win_text = codesters.Text ("You Win",0 , 0,"red") if timer == 0 and score < 50 : lose_text = codesters.Text("You Lose", 0, 0, "red") stage.event_interval(interval, 1)
Support