Fix: timer millisecond display
This commit is contained in:
@@ -11,7 +11,7 @@ function TimeScoreRecord(x, y) {
|
||||
|
||||
TimeScoreRecord.prototype.makeScoreText = function(x, y) {
|
||||
var scoreText = game.add.text(x, y, "");
|
||||
scoreText.anchor.set(0, 0.5);
|
||||
scoreText.anchor.set(1, 0.5);
|
||||
// scoreText.font = "Orbitron";
|
||||
scoreText.fontSize = 30;
|
||||
scoreText.fontWeight = "bold"; // "normal";
|
||||
@@ -24,8 +24,8 @@ TimeScoreRecord.prototype.makeScoreText = function(x, y) {
|
||||
}
|
||||
|
||||
TimeScoreRecord.prototype.setContent = function(time, score) {
|
||||
this.timeText.setText(time);
|
||||
this.scoreText.text = score;
|
||||
this.timeText.setMSTimeText(time);
|
||||
this.scoreText.text = NumberUtil.numberWithCommas(Math.floor(score));
|
||||
}
|
||||
|
||||
TimeScoreRecord.prototype.setTextColorString = function(colorString) {
|
||||
@@ -34,4 +34,4 @@ TimeScoreRecord.prototype.setTextColorString = function(colorString) {
|
||||
}
|
||||
|
||||
TimeScoreRecord.TIMER_OFFSET_X = 0;
|
||||
TimeScoreRecord.SCORE_OFFSET_X = 100;
|
||||
TimeScoreRecord.SCORE_OFFSET_X = 120;
|
||||
@@ -37,6 +37,7 @@ TimerStage.prototype.makeTimeScoreRecordArray = function() {
|
||||
this.posX,
|
||||
this.posY + TimerStage.RECORD_OFFSET_Y + TimerStage.RECORD_GAP_Y * i
|
||||
);
|
||||
timeScoreRecord.setTextColorString("grey");
|
||||
this.timeScoreRecordArray.push(timeScoreRecord);
|
||||
}
|
||||
}
|
||||
@@ -45,14 +46,7 @@ TimerStage.prototype.makeTimeScoreRecordArray = function() {
|
||||
TimerStage.prototype.initialize = function() {
|
||||
this.timeLimitMS = TimerStage.START_LIMIT_TIME_MS;
|
||||
|
||||
this.startTime = 0.0;
|
||||
this.timeLeft = 0.0;
|
||||
this.isTimerStarted = false;
|
||||
this.isTimerPaused = true;
|
||||
|
||||
this.onTimeUpdate = null;
|
||||
this.onTimeOver = null;
|
||||
|
||||
this.state = TimerStage.STATE_READY;
|
||||
this.mainTimer = game.time.create(false);
|
||||
|
||||
this.timerEvent = null;
|
||||
@@ -61,14 +55,16 @@ TimerStage.prototype.initialize = function() {
|
||||
(function() { this.updateTimer(); }).bind(this),
|
||||
this
|
||||
);
|
||||
// this.mainTimer.start();
|
||||
|
||||
this.recordArray = new Array();
|
||||
}
|
||||
|
||||
TimerStage.prototype.updateTimer = function() {
|
||||
// console.log(game.time.totalElapsedSeconds());
|
||||
// console.log(this.mainTimer.ms);
|
||||
console.log(this.mainTimer.ms);
|
||||
var timeLeft = this.timeLimitMS - this.mainTimer.ms;
|
||||
this.mainTimerText.setMSTimeText(timeLeft);
|
||||
// this.mainTimerText.setMSTimeText(this.mainTimer.ms);
|
||||
|
||||
if(timeLeft < 0) {
|
||||
console.log("Game Over");
|
||||
@@ -76,36 +72,33 @@ TimerStage.prototype.updateTimer = function() {
|
||||
}
|
||||
|
||||
TimerStage.prototype.buttonClicked = function() {
|
||||
// 시작
|
||||
if(!this.isTimerStarted) {
|
||||
// console.log("start");
|
||||
if(this.state == TimerStage.STATE_READY) {
|
||||
// 시작
|
||||
this.mainTimer.start();
|
||||
|
||||
this.isTimerStarted = true;
|
||||
this.timerButton.text.text = "정지";
|
||||
|
||||
return;
|
||||
this.state = TimerStage.STATE_PLAYING;
|
||||
} else if(this.state == TimerStage.STATE_PLAYING) {
|
||||
// 중지
|
||||
this.decideGrade(this.timeLimitMS - this.mainTimer.ms);
|
||||
|
||||
this.mainTimer.stop(false);
|
||||
// this.updateTimer();
|
||||
|
||||
// this.mainTimerText.setMSTimeText(this.timeLimitMS);
|
||||
this.isTimerStarted = false;
|
||||
this.isTimerStoped = true;
|
||||
this.timerButton.text.text = "리셋";
|
||||
|
||||
this.state = TimerStage.STATE_STOPPED;
|
||||
} else {
|
||||
// 리셋
|
||||
this.mainTimerText.setMSTimeText(this.timeLimitMS);
|
||||
this.timerButton.text.text = "시작";
|
||||
|
||||
this.state = TimerStage.STATE_READY;
|
||||
}
|
||||
|
||||
|
||||
// 정지
|
||||
// console.log("stop");
|
||||
this.decideGrade(this.timeLimitMS - this.mainTimer.ms);
|
||||
|
||||
this.mainTimer.stop(false);
|
||||
this.updateTimer();
|
||||
|
||||
this.mainTimerText.setMSTimeText(this.timeLimitMS);
|
||||
this.isTimerStarted = false;
|
||||
this.timerButton.text.text = "시작";
|
||||
|
||||
|
||||
/*
|
||||
if(this.mainTimer.paused)
|
||||
this.mainTimer.resume();
|
||||
else if(this.mainTimer.running)
|
||||
this.mainTimer.pause();
|
||||
*/
|
||||
}
|
||||
|
||||
TimerStage.prototype.decideGrade = function(timeLeft) {
|
||||
@@ -113,32 +106,84 @@ TimerStage.prototype.decideGrade = function(timeLeft) {
|
||||
if(timeLeft < 0) {
|
||||
console.log("Game Over")
|
||||
}
|
||||
else if(timeLeft < 200) this.gradeGreat();
|
||||
else if(timeLeft < 500) this.gradeGood();
|
||||
else if(timeLeft < 1000) this.gradeSoSo();
|
||||
else this.gradeBad();
|
||||
else if(timeLeft < 200) this.gradeGreat(timeLeft);
|
||||
else if(timeLeft < 500) this.gradeGood(timeLeft);
|
||||
else if(timeLeft < 1000) this.gradeSoSo(timeLeft);
|
||||
else this.gradeBad(timeLeft);
|
||||
|
||||
this.updateTimeScoreRecordArray();
|
||||
}
|
||||
|
||||
TimerStage.prototype.gradeGreat = function(timeLeft) {
|
||||
console.log("Great")
|
||||
var score = this.timeLimitMS * 10;
|
||||
this.timeLimitMS = this.timeLimitMS + 3000;
|
||||
|
||||
|
||||
this.recordArray.push( { timeLeft, score } );
|
||||
}
|
||||
|
||||
TimerStage.prototype.gradeGood = function(timeLeft) {
|
||||
console.log("Good")
|
||||
var score = this.timeLimitMS * 3;
|
||||
this.timeLimitMS = this.timeLimitMS + 1000;
|
||||
|
||||
|
||||
this.recordArray.push( { timeLeft, score } );
|
||||
}
|
||||
|
||||
TimerStage.prototype.gradeSoSo = function(timeLeft) {
|
||||
console.log("SoSo")
|
||||
var score = this.timeLimitMS * 2;
|
||||
this.timeLimitMS = this.timeLimitMS + 500;
|
||||
|
||||
this.recordArray.push( { timeLeft, score } );
|
||||
}
|
||||
|
||||
TimerStage.prototype.gradeBad = function(timeLeft) {
|
||||
console.log("Bad")
|
||||
var score = this.timeLimitMS;
|
||||
|
||||
// this.recordArray.push( { timeLeft, score } );
|
||||
var record = {
|
||||
timeLeft: 0.0,
|
||||
score: 0
|
||||
}
|
||||
record.timeLeft = timeLeft;
|
||||
record.score = score;
|
||||
|
||||
this.recordArray.push(record);
|
||||
}
|
||||
|
||||
|
||||
TimerStage.prototype.updateTimeScoreRecordArray = function() {
|
||||
// console.log(this.recordArray);
|
||||
|
||||
for(var i = 0; i < TimerStage.RECORD_COUNT; i++) {
|
||||
var timeScoreRecordIndex = i;
|
||||
var recordIndex = this.recordArray.length - 1 - i;
|
||||
if(recordIndex < 0)
|
||||
break;
|
||||
|
||||
var record = this.recordArray[recordIndex];
|
||||
// console.log(record);
|
||||
this.timeScoreRecordArray[timeScoreRecordIndex].setContent(record.timeLeft, record.score);
|
||||
if(record.timeLeft < 200)
|
||||
this.timeScoreRecordArray[timeScoreRecordIndex].setTextColorString("gold");
|
||||
else if(record.timeLeft < 500)
|
||||
this.timeScoreRecordArray[timeScoreRecordIndex].setTextColorString("orange");
|
||||
else if(record.timeLeft < 1000)
|
||||
this.timeScoreRecordArray[timeScoreRecordIndex].setTextColorString("red");
|
||||
else
|
||||
this.timeScoreRecordArray[timeScoreRecordIndex].setTextColorString("white");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
TimerStage.STATE_READY = 0;
|
||||
TimerStage.STATE_PLAYING = 1;
|
||||
TimerStage.STATE_STOPPED = 2;
|
||||
|
||||
TimerStage.START_LIMIT_TIME_MS = 1000;
|
||||
|
||||
|
||||
@@ -35,7 +35,16 @@ TimerText.prototype.setMSTimeText = function(ms) {
|
||||
var sec2Digit = ("00" + sec).slice(-2);
|
||||
|
||||
var millisec = ms % 1000;
|
||||
var millisec2Digit = ("00" + millisec).slice(-2);
|
||||
console.log("millisec : " + millisec);
|
||||
var millisec2Digit = "" + millisec;
|
||||
if(millisec < 10)
|
||||
millisec2Digit = ("000" + millisec).substring(0, 2);
|
||||
else if(millisec < 100)
|
||||
millisec2Digit = ("00" + millisec).substring(0, 2);
|
||||
else if(millisec < 10)
|
||||
millisec2Digit = ("0" + millisec).substring(0, 2);
|
||||
else
|
||||
millisec2Digit = ("" + millisec).substring(0, 2);
|
||||
|
||||
this.setText(sec2Digit + "." + millisec2Digit);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user