Browse Source

clockUI

Load_Fix
Robert Chen 11 years ago
parent
commit
1ceb3f67cd
  1. 4
      index.html
  2. 3
      js/main.js
  3. 7
      js/screens.js
  4. 77
      js/ui.js

4
index.html

@ -22,7 +22,7 @@
<script src="js/main.js"></script> <script src="js/main.js"></script>
<script> <script>
new GameState(); new GameState();
/*
function showXY(e) function showXY(e)
{ {
var mouseX, mouseY; var mouseX, mouseY;
@ -37,7 +37,7 @@
} }
console.log("x: " + mouseX + "y :" + mouseY); console.log("x: " + mouseX + "y :" + mouseY);
}*/ }
</script> </script>
<!-- Load all the things! --> <!-- Load all the things! -->
</html> </html>

3
js/main.js

@ -17,6 +17,7 @@ function GameState(){
this.peekRecords = []; this.peekRecords = [];
this.turkeyCooking = false; this.turkeyCooking = false;
this.turkeyType = ""; this.turkeyType = "";
this.alarmTimer = 0;
// stats // stats
this.storeVisits = 0; this.storeVisits = 0;
@ -324,7 +325,7 @@ function GameUI( canvasElem, gameState ){
var soundManager = new SoundManager( gameState ); var soundManager = new SoundManager( gameState );
this.activeScreenObj = new LoadingScreen( this.stage, gameState ); this.activeScreenObj = new KitchenScreen( this.stage, gameState );
var textContent = new createjs.Text( "", "20px Arial", "#00000000" ); var textContent = new createjs.Text( "", "20px Arial", "#00000000" );
textContent.x = 750; textContent.x = 750;
textContent.y = 30; textContent.y = 30;

7
js/screens.js

@ -97,7 +97,7 @@ function MainScreen( stage, gameState ){
new ImgButton( stage, gameState, 17,470, "res/screens/MainScreen/ButtonHelp.png", "res/screens/MainScreen/ButtonHelp.png",null, null, "Click", function(){ gameState.pubsub.publish("ShowHelp",""); } ); new ImgButton( stage, gameState, 17,470, "res/screens/MainScreen/ButtonHelp.png", "res/screens/MainScreen/ButtonHelp.png",null, null, "Click", function(){ gameState.pubsub.publish("ShowHelp",""); } );
new ImgButton( stage, gameState, 17,527, "res/screens/MainScreen/ButtonCredits.png", "res/screens/MainScreen/ButtonCredits.png","SwitchScreen", "CreditsScreen", "Click" ); new ImgButton( stage, gameState, 17,527, "res/screens/MainScreen/ButtonCredits.png", "res/screens/MainScreen/ButtonCredits.png","SwitchScreen", "CreditsScreen", "Click" );
gameState.pubsub.publish( "BackgroundLoop", {name:"TitleMusic", pos:5650, volume:1} ); gameState.pubsub.publish( "BackgroundLoop", {name:"TitleMusic", pos:5650, volume:0.7} );
this.uiElems = []; this.uiElems = [];
return { return {
@ -256,6 +256,7 @@ function KitchenScreen( stage, gameState ){
this.uiElems.push( gameState.ovenUI ? gameState.ovenUI.render() : ( gameState.ovenUI = new OvenUI( stage, gameState ) ).render() ); this.uiElems.push( gameState.ovenUI ? gameState.ovenUI.render() : ( gameState.ovenUI = new OvenUI( stage, gameState ) ).render() );
this.uiElems.push( new ClockUI( stage, gameState ) ); this.uiElems.push( new ClockUI( stage, gameState ) );
this.uiElems.push( new AlarmUI(stage, gameState) );
stage.addChild( new Button( stage, gameState, 14, 17, 73, 45, null,null, function(){ gameState.pubsub.publish("ShowHelp","");} ) ); stage.addChild( new Button( stage, gameState, 14, 17, 73, 45, null,null, function(){ gameState.pubsub.publish("ShowHelp","");} ) );
@ -269,7 +270,7 @@ function KitchenScreen( stage, gameState ){
if( !gameState.turkeyBought ){ if( !gameState.turkeyBought ){
gameState.pubsub.publish( "ShowDialog", {seq:"KitchenInitial", autoAdvance:true} ); gameState.pubsub.publish( "ShowDialog", {seq:"KitchenInitial", autoAdvance:true} );
} }
return { return {
blit : function(){ blit : function(){
@ -392,7 +393,7 @@ function ScoreScreen( stage, gameState ){
this.background = new createjs.Bitmap( "res/screens/ScoreScreen/Score-Tally.png" ); this.background = new createjs.Bitmap( "res/screens/ScoreScreen/Score-Tally.png" );
stage.addChild( this.background ); stage.addChild( this.background );
gameState.pubsub.publish( "BackgroundLoop", {name:"TitleMusic", pos:5650, volume:1} ); gameState.pubsub.publish( "BackgroundLoop", {name:"TitleMusic", pos:5650, volume:0.7} );
// //

77
js/ui.js

@ -152,34 +152,55 @@ function AlarmUI(stage, gameState){
var that = this; var that = this;
this.showingConfirm = false; this.showingConfirm = false;
var finalImg = new createjs.Bitmap("res/screens/KitchenScreen/FinalConfirmation.png"); var finalImg = new createjs.Bitmap("res/screens/KitchenScreen/AlarmKitchen.png");
var yesButton = new Button( stage, gameState, 355, 338, 388, 50, null, null, function(){
gameState.pubsub.publish( "Play", "Ding" ); var timerText = new createjs.Text("00:00", "24px Arial", "#ffffffff" );
gameState.pubsub.publish( "SwitchScreen", "ScoreScreen" ); timerText.x = 372;
that.hideFinalConfirm(); timerText.y = 290;
var clearButton = new Button( stage, gameState, 364, 327, 17, 13, null, null, function(){
gameState.alarmTimer = 0;
that.updateTimer();
} ); } );
var noButton = new Button( stage, gameState, 355, 395, 388, 50, null, null, function(){that.hideFinalConfirm();} );
this.hideFinalConfirm = function(){ var hourButton = new Button( stage, gameState, 386, 327, 24, 13, null, null, function(){
stage.removeChild( finalImg ); gameState.alarmTimer +=3600;
stage.removeChild( yesButton ); that.updateTimer();
stage.removeChild( noButton ); } );
that.showingConfirm = false; var minuteButton = new Button( stage, gameState, 414, 327, 24, 13, null, null, function(){
}; gameState.alarmTimer +=300;
that.updateTimer();
} );
this.updateTimer = function(){
var colon = gameState.currentTime%2 ? ":" : " ";
var totalSec = gameState.alarmTimer;
var hours = parseInt( totalSec / 3600 ) % 24
var minutes = parseInt( totalSec / 60 ) % 60;
var timeText = ("00"+hours).slice(-2) + colon + ("00"+minutes).slice(-2);
timerText.text = timeText;
}
// Show core temperature // Show core temperature
this.showFinalConfirm = function(){ //this.showAlarmUI = function(){
console.log("Showing final confirm"); stage.addChild( finalImg );
if( !that.showingConfirm ){ stage.addChild( timerText );
that.showingConfirm = true; stage.addChild( clearButton );
stage.addChild( finalImg ); stage.addChild( hourButton );
stage.addChild( noButton ); stage.addChild( minuteButton );
stage.addChild( yesButton ); //};
//alarmTimer
this.updateTimer();
return{
secondTick: function(){
that.updateTimer();
},
tick:function(){
} }
}; }
// change temperature, this one's for the UI
gameState.pubsub.subscribe( "ShowFinalConfirm", this.showFinalConfirm );
} }
function CookbookUI( stage, gameState ){ function CookbookUI( stage, gameState ){
@ -253,7 +274,7 @@ function OvenUI( stage, gameState ){
this.ovenDoor = OVEN_CLOSED; this.ovenDoor = OVEN_CLOSED;
// Important Model, dummy placeholder // Important Model, dummy placeholder
var ovenModel = { secondTick:function(){} }; var ovenModel = { secondTick:function(){}, setRawTemp:function(){}, getRawTemp:function(){} };
var ovenLight = new createjs.Shape(); var ovenLight = new createjs.Shape();
ovenLight.graphics.beginFill( "black" ).drawCircle( 181, 126, 2 ); ovenLight.graphics.beginFill( "black" ).drawCircle( 181, 126, 2 );
@ -387,9 +408,9 @@ function OvenUI( stage, gameState ){
var state = ovenModel.getTurkeyState(); var state = ovenModel.getTurkeyState();
gameState.pubsub.publish( "ShowDialog", {seq:"custom", autoAdvance:true, customText:"Hmm... Looks " + turkeyState["skin"]["cond"][2] + "." } ); gameState.pubsub.publish( "ShowDialog", {seq:"custom", autoAdvance:true, customText:"Hmm... Looks " + turkeyState["skin"]["cond"][2] + "." } );
gameState.pubsub.publish( "AddRecord", {type:"Open ", text:"The turkey looked " + turkeyState["skin"]["cond"][2]} ); gameState.pubsub.publish( "AddRecord", {type:"Open ", text:"The turkey looked " + turkeyState["skin"]["cond"][2]} );
}
if(ovenModel)
ovenModel.setRawTemp( (ovenModel.getRawTemp() - 25) < 150 ? 150 : ovenModel.getRawTemp() - 25 ); ovenModel.setRawTemp( (ovenModel.getRawTemp() - 25) < 150 ? 150 : ovenModel.getRawTemp() - 25 );
}
gameState.pubsub.publish( "Play", "Oven_Door_Full_Open" ); gameState.pubsub.publish( "Play", "Oven_Door_Full_Open" );
}else if (that.ovenDoor == OVEN_OPEN ){ }else if (that.ovenDoor == OVEN_OPEN ){
that.ovenDoor = OVEN_PEEK; that.ovenDoor = OVEN_PEEK;
@ -463,7 +484,6 @@ function OvenUI( stage, gameState ){
// incur -25 upon door open and penalty -5 degrees a second for opening the oven. // incur -25 upon door open and penalty -5 degrees a second for opening the oven.
ovenModel.setRawTemp( (ovenModel.getRawTemp() - 5) < 150 ? 150 : ovenModel.getRawTemp() - 5 ); ovenModel.setRawTemp( (ovenModel.getRawTemp() - 5) < 150 ? 150 : ovenModel.getRawTemp() - 5 );
} }
ovenModel.secondTick(); ovenModel.secondTick();
gameState.currentTime += diff; gameState.currentTime += diff;
} }
@ -539,12 +559,13 @@ function OvenUI( stage, gameState ){
} }
stage.addChild(panFront); stage.addChild(panFront);
} }
// Pan front goes here // Pan front goes here
stage.addChild( panFront ); stage.addChild( panFront );
//finalize button //finalize button
if( gameState.turkeyBought ){ if( gameState.turkeyBought ){
stage.addChild( new Button( stage, gameState, 45, 250, 250, 175, null, null, function(){ stage.addChild( new Button( stage, gameState, 45, 250, 250, 150, null, null, function(){
gameState.pubsub.publish("Play", "Error"); gameState.pubsub.publish("Play", "Error");
gameState.pubsub.publish("ShowFinalConfirm",""); gameState.pubsub.publish("ShowFinalConfirm","");
} ) ); } ) );
@ -826,7 +847,7 @@ function Button( stage, gameState, x_orig, y_orig, x_dest, y_dest, eventCmd, arg
var button = new createjs.Shape(); var button = new createjs.Shape();
button.graphics.beginFill("#ffffff").drawRect(x_orig, y_orig, x_dest, y_dest); button.graphics.beginFill("#ffffff").drawRect(x_orig, y_orig, x_dest, y_dest);
button.alpha = 0.01; button.alpha = 0.5;
button.addEventListener( "click", function(){ button.addEventListener( "click", function(){
gameState.pubsub.publish( "Play", "Click" ); gameState.pubsub.publish( "Play", "Click" );
if( !altfunc ){ if( !altfunc ){

Loading…
Cancel
Save