diff --git a/index.html b/index.html index 6992ddd..e02a96c 100644 --- a/index.html +++ b/index.html @@ -1,6 +1,6 @@ - Turkey Banking Simulator + Turkey Baking Simulator



@@ -40,4 +40,5 @@ /* do something with mouseX/mouseY */ } + diff --git a/js/dialogue.js b/js/dialogue.js index 9d01ed6..57eb956 100644 --- a/js/dialogue.js +++ b/js/dialogue.js @@ -1,11 +1,130 @@ -function DialogueSequence(){ +function DialogueSequence( sequence ){ + + var targetStory = story[sequence].slice(0); return { next: function(){ - return story.shift().split(": ")[1]; + return targetStory.shift().split(": ")[1]; }, more: function(){ - return story.length > 0; + return targetStory.length > 0; } } +} + +function DialogUI( stage, gameState ){ + var that = this; + // Dialog States + var DIALOG_RECEDING = 0; + var DIALOG_SHOWING = 1; + var DIALOG_PAUSING = 2; + var MILLIS_PER_CHAR = 100; + + this.dialogSpeed = 30; + this.dialogState = DIALOG_PAUSING; + + this.dialogMotionQueue = [DIALOG_RECEDING]; + this.currDialogueSeq = new DialogueSequence("Null"); + dialogQueue = []; + + this.dialogBox = new createjs.Bitmap("res/DialogueBox.png"); + this.dialogBox.x = 10; + this.dialogBox.y = 675; + + this.textContent = new createjs.Text( "", "24px Arial", "#00000000" ); + this.textContent.x = 205; + this.textContent.y = 705; + this.textContent.lineWidth = 565; + this.textContent.lineHeight = 30; + this.textContent.textBaseline = "alphabetic"; + + this.dialogBox.addEventListener( "mouseover", function(){ document.body.style.cursor='pointer'; } ); + this.dialogBox.addEventListener( "mouseout", function(){ document.body.style.cursor='default'; } ); + this.dialogBox.addEventListener( "click", function(){ setTimeout( clickEvent, 100); }); + + this.textContent.addEventListener( "mouseover", function(){ document.body.style.cursor='pointer'; } ); + this.textContent.addEventListener( "mouseout", function(){ document.body.style.cursor='default'; } ); + this.textContent.addEventListener( "click", function(){ setTimeout( clickEvent, 100); }); + + this.showDialog= function( textSeq ){ + that.currDialogueSeq = new DialogueSequence( textSeq.seq ); + that.textContent.text=that.currDialogueSeq.next(); + that.autoAdvance = textSeq.autoAdvance; + that.dialogMotionQueue = [DIALOG_SHOWING]; + } + + gameState.pubsub.subscribe( "ShowDialog", this.showDialog ); + + // negate double setTimeout if clicked + var oldTime = new Date().getTime(); + var delayCounter = 0; + var clickEvent = function( timer ){ + + // if there is more dialogue text, then keep going, otherwise, recede + if( that.currDialogueSeq.more() ){ + setTimeout( function(){ that.dialogMotionQueue.push(DIALOG_SHOWING) }, 500); + that.textContent.text=that.currDialogueSeq.next(); + delayCounter = 0; + oldTime = new Date().getTime() + }else{ + // pause and close dialog + setTimeout( function(){that.dialogMotionQueue.push(DIALOG_RECEDING)}, 500 ); + } + } + + stage.addChild( this.dialogBox ); + stage.addChild( this.textContent ); + + return { + tick: function(){ + delayCounter = new Date().getTime() - oldTime; + + if( that.autoAdvance == true && that.dialogBox.y ==435 && delayCounter > ( that.textContent.text.length * MILLIS_PER_CHAR ) ){ + clickEvent(); + } + + if( that.dialogState == DIALOG_RECEDING ){ + that.dialogBox.y+=that.dialogSpeed; + that.textContent.y +=that.dialogSpeed; + console.log( "Receding" + that.dialogBox.y ); + } + if( that.dialogState == DIALOG_SHOWING ){ + that.dialogBox.y-=that.dialogSpeed; + that.textContent.y -=that.dialogSpeed; + console.log( "Advancing" + that.dialogBox.y ); + } + + // toggle states + if( that.dialogBox.y > 675 && that.dialogState == DIALOG_RECEDING ){ + that.dialogBox.y = 675; + that.textContent.y = 735; + that.dialogState = DIALOG_PAUSING; + console.log( "Pausing on recede" + that.dialogBox.y ); + + } + if( that.dialogBox.y < 435 && that.dialogState == DIALOG_SHOWING ){ + that.dialogBox.y = 435; + that.textContent.y = 480; + that.dialogState = DIALOG_PAUSING; + console.log( "Pausing on showing" + that.dialogBox.y ); + } + + /* next states if there are any on the queue */ + if( that.dialogMotionQueue.length > 0 && that.dialogState == DIALOG_PAUSING ){ + that.dialogState = that.dialogMotionQueue.shift(); + } + }, + + minDialog: function(){ + that.dialogMotionQueue.push( DIALOG_RECEDING ); + }, + + maxDialog: function(){ + that.dialogMotionQueue.push( DIALOG_SHOWING ); + }, + render: function(){ + stage.addChild( that.dialogBox ); + stage.addChild( that.textContent ); + } + } } \ No newline at end of file diff --git a/js/main.js b/js/main.js index 6d5b055..418b11f 100644 --- a/js/main.js +++ b/js/main.js @@ -6,13 +6,19 @@ function GameState(){ this.currentTime = new Date().getTime(); this.oldTime = new Date().getTime(); + this.name = ""; + this.gender = ""; + this.wallet = 1000; + // Load all our resources: var queue = new createjs.LoadQueue(true); queue.installPlugin(createjs.Sound); + //queue.addEventListener("fileload", handleFileComplete); queue.loadFile( {id: "TitleMusicFile", src:"res/sound/turkey_in_the_straw.mp3"} ); queue.loadFile( {id: "MarketBackgroundSoundFile", src:"res/sound/supermarket.mp3"} ); queue.loadFile( {id: "MarketBackgroundSoundFile", src:"res/items/FrillsBox.png"} ); + queue.loadFile( {id: "TurkeySpriteFile", src:"res/TurkeySprite.png"} ); this.screenState = 0; this.newScreen = ""; @@ -21,15 +27,15 @@ function GameState(){ // Game State flags this.turkeyBought = false; this.marketItems = { - "FrillsBox" : new MarketItem( this, "FrillsBox", 133,92, 100, "res/items/FrillsBox.png", "res/items/FrillsBoxGlow.png" ), + "FrillsBox" : new MarketItem( this, "FrillsBox", 133,92, 2000, "res/items/FrillsBox.png", "res/items/FrillsBoxGlow.png" ), "TuTempProberkey" : new MarketItem( this, "TuTempProberkey", 200, 57, 100, "res/items/TempProbe.png", "res/items/TempProbeGlow.png" ), - "OvenLightBox" : new MarketItem( this, "OvenLightBox", 131,222, 100, "res/items/OvenLightBox.png", "res/items/OvenLightBoxGlow.png" ), + "OvenLightBox" : new MarketItem( this, "OvenLightBox", 131,222, 300, "res/items/OvenLightBox.png", "res/items/OvenLightBoxGlow.png" ), - "Alarm" : new MarketItem( this, "Alarm", 173,248, 100, "res/items/Alarm.png", "res/items/AlarmGlow.png" ), - "Cookbook" : new MarketItem( this, "Cookbook", 283,203, 100, "res/items/Cookbook1.png", "res/items/Cookbook1Glow.png" ), - "StuffingRepurposed" : new MarketItem( this, "StuffingRepurposed", 510,197, 100, "res/items/StuffingRepurposed.png", "res/items/StuffingRepurposedGlow.png" ), - "StuffingExquisite" : new MarketItem( this, "StuffingExquisite", 458,210, 100, "res/items/StuffingExquisite.png", "res/items/StuffingExquisiteGlow.png" ), - "StuffingSpecial" : new MarketItem( this, "StuffingSpecial", 390,220, 100, "res/items/StuffingSpecial.png", "res/items/StuffingSpecialGlow.png" ), + "Alarm" : new MarketItem( this, "Alarm", 173,248, 500, "res/items/Alarm.png", "res/items/AlarmGlow.png" ), + "Cookbook" : new MarketItem( this, "Cookbook", 283,203, 400, "res/items/Cookbook1.png", "res/items/Cookbook1Glow.png" ), + "StuffingRepurposed" : new MarketItem( this, "StuffingRepurposed", 510,197, 200, "res/items/StuffingRepurposed.png", "res/items/StuffingRepurposedGlow.png" ), + "StuffingExquisite" : new MarketItem( this, "StuffingExquisite", 458,210, 300, "res/items/StuffingExquisite.png", "res/items/StuffingExquisiteGlow.png" ), + "StuffingSpecial" : new MarketItem( this, "StuffingSpecial", 390,220, 500, "res/items/StuffingSpecial.png", "res/items/StuffingSpecialGlow.png" ), "Turkey1" : new MarketItem( this, "Turkey1", 170,350, 100, "res/items/Turkey5.png", "res/items/Turkey5Glow.png" ), "Turkey2": new MarketItem( this, "Turkey2", 540,320, 100, "res/items/Turkey4.png", "res/items/Turkey4Glow.png" ), @@ -39,13 +45,30 @@ function GameState(){ }; this.purchasedItems = []; - + // did we already show the player the kitchen intro? this.kitchenIntro = false; this.mainUI = new GameUI( "demoCanvas", this ); createjs.Ticker.addEventListener( "tick", gameLoop ); + function addHighScore(name, turkeyPoundage, cookTime, score){ + var scores = {}; + var now = new Date(); + if( !localStorage.getItem("highScores") ){ + scores = JSON.parse( localStorage.getItem("highScores") ); + } + + scores[now.getYear()+"/"+now.getMonth()+"/"+now.getDay()] = { + "name" : name, + "weight" : turkeyPoundage, + "cookTime" : cookTime, + "score" : score + }; + + localStorage.setItem("highScores", JSON.stringfy(scores)); + } + function gameLoop(){ that.mainUI.draw(); } @@ -104,7 +127,9 @@ function GameUI( canvasElem, gameState ){ "CreditsScreen" : CreditsScreen } - this.activeScreenObj = new MarketScreen( this.stage, gameState ); + var soundManager = new SoundManager( gameState ); + + this.activeScreenObj = new MainScreen( this.stage, gameState ); var textContent = new createjs.Text( "", "20px Arial", "#00000000" ); textContent.x = 750; textContent.y = 30; @@ -114,12 +139,12 @@ function GameUI( canvasElem, gameState ){ overlay.alpha = 0; this.stage.addChild(overlay); - var soundManager = new SoundManager( gameState ); + var dialogManager = new DialogUI( this.stage, gameState ); // delay for fade in and fade-out this.switchScreen = function( screenName ){ gameState.screenState = SCREEN_OUT; - gameState.pubsub.publish( "FadeOut", "" ); + dialogManager.minDialog(); console.log("Switch screen called with" + screenName); gameState.newScreen = screenName; }; @@ -128,6 +153,7 @@ function GameUI( canvasElem, gameState ){ that.activeScreenObj = new that.screens[ screenName ]( that.stage, gameState ); that.stage.addChild( textContent ); that.stage.addChild( overlay ); + dialogManager.render(); }; gameState.pubsub.subscribe( "SwitchScreen", this.switchScreen ); @@ -159,114 +185,14 @@ function GameUI( canvasElem, gameState ){ } soundManager.tick(); that.activeScreenObj.blit(); + dialogManager.tick(); textContent.text = createjs.Ticker.getMeasuredFPS().toFixed(1); that.stage.update(); } } } -function DialogUI( stage ){ - var that = this; - // Dialog States - var DIALOG_RECEDING = 0; - var DIALOG_SHOWING = 1; - var DIALOG_PAUSING = 2; - var MILLIS_PER_CHAR = 100; - - this.dialogSpeed = 30; - this.dialogState = DIALOG_PAUSING; - - this.dialogMotionQueue = [DIALOG_SHOWING]; - this.currDialogueSeq = new DialogueSequence(); - dialogQueue = []; - - this.dialogBox = new createjs.Bitmap("res/DialogueBox.png"); - this.dialogBox.x = 10; - this.dialogBox.y = 675; - - this.textContent = new createjs.Text( "Hey there kids!", "24px Arial", "#00000000" ); - this.textContent.x = 205; - this.textContent.y = 705; - this.textContent.lineWidth = 565; - this.textContent.lineHeight = 30; - this.textContent.textBaseline = "alphabetic"; - - this.dialogBox.addEventListener( "mouseover", function(){ document.body.style.cursor='pointer'; } ); - this.dialogBox.addEventListener( "mouseout", function(){ document.body.style.cursor='default'; } ); - this.dialogBox.addEventListener( "click", function(){ setTimeout( clickEvent, 100); }); - - this.textContent.addEventListener( "mouseover", function(){ document.body.style.cursor='pointer'; } ); - this.textContent.addEventListener( "mouseout", function(){ document.body.style.cursor='default'; } ); - this.textContent.addEventListener( "click", function(){ setTimeout( clickEvent, 100); }); - - - // negate double setTimeout if clicked - var oldTime = new Date().getTime(); - var delayCounter = 0; - var clickEvent = function( timer ){ - - // if there is more dialogue text, then keep going, otherwise, recede - if( that.currDialogueSeq.more() ){ - setTimeout( function(){ that.dialogMotionQueue.push(DIALOG_SHOWING) }, 1000); - that.textContent.text=that.currDialogueSeq.next(); - delayCounter = 0; - oldTime = new Date().getTime() - }else{ - // pause and close dialog - setTimeout( function(){that.dialogMotionQueue.push(DIALOG_RECEDING)}, 1000 ); - } - } - stage.addChild( this.dialogBox ); - stage.addChild( this.textContent ); - - return { - tick: function(){ - delayCounter = new Date().getTime() - oldTime; - - if(that.dialogBox.y ==435 && delayCounter > ( that.textContent.text.length * MILLIS_PER_CHAR ) ){ - clickEvent(); - } - if( that.dialogState == DIALOG_RECEDING ){ - that.dialogBox.y+=that.dialogSpeed; - that.textContent.y +=that.dialogSpeed; - console.log( "Receding" + that.dialogBox.y ); - } - if( that.dialogState == DIALOG_SHOWING ){ - that.dialogBox.y-=that.dialogSpeed; - that.textContent.y -=that.dialogSpeed; - console.log( "Advancing" + that.dialogBox.y ); - } - - // toggle states - if( that.dialogBox.y > 675 && that.dialogState == DIALOG_RECEDING ){ - that.dialogBox.y = 675; - that.textContent.y = 705; - that.dialogState = DIALOG_PAUSING; - console.log( "Pausing on recede" + that.dialogBox.y ); - - } - if( that.dialogBox.y < 435 && that.dialogState == DIALOG_SHOWING ){ - that.dialogBox.y = 435; - that.textContent.y = 480; - that.dialogState = DIALOG_PAUSING; - console.log( "Pausing on showing" + that.dialogBox.y ); - } - - /* next states if there are any on the queue */ - if( that.dialogMotionQueue.length > 0 && that.dialogState == DIALOG_PAUSING ){ - that.dialogState = that.dialogMotionQueue.shift(); - } - }, - - minDialog: function(){ - that.dialogMotionQueue.push( DIALOG_RECEDING ); - }, - - maxDialog: function(){ - that.dialogMotionQueue.push( DIALOG_SHOWING ); - }, - } -} + function Dialogue( character, text ){ var that = this; diff --git a/js/model.js b/js/model.js index e329b32..4d1ea7c 100644 --- a/js/model.js +++ b/js/model.js @@ -218,6 +218,9 @@ UtilityFunctions = { }, lbs2kgs: function(){ return pounds * 0.453592 + }, + randRange: function(lowVal,highVal) { + return Math.floor(Math.random()*(highVal-lowVal+1))+lowVal; } } diff --git a/js/screens.js b/js/screens.js index 4e1deb0..ecc60c3 100644 --- a/js/screens.js +++ b/js/screens.js @@ -4,13 +4,12 @@ function LoadingTitleScreen( stage, gameState ){ this.picture = new createjs.Bitmap( "res/Loading-Title.png" ); this.ovenLight = new createjs.Shape(); this.ovenLight.graphics.beginFill( "red" ).drawCircle( 396, 318, 5 ); - this.ovenLight.addEventListener( "click", function(){alert("hello world")}); stage.addChild( this.picture ); stage.addChild( this.ovenLight ); this.uiElems = []; - this.uiElems.push( new DialogUI( stage ) ); + this.uiElems.push( new DialogUI( stage, gameState ) ); return { blit : function(){ @@ -45,19 +44,49 @@ function InfoHelpScreen( stage, gameState ){ function MainScreen( stage, gameState ){ var that = this; - this.background = new createjs.Bitmap( "res/Main.png" ); + this.background = new createjs.Bitmap( "res/Main-Screen.png" ); stage.addChild( this.background ); + var turkeyAnimations = { peck:[14,24,"peck"], ruffle:[0,13,"ruffle"], stare:[25,35,"stare"] }; + var data = { + images: ["res/TurkeySprite.png"], + frames: { width:400, height:350 }, + animations: turkeyAnimations + }; + + var spriteSheet = new createjs.SpriteSheet(data); + var animation = new createjs.Sprite(spriteSheet, "stare"); + animation.x = 200; + animation.y = 210; + + animation.addEventListener("tick", handleTick); + function handleTick(event) { + if ( turkeyAnimations[event.currentTarget.currentAnimation][1] == event.currentTarget.currentFrame ){ + event.currentTarget.paused = true; + } + // Click happened. + } + stage.addChild(animation); + + this.grassLayer = new createjs.Bitmap( "res/Grass.png" ); + stage.addChild( this.grassLayer ); + // buttons info/credits/start - stage.addChild( new Button( stage, gameState, 13, 445, 222, 65, "SwitchScreen", "InfoHelpScreen" ) ); - stage.addChild( new Button( stage, gameState, 13, 515, 222, 65, "SwitchScreen", "CreditsScreen" ) ); - stage.addChild( new Button( stage, gameState, 564, 520, 222, 65, "SwitchScreen", "DifficultyScreen" ) ); + new ImgButton( stage, gameState, 571,527, "res/MainScreen/ButtonStart.png", "res/MainScreen/ButtonStart.png","SwitchScreen", "DifficultyScreen", "Click" ); + new ImgButton( stage, gameState, 17,470, "res/MainScreen/ButtonHelp.png", "res/MainScreen/ButtonHelp.png","SwitchScreen", "InfoScreen", "Click" ); + new ImgButton( stage, gameState, 17,527, "res/MainScreen/ButtonCredits.png", "res/MainScreen/ButtonCredits.png","SwitchScreen", "CreditsScreen", "Click" ); + gameState.pubsub.publish( "BackgroundLoop", {name:"TitleMusic", pos:5650, volume:1} ); this.uiElems = []; return { blit : function(){ + // Randomly do stuff + + if( createjs.Ticker.getTicks() %50 == 0 ){ + animation.gotoAndPlay(["peck", "ruffle", "stare"][UtilityFunctions.randRange(0,2)]); + } // Draw all the uiElements for( var index in that.uiElems ){ that.uiElems[ index ].tick(); @@ -92,22 +121,29 @@ function DifficultyScreen( stage, gameState ){ function KitchenScreen( stage, gameState ){ var that = this; + + // Fade out any other sounds + gameState.pubsub.publish( "FadeOut", "" ); + this.background = new createjs.Bitmap( "res/kitchen.png" ); stage.addChild( this.background ); this.uiElems = []; - - for(var i in gameState.purchasedItems){ + for(var i in gameState.purchasedItems ){ console.log(gameState.purchasedItems); gameState.purchasedItems[i].draw( stage, 403+100*i, 350 ); } - this.uiElems.push( new OvenUI( stage, gameState ) ); + this.uiElems.push( gameState.ovenUI ? gameState.ovenUI : ( gameState.ovenUI = new OvenUI( stage, gameState ) ) ); this.uiElems.push( new ClockUI( stage, gameState ) ); this.uiElems.push( new WindowUI( stage, gameState ) ) - this.uiElems.push( new DialogUI( stage ) ); + stage.addChild( new Button( stage, gameState, 500, 40, 450, 105, "SwitchScreen", "MarketScreen" ) ); + // If player did not buy a turkey, tell them + if( !gameState.turkeyBought ){ + gameState.pubsub.publish( "ShowDialog", {seq:"KitchenInitial", autoAdvance:false} ); + } return { blit : function(){ @@ -123,16 +159,45 @@ function KitchenScreen( stage, gameState ){ function MarketScreen( stage, gameState ){ var that = this; - this.background = new createjs.Bitmap( "res/Store-Screen-Clean.png" ); + this.background = new createjs.Bitmap( "res/screens/MarketScreen.png" ); + var price = new createjs.Text( "100", "24px Arial", "#00000000" ); + price.x = 725; + price.y = 500; + + var wallet = new createjs.Text( gameState.wallet, "24px Arial", "#00000000" ); + wallet.x = 725; + wallet.y = 550; + + // Play soundz + gameState.pubsub.publish( "Play", {name:"Entrance", volume:0.3} ); + gameState.pubsub.publish( "BackgroundLoop", {name:"MarketMusic", volume:1} ); + gameState.pubsub.publish( "BackgroundLoop", {name:"MarketSound", volume:0.4} ); + stage.addChild( this.background ); + stage.addChild(price); + stage.addChild(wallet); + this.uiElems = []; - this.uiElems.push( new ImgButton( stage, gameState, 690,0, "res/items/ExitSign.png", "res/items/ExitGlow.png","SwitchScreen", "KitchenScreen" ) ); + this.uiElems.push( new ImgButton( stage, gameState, 690,0, "res/items/ExitSign.png", "res/items/ExitGlow.png","SwitchScreen", "KitchenScreen", "Click" ) ); var marketItemKeys = Object.keys(gameState.marketItems); for (var index in marketItemKeys ) { gameState.marketItems[marketItemKeys[index]].draw( stage ); } - this.topground = new createjs.Bitmap( "res/TopShelf.png" ); + this.topground = new createjs.Bitmap( "res/screens/MarketTopShelf.png" ); stage.addChild( this.topground ); + + + this.showPrice = function( cost ){ + price.text = cost; + } + gameState.pubsub.subscribe( "ShowPrice", this.showPrice ); + this.setWalletAmount = function(newAmount){ + wallet.text=gameState.wallet=newAmount; + + } + + gameState.pubsub.subscribe("WalletAmount", this.setWalletAmount); + return { blit : function(){ diff --git a/js/soundmanager.js b/js/soundmanager.js new file mode 100644 index 0000000..170774d --- /dev/null +++ b/js/soundmanager.js @@ -0,0 +1,101 @@ +function SoundInstance( soundObj, loop ){ + this.soundObj = soundObj; +} +function SoundManager( gameState ){ + var that = this; + var soundCache = []; + + var AUDIO_OUT = 1; + var AUDIO_IN = 2; + var AUDIO_STABLE = 0; + + this.audioState = AUDIO_STABLE; + + // Register all sounds loaded in gameState + createjs.Sound.registerSound("res/sound/turkey_in_the_straw.mp3", "TitleMusic"); + createjs.Sound.registerSound("res/sound/supermarket.mp3", "MarketBackgroundSound"); + createjs.Sound.registerSound("res/sound/Music/Waterford.mp3", "MarketMusic"); + createjs.Sound.registerSound("res/sound/GUI/pop.mp3", "Pop"); + createjs.Sound.registerSound("res/sound/GUI/lowclick.mp3", "LowClick"); + createjs.Sound.registerSound("res/sound/GUI/click.mp3", "Click"); + createjs.Sound.registerSound("res/sound/GUI/buzz.mp3", "Error"); + createjs.Sound.registerSound("res/sound/Store/buy.mp3", "Buy"); + createjs.Sound.registerSound("res/sound/Store/entrance.mp3", "Entrance"); + createjs.Sound.registerSound("res/sound/Store/backgroundSound.mp3", "MarketSound"); + + + this.backgroundSounds = []; + this.backgroundSoundsQueue = []; + this.fadeOut = function(){ + for ( var i in that.backgroundSounds ){ + that.backgroundSounds[i].audioState = AUDIO_OUT; + } + }; + this.play = function( soundName ){ + var channel = createjs.Sound.createInstance("Pop"); + if( typeof soundName != "object" ){ + channel = soundCache[soundName] ? soundCache[soundName] : soundCache[soundName] = createjs.Sound.createInstance(soundName); + } + else{ + channel = soundCache[soundName.name] ? soundCache[soundName.name] : soundCache[soundName.name] = createjs.Sound.createInstance(soundName.name); + channel.volume = soundName.volume; + } + channel.play(); + }; + + this.backgroundLoop = function( soundName ){ + var newBackgroundSound; + if( typeof soundName != "object" ){ + newBackgroundSound = soundCache[soundName] ? soundCache[soundName] : soundCache[soundName] = createjs.Sound.createInstance(soundName); + } + else{ + newBackgroundSound = soundCache[soundName.name] ? soundCache[soundName.name] : soundCache[soundName.name] = createjs.Sound.createInstance( soundName.name ); + newBackgroundSound.setPosition(soundName.pos || 0); + newBackgroundSound.volume = soundName.volume || 1; + newBackgroundSound.play(); + + // loop-de-loop + newBackgroundSound.addEventListener("complete", function(){ + if( newBackgroundSound.volume == 0 ){ newBackgroundSound.stop(); return; } + newBackgroundSound.setPosition(soundName.pos || 0); + newBackgroundSound.volume = soundName.volume || 1; + newBackgroundSound.play(); + }); + } + that.backgroundSoundsQueue.push(newBackgroundSound); + }; + + gameState.pubsub.subscribe( "Play", this.play ); + gameState.pubsub.subscribe( "BackgroundLoop", this.backgroundLoop ); + gameState.pubsub.subscribe( "FadeOut", this.fadeOut ); + + return { + tick: function(){ + for ( var i in that.backgroundSounds ){ + if( that.backgroundSounds[i].audioState == AUDIO_OUT ){ + that.backgroundSounds[i].volume -=0.03; + } + if( that.backgroundSounds[i].audioState == AUDIO_IN ){ + that.backgroundSounds[i].volume +=0.03; + } + if( that.backgroundSounds[i].volume >= 1.0 ){ + that.backgroundSounds[i].volume = 1; + } + if( that.backgroundSounds[i].volume <= 0.0 ){ + that.backgroundSounds[i].volume = 0; + that.backgroundSounds[i].stop(); + that.backgroundSounds.splice( i, 1 ); + } + } + if( that.backgroundSounds.length == 0 ){ + for ( var i in that.backgroundSoundsQueue ){ + var newSound = that.backgroundSoundsQueue[i]; + newSound.audioState = AUDIO_IN; + that.backgroundSounds.push( newSound ); + } + that.backgroundSoundsQueue = []; + } + } + } + +} \ No newline at end of file diff --git a/js/stories.js b/js/stories.js index 64efc75..b8dae59 100644 --- a/js/stories.js +++ b/js/stories.js @@ -1,4 +1,10 @@ -var story = ["Brother: Hey Grandpa, I've got a funny story about that primer you gave me", +var story = { + "Null":["Me: "], + "KitchenInitial" : ["Me: I need to buy a turkey..."], + "CannotBuyTurkey" : ["Me: I've barely have time for ONE turkey, let alone TWO!"], + "NoMoney" : ["Me: I can't afford this!"], + "BuyTurkeyFirst" : ["Me: You should buy a turkey first!"], + "PaintStory" : ["Brother: Hey Grandpa, I've got a funny story about that primer you gave me", "Grandpa: You'll have to remind me, again, my memory isn't too good in my old age", "Brother: Well, you gave me some primer to redo my room.", "Mom: How is that going? Last I heard you had the priming done", @@ -9,4 +15,5 @@ var story = ["Brother: Hey Grandpa, I've got a funny story about that primer you "Brother: Well yes, but I was also cutting the edges, like you taught me. And that was easier with the paint bucket in my hand. Or so I thought...", "Brother: Right. Well, umm so I quickly put the paint can down in the roller pan, seee, that I had nearby, and as I turned around to go clean myself off with some paper towels, I noticed a drip line all the way from the garage.", "Brother: That's not good. So I dashed for the towels, and tried to soak up as much as possible. And well.. yeah So, in the future, I probably won't go for your primer Grandpa.", -"Grandpa: ..."]; \ No newline at end of file +"Grandpa: ..."] +}; \ No newline at end of file diff --git a/js/ui.js b/js/ui.js index 39fb416..8f2db8f 100644 --- a/js/ui.js +++ b/js/ui.js @@ -143,24 +143,41 @@ function MarketItem( gameState, name, x, y, cost, mouseOutImg, mouseOverImg ){ var mouseOut = new createjs.Bitmap( mouseOutImg ); mouseOver.x = mouseOut.x = x; mouseOver.y = mouseOut.y = y; - mouseOut.addEventListener( "mouseover", function(){ document.body.style.cursor='pointer'; mouseOver.visible = true; mouseOut.visible = false; } ); - mouseOut.addEventListener( "mouseout", function(){ document.body.style.cursor='default'; mouseOver.visible = false; mouseOut.visible = true; } ); - mouseOver.addEventListener( "mouseover", function(){ document.body.style.cursor='pointer'; mouseOver.visible = true; mouseOut.visible = false; } ); - mouseOver.addEventListener( "mouseout", function(){ document.body.style.cursor='default'; mouseOver.visible = false; mouseOut.visible = true; } ); + mouseOut.addEventListener( "mouseover", function(){ document.body.style.cursor='pointer'; mouseOver.visible = true; mouseOut.visible = false; gameState.pubsub.publish("ShowPrice", cost ); } ); + mouseOut.addEventListener( "mouseout", function(){ document.body.style.cursor='default'; mouseOver.visible = false; mouseOut.visible = true; gameState.pubsub.publish("ShowPrice", "" ); } ); + mouseOver.addEventListener( "mouseover", function(){ document.body.style.cursor='pointer'; mouseOver.visible = true; mouseOut.visible = false; gameState.pubsub.publish("ShowPrice", cost ); } ); + mouseOver.addEventListener( "mouseout", function(){ document.body.style.cursor='default'; mouseOver.visible = false; mouseOut.visible = true; gameState.pubsub.publish("ShowPrice", "" );} ); mouseOver.addEventListener( "click", function(){ - if(!that.bought){ + if(!that.bought && cost <= gameState.wallet ){ if( that.name.indexOf("Turkey") == 0 && gameState.turkeyBought != true){ gameState.turkeyBought = true; gameState.marketItems[ that.name ].delete(); + gameState.pubsub.publish("Play", {name:"Buy", volume:0.7} ); + gameState.pubsub.publish("WalletAmount", gameState.wallet - Math.abs(cost)) } - // can we buy this? Only possible if you already bought a turkey - if( !that.name.indexOf("Turkey") == 0 && gameState.turkeyBought == true ){ + else if( !that.name.indexOf("Turkey") == 0 && gameState.turkeyBought == true ){ gameState.purchasedItems.push( objReturn ); gameState.marketItems[ that.name ].delete(); that.bought = true; + gameState.pubsub.publish("Play", {name:"Buy", volume:0.7}); + gameState.pubsub.publish("WalletAmount", gameState.wallet - Math.abs(cost)); + } + // One turkey only + else if( that.name.indexOf("Turkey") == 0 && gameState.turkeyBought == true ){ + gameState.pubsub.publish( "ShowDialog", {seq:"CannotBuyTurkey", autoAdvance:false} ); + gameState.pubsub.publish( "Play", "Error" ); + } + // Buy turkey first + else{ + gameState.pubsub.publish( "ShowDialog", {seq:"BuyTurkeyFirst", autoAdvance:false} ); + gameState.pubsub.publish( "Play", "Error" ); } } + else{ + gameState.pubsub.publish( "ShowDialog", {seq:"NoMoney", autoAdvance:false} ); + gameState.pubsub.publish( "Play", "Error" ); + } }); mouseOver.visible = false; @@ -184,7 +201,7 @@ function MarketItem( gameState, name, x, y, cost, mouseOutImg, mouseOverImg ){ -function ImgButton( stage, gameState, x, y, mouseOutImg, mouseOverImg, eventCmd, arg ){ +function ImgButton( stage, gameState, x, y, mouseOutImg, mouseOverImg, eventCmd, arg, sound ){ var mouseOver = new createjs.Bitmap( mouseOverImg ); var mouseOut = new createjs.Bitmap( mouseOutImg ); mouseOver.x = mouseOut.x = x; @@ -193,7 +210,12 @@ function ImgButton( stage, gameState, x, y, mouseOutImg, mouseOverImg, eventCmd, mouseOut.addEventListener( "mouseout", function(){ document.body.style.cursor='default'; mouseOver.visible = false; mouseOut.visible = true; } ); mouseOver.addEventListener( "mouseover", function(){ document.body.style.cursor='pointer'; mouseOver.visible = true; mouseOut.visible = false; } ); mouseOver.addEventListener( "mouseout", function(){ document.body.style.cursor='default'; mouseOver.visible = false; mouseOut.visible = true; } ); - mouseOver.addEventListener( "click", function(){ gameState.pubsub.publish( eventCmd, arg ) } ); + mouseOver.addEventListener( "click", function(){ + if( sound ){ + gameState.pubsub.publish("Play", sound ); + } + gameState.pubsub.publish( eventCmd, arg ) + } ); mouseOver.visible = false; stage.addChild( mouseOut ); stage.addChild( mouseOver ); @@ -212,7 +234,7 @@ function Button( stage, gameState, x_orig, y_orig, x_dest, y_dest, eventCmd, arg button.addEventListener( "click", function(){ gameState.pubsub.publish( eventCmd, arg ) } ); button.addEventListener( "mouseover", function(){ document.body.style.cursor='pointer'; } ); button.addEventListener( "mouseout", function(){ document.body.style.cursor='default'; } ); - + gameState.pubsub.publish( "Play", "Click" ); return button; } \ No newline at end of file diff --git a/res/Grass.png b/res/Grass.png new file mode 100644 index 0000000..a49a718 Binary files /dev/null and b/res/Grass.png differ diff --git a/res/Loading/.DS_Store b/res/Loading/.DS_Store new file mode 100644 index 0000000..836537d Binary files /dev/null and b/res/Loading/.DS_Store differ diff --git a/res/Loading/Loading-Title-Mockup.png b/res/Loading/Loading-Title-Mockup.png new file mode 100644 index 0000000..6fb1346 Binary files /dev/null and b/res/Loading/Loading-Title-Mockup.png differ diff --git a/res/Loading/Loading-Title.png b/res/Loading/Loading-Title.png new file mode 100644 index 0000000..4a29c5c Binary files /dev/null and b/res/Loading/Loading-Title.png differ diff --git a/res/Loading/PanFront.png b/res/Loading/PanFront.png new file mode 100644 index 0000000..c417b98 Binary files /dev/null and b/res/Loading/PanFront.png differ diff --git a/res/Loading/TextCooking.png b/res/Loading/TextCooking.png new file mode 100644 index 0000000..04f1bf1 Binary files /dev/null and b/res/Loading/TextCooking.png differ diff --git a/res/Loading/TextDone.png b/res/Loading/TextDone.png new file mode 100644 index 0000000..b09feb7 Binary files /dev/null and b/res/Loading/TextDone.png differ diff --git a/res/Loading/Turkey0.png b/res/Loading/Turkey0.png new file mode 100644 index 0000000..0034373 Binary files /dev/null and b/res/Loading/Turkey0.png differ diff --git a/res/Loading/Turkey25.png b/res/Loading/Turkey25.png new file mode 100644 index 0000000..31afea2 Binary files /dev/null and b/res/Loading/Turkey25.png differ diff --git a/res/Loading/Turkey50.png b/res/Loading/Turkey50.png new file mode 100644 index 0000000..e266b72 Binary files /dev/null and b/res/Loading/Turkey50.png differ diff --git a/res/Loading/Turkey75.png b/res/Loading/Turkey75.png new file mode 100644 index 0000000..77cfd76 Binary files /dev/null and b/res/Loading/Turkey75.png differ diff --git a/res/Loading/TurkeyDone.png b/res/Loading/TurkeyDone.png new file mode 100644 index 0000000..8935783 Binary files /dev/null and b/res/Loading/TurkeyDone.png differ diff --git a/res/Main-Screen.png b/res/Main-Screen.png new file mode 100644 index 0000000..dac54b9 Binary files /dev/null and b/res/Main-Screen.png differ diff --git a/res/Main.png b/res/Main.png deleted file mode 100644 index 72215e5..0000000 Binary files a/res/Main.png and /dev/null differ diff --git a/res/MainScreen/.DS_Store b/res/MainScreen/.DS_Store new file mode 100644 index 0000000..d6adeb8 Binary files /dev/null and b/res/MainScreen/.DS_Store differ diff --git a/res/MainScreen/ButtonCredits.png b/res/MainScreen/ButtonCredits.png new file mode 100644 index 0000000..6b6a7ef Binary files /dev/null and b/res/MainScreen/ButtonCredits.png differ diff --git a/res/MainScreen/ButtonHelp.png b/res/MainScreen/ButtonHelp.png new file mode 100644 index 0000000..d6ab1b5 Binary files /dev/null and b/res/MainScreen/ButtonHelp.png differ diff --git a/res/MainScreen/ButtonStart.png b/res/MainScreen/ButtonStart.png new file mode 100644 index 0000000..f1eb3dd Binary files /dev/null and b/res/MainScreen/ButtonStart.png differ diff --git a/res/TurkeySprite.png b/res/TurkeySprite.png new file mode 100644 index 0000000..c404648 Binary files /dev/null and b/res/TurkeySprite.png differ diff --git a/res/items/.DS_Store b/res/items/.DS_Store new file mode 100644 index 0000000..de60d0b Binary files /dev/null and b/res/items/.DS_Store differ diff --git a/res/people/.DS_Store b/res/people/.DS_Store new file mode 100644 index 0000000..91a2f7a Binary files /dev/null and b/res/people/.DS_Store differ diff --git a/res/people/Brother.png b/res/people/Brother.png new file mode 100644 index 0000000..cb5e69b Binary files /dev/null and b/res/people/Brother.png differ diff --git a/res/screens/.DS_Store b/res/screens/.DS_Store new file mode 100644 index 0000000..3567650 Binary files /dev/null and b/res/screens/.DS_Store differ diff --git a/res/screens/MarketScreen.png b/res/screens/MarketScreen.png new file mode 100644 index 0000000..7290eda Binary files /dev/null and b/res/screens/MarketScreen.png differ diff --git a/res/screens/MarketTopShelf.png b/res/screens/MarketTopShelf.png new file mode 100644 index 0000000..9c13e4d Binary files /dev/null and b/res/screens/MarketTopShelf.png differ diff --git a/res/sound/.DS_Store b/res/sound/.DS_Store new file mode 100644 index 0000000..9e827e8 Binary files /dev/null and b/res/sound/.DS_Store differ diff --git a/res/sound/Audio Sources.txt b/res/sound/Audio Sources.txt new file mode 100755 index 0000000..6bbe59c --- /dev/null +++ b/res/sound/Audio Sources.txt @@ -0,0 +1,35 @@ +Unless Otherwise noted, all sounds and music are in the public Domain. + +--------------------------- + + + +turkey_in_the_straw + +Composition Licence: Traditional, arr. first published between 1829 and 1834. This MP3 (or other media file) is in the public domain because its copyright has expired. This applies to the United States, where Works published prior to 1978 were copyright protected for a maximum of 75 years. See Circular 1 "COPYRIGHT BASICS" from the U.S. Copyright Office. Works published before 1924 are now in the public domain. + +This file is also in the public domain in countries that figure copyright from the date of death of the artist (post mortem auctoris in this case George Washington Dixon 1801? âMarch 2, 1861), and that most commonly runs for a period of 50 to 70 years from December 31 of that year. + +Performance Licence: The United States Air Force Band Web site is provided as a public service by the United States Air Force Band and Department of the Air Force. + +Information presented on the United States Air Force Band site is considered public information and may be distributed or copied. Use of appropriate byline/photo/image credits is requested. + +UPLOADED by Sookietex + +--------------------------- + + +Freesound.org +file name references the author name and file number. + + +--------------------------- + +Title: Improved Ice Cream Truck +Artist: Kevin MacLeod +Genre: Folk +Length: 0:51 +Bitrate: 320 kbps +Size: 1.93MB + +An improved version of a traditional Ice Cream Truck melody… whose actual title I forget. \ No newline at end of file diff --git a/res/sound/Events/.DS_Store b/res/sound/Events/.DS_Store new file mode 100644 index 0000000..f166e1b Binary files /dev/null and b/res/sound/Events/.DS_Store differ diff --git a/res/sound/Events/Fire/.DS_Store b/res/sound/Events/Fire/.DS_Store new file mode 100644 index 0000000..c309567 Binary files /dev/null and b/res/sound/Events/Fire/.DS_Store differ diff --git a/res/sound/Events/Fire/87564__sgak__fire Fire Start Louder.mp3 b/res/sound/Events/Fire/87564__sgak__fire Fire Start Louder.mp3 new file mode 100755 index 0000000..153f2ea Binary files /dev/null and b/res/sound/Events/Fire/87564__sgak__fire Fire Start Louder.mp3 differ diff --git a/res/sound/Events/Fire/87564__sgak__fire Loop.mp3 b/res/sound/Events/Fire/87564__sgak__fire Loop.mp3 new file mode 100755 index 0000000..83394e8 Binary files /dev/null and b/res/sound/Events/Fire/87564__sgak__fire Loop.mp3 differ diff --git a/res/sound/GUI/.DS_Store b/res/sound/GUI/.DS_Store new file mode 100644 index 0000000..8d7ac03 Binary files /dev/null and b/res/sound/GUI/.DS_Store differ diff --git a/res/sound/GUI/buzz.mp3 b/res/sound/GUI/buzz.mp3 new file mode 100644 index 0000000..ba53997 Binary files /dev/null and b/res/sound/GUI/buzz.mp3 differ diff --git a/res/sound/GUI/click.mp3 b/res/sound/GUI/click.mp3 new file mode 100755 index 0000000..62f45a1 Binary files /dev/null and b/res/sound/GUI/click.mp3 differ diff --git a/res/sound/GUI/lowclick.mp3 b/res/sound/GUI/lowclick.mp3 new file mode 100755 index 0000000..9adcba7 Binary files /dev/null and b/res/sound/GUI/lowclick.mp3 differ diff --git a/res/sound/GUI/pop.mp3 b/res/sound/GUI/pop.mp3 new file mode 100755 index 0000000..22c7d8d Binary files /dev/null and b/res/sound/GUI/pop.mp3 differ diff --git a/res/sound/Music/.DS_Store b/res/sound/Music/.DS_Store new file mode 100644 index 0000000..86f5115 Binary files /dev/null and b/res/sound/Music/.DS_Store differ diff --git a/res/sound/Music/Waterford.mp3 b/res/sound/Music/Waterford.mp3 new file mode 100755 index 0000000..7761dcc Binary files /dev/null and b/res/sound/Music/Waterford.mp3 differ diff --git a/res/sound/Store/.DS_Store b/res/sound/Store/.DS_Store new file mode 100644 index 0000000..973d5b5 Binary files /dev/null and b/res/sound/Store/.DS_Store differ diff --git a/res/sound/Store/Background Sounds/.DS_Store b/res/sound/Store/Background Sounds/.DS_Store new file mode 100644 index 0000000..0f2beb1 Binary files /dev/null and b/res/sound/Store/Background Sounds/.DS_Store differ diff --git a/res/sound/Store/Background Sounds/72565__wrinex__supermarkt-ms Loop 2.ogg b/res/sound/Store/Background Sounds/72565__wrinex__supermarkt-ms Loop 2.ogg new file mode 100755 index 0000000..68cfe8f Binary files /dev/null and b/res/sound/Store/Background Sounds/72565__wrinex__supermarkt-ms Loop 2.ogg differ diff --git a/res/sound/Store/Background Sounds/72565__wrinex__supermarkt-ms Loop 3.mp3 b/res/sound/Store/Background Sounds/72565__wrinex__supermarkt-ms Loop 3.mp3 new file mode 100755 index 0000000..078ab6b Binary files /dev/null and b/res/sound/Store/Background Sounds/72565__wrinex__supermarkt-ms Loop 3.mp3 differ diff --git a/res/sound/Store/Background Sounds/72565__wrinex__supermarkt-ms Loop 3.ogg b/res/sound/Store/Background Sounds/72565__wrinex__supermarkt-ms Loop 3.ogg new file mode 100755 index 0000000..66f0cf7 Binary files /dev/null and b/res/sound/Store/Background Sounds/72565__wrinex__supermarkt-ms Loop 3.ogg differ diff --git a/res/sound/Store/Background Sounds/72565__wrinex__supermarkt-ms Loop 4.ogg b/res/sound/Store/Background Sounds/72565__wrinex__supermarkt-ms Loop 4.ogg new file mode 100755 index 0000000..93aef3f Binary files /dev/null and b/res/sound/Store/Background Sounds/72565__wrinex__supermarkt-ms Loop 4.ogg differ diff --git a/res/sound/Store/Background Sounds/72565__wrinex__supermarkt-ms Loop 5.ogg b/res/sound/Store/Background Sounds/72565__wrinex__supermarkt-ms Loop 5.ogg new file mode 100755 index 0000000..68c826e Binary files /dev/null and b/res/sound/Store/Background Sounds/72565__wrinex__supermarkt-ms Loop 5.ogg differ diff --git a/res/sound/Store/Background Sounds/72565__wrinex__supermarkt-ms Loop 6.ogg b/res/sound/Store/Background Sounds/72565__wrinex__supermarkt-ms Loop 6.ogg new file mode 100755 index 0000000..0dbaf1b Binary files /dev/null and b/res/sound/Store/Background Sounds/72565__wrinex__supermarkt-ms Loop 6.ogg differ diff --git a/res/sound/Store/Background Sounds/72565__wrinex__supermarkt-ms Loop1.mp3 b/res/sound/Store/Background Sounds/72565__wrinex__supermarkt-ms Loop1.mp3 new file mode 100755 index 0000000..9259c6c Binary files /dev/null and b/res/sound/Store/Background Sounds/72565__wrinex__supermarkt-ms Loop1.mp3 differ diff --git a/res/sound/Store/Background Sounds/72565__wrinex__supermarkt-ms Loop1.ogg b/res/sound/Store/Background Sounds/72565__wrinex__supermarkt-ms Loop1.ogg new file mode 100755 index 0000000..e452457 Binary files /dev/null and b/res/sound/Store/Background Sounds/72565__wrinex__supermarkt-ms Loop1.ogg differ diff --git a/res/sound/Store/backgroundSound.mp3 b/res/sound/Store/backgroundSound.mp3 new file mode 100755 index 0000000..078ab6b Binary files /dev/null and b/res/sound/Store/backgroundSound.mp3 differ diff --git a/res/sound/Store/buy.mp3 b/res/sound/Store/buy.mp3 new file mode 100755 index 0000000..2129a6b Binary files /dev/null and b/res/sound/Store/buy.mp3 differ diff --git a/res/sound/Store/entrance.mp3 b/res/sound/Store/entrance.mp3 new file mode 100755 index 0000000..0b56b47 Binary files /dev/null and b/res/sound/Store/entrance.mp3 differ diff --git a/res/sound/Waterford.mp3 b/res/sound/Waterford.mp3 new file mode 100644 index 0000000..7761dcc Binary files /dev/null and b/res/sound/Waterford.mp3 differ diff --git a/res/sound/supermarket.mp3 b/res/sound/supermarket.mp3 new file mode 100644 index 0000000..078ab6b Binary files /dev/null and b/res/sound/supermarket.mp3 differ diff --git a/res/sound/turkey_in_the_straw.ogg b/res/sound/turkey_in_the_straw.ogg deleted file mode 100644 index 85fff1e..0000000 Binary files a/res/sound/turkey_in_the_straw.ogg and /dev/null differ