From 5852f56a9ff1765f74b17346f2ec573844632f7f Mon Sep 17 00:00:00 2001 From: FishyDeveloper <52783797+FishyDeveloper@users.noreply.github.com> Date: Thu, 18 Mar 2021 17:38:05 +0700 Subject: [PATCH] Adding spaces Adding spaces between last code and comment to make it more readable --- main.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index a4256fa..19990f4 100644 --- a/main.py +++ b/main.py @@ -10,15 +10,19 @@ def main(): + #initialise the pygame pygame.init() + # set the display - DISPLAY=pygame.display.set_mode((640,480),0,32) + DISPLAY = pygame.display.set_mode((640,480),0,32) pygame.display.set_caption('Flappuccino') pygame.display.set_icon(Bean().sprite) # get fonts + font = pygame.font.Font('data/fonts/font.otf', 100) font_small = pygame.font.Font('data/fonts/font.otf', 32) font_20 = pygame.font.Font('data/fonts/font.otf', 20) + # get some images shop = pygame.image.load('data/gfx/shop.png') shop_bg = pygame.image.load('data/gfx/shop_bg.png') @@ -27,19 +31,24 @@ def main(): title_bg = pygame.image.load('data/gfx/bg.png') title_bg.fill((255, 30.599999999999998, 0.0), special_flags=pygame.BLEND_ADD) shadow = pygame.image.load('data/gfx/shadow.png') + # get sounds flapfx = pygame.mixer.Sound("data/sfx/flap.wav") upgradefx = pygame.mixer.Sound("data/sfx/upgrade.wav") beanfx = pygame.mixer.Sound("data/sfx/bean.wav") deadfx = pygame.mixer.Sound("data/sfx/dead.wav") + # colors WHITE=(255,255,255) # constant + # variables rotOffset = -5 + # creating a new object player player = Player() beans = [] buttons = [] + # adding three buttons for i in range(3): buttons.append(Button()) # now simply loading images based off of indexes in the list @@ -49,13 +58,17 @@ def main(): buttons[1].price = 5 buttons[2].typeIndicatorSprite = pygame.image.load('data/gfx/beanup_indicator.png') buttons[2].price = 30 + # getting 5 beans for i in range(5): beans.append(Bean()) + # now looping through the beans list for bean in beans: bean.position.xy = random.randrange(0, DISPLAY.get_width() - bean.sprite.get_width()), beans.index(bean)*-200 - player.position.y + # creating a list of backgrounds, with each index being an object bg = [Background(), Background(), Background()] + # some variables that we need beanCount = 0 startingHeight = player.position.y @@ -64,11 +77,13 @@ def main(): flapForce = 3 beanMultiplier = 5 dead = False + # we need the framerate and then the time framerate = 60 last_time = time.time() splashScreenTimer = 0 #splash screen + # playing a sound pygame.mixer.Sound.play(flapfx) while splashScreenTimer < 100: @@ -85,12 +100,14 @@ def main(): sys.exit() DISPLAY.fill((231, 205, 183)) + # fill the start message on the top of the game startMessage = font_small.render("POLYMARS", True, (171, 145, 123)) DISPLAY.blit(startMessage, (DISPLAY.get_width()/2 - startMessage.get_width()/2, DISPLAY.get_height()/2 - startMessage.get_height()/2)) # update display pygame.display.update() + # wait for 10 seconds pygame.time.delay(10) @@ -101,11 +118,14 @@ def main(): dt = time.time() - last_time dt *= 60 last_time = time.time() + # get the position of the mouse - mouseX,mouseY = pygame.mouse.get_pos() + mouseX,mouseY = pygame.mouse.get_pos() + # getting the keys pressed clicked = False keys = pygame.key.get_pressed() + # checking events for event in pygame.event.get(): if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: @@ -114,12 +134,13 @@ def main(): if event.type==QUIT: pygame.quit() sys.exit() + # so the user clicked, and by any change the mouse's position was on the buttons if (clicked and checkCollisions(mouseX, mouseY, 3, 3, DISPLAY.get_width()/2 - retry_button.get_width()/2, 288, retry_button.get_width(), retry_button.get_height())): clicked = False pygame.mixer.Sound.play(upgradefx) titleScreen = False - + DISPLAY.fill(WHITE) DISPLAY.blit(title_bg, (0,0)) DISPLAY.blit(shadow, (0,0)) @@ -136,12 +157,14 @@ def main(): dt = time.time() - last_time dt *= 60 last_time = time.time() + # again, get the position mouseX,mouseY = pygame.mouse.get_pos() jump = False clicked = False keys = pygame.key.get_pressed() + # get events for event in pygame.event.get(): if event.type==pygame.KEYDOWN and event.key==K_SPACE: @@ -180,6 +203,7 @@ def main(): levelDisplay = font_20.render('Lvl. ' + str(button.level), True, (200,200,200)) DISPLAY.blit(levelDisplay, (234 + (buttons.index(button)*125), 441)) DISPLAY.blit(button.typeIndicatorSprite, (202 + (buttons.index(button)*125), 377)) + beanCountDisplay = font_small.render(str(beanCount).zfill(7), True, (0,0,0)) DISPLAY.blit(beanCountDisplay, (72, 394)) if dead: