Question: python this code creates a grey square which moves to the left on the screen. each time it runs through the game loop i want

python this code creates a grey square which moves to the left on the screen. each time it runs through the game loop i want it to create a new grey square up to a max of 15 grey squares, however there is only ever 1 grey square for some reason. code is below.

import pygame import time import random

pygame.init()

display_width = 1000 display_height= 800

black = (0,0,0) white = (255,255,255) red = (255,0,0) green = (0,255,0) blue = (0,0,255) grey=(169,169,169)

gameDisplay= pygame.display.set_mode((800,600))

pygame.display.set_caption('stalingrad')

clock = pygame.time.Clock()

def spawn_soldier(thingx,thingy, thingw, thingh, colour): pygame.draw.rect(gameDisplay, colour,[thingx, thingy, thingw, thingh])

def game_loop():

russian_width= 20 russian_height= 20 russian_speed = 3 russian_startx=-30 russian_starty=random.randrange(0, display_height)

german_width=20 german_height=20 german_speed=-1 german_startx=780 german_starty=random.randrange(0, display_height)

germancount=0 russiancount=0

game_exit=False

while not game_exit: gameDisplay.fill(white)

###################################################################################### if germancount<15: # here, i want it to spawn a new grey square every time iit runs through #game loop if there are less than 15 grey sqarres. but it only makes 1 #####################################################################################

spawn_soldier(german_startx, german_starty, german_width, german_height, grey) if german_startx > 700: german_startx += german_speed

pygame.display.update() 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!