Skip to content

Commit

Permalink
Merge pull request #271 from SCCapstone/colin_final_changes
Browse files Browse the repository at this point in the history
Colin final changes
  • Loading branch information
bgrose authored Apr 3, 2023
2 parents 9c09e0c + 83480af commit f08f5dd
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 47 deletions.
Binary file added assets/backgrounds/pixelNebula.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/backgrounds/pixelSpace.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/sprites/BaseDuck.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions assets/values.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import os
import time
from fileio import customizationIO

global startTime
global game_score
global coins_in_game
global current_skin
global current_skin_index
global current_hat_index
global current_background
global current_background_index
global total_coins

customizationIO.load_customization()

# Colors
COLOR_Purple = (46, 41, 78)
Expand Down Expand Up @@ -81,6 +89,22 @@ 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"
elif index == 1:
return "assets/backgrounds/pixelNebula.png"
else:
return "assets/backgrounds/pixelSpace.png"

newHighScore = False
newHighScoreId = -1
Expand Down
1 change: 0 additions & 1 deletion fileio/customizationIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
global coins, current_skin, current_hat
global current_background


def load_customization():
"""summary: Loads the customization from the file
"""
Expand Down
4 changes: 4 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
highScoreIO.load_high_scores()
values.setStartTime()
customizationIO.load_customization()
values.total_coins = customizationIO.coins
values.current_skin_index = customizationIO.current_skin
values.current_hat_index = customizationIO.current_hat
values.current_background = values.getBG(customizationIO.current_background)

# Initialize the mixer
noises = soundHandler.SFXHandler()
Expand Down
205 changes: 162 additions & 43 deletions views/customizeScreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
from assets import values
import menuStructure as menuS
import main as main
from fileio import customizationIO

customizationIO.load_customization()


ownedSkins = customizationIO.skins
ownedBackgrounds = customizationIO.backgrounds

normalSkins = [
"assets/sprites/ducks/baseDuck.png", "assets/sprites/ducks/blueDuck.png",
Expand Down Expand Up @@ -62,6 +69,34 @@
"assets/sprites/ducks/richSunnies.png"
]

bgs = [
"assets/backgrounds/base_bg.jpg",
"assets/backgrounds/pixelNebula.png",
"assets/backgrounds/pixelSpace.png"
]

# Get current skin that is equipped
current_skin_index = customizationIO.current_skin
current_hat_index = customizationIO.current_hat
current_background_index = customizationIO.current_background
tempArray = []

if current_skin_index == 0:
tempArray = normalSkins
elif current_skin_index == 1:
tempArray = baseSkins
elif current_skin_index == 2:
tempArray = blueSkins
elif current_skin_index == 3:
tempArray = brownSkins
elif current_skin_index == 4:
tempArray = graySkins
elif current_skin_index == 5:
tempArray = greenSkins
elif current_skin_index == 6:
tempArray = richSkins

values.setSkin(tempArray[current_hat_index])

def loadAssets(purchaseSize):
allSkins = []
Expand All @@ -71,6 +106,7 @@ def loadAssets(purchaseSize):
grayAccessories = []
greenAccessories = []
richAccessories = []
backgrounds = []
for x in normalSkins:
allSkins.append(
pygame.transform.scale(pygame.image.load(x),
Expand Down Expand Up @@ -99,11 +135,17 @@ def loadAssets(purchaseSize):
richAccessories.append(
pygame.transform.scale(pygame.image.load(x),
(purchaseSize, purchaseSize)))
return allSkins, baseAccessories, blueAccessories, brownAccessories, grayAccessories, greenAccessories, richAccessories
for x in bgs:
backgrounds.append(
pygame.transform.scale(pygame.image.load(x),
(purchaseSize / 2, purchaseSize / 2)))
return allSkins, baseAccessories, blueAccessories, brownAccessories, grayAccessories, greenAccessories, richAccessories, backgrounds


# Runs the customize screen
def customize_screen(noises, duckIndex, arrayIndex):
ownedSkins = customizationIO.skins
ownedBackgrounds = customizationIO.backgrounds
startingDuck = duckIndex
startingArray = arrayIndex

Expand Down Expand Up @@ -143,7 +185,9 @@ def customize_screen(noises, duckIndex, arrayIndex):
screen.blit(customize_text_image, customizeCords)

#Coins available text - import actaul amount from JSON
coins_text_image = subtitleFont.render("Coins: 500", True,
coins_imported = customizationIO.coins
coin_text = "Coins: " + str(coins_imported)
coins_text_image = subtitleFont.render(coin_text, True,
values.COLOR_Yellow)
coinsCords = (left + screen.get_width() * .1215,
screen.get_height() / 16 * 3)
Expand All @@ -160,7 +204,7 @@ def customize_screen(noises, duckIndex, arrayIndex):

#load duck base skins
purchaseSize = int(values.screenX * .1504)
allSkins, baseAccessories, blueAccessories, brownAccessories, grayAccessories, greenAccessories, richAccessories = loadAssets(
allSkins, baseAccessories, blueAccessories, brownAccessories, grayAccessories, greenAccessories, richAccessories, backgrounds = loadAssets(
purchaseSize)

if arrayIndex == 0:
Expand All @@ -177,11 +221,15 @@ def customize_screen(noises, duckIndex, arrayIndex):
currentArray = greenAccessories
elif arrayIndex == 6:
currentArray = richAccessories
elif arrayIndex == 7:
currentArray = backgrounds
else:
currentArray = allSkins

#scale base skins for preview
previewSize = int(values.screenX * .28935)
if arrayIndex == 7:
previewSize = previewSize * 2 / 3

#TODO Purchase / Equip Skin

Expand All @@ -201,38 +249,90 @@ def customize_screen(noises, duckIndex, arrayIndex):
pygame.draw.rect(screen, values.COLOR_Pink,
(xArr1 + wArr + sep, yArr, box, hArr), 0)

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 section
# Check and see if the skin is owned
if arrayIndex == 0:
usedArray = normalSkins
elif arrayIndex == 1:
usedArray = baseSkins
elif arrayIndex == 2:
usedArray = blueSkins
elif arrayIndex == 3:
usedArray = brownSkins
elif arrayIndex == 4:
usedArray = graySkins
elif arrayIndex == 5:
usedArray = greenSkins
elif arrayIndex == 6:
usedArray = richSkins
elif arrayIndex == 7:
usedArray = bgs
else:
usedArray = normalSkins

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(
)[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)
else:
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))
else:
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))
# Skin is unowned, show purchase option
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)
else:
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))

# Rotated form of the left arrow (Should probably change to a different sprite later)
rightArr = pygame.transform.rotate(bigArr, 180)
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))

#TODO Preview of Duck in Current State
screen.blit(currentPreview,
(screen.get_width() / 3, screen.get_height() / 4))
if arrayIndex < 7:
screen.blit(currentPreview,
(screen.get_width() / 3, screen.get_height() / 4))
else:
screen.blit(currentPreview,
(screen.get_width() / 2.625, screen.get_height() / 3.5))
#will make these box objects for an array so we can move with arrows, know which ones have been purchased.
numboxes = 6
if arrayIndex != 7:
numboxes = 6
else:
numboxes = 3
for i in range(numboxes):
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))
if arrayIndex == 7:
# 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))
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))

#4 boxes to change screen to purchase base skins, hats, trails, and backgrounds
xCord = math.floor(screen.get_width() * .0289)
Expand Down Expand Up @@ -279,8 +379,8 @@ def customize_screen(noises, duckIndex, arrayIndex):
if pygame.mouse.get_pos()[0] > xCord and pygame.mouse.get_pos(
)[0] < xCord + width and pygame.mouse.get_pos()[1] > (
yCord +
(height + separation) * 3) and pygame.mouse.get_pos()[1] < (
yCord + height + (height + separation) * 3):
(height + separation) * 2) and pygame.mouse.get_pos()[1] < (
yCord + height + (height + separation) * 2):
Backgrounds_text_image = smallFont.render("Backgrounds", True,
values.COLOR_Yellow)
else:
Expand Down Expand Up @@ -334,6 +434,8 @@ def customize_screen(noises, duckIndex, arrayIndex):
)[1] < yCord + height + (height + separation) * 2:
noises.playSound("quack")
# Backgrounds box
startingArray = 7
startingDuck = 0
#TODO make text red or highlight box, then switch screen to customize different asset

#click on left arrow, move boxes to the left
Expand All @@ -343,7 +445,10 @@ def customize_screen(noises, duckIndex, arrayIndex):
noises.playSound("quack")
startingDuck -= 1
if startingDuck < 0:
startingDuck = len(allSkins) - 1
if arrayIndex < 7:
startingDuck = len(allSkins) - 1
else:
startingDuck = 2
# Make the duck the new duck
currentPreview = pygame.transform.scale(
currentArray[startingDuck], (previewSize, previewSize))
Expand All @@ -356,29 +461,43 @@ 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 arrayIndex == 0:
values.setSkin(normalSkins[startingDuck])
elif arrayIndex == 1:
values.setSkin(baseSkins[startingDuck])
elif arrayIndex == 2:
values.setSkin(blueSkins[startingDuck])
elif arrayIndex == 3:
values.setSkin(brownSkins[startingDuck])
elif arrayIndex == 4:
values.setSkin(graySkins[startingDuck])
elif arrayIndex == 5:
values.setSkin(greenSkins[startingDuck])
elif arrayIndex == 6:
values.setSkin(richSkins[startingDuck])
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])
else:
values.setSkin(usedArray[startingDuck])
else:
if coins_imported >= 100:
# Can purchase
if "background" in usedArray[startingDuck]:
# It is a background
customizationIO.backgrounds.append(usedArray[startingDuck])
customizationIO.current_background = startingDuck
else:
# It is a skin
customizationIO.skins.append(usedArray[startingDuck])
customizationIO.current_skin = arrayIndex
customizationIO.current_hat = startingDuck
coins_imported -= 100
customizationIO.coins = coins_imported
customizationIO.save_customization()
customizationIO.load_customization()
ownedSkins = customizationIO.skins
ownedBackgrounds = customizationIO.backgrounds

#click on right arrow, move boxes to the right
elif xArr1 + sep + wArr + box + sep < pygame.mouse.get_pos(
)[0] < xArr1 + sep + sep + wArr + box + wArr and yArr < pygame.mouse.get_pos(
)[1] < yArr + hArr:
noises.playSound("quack")
startingDuck += 1
if startingDuck > len(allSkins) - 1:
startingDuck = 0
if arrayIndex < 7:
if startingDuck > len(allSkins) - 1:
startingDuck = 0
else:
if startingDuck > 2:
startingDuck = 0
# Make the duck the new duck
currentPreview = pygame.transform.scale(
currentArray[startingDuck], (previewSize, previewSize))
Expand Down
Loading

0 comments on commit f08f5dd

Please sign in to comment.