diff --git a/index.html b/index.html index 8a5ee17..653f92b 100644 --- a/index.html +++ b/index.html @@ -15,6 +15,8 @@ + + diff --git a/js/dialogue.js b/js/dialogue.js new file mode 100644 index 0000000..9d01ed6 --- /dev/null +++ b/js/dialogue.js @@ -0,0 +1,11 @@ +function DialogueSequence(){ + + return { + next: function(){ + return story.shift().split(": ")[1]; + }, + more: function(){ + return story.length > 0; + } + } +} \ No newline at end of file diff --git a/js/main.js b/js/main.js index 1e4172c..080bef1 100644 --- a/js/main.js +++ b/js/main.js @@ -1,15 +1,28 @@ function GameState(){ var that = this; + var SCREEN_OUT = 1; + var SCREEN_IN = 2; + var SCREEN_STABLE = 0; + var screenAlpha = 1; + this.pubsub = {}; BindPubSub( this.pubsub ); this.currentTime = new Date().getTime(); - this.oldTime = new Date().getTime(); this.mainUI = new GameUI( "demoCanvas", this ); createjs.Ticker.addEventListener( "tick", gameLoop ); + + // Load all our resources: + var queue = new createjs.LoadQueue(true); + queue.installPlugin(createjs.Sound); + //queue.addEventListener("fileload", handleFileComplete); + queue.loadFile( {id: "sound", src:"res/sound/turkey_in_the_straw.mp3"} ); + + this.screenState = 0; + function gameLoop(){ that.mainUI.draw(); } @@ -23,7 +36,7 @@ function GameUI( canvasElem, gameState ){ var that = this; this.stage = new createjs.Stage( canvasElem ); -// this.stage.enableMouseOver(36); + this.stage.enableMouseOver(20); this.activeScreenName = "EndingScreen"; this.activeScreenObj = {}; @@ -42,19 +55,29 @@ function GameUI( canvasElem, gameState ){ "CreditsScreen" : CreditsScreen } - this.activeScreenObj = new MainScreen( this.stage, gameState ); + this.activeScreenObj = new KitchenScreen( this.stage, gameState ); + var textContent = new createjs.Text( "", "16px Arial", "#00000000" ); + textContent.x = 750; + textContent.y = 30; + that.stage.addChild( textContent); this.switchScreen = function( screenName ){ + //gameState.screenState = SCREEN_OUT; + console.log("Switch screen called with" + screenName); that.stage.removeAllChildren(); that.activeScreenObj = new that.screens[ screenName ]( that.stage, gameState ); + //var rect = new createjs.Rectangle(0, 0, 100, 100); + that.stage.addChild( textContent ); } + gameState.pubsub.subscribe( "SwitchScreen", this.switchScreen ); return { draw : function(){ that.activeScreenObj.blit(); + textContent.text = createjs.Ticker.getMeasuredFPS().toFixed(1); that.stage.update(); } } @@ -66,29 +89,62 @@ function DialogUI( stage ){ var DIALOG_RECEDING = 0; var DIALOG_SHOWING = 1; var DIALOG_PAUSING = 2; + var MILLIS_PER_CHAR = 50; - this.dialogSpeed = 15; + this.dialogSpeed = 30; this.dialogState = DIALOG_PAUSING; - this.dialogMotionQueue = [DIALOG_RECEDING,DIALOG_SHOWING,DIALOG_RECEDING]; + this.dialogMotionQueue = [DIALOG_RECEDING,DIALOG_SHOWING,DIALOG_PAUSING]; + this.currDialogueSeq = new DialogueSequence(); dialogQueue = []; - // Replace with bitmap - this.dialogBox = new createjs.Shape(); - this.dialogBox.graphics.beginFill( "#00ffff" ).drawRect( 0, 450, 800, 150 ); + this.dialogBox = new createjs.Bitmap("res/DialogueBox.png"); + this.dialogBox.x = 10; + this.dialogBox.y = 435; - this.textContent = new createjs.Text( "Hello World This is some conversation text", "20px Arial", "#ff7700" ); - this.textContent.x = 50; - this.textContent.y = 500; + this.textContent = new createjs.Text( "Hey there kids!", "16px Arial", "#00000000" ); + this.textContent.x = 195; + this.textContent.y = 475; + this.textContent.lineWidth = 600; + 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(){ clickEvent(); }); + + 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(){ clickEvent(); }); + + + // 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() ){ + that.dialogMotionQueue.push(DIALOG_SHOWING); + 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; @@ -101,23 +157,23 @@ function DialogUI( stage ){ } // toggle states - if( that.dialogBox.y > 150 && that.dialogState == DIALOG_RECEDING ){ - that.dialogBox.y = 150; - that.textContent.y = 650; + 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 < 0 && that.dialogState == DIALOG_SHOWING ){ - that.dialogBox.y = 0; - that.textContent.y = 500; + if( that.dialogBox.y < 435 && that.dialogState == DIALOG_SHOWING ){ + that.dialogBox.y = 435; + that.textContent.y = 465; 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.pop(); + that.dialogState = that.dialogMotionQueue.shift(); } }, diff --git a/js/screens.js b/js/screens.js index 16ee196..474f53c 100644 --- a/js/screens.js +++ b/js/screens.js @@ -48,6 +48,22 @@ function MainScreen( stage, gameState ){ this.background = new createjs.Bitmap( "res/Main.png" ); stage.addChild( this.background ); + //createjs.Sound.addEventListener("fileload", createjs.proxy(loadHandler, this)); + createjs.Sound.registerSound("res/sound/turkey_in_the_straw.mp3", "sound"); + + var instance = createjs.Sound.createInstance("sound"); // play using id. Could also use full sourcepath or event.src. + instance.setPosition(5650); + instance.volume = 0.5; + + instance.play(); + + // loop-de-loop + instance.addEventListener("complete", playAgain); + function playAgain(event) { + instance.setPosition(5650); + instance.play(); + } + // 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" ) ); @@ -76,8 +92,8 @@ function DifficultyScreen( stage, gameState ){ stage.addChild( this.background ); // Easy/Hard Button - stage.addChild( new Button( stage, gameState, 170, 40, 450, 105, "SwitchScreen", "KitchenScreen" ) ); - stage.addChild( new Button( stage, gameState, 170, 150, 450, 105, "SwitchScreen", "KitchenScreen" ) ); + stage.addChild( new Button( stage, gameState, 170, 40, 450, 105, "SwitchScreen", "MarketScreen" ) ); + stage.addChild( new Button( stage, gameState, 170, 150, 450, 105, "SwitchScreen", "MarketScreen" ) ); return { blit : function(){ @@ -116,10 +132,28 @@ function KitchenScreen( stage, gameState ){ function MarketScreen( stage, gameState ){ var that = this; - this.background = new createjs.Bitmap( "res/Main.png" ); + this.background = new createjs.Bitmap( "res/Store-Screen-Clean.png" ); stage.addChild( this.background ); + stage.addChild( new Button( stage, gameState, 13, 445, 222, 65, "SwitchScreen", "KitchenScreen" ) ); this.uiElems = []; + this.uiElems.push( new MarketItem( stage, gameState, 275,195, 100, "res/items/Alarm.png", "res/items/AlarmGlow.png" ) ); + this.uiElems.push( new MarketItem( stage, gameState, 200,200, 100, "res/items/Bottle1.png", "res/items/Bottle1.png" ) ); + this.uiElems.push( new MarketItem( stage, gameState, 456,123, 100, "res/items/Bottle2.png", "res/items/Bottle2.png" ) ); + this.uiElems.push( new MarketItem( stage, gameState, 312,222, 100, "res/items/Bottle3.png", "res/items/Bottle3.png" ) ); + this.uiElems.push( new MarketItem( stage, gameState, 300,400, 100, "res/items/Cookbook1.png", "res/items/Cookbook1Glow.png" ) ); + this.uiElems.push( new MarketItem( stage, gameState, 12,11, 100, "res/items/FrillsBox.png", "res/items/FrillsBoxGlow.png" ) ); + this.uiElems.push( new MarketItem( stage, gameState, 44,222, 100, "res/items/OvenLightBox.png", "res/items/OvenLightBoxGlow.png" ) ); + this.uiElems.push( new MarketItem( stage, gameState, 66,444, 100, "res/items/StuffingExquisite.png", "res/items/StuffingExquisiteGlow.png" ) ); + this.uiElems.push( new MarketItem( stage, gameState, 293,12, 100, "res/items/StuffingRepurposed.png", "res/items/StuffingRepurposedGlow.png" ) ); + this.uiElems.push( new MarketItem( stage, gameState, 438,200, 100, "res/items/StuffingSpecial.png", "res/items/StuffingSpecialGlow.png" ) ); + this.uiElems.push( new MarketItem( stage, gameState, 444,334, 100, "res/items/TempProbe.png", "res/items/TempProbeGlow.png" ) ); + this.uiElems.push( new MarketItem( stage, gameState, 555,33, 100, "res/items/Turkey1.png", "res/items/Turkey1Glow.png" ) ); + this.uiElems.push( new MarketItem( stage, gameState, 200,200, 100, "res/items/Turkey2.png", "res/items/Turkey2Glow.png" ) ); + this.uiElems.push( new MarketItem( stage, gameState, 100,100, 100, "res/items/Turkey3.png", "res/items/Turkey3Glow.png" ) ); + this.uiElems.push( new MarketItem( stage, gameState, 122,349, 100, "res/items/Turkey4.png", "res/items/Turkey4Glow.png" ) ); + this.uiElems.push( new MarketItem( stage, gameState, 96,406, 100, "res/items/Turkey5.png", "res/items/Turkey5Glow.png" ) ); + return { blit : function(){ diff --git a/js/stories.js b/js/stories.js new file mode 100644 index 0000000..64efc75 --- /dev/null +++ b/js/stories.js @@ -0,0 +1,12 @@ +var story = ["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", +"Brother: Yup. Well, almost. I still have a mess to clean up", +"Mom : What happened?", +"Brother: Well, this can of primer was pretty old. And I guess it rusted on the bottom. So I prep everything, and get the primer can lid taken off, and start going to town on the wall. Then, I start feeling some wetness on my pants. I look down and there are primer drops all over my pants.", +"Dad: Why were you holding the paint bucket though. Don't you just pour it in a roller pan and do it that way like I taught 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 diff --git a/js/ui.js b/js/ui.js index 864c77f..b82cd8e 100644 --- a/js/ui.js +++ b/js/ui.js @@ -84,7 +84,7 @@ function OvenUI( stage, gameState ){ this.changeTemperature = function( direction ){ - if( temperatureText.text == "OFF" && direction == "Up" ) temperatureText.text = "150"; + if( temperatureText.text == "OFF" && direction == "Up" ) temperatureText.text = "125"; if( !( temperatureText.text == "OFF" && direction == "Down" ) ){ var temp = ( direction == "Up" ? parseInt(temperatureText.text)+25 : parseInt(temperatureText.text)-25); @@ -110,8 +110,8 @@ function OvenUI( stage, gameState ){ gameState.currentTime += 1000; } - setInterval(this.secondTick, 500); - + setInterval(this.secondTick, 1000); + stage.addChild( this.text ); return { @@ -131,33 +131,36 @@ return { } } -function Item(){ - /*img.onPress = function(e) { - document.body.style.cursor='move'; - offset = {x:e.stageX - e.target.x, y:e.stageY - e.target.y}; +function MarketItem( stage, gameState, x, y, cost, mouseOutImg, mouseOverImg ){ + var mouseOver = new createjs.Bitmap( 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; } ); + mouseOver.addEventListener( "click", function(){ alert("buy!"); } ); + mouseOver.visible = false; + stage.addChild( mouseOut ); + stage.addChild( mouseOver ); - e.onMouseMove = drag; - }*/ + return { + tick: function(){} + } } function Button( stage, gameState, x_orig, y_orig, x_dest, y_dest, eventCmd, arg ){ var that = this; - var infoButton = new createjs.Shape(); - infoButton.graphics.beginFill("#ffffff").drawRect(x_orig, y_orig, x_dest, y_dest); - infoButton.alpha = 0.5; - infoButton.addEventListener( "click", function(){ gameState.pubsub.publish( eventCmd, arg ) } ); - - infoButton.onMouseOver = function(e) { - alert("mouseover"); - document.body.style.cursor='pointer'; - } - - infoButton.onMouseOut = function(e) { - document.body.style.cursor='default'; - } + var button = new createjs.Shape(); + button.graphics.beginFill("#ffffff").drawRect(x_orig, y_orig, x_dest, y_dest); + button.alpha = 0.5; + 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'; } ); - return infoButton; + return button; } \ No newline at end of file diff --git a/res/DialogueBox.png b/res/DialogueBox.png new file mode 100644 index 0000000..bced340 Binary files /dev/null and b/res/DialogueBox.png differ diff --git a/res/items/Alarm.png b/res/items/Alarm.png new file mode 100644 index 0000000..56da1d1 Binary files /dev/null and b/res/items/Alarm.png differ diff --git a/res/items/AlarmGlow.png b/res/items/AlarmGlow.png new file mode 100644 index 0000000..dabed2d Binary files /dev/null and b/res/items/AlarmGlow.png differ diff --git a/res/items/Bottle1.png b/res/items/Bottle1.png new file mode 100644 index 0000000..1f47149 Binary files /dev/null and b/res/items/Bottle1.png differ diff --git a/res/items/Bottle2.png b/res/items/Bottle2.png new file mode 100644 index 0000000..748d977 Binary files /dev/null and b/res/items/Bottle2.png differ diff --git a/res/items/Bottle3.png b/res/items/Bottle3.png new file mode 100644 index 0000000..7074625 Binary files /dev/null and b/res/items/Bottle3.png differ diff --git a/res/items/Cookbook.png b/res/items/Cookbook.png new file mode 100644 index 0000000..dfa340f Binary files /dev/null and b/res/items/Cookbook.png differ diff --git a/res/items/Cookbook1.png b/res/items/Cookbook1.png new file mode 100644 index 0000000..74323c2 Binary files /dev/null and b/res/items/Cookbook1.png differ diff --git a/res/items/Cookbook1Glow.png b/res/items/Cookbook1Glow.png new file mode 100644 index 0000000..02fe431 Binary files /dev/null and b/res/items/Cookbook1Glow.png differ diff --git a/res/items/CookbookGlow.png b/res/items/CookbookGlow.png new file mode 100644 index 0000000..3263dfe Binary files /dev/null and b/res/items/CookbookGlow.png differ diff --git a/res/items/FrillsBox.png b/res/items/FrillsBox.png new file mode 100644 index 0000000..f148423 Binary files /dev/null and b/res/items/FrillsBox.png differ diff --git a/res/items/FrillsBoxGlow.png b/res/items/FrillsBoxGlow.png new file mode 100644 index 0000000..e1a961b Binary files /dev/null and b/res/items/FrillsBoxGlow.png differ diff --git a/res/items/OvenLightBox.png b/res/items/OvenLightBox.png new file mode 100644 index 0000000..9d7a938 Binary files /dev/null and b/res/items/OvenLightBox.png differ diff --git a/res/items/OvenLightBoxGlow.png b/res/items/OvenLightBoxGlow.png new file mode 100644 index 0000000..705d74d Binary files /dev/null and b/res/items/OvenLightBoxGlow.png differ diff --git a/res/items/Store-Screen-Clean.png b/res/items/Store-Screen-Clean.png new file mode 100644 index 0000000..e305a4c Binary files /dev/null and b/res/items/Store-Screen-Clean.png differ diff --git a/res/items/Store-ScreenV11-17.png b/res/items/Store-ScreenV11-17.png new file mode 100644 index 0000000..ba95d69 Binary files /dev/null and b/res/items/Store-ScreenV11-17.png differ diff --git a/res/items/Store-ScreenV11-19.png b/res/items/Store-ScreenV11-19.png new file mode 100644 index 0000000..3f6fa6b Binary files /dev/null and b/res/items/Store-ScreenV11-19.png differ diff --git a/res/items/StuffingExquisite.png b/res/items/StuffingExquisite.png new file mode 100644 index 0000000..25037cc Binary files /dev/null and b/res/items/StuffingExquisite.png differ diff --git a/res/items/StuffingExquisiteGlow.png b/res/items/StuffingExquisiteGlow.png new file mode 100644 index 0000000..82d3cf1 Binary files /dev/null and b/res/items/StuffingExquisiteGlow.png differ diff --git a/res/items/StuffingRepurposed.png b/res/items/StuffingRepurposed.png new file mode 100644 index 0000000..1172e69 Binary files /dev/null and b/res/items/StuffingRepurposed.png differ diff --git a/res/items/StuffingRepurposedGlow.png b/res/items/StuffingRepurposedGlow.png new file mode 100644 index 0000000..98d5042 Binary files /dev/null and b/res/items/StuffingRepurposedGlow.png differ diff --git a/res/items/StuffingSpecial.png b/res/items/StuffingSpecial.png new file mode 100644 index 0000000..ecbfa8d Binary files /dev/null and b/res/items/StuffingSpecial.png differ diff --git a/res/items/StuffingSpecialGlow.png b/res/items/StuffingSpecialGlow.png new file mode 100644 index 0000000..c4b000d Binary files /dev/null and b/res/items/StuffingSpecialGlow.png differ diff --git a/res/items/TempProbe.png b/res/items/TempProbe.png new file mode 100644 index 0000000..0b0fdfc Binary files /dev/null and b/res/items/TempProbe.png differ diff --git a/res/items/TempProbeGlow.png b/res/items/TempProbeGlow.png new file mode 100644 index 0000000..88fed48 Binary files /dev/null and b/res/items/TempProbeGlow.png differ diff --git a/res/items/Turkey1.png b/res/items/Turkey1.png new file mode 100644 index 0000000..b8d3b8b Binary files /dev/null and b/res/items/Turkey1.png differ diff --git a/res/items/Turkey1Glow.png b/res/items/Turkey1Glow.png new file mode 100644 index 0000000..891be9a Binary files /dev/null and b/res/items/Turkey1Glow.png differ diff --git a/res/items/Turkey2.png b/res/items/Turkey2.png new file mode 100644 index 0000000..f4ee1a0 Binary files /dev/null and b/res/items/Turkey2.png differ diff --git a/res/items/Turkey2Glow.png b/res/items/Turkey2Glow.png new file mode 100644 index 0000000..e17fea4 Binary files /dev/null and b/res/items/Turkey2Glow.png differ diff --git a/res/items/Turkey3.png b/res/items/Turkey3.png new file mode 100644 index 0000000..7978e5c Binary files /dev/null and b/res/items/Turkey3.png differ diff --git a/res/items/Turkey3Glow.png b/res/items/Turkey3Glow.png new file mode 100644 index 0000000..6250e7c Binary files /dev/null and b/res/items/Turkey3Glow.png differ diff --git a/res/items/Turkey4.png b/res/items/Turkey4.png new file mode 100644 index 0000000..f4aa5ea Binary files /dev/null and b/res/items/Turkey4.png differ diff --git a/res/items/Turkey4Glow.png b/res/items/Turkey4Glow.png new file mode 100644 index 0000000..ca6a758 Binary files /dev/null and b/res/items/Turkey4Glow.png differ diff --git a/res/items/Turkey5.png b/res/items/Turkey5.png new file mode 100644 index 0000000..77a7151 Binary files /dev/null and b/res/items/Turkey5.png differ diff --git a/res/items/Turkey5Glow.png b/res/items/Turkey5Glow.png new file mode 100644 index 0000000..a70ae85 Binary files /dev/null and b/res/items/Turkey5Glow.png differ diff --git a/res/sound/turkey_in_the_straw.mp3 b/res/sound/turkey_in_the_straw.mp3 new file mode 100644 index 0000000..a32a2c8 Binary files /dev/null and b/res/sound/turkey_in_the_straw.mp3 differ diff --git a/res/sound/turkey_in_the_straw.ogg b/res/sound/turkey_in_the_straw.ogg new file mode 100644 index 0000000..85fff1e Binary files /dev/null and b/res/sound/turkey_in_the_straw.ogg differ