Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
bgrose committed Feb 27, 2023
1 parent 9364724 commit 0bf36fe
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 62 deletions.
3 changes: 2 additions & 1 deletion assets/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def resetCoinsinGame():
global coins_in_game
coins_in_game = 0


def setSkin(skin):
global current_skin
current_skin = skin
Expand All @@ -87,4 +88,4 @@ def setSkin(skin):
gameTime = -1
startTime = -1
enemysKilled = -1
distanceTraveled = -1
distanceTraveled = -1
6 changes: 3 additions & 3 deletions fileio/customizationIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()

3 changes: 2 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
93 changes: 54 additions & 39 deletions views/customizeScreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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 = []
Expand All @@ -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"))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -365,12 +379,13 @@ 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)
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
menuS.set_game_menu(menuS.menu.QUIT)

return startingDuck, startingArray
return startingDuck, startingArray
24 changes: 10 additions & 14 deletions views/gameScreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,8 +17,6 @@
GRID_SIZE = 64
FPS = 30



pygame.init()
#CONTROLS

Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -838,27 +833,30 @@ 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
day = str(
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
Expand All @@ -877,5 +875,3 @@ def gameScreen():
RIGHT = pygame.K_RIGHT
#pygame.quit()
#sys.exit()


2 changes: 1 addition & 1 deletion views/highScoreScreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
6 changes: 3 additions & 3 deletions views/statScreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0bf36fe

Please sign in to comment.