def newGame(): #holds initial level value global levelCount levelCount = 1 wall = Wall() #builds wall of bricks wall.buildWall(gameDisplay, ballRect, ballDirection, levelCount) #creates new lists to avoid bugs global newBrickList global newRecList global newColorList global newHitList global newPowerList newBrickList = wall.brickList newRecList = wall.recList newColorList = wall.colorList newHitList = wall.hitList newPowerList = wall.powerList #resets intial life value lifeCount = 3 #resets bricksBroken global bricksBroken bricksBroken = 0 #resets startTime global startTime startTime = time.time() resetBall() py.display.flip()
def levelFive(): wall = Wall() gameDisplay.fill((0,0,0)) #builds wall of bricks global levelCount wall.buildWall(gameDisplay, ballRect, ballDirection, 5) #creates new lists to avoid bugs global newBrickList global newRecList global newColorList global newHitList global newPowerList newBrickList = wall.brickList newRecList = wall.recList newColorList = wall.colorList newHitList = wall.hitList newPowerList = wall.powerList resetBall() #resets bricksBroken global bricksBroken bricksBroken = 0 #resets startTime global startTime startTime = time.time() py.display.flip() global play play = True
#randomizes initial location between bricks and paddle ballRect.x = r.randrange( 10, 790) #width is 800, above 10 and bellow 790 so not on edge of screen ballRect.y = r.randrange( 146, 610) #4 rows of bricks ending at 146px, paddle begin at 620px #variable to change ball direction; begins in random direction #tried using trig to calculate better angle options, but move() function only takes int ballDirection = [r.choice([1, -1]), r.choice([1, -1])] #creates wall object wall = Wall() #builds wall of bricks wall.buildWall(gameDisplay, ballRect, ballDirection, 1) #creates new lists to avoid bugs newBrickList = wall.brickList newRecList = wall.recList newColorList = wall.colorList #creates and places paddle with a rectangle paddle = Paddle() paddleRect = paddle.image.get_rect() paddleRect.x = 300 paddleRect.y = 620 #allows for held down keys to continue movement py.key.set_repeat(10, 10)