diff --git a/assets/values.py b/assets/values.py index 8440a00..9ae57f7 100644 --- a/assets/values.py +++ b/assets/values.py @@ -76,6 +76,7 @@ def resetCoinsinGame(): global coins_in_game coins_in_game = 0 + def setSkin(skin): global current_skin current_skin = skin @@ -87,4 +88,4 @@ def setSkin(skin): gameTime = -1 startTime = -1 enemysKilled = -1 -distanceTraveled = -1 \ No newline at end of file +distanceTraveled = -1 diff --git a/fileio/customizationIO.py b/fileio/customizationIO.py index 24b9288..86e4159 100644 --- a/fileio/customizationIO.py +++ b/fileio/customizationIO.py @@ -48,9 +48,9 @@ def load_new_customization(): def save_customization(): """summary: Saves the customization to the file """ - global skins, hats, backgrounds + global skins, hats, backgrounds global coins, current_skin, current_hat - global current_background + global current_background data = { "skins": skins, "hats": hats, @@ -63,8 +63,8 @@ def save_customization(): with open("fileio\\Customization.json", "w") as f: json.dump(data, f, indent=4) + def add_currency(amount): global coins coins += amount save_customization() - \ No newline at end of file diff --git a/main.py b/main.py index 78cdf55..48e1af8 100644 --- a/main.py +++ b/main.py @@ -76,7 +76,8 @@ def main(): ran = True gameScreen.gameScreen() elif menuS.get_game_menu() == menuS.menu.CUSTOMIZE: - startingDuck, startingTab = customizeScreen.customize_screen(noises, startingDuck, startingTab) + startingDuck, startingTab = customizeScreen.customize_screen( + noises, startingDuck, startingTab) elif menuS.get_game_menu() == menuS.menu.HIGH_SCORE: if values.newHighScore and not visitedHighScore: noises.playMusic("highScore") diff --git a/views/customizeScreen.py b/views/customizeScreen.py index 8ebe6c1..21bccad 100644 --- a/views/customizeScreen.py +++ b/views/customizeScreen.py @@ -6,31 +6,26 @@ import menuStructure as menuS normalSkins = [ - "assets/sprites/ducks/baseDuck.png", - "assets/sprites/ducks/blueDuck.png", - "assets/sprites/ducks/brownDuck.png", - "assets/sprites/ducks/grayDuck.png", - "assets/sprites/ducks/greenDuck.png", - "assets/sprites/ducks/richDuck.png" - ] + "assets/sprites/ducks/baseDuck.png", "assets/sprites/ducks/blueDuck.png", + "assets/sprites/ducks/brownDuck.png", "assets/sprites/ducks/grayDuck.png", + "assets/sprites/ducks/greenDuck.png", "assets/sprites/ducks/richDuck.png" +] baseSkins = [ "assets/sprites/ducks/baseChain.png", "assets/sprites/ducks/baseConstruction.png", "assets/sprites/ducks/baseCowboy.png", - "assets/sprites/ducks/baseLuffy.png", - "assets/sprites/ducks/baseSanta.png", + "assets/sprites/ducks/baseLuffy.png", "assets/sprites/ducks/baseSanta.png", "assets/sprites/ducks/baseSunnies.png" - ] +] blueSkins = [ "assets/sprites/ducks/blueChain.png", "assets/sprites/ducks/blueConstruction.png", "assets/sprites/ducks/blueCowboy.png", - "assets/sprites/ducks/blueLuffy.png", - "assets/sprites/ducks/blueSanta.png", + "assets/sprites/ducks/blueLuffy.png", "assets/sprites/ducks/blueSanta.png", "assets/sprites/ducks/blueSunnies.png" - ] +] brownSkins = [ "assets/sprites/ducks/brownChain.png", @@ -39,16 +34,15 @@ "assets/sprites/ducks/brownLuffy.png", "assets/sprites/ducks/brownSanta.png", "assets/sprites/ducks/brownSunnies.png" - ] +] graySkins = [ "assets/sprites/ducks/grayChain.png", "assets/sprites/ducks/grayConstruction.png", "assets/sprites/ducks/grayCowboy.png", - "assets/sprites/ducks/grayLuffy.png", - "assets/sprites/ducks/graySanta.png", + "assets/sprites/ducks/grayLuffy.png", "assets/sprites/ducks/graySanta.png", "assets/sprites/ducks/graySunnies.png" - ] +] greenSkins = [ "assets/sprites/ducks/greenChain.png", @@ -57,16 +51,16 @@ "assets/sprites/ducks/greenLuffy.png", "assets/sprites/ducks/greenSanta.png", "assets/sprites/ducks/greenSunnies.png" - ] +] richSkins = [ "assets/sprites/ducks/richChain.png", "assets/sprites/ducks/richConstruction.png", "assets/sprites/ducks/richCowboy.png", - "assets/sprites/ducks/richLuffy.png", - "assets/sprites/ducks/richSanta.png", + "assets/sprites/ducks/richLuffy.png", "assets/sprites/ducks/richSanta.png", "assets/sprites/ducks/richSunnies.png" - ] +] + def loadAssets(purchaseSize): allSkins = [] @@ -77,27 +71,41 @@ def loadAssets(purchaseSize): greenAccessories = [] richAccessories = [] for x in normalSkins: - allSkins.append(pygame.transform.scale(pygame.image.load(x), (purchaseSize, purchaseSize))) + allSkins.append( + pygame.transform.scale(pygame.image.load(x), + (purchaseSize, purchaseSize))) for x in baseSkins: - baseAccessories.append(pygame.transform.scale(pygame.image.load(x), (purchaseSize, purchaseSize))) + baseAccessories.append( + pygame.transform.scale(pygame.image.load(x), + (purchaseSize, purchaseSize))) for x in blueSkins: - blueAccessories.append(pygame.transform.scale(pygame.image.load(x), (purchaseSize, purchaseSize))) + blueAccessories.append( + pygame.transform.scale(pygame.image.load(x), + (purchaseSize, purchaseSize))) for x in brownSkins: - brownAccessories.append(pygame.transform.scale(pygame.image.load(x), (purchaseSize, purchaseSize))) + brownAccessories.append( + pygame.transform.scale(pygame.image.load(x), + (purchaseSize, purchaseSize))) for x in graySkins: - grayAccessories.append(pygame.transform.scale(pygame.image.load(x), (purchaseSize, purchaseSize))) + grayAccessories.append( + pygame.transform.scale(pygame.image.load(x), + (purchaseSize, purchaseSize))) for x in greenSkins: - greenAccessories.append(pygame.transform.scale(pygame.image.load(x), (purchaseSize, purchaseSize))) + greenAccessories.append( + pygame.transform.scale(pygame.image.load(x), + (purchaseSize, purchaseSize))) for x in richSkins: - richAccessories.append(pygame.transform.scale(pygame.image.load(x), (purchaseSize, purchaseSize))) + richAccessories.append( + pygame.transform.scale(pygame.image.load(x), + (purchaseSize, purchaseSize))) return allSkins, baseAccessories, blueAccessories, brownAccessories, grayAccessories, greenAccessories, richAccessories + # Runs the customize screen def customize_screen(noises, duckIndex, arrayIndex): startingDuck = duckIndex startingArray = arrayIndex - retDuck = startingDuck - + # Set the background to main.jpg background = pygame.image.load( os.path.join("assets", "backgrounds", "tertiary.jpg")) @@ -151,7 +159,8 @@ def customize_screen(noises, duckIndex, arrayIndex): #load duck base skins purchaseSize = int(values.screenX * .1504) - allSkins, baseAccessories, blueAccessories, brownAccessories, grayAccessories, greenAccessories, richAccessories = loadAssets(purchaseSize) + allSkins, baseAccessories, blueAccessories, brownAccessories, grayAccessories, greenAccessories, richAccessories = loadAssets( + purchaseSize) if arrayIndex == 0: currentArray = allSkins @@ -206,10 +215,12 @@ def customize_screen(noises, duckIndex, arrayIndex): screen.blit(rightArr, (xArr1 + sep + sep + box + wArr, yArr)) #TODO array of skins to purchase /equip at the bottom of the screen - - currentPreview = pygame.transform.scale(currentArray[startingDuck], (previewSize, previewSize)) + + currentPreview = pygame.transform.scale(currentArray[startingDuck], + (previewSize, previewSize)) #TODO Preview of Duck in Current State - screen.blit(currentPreview, (screen.get_width() / 3, screen.get_height() / 4)) + screen.blit(currentPreview, + (screen.get_width() / 3, screen.get_height() / 4)) #will make these box objects for an array so we can move with arrows, know which ones have been purchased. numboxes = 6 for i in range(numboxes): @@ -218,7 +229,9 @@ def customize_screen(noises, duckIndex, arrayIndex): ((i + 1) * screen.get_width() * .1157 - screen.get_width() * .0289, screen.get_height() * .7610, screen.get_width() * .0868, screen.get_width() * .0868), 0) - screen.blit(currentArray[i], ((i + 1) * screen.get_width() * .1157 - screen.get_width() * .0607, screen.get_height() * .7117)) + screen.blit(currentArray[i], + ((i + 1) * screen.get_width() * .1157 - + screen.get_width() * .0607, screen.get_height() * .7117)) #4 boxes to change screen to purchase base skins, hats, trails, and backgrounds xCord = math.floor(screen.get_width() * .0289) @@ -327,11 +340,12 @@ def customize_screen(noises, duckIndex, arrayIndex): )[0] < xArr1 + wArr and yArr < pygame.mouse.get_pos( )[1] < yArr + hArr: noises.playSound("quack") - startingDuck -=1 + startingDuck -= 1 if startingDuck < 0: startingDuck = len(allSkins) - 1 # Make the duck the new duck - currentPreview = pygame.transform.scale(currentArray[startingDuck], (previewSize, previewSize)) + currentPreview = pygame.transform.scale( + currentArray[startingDuck], (previewSize, previewSize)) #click on equip or buy elif xArr1 + sep + wArr < pygame.mouse.get_pos( @@ -365,7 +379,8 @@ def customize_screen(noises, duckIndex, arrayIndex): if startingDuck > len(allSkins) - 1: startingDuck = 0 # Make the duck the new duck - currentPreview = pygame.transform.scale(currentArray[startingDuck], (previewSize, previewSize)) + currentPreview = pygame.transform.scale( + currentArray[startingDuck], (previewSize, previewSize)) elif event.type == pygame.QUIT: menuS.set_game_menu(menuS.menu.QUIT) @@ -373,4 +388,4 @@ def customize_screen(noises, duckIndex, arrayIndex): if event.key == pygame.K_ESCAPE: menuS.set_game_menu(menuS.menu.QUIT) - return startingDuck, startingArray \ No newline at end of file + return startingDuck, startingArray diff --git a/views/gameScreen.py b/views/gameScreen.py index 5de2ce9..3cdb7d1 100644 --- a/views/gameScreen.py +++ b/views/gameScreen.py @@ -6,7 +6,6 @@ import time import menuStructure as menuS import main as main -from enum import Enum from assets import values from fileio import settingIO from fileio import statsIO @@ -18,8 +17,6 @@ GRID_SIZE = 64 FPS = 30 - - pygame.init() #CONTROLS @@ -68,7 +65,7 @@ def loadImage(filePath, scale): DAMAGE_BUFF = loadImage(os.path.join("assets", "sprites", "Damage_Buff.png"), scale=True) #DUCK_IMG2 = loadImage(os.path.join("assets", "sprites", "DuckFrame2.png"), - #scale=True) +#scale=True) ENEMY_LASER = loadImage(os.path.join("assets", "sprites", "Laser_Proj.png"), scale=False) ENEMY_IMG = loadImage(os.path.join("assets", "sprites", "Enemy_Sprite.png"), @@ -348,7 +345,7 @@ def apply(self, duck): if self.effect == "Health": duck.health += 1 if self.effect == "Speed": - if random.randint(0,9) == 0: + if random.randint(0, 9) == 0: duck.speed -= 3 duck.speed += 3 if self.effect == "Damage": @@ -685,7 +682,6 @@ def process_events(self): self.end_game_process() values.distanceTraveled = self.totalDistanceTraveled - values.newHighScore = False menuS.menu.QUIT main.quit_game() @@ -765,7 +761,6 @@ def update(self): if self.duck.health <= 0 or self.duck.rect.right < 0: self.stage = Game.GAME_OVER - self.distanceTraveled += self.gameSpeed self.totalDistanceTraveled += self.gameSpeed @@ -838,15 +833,19 @@ def loop(self): self.update() self.draw() self.clock.tick(FPS) - + def end_game_process(self): #find game time using values.start_time game_time = time.time() - values.startTime #convert to MM:SS values.gameTime = time.strftime('%M:%S', time.gmtime(game_time)) - + # Game Format is [Distance, Time, Points, Currency, Enemies, Spaceships, Meteroids] - game = [self.totalDistanceTraveled, math.floor(self.elapsedTime), self.duck.score, self.duck.coins, self.duck.enemiesKilled] + game = [ + self.totalDistanceTraveled, + math.floor(self.elapsedTime), self.duck.score, self.duck.coins, + self.duck.enemiesKilled + ] statsIO.postgame_update(game) statsIO.create_game_log(game) #make YYYY-MM-DD @@ -854,11 +853,10 @@ def end_game_process(self): str(datetime.datetime.now().year) + "-" + str(datetime.datetime.now().month) + "-" + str(datetime.datetime.now().day)) - score = [settingIO.Player_Name, values.game_score, day] highScoreIO.check_for_high_score(score) - + def gameScreen(): global UP, DOWN, LEFT, RIGHT @@ -877,5 +875,3 @@ def gameScreen(): RIGHT = pygame.K_RIGHT #pygame.quit() #sys.exit() - - diff --git a/views/highScoreScreen.py b/views/highScoreScreen.py index c206e03..546d371 100644 --- a/views/highScoreScreen.py +++ b/views/highScoreScreen.py @@ -20,7 +20,7 @@ def high_score_screen(noises, gameOver=False, scoreId=-1): Args: noises (SFXHandler): sounds for screen """ - + # Set the background to main.jpg background = pygame.image.load( os.path.join("assets", "backgrounds", "tertiary.jpg")) diff --git a/views/statScreen.py b/views/statScreen.py index 3d3b651..d51e1f1 100644 --- a/views/statScreen.py +++ b/views/statScreen.py @@ -203,15 +203,15 @@ def screen_no_button(screen): #convert to MM:SS rounded_total_time = round(statsIO.totalGameTime, 2) totTime = time.strftime('%M:%S', time.gmtime(rounded_total_time)) - ValtotGameTime_text_image = subtitleFont.render(str(totTime), - True, values.COLOR_Red) + ValtotGameTime_text_image = subtitleFont.render(str(totTime), True, + values.COLOR_Red) ValEnemyKills_text_image = subtitleFont.render(str(statsIO.enemyDefeated), True, values.COLOR_Red) ValAllTimeCurrency_text_image = subtitleFont.render( str(statsIO.allTimeCurrency), True, values.COLOR_Red) rounded_average_time = round(statsIO.averageGameTime, 2) - + avTime = time.strftime('%M:%S', time.gmtime(rounded_average_time)) ValAverageGameTime_text_image = subtitleFont.render( str(avTime), True, values.COLOR_Red)