logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

add a code which is like for every 10 points collected in the game the player

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

Game code

add a code which is like for every 10 points collected in the game the player will gain 1 life. and a text that will show up temporarily when the life is added then disappear.

import turtle

import random

import sys

 

point = 0

live = 3

extra = 0

 

#screen

screen = turtle.Screen()

screen.setup(width=900,height=600)

screen.bgcolor('light blue')

screen.title('Shopping Cart')

screen.tracer(0)

 

#points and lives

score_board = turtle.Turtle()

score_board.hideturtle()

score_board.speed()

score_board.color('black')

score_board.penup()

score_board.goto(20, 263)

font = ('Courier', 27, 'bold')

score_board.write(f'Points: {point}     Lives:{live}', align='right',font=font)

    

#player

player = turtle.Turtle()

player.speed(0)

player.shape('square')

player.color('gray')

player.penup()

player.goto(0,-280)

player.direction = 'stop'

 

#list_fruits

positive_fruits =[]

#['apple','orange','grape','banana','kiwi','strawberry','coconut','blueberry','avocado','pineapple']

#positive_fruit

for _ in range(10):

    positive_fruit = turtle.Turtle()

    positive_fruit.speed(0)

    positive_fruit.shape('circle')

    positive_fruit.color('white')

    positive_fruit.penup()

    positive_fruit.goto(-100, -900 )

    positive_fruit.speed =  random.uniform(0,2)

    positive_fruits.append(positive_fruit)

 

#list_veg

negative_vegs =[]

#negative_veg

for n in range(10):

    negative_veg = turtle.Turtle()

    negative_veg.speed(0)

    negative_veg.shape('triangle')

    negative_veg.color('red')

    negative_veg.penup()

    negative_veg.goto(100, -900 )

    negative_veg.speed =  random.uniform(0,2)

    negative_vegs.append(negative_veg)

    

#function

def left():

    player.direction = 'left'

 

def right():

    player.direction = 'right'

 

 

#connection to keyboard

screen.listen()

screen.onkeypress(left,"Left")

screen.onkeypress(left,'a')

screen.onkeypress(right,"Right")

screen.onkeypress(right, 'd')

                  

    

#main game loop

while True:

    screen.update()

    #player movements

    if player.direction == 'left':

        x = player.xcor()

        x -= 1

        player.setx(x)

        

    if player.direction == 'right':

        x = player.xcor()

        x += 1

        player.setx(x)

 

        

    # move positive fruit

    for positive_fruit in positive_fruits:

        y = positive_fruit.ycor()

        y -= positive_fruit.speed

        positive_fruit.sety(y)

 

        if y < -450:

            x = random.randint(-400, 400 )

            y = random.randint(600, 600)

            positive_fruit.goto(x, y)

 

        #hit player

        if positive_fruit.distance(player) < 20:

            x = random.randint(-400, 400)

            y = random.randint(600, 600)

            positive_fruit.goto(x,y)

            point += 1

            score_board.clear()

            score_board.write(f'Points: {point}     Lives:{live}', align='right',font=font)

 

            #extra lives

            if point == [+10]:

                live += 1

                extra = turtle.Turtle()

                extra.hideturtle()

                extra.speed()

                extra.color('red')

                extra.penup()

                extra.goto(400, 600)

                font = ('Courier', 27, 'bold') 

                extra.write(f'+LIFE ADDED', align='center', font=font)

            score_board.clear()

            score_board.write(f'Points: {point}     Lives:{live}', align='right',font=font)

                

      # move negative vegetables

    for negative_veg in negative_vegs:

        y =  negative_veg.ycor()

        y -=  negative_veg.speed

        negative_veg.sety(y)

 

        if y < -450:

            x = random.randint(-400, 400 )

            y = random.randint(600, 600)

            negative_veg.goto(x,y)

            

            #hit player

        if  negative_veg.distance(player) < 20:

            x = random.randint(-400, 400)

            y = random.randint(600, 600)

            negative_veg.goto(x,y)

            point -= 1

            live -= 1

            score_board.clear()

            score_board.write(f'Points: {point}     Lives:{live}', align='right',font=font)

 

                

            

 

screen.mainloop()

 

 

 

(5/5)
Attachments:

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Um e HaniScience

994 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

748 Answers

Hire Me
expert
Husnain SaeedComputer science

570 Answers

Hire Me
expert
Atharva PatilComputer science

524 Answers

Hire Me