rot.js + encant.js マップジェネレーター _shimizu Follow 2014-07-10 16:24:18 License: Refer to code comments Fork5 Fav4 View13168 Play Stop Reload Fullscreen Smart Phone Fork tree Readme JavaScript 104 lines HTML 1 lines CSS 1 lines rot.js http://ondras.github.com/rot.js/hp/ クリックするとマップが生成されます。 RPGを作るのに便利なアルゴリズムを提供する「rot.js」 http://shimz.me/blog/?p=1343 rot.js + encant.js マップジェネレーター enchant.js v0.4.5 enchant(); window.onload = function() { var game = new Game(420, 420); game.bs = 8; game.preload("http://jsrun.it/assets/1/T/u/d/1TudM.gif"); game.onload = function() { var w = 52, h = 52; var wall_img = 1; var road_img = 0; var map = new Map(game.bs, game.bs); map.image = game.assets['http://jsrun.it/assets/1/T/u/d/1TudM.gif']; //マップの画像を読み込む var maze = createMaze("uniform", w, h, wall_img, road_img); showMap(map, maze.col, maze.data); var mapAlgIdx = 0; this.rootScene.addEventListener("touchstart", function(e) { if(mapAlgIdx > 5) mapAlgIdx = 0; var mapAlg = ["divided","icey","eller","cellular","digger","uniform"]; var maze = createMaze(mapAlg[mapAlgIdx], w, h, wall_img, road_img); showMap(map, maze.col, maze.data); mapAlgIdx++; }); function showMap(map, m_col, m_data){ map.loadData(m_data); map.collisionData = m_col; game.rootScene.addChild(map); } } game.start(); }; function createMaze(alg, w, h, wall_img, road_img){ var m_col = []; var m_data = []; for(var x=0;x < w;x++){ m_col[x] = []; for(var y=0;y < h; y++){ m_col[x][y] = null; } } switch(alg){ case 'divided': var maze = new ROT.Map.DividedMaze(w, h); maze.create(function(x, y, val){ m_col[x][y] = val; }); break; case 'icey': var maze = new ROT.Map.IceyMaze(w, h, 4); maze.create(function(x, y, val){ m_col[x][y] = val; }); break; case 'eller': var maze = new ROT.Map.EllerMaze(w, h); maze.create(function(x, y, val){ m_col[x][y] = val; }); break; case 'cellular': var maze = new ROT.Map.Cellular(w, h); maze.randomize(0.5); maze.create(function(x, y, val){ m_col[x][y] = val; }); break; case 'digger': var maze = new ROT.Map.Digger(w, h); maze.create(function(x, y, val){ m_col[x][y] = val; }); break; case 'uniform': var maze = new ROT.Map.Uniform(w, h); maze.create(function(x, y, val){ m_col[x][y] = val; }); break; } for(var y=0; y < m_col.length; y++){ m_data[y] = []; for(var x=0; x < m_col.length; x++){ switch(m_col[y][x]){ case 1:m_data[y][x] = wall_img;break; case 0:m_data[y][x] = road_img;break; } } } return {col:m_col, data:m_data} ; } <script type="text/javascript" src="http://jsrun.it/assets/6/C/Z/K/6CZKY"></script> rot.js + encant.js マップジェネレーター body { margin:0px} rot.js http://ondras.github.com/rot.js/hp/ クリックするとマップが生成されます。 RPGを作るのに便利なアルゴリズムを提供する「rot.js」 http://shimz.me/blog/?p=1343 enchant(); window.onload = function() { var game = new Game(420, 420); game.bs = 8; game.preload("http://jsrun.it/assets/1/T/u/d/1TudM.gif"); game.onload = function() { var w = 52, h = 52; var wall_img = 1; var road_img = 0; var map = new Map(game.bs, game.bs); map.image = game.assets['http://jsrun.it/assets/1/T/u/d/1TudM.gif']; //マップの画像を読み込む var maze = createMaze("uniform", w, h, wall_img, road_img); showMap(map, maze.col, maze.data); var mapAlgIdx = 0; this.rootScene.addEventListener("touchstart", function(e) { if(mapAlgIdx > 5) mapAlgIdx = 0; var mapAlg = ["divided","icey","eller","cellular","digger","uniform"]; var maze = createMaze(mapAlg[mapAlgIdx], w, h, wall_img, road_img); showMap(map, maze.col, maze.data); mapAlgIdx++; }); function showMap(map, m_col, m_data){ map.loadData(m_data); map.collisionData = m_col; game.rootScene.addChild(map); } } game.start(); }; function createMaze(alg, w, h, wall_img, road_img){ var m_col = []; var m_data = []; for(var x=0;x < w;x++){ m_col[x] = []; for(var y=0;y < h; y++){ m_col[x][y] = null; } } switch(alg){ case 'divided': var maze = new ROT.Map.DividedMaze(w, h); maze.create(function(x, y, val){ m_col[x][y] = val; }); break; case 'icey': var maze = new ROT.Map.IceyMaze(w, h, 4); maze.create(function(x, y, val){ m_col[x][y] = val; }); break; case 'eller': var maze = new ROT.Map.EllerMaze(w, h); maze.create(function(x, y, val){ m_col[x][y] = val; }); break; case 'cellular': var maze = new ROT.Map.Cellular(w, h); maze.randomize(0.5); maze.create(function(x, y, val){ m_col[x][y] = val; }); break; case 'digger': var maze = new ROT.Map.Digger(w, h); maze.create(function(x, y, val){ m_col[x][y] = val; }); break; case 'uniform': var maze = new ROT.Map.Uniform(w, h); maze.create(function(x, y, val){ m_col[x][y] = val; }); break; } for(var y=0; y < m_col.length; y++){ m_data[y] = []; for(var x=0; x < m_col.length; x++){ switch(m_col[y][x]){ case 1:m_data[y][x] = wall_img;break; case 0:m_data[y][x] = road_img;break; } } } return {col:m_col, data:m_data} ; } <script type="text/javascript" src="http://jsrun.it/assets/6/C/Z/K/6CZKY"></script> body { margin:0px} use an iframe compat browser, deer Play on jsdo.it games Author Share ブログに埋め込む QR Tag Download Complete! Description What kind of game? rot.js http://ondras.github.com/rot.js/hp/ クリックするとマップが生成されます。 RPGを作るのに便利なアルゴリズムを提供する「rot.js」 http://shimz.me/blog/?p=1343 Control Device Smartphone Controllerjsdo.it WebSocket Controller» Mouse Keyboard Touch Device Fullscreen Activated Inactivated jsdo.it games から削除する Submit Author _shimizu URLhttp://shimz.me/blog/ 群馬県高崎市在住のエンジニア 。サーバ管理したり、自動組版のスクリプト組んだり、サイト作ったりして生きてます。データビジュアライゼーションとオープンデータにハマってます。Webデザイン & JS勉強中。 I luv javascript! Tweet Default Panel Auto play Screenshot Readme JavaScript HTML CSS Size Width: px Height: px code <script type="text/javascript" src="http://jsdo.it/blogparts/wuzh/js"></script> encant.js game rot.js Discussion Questions on this code? Tags encant.js game rot.js Favorite by siouxcitizen sakotsu katatema01: encant.jsrot.js nishink: game Forked sort by latest page views favorite forked forked: rot.js + encant.js マップ mizchi1 00 550 55/83/0 encant.js rot.js forked: rot.js + encant.js マップ mizchi1 00 619 105/1/1 encant.js game rot.js forked: rot.js + encant.js マップ tak4hir0 00 594 105/1/1 encant.js game rot.js forked: rot.js + encant.js マップ satopeck 00 500 100/1/1 encant.js game rot.js 1 2NEXT>>