Skip to content

Instantly share code, notes, and snippets.

@seventhsense
Created December 18, 2012 15:40
Show Gist options
  • Save seventhsense/4329086 to your computer and use it in GitHub Desktop.
Save seventhsense/4329086 to your computer and use it in GitHub Desktop.
enchant();
var game, physicsWorld;
window.onload = function () {
game = new Game(320, 320);
game.fps = 30;
game.preload("chara1.gif", "icon1.png", "map2.gif");
game.onload = function () {
physicsWorld = new PhysicsWorld(0, 9.8);
stage = new Group();
game.rootScene.addChild (stage);
for(var i = 0; i < 20; i++){
//床を生成
var floor = new PhyBoxSprite(16, 16, enchant.box2d.STATIC_SPRITE, 1.0, 0.5, 0.3, true);
floor.image = game.assets["map2.gif"];
floor.frame = 2;
floor.position = { x: i*16, y: 300 };
stage.addChild(floor);
}
game.rootScene.addEventListener("enterframe", function () {
physicsWorld.step(game.fps);
if(game.frame % game.fps == 0){
//ボールを生成
var ball = new PhyCircleSprite(8, enchant.box2d.DYNAMIC_SPRITE, 1.0, 0.5, 0.2, true);
ball.image = game.assets["icon1.png"];
ball.frame = 4;
ball.position = { x: 0, y: 120 };
ball.applyImpulse(new b2Vec2(Math.random(), 0));
stage.addChild(ball);
ball.addEventListener("enterframe", function(){
if (game.input.right)ball.destroy();
})
}
});
game.rootScene.addEventListener("touchstart", function (evt) {
//ボールを生成
var ball = new PhyCircleSprite(8, enchant.box2d.DYNAMIC_SPRITE, 1.0, 0.5, 0.2, true);
ball.image = game.assets["icon1.png"];
ball.frame = 3;
ball.position = { x: evt.x, y: evt.y };
ball.applyImpulse(new b2Vec2(Math.random() * 0.1, 0));
game.rootScene.addChild(ball);
ball.addEventListener("enterframe", function(){
if(ball > 3)ball.destroy();
})
});
};
game.start();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment