Skip to content

Commit

Permalink
Merge pull request #18 from fernjager/OvenFixMobile
Browse files Browse the repository at this point in the history
Oven fix mobile
  • Loading branch information
fernjager committed Nov 30, 2022
2 parents 38b30e2 + 79844a9 commit b281490
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 50 deletions.
5 changes: 3 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
<head>
<title>Turkey Cooking Simulator</title>
<style type="text/css">
#demoCanvas{ touch-action: auto; }
body {overscroll-behavior-y: contain;}
</style>
</head>
<body bgcolor="#250c00">

<center>
<div class="canvasContainer">
<canvas id="demoCanvas" width="800" height="600" style="border:1px solid #000000"></canvas>
</div>
</center>
</body>
<script src="//code.createjs.com/createjs-2013.09.25.min.js"></script>
<script src="//code.createjs.com/1.0.0/createjs.min.js"></script>
<script src="js/model.js"></script>
<script src="js/soundmanager.js"></script>
<script src="js/stories.js"></script>
Expand Down
6 changes: 4 additions & 2 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ function GameState(){
}
}


function GameUI( canvasElem, gameState ){
var that = this;

Expand All @@ -337,7 +338,7 @@ function GameUI( canvasElem, gameState ){

this.stage = new createjs.Stage( canvasElem );
this.stage.enableMouseOver(25);

this.activeScreenName = "EndingScreen";
this.activeScreenObj = {};

Expand Down Expand Up @@ -391,7 +392,7 @@ function GameUI( canvasElem, gameState ){
that.stage.removeChild(items[index]);
}
});

return {
draw : function(){
if( gameState.screenState == SCREEN_OUT ){
Expand All @@ -416,6 +417,7 @@ function GameUI( canvasElem, gameState ){
that.stage.update();
}
}

}

function Record( type, dateTime, record ){
Expand Down
12 changes: 10 additions & 2 deletions js/stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ var messages = {
"NoMoney" : ["Me: I can't afford this!"],
"BuyTurkeyFirst" : ["Me: I should buy a turkey first!"],
"EmptyOven" : ["Me: I'll start cooking once I get a turkey."],
"OpenDoor" :["Me: I should probably try opening the oven door to measure the turkey's temperature."]
"OpenDoor" :["Me: I should probably try opening the oven door to measure the turkey's temperature."],
"BrokenLight" :["Me: The oven light is broken. I should buy a replacement."]
}

//Terrible Results
Expand Down Expand Up @@ -175,7 +176,7 @@ var story = {
"Brother: Thanks Grandpa, I'll definitely keep that in mind."],

"Hanging Doorway Ornaments":[
"Grandma: A real bother these days are the people that decorations in their doorways. They get in your face as you try to walk through.",
"Grandma: A real bother these days are the people with decorations in their doorways. They get in your face as you try to walk through.",
"Grandma: And what if there is an Earthquake!",
"Grandpa: It isn't like we live on a fault line.",
"Grandma: Just stop hanging your bears in the doorway.",
Expand Down Expand Up @@ -476,6 +477,13 @@ var story = {
["Mom: My favorite color is butter.",
"Spouse: That's cool."],

"Secret Debug Story":
["Spouse: Hey [Player], do you think the universe is just one giant computer simulation?",
"Spouse: Like, maybe there are secret cheat codes or something.",
"Spouse: But how would we enter the cheat codes? Wildly flail our arms around in some way?",
"Spouse: Or maybe we need to eat certain foods on specific days of the week!",
"Spouse: Hah, that would be funny." ],

"Cat Story":
["Cat: Meow Meow Meow Meow Meow",
"Dad: I think the cat's hungry!",
Expand Down
111 changes: 67 additions & 44 deletions js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ function OvenUI( stage, gameState ){
var OVEN_CLOSED = 0;
var OVEN_PEEK = 1;
var OVEN_OPEN = 2;
this.ovenDoorTimer = 0;

this.ovenDoor = OVEN_CLOSED;
var ovenLight = new createjs.Shape();
Expand Down Expand Up @@ -433,6 +434,8 @@ function OvenUI( stage, gameState ){
var panFront = new createjs.Bitmap( "res/screens/KitchenScreen/PanFront.png" );
panFront.alpha = 0;

var finalButton;

this.changeTemperature = function( direction ){

if( gameState.turkeyBought ){
Expand Down Expand Up @@ -482,6 +485,10 @@ function OvenUI( stage, gameState ){
doorOpen.alpha = 0;
}
}
else
{
gameState.pubsub.publish("ShowDialog", {seq:"BrokenLight", autoAdvance:true});
}
}

this.startTurkeyModel = function(){
Expand All @@ -495,6 +502,7 @@ function OvenUI( stage, gameState ){
handleBar.addEventListener( "mouseover", function(){ document.body.style.cursor='pointer'; } );
handleBar.addEventListener( "mouseout", function(){ document.body.style.cursor='default'; } );
handleBar.addEventListener( "pressup", handlePress );
//handleBar.addEventListener( "click", ovenPeek );

var evalSkin = {
"raw": "The turkey looks no different from when I put it in",
Expand All @@ -506,72 +514,85 @@ function OvenUI( stage, gameState ){
"burnt": "The turkey looks burnt"
};


// Look for a drag event
function handlePress(event) {
if( event.stageY > 300 && that.ovenDoor != OVEN_OPEN ){
that.ovenDoor = OVEN_OPEN;
doorPeekLightOn.alpha = doorClosedLightOn.alpha = 0;
doorPeekLightOff.alpha = doorClosedLightOff.alpha = 0;
doorOpen.alpha = 1;
handleBar.graphics.clear();
handleBar.graphics.beginFill("#ffffff").drawRect(5, 450, 400, 60);
handleBar.alpha = 0.01;

if( gameState.turkeyBought ){
var state = gameState.ovenModel.getTurkeyState();
if(!evalSkin[turkeyState["skin"]["cond"][2]])
gameState.pubsub.publish("Death","");
gameState.pubsub.publish( "ShowDialog", {seq:"custom", autoAdvance:true, customText:evalSkin[turkeyState["skin"]["cond"][2]] + "." } );
gameState.pubsub.publish( "AddRecord", {type:"Open ", text:"The turkey looked " + turkeyState["skin"]["cond"][2]} );
gameState.ovenModel.setRawTemp( (gameState.ovenModel.getRawTemp() - 3 ) < 20 ? 20 : gameState.ovenModel.getRawTemp() - 3 );
gameState.ovenOpened++;
}

gameState.pubsub.publish( "Play", "Oven_Door_Full_Open" );
if( event.stageY > 300 && that.ovenDoor != OVEN_OPEN){
ovenOpen();
//Mouse Drag to open fully from peek or closed.
} else if (that.ovenDoor == OVEN_PEEK && (Date.now() - that.ovenDoorTimer < 2000)) {
//Peek to Open if double clicked within seconds. Meant for Mobile users who cannot drag
ovenOpen();
}else if( that.ovenDoor == OVEN_CLOSED && that.ovenDoor != OVEN_OPEN ){
ovenPeek();
}else if (that.ovenDoor == OVEN_OPEN ){
that.ovenDoor = OVEN_PEEK;
ovenClose();
gameState.pubsub.publish( "Play", "Oven_Door_Full_Close" );
handleBar.graphics.clear();
handleBar.graphics.beginFill("#ffffff").drawRect(20, 190, 300, 20);
handleBar.alpha = 0.01;
ovenPeek();
}else if (that.ovenDoor == OVEN_PEEK){
ovenClose();
gameState.pubsub.publish( "Play", "Oven_Door_Peek_Close" );
}
}

function ovenClose() {
that.ovenDoor = OVEN_CLOSED;
handleBar.graphics.clear();
handleBar.graphics.beginFill("#ffffff").drawRect(20, 190, 300, 20);
doorClosedLightOn.alpha = lightPressedImg.alpha;
doorClosedLightOff.alpha = !lightPressedImg.alpha;
doorPeekLightOn.alpha = 0;
doorPeekLightOff.alpha = 0;
doorOpen.alpha = 0;
handleBar.y = 0;

if( gameState.turkeyBought ){
finalButton.alpha = 0
}
}

handleBar.addEventListener( "click", ovenPeek );
function ovenOpen() {
that.ovenDoor = OVEN_OPEN;
gameState.pubsub.publish( "Play", "Oven_Door_Full_Open" );
doorPeekLightOn.alpha = doorClosedLightOn.alpha = 0;
doorPeekLightOff.alpha = doorClosedLightOff.alpha = 0;
doorOpen.alpha = 1;
handleBar.graphics.clear();
handleBar.graphics.beginFill("#ffffff").drawRect(5, 450, 400, 60);


if( gameState.turkeyBought ){
finalButton.alpha = 0.01;
var state = gameState.ovenModel.getTurkeyState();
if(!evalSkin[turkeyState["skin"]["cond"][2]])
gameState.pubsub.publish("Death","");
gameState.pubsub.publish( "ShowDialog", {seq:"custom", autoAdvance:true, customText:evalSkin[turkeyState["skin"]["cond"][2]] + "." } );
gameState.pubsub.publish( "AddRecord", {type:"Open ", text:"The turkey looked " + turkeyState["skin"]["cond"][2]} );
gameState.ovenModel.setRawTemp( (gameState.ovenModel.getRawTemp() - 3 ) < 20 ? 20 : gameState.ovenModel.getRawTemp() - 3 );
gameState.ovenOpened++;
}
}

function ovenPeek(){
if( that.ovenDoor == OVEN_CLOSED && that.ovenDoor != OVEN_OPEN ){
that.ovenDoor = OVEN_PEEK;
that.ovenDoorTimer = Date.now();
gameState.pubsub.publish( "Play", "Oven_Door_Peek_Open" );
doorPeekLightOn.alpha = lightPressedImg.alpha;
doorPeekLightOff.alpha = !lightPressedImg.alpha;
doorClosedLightOn.alpha = 0;
doorClosedLightOff.alpha = 0;
doorOpen.alpha = 0;
that.ovenDoor = OVEN_PEEK;

handleBar.y = 48;


if( gameState.turkeyBought ){
finalButton.alpha = 0
var state = gameState.ovenModel.getTurkeyState();
if(!evalSkin[turkeyState["skin"]["cond"][2]])
gameState.pubsub.publish("Death","");
gameState.pubsub.publish( "ShowDialog", {seq:"custom", autoAdvance:true, customText:evalSkin[turkeyState["skin"]["cond"][2]] } );
gameState.pubsub.publish( "AddRecord", {type:"Peek ", text:"The turkey looked " +turkeyState["skin"]["cond"][2]} );
}
}
else if (that.ovenDoor == OVEN_PEEK){
doorClosedLightOn.alpha = lightPressedImg.alpha;
doorClosedLightOff.alpha = !lightPressedImg.alpha;
doorPeekLightOn.alpha = 0;
doorPeekLightOff.alpha = 0;
that.ovenDoor = OVEN_CLOSED;
gameState.pubsub.publish( "Play", "Oven_Door_Peek_Close" );
doorOpen.alpha = 0;
handleBar.y = 0;
}
}

// Show core temperature
this.showTempDialog = function(){
if( that.ovenDoor != OVEN_OPEN ){
Expand Down Expand Up @@ -684,14 +705,16 @@ function OvenUI( stage, gameState ){

//finalize button
if( gameState.turkeyBought ){
stage.addChild( new Button( stage, gameState, 45, 250, 250, 150, null, null, function(){
finalButton = new Button( stage, gameState, 45, 250, 250, 150, null, null, function(){
if(!evalSkin[turkeyState["skin"]["cond"][2]]){
gameState.pubsub.publish("Death","");
return;
}
gameState.pubsub.publish("Play", "Error");
gameState.pubsub.publish("ShowFinalConfirm","");
} ) );
} )
finalButton.alpha=0;
stage.addChild(finalButton);
}

stage.addChild( doorPeekLightOn);
Expand Down

0 comments on commit b281490

Please sign in to comment.