Created
July 28, 2013 15:55
-
-
Save Akiyah/6099057 to your computer and use it in GitHub Desktop.
forked: Move Bear
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
参考: | |
夏休みに息子とゲームを作ることにした | |
http://black.ap.teacup.com/akiyah/1810.html | |
TODO: | |
・3キャラごとに耐久力を変える | |
・ステージクリアして次のステージに行けるようにする | |
・Nexus7のSleipnirでダブルタッチしても拡大縮小が動かないようにする | |
・blogに張った時にタッチできないようなので何とかする | |
・ハイスコア | |
DONE: | |
・タッチだけでなくマウスクリックでも倒せるようにする | |
・最初のカウントダウンを削除する | |
・キャラをもっとたくさん出す | |
・3キャラごとに速度を変える | |
・3キャラの登場パターンをランダムにする | |
・3キャラの画像を変更する(画像待ち) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { background-color: #DDDDDD; font: 30px sans-serif; margin:0px; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<canvas id='world'></canvas> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// forked from develop_sector2's "Move Bear" http://jsdo.it/develop_sector2/aqe2 | |
enchant(); | |
var game; | |
var score = 0; | |
var CharSprite = Class.create( Sprite , { | |
initialize : function(){ | |
Sprite.call(this,32,32); | |
this.image = game.assets['http://jsrun.it/assets/n/f/5/z/nf5zp.gif']; | |
//this.x = 100; | |
//this.time = 0; | |
//this.idx = 0; | |
//this.interval = 0; | |
//this.num = 0; | |
this.anime = {time:0,idx:0,interval:0,frames:[0]}; | |
//this.active = false; | |
this.deadTime = 0; | |
}, | |
// 初期位置、初期速度の設定。(startFrame は移動開始するgame.frame の値) | |
InitSetting : function(x,y,x_sp,y_sp,startFrame,point){ | |
this.x = x; | |
this.y = y; | |
this.x_sp = x_sp; | |
this.y_sp = y_sp; | |
this.startFrame = startFrame; | |
this.point = point; | |
//this.active = true; | |
game.rootScene.addChild(this); | |
if( x_sp < 0 ) { | |
this.scaleX = -1; | |
} | |
this.deadTime = 0; | |
}, | |
// 生きている時のアニメーション設定 | |
// interval : 再生間隔 | |
// frames : アニメーションに使うフレーム配列 | |
InitAnimation : function(interval,frames, deadFrame){ | |
this.anime.interval = interval; | |
this.anime.frames = frames; | |
this.frame = frames[0]; | |
this.deadFrame = deadFrame; | |
}, | |
// アニメーション処理全般 | |
AnimeFrame : function(){ | |
var max = 0; | |
// 生きている時のアニメーション | |
if( this.deadTime == 0 ){ | |
var index = Math.floor(game.frame / this.anime.interval) % this.anime.frames.length; | |
this.frame = this.anime.frames[index]; | |
// 死んだときのアニメーション | |
} else { | |
var time = ( game.frame - this.deadTime ); | |
this.frame = this.deadFrame; | |
if( time < 30 ){ | |
if( ( time % 2 ) == 0 ){ | |
this.scaleX = 1.1; | |
this.scaleY = 1.1; | |
} else { | |
this.scaleX = 0.9; | |
this.scaleY = 0.9; | |
} | |
if( this.x_sp < 0 ) { | |
this.scaleX *= -1; | |
} | |
} else { | |
game.rootScene.removeChild(this); | |
} | |
} | |
}, | |
// 移動処理全般 | |
Move : function(){ | |
if( this.startFrame < game.frame && this.deadTime == 0 ){ | |
this.x += this.x_sp; | |
this.y += this.y_sp; | |
// 範囲外に出たら消えるように | |
if( (this.x < -500 )||(500 < this.x)||(this.y < -500 )|(500 < this.y) ){ | |
game.rootScene.removeChild(this); | |
} | |
} | |
}, | |
// マイフレーム毎の処理 | |
onenterframe : function(){ | |
this.AnimeFrame(); | |
this.Move(); | |
}, | |
ontouchstart : function(){ | |
if( this.deadTime == 0 ){ | |
score += this.point; | |
this.deadTime = game.frame; | |
} | |
} | |
}); | |
window.onload = function() { | |
game = new Game(320,320); | |
game.preload( | |
'http://jsrun.it/assets/n/f/5/z/nf5zp.gif', | |
'http://jsrun.it/assets/2/A/U/a/2AUaq.gif'); | |
game.addChar = function(type, frame){ | |
var interval; | |
var frames; | |
var deadFrame; | |
var point; | |
switch( type ){ | |
case 1: | |
interval = 5; | |
frames = [15,16,15,17]; | |
deadFrame = 18; | |
point = 1; | |
break; | |
case 2: | |
interval = 3; | |
frames = [20,21,20,22]; | |
deadFrame = 23; | |
point = 2; | |
break; | |
case 3: | |
interval = 1; | |
frames = [25,26,25,27]; | |
deadFrame = 28; | |
point = 3; | |
break; | |
} | |
var x_type = Math.random() > 0.5; | |
var x = x_type ? 330 : -40; | |
var x_sp = (x_type ? -2 : 2) * type / 5; | |
var y = 20 + 200 * Math.random(); | |
var y_sp = (Math.random()*4 -2) * type / 5; | |
var bear = new CharSprite(); | |
bear.InitAnimation( interval , frames, deadFrame ); | |
bear.InitSetting(x,y,x_sp,y_sp,frame,type); | |
} | |
game.addLabel = function( text , color , x , y ){ | |
var label = new Label(text); | |
label.font = "16px monospace"; | |
label.color = color; | |
label.x = x; | |
label.y = y; | |
game.rootScene.addChild(label); | |
}; | |
game.rootScene.addEventListener(Event.ENTER_FRAME,function(){ | |
if( ( game.frame > ( 1 * 20 * 30 ) - 100 ) ){ | |
// ゲーム終了処理 | |
game.addLabel( "Game is Over!" , "rgb(255,0,0)",10,10); | |
game.addLabel( "score = " + score , "rgb(0,0,0)", 10,50); | |
game.stop(); | |
} | |
}); | |
function init_mark(scene) { | |
var mark = new Sprite(32,32); | |
mark.image = game.assets['http://jsrun.it/assets/2/A/U/a/2AUaq.gif']; | |
scene.addChild(mark); | |
scene.addEventListener(Event.TOUCH_START,function(e){ | |
var x = e.x - (mark.width/2); // スプライト幅の半分の値を引くことで中央にする | |
var y = e.y - (mark.height/2); // スプライト高さの半分の値を引くことで中央にする | |
mark.moveTo(x, y); | |
}); | |
} | |
game.onload = function(){ | |
init_mark(game.rootScene); | |
var i; | |
game.frame = 0; | |
for( i = 0 ; i < 300/5 ; i++ ) { | |
var frame = (i + 1) * 5; | |
var type = Math.floor(Math.random()*3) + 1; | |
game.addChar( type, frame ); | |
} | |
}; | |
game.start(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment