¥È¥Ã¥×   ¿·µ¬ °ìÍ÷ ñ¸ì¸¡º÷ ºÇ½ª¹¹¿·   ¥Ø¥ë¥×   ºÇ½ª¹¹¿·¤ÎRSS

JavaScript/tmlib.js/sample/Èò¤±¥²¡¼(³«»Ï, ½ªÎ»²èÌ̤¢¤ê) ¤Î¥Ð¥Ã¥¯¥¢¥Ã¥×(No.1)


phi»á¤ÎºîÀ®¤µ¤ì¤¿¥·¥å¡¼¥Æ¥£¥ó¥°¥²¡¼¥à¤Î¥µ¥ó¥×¥ë¥¢¥×¥ê¤Ç¤¹¡£jsdo.it¤Î¥³¡¼¥É²èÌ̤Ͼ®¤µ¤¯¤Æ¸«¤Ë¤¯¤¤¤Î¤Ç°úÍѤµ¤»¤Æ¤¤¤¿¤À¤¤¤Æ¤Þ¤¹¡£¥ª¥ê¥¸¥Ê¥ë¤Ï¤³¤Á¤é¤Ç¤¹¡£

#pre{{
// forked from phi's "Èò¤±¥²¡¼ - tmlib.js #techbuzz" http://jsdo.it/phi/gEhZ
/*
* Äê¿ô
*/
var SCREEN_WIDTH = 465;
var SCREEN_HEIGHT = 465;
var SCREEN_CENTER_X = SCREEN_WIDTH/2;
var SCREEN_CENTER_Y = SCREEN_HEIGHT/2;
var PLAYER_SIZE = 32;

/*
* ¥°¥í¡¼¥Ð¥ëÊÑ¿ô
*/
var app = null;
var enemyList = null;

/*
* ¥×¥ì¥¤¥ä¡¼
*/
var Player = tm.createClass({
superClass: tm.app.TriangleShape,
// ½é´ü²½
init: function() {
this.superInit(PLAYER_SIZE, PLAYER_SIZE);
},
// ¹¹¿·
update: function(app) {
var p = app.pointing;
// ¥Þ¥¦¥¹¥À¥¦¥ó or ¥¿¥Ã¥ÁȽÄê
if (p.getPointing()) {
// °ÜÆ°
this.x += app.pointing.deltaPosition.x*1.25;
// ²èÌÌÆâÀ©¸æ
if (this.x < 0) { this.x = 0; }
else if (this.x > SCREEN_WIDTH) { this.x = SCREEN_WIDTH; }
}
}
});

/*
* ¥¨¥Í¥ß¡¼
*/
var Enemy = tm.createClass({
superClass: tm.app.StarShape,
// ½é´ü²½
init: function() {
this.superInit(PLAYER_SIZE, PLAYER_SIZE);
},
// ¹¹¿·
update: function(app) {
this.y += 8; // °ÜÆ°
this.rotation += 15; // ²óž
// ºï½üȽÄê
if (this.y > SCREEN_HEIGHT) {
this.remove();
enemyList.erase(this);
}
}
});

var TitleScene = tm.createClass({
superClass: tm.app.TitleScene,

init: function() {
this.superInit({
title: "Èò¤±¥²¡¼ - tmlib.js",
width: SCREEN_WIDTH,
height: SCREEN_HEIGHT
});
},

onnextscene: function() {
var mainScene = new MainScene();
app.replaceScene(mainScene);
}
});
var ResultScene = tm.createClass({
superClass: tm.app.ResultScene,

init: function() {
this.superInit({
score: app.frame,
msg: "Game Over!",
width: SCREEN_WIDTH,
height: SCREEN_HEIGHT
});
},

onnextscene: function() {
app.replaceScene(TitleScene());
}
});

var MainScene = tm.createClass({
superClass: tm.app.Scene,
init: function() {
this.superInit();

enemyList = [];

// ¥×¥ì¥¤¥ä¡¼
this.player = Player();
this.addChild(this.player);
this.player.x = SCREEN_CENTER_X;
this.player.y = SCREEN_HEIGHT-100;
},

update: function() {
// ¥¨¥Í¥ß¡¼À¸À®
if (app.frame % 8 == 0) {
// ¥¨¥Í¥ß¡¼
var enemy = Enemy();
enemy.x = tm.util.Random.randint(0, SCREEN_WIDTH);
enemy.y = -50;
this.addChild(enemy); // ¥·¡¼¥ó¤ËÄɲÃ
enemyList.push(enemy); // ¥ê¥¹¥È¤ËÄɲÃ
}

// ¥×¥ì¥¤¥ä¡¼, ¥¨¥Í¥ß¡¼¾×ÆÍȽÄê
for (var i=0,len=enemyList.length; i<len; ++i) {
var enemy = enemyList[i];
// ¾×ÆÍȽÄê
if (this.player.isHitElement(enemy)) {
// Game Over
app.replaceScene(ResultScene());
}
}
}
});


/* * ¥á¥¤¥ó½èÍý(¥Ú¡¼¥¸Æɤ߹þ¤ß¸å¤Ë¼Â¹Ô¤µ¤ì¤ë)
*/
tm.main(function() {
// ¥¢¥×¥ê¥±¡¼¥·¥ç¥óºîÀ®
app = tm.app.CanvasApp("#world");
app.resize(SCREEN_WIDTH, SCREEN_HEIGHT);
app.fitWindow(); // ¥ê¥µ¥¤¥ºÂбþ

// ³«»Ï¥·¡¼¥ó
app.replaceScene(TitleScene());

// ¼Â¹Ô
app.run();
});
}}