myfunction() Let's make this game more challenging by adding another ball and giving…
- User
my_function() Let's make this game more challenging by adding another ball and giving each ball a different speed!
Add another ball! Place another Function Call in your main function which calls add_ball(). Set the ball speed! Add the parameter speed to your add_ball() function definition. Replace -8 in set_y_speed() with the new parameter speed. In main(), add integer parameters to the add_ball() function calls. Make sure they are negative!
def set_stage(): """ Sets up the stage for the game """
codestage.set_background("soccerfield") stage.disable_floor()def add_player(): """ Adds a player to the stage for the user to control """
codeplayer = codesters.Sprite("player1") player.go_to(0, -155) return playerdef add_ball(): """ Adds a ball to the stage and sets its attributes """
codeball = codesters.Sprite("soccerball") ball.set_y_speed(-8)def head_ball(sprite, hit_sprite): """ Detects collisions between the player and ball """
codemy_var = hit_sprite.get_y_speed() hit_sprite.set_y_speed(-my_var + 1) my_var = hit_sprite.get_x_speed() hit_sprite.set_x_speed(my_var + 1)def move_left(): """ Moves the player left """
codeplayer.move_left(50)def move_right(): """ Moves the player right """
codeplayer.move_right(50)def main(): """ Sets up the program and calls other functions """
codeset_stage() player = add_player() add_ball() player.event_collision(head_ball) stage.event_key("left", move_left) player.event_key("right", move_right)main()
- Assistant
def add_ball(speed): """ Adds a ball to the stage and sets its attributes """
codeball = codesters.Sprite("soccerball") ball.set_y_speed(speed)def main(): """ Sets up the program and calls other functions """
codeset_stage() player = add_player() add_ball(-8) add_ball(-12) # Add another ball with different speed player.event_collision(head_ball) stage.event_key("left", move_left) player.event_key("right", move_right)main()
- User
def set_stage(): """ Sets up the stage for the game """
codestage.set_background("soccerfield") stage.disable_floor()def add_player(): """ Adds a player to the stage for the user to control """
codeplayer = codesters.Sprite("player1") player.go_to(0, -155) return playerdef add_ball(): """ Adds a ball to the stage and sets its attributes """
codeball = codesters.Sprite("soccerball") ball.set_y_speed(-8)def head_ball(sprite, hit_sprite): """ Detects collisions between the player and ball """
codemy_var = hit_sprite.get_y_speed() hit_sprite.set_y_speed(-my_var + 1) my_var = hit_sprite.get_x_speed() hit_sprite.set_x_speed(my_var + 1) - Assistant
def set_stage(): """ Sets up the stage for the game """
codestage.set_background("soccerfield") stage.disable_floor()def add_player(): """ Adds a player to the stage for the user to control """
codeplayer = codesters.Sprite("player1") player.go_to(0, -155) return playerdef add_ball(speed): """ Adds a ball to the stage and sets its attributes """
codeball = codesters.Sprite("soccerball") ball.set_y_speed(speed)def head_ball(sprite, hit_sprite): """ Detects collisions between the player and ball """
codemy_var = hit_sprite.get_y_speed() hit_sprite.set_y_speed(-my_var + 1) my_var = hit_sprite.get_x_speed() hit_sprite.set_x_speed(my_var + 1) - User
Let's make this game more challenging by adding another ball and giving each ball a different speed!
Add another ball! Place another Function Call in your main function which calls add_ball(). Set the ball speed! Add the parameter speed to your add_ball() function definition. Replace -8 in set_y_speed() with the new parameter speed. In main(), add integer parameters to the add_ball() function calls. Make sure they are negative!
- Assistant
def set_stage(): """ Sets up the stage for the game """
codestage.set_background("soccerfield") stage.disable_floor()def add_player(): """ Adds a player to the stage for the user to control """
codeplayer = codesters.Sprite("player1") player.go_to(0, -155) return playerdef add_ball(speed): """ Adds a ball to the stage and sets its attributes """
codeball = codesters.Sprite("soccerball") ball.set_y_speed(speed)def head_ball(sprite, hit_sprite): """ Detects collisions between the player and ball """
codemy_var = hit_sprite.get_y_speed() hit_sprite.set_y_speed(-my_var + 1) my_var = hit_sprite.get_x_speed() hit_sprite.set_x_speed(my_var + 1) - User
bad input on line: 2
- Assistant
It seems like there might be an issue with the input. Here is the corrected code:
python