// Main
console.log("Hello EnchantJS!!");
var assets = [
"images/back_town.png",
"images/washi_stand.png",
"images/washi_sit.png",
"images/washi_kick_l.png",
"images/washi_kick_r.png",
"images/title.png",// タイトル
"sounds/hit.mp3",
"sounds/jump.mp3",
"images/cf307/nuhehidari.png",
"images/cf307/nuhemigi.png",
"images/cf307/zyoniue.png",
"images/cf307/yazirusi(64).png",
];
function gameStart(){// ゲーム画面
scene = gameManager.createGameScene();
core.replaceScene(scene); core.resume();
//==========
// ここから
//==========
scene.backgroundColor = "darkgray";
// 町
var town = new Sprite(320, 480);
town.image = core.assets["images/back_town.png"];
scene.addChild(town);
// ラベル
var label = new Label("タップで移動");
label.x = 320 / 2 - 150 / 2;
label.y = 340 + 44;
label.color = "black";
label.font = "32px Arial";
scene.addChild(label);
// わし
var washi = new Sprite(64, 64);
washi.image = core.assets["images/cf307/nuhehidari.png"];
washi.x = 160 - 32;
washi.y = 260;
scene.addChild(washi);
washi.scale(1.5, 1.5);
// 矢印左
var hidari = new Sprite(64, 64);
hidari.image = core.assets["images/cf307/yazirusi(64).png"];
hidari.x = washi.x - 64;
hidari.y = washi.y;
scene.addChild(hidari);
hidari.scale(0.8, 0.8);
hidari.rotate(-90);
// 矢印右
var migi = new Sprite(64, 64);
migi.image = core.assets["images/cf307/yazirusi(64).png"];
migi.x = 160 - 32 + 64;
migi.y = 260;
scene.addChild(migi);
migi.scale(0.8, 0.8);
migi.rotate(90);
// 矢印上
var ue = new Sprite(64, 64);
ue.image = core.assets["images/cf307/yazirusi(64).png"];
ue.x = 160 - 32;
ue.y = 260 - 64 - 6;
scene.addChild(ue);
ue.scale(0.8, 0.8);
// 矢印下
var sita = new Sprite(64, 64);
sita.image = core.assets["images/cf307/yazirusi(64).png"];
sita.x = 160 - 32;
sita.y = 260 + 64;
scene.addChild(sita);
sita.scale(0.8, 0.8);
sita.rotate(180);
scene.addEventListener(Event.TOUCH_START, function(e){
console.log("ごりら");
console.log(e.x);
if(e.x < washi.x){
console.log("ちっちゃいね");
washi.image = core.assets["images/cf307/nuhehidari.png"];
label.text = " 左ぢゃ!";
washi.moveBy(-20, 0, 0);
hidari.moveBy(-20, 0, 0);
migi.moveBy(-20, 0, 0);
ue.moveBy(-20, 0, 0);
sita.moveBy(-20, 0, 0);
label.moveBy(-20, 0, 0);
}
if(washi.x + washi.width < e.x){
console.log("でかいね");
washi.image = core.assets["images/cf307/nuhemigi.png"];
label.text = " 右ぢゃ!";
washi.moveBy(20, 0, 0);
hidari.moveBy(20, 0, 0);
migi.moveBy(20, 0, 0);
ue.moveBy(20, 0, 0);
sita.moveBy(20, 0, 0);
label.moveBy(20, 0, 0);
}
if(washi.y > e.y){
console.log("うえだね");
washi.image = core.assets["images/cf307/zyoniue.png"];
label.text = " 上ぢゃ!";
washi.moveBy(0, -20, 0);
hidari.moveBy(0, -20, 0);
migi.moveBy(0, -20, 0);
ue.moveBy(0, -20, 0);
sita.moveBy(0, -20, 0);
label.moveBy(0, -20, 0);
}
if(washi.y + washi.height < e.y){
console.log("しただね");
washi.image = core.assets["images/cf307/nuhehidari.png"];
label.text = " 下ぢゃ!";
washi.moveBy(0, 20, 0);
hidari.moveBy(0, 20, 0);
migi.moveBy(0, 20, 0);
ue.moveBy(0, 20, 0);
sita.moveBy(0, 20, 0);
label.moveBy(0, 20, 0);
}
});
//==========
// ここまで
//==========
}
function getRandom(start, end) {
return start + Math.floor( Math.random() * (end - start + 1));
}
function titleStart(){// タイトル画面
var scene = gameManager.createTitleScene();
core.replaceScene(scene); core.pause();
scene.on(enchant.Event.TOUCH_START, function(){gameStart();});
}
//==========
// EnchantJS
enchant();
var gameManager;
var core;
var scene;
window.onload = function(){
gameManager = new common.GameManager();
core = gameManager.createCore(320, 480);
core.preload(assets);
core.onload = function(){titleStart();};
core.start();
}
関連