Add: RecordUtil

This commit is contained in:
2018-12-03 00:25:16 +09:00
parent 057ac18184
commit eb61871526
12 changed files with 92 additions and 270 deletions
+25
View File
@@ -0,0 +1,25 @@
function RecordUtil() {
}
RecordUtil.getRecordValueWithUnit = function(record, appID) {
var recordValue = RecordUtil.getRecordValueText(record, appID);
var recordUnit = RecordUtil.getRecordUnit(appID);
return recordValue + recordUnit;
}
RecordUtil.getRecordValueText = function(record, appID) {
if(appID == 104)
return record.toFixed(2);
else
NumberUtil.numberWithCommas(Math.floor(record));
}
RecordUtil.getRecordUnit = function(appID) {
if(appID == 104)
return " 초";
else if(appID < 100)
return " 타";
else
return " 점";
}
+4 -3
View File
@@ -63,9 +63,10 @@ ScreenBottomUI.prototype.printText = function(textObject, text, align) {
}
ScreenBottomUI.prototype.printLeftTextWithAppHighestRecord = function(bestRecord) {
var roundUpBestRecord = Math.round(bestRecord);
var highScoreWithCommas = NumberUtil.numberWithCommas(roundUpBestRecord);
this.printLeftText("최고 기록 : " + highScoreWithCommas);
this.printLeftText(
"최고 기록 : "
+ RecordUtil.getRecordValueWithUnit(bestRecord, sessionStorageManager.getPlayingAppID())
);
}
ScreenBottomUI.prototype.getFontStyle = function() {
-178
View File
@@ -1,178 +0,0 @@
Alien.prototype = Object.create(Phaser.Sprite.prototype);
Alien.constructor = Alien;
function Alien(spaceship, onCollisionFunction) {
this.spaceship = spaceship;
this.onCollisionFunction = onCollisionFunction;
this.isActivated = false;
this.speed = Alien.DEFAULT_SPEED_DOT_PER_SEC;
this.boostSpeed = Alien.DEFAULT_SPEED_DOT_PER_SEC / 10;
this.angleFromSpaceship = 0;
this.angleFromAlien = 0;
this.responRadius = 0;
this.speedLevel = 0;
Phaser.Sprite.call(this, game, 0, 0, 'alien');
this.anchor.set(0.5);
game.add.existing(this);
// game.physics.enable(this, Phaser.Physics.ARCADE);
game.physics.arcade.enable(this);
this.moveRandomPosition();
}
Alien.prototype.moveRandomPosition = function() {
this.angleFromAlien = game.rnd.integerInRange(0, 360);
// console.log(this.angleFromAlien);
var radians = this.angleFromAlien * Math.PI / 180;
this.responRadius = Alien.START_Radius_PX * ( ( (100 + game.rnd.integerInRange(0, Alien.START_RANDOM_Radius_PERCENT) ) / 100) );
var posX = Math.sin(radians) * this.responRadius;
var posY = Math.cos(radians) * this.responRadius;
this.x = game.world.centerX + posX;
this.y = game.world.centerY + posY;
// this.x = this.spaceship.x + posX;
// this.y = this.spaceship.y + posY;
var AlienAngle = this.getAngle(this.spaceship.x, this.spaceship.y, this.x, this.y);
this.angle = this.getSpriteAngle(AlienAngle);
this.angleFromAlien = AlienAngle;
this.upgradeLevel();
}
Alien.prototype.update = function() {
if(!this.isActivated)
return;
// game.physics.arcade.overlap(this.spaceship, this, this.collisionHandler, null, this);
game.physics.arcade.collide(this.spaceship, this, this.collisionHandler, null, this);
var deltaTime = game.time.elapsed / 1000;
var radians = this.angleFromAlien * Math.PI / 180;
var moveX = Math.sin(radians) * this.speed * deltaTime;
var moveY = Math.cos(radians) * this.speed * deltaTime;
this.x -= moveX;
this.y -= moveY;
var distanceX = this.x - game.world.centerX;
var distanceY = this.y - game.world.centerY;
var distanceFromCenter = Math.sqrt(Math.abs(distanceX * distanceX) + Math.abs(distanceY * distanceY));
if(distanceFromCenter > this.responRadius)
this.moveRandomPosition();
}
Alien.prototype.collisionHandler = function() {
this.stop();
this.onCollisionFunction();
}
Alien.prototype.stop = function() {
this.setActive(false);
this.body.enable = false;
this.alpha = 0;
}
Alien.prototype.setActive = function(isActivated) {
this.isActivated = isActivated;
}
Alien.prototype.getSpriteAngle = function (angle){
return 360 - angle;
}
Alien.prototype.getAngle = function (x1, y1, x2, y2){
var dx = x2 - x1;
var dy = y2 - y1;
var rad= Math.atan2(dx, dy);
var degree = (rad * 180) / Math.PI ;
if(degree < 0)
degree += 360;
return degree;
}
Alien.prototype.upgradeLevel = function() {
if(this.speedLevel == 5)
return;
var rand = game.rnd.integerInRange(0, 100);
var successNumber = 0;
switch(this.speedLevel) {
case 0:
successNumber = 90;
break;
case 1:
successNumber = 80;
break;
case 2:
successNumber = 70;
break;
case 3:
successNumber = 60;
break;
case 4:
successNumber = 50;
break;
}
if(rand < successNumber)
this.speedUp();
}
Alien.prototype.speedUp = function() {
this.speedLevel++;
this.speed = Alien.DEFAULT_SPEED_DOT_PER_SEC + (this.boostSpeed * this.speedLevel);
switch(this.speedLevel) {
case 1:
this.tint = 0xffffff;
break;
case 2:
this.tint = 0xffaaaa;
break;
case 3:
this.tint = 0xaaffaa;
break;
case 4:
this.tint = 0xaaaaff;
break;
case 5:
this.tint = 0xaaaaaa;
break;
}
}
Alien.DEFAULT_SPEED_DOT_PER_SEC = 150;
Alien.START_Radius_PX = 600;
Alien.START_RANDOM_Radius_PERCENT = 40;
+8 -20
View File
@@ -1,5 +1,9 @@
var Game = {
preload: function() {
game.stage.disableVisibilityChange = true;
},
create: function() {
game.physics.enable(this, Phaser.Physics.ARCADE);
@@ -25,9 +29,7 @@ var Game = {
// game stage
var stars = game.add.group();
for (var i = 0; i < 128; i++)
{
for (var i = 0; i < 128; i++) {
var randomY = game.rnd.integerInRange(60, GAME_SCREEN_SIZE.y - 80);
stars.create(game.world.randomX, randomY, 'star');
}
@@ -39,7 +41,7 @@ var Game = {
this.aliens = [];
for(var i = 0; i < 100; i++) {
var alien = new Alien(this.spaceship,
var alien = new Missile(this.spaceship,
(function() {
this.spaceship.alpha = 0;
this.spaceship.body.enable = false;
@@ -58,20 +60,6 @@ var Game = {
screenTopUI.makeBackButton( (function() { this.back(); }).bind(this) );
screenTopUI.makeFullScreenButton();
/*
var scoreBoard = new ScoreBoard();
this.scoreManager.addOnChangeScoreListener( function(score) {
sessionStorageManager.setRecord(score);
scoreBoard.printScore(NumberUtil.numberWithCommas(score));
});
this.scoreManager.addOnChangeHighScoreListener( function(highScore) {
// console.log(highScore);
// sessionStorageManager.setAppHighestRecord(highScore);
sessionStorageManager.setIsNewBestRecrd(true);
// screenBottomUI.printLeftTextWithAppHighestRecord(sessionStorageManager.getAppHighestRecord());
});
*/
this.stopWatch = new StopWatch(
60, // sec
(function() {
@@ -91,8 +79,8 @@ var Game = {
// this.startGame();
this.spaceship.setActive(true);
this.countDown();
this.spaceship.setActive(true);
},
@@ -202,7 +190,7 @@ var Game = {
hitStarEmitter.maxParticleScale = 3;
hitStarEmitter.forEach(
function(particle) {
particle.tint = 0xFFd700;
particle.tint = 0xadff2f;
}
);
hitStarEmitter.gravity = 0;
+17 -8
View File
@@ -8,7 +8,7 @@ function Missile(spaceship, onCollisionFunction) {
this.isActivated = false;
this.speed = Missile.DEFAULT_SPEED_DOT_PER_SEC;
this.boostSpeed = Missile.DEFAULT_SPEED_DOT_PER_SEC / 10;
this.boostSpeed = Missile.DEFAULT_SPEED_DOT_PER_SEC / 5;
this.angleFromSpaceship = 0;
this.angleFromMissile = 0;
@@ -22,7 +22,6 @@ function Missile(spaceship, onCollisionFunction) {
this.anchor.set(0.5);
game.add.existing(this);
// game.physics.enable(this, Phaser.Physics.ARCADE);
game.physics.arcade.enable(this);
this.moveRandomPosition();
@@ -32,8 +31,8 @@ function Missile(spaceship, onCollisionFunction) {
Missile.prototype.moveRandomPosition = function() {
// move random position
this.angleFromMissile = game.rnd.integerInRange(0, 360);
// console.log(this.angleFromMissile);
var radians = this.angleFromMissile * Math.PI / 180;
@@ -43,16 +42,22 @@ Missile.prototype.moveRandomPosition = function() {
this.x = game.world.centerX + posX;
this.y = game.world.centerY + posY;
// this.x = this.spaceship.x + posX;
// this.y = this.spaceship.y + posY;
var MissileAngle = this.getAngle(this.spaceship.x, this.spaceship.y, this.x, this.y);
// set missile direction
var spaceshipAreaX = this.spaceship.x + this.getRandomArea();
var spaceshipAreaY = this.spaceship.y + this.getRandomArea();
var MissileAngle = this.getAngle(spaceshipAreaX, spaceshipAreaY, this.x, this.y);
this.angle = this.getSpriteAngle(MissileAngle);
this.angleFromMissile = MissileAngle;
}
this.upgradeLevel();
Missile.prototype.getRandomArea = function() {
var randomValue = Math.random();
var randomArea = Missile.SPACESHIP_RANDOM_AREA_MARGIN * randomValue - Missile.SPACESHIP_RANDOM_AREA_MARGIN / 2;
return randomArea;
}
Missile.prototype.update = function() {
@@ -73,8 +78,10 @@ Missile.prototype.update = function() {
var distanceX = this.x - game.world.centerX;
var distanceY = this.y - game.world.centerY;
var distanceFromCenter = Math.sqrt(Math.abs(distanceX * distanceX) + Math.abs(distanceY * distanceY));
if(distanceFromCenter > this.responRadius)
if(distanceFromCenter > this.responRadius) {
this.moveRandomPosition();
this.upgradeLevel();
}
}
@@ -176,3 +183,5 @@ Missile.DEFAULT_SPEED_DOT_PER_SEC = 150;
Missile.START_Radius_PX = 600;
Missile.START_RANDOM_Radius_PERCENT = 40;
Missile.SPACESHIP_RANDOM_AREA_MARGIN = 100;
+3 -2
View File
@@ -5,13 +5,14 @@ function Spaceship() {
this.isActivated = false;
this.speed = Spaceship.DEFAULT_SPEED;
Phaser.Sprite.call(this, game, game.world.centerX, game.world.centerY, 'spaceship');
Phaser.Sprite.call(this, game, game.world.centerX, game.world.centerY, 'alien');
game.add.existing(this);
game.physics.arcade.enable(this);
this.scale.set(1);
this.anchor.set(0.5);
this.halfWidth = this.width / 2;
game.physics.arcade.enable(this);
// this.setActive(true);
}
+8 -13
View File
@@ -1,13 +1,12 @@
function StopWatch() {
this.ellpasedTime = 0;
this.startTime = 0;
this.isPaused = true;
var fontStyle = StopWatch.DEFAULT_TEXT_FONT;
fontStyle.align = "right";
fontStyle.boundsAlignH = "right";
this.timerText = game.add.text(game.world.width - 200, 35, "", fontStyle);
this.timerText.anchor.set(0, 0.5);
this.timerText = game.add.text(game.world.centerX, 35, "", fontStyle);
this.timerText.anchor.set(0.5);
// var grd = this.label.context.createLinearGradient(0, 0, 0, StopWatch.FONT_HEIGHT_PX);
// grd.addColorStop(0, '#8ED6FF');
@@ -20,15 +19,16 @@ function StopWatch() {
// this.label.strokeThickness = 3;
this.timerEvent = null;
};
}
StopWatch.prototype.start = function() {
this.isPaused = false;
this.startTime = game.time.totalElapsedSeconds();
console.log(this.startTime);
this.printTime();
if(this.timerEvent === null)
this.timerEvent = game.time.events.loop(Phaser.Timer.SECOND / 10, this.updateTimer, this);
this.timerEvent = game.time.events.loop(Phaser.Timer.SECOND / 100, this.updateTimer, this);
}
StopWatch.prototype.pause = function() {
@@ -57,12 +57,7 @@ StopWatch.prototype.updateTimer = function() {
}
StopWatch.prototype.printTime = function() {
var ellapsedTimeText = this.ellpasedTime.toString();
var timeText = "";
if(ellapsedTimeText.length == 1)
timeText = ellapsedTimeText + ".0";
else
timeText = ellapsedTimeText.substring(0, 3);
var timeText = this.ellpasedTime.toFixed(2);
this.timerText.text = timeText + "초";
}
+11 -9
View File
@@ -51,20 +51,22 @@ HistoryBoard.prototype.calcDate = function(daysBefore) {
HistoryBoard.prototype.printRecord = function(index, date, bestRecord) {
var posX = 60;
var posX = 130;
var posY = game.world.height / 2 + 90 + 30 * index;
var style = { font: "20px Arial", fill: "#ffc", align: "right", boundsAlignH: "right", boundsAlignV: "top" };
style.boundsAlignH = "center";
game.add.text(posX, posY, StringUtil.printMonthDay(date), style)
.setTextBounds(0, 0, 100, 60)
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
var dateText = game.add.text(posX, posY, StringUtil.printMonthDay(date), style);
dateText.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
dateText.anchor.set(1, 0);
style.boundsAlignH = "right";
game.add.text(posX + 80, posY, StringUtil.getRecordTextWithoutUnit(bestRecord), style)
.setTextBounds(0, 0, 100, 60)
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
var recordText = game.add.text(
posX + 120, posY,
RecordUtil.getRecordValueWithUnit(bestRecord, sessionStorageManager.getPlayingAppID()),
style
);
recordText.anchor.set(1, 0);
recordText.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
}
HistoryBoard.prototype.printSample = function() {
+6 -7
View File
@@ -126,23 +126,22 @@ RankingBoard.prototype.printRecord = function(type, index, data) {
var style = { font: "20px Arial", fill: "#fff", align: "right", boundsAlignH: "right", boundsAlignV: "top" };
// rank
style.boundsAlignH = "right";
// style.boundsAlignH = "right";
var rankText = game.add.text(this.getPosX(type), this.getPosY(index), data.rank, style);
// .setTextBounds(0, 0, 40, 40)
rankText.anchor.set(1, 0);
rankText.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
// player name
var playerNameText = game.add.text(this.getPosX(type) + 20, this.getPosY(index), data.playerName, style);
// .setTextBounds(0, 0, 60, 60)
playerNameText.anchor.set(0, 0);
playerNameText.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
// bestRecord
var bestRecord = StringUtil.getRecordTextWithoutUnit(data.bestRecord);
style.boundsAlignH = "right";
var recordText = game.add.text(this.getPosX(type) + 180, this.getPosY(index), bestRecord, style);
// .setTextBounds(0, 0, 80, 60)
var recordText = game.add.text(
this.getPosX(type) + 180, this.getPosY(index),
RecordUtil.getRecordValueWithUnit(data.bestRecord, sessionStorageManager.getPlayingAppID()),
style
);
recordText.anchor.set(1, 0);
recordText.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
}
+4 -24
View File
@@ -58,7 +58,7 @@ var Result = {
// bottom ui
var screenBottomUI = new ScreenBottomUI();
screenBottomUI.printLeftTextWithAppHighestRecord(Math.floor(sessionStorageManager.getAppHighestRecord()));
screenBottomUI.printLeftTextWithAppHighestRecord(sessionStorageManager.getAppHighestRecord());
screenBottomUI.printCenterText(sessionStorageManager.getPlayingAppKoreanName());
screenBottomUI.printRightText(sessionStorageManager.getPlayerName());
},
@@ -87,16 +87,6 @@ var Result = {
if(sessionStorageManager.getRecord() === null)
sessionStorageManager.setRecord(0);
var record = 0;
if(sessionStorageManager.getPlayingAppID() == 104) {
var recordTime = sessionStorageManager.getRecord();
record = recordTime.toFixed(3);
} else {
record = NumberUtil.numberWithCommas(Math.floor(sessionStorageManager.getRecord()));
}
style.font = "80px Arial";
if(isTypingPracticeApp() || isTypingTestApp()) {
var animalLevelID = 0;
if(isTypingPracticeApp())
@@ -111,27 +101,17 @@ var Result = {
rightAnimal.startAnimation(Animal.SPECIES_DATA[animalLevelID]);
}
var record = sessionStorageManager.getRecord();
style.font = "80px Arial";
var scoreText = game.add.text(
x, y,
record + StringUtil.getScoreUnit(sessionStorageManager.getPlayingAppID()),
RecordUtil.getRecordValueWithUnit(record, sessionStorageManager.getPlayingAppID()),
style
);
scoreText.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
scoreText.anchor.set(0.5);
},
/*
recordUnit: function() {
var recordUnit = "";
if(sessionStorageManager.getPlayingAppID() == 104)
return "초";
else if(sessionStorageManager.getPlayingAppID() >= 100)
return "점";
else
return "타";
},
*/
printTodayBestRecord: function() {
var newRecordEmitter = game.add.emitter(game.world.centerX, 140, 300);
newRecordEmitter.makeParticles('star');
+3 -4
View File
@@ -22,8 +22,8 @@
})(window,document,'script','dataLayer','GTM-N8PB4F3');</script>
<!-- End Google Tag Manager -->
<title>외계인 피하기, 초코마에</title>
<meta name="description" CONTENT="외계인 피하기 - 마우스 움직임 연습 앱 | 초코마에, Dodge aliens - Mouse moving practice app | chcomae">
<title>미사일 피하기, 초코마에</title>
<meta name="description" CONTENT="미사일 피하기 - 마우스 움직임 연습 앱 | 초코마에, Dodge missiles - Mouse moving practice app | chcomae">
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
@@ -57,8 +57,7 @@
<!-- Space Invaders : source files -->
<script src="../../game/mouse/dodge/loading.js"></script>
<script src="../../game/mouse/dodge/spaceship.js"></script>
<script src="../../game/mouse/dodge/alien.js"></script>
<!-- <script src="../../game/mouse/dodge/missile.js"></script> -->
<script src="../../game/mouse/dodge/missile.js"></script>
<script src="../../game/mouse/dodge/stop_watch.js"></script>
<script src="../../game/mouse/dodge/game.js"></script>
<script src="../../game/mouse/dodge/main.js"></script>
+1
View File
@@ -20,6 +20,7 @@
<script src="../../game/lib/keyboard_shortcut.js"></script>
<script src="../../game/lib/number_util.js"></script>
<script src="../../game/lib/string_util.js"></script>
<script src="../../game/lib/record_util.js"></script>
<script src="../../game/lib/date_util.js"></script>
<script src="../../game/lib/history_record_manager.js"></script>
<script src="../../game/lib/ranking_record_manager.js"></script>