基本:よく使うコード

// 当たり判定
for (var i in enemies) {
	// 敵に当たったら:下記は2通り
	if (enemies[i].intersect(this)) {
	if (this.within(enemies[i], 30)) {


// ゲームクリアの画像を表示して終了
core.end(null, null, core.assets['clear.png']);
core.end(null, null, core.assets['timeup.png']);


// 画面触った、離した
bg.addEventListener('touchstart', function(e) {
	player.moving = true;
});
bg.addEventListener('touchend', function(e) {
	player.moving = false;
});


// 自機と敵の位置から弾の発射角度を求める
var sx = 相手x - this.x;
var sy = 相手y - this.y;
var angle = Math.atan(sx / sy);
// 弾を発射する
var s = new EnamyBullet(this.x+0, this.y+0,angle);
// :
// :
// 弾の移動処理
this.addEventListener('enterframe', function() {
	this.x += this.speed * Math.sin(this.angle);
	this.y += this.speed * Math.cos(this.angle);
});


// 爆発 5フレーム毎にアニメーション(Slow)
this.image = core.assets['爆発.png'];
this.addEventListener('enterframe', function() {
	if (core.frame % 5 == 0) this.frame++;
	if (this.frame == 10) this.remove();
});
core.rootScene.addChild(this);


// text
var scoreLbl = new Label();
scoreLbl.moveTo(285,280);
scoreLbl.font = "10px 'Arial', 'Monaco'";
scoreLbl.color = "#ffffff";
scoreLbl.text = 'test';
core.rootScene.addChild(scoreLbl);


// 線を4フレームの間だけ描写
var my_shot_line = enchant.Class.create(enchant.Sprite, {
	initialize: function(x, y, xx, yy) {
		enchant.Sprite.call(this, 320, 400);
		this.moveTo(0,0);
		var surface = new Surface(320,400);
		var context = surface.context;
		context.strokeStyle = 'red';
		context.lineWidth = 1;
		context.beginPath();
		context.moveTo(x, y);
		context.lineTo(xx, yy);
		context.closePath();
		context.stroke();
		this.endframe = core.frame + 4;
		this.image = surface;
		this.addEventListener('enterframe', function() {
			if (core.frame == this.endframe) this.remove();
		});
		core.rootScene.addChild(this);
	},
	remove: function() {
		core.rootScene.removeChild(this);
		delete this;
	}
});


// グループ化
var boss_group = new Group();
boss_group.moveTo(0, 0);
// 256x256のキャラの中心をグループの開始点にセット
bos.x =-128; bos.y=-128;
boss_group.addChild(bos);
// 他のスプライトも同様に開始点をずらす
var cores = new boss_core(78-128, 78-128);
boss_group.addChild(cores);
// 移動例
boss_group.tl.moveBy(200, 0, 100).and().rotateBy(360,100);

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です