topical media & game development
mobile-graphic-enchant-examples-expert-action-game.js / js
enchant();
enchant.Sound.enabledInMobileSafari = true;
if(location.protocol == 'file:'){
enchant.ENV.USE_WEBAUDIO = false;
console.log('1');
}
window.onload = function() {
var Rectangle = enchant.Class.create({
initialize: function(x, y, width, height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
},
right: {
get: function() {
return this.x + this.width;
}
},
bottom: {
get: function() {
return this.y + this.height;
}
}
});
var game = new Game(320, 320);
game.fps = 24;
game.preload('chara1.gif', 'map2.gif', 'jump.wav', 'gameover.wav');
game.onload = function() {
var blocks = [
[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,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,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]
];
var map = new Map(16, 16);
map.image = game.assets['map2.gif'];
map.loadData(blocks);
var bear = new Sprite(32, 32);
bear.x = 8;
bear.y = -32;
bear.vx = 0;
bear.vy = 0;
bear.ax = 0;
bear.ay = 0;
bear.pose = 0;
bear.jumping = true;
bear.jumpBoost = 0;
bear.image = game.assets['chara1.gif'];
bear.addEventListener('enterframe', function(e) {
var friction = 0;
if (this.vx > 0.3) {
friction = -0.3;
} else if (this.vx > 0) {
friction = -this.vx;
}
if (this.vx < -0.3) {
friction = 0.3;
} else if (this.vx < 0) {
friction = -this.vx;
}
if (this.jumping) {
if (!game.input.up || --this.jumpBoost < 0) {
this.ay = 0;
}
} else {
if (game.input.up) {
this.jumpBoost = 5;
this.ay = -5;
game.assets['jump.wav'].clone().play();
}
}
this.ax = 0;
if (game.input.left) this.ax -= 0.5;
if (game.input.right) this.ax += 0.5;
if (this.ax > 0) this.scaleX = 1;
if (this.ax < 0) this.scaleX = -1;
if (this.ax != 0) {
if (game.frame % 3 == 0) {
this.pose++;
this.pose %= 2;
}
this.frame = this.pose + 1;
} else {
this.frame = 0;
}
this.vx += this.ax + friction;
this.vy += this.ay + 2 ; // 2 is gravity
this.vx = Math.min(Math.max(this.vx, -10), 10);
this.vy = Math.min(Math.max(this.vy, -10), 10);
var dest = new Rectangle(
this.x + this.vx + 5, this.y + this.vy + 2,
this.width-10, this.height-2
);
this.jumping = true;
if (dest.x < -stage.x) {
dest.x = -stage.x;
this.vx = 0;
}
while (true) {
var boundary, crossing;
var dx = dest.x - this.x - 5;
var dy = dest.y - this.y - 2;
if (dx > 0 && Math.floor(dest.right / 16) != Math.floor((dest.right - dx) / 16)) {
boundary = Math.floor(dest.right / 16) * 16;
crossing = (dest.right - boundary) / dx * dy + dest.y;
if ((map.hitTest(boundary, crossing) && !map.hitTest(boundary-16, crossing)) ||
(map.hitTest(boundary, crossing + dest.height) && !map.hitTest(boundary-16, crossing + dest.height))) {
this.vx = 0;
dest.x = boundary - dest.width - 0.01;
continue;
}
} else if (dx < 0 && Math.floor(dest.x / 16) != Math.floor((dest.x - dx) / 16)) {
boundary = Math.floor(dest.x / 16) * 16 + 16;
crossing = (boundary - dest.x) / dx * dy + dest.y;
if ((map.hitTest(boundary-16, crossing) && !map.hitTest(boundary, crossing)) ||
(map.hitTest(boundary-16, crossing + dest.height) && !map.hitTest(boundary, crossing + dest.height))) {
this.vx = 0;
dest.x = boundary + 0.01;
continue;
}
}
if (dy > 0 && Math.floor(dest.bottom / 16) != Math.floor((dest.bottom - dy) / 16)) {
boundary = Math.floor(dest.bottom / 16) * 16;
crossing = (dest.bottom - boundary) / dy * dx + dest.x;
if ((map.hitTest(crossing, boundary) && !map.hitTest(crossing, boundary-16)) ||
(map.hitTest(crossing + dest.width, boundary) && !map.hitTest(crossing + dest.width, boundary-16))) {
this.jumping = false;
this.vy = 0;
dest.y = boundary - dest.height - 0.01;
continue;
}
} else if (dy < 0 && Math.floor(dest.y / 16) != Math.floor((dest.y - dy) / 16)) {
boundary = Math.floor(dest.y / 16) * 16 + 16;
crossing = (boundary - dest.y) / dy * dx + dest.x;
if ((map.hitTest(crossing, boundary-16) && !map.hitTest(crossing, boundary)) ||
(map.hitTest(crossing + dest.width, boundary-16) && !map.hitTest(crossing + dest.width, boundary))) {
this.vy = 0;
dest.y = boundary + 0.01;
continue;
}
}
break;
}
this.x = dest.x-5;
this.y = dest.y-2;
if (this.y > 320) {
game.assets['gameover.wav'].play();
var score = Math.round(bear.x);
this.frame = 3;
this.vy = -20;
this.addEventListener('enterframe', function() {
this.vy += 2;
this.y += Math.min(Math.max(this.vy, -10), 10);
if (this.y > 320) {
game.end(score, score + 'mで死にました');
}
});
this.removeEventListener('enterframe', arguments.callee);
}
});
var stage = new Group();
stage.addChild(map);
stage.addChild(bear);
stage.addEventListener('enterframe', function(e) {
if (this.x > 64 - bear.x) {
this.x = 64 - bear.x;
}
});
var pad = new Pad();
pad.x = 0;
pad.y = 224;
game.rootScene.addChild(stage);
game.rootScene.addChild(pad);
game.rootScene.backgroundColor = 'rgb(182, 255, 255)';
};
game.start();
};
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.