[[Programing]]

ϡenchant.jsϤȤɬפʡŪʥΤޤȤǤenchant.js°ΥץΥ󥲡(\examples\action)ȥ塼ƥ󥰥(\examples\shooting)ʤɤɤƤޤ
ϡenchant.jsϤȤɬפʡŪʥΤޤȤǤ

enchant.js°ΥץΥ󥲡(\examples\action)ȥ塼ƥ󥰥(\examples\shooting)ʤɤɤƤޤ

enchant.jsϡץ뤿Υ饤֥ץǤ(२󥸥Ȥ)

HTML5JavascriptȤѤǺƤơѥʤޡȥե䥿֥åȤˤбǤޤ

ǤϡĥɤʣˤƤäơޤ륲ޤ

-[[9leap : 30á󥴽ᥲ by y_catch - ɤǤͷ٤롢Ʒॵ:http://9leap.net/games/1126]]
-30ô֤ǡǤ󥴤򽸤Ƥ
-ǡޤޤ
-νꥢȤȡޥå(ѥ)å(ޡȥե)ǤǤޤ

⤦餷

-[[9leap : 30á󥴽ᥲPart2:http://9leap.net/games/1176]]

#ref(1176_140.gif)



#contents

* [#yc6b9b9f]

-[[enchant.js - HTML5 + JavaScript Game Engine:http://enchantjs.com/ja/]]


*ɬפʥե [#b8f4e08f]

enchant.js顢ΥեФޤ

޲(bear.gif)ϡɤƤޤ

- enchant.jsenchant.js
- game.jsΥᥤץ
- index.htmlᥤץƤӽФHTMLե롣֥饦dz
- bear.gif:ե

#ref(bear.gif)

* index.html [#nde0ff97]

¹Ԥˤϡ index.html֥륯å顢ᥤץǤgame.js䡢饤֥Ǥenchant.jsƤӽФƤޤ

 <!DOCTYPE html>
 <html>
     <head>
         <meta charset="utf-8">
         <meta name="viewport" content="width=device-width, user-scalable=no"> 
         <meta name="apple-mobile-web-app-capable" content="yes"> 
         <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
         <title>Sample Game</title>
         <script type="text/javascript" src="enchant.js"></script>
         <script type="text/javascript" src="game.js"></script>
         <style type="text/css">
             body {
                 margin: 0;
             }
         </style>
     </head>
     <body>
     </body>
 </html>

* game.jsδܥ [#b1f8a8b5]

ΥᥤץǤgame.jsδŪʹ֤ˤߤƤޤ

**⤷ʤ [#z5168b76]

줬ܷե(bear.gif)ɤ߹Ǥ뤱ɽϤʤ

ΥƥȤgame.jsȤƥȥեȤ¸롣ơindex.htmlƤӽФȡץ¹ԡ

 enchant();
 
 window.onload = function() {
 	var game = new Game(320, 320); 	//̤
 	game.preload('bear.gif');	//եɤ߹
 
 	game.onload = function() {
 		//{פȡ}פδ֤ˡư򵭽Ҥ
 	}
 	game.start();
 }

**򤿤ɽ [#qb76c8e5]

ҤΥե񤭴ơץ饤ȵǽ(Sprite)Dzɽ롣

 enchant();
 
 window.onload = function() {
 	var game = new Game(320, 320);
 	game.preload('bear.gif');
 
 	game.onload = function() {
 		var bear = new Sprite(20, 30);
       	bear.image = game.assets['bear.gif'];
 
 		game.rootScene.addChild(bear);
 	}
 	game.start();
 }

**ɽѤ [#p7e99849]

ʣΥ᡼äƤξ硢ץ饤Ȥ̤Υ᡼ɽ롣

ޤ⤤Ƥ륢˥᡼ʤɤ˻Ȥޤ(ޤ⤭ޤ)

 enchant();
 
 window.onload = function() {
 	var game = new Game(320, 320);
 	game.preload('bear.gif');
 
 	game.onload = function() {
 		var bear = new Sprite(20, 30);
       	bear.image = game.assets['bear.gif'];
 		bear.frame = 1;
 
 		game.rootScene.addChild(bear);
 	}
 	game.start();
 }


**ɽ֤ [#mb934d47]

ץ饤Ȥΰ֤

 enchant();
 
 window.onload = function() {
 	var game = new Game(320, 320);
 	game.preload('bear.gif');
 
 	game.onload = function() {
 		var bear = new Sprite(20, 30);
       	bear.image = game.assets['bear.gif'];
 		bear.x = 150;
 		bear.y = 150;
 		bear.frame = 1;
 
 		game.rootScene.addChild(bear);
 	}
 	game.start();
 }

**ϤDzڤؤ [#s89a6625]

򲡤ơڤؤ

 enchant();
 
 window.onload = function() {
 	var game = new Game(320, 320);
 	game.preload('bear.gif');
 
 	game.onload = function() {
 		var bear = new Sprite(20, 30);
       		bear.image = game.assets['bear.gif'];
 
       		bear.addEventListener('enterframe', function() {
 			bear.x = 150;
 			bear.y = 150;
 			if(game.input.left) bear.frame = 1;
 			if(game.input.right) bear.frame = 2;
 		});
 		game.rootScene.addChild(bear);
 	}
 	game.start();
 }

**˥᡼ [#f6c15a11]

ǡξ

 enchant();
 
 window.onload = function() {
 	var game = new Game(320, 320);
 	game.preload('bear.gif');
 
 	game.onload = function() {
 		var bear = new Sprite(20, 30);
       		bear.image = game.assets['bear.gif'];
 
       		bear.addEventListener('enterframe', function() {
			bear.x = 150;
			bear.y = 150;
			if(game.input.right) {
				if(bear.frame == 1) {
					bear.frame = 2;
				} else {
					bear.frame = 1;
				}
			}
			if(game.input.left) {
				if(bear.frame == 4) {
					bear.frame = 5;
				} else {
					bear.frame = 4;
				}
			}
 		});
 		game.rootScene.addChild(bear);
 	}
 	game.start();
 }

**˥᡼ [#v06aaf4f]

롣ɤ̵롣

 enchant();
 
 window.onload = function() {
 	var game = new Game(320, 320);
 	game.preload('bear.gif');
 
 	game.onload = function() {
 		var bear = new Sprite(20, 30);
       		bear.image = game.assets['bear.gif'];
 
       		bear.addEventListener('enterframe', function() {
			bear.y = 150;
			if(game.input.right) {
				if(bear.frame == 1) {
					bear.frame = 2;
				} else {
					bear.frame = 1;
				}
				bear.x += 5;	
			}
			if(game.input.left) {
				if(bear.frame == 4) {
					bear.frame = 5;
				} else {
					bear.frame = 4;
				}
				bear.x -= 5;	
			}
 		});
 		game.rootScene.addChild(bear);
 	}
 	game.start();
 }

**˥᡼ [#r9bd2f81]

롣ɤǻߤޤ롣

 enchant();
 
 window.onload = function() {
 	var game = new Game(320, 320);
 	game.preload('bear.gif');
 
 	game.onload = function() {
 		var bear = new Sprite(20, 30);
       		bear.image = game.assets['bear.gif'];
 
       		bear.addEventListener('enterframe', function() {
 			bear.y = 150;
 			if(game.input.right) {
 				if(bear.frame == 1) {
 					bear.frame = 2;
 				} else {
 					bear.frame = 1;
 				}
 				if (bear.x < 300) {
 					bear.x += 5;
 				} else {
 					bear.x = 300;
 				}
 			}
 			if(game.input.left) {
 				if(bear.frame == 4) {
 					bear.frame = 5;
 				} else {
 					bear.frame = 4;
 				}
 				if (bear.x > 0) {
 					bear.x -= 5;
 				} else {
 					bear.x = 0;
 				}
 			}
 		});
 		game.rootScene.addChild(bear);
 	}
 	game.start();
 }

**ץ [#t3df58f2]

-[[ץץ¹Ԥ:http://www.catch.jp/program/enchant.js/lesson_1/]]
-ǡޤޤ
-[[:http://www.catch.jp/program/enchant.js/lesson_1/game.js]]

ޤǤǴե

#ref(enchant_sample_lesson1.lzh)

*ʸɽ [#rff46cbc]

̾ʸɽˤϡ٥뵡ǽ(Label)Ȥޤ


**̾˸ʸɽ [#u7bfd3f6]

Running Bear:פȤʸɽ

 enchant();
 
 window.onload = function() {
 	var game = new Game(320, 320);
 
 	var label = new Label("Running Bear:");
 	label.x = 0;
 	label.y = 0;
 	game.rootScene.addChild(label);
 
 	game.start();
 }


**ʸ񤭴 [#l4d79b5d]

ǤϤʤɽƤʸѲ

 enchant();
 
 window.onload = function() {
 	var game = new Game(320, 320);
 	game.preload("bear.gif");
 
 	var label = new Label("Running Bear:");
 	label.x = 0;
 	label.y = 0;
 	game.rootScene.addChild(label);
 	
 	game.onload = function() {
 		var label_time = new Label();
 		label_time.x = 0;
 		label_time.y = 14;
 		
       		label_time.addEventListener('enterframe', function() {
 			label_time.text = game.frame;
 		});
 		game.rootScene.addChild(label_time);
 	}
 	game.start();
 }

**˥᡼ʸɽ [#x93a3f15]

ޤꡢв֤ɽޤ

˥᡼Υԡɤgame.fps = 15;פĴƤޤ
 
 enchant();
 
 window.onload = function() {
 	var game = new Game(320, 320);
 	game.preload("bear.gif");
 	game.fps = 15;
 
 	var label = new Label("Running Bear:");
 	label.x = 0;
 	label.y = 0;
 	game.rootScene.addChild(label);
 	
 	game.onload = function() {
		//٥ʸɽ
 		var label_time = new Label();
 		label_time.x = 0;
 		label_time.y = 14;
 				
       	label_time.addEventListener('enterframe', function() {
 			label_time.text = game.frame;
 		});
 		game.rootScene.addChild(label_time);
 
		//ץ饤Ȥǥɽ
 		var bear = new Sprite(20, 30);
       	bear.image = game.assets['bear.gif'];
 		
 		bear.addEventListener('enterframe', function() {
 			if(bear.frame == 1) {
 				bear.frame = 2;
 			} else {
 				bear.frame = 1;
 			}
 			
 			bear.x += 5
 			if (bear.x > 300) {
 					bear.x = 0;
 			}
 			bear.y = 50;
 		});
 		game.rootScene.addChild(bear);
 	}
 	game.start();
 }


**ץ [#dcb86424]

-[[ץץ¹Ԥ:http://www.catch.jp/program/enchant.js/lesson_2/]]
-ޤꡢв֤ɽޤ
-[[:http://www.catch.jp/program/enchant.js/lesson_2/game.js]]

ޤǤǴե

#ref(enchant_sample_lesson2.lzh)



*̲Ф [#o4cfc1f5]

˸̲ĤȡڤǤ

**ȤˤФ [#hab3d314]

ɥե()ɤ߹ǡ.playפǺޤ
 
 enchant();
 
 window.onload = function() {
     var game = new Game(320, 320);
     game.preload('jump.wav');
     game.onload = function() {
 	    var sound = game.assets['jump.wav'].play();
 	    sound.play();
     };
     game.start();
 };



**ˤ碌ƲФ [#se2442cc]

ɽΤȤˡȤ߹ߤޤ

̲եɤ߹ʤơ٤ϫޤenchant.jsΥС󤬸ŤȤޤʤޤ

 enchant();
 
 window.onload = function() {
     var game = new Game(320, 320);
     game.preload('jump.wav', 'bear.gif');
     game.onload = function() {
 	    game.assets['jump.wav'].play();
 		
 		var bear = new Sprite(20, 30);
       	bear.image = game.assets['bear.gif'];
 		
 		bear.addEventListener('enterframe', function() {
 			if(game.input.right) {
 				var sound = game.assets['jump.wav'].clone();
 				sound.play();
 			}
 		});
 		game.rootScene.addChild(bear);
     };
     game.start();
 };

**ץ [#m807a206]

-[[ץץ¹Ԥ:http://www.catch.jp/program/enchant.js/lesson_4/]]
-DzФޤ
-[[:http://www.catch.jp/program/enchant.js/lesson_4/game.js]]

ޤǤǴե

#ref(enchant_sample_lesson4.lzh)

*ʲ [#h52552ae]

ץϡĤʤȤ߹碌Ȥƺȡ䤹ʤޤ

**ʲ [#n27ba729]

KumaȤ(֥)player1player2˳ƤƤޤ
ҤȤĤ߷׿(Kuma)顢ʣʤФƤޤʤϡƬʸʸˤޤϡʸǽ񤤤Ƥޤ

 enchant();
 
 var Kuma = enchant.Class.create(enchant.Sprite, {
     initialize: function(x, y){
         enchant.Sprite.call(this, 20, 30);
         this.image = game.assets['bear.gif'];
         this.x = x; this.y = y; this.frame = 0;
         game.rootScene.addChild(this);
     }
 });
 
 window.onload = function() {
     game = new Game(320, 320); 
     game.preload('bear.gif');
     game.onload = function() {
 	player1 = new Kuma(0, 0);
 	player1.frame = 1;
 	player2 = new Kuma(30, 0);
 	player2.frame = 2;
     }
     game.start();
 }

**ʲư [#ia4fd2e6]

ʤǤϡʤ߷׿¦ưǤޤǤϡKumaʤˡmove_rightmove_leftƤޤơᥤʬǡ줿˹碌ơmove_rightmove_leftƤӽФƤޤ

 enchant();
 
 var Kuma = enchant.Class.create(enchant.Sprite, {
     initialize: function(x, y){
         enchant.Sprite.call(this, 20, 30);
         this.image = game.assets['bear.gif'];
         this.x = x; this.y = y; this.frame = 0;
         game.rootScene.addChild(this);
     },
 	move_right: function() {
 		this.x += 5;
 	},
 	move_left: function() {
 		this.x -= 5;
 	}
 });
 
 window.onload = function() {
     game = new Game(320, 320); 
     game.preload('bear.gif');
     game.onload = function() {
 		player = new Kuma(0, 0);
 		
 		game.addEventListener('enterframe', function() {
 			if(game.input.right) {
 				player.move_right();
 			}
 			if(game.input.left) {
 				player.move_left();
 			}
 		});
     }
     game.start();
 }

**ʲΥ˥᡼ [#q6b81d2f]

äĤƤߤϤθФϡ¦˰ưǡ¦Ϥäꡣ
ϺĤǤ롣

 enchant();
 SCREEN_WIDTH = 320;
 SCREEN_HEIGHT = 320;
 
 var Kuma = enchant.Class.create(enchant.Sprite, {
     initialize: function(x, y){
 		this.KUMA_WIDTH = 20;
 		this.KUMA_HEIGHT = 30;
 		this.KUMA_Y = 50;
 		this.dir = 0;		//ʹ 0:(right)1:(left)
 		this.walk = 0;		//ԥݡ 0: 1:­ 2:­
 		this.step = 5;
 		
 		enchant.Sprite.call(this, this.KUMA_WIDTH, this.KUMA_HEIGHT);
 		this.image = game.assets['bear.gif'];
 		this.x = x;
 		this.y = this.KUMA_Y;
 		this.frame = 0;
 
 		this.addEventListener('enterframe', function() {
 			if(game.input.right) {
 				this.move_right();
 			} else if(game.input.left) {
 				this.move_left();
 			} else {
 				this.move_stop();
 			}
 			this.change_frame();
 		});
 		game.rootScene.addChild(this);
 	},
 	move_right: function() {
 		this.dir = 0;
 		if((this.walk == 0) || (this.walk == 2)){
 			this.walk = 1;
 		} else if(this.walk == 1) {
 			this.walk = 2;
 		}
 		if (this.x < (SCREEN_WIDTH - this.KUMA_WIDTH)) {
 			this.x += this.step;
 		} else {
 			this.x = SCREEN_WIDTH - this.KUMA_WIDTH;
 		}
 	},
 	move_left: function() {
 		this.dir = 1;
 		if((this.walk == 0) || (this.walk == 2)){
 			this.walk = 1;
 		} else if(this.walk == 1) {
 			this.walk = 2;
 		}
 		if (this.x > 0) {
 			this.x -= this.step;
 		} else {
 			this.x = 0;
 		}
 	},
 	move_stop: function(){
 		if(this.walk !== 0) {
 			game.assets['jump.wav'].play();
 		}
 		this.walk = 0;
 	},
 	change_frame: function() {
 		this.frame = this.dir * 3 + this.walk;
 	}
 });
 
 window.onload = function() {
 	game = new Game(SCREEN_WIDTH, SCREEN_HEIGHT); 
 	game.preload('jump.wav', 'bear.gif');
 	game.onload = function() {
 		player = new Kuma(0, 0);
 	}
 	game.start();
 }

-[[ץץ¹Ԥ:http://www.catch.jp/program/enchant.js/lesson_5/]]
-ǥޤޤ
-[[:http://www.catch.jp/program/enchant.js/lesson_5/game.js]]

ޤǤǴե

#ref(enchant_sample_lesson5.lzh)


*ʣΥѡĤư [#f49c9150]

󥲡ǤϡʣŨ䥿åȤо줷ޤȤСФǤȤ١ȤäǤ¸뤿ˤϡ̤ΥѡĤʣо줵ơƱưɬפޤ

**ʣβɽ [#he4e0e00]

ޤʣβɽˡҤȤĤʲɽƤߤޤ礦ϡۤɤΥʲˡȤۤȤƱǡAppleȤʤ夫ߤäƤޤAppleϡ1ɽޤäƤΤϡβʤõǤ褦ˤƤȤ(remove)Ǥ

 enchant();
 SCREEN_WIDTH = 320;
 SCREEN_HEIGHT = 320;
 
 var Apple = enchant.Class.create(enchant.Sprite, {
 	initialize: function(x, y){
 		this.WIDTH = 16;
 		this.HEIGHT = 16;
 		this.STEP = 5;
 		
 		enchant.Sprite.call(this, this.WIDTH, this.HEIGHT);
 		this.image = game.assets['icon0.gif'];
 		this.x = x;
 		this.y = y;
 		this.frame = 15;
 		this.addEventListener('enterframe', function(){
 			this.move_step();
 		});
 		game.rootScene.addChild(this);
 	},
 	move_step: function() {
 		this.y += this.STEP;
 		if (this.y >= (SCREEN_HEIGHT - this.HEIGHT)) {
 			this.remove();
 		}
 	},
 	remove: function(){
 		game.rootScene.removeChild(this);
 	}
 });
 
 window.onload = function() {
 	game = new Game(SCREEN_WIDTH, SCREEN_HEIGHT); 
 	game.fps = 15;
 	game.preload('icon0.gif');
 	game.onload = function() {
 		target = new Apple(100, 0);
 	}
 	game.start();
 }

**ʣβư [#oda390f1]

¤ʣư褦ˤȡʤޤʣApple夫ߤäƤޤʤʬϡۤɤƱǤ¦ʣAppleβƤޤ

 enchant();
 SCREEN_WIDTH = 320;
 SCREEN_HEIGHT = 320;
 
 var Apple = enchant.Class.create(enchant.Sprite, {
 	initialize: function(x, y){
 		this.WIDTH = 16;
 		this.HEIGHT = 16;
 		this.STEP = 5;
 		
 		enchant.Sprite.call(this, this.WIDTH, this.HEIGHT);
 		this.image = game.assets['icon0.gif'];
 		this.x = x;
 		this.y = y;
 		this.frame = 15;
 		this.addEventListener('enterframe', function(){
 			this.move_step();
 		});
 		game.rootScene.addChild(this);
 	},
 	move_step: function() {
 		this.y += this.STEP;
 		if (this.y >= (SCREEN_HEIGHT - this.HEIGHT)) {
 			this.remove();
 		}
 	},
 	remove: function(){
 		game.rootScene.removeChild(this);
 	}
 });
 
 window.onload = function() {
 	game = new Game(SCREEN_WIDTH, SCREEN_HEIGHT); 
 	game.fps = 15;
 	game.preload('icon0.gif');
 	game.onload = function() {
 		targets = [];
 		game.rootScene.addEventListener('enterframe', function(){
  			if((game.frame % 10) == 0){
 				var x = Math.floor(Math.random() * 300);
 				targets[game.frame] = new Apple(x, 0);
 			}
 		});
 	}
 	game.start();
 }

-[[ץץ¹Ԥ:http://www.catch.jp/program/enchant.js/lesson_6_2/]]
-[[:http://www.catch.jp/program/enchant.js/lesson_6_2/game.js]]

ޤǤǴե

#ref(enchant_sample_lesson6-2.lzh)

ˡ̣դäȡ餷ʤäƤޤ͡


**(ĤǤ)ŨƱɽ [#v823b793]

ĤǤ뼫ȡŨƱɽȡʤޤ
 
 enchant();
 SCREEN_WIDTH = 320;
 SCREEN_HEIGHT = 320;
 
 //ĤǤ뼫
 var Kuma = enchant.Class.create(enchant.Sprite, {
     initialize: function(x, y){
 		this.KUMA_WIDTH = 20;
 		this.KUMA_HEIGHT = 30;
 		this.KUMA_Y = 200;
 		this.dir = 0;		//ʹ 0:(right)1:(left)
 		this.walk = 0;		//ԥݡ 0: 1:­ 2:­
 		this.step = 5;
 		
 		enchant.Sprite.call(this, this.KUMA_WIDTH, this.KUMA_HEIGHT);
 		this.image = game.assets['bear.gif'];
 		this.x = x;
 		this.y = this.KUMA_Y;
 		this.frame = 0;
 
 		this.addEventListener('enterframe', function() {
 			if(game.input.right) {
 				this.move_right();
 			} else if(game.input.left) {
 				this.move_left();
 			} else {
 				this.move_stop();
 			}
 			this.change_frame();
 		});
 		game.rootScene.addChild(this);
 	},
 	move_right: function() {
 		this.dir = 0;
 		if((this.walk == 0) || (this.walk == 2)){
 			this.walk = 1;
 		} else if(this.walk == 1) {
 			this.walk = 2;
 		}
 		if (this.x < (SCREEN_WIDTH - this.KUMA_WIDTH)) {
 			this.x += this.step;
 		} else {
 			this.x = SCREEN_WIDTH - this.KUMA_WIDTH;
 		}
 	},
 	move_left: function() {
 		this.dir = 1;
 		if((this.walk == 0) || (this.walk == 2)){
 			this.walk = 1;
 		} else if(this.walk == 1) {
 			this.walk = 2;
 		}
 		if (this.x > 0) {
 			this.x -= this.step;
 		} else {
 			this.x = 0;
 		}
 	},
 	move_stop: function(){
 		if(this.walk !== 0) {
 			game.assets['jump.wav'].play();
 		}
 		this.walk = 0;
 	},
 	change_frame: function() {
 		this.frame = this.dir * 3 + this.walk;
 	}
 });
 
 //ʣɽꥭ
 var Apple = enchant.Class.create(enchant.Sprite, {
 	initialize: function(x, y){
 		this.WIDTH = 16;
 		this.HEIGHT = 16;
 		this.STEP = 5;
 		
 		enchant.Sprite.call(this, this.WIDTH, this.HEIGHT);
 		this.image = game.assets['icon0.gif'];
 		this.x = x;
 		this.y = y;
 		this.frame = 15;
 		this.addEventListener('enterframe', function(){
 			this.move_step();
 		});
 		game.rootScene.addChild(this);
 	},
 	move_step: function() {
 		this.y += this.STEP;
 		if (this.y >= (SCREEN_HEIGHT - this.HEIGHT)) {
 			this.remove();
 		}
 	},
 	remove: function(){
 		game.rootScene.removeChild(this);
 	}
 });
 
 window.onload = function() {
 	game = new Game(SCREEN_WIDTH, SCREEN_HEIGHT); 
 	game.fps = 15;
 	game.preload('bear.gif', 'icon0.gif', 'jump.wav');
 	game.onload = function() {
 		player = new Kuma(0, 0);
 		targets = [];
 		game.rootScene.addEventListener('enterframe', function(){
  			if((game.frame % 10) == 0){
 				var x = Math.floor(Math.random() * 300);
 				targets[game.frame] = new Apple(x, 0);
 			}
 		});
 	}
 	game.start();
 }

-[[ץץ¹Ԥ:http://www.catch.jp/program/enchant.js/lesson_6_3/]]
-[[:http://www.catch.jp/program/enchant.js/lesson_6_3/game.js]]

ޤǤǴե

#ref(enchant_sample_lesson6-3.lzh)

Ƚդäȡäݤʤޤ͡

**Ƚ [#vf730204]

ꥭ餬ܿɤȽԤޤȽϡɽ뤿ʤǤ륹ץ饤(Sprite)Ƚ̿(intersect)Ȥޤ(Apple)ưȤ󥯥ޤȤȽԤäơäƤ顢оݤΥ󥴤õ̲Ĥ餷ޤ

 enchant();
 SCREEN_WIDTH = 320;
 SCREEN_HEIGHT = 320;
 score = 0;
 
 //ĤǤ뼫
 var Kuma = enchant.Class.create(enchant.Sprite, {
     initialize: function(x, y){
 		this.KUMA_WIDTH = 20;
 		this.KUMA_HEIGHT = 30;
 		this.KUMA_Y = 200;
 		this.dir = 0;		//ʹ 0:(right)1:(left)
 		this.walk = 0;		//ԥݡ 0: 1:­ 2:­
 		this.step = 5;
 		
 		enchant.Sprite.call(this, this.KUMA_WIDTH, this.KUMA_HEIGHT);
 		this.image = game.assets['bear.gif'];
 		this.x = x;
 		this.y = this.KUMA_Y;
 		this.frame = 0;
 
 		this.addEventListener('enterframe', function() {
 			if(game.input.right) {
 				this.move_right();
 			} else if(game.input.left) {
 				this.move_left();
 			} else {
 				this.move_stop();
 			}
 			this.change_frame();
 		});
 		game.rootScene.addChild(this);
 	},
 	move_right: function() {
 		this.dir = 0;
 		if((this.walk == 0) || (this.walk == 2)){
 			this.walk = 1;
 		} else if(this.walk == 1) {
 			this.walk = 2;
 		}
 		if (this.x < (SCREEN_WIDTH - this.KUMA_WIDTH)) {
 			this.x += this.step;
 		} else {
 			this.x = SCREEN_WIDTH - this.KUMA_WIDTH;
 		}
 	},
 	move_left: function() {
 		this.dir = 1;
 		if((this.walk == 0) || (this.walk == 2)){
 			this.walk = 1;
 		} else if(this.walk == 1) {
 			this.walk = 2;
 		}
 		if (this.x > 0) {
 			this.x -= this.step;
 		} else {
 			this.x = 0;
 		}
 	},
 	move_stop: function(){
 		this.walk = 0;
 	},
 	change_frame: function() {
 		this.frame = this.dir * 3 + this.walk;
 	}
 });
 
 //ʣɽꥭ
 var Apple = enchant.Class.create(enchant.Sprite, {
 	initialize: function(x, y){
 		this.WIDTH = 16;
 		this.HEIGHT = 16;
 		this.STEP = 5;
 		
 		enchant.Sprite.call(this, this.WIDTH, this.HEIGHT);
 		this.image = game.assets['icon0.gif'];
 		this.x = x;
 		this.y = y;
 		this.frame = 15;
 		this.addEventListener('enterframe', function(){
 			this.move_step();
 		});
 		game.rootScene.addChild(this);
 	},
 	move_step: function() {
 		this.y += this.STEP;
 
 		//Ƚ
 		if(this.intersect(player)){
 			this.remove();
 			game.assets['jump.wav'].play();
 		}
 		//üã
 		if (this.y >= (SCREEN_HEIGHT - this.HEIGHT)) {
 			this.remove();
 		}
 	},
 	remove: function(){
 		game.rootScene.removeChild(this);
 	}
 });
 
 window.onload = function() {
 	game = new Game(SCREEN_WIDTH, SCREEN_HEIGHT); 
 	game.fps = 15;
 	game.preload('bear.gif', 'icon0.gif', 'jump.wav');
 	game.onload = function() {
 		player = new Kuma(0, 0);
 		targets = [];
 		game.rootScene.addEventListener('enterframe', function(){
  			if((game.frame % 10) == 0){
 				var x = Math.floor(Math.random() * 300);
 				targets[game.frame] = new Apple(x, 0);
 			}
 		});
 	}
 	game.start();
 }

-[[ץץ¹Ԥ:http://www.catch.jp/program/enchant.js/lesson_7/]]
-[[:http://www.catch.jp/program/enchant.js/lesson_7/game.js]]

ޤǤǴե

#ref(enchant_sample_lesson7.lzh)

*ʥץ饰 [#o7f33f99]

enchant.jsϡץ饰(plugin)ǵǽĥǤޤ

Ȥ⡢ץ饰ѤȺȸΨ夬ޤ

-[[pluginenchant.js - HTML5 + JavaScript Game Engine:http://enchantjs.com/ja/plugin.html]]

⻲ͤˤʤޤ

-[[enchant.jsǺޤǺä9leapٻͤˤˡ | IDEA*IDEA:http://www.ideaxidea.com/archives/2011/05/for_9leap.html]]

**ץ饰λȤ [#x47ae7cf]

ץ饰ϡenchant.jsƱեľpluginsեȤǤ礦

enchant.jsषϡԤˤʤäƤޤ

줫顢ץ饰ɬפȤƱեѰդޤ

-nineleap.enchant.jsξ
--start.png
--end.png
--font.png
-ui.enchant.jsξ
--apad.png
--pad.png

Ȥϡindex.html˥ץ饰եεҤɲäޤ

 <!DOCTYPE html>
 <html>
     <head>
         <meta charset="utf-8">
         <meta name="viewport" content="width=device-width, user-scalable=no"> 
         <meta name="apple-mobile-web-app-capable" content="yes"> 
         <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
         <title>enchant</title>
         <script type="text/javascript" src="enchant.js"></script>
         <script type="text/javascript" src="plugins/nineleap.enchant.js"></script>
         <script type="text/javascript" src="plugins/util.enchant.js"></script>
         <script type="text/javascript" src="plugins/ui.enchant.js"></script>
         <script type="text/javascript" src="game.js"></script>
         <style type="text/css">
             body {margin: 0;}
         </style>
     </head>
     <body>
     </body>
 </html>

嵭Ǥϡ10-11ܤpluginsեˤץ饰ե(nineleap.enchant.jsutil.enchant.js)ꤷƤޤץ饰ϡץ(:game.js)˵Ҥޤ

**Ȳ [#g122127c]

nineleap.enchant.jsɤ߹ȡॹȻ˼ưŪ˥ѥåɽޤ

**λ [#h45a6768]

nineleap.enchant.jsɤ߹ߡཪλ٤Ȥ˲Υɤ񤭤ޤ

 game.end(game.score, "game end");

game.scoreϡǼѿ


**ɽ [#df53f786]

ץ(game.onload = function()ΤȤ)ˡΥɤ񤭤ޤȡ֤Ƥ(ȥå)ˤʤޤ

 timeLabel = new TimeLabel(8, 8);
 game.rootScene.addChild(timeLabel);

Τ褦˽񤯤ȥȥ

 timeLabel = new TimeLabel(8, 8, "countdown");
 timeLabel.time = 30;
 game.rootScene.addChild(timeLabel);

ɽ٥ѹˤ

 timeLabel.label = "LIFE:";

ߤηв֤Фˤϡ

 A = timeLabel.label;

**ɽ [#w26baaee]

ץΤνʬ(window.onload = function() )ˡΥɤ񤭤ޤ줬ˤʤޤ

 game.score = 0; //ν

ץ(game.onload = function()ΤȤ)ˡΥɤ񤭤ޤ줬ɽ

 scoreLabel = new ScoreLabel(40, 8);
 game.rootScene.addChild(scoreLabel);

ɲåɤȤơΥɤ񤭤ޤ

 game.score += 10;

ɽ٥ѹˤ

 scoreLabel.label = "APPLE:";

**(ɽ) [#f8deb4c9]

Ũ㳲ʪʤɤХХɽ뤳ȤɽȤޤ͡ΥɽˤϡȤޤȤϡȤ110ޤǤο򼡡Ŭ˺ФˡǤutil.enchant.jsץ饰Ȥȡ򼡤Τ褦˴ñ˰ޤ

 A = rand(10); //

**åѥåб [#y718b9d7]

ޡȥեʤɤΥåѥåбˤˤϡΥɤɲäޤǡؤޥǡƱ褦˥Ǥޤ

 var pad = new Pad();
 pad.x = 0;
 pad.y = 220;
 game.rootScene.addChild(pad);

pad.xpad.yǡѥѥåɤɽ֤ꡣ

**ץ [#t3df58f2]

-[[ץץ¹Ԥ:http://www.catch.jp/program/enchant.js/lesson_8/]]
-30ô֤ǡǤ󥴤򽸤Ƥ
-ǡޤޤ
-νꥢȤȡޥå(ѥ)å(ޡȥե)ǤǤޤ
-[[:http://www.catch.jp/program/enchant.js/lesson_8/game.js]]

ޤǤǴե

#ref(enchant_sample_lesson8.lzh)


*̤Ť͹碌 [#hfa3967f]

ʣʥ̤ɽȤϡŤ͹碌褦˺Ǥ

enchant.jsǤϡΤ褦˽Ť̤ͤ򥷡(Scene)ȸƤӤޤ

-[[enchant.jsΥץ륳ɤɤRPGԤ1 | IDEA*IDEA:http://www.ideaxidea.com/archives/2011/04/enchant_rgb_undocumented.html]]
-[[enchant.js ֺ®ǥޤꤳʤפεŪ | IDEA*IDEA:http://www.ideaxidea.com/archives/2011/04/cars_explained.html]]

*9leapǸ [#q01863b9]

9leapϡenchant.jsȤäƥȡƤ줿ϡѥǤ⥹ޡȥեǤͷ٤ޤ

-[[9leap : ȥåץڡ - ɤǤͷ٤롢Ʒॵ:http://9leap.net/]]

 󤹤ȥơȤƤǽˤʤۤ
 Ʊǥץ쥤TwitterǥեƤͤξϥɽޤ
 򤪵ɲäơ夫ͷ֤ȤǤޤ

9leap˥󤹤ˤϡTwitterȤɬפǤ

**ˡ [#r7d51209]

ϡ餬ͤˤʤޤ

-[[iPad 2ץߥ󥰥ƥȥȡ9leap٤˥Ƥˡ | IDEA*IDEA:http://www.ideaxidea.com/archives/2011/05/9leap.html]]

**9leapƤƤߤ [#c4044f76]

-[[9leap : 30á󥴽ᥲ by y_catch - ɤǤͷ٤롢Ʒॵ:http://9leap.net/games/1126]]

*طʡޥåפɽ [#m1aa7ffd]

Ȥ饯ǤϤӤΤǡطʤɽƤߤޤ

طʤˤϡطʿꤹˡȲꤹˡޤ

**طʿλ [#g6911641]

طʿꤹˤϡΤ褦˥(game.rootScene)طʿ(backgroundColor)RGBꤷޤ

 game.rootScene.backgroundColor = 'rgb(182, 255, 255)';

**طʲɽ [#n13e96b1]

طʲɽˤϡޤطʤθˤʤǺѰդޤϡΤ褦93ޥǺ(map2.gif)Ȥޤ

#ref(map2.gif)

93ޥβϡΤ褦ֹƤޤ

  0, 1, 2, 3, 4, 5, 6, 7, 8
  9,10,11,12,13,14,15,16,17
 18,19,20,21,22,23,24,25,26

ˡβɤΤ褦ˤʤ٤뤫ͤǻꤷޤ

Ǻ֤Ȥˤϡֹꤷޤ
ʤˤʤȤϡ-1פꤷޤ

ϡ20ޥ10ޥβطʤȤɽޤ

 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],
 	[4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4],
 	[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],
 ];

ºݤ֤ˤϡΤ褦ˤޤ

-game.preload('bear.gif', 'map2.gif'); Ǻɤ߹
-Υɤطʤ

 var map = new Map(16, 16);
 map.image = game.assets['map2.gif'];
 map.loadData(blocks);

-game.rootScene.addChild(map); ǡǸϿ

**ץ [#b332014e]


-[[ץץ¹Ԥ:http://www.catch.jp/program/enchant.js/lesson_3/]]
-طʤɽ졢ǥޤޤ
-[[:http://www.catch.jp/program/enchant.js/lesson_3/game.js]]

ޤǤǴե

#ref(enchant_sample_lesson3.lzh)

*nakamura001 ץ뽸 [#z2822510]

ޤǡenchant.jsΥץäƤ顢ΥȤˤɤޤȤޤäƤΤȯȥǥˤɤ夯Τݤ˴ޤǡ󥯤Ƥޤ

-[[nakamura001 @  - ȥåץڡ/JavaScript/饤֥/enchant.js/ץ:http://www32.atwiki.jp/nakamura001/pages/149.html]]

-饯򱦤˰ư [[:http://tsuyobi.heteml.jp/html/javascript/enchantjs/samples/01.js]][[ǥ:http://tsuyobi.heteml.jp/html/javascript/enchantjs/samples/01.html]]
-饯ǰư [[:http://tsuyobi.heteml.jp/html/javascript/enchantjs/samples/02.js]][[ǥ:http://tsuyobi.heteml.jp/html/javascript/enchantjs/samples/02.html]]
-ư(饯βȿž) [[:http://d.hatena.ne.jp/nakamura001/20110503/1304432316]]
-åפ֤˥饯ư [[:http://tsuyobi.heteml.jp/html/javascript/enchantjs/samples/03.js]][[ǥ:http://tsuyobi.heteml.jp/html/javascript/enchantjs/samples/03.html]]
-٥ɽ [[:http://tsuyobi.heteml.jp/html/javascript/enchantjs/samples/04.js]][[ǥ:http://tsuyobi.heteml.jp/html/javascript/enchantjs/samples/04.html]]

-Ƚ(饤֥Υ᥽åɤȤ鷺˼Ƚ) [[:http://tsuyobi.heteml.jp/html/javascript/enchantjs/samples/05.js]][[ǥ:http://tsuyobi.heteml.jp/html/javascript/enchantjs/samples/05.html]]
-Ƚ(饤֥Υ᥽åɤȽ) [[:http://tsuyobi.heteml.jp/html/javascript/enchantjs/samples/06.js]][[ǥ:http://tsuyobi.heteml.jp/html/javascript/enchantjs/samples/06.html]]
-饯˥᡼ˡ [[:http://d.hatena.ne.jp/nakamura001/20110421/1303383146]]
-饯ɲˡ [[:http://d.hatena.ne.jp/nakamura001/20110422/1303491804]]

-֤ΰư [[:http://d.hatena.ne.jp/nakamura001/20110423/1303565014]]
-쥤䡼طθ饯ɲˡ [[:http://d.hatena.ne.jp/nakamura001/20110423/1303579051]]
-ʪʪꤲˡ [[:http://d.hatena.ne.jp/nakamura001/20110503/1304433222]]

*git [#ecca0cf8]

-[[ycatch/test_enchant.js - GitHub:https://github.com/ycatch/test_enchant.js]]

ȥå   ʬ Хåå   ñ측 ǽ   إ   ǽRSS