From 01a4a9f014993d9ba6dc247efc919259ab69a68d Mon Sep 17 00:00:00 2001 From: bgrose <47512745+bgrose@users.noreply.github.com> Date: Sun, 2 Apr 2023 20:35:34 -0400 Subject: [PATCH] format --- assets/soundHandler.py | 6 ++- assets/values.py | 4 ++ fileio/customizationIO.py | 1 + fileio/settingIO.py | 1 - main.py | 2 - test/test_SettingIO.py | 1 - test/test_StatIO.py | 2 +- test/test_behavior_customizeScreen.py | 7 +-- test/test_behavior_gameOverScreen.py | 8 +-- test/test_behavior_gameScreen.py | 8 +-- test/test_behavior_highScoreScreen.py | 8 +-- test/test_behavior_settingsScreen.py | 8 +-- test/test_behavior_statScreen.py | 8 +-- test/test_customizationIO.py | 17 +++---- test/test_customizeScreen.py | 11 ++-- test/test_gameOverScreen.py | 9 ++-- test/test_gameScreen.py | 6 +-- test/test_highScoreScreen.py | 17 ++++--- test/test_homeScreen.py | 15 +++--- test/test_main.py | 12 ++--- test/test_menuStructure.py | 52 +++++++++---------- test/test_settingsScreen.py | 26 ++++++---- test/test_soundHandler.py | 16 +++--- test/test_statScreen.py | 12 ++--- test/test_values.py | 47 +++++++++-------- views/customizeScreen.py | 73 +++++++++++++++------------ views/gameScreen.py | 54 ++++++++++---------- views/settingScreen.py | 17 ++++--- 28 files changed, 210 insertions(+), 238 deletions(-) diff --git a/assets/soundHandler.py b/assets/soundHandler.py index 90f53ad..4778585 100644 --- a/assets/soundHandler.py +++ b/assets/soundHandler.py @@ -21,8 +21,10 @@ class SFXHandler: def __init__(self): pygame.mixer.init() self.currentSong = "NA" - self.sound_volume(settingIO.SFX_Volume * (settingIO.Master_Volume / 100)) - self.music_volume(settingIO.Music_Volume * (settingIO.Master_Volume / 100)) + self.sound_volume(settingIO.SFX_Volume * + (settingIO.Master_Volume / 100)) + self.music_volume(settingIO.Music_Volume * + (settingIO.Master_Volume / 100)) def sound_volume(self, newVol): # Make sure it is a valid volume diff --git a/assets/values.py b/assets/values.py index 16ebb34..0d50dc4 100644 --- a/assets/values.py +++ b/assets/values.py @@ -89,15 +89,18 @@ def setSkin(skin): global current_skin current_skin = skin + def setBackground(bg): global current_background current_background = bg + def updateCoins(): global coins_in_game customizationIO.coins += coins_in_game customizationIO.save_customization() + def getBG(index): if index == 0: return "assets/backgrounds/base_bg.jpg" @@ -106,6 +109,7 @@ def getBG(index): else: return "assets/backgrounds/pixelSpace.png" + newHighScore = False newHighScoreId = -1 diff --git a/fileio/customizationIO.py b/fileio/customizationIO.py index 0eaf815..86e4159 100644 --- a/fileio/customizationIO.py +++ b/fileio/customizationIO.py @@ -5,6 +5,7 @@ global coins, current_skin, current_hat global current_background + def load_customization(): """summary: Loads the customization from the file """ diff --git a/fileio/settingIO.py b/fileio/settingIO.py index 7aef816..e402a88 100644 --- a/fileio/settingIO.py +++ b/fileio/settingIO.py @@ -16,7 +16,6 @@ global SFX_Volume, DifficultyLevel, keys - class difficulty(Enum): EASY = 1 MEDIUM = 2 diff --git a/main.py b/main.py index e983e5f..0e6432a 100644 --- a/main.py +++ b/main.py @@ -24,8 +24,6 @@ pygame.display.set_caption("Ducks In Space") pygame.display.update() - - statsIO.load_stats() settingIO.load_settings(values.SETTING_PATH) highScoreIO.load_high_scores() diff --git a/test/test_SettingIO.py b/test/test_SettingIO.py index c1c6452..903ad45 100644 --- a/test/test_SettingIO.py +++ b/test/test_SettingIO.py @@ -1,7 +1,6 @@ import sys sys.path.append('..') -import pygame from fileio import settingIO diff --git a/test/test_StatIO.py b/test/test_StatIO.py index ddd1de0..35e8489 100644 --- a/test/test_StatIO.py +++ b/test/test_StatIO.py @@ -32,7 +32,7 @@ def test_postgame_update(): assert statsIO.totalGamesPlayed == 1 assert statsIO.totalGameTime == 100 assert statsIO.enemyDefeated == 100 - #assert statsIO.spaceshipKills == 100 + #assert statsIO.spaceshipKills == 100 #assert statsIO.meteroidKills == 100 assert statsIO.allTimeCurrency == 100 assert statsIO.averageGameTime == 100 diff --git a/test/test_behavior_customizeScreen.py b/test/test_behavior_customizeScreen.py index 6003a39..a991f61 100644 --- a/test/test_behavior_customizeScreen.py +++ b/test/test_behavior_customizeScreen.py @@ -2,13 +2,8 @@ sys.path.append('..') #import pytest_bdd methods and feature file for this test -from pytest_bdd import * -import pygame -import menuStructure as menuS #from views import customizeScreen -from assets import values -from assets import soundHandler #scenario('../test/features/customizeScreen.feature', '') -#Use given when then structure for tests \ No newline at end of file +#Use given when then structure for tests diff --git a/test/test_behavior_gameOverScreen.py b/test/test_behavior_gameOverScreen.py index 680859a..067c8b1 100644 --- a/test/test_behavior_gameOverScreen.py +++ b/test/test_behavior_gameOverScreen.py @@ -2,13 +2,7 @@ sys.path.append('..') #import pytest_bdd methods and feature file for this test -from pytest_bdd import * -import pygame -import menuStructure as menuS -from views import gameOverScreen -from assets import values -from assets import soundHandler #scenario('../test/features/gameOverScreen.feature', '') -#Use given when then structure for tests \ No newline at end of file +#Use given when then structure for tests diff --git a/test/test_behavior_gameScreen.py b/test/test_behavior_gameScreen.py index 7227f7f..01a3a3e 100644 --- a/test/test_behavior_gameScreen.py +++ b/test/test_behavior_gameScreen.py @@ -2,13 +2,7 @@ sys.path.append('..') #import pytest_bdd methods and feature file for this test -from pytest_bdd import * -import pygame -import menuStructure as menuS -from views import gameScreen -from assets import values -from assets import soundHandler #scenario('../test/features/gameScreen.feature', '') -#Use given when then structure for tests \ No newline at end of file +#Use given when then structure for tests diff --git a/test/test_behavior_highScoreScreen.py b/test/test_behavior_highScoreScreen.py index 993dd7d..cabd9bf 100644 --- a/test/test_behavior_highScoreScreen.py +++ b/test/test_behavior_highScoreScreen.py @@ -2,13 +2,7 @@ sys.path.append('..') #import pytest_bdd methods and feature file for this test -from pytest_bdd import * -import pygame -import menuStructure as menuS -from views import highScoreScreen -from assets import values -from assets import soundHandler #scenario('../test/features/highScoreScreen.feature', '') -#Use given when then structure for tests \ No newline at end of file +#Use given when then structure for tests diff --git a/test/test_behavior_settingsScreen.py b/test/test_behavior_settingsScreen.py index f44ea87..7f3937c 100644 --- a/test/test_behavior_settingsScreen.py +++ b/test/test_behavior_settingsScreen.py @@ -2,13 +2,7 @@ sys.path.append('..') #import pytest_bdd methods and feature file for this test -from pytest_bdd import * -import pygame -import menuStructure as menuS -from views import settingScreen -from assets import values -from assets import soundHandler #scenario('../test/features/settingsScreen.feature', '') -#Use given when then structure for tests \ No newline at end of file +#Use given when then structure for tests diff --git a/test/test_behavior_statScreen.py b/test/test_behavior_statScreen.py index f208846..9a76ac7 100644 --- a/test/test_behavior_statScreen.py +++ b/test/test_behavior_statScreen.py @@ -2,13 +2,7 @@ sys.path.append('..') #import pytest_bdd methods and feature file for this test -from pytest_bdd import * -import pygame -import menuStructure as menuS -from views import statScreen -from assets import values -from assets import soundHandler #scenario('../test/features/statScreen.feature', '') -#Use given when then structure for tests \ No newline at end of file +#Use given when then structure for tests diff --git a/test/test_customizationIO.py b/test/test_customizationIO.py index 92b6d10..0364b60 100644 --- a/test/test_customizationIO.py +++ b/test/test_customizationIO.py @@ -2,14 +2,14 @@ sys.path.append('..') import os -import pytest from fileio import customizationIO + def test_load_customization(): customizationIO.load_new_customization() customizationIO.load_customization() - + assert customizationIO.skins == [] assert customizationIO.hats == [] assert customizationIO.backgrounds == [] @@ -17,19 +17,14 @@ def test_load_customization(): assert customizationIO.current_skin == 0 assert customizationIO.current_hat == 0 assert customizationIO.current_background == 0 - + + def test_save_customization(): customizationIO.save_customization() assert os.path.exists("fileio\\Customization.json") - + + def test_add_currency(): customizationIO.load_new_customization() customizationIO.add_currency(69) assert customizationIO.coins == 69 - - - - - - - diff --git a/test/test_customizeScreen.py b/test/test_customizeScreen.py index 78826dc..6d0cb9e 100644 --- a/test/test_customizeScreen.py +++ b/test/test_customizeScreen.py @@ -1,11 +1,6 @@ import sys -import pygame sys.path.append('..') -import os -import pytest - -from views import customizeScreen normalSkins = ['normal1.png', 'normal2.png', 'normal3.png'] @@ -15,7 +10,6 @@ graySkins = ['gray1.png', 'gray2.png', 'gray3.png'] greenSkins = ['green1.png', 'green2.png'] richSkins = ['rich1.png'] - """ def test_load_assets(): # Define test input @@ -39,6 +33,7 @@ def test_load_assets(): assert len(result[5]) == len(greenSkins) assert len(result[6]) == len(richSkins) """ - + + def test_customize_screen(): - assert True \ No newline at end of file + assert True diff --git a/test/test_gameOverScreen.py b/test/test_gameOverScreen.py index 68c262e..9d1181e 100644 --- a/test/test_gameOverScreen.py +++ b/test/test_gameOverScreen.py @@ -1,13 +1,12 @@ import sys sys.path.append('..') -import os -import pytest -from views import gameOverScreen + def test_start_screen(): - assert True; + assert True + def test_shareScoreGraphic(): - assert True; \ No newline at end of file + assert True diff --git a/test/test_gameScreen.py b/test/test_gameScreen.py index a58c0cf..19ce660 100644 --- a/test/test_gameScreen.py +++ b/test/test_gameScreen.py @@ -1,10 +1,8 @@ import sys sys.path.append('..') -import os -import pytest -from views import gameScreen + def testt_loadImage(): - assert True \ No newline at end of file + assert True diff --git a/test/test_highScoreScreen.py b/test/test_highScoreScreen.py index bf44062..af92a26 100644 --- a/test/test_highScoreScreen.py +++ b/test/test_highScoreScreen.py @@ -1,23 +1,24 @@ import sys -import pygame sys.path.append('..') -import os -import pytest -from views import highScoreScreen + def test_high_score_screen(): assert True - + + def test_write_scores_text(): assert True - + + def test_write_no_high_score(): assert True - + + def test_draw_buttons(): assert True - + + def test_check_cords(): assert True diff --git a/test/test_homeScreen.py b/test/test_homeScreen.py index 5adaff1..a26d67a 100644 --- a/test/test_homeScreen.py +++ b/test/test_homeScreen.py @@ -1,19 +1,20 @@ import sys sys.path.append('..') -import os -import pytest -from views import homeScreen + def test_home_screen(): assert True - + + def test_check_highlight(): assert True - + + def test_click_handler(): assert True - + + def test_check_click(): - assert True \ No newline at end of file + assert True diff --git a/test/test_main.py b/test/test_main.py index 09f1c65..f151806 100644 --- a/test/test_main.py +++ b/test/test_main.py @@ -1,18 +1,14 @@ import sys -import unittest.mock as mock -import main -import menuStructure as menuS sys.path.append('..') -import os -import pytest -import main + def test_main(): # Untestable assert True - + + def test_quit_game(): # Untestable - assert True \ No newline at end of file + assert True diff --git a/test/test_menuStructure.py b/test/test_menuStructure.py index 12d8050..e900086 100644 --- a/test/test_menuStructure.py +++ b/test/test_menuStructure.py @@ -1,9 +1,6 @@ import sys sys.path.append('..') -import os -import pytest -import unittest import menuStructure import time @@ -11,38 +8,37 @@ def test_set_and_get_game_menu(): - # Test setting and getting the game menu - from menuStructure import menu - menuStructure.set_game_menu(menu.HOME) - assert menuStructure.get_game_menu() == (menu.HOME) - - menuStructure.set_game_menu(menu.STAT) - assert menuStructure.get_game_menu() == (menu.STAT) + # Test setting and getting the game menu + from menuStructure import menu + menuStructure.set_game_menu(menu.HOME) + assert menuStructure.get_game_menu() == (menu.HOME) - menuStructure.set_game_menu(menu.GAME) - assert menuStructure.get_game_menu() == (menu.GAME) + menuStructure.set_game_menu(menu.STAT) + assert menuStructure.get_game_menu() == (menu.STAT) - menuStructure.set_game_menu(menu.CUSTOMIZE) - assert menuStructure.get_game_menu() == (menu.CUSTOMIZE) + menuStructure.set_game_menu(menu.GAME) + assert menuStructure.get_game_menu() == (menu.GAME) - menuStructure.set_game_menu(menu.HIGH_SCORE) - assert menuStructure.get_game_menu() == (menu.HIGH_SCORE) + menuStructure.set_game_menu(menu.CUSTOMIZE) + assert menuStructure.get_game_menu() == (menu.CUSTOMIZE) - menuStructure.set_game_menu(menu.SETTING) - assert menuStructure.get_game_menu() == (menu.SETTING) + menuStructure.set_game_menu(menu.HIGH_SCORE) + assert menuStructure.get_game_menu() == (menu.HIGH_SCORE) - menuStructure.set_game_menu(menu.QUIT) - assert menuStructure.get_game_menu() == (menu.QUIT) + menuStructure.set_game_menu(menu.SETTING) + assert menuStructure.get_game_menu() == (menu.SETTING) - menuStructure.set_game_menu(menu.GAMEOVER) - assert menuStructure.get_game_menu() == (menu.GAMEOVER) + menuStructure.set_game_menu(menu.QUIT) + assert menuStructure.get_game_menu() == (menu.QUIT) + menuStructure.set_game_menu(menu.GAMEOVER) + assert menuStructure.get_game_menu() == (menu.GAMEOVER) -def test_double_click_preventer(): - # Test that the double_click_preventer function sleeps for 0.1 seconds - start_time = time.time() - menuStructure.double_click_preventer() - end_time = time.time() - assert math.isclose(end_time - start_time, 0.1, abs_tol = 0.05) +def test_double_click_preventer(): + # Test that the double_click_preventer function sleeps for 0.1 seconds + start_time = time.time() + menuStructure.double_click_preventer() + end_time = time.time() + assert math.isclose(end_time - start_time, 0.1, abs_tol=0.05) diff --git a/test/test_settingsScreen.py b/test/test_settingsScreen.py index e9fb0f2..591285e 100644 --- a/test/test_settingsScreen.py +++ b/test/test_settingsScreen.py @@ -2,21 +2,23 @@ import pygame sys.path.append('..') -import os -import pytest from views import settingScreen + def test_settingScreen(): assert True - + + def test_round_Percent(): assert settingScreen.round_Percent(53.2) == 55 assert settingScreen.round_Percent(48.3) == 45 - + + def test_draw_background(): assert True - + + """ def test_checkCords(): assert settingScreen.checkCords((100, 100), 50) == True @@ -43,6 +45,8 @@ def test_checkDifCords(): image = pygame.Surface((50, 50)) assert settingScreen.checkDifCords(cords, image) == False """ + + def test_checkSliderCords(): left = 100 factor = 20 @@ -50,9 +54,13 @@ def test_checkSliderCords(): screen = pygame.Surface((500, 500)) range = 200 height = 5 - pygame.mouse.set_pos((left + factor + image.get_width() + range/2, screen.get_height() / 16 * height + 25)) - assert settingScreen.checkSliderCords(left, factor, image, screen, range, height) == True + pygame.mouse.set_pos((left + factor + image.get_width() + range / 2, + screen.get_height() / 16 * height + 25)) + assert settingScreen.checkSliderCords(left, factor, image, screen, range, + height) == True # Test with coordinates outside the slider - pygame.mouse.set_pos((left + factor + image.get_width() + range + 50, screen.get_height() / 16 * height + 25)) - assert settingScreen.checkSliderCords(left, factor, image, screen, range, height) == False \ No newline at end of file + pygame.mouse.set_pos((left + factor + image.get_width() + range + 50, + screen.get_height() / 16 * height + 25)) + assert settingScreen.checkSliderCords(left, factor, image, screen, range, + height) == False diff --git a/test/test_soundHandler.py b/test/test_soundHandler.py index fe2ffd8..ff10015 100644 --- a/test/test_soundHandler.py +++ b/test/test_soundHandler.py @@ -1,22 +1,24 @@ import sys sys.path.append('..') -import os -import pytest -from assets import soundHandler + def test_init(): assert True + def test_sound_volume(): assert True - + + def test_music_volume(): assert True - + + def test_playSound(): assert True - + + def test_playMusic(): - assert True \ No newline at end of file + assert True diff --git a/test/test_statScreen.py b/test/test_statScreen.py index 51942da..e44efd6 100644 --- a/test/test_statScreen.py +++ b/test/test_statScreen.py @@ -1,16 +1,16 @@ import sys sys.path.append('..') -import os -import pytest -from views import statScreen + def test_start_screen(): assert True - + + def test_share_stats(): assert True - + + def test_screen_no_button(): - assert True \ No newline at end of file + assert True diff --git a/test/test_values.py b/test/test_values.py index 79e49e7..8ec5738 100644 --- a/test/test_values.py +++ b/test/test_values.py @@ -1,17 +1,16 @@ import sys sys.path.append('..') -import os -import pytest -import time from assets import values + def test_set_screen_size(): - values.set_screen_size(500, 600) - assert values.screenX == 500 - assert values.screenX == 500 - assert values.SCREEN_SIZE == (500,600) + values.set_screen_size(500, 600) + assert values.screenX == 500 + assert values.screenX == 500 + assert values.SCREEN_SIZE == (500, 600) + """def test_sessionRunTime(): global startTime @@ -22,29 +21,33 @@ def test_set_screen_size(): assert result == "01:00" """ + def test_setStartTime(): - global startTime - values.setStartTime() - assert values.startTime > -1 + global startTime + values.setStartTime() + assert values.startTime > -1 + def test_setGameScore(): - values.setGameScore(100) - assert values.game_score == 100 + values.setGameScore(100) + assert values.game_score == 100 + def test_resetGameScore(): - game_score = 50 - values.resetGameScore() - assert values.game_score == 0 + values.resetGameScore() + assert values.game_score == 0 + def test_setCoinsinGame(): - values.setCoinsinGame(10) - assert values.coins_in_game == 10 + values.setCoinsinGame(10) + assert values.coins_in_game == 10 + def test_resetCoinsinGame(): - coins_in_game = 20 - values.resetCoinsinGame() - assert values.coins_in_game == 0 + values.resetCoinsinGame() + assert values.coins_in_game == 0 + def test_setSkin(): - values.setSkin("skin1") - assert values.current_skin == "skin1" \ No newline at end of file + values.setSkin("skin1") + assert values.current_skin == "skin1" diff --git a/views/customizeScreen.py b/views/customizeScreen.py index 5c07a2d..64e4fd4 100644 --- a/views/customizeScreen.py +++ b/views/customizeScreen.py @@ -9,7 +9,6 @@ customizationIO.load_customization() - ownedSkins = customizationIO.skins ownedBackgrounds = customizationIO.backgrounds @@ -70,8 +69,7 @@ ] bgs = [ - "assets/backgrounds/base_bg.jpg", - "assets/backgrounds/pixelNebula.png", + "assets/backgrounds/base_bg.jpg", "assets/backgrounds/pixelNebula.png", "assets/backgrounds/pixelSpace.png" ] @@ -98,6 +96,7 @@ values.setSkin(tempArray[current_hat_index]) + def loadAssets(purchaseSize): allSkins = [] baseAccessories = [] @@ -106,7 +105,7 @@ def loadAssets(purchaseSize): grayAccessories = [] greenAccessories = [] richAccessories = [] - backgrounds = [] + backgrounds = [] for x in normalSkins: allSkins.append( pygame.transform.scale(pygame.image.load(x), @@ -137,8 +136,8 @@ def loadAssets(purchaseSize): (purchaseSize, purchaseSize))) for x in bgs: backgrounds.append( - pygame.transform.scale(pygame.image.load(x), - (purchaseSize / 2, purchaseSize / 2))) + pygame.transform.scale(pygame.image.load(x), + (purchaseSize / 2, purchaseSize / 2))) return allSkins, baseAccessories, blueAccessories, brownAccessories, grayAccessories, greenAccessories, richAccessories, backgrounds @@ -249,7 +248,6 @@ def customize_screen(noises, duckIndex, arrayIndex): pygame.draw.rect(screen, values.COLOR_Pink, (xArr1 + wArr + sep, yArr, box, hArr), 0) - # Equip section # Check and see if the skin is owned if arrayIndex == 0: @@ -271,28 +269,35 @@ def customize_screen(noises, duckIndex, arrayIndex): else: usedArray = normalSkins - if usedArray[startingDuck] in ownedSkins or usedArray[startingDuck] in ownedBackgrounds: + if usedArray[startingDuck] in ownedSkins or usedArray[ + startingDuck] in ownedBackgrounds: # Skin is owned, show equip - if pygame.mouse.get_pos()[0] > xArr1 + wArr + sep and pygame.mouse.get_pos( + if pygame.mouse.get_pos( + )[0] > xArr1 + wArr + sep and pygame.mouse.get_pos( )[0] < xArr1 + wArr + sep + box and pygame.mouse.get_pos( )[1] > yArr and pygame.mouse.get_pos()[1] < yArr + hArr: - equip_text_image = smallFont.render("Equip", True, values.COLOR_Yellow) + equip_text_image = smallFont.render("Equip", True, + values.COLOR_Yellow) else: - equip_text_image = smallFont.render("Equip", True, values.COLOR_Purple) + equip_text_image = smallFont.render("Equip", True, + values.COLOR_Purple) screen.blit(equip_text_image, (xArr1 + wArr + sep + screen.get_width() * .0434, - yArr + screen.get_height() * .0313)) + yArr + screen.get_height() * .0313)) else: # Skin is unowned, show purchase option - if pygame.mouse.get_pos()[0] > xArr1 + wArr + sep and pygame.mouse.get_pos( + if pygame.mouse.get_pos( + )[0] > xArr1 + wArr + sep and pygame.mouse.get_pos( )[0] < xArr1 + wArr + sep + box and pygame.mouse.get_pos( )[1] > yArr and pygame.mouse.get_pos()[1] < yArr + hArr: - equip_text_image = smallFont.render("100", True, values.COLOR_Yellow) + equip_text_image = smallFont.render("100", True, + values.COLOR_Yellow) else: - equip_text_image = smallFont.render("100", True, values.COLOR_Purple) + equip_text_image = smallFont.render("100", True, + values.COLOR_Purple) screen.blit(equip_text_image, (xArr1 + wArr + sep + screen.get_width() * .055, - yArr + screen.get_height() * .0313)) + yArr + screen.get_height() * .0313)) # Rotated form of the left arrow (Should probably change to a different sprite later) rightArr = pygame.transform.rotate(bigArr, 180) @@ -318,21 +323,23 @@ def customize_screen(noises, duckIndex, arrayIndex): # Make backgrounds in center of box pygame.draw.rect( screen, values.COLOR_Pink, - ((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() * .0225, screen.get_height() * .77)) + ((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() * .0225, screen.get_height() * .77)) else: pygame.draw.rect( screen, values.COLOR_Pink, - ((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)) + ((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)) #4 boxes to change screen to purchase base skins, hats, trails, and backgrounds xCord = math.floor(screen.get_width() * .0289) @@ -461,7 +468,8 @@ def customize_screen(noises, duckIndex, arrayIndex): noises.playSound("quack") # Set the duck to the current one with values.py # Figure out which array we are currently in - if usedArray[startingDuck] in ownedSkins or usedArray[startingDuck] in ownedBackgrounds: + if usedArray[startingDuck] in ownedSkins or usedArray[ + startingDuck] in ownedBackgrounds: # We own the item, figure out what it is if "background" in usedArray[startingDuck]: values.setBackground(usedArray[startingDuck]) @@ -472,11 +480,13 @@ def customize_screen(noises, duckIndex, arrayIndex): # Can purchase if "background" in usedArray[startingDuck]: # It is a background - customizationIO.backgrounds.append(usedArray[startingDuck]) + customizationIO.backgrounds.append( + usedArray[startingDuck]) customizationIO.current_background = startingDuck else: # It is a skin - customizationIO.skins.append(usedArray[startingDuck]) + customizationIO.skins.append( + usedArray[startingDuck]) customizationIO.current_skin = arrayIndex customizationIO.current_hat = startingDuck coins_imported -= 100 @@ -508,6 +518,5 @@ def customize_screen(noises, duckIndex, arrayIndex): if event.key == pygame.K_ESCAPE: menuS.set_game_menu(menuS.menu.HOME) main.main() - return startingDuck, startingArray diff --git a/views/gameScreen.py b/views/gameScreen.py index cbed90a..535ff29 100644 --- a/views/gameScreen.py +++ b/views/gameScreen.py @@ -20,7 +20,7 @@ pygame.init() #CONTROLS -#for some reason this is causing an error when running tests +#for some reason this is causing an error when running tests #AttributeError: module 'fileio.settingIO' has no attribute 'keys' if settingIO.keys == "wasd": UP = pygame.K_w @@ -59,8 +59,7 @@ def loadImage(filePath, scale): BLOCK_IMG = loadImage(os.path.join("assets", "sprites", "Wall_block.png"), scale=True) BLOCK_IMG2 = pygame.transform.flip(BLOCK_IMG, False, True) -DUCK_IMG = loadImage(values.current_skin, - scale=True) +DUCK_IMG = loadImage(values.current_skin, scale=True) SWAG_DUCK = loadImage(os.path.join("assets", "sprites", "SwagDuck.png"), scale=True) COIN_IMG = loadImage(os.path.join("assets", "sprites", "Coin.png"), scale=True) @@ -74,7 +73,8 @@ def loadImage(filePath, scale): scale=True) ROCKET_IMG = loadImage(os.path.join("assets", "sprites", "Rocket.png"), scale=True) -EXPLOSION_IMG = loadImage(os.path.join("assets","sprites","Boom.png"),scale=True) +EXPLOSION_IMG = loadImage(os.path.join("assets", "sprites", "Boom.png"), + scale=True) HEALTH_IMG = loadImage(os.path.join("assets", "sprites", "Health_Symbol.png"), scale=True) EXIT_IMG = loadImage(os.path.join("assets", "sprites", "Exit_Button.png"), @@ -95,7 +95,6 @@ def loadImage(filePath, scale): POWERUP_IMGS = {"Health": HEALTH_IMG, "Speed": SPEED_IMG} - class Entity(pygame.sprite.Sprite): def __init__(self, x, y, image): @@ -145,21 +144,20 @@ def __init__(self, x, y, image): self.image = pygame.transform.rotate(image, theta) self.speed = vBase # Set velocity - dr = math.sqrt(dx ** 2 + dy ** 2) + dr = math.sqrt(dx**2 + dy**2) self.vx = vBase * dx / dr self.vy = -vBase * dy / dr def update(self, level, duck): - self.rect.x += self.vx self.rect.y += self.vy hit_list = pygame.sprite.spritecollide(self, level.enemies, True) bit_list = pygame.sprite.spritecollide(self, level.blocks, False) if hit_list or bit_list: - level.addBoom(self.rect.x,self.rect.y) + level.addBoom(self.rect.x, self.rect.y) self.kill() duck.enemiesKilled += 1 @@ -179,10 +177,12 @@ def levelUpdate(self, speed, level, duck): if hit_list: duck.rect.right = self.rect.left + class RocketCD(pygame.sprite.Sprite): - def __init__(self,x,y,cd): + + def __init__(self, x, y, cd): super().__init__() - self.rect = pygame.rect.Rect(0,0,3,56) + self.rect = pygame.rect.Rect(0, 0, 3, 56) self.rect.x = x self.rect.y = y @@ -193,7 +193,7 @@ def __init__(self,x,y,cd): self.avail = True - def update(self,duck): + def update(self, duck): self.rect.x = duck.rect.x - 10 self.rect.y = duck.rect.y + 4 + self.yoffset @@ -206,8 +206,8 @@ def update(self,duck): self.yoffset = 0 else: prop = self.time / self.cd - self.rect.height = math.floor(56*prop) - self.yoffset = 56-self.rect.height + self.rect.height = math.floor(56 * prop) + self.yoffset = 56 - self.rect.height def shoot(self): self.avail = False @@ -215,7 +215,6 @@ def shoot(self): self.yoffset = 0 - class Duck(Entity): def __init__(self, images): @@ -247,9 +246,9 @@ def __init__(self, images): self.rockets = [] self.rocketGroup = pygame.sprite.Group() - + self.rocketCooldown = 30 - self.RocketCD = RocketCD(0,0,self.rocketCooldown) + self.RocketCD = RocketCD(0, 0, self.rocketCooldown) def moveLeft(self): self.vx = -self.speed @@ -413,7 +412,6 @@ def apply(self, duck): duck.takeDamage(1) if self.effect == "Bomb": duck.takeDamage(3) - class Enemy(Entity): @@ -429,10 +427,9 @@ def update(self, duck, blocks): if self.rect.y - duck.rect.y > 100: self.directiony = -1 - + if self.rect.y - duck.rect.y < -100: self.directiony = 1 - self.vx = self.speed * -1 self.vy = self.speed * self.directiony @@ -444,12 +441,13 @@ def update(self, duck, blocks): self.rect.y = 0 elif self.rect.bottom > HEIGHT: self.rect.y = HEIGHT - self.rect.height - + hit_list = pygame.sprite.spritecollide(self, blocks, False) for block in hit_list: if self.rect.centerx > block.rect.x + GRID_SIZE and self.rect.left < 10: - self.rect.left = block.rect.right + self.rect.left = block.rect.right + #Level made of tiles #Tile one screen long with own sprites @@ -519,16 +517,16 @@ def __init__(self, numBlocks, numEnemies, numPowerups, numCoins, offset): class Boom(Entity): + def __init__(self, x, y): - super().__init__(x,y, EXPLOSION_IMG) + super().__init__(x, y, EXPLOSION_IMG) self.timer = 8 + def levelUpdate(self, speed, level, duck): self.rect.x -= speed self.timer -= 1 if self.rect.right < 0 or self.timer <= 0: level.active_sprites.remove(self) - - class Level(): @@ -542,7 +540,6 @@ def __init__(self, difficulty): self.enemies = pygame.sprite.Group() self.coins = pygame.sprite.Group() self.powerups = pygame.sprite.Group() - self.active_sprites = pygame.sprite.Group() self.inactive_sprites = pygame.sprite.Group() @@ -562,7 +559,7 @@ def __init__(self, difficulty): self.reset() def addBoom(self, x, y): - newBoom = Boom(x,y) + newBoom = Boom(x, y) self.active_sprites.add(newBoom) def update(self, duck): @@ -666,7 +663,7 @@ def __init__(self): def reset(self): DUCK_IMG = loadImage(values.current_skin, scale=True) - BACKGROUND_IMG = loadImage(values.current_background, False) + loadImage(values.current_background, False) self.elapsedTime = 0 self.duck = Duck([DUCK_IMG]) self.level = Level(self.difficulty) @@ -877,7 +874,8 @@ def draw(self): self.level.active_layer.blit(self.duck.image, [self.duck.rect.x, self.duck.rect.y]) #Draw cd - pygame.draw.rect(self.level.active_layer,(255,0,0),self.duck.RocketCD.rect) + pygame.draw.rect(self.level.active_layer, (255, 0, 0), + self.duck.RocketCD.rect) SCREEN.blit(self.level.background_layer, [0, 0]) SCREEN.blit(self.level.inactive_layer, [0, 0]) diff --git a/views/settingScreen.py b/views/settingScreen.py index b19feb0..ab8bf0a 100644 --- a/views/settingScreen.py +++ b/views/settingScreen.py @@ -323,10 +323,11 @@ def settings_screen(noises): (left + 30 + master_volume_image.get_width())) / masterValRange * 100) settingIO.Master_Volume = newPercent - noises.music_volume(settingIO.Music_Volume*settingIO.Master_Volume/100) - noises.sound_volume(settingIO.SFX_Volume*settingIO.Master_Volume/100) - - + noises.music_volume(settingIO.Music_Volume * + settingIO.Master_Volume / 100) + noises.sound_volume(settingIO.SFX_Volume * + settingIO.Master_Volume / 100) + elif checkSliderCords(left, 70, music_volume_image, screen, musicValRange, 4.95): noises.playSound("quack") @@ -335,8 +336,9 @@ def settings_screen(noises): (left + 70 + music_volume_image.get_width())) / musicValRange * 100) settingIO.Music_Volume = newPercent - noises.music_volume(settingIO.Music_Volume*settingIO.Master_Volume/100) - + noises.music_volume(settingIO.Music_Volume * + settingIO.Master_Volume / 100) + elif checkSliderCords(left, 70, sfx_volume_image, screen, sfxValRange, 5.95): noises.playSound("quack") @@ -345,7 +347,8 @@ def settings_screen(noises): (left + 70 + sfx_volume_image.get_width())) / sfxValRange * 100) settingIO.SFX_Volume = newPercent - noises.sound_volume(settingIO.SFX_Volume*settingIO.Master_Volume/100) + noises.sound_volume(settingIO.SFX_Volume * + settingIO.Master_Volume / 100) if inputNameBox.collidepoint(event.pos): # Toggle the active variable.