Question: Python pygame using python3 I need help adding the following features to my code: Number of lives add multiple falling objects add player car to

Python pygame using python3 I need help adding the following features to my code:

Number of lives

add multiple falling objects

add player car to go up ad down not just side to side and rotate

I need these added to my code, not new code please help here is my code:

from __future__ import division import pygame import time import random from os import path pygame.mixer.init() pygame.mixer.music.load("joker.mp3") pygame.mixer.music.play() class Bullet(object): speed = -15 width = 20 height = 20 def __init__(self,x,y,color): self.x = x  self.y = y  self.color = color   def tick(self): self.y += self.speed pygame.draw.rect(gameDisplay, self.color, [self.x, self.y, self.width, self.height]) def dispose(self): #print(self.y) #print(display_height) if self.y < 0: return True  else: return False   def hit(self,thing_startx,thing_starty,thing_width,thing_height): if self.y < thing_starty+thing_height: print('bullet y crossover') if self.x > thing_startx and self.x < thing_startx + thing_width or self.x + car_width > thing_startx and self.x + car_width < thing_startx + thing_width: print('bullet x crossover') Explode=pygame.mixer.Sound("Explosion.wav") return True  return False  pygame.init() display_width = 800 display_height = 600 gameDisplay = pygame.display.set_mode((display_width,display_height)) pygame.display.set_caption('Hilarious Shooter') green= (124,252,0) white= (255,255,255) red = (255,255,0) car_width = 73 background = pygame.image.load(path.join('joker.png')).convert() background_rect = background.get_rect() clock = pygame.time.Clock() carImg = pygame.image.load('racecar.png') def things_dodged(count): font = pygame.font.SysFont(None, 25) text = font.render("Dodged: "+str(count),True,green) gameDisplay.blit(text,(0,0)) def display_hits(count): font = pygame.font.SysFont(None, 25) text = font.render("Hits: "+str(count),True,green) gameDisplay.blit(text,(0,30)) def things(thingx, thingy,thingw,thingh,color): pygame.draw.rect(gameDisplay, color, [thingx,thingy,thingw,thingh]) def car(x,y): gameDisplay.blit(carImg,(x,y)) def text_objects(text,font): text_surface = font.render(text,True, green) return text_surface,text_surface.get_rect() def message_display(text): large_text = pygame.font.Font("freesansbold.ttf",115) text_surf, text_rect = text_objects(text,large_text) text_rect.center = ((display_width/2),(display_height/2)) gameDisplay.blit(text_surf,text_rect) pygame.display.update() time.sleep(2) game_loop() def crash(): message_display("You Crashed") def game_loop(): # defines starting points for the car x = (display_width * 0.45) y = (display_height * 0.8) x_change = 0 thing_startx = random.randrange(0,display_width) thing_starty = -600 thing_speed = 7 thing_width = 80 thing_height = 80 bullets = [] thing_count = 1 dodged = 0 hits = 0 game_exit = False   while not game_exit: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: x_change = -5 elif event.key == pygame.K_RIGHT: x_change = 5 if event.type == pygame.KEYUP: if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT: x_change = 0 if event.type == pygame.KEYUP: if event.key == pygame.K_SPACE: bullet1 = Bullet(x+(car_width/2),y,green) bullets.append(bullet1) x += x_change gameDisplay.blit(background, background_rect) deletions = [] count = 0 for bullet in bullets: bullet.tick() if bullet.dispose(): deletions.append(count) if bullet.hit(thing_startx,thing_starty,thing_width,thing_height): deletions.append(count) hits += 1 thing_starty = 0 - thing_height thing_startx = random.randrange(0, display_width) thing_speed += 1 thing_width += (dodged * 1.2) count += 1 i = len(deletions) - 1 while i >= 0: del bullets[deletions[i]] i -= 1 print("delete") things(thing_startx,thing_starty,thing_width,thing_height,green) thing_starty += thing_speed car(x, y) things_dodged(dodged) display_hits(hits) if x > display_width - car_width or x < 0: crash() if thing_starty > display_height: thing_starty = 0 - thing_height thing_startx = random.randrange(0,display_width) dodged += 1 thing_speed += 1 thing_width += (dodged * 1.2) if y < thing_starty+thing_height: #print('y crossover') if x > thing_startx and x < thing_startx + thing_width or x + car_width > thing_startx and x + car_width < thing_startx + thing_width: #print('x crossover') crash() # display.flip will update the entire surface, basically the entire screen # display.update will update specific areas of the screen # display.update will update the entire surface as well if it is not passed a parameter pygame.display.update() # number of frames per second clock.tick(60) game_loop() pygame.quit() quit() 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!