Skip to content

Commit

Permalink
Added code and resources for Part 5
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmtracey committed Jun 12, 2015
1 parent 2c6ace5 commit c59e7eb
Show file tree
Hide file tree
Showing 40 changed files with 106 additions and 0 deletions.
Binary file added Part 5/Code/assets/images/Large/cat.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 Part 5/Code/assets/images/Large/chicken.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 Part 5/Code/assets/images/Large/cow.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 Part 5/Code/assets/images/Large/dog.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 Part 5/Code/assets/images/Large/horse.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 Part 5/Code/assets/images/Large/mouse.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 Part 5/Code/assets/images/Large/pig.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 Part 5/Code/assets/images/Large/rooster.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 Part 5/Code/assets/images/Large/sheep.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 Part 5/Code/assets/images/cat.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 Part 5/Code/assets/images/chicken.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 Part 5/Code/assets/images/cow.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 Part 5/Code/assets/images/dog.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 Part 5/Code/assets/images/horse.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 Part 5/Code/assets/images/mouse.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 Part 5/Code/assets/images/pig.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 Part 5/Code/assets/images/rooster.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 Part 5/Code/assets/images/sheep.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 Part 5/Code/assets/images/stop.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 Part 5/Code/assets/sounds/MP3/cat.mp3
Binary file not shown.
Binary file added Part 5/Code/assets/sounds/MP3/chicken.mp3
Binary file not shown.
Binary file added Part 5/Code/assets/sounds/MP3/cow.mp3
Binary file not shown.
Binary file added Part 5/Code/assets/sounds/MP3/dog.mp3
Binary file not shown.
Binary file added Part 5/Code/assets/sounds/MP3/farm.mp3
Binary file not shown.
Binary file added Part 5/Code/assets/sounds/MP3/horse.mp3
Binary file not shown.
Binary file added Part 5/Code/assets/sounds/MP3/mouse.mp3
Binary file not shown.
Binary file added Part 5/Code/assets/sounds/MP3/pig.mp3
Binary file not shown.
Binary file added Part 5/Code/assets/sounds/MP3/rooster.mp3
Binary file not shown.
Binary file added Part 5/Code/assets/sounds/MP3/sheep.mp3
Binary file not shown.
Binary file added Part 5/Code/assets/sounds/OGG/cat.ogg
Binary file not shown.
Binary file added Part 5/Code/assets/sounds/OGG/chicken.ogg
Binary file not shown.
Binary file added Part 5/Code/assets/sounds/OGG/cow.ogg
Binary file not shown.
Binary file added Part 5/Code/assets/sounds/OGG/dog.ogg
Binary file not shown.
Binary file added Part 5/Code/assets/sounds/OGG/farm.ogg
Binary file not shown.
Binary file added Part 5/Code/assets/sounds/OGG/horse.ogg
Binary file not shown.
Binary file added Part 5/Code/assets/sounds/OGG/mouse.ogg
Binary file not shown.
Binary file added Part 5/Code/assets/sounds/OGG/pig.ogg
Binary file not shown.
Binary file added Part 5/Code/assets/sounds/OGG/rooster.ogg
Binary file not shown.
Binary file added Part 5/Code/assets/sounds/OGG/sheep.ogg
Binary file not shown.
106 changes: 106 additions & 0 deletions Part 5/Code/sounds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import pygame, sys, random
import pygame.locals as GAME_GLOBALS
import pygame.event as GAME_EVENTS
import pygame.time as GAME_TIME

windowWidth = 600
windowHeight = 650

pygame.init()
surface = pygame.display.set_mode((windowWidth, windowHeight))
pygame.display.set_caption('Soundboard')

buttons = []
stopButton = { "image" : pygame.image.load("assets/images/stop.png"), "position" : (275, 585)}

mousePosition = None
volume = 1.0

pygame.mixer.init()
pygame.mixer.music.load('assets/sounds/OGG/farm.ogg')
pygame.mixer.music.play(-1)

def drawButtons():

for button in buttons:
surface.blit(button["image"], button["position"])

surface.blit(stopButton["image"], stopButton['position'])

def drawVolume():

pygame.draw.rect(surface, (229, 229, 229), (450, 610, 100, 5))

volumePosition = (100 / 100) * (volume * 100)

pygame.draw.rect(surface, (204, 204, 204), (450 + volumePosition, 600, 10, 25))

def handleClick():

global mousePosition, volume

for button in buttons:

buttonSize = button['image'].get_rect().size
buttonPosition = button['position']

if mousePosition[0] > buttonPosition[0] and mousePosition[0] < buttonPosition[0] + buttonSize[0]:

if mousePosition[1] > buttonPosition[1] and mousePosition[1] < buttonPosition[1] + buttonSize[1]:
button['sound'].set_volume(volume)
button['sound'].play()

if mousePosition[0] > stopButton['position'][0] and mousePosition[0] < stopButton['position'][0] + stopButton['image'].get_rect().size[0]:
if mousePosition[1] > stopButton['position'][1] and mousePosition[1] < stopButton['position'][1] + stopButton['image'].get_rect().size[1]:
pygame.mixer.stop()

def checkVolume():

global mousePosition, volume

if pygame.mouse.get_pressed()[0] == True:

if mousePosition[1] > 600 and mousePosition[1] < 625:
if mousePosition[0] > 450 and mousePosition[0] < 550:
volume = float((mousePosition[0] - 450)) / 100

def quitGame():
pygame.quit()
sys.exit()

# Create Buttons
buttons.append({ "image" : pygame.image.load("assets/images/sheep.png"), "position" : (25, 25), "sound" : pygame.mixer.Sound('assets/sounds/OGG/sheep.ogg')})
buttons.append({ "image" : pygame.image.load("assets/images/rooster.png"), "position" : (225, 25), "sound" : pygame.mixer.Sound('assets/sounds/OGG/rooster.ogg')})
buttons.append({ "image" : pygame.image.load("assets/images/pig.png"), "position" : (425, 25), "sound" : pygame.mixer.Sound('assets/sounds/OGG/pig.ogg')})
buttons.append({ "image" : pygame.image.load("assets/images/mouse.png"), "position" : (25, 225), "sound" : pygame.mixer.Sound('assets/sounds/OGG/mouse.ogg')})
buttons.append({ "image" : pygame.image.load("assets/images/horse.png"), "position" : (225, 225), "sound" : pygame.mixer.Sound('assets/sounds/OGG/horse.ogg')})
buttons.append({ "image" : pygame.image.load("assets/images/dog.png"), "position" : (425, 225), "sound" : pygame.mixer.Sound('assets/sounds/OGG/dog.ogg')})
buttons.append({ "image" : pygame.image.load("assets/images/cow.png"), "position" : (25, 425), "sound" : pygame.mixer.Sound('assets/sounds/OGG/cow.ogg')})
buttons.append({ "image" : pygame.image.load("assets/images/chicken.png"), "position" : (225, 425), "sound" : pygame.mixer.Sound('assets/sounds/OGG/chicken.ogg')})
buttons.append({ "image" : pygame.image.load("assets/images/cat.png"), "position" : (425, 425), "sound" : pygame.mixer.Sound('assets/sounds/OGG/cat.ogg')})

# 'main' loop
while True:

surface.fill((255,255,255))

mousePosition = pygame.mouse.get_pos()

for event in GAME_EVENTS.get():

if event.type == pygame.KEYDOWN:

if event.key == pygame.K_ESCAPE:
quitGame()

if event.type == GAME_GLOBALS.QUIT:
quitGame()

if event.type == pygame.MOUSEBUTTONUP:
handleClick()

drawButtons()
checkVolume()
drawVolume()

pygame.display.update()

0 comments on commit c59e7eb

Please sign in to comment.