Skip to content

Instantly share code, notes, and snippets.

@teramotodaiki
Last active June 6, 2016 17:52
Show Gist options
  • Save teramotodaiki/efac6b29a1b063639661ed55e9e5b9fe to your computer and use it in GitHub Desktop.
Save teramotodaiki/efac6b29a1b063639661ed55e9e5b9fe to your computer and use it in GitHub Desktop.
// Game start
var __beginTime = new Date().getTime();
var __dump = new Array(15).fill(0);
var __stopper = function (id) {
var elapsed = new Date().getTime() - __beginTime;
__dump[id] ++;
return elapsed < 0;
};
game.on('load', function () {
console.log(__dump.join('\n'));
});
var map;
var floor;
var Map = new Array(11);
game.onload = function () {
/*var map = Hack.maps['map1'];
map.load(); // Load Map; Hack.defaultParentNode == map.scene*/
Hack.maps['map1'].load(); // Load Map; Hack.defaultParentNode == map.scene
// ( Keep this line -- ここはけさないでね ) //
// プレイヤー(騎士)
var player = Hack.player = new Player();
player.locate(3, 5);
player.hp = 3;
player.onbecomedead = function () {
this.destroy();
Hack.textarea.remove();
Hack.gameover();
};
Hack.log('');
Hack.textarea.backgroundColor = "rgba(0,0,0,0.6)";
Hack.textarea.onenterframe = function(){
Hack.textarea.moveTo(40,255);
Hack.textarea.opacity -= 0.02;
};
Hack.textarea.text = 'abc';
Hack.textarea.opacity = 3;
game.addEventListener('enterframe', function event() {
if (Hack.lifeLabel.tl && Hack.scoreLabel.tl) {
Hack.lifeLabel.remove();
Hack.scoreLabel.remove();
game.removeEventListener('enterframe', event);
}
});
Hack.camera.zoom = 1.5;
LoadMapObject();
Hack.camera.onrendered = function(e) {
DrawMap(e);
};
var dump = Map.map(function (map) {
return map.map(function (row) {
return row.map(function (num) {
return (' ' + num).substr(-3);
}).join('');
}).join('\n');
}).join('\n\n\n');
alert(dump);
};
// Before game start
Hack.onload = function () {
MapObject.dictionary = {
clay: 320, clayWall: 340, clayFloor: 323,
stone: 321, stoneWall: 341, stoneFloor: 342,
warp: 324, warpRed: 325,
warpGreen: 326, warpYellow: 327,
magic: 328, usedMagic: 329,
pot: 400, rock: 401, upStair: 402,
box: 420, flower: 421, downStair: 422,
trap: 440, usedTrap: 441, step: 442,
castle: 500, village: 501, caveGate: 502,
tree: 520, table: 521, openedBox: 522,
beam: 540, diamond: 560, sapphire: 561,
ruby: 562, heart: 563, skull: 564,
coin: 565, star: 566, key: 567,
bomb: 580, coldBomb: 581, egg: 582,
poo: 583,
sandySoil: 45, claySoil: 323,
grassland: 322, waterside: 205,
flatGray: 135, squareGray: 93
};
Hack.maps = {};
// map1
/*Hack.maps['map1'] = new RPGMap(32, 32, 30, 30);
Hack.maps['map1'].imagePath = 'enchantjs/x2/dotmat.gif';
Hack.maps['map1'].type = 'stoneFloor';*/
for(floor = 1;floor <= 10;floor++){
LoadMap();
}
floor = 1;
// < Keep this line -- ここはけさないでね > //
};
// Score up/Score down
Hack.onscorechange = function () {
// [ Keep this line -- ここはけさないでね ] //
};
function LoadMap(){
var w;
var h;
var X;
var Y;
var loop;
var count;
var rand;
var room;
var y;
var x;
var num;
//部屋
do{
//マップ初期化
map = new Array(30);
for(y = 0; y < 30; y++){
map[y] = new Array(30);
for(x = 0; x < 30; x++){
map[y][x] = 0;
}
}
room = 0;
for(var i = 0; i < 200;i = i){
//部屋を作る
count = 0;
do{
w = random(7,12);
h = random(7,12);
X = random(0,31 - w);
Y = random(0,31 - h);
loop = 0;
for(y = 0; y < h; y++){
for(x = 0; x < w; x++){
if(map[Y + y][X + x] !== 0 && map[Y + y][X + x] != 4)loop = 1;
}
}
count++;
}while(loop && count < 1000 && __stopper(1));
if(count == 1000 || !__stopper(2))break;
//部屋を置く
do{
rand = random(0,((w + h) - 8) * 2);
loop = 0;
for(num = 0; num < 3 && __stopper(3); num++){
for(y = num; y < h - num && __stopper(4); y++){
for(x = num; x < w - num && __stopper(5); x++){
map[Y + y][X + x] = 4 - num;
if(num == 2)map[Y + y][X + x] = 70 + room;
/*if(num == 1 && ((y % (h - 3) == 1) != (x % (w - 3) == 1))){
if(rand == 0){
map[Y + y][X + x] = 5;
if((Y + y) % 27 == 1 || (X + x) % 27 == 1)loop = 1;
}
rand--;
}*/
}
}
}
}while(loop && __stopper(6));
i += ((w-4) * (h-4));
room++;
}
}while(count == 1000 && __stopper(7));
for(y = 0; y < 30; y++){
for(x = 0; x < 30; x++){
if(y % 29 === 0 || x % 29 === 0){
map[y][x] = 3;
}else if(map[y][x] == 4)map[y][x] = 0;
}
}
//通路
var X1;
var Y1;
room = room * -1;
do{
do{
count = 0;
do{
X = random(2,28);
Y = random(2,28);
}while(map[Y][X] < 70 && __stopper(8));
num = map[Y][X] - 70;
map[Y][X] = map[Y][X] * -1;
do{
X1 = X;
Y1 = Y;
loop = 1;
if(map[Y][X] != -3)rand = random(0,4);
switch(rand){
case 0:
X++;
break;
case 1:
X--;
break;
case 2:
Y++;
break;
case 3:
Y--;
}
switch(map[Y][X]){
case 0:
loop = 2;
break;
case 3:
if(Y + (Y - Y1) > 0 && Y + (Y - Y1) < 29 && X + (X - X1) > 0 && X + (X - X1) < 29){
if((room < 0 && map[Y + (Y - Y1)][X + (X - X1)] >= 70) || (room > 0 && (map[Y + (Y - Y1)][X + (X - X1)] == 1||(map[Y + (Y - Y1)][X + (X - X1)] < 70 && map[Y + (Y - Y1)][X + (X - X1)] >= 40))) || (map[Y1][X1] <= -70 && map[Y + ((Y - Y1) * 2)][X + ((X - X1) * 2)] != 1))loop = 2;
}
}
if((map[Y][X] >= 70 && map[Y][X] != 70 + num)|| map[Y][X] == 1 || (map[Y][X] < 70 && map[Y][X] >= 40))loop = 0;
if(loop == 2){
map[Y][X] = map[Y][X] === 0? -1:map[Y][X] * -1;
if(X != X1){
if(map[Y + 1][X] === 0)map[Y + 1][X] = -8;
if(map[Y - 1][X] === 0)map[Y - 1][X] = -8;
}
if(Y != Y1){
if(map[Y][X + 1] === 0)map[Y][X + 1] = -8;
if(map[Y][X - 1] === 0)map[Y][X - 1] = -8;
}
for(y = -1; y < 2; y++){
for(x = -1; x < 2; x++){
if(map[Y1 + y][X1 + x] === 0)map[Y1 + y][X1 + x] = -9;
}
}
for(y = 0; y < 30; y++){
for(x = 0; x < 30; x++){
if(map[y][x] == -8)map[y][x]=0;
}
}
}
if(loop == 1){
X = X1;
Y = Y1;
}
count++;
}while(count != 1000 && loop && __stopper(9));
if(loop === 0 || !__stopper(10))break;
for(y = 0; y < 30; y++){
for(x = 0; x < 30; x++){
//if(map[y][x] == 4)map[y][x]=5;
if(map[y][x] == -1 || map[y][x] == -9){
map[y][x] = 0;
}else if(map[y][x] < -1){
map[y][x] = map[y][x] * -1;
}
}
}
}while(count == 1000 && loop && __stopper(11));
map[Y][X] = map[Y][X] * -1;
X += X - X1;
Y += Y - Y1;
count = map[Y][X];
for(y = 0; y < 30; y++){
for(x = 0; x < 30; x++){
if(map[y][x] == 70 + num|| (room < 0 && map[y][x] == count))map[y][x] = map[y][x] - 30;
if(map[y][x] == -9)map[y][x] = 3;
if(map[y][x] <= -70)map[y][x] = (map[y][x] * -1) - 60;
if(map[y][x] <= -1)map[y][x] = 1;
}
}
if(room < 0){
room = room * -1;
room--;
}
room--;
}while(room && __stopper(12));
//マップ表示
var map1 = new Array(30);
for(y = 0; y < 30; y++){
map1[y] = new Array(30);
for(x = 0; x < 30; x++){
switch(map[y][x]){
case 0:
case 3:
map1[y][x] = 341;
if(y == 29){
map1[y][x] = 321;
}else if(map[y + 1][x] === 0 || map[y + 1][x] == 3)map1[y][x] = 321;
break;
default:
map1[y][x] = 342;
}
}
}
//当たり判定
var map2 = new Array(30);
for(y = 0; y < 30; y++){
map2[y] = new Array(30);
for(x = 0; x < 30; x++){
switch(map[y][x]){
case 0:
case 3:
map2[y][x] = 1;
break;
default:
map2[y][x] = 0;
}
}
}
Hack.maps['map' + floor] = new RPGMap(32, 32, 30, 30);
Hack.maps['map' + floor].imagePath = 'enchantjs/x2/dotmat.gif';
Hack.maps['map' + floor].bmap.loadData(map1);
Hack.maps['map' + floor].cmap = map2;
Map[floor] = map;
}
function LoadMapObject(){
//Hack.maps['map1'].load(); // Load Map; Hack.defaultParentNode == map.scene
var X;
var Y;
map = Map[floor];
//プレイヤー
do{
X = random(2,28);
Y = random(2,28);
}while(!(40 <= map[Y][X] && map[Y][X] < 50) && __stopper(13));
map[Y][X] = 9;
Hack.player.locate(X,Y);
//階段
do{
X = random(2,28);
Y = random(2,28);
}while(!(40 <= map[Y][X] && map[Y][X] < 50) && __stopper(14));
map[Y][X] = 8;
var item1 = new MapObject('upStair');
item1.locate(X, Y, 'map' + floor);
item1.layer = RPGMap.Layer.Under;
item1.onplayerenter = function () {
if(floor == 10){
Hack.gameclear();
}else{
floor++;
Hack.changeMap('map' + floor);
LoadMapObject();
}
};
}
function DrawMap(e){
var context = e.surface.context;
context.beginPath();
//プレイヤー
context.fillStyle = "rgba(128,128,0,0.5)";
context.arc(153 + (Hack.player.x / 32 * 6), 73 + (Hack.player.y / 32 * 6), 6, 0, Math.PI*2, false);
context.fill();
}
/*
0 壁
1 通路
2 部屋
3 壊せない壁
8 階段
9 プレイヤー
10~99 部屋番号
100~199 敵
200~299 アイテム
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment