Add: dodge app
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
Alien.prototype = Object.create(Phaser.Sprite.prototype);
|
||||
Alien.constructor = Alien;
|
||||
|
||||
function Alien(spaceship) {
|
||||
this.spaceship = spaceship;
|
||||
|
||||
this.isActivated = false;
|
||||
this.speed = Alien.DEFAULT_SPEED_DOT_PER_SEC;
|
||||
this.angleFromSpaceship = 0;
|
||||
this.angleFromAlien = 0;
|
||||
|
||||
Phaser.Sprite.call(this, game, 0, 0, 'alien_normal');
|
||||
this.anchor.set(0.5);
|
||||
|
||||
game.add.existing(this);
|
||||
this.moveRandomPosition();
|
||||
|
||||
this.setActive(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Alien.prototype.moveRandomPosition = function() {
|
||||
this.angleFromAlien = game.rnd.integerInRange(0, 360);
|
||||
// console.log(this.angleFromAlien);
|
||||
|
||||
var radians = this.angleFromAlien * Math.PI / 180;
|
||||
|
||||
var radious = Alien.START_RADIOUS_PX * ( ( (100 + game.rnd.integerInRange(0, Alien.START_RANDOM_RADIOUS_PERCENT) ) / 100) );
|
||||
var posX = Math.sin(radians) * radious;
|
||||
var posY = Math.cos(radians) * radious;
|
||||
|
||||
this.x = this.spaceship.x + posX;
|
||||
this.y = this.spaceship.y + posY;
|
||||
|
||||
this.angle = this.getSpriteAngle(this.angleFromAlien);
|
||||
}
|
||||
|
||||
Alien.prototype.update = function() {
|
||||
if(!this.isActivated)
|
||||
return;
|
||||
|
||||
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 > Alien.START_RADIOUS_PX)
|
||||
this.moveRandomPosition();
|
||||
}
|
||||
|
||||
|
||||
Alien.prototype.stop = function() {
|
||||
this.setActive(false);
|
||||
}
|
||||
|
||||
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.goRandomPosition = function() {
|
||||
// set random position
|
||||
var SPAWN_BOX_LEFT = 80;
|
||||
var SPAWN_BOX_WIDTH = game.world.width - 160;
|
||||
var SPAWN_BOX_TOP = 280;
|
||||
var SPAWN_BOX_HEIGHT = game.world.height - 400;
|
||||
|
||||
this.x = SPAWN_BOX_LEFT + Math.random() * SPAWN_BOX_WIDTH;
|
||||
this.y = SPAWN_BOX_TOP + Math.random() * SPAWN_BOX_HEIGHT;
|
||||
|
||||
// if(isDebugMode()) {
|
||||
// this.game.add.graphics()
|
||||
// .beginFill(0xffffff, 0.1)
|
||||
// .drawRect(SPAWN_BOX_LEFT, SPAWN_BOX_TOP, SPAWN_BOX_WIDTH, SPAWN_BOX_HEIGHT);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Alien.DEFAULT_SPEED_DOT_PER_SEC = 100;
|
||||
|
||||
Alien.START_RADIOUS_PX = 600;
|
||||
Alien.START_RANDOM_RADIOUS_PERCENT = 40;
|
||||
@@ -0,0 +1,137 @@
|
||||
var Game = {
|
||||
|
||||
create: function() {
|
||||
this.game.stage.backgroundColor = "#000000"; // '#4d4d4d';
|
||||
|
||||
this.scoreManager = new ScoreManager();
|
||||
|
||||
sessionStorageManager.setIsNewAppHighestRecord(false);
|
||||
|
||||
var experienceAppTimer = new ExperienceAppTimer();
|
||||
experienceAppTimer.setTimeOverListener(
|
||||
(function() { this.gameOver(); }).bind(this)
|
||||
);
|
||||
|
||||
// keyboard shortcut
|
||||
this.keyboardShortcut = new KeyboardShortcut();
|
||||
this.keyboardShortcut.addCallback(
|
||||
Phaser.KeyCode.ESC, // keyCode
|
||||
null, // keyDownHandler
|
||||
(function() { this.back(); }).bind(this), // keyUpHandler
|
||||
"dodge" // callerClassName
|
||||
);
|
||||
|
||||
// game stage
|
||||
var stars = game.add.group();
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// contents
|
||||
this.spaceship = new Spaceship();
|
||||
|
||||
this.aliens = [];
|
||||
for(var i = 0; i < 50; i++) {
|
||||
var alien = new Alien(this.spaceship);
|
||||
this.aliens.push(alien);
|
||||
}
|
||||
|
||||
|
||||
// top ui
|
||||
var screenTopUI = new ScreenTopUI();
|
||||
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());
|
||||
});
|
||||
|
||||
|
||||
// bottom ui
|
||||
var screenBottomUI = new ScreenBottomUI();
|
||||
screenBottomUI.printLeftTextWithAppHighestRecord(sessionStorageManager.getAppHighestRecord());
|
||||
screenBottomUI.printCenterText(sessionStorageManager.getPlayingAppKoreanName());
|
||||
screenBottomUI.printRightText(sessionStorageManager.getPlayerName());
|
||||
|
||||
|
||||
this.startGame();
|
||||
// this.countDown();
|
||||
},
|
||||
|
||||
|
||||
back: function() {
|
||||
sessionStorageManager.resetPlayingAppData();
|
||||
location.href = '../../web/client/menu_app.html';
|
||||
},
|
||||
|
||||
initListeners: function() {
|
||||
},
|
||||
|
||||
/*
|
||||
countDown() {
|
||||
var style = { font: "bold 200px Arial", fill: "#fff", boundsAlignH: "center", boundsAlignV: "middle" };
|
||||
this.countDownText = game.add.text(0, 0, "", style);
|
||||
this.countDownText.setTextBounds(0, 0, game.world.width, game.world.height);
|
||||
this.countDownText.stroke = "#333";
|
||||
this.countDownText.strokeThickness = 50;
|
||||
|
||||
this.countDownNumber = 3;
|
||||
if(isDebugMode())
|
||||
this.countDownNumber = 1;
|
||||
this.tweenCountDown();
|
||||
}
|
||||
|
||||
tweenCountDown() {
|
||||
if(this.countDownNumber === 0) {
|
||||
this.startGame();
|
||||
return;
|
||||
}
|
||||
|
||||
this.countDownText.text = this.countDownNumber.toString();
|
||||
this.countDownText.alpha = 1;
|
||||
|
||||
var countDownTween = game.add.tween(this.countDownText);
|
||||
countDownTween.to( { alpha: 0 }, 1000, Phaser.Easing.Linear.None, true);
|
||||
countDownTween.onComplete.add(this.tweenCountDown, this);
|
||||
|
||||
this.countDownNumber--;
|
||||
}
|
||||
*/
|
||||
|
||||
startGame: function() {
|
||||
},
|
||||
|
||||
gameOver: function() {
|
||||
var gameOverText = new GameOverText();
|
||||
|
||||
game.time.events.add(GAME_OVER_WAIT_TIME_MS, this.goResult, this);
|
||||
},
|
||||
|
||||
goResult: function() {
|
||||
location.href = '../../web/client/result.html';
|
||||
},
|
||||
|
||||
getScore: function() {
|
||||
return (this.alienTimer.activatedAlienIndex) * 2;
|
||||
},
|
||||
|
||||
onAlienEscaped: function() {
|
||||
this.heartManager.breakHearts(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Game.GAME_OVER_WAIT_TIME_MS = 2000;
|
||||
@@ -0,0 +1,94 @@
|
||||
var Loading = {
|
||||
|
||||
preload: function() {
|
||||
// game.load.image('loadingbar', './image/phaser.png');
|
||||
},
|
||||
|
||||
create: function() {
|
||||
// var userID = sessionStorage.getItem("UserID");
|
||||
// console.log("userID : " + userID);
|
||||
|
||||
// game.stage.backgroundColor = '#4d4d4d';
|
||||
|
||||
// // Progress report
|
||||
// this.textProgress = game.add.text(game.world.centerX, 100, '로딩중 . . .', textStyleBasic);
|
||||
// this.textProgress.anchor.setTo(0.5, 0.4);
|
||||
// this.textProgress.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
|
||||
|
||||
// // Preload bar
|
||||
// this.preloadBar = this.add.sprite(game.world.centerX, game.world.centerY, 'loadingbar');
|
||||
// this.preloadBar.anchor.setTo(0.5);
|
||||
// this.preloadBar.alpha = 0;
|
||||
|
||||
game.load.onFileComplete.add(this.fileComplete, this);
|
||||
game.load.onLoadComplete.add(this.loadComplete, this);
|
||||
|
||||
this.startLoading();
|
||||
},
|
||||
|
||||
startLoading: function() {
|
||||
game.load.image('icon_fullscreen', '../../../resources/image/icon/fullscreen_white.png');
|
||||
|
||||
game.load.image('star', '../../../resources/image/background/star_7x7.png');
|
||||
|
||||
game.load.image('alien_normal', '../../../resources/image/character/alien/green_alien.png');
|
||||
|
||||
game.load.image('heart_full', '../../../resources/image/ui/heart_full.png');
|
||||
game.load.image('heart_empty', '../../../resources/image/ui/heart_empty.png');
|
||||
// game.load.image('a', '../../../resources/image/icon/fullscreen_white.png');
|
||||
// game.load.image('b', '../../../resources/image/icon/fullscreen_white.png');
|
||||
// game.load.image('c', '../../../resources/image/icon/fullscreen_white.png');
|
||||
// game.load.image('d', '../../../resources/image/icon/fullscreen_white.png');
|
||||
// game.load.image('a', './image/phaser.png');
|
||||
// game.load.image('b', './image/phaser.png');
|
||||
// game.load.image('c', './image/phaser.png');
|
||||
// game.load.image('d', './image/phaser.png');
|
||||
// game.load.image('e', './image/phaser.png');
|
||||
// game.load.image('g', './image/phaser.png');
|
||||
// game.load.image('e', './image/phaser.png');
|
||||
// game.load.image('f', './image/phaser.png');
|
||||
// game.load.image('g', './image/phaser.png');
|
||||
// game.load.image('h', './image/phaser.png');
|
||||
|
||||
// game.load.image('phaser', './image/phaser.png');
|
||||
// game.load.spritesheet('button', './image/button_basic.png', 200, 100);
|
||||
// game.load.image('star', './image/star_particle.png');
|
||||
// game.load.image('medal_gold', './image/medal_gold.png');
|
||||
// game.load.image('medal_silver', './image/medal_silver.png');
|
||||
// game.load.image('medal_bronze', './image/medal_bronze.png');
|
||||
|
||||
game.load.start();
|
||||
},
|
||||
|
||||
fileComplete: function(progress, cacheKey, success, totalLoaded, totalFiles) {
|
||||
// this.preloadBar.alpha = progress / 100;
|
||||
|
||||
// console.log('progress : ' + progress);
|
||||
|
||||
// text.setText("File Complete: " + progress + "% - " + totalLoaded + " out of " + totalFiles);
|
||||
|
||||
// var newImage = game.add.image(x, y, cacheKey);
|
||||
// newImage.scale.set(0.3);
|
||||
|
||||
// x += newImage.width + 20;
|
||||
// if (x > 700)
|
||||
// {
|
||||
// x = 32;
|
||||
// y += 332;
|
||||
// }
|
||||
},
|
||||
|
||||
loadComplete: function(progress, cacheKey, success, totalLoaded, totalFiles) {
|
||||
// this.preloadBar.alpha = 1;
|
||||
|
||||
if(isDebugMode()) {
|
||||
this.state.start('Game');
|
||||
return;
|
||||
}
|
||||
|
||||
this.state.start('Game');
|
||||
// this.startMenu();
|
||||
// this.startTypingTestStage();
|
||||
// this.startTypingTestResult();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/////////////////////////////
|
||||
// Main game
|
||||
|
||||
var CONTENT_ID = "Space Invaders";
|
||||
|
||||
var game = new Phaser.Game(
|
||||
GAME_SCREEN_SIZE.x, GAME_SCREEN_SIZE.y,
|
||||
Phaser.CANVAS, CONTENT_ID,
|
||||
this, false, false
|
||||
);
|
||||
|
||||
game.state.add('Loading', Loading);
|
||||
game.state.start('Loading');
|
||||
|
||||
game.state.add('Game', Game);
|
||||
// game.state.add('Menu', Menu);
|
||||
@@ -0,0 +1,92 @@
|
||||
Spaceship.prototype = Object.create(Phaser.Sprite.prototype);
|
||||
Spaceship.constructor = Spaceship;
|
||||
|
||||
function Spaceship() {
|
||||
this.isActivated = false;
|
||||
this.isOnWaitingRoom = true;
|
||||
this.speed = Spaceship.DEFAULT_SPEED;
|
||||
|
||||
Phaser.Sprite.call(this, game, game.world.centerX, game.world.centerY, 'heart_full');
|
||||
game.add.existing(this);
|
||||
this.scale.set(0.5);
|
||||
this.anchor.set(0.5);
|
||||
this.halfWidth = this.width / 2;
|
||||
|
||||
game.physics.enable(this, Phaser.Physics.ARCADE);
|
||||
|
||||
this.setActive(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Spaceship.prototype.update = function() {
|
||||
if(this.isActivated) {
|
||||
game.physics.arcade.moveToPointer(this, this.speed);
|
||||
|
||||
if(Phaser.Rectangle.contains(this.body, game.input.x, game.input.y)) {
|
||||
this.stop();
|
||||
this.setDirection(Spaceship.DIR_MIDDLE);
|
||||
return;
|
||||
}
|
||||
|
||||
if(this.x - this.halfWidth < game.input.x && game.input.x < this.x + this.halfWidth) {
|
||||
this.setDirection(Spaceship.DIR_MIDDLE);
|
||||
} else if(this.x > game.input.x) {
|
||||
this.setDirection(Spaceship.DIR_LEFT);
|
||||
} else {
|
||||
this.setDirection(Spaceship.DIR_RIGHT);
|
||||
}
|
||||
} else {
|
||||
this.stop();
|
||||
}
|
||||
}
|
||||
|
||||
Spaceship.prototype.setDirection = function(dir) {
|
||||
switch(dir) {
|
||||
case Spaceship.DIR_LEFT:
|
||||
this.tint = 0x99ff99;
|
||||
break;
|
||||
|
||||
case Spaceship.DIR_MIDDLE:
|
||||
this.tint = 0xffffff;
|
||||
break;
|
||||
|
||||
case Spaceship.DIR_RIGHT:
|
||||
this.tint = 0x9999ff;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Spaceship.prototype.stop = function() {
|
||||
this.body.velocity.setTo(0, 0);
|
||||
}
|
||||
|
||||
Spaceship.prototype.setActive = function(isActivated) {
|
||||
this.isActivated = isActivated;
|
||||
}
|
||||
|
||||
Spaceship.prototype.goRandomPosition = function() {
|
||||
// set random position
|
||||
var SPAWN_BOX_LEFT = 80;
|
||||
var SPAWN_BOX_WIDTH = game.world.width - 160;
|
||||
var SPAWN_BOX_TOP = 280;
|
||||
var SPAWN_BOX_HEIGHT = game.world.height - 400;
|
||||
|
||||
this.x = SPAWN_BOX_LEFT + Math.random() * SPAWN_BOX_WIDTH;
|
||||
this.y = SPAWN_BOX_TOP + Math.random() * SPAWN_BOX_HEIGHT;
|
||||
|
||||
// if(isDebugMode()) {
|
||||
// this.game.add.graphics()
|
||||
// .beginFill(0xffffff, 0.1)
|
||||
// .drawRect(SPAWN_BOX_LEFT, SPAWN_BOX_TOP, SPAWN_BOX_WIDTH, SPAWN_BOX_HEIGHT);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Spaceship.DEFAULT_SPEED = 200;
|
||||
|
||||
Spaceship.DIR_LEFT = 0;
|
||||
Spaceship.DIR_MIDDLE = 1;
|
||||
Spaceship.DIR_RIGHT = 2;
|
||||
@@ -0,0 +1,80 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
|
||||
<meta charset="UTF-8">
|
||||
|
||||
<!-- Global site tag (gtag.js) - Google Analytics -->
|
||||
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-85912788-2"></script>
|
||||
<script>
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
function gtag(){dataLayer.push(arguments);}
|
||||
gtag('js', new Date());
|
||||
|
||||
gtag('config', 'UA-85912788-2');
|
||||
</script>
|
||||
|
||||
<!-- Google Tag Manager -->
|
||||
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
|
||||
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
|
||||
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
|
||||
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
|
||||
})(window,document,'script','dataLayer','GTM-N8PB4F3');</script>
|
||||
<!-- End Google Tag Manager -->
|
||||
|
||||
<title>미사일 피하기, 초코마에</title>
|
||||
<meta name="description" CONTENT="외계인 침공 Space Invaders, 마우스 클릭 연습 앱 mouse click practice app, 초코마에 chcomae">
|
||||
|
||||
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
|
||||
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
|
||||
|
||||
<!-- <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script> -->
|
||||
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/2.6.2/phaser.js"></script> -->
|
||||
<script src="../../../resources/js/phaser.min.js"></script>
|
||||
|
||||
<!-- global source files -->
|
||||
<script src="../../game/lib/session_storage_manager.js"></script>
|
||||
<script src="../../game/lib/score_manager.js"></script>
|
||||
<script src="../../game/lib/heart_manager.js"></script>
|
||||
<script src="../../game/global/global_variables.js"></script>
|
||||
|
||||
<!-- library source files -->
|
||||
<script src="../../game/lib/keyboard_shortcut.js"></script>
|
||||
<script src="../../game/lib/number_util.js"></script>
|
||||
<script src="../../game/lib/history_record_manager.js"></script>
|
||||
<script src="../../game/lib/input_type_text.js"></script>
|
||||
<script src="../../game/lib/score_board.js"></script>
|
||||
<script src="../../game/lib/score_text.js"></script>
|
||||
<script src="../../game/lib/button/round_rect_button.js"></script>
|
||||
<script src="../../game/lib/button/back_button.js"></script>
|
||||
<script src="../../game/lib/button/fullscreen_button.js"></script>
|
||||
<script src="../../game/lib/db_connect_manager.js"></script>
|
||||
<script src="../../game/lib/screen_top_ui.js"></script>
|
||||
<script src="../../game/lib/screen_bottom_ui.js"></script>
|
||||
<script src="../../game/lib/experience_app_timer.js"></script>
|
||||
<script src="../../game/lib/game_over_text.js"></script>
|
||||
|
||||
<!-- 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/game.js"></script>
|
||||
<script src="../../game/mouse/dodge/main.js"></script>
|
||||
|
||||
|
||||
<style>
|
||||
body{
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
canvas{
|
||||
margin: 0 auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="Space Invaders" style="text-align:center;"></div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user