Compare commits
173 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
640b0c53bd | ||
![]() |
b5d8f58861 | ||
![]() |
6b06e7ef3d | ||
![]() |
8e084b5e1c | ||
![]() |
74074e91ff | ||
![]() |
fa158c25a3 | ||
![]() |
9de2d66b9d | ||
![]() |
2df3fbbf82 | ||
![]() |
6d2656e9c6 | ||
![]() |
af00e56609 | ||
![]() |
d9aed86cf4 | ||
![]() |
38da13af5e | ||
![]() |
d307ac3229 | ||
![]() |
5ad486a526 | ||
![]() |
57da20d223 | ||
![]() |
cd2da708c6 | ||
![]() |
6cdf0238a8 | ||
![]() |
15cde9a429 | ||
![]() |
611818a198 | ||
![]() |
5508b83cc9 | ||
![]() |
faeac3ed6d | ||
![]() |
b418f79507 | ||
![]() |
6e7bb4533c | ||
![]() |
d711acc5e7 | ||
![]() |
b9bf7e8ab5 | ||
![]() |
9d0ca36b81 | ||
![]() |
147fc36acc | ||
![]() |
8eab5c9d75 | ||
![]() |
10b1a56df5 | ||
![]() |
435e60e77d | ||
![]() |
af12ffaba4 | ||
![]() |
c5fe0a8f9d | ||
![]() |
8f57128ba2 | ||
![]() |
8c26178900 | ||
![]() |
95b91c125b | ||
![]() |
8be5054913 | ||
![]() |
8cbc2f1ecb | ||
![]() |
f09163f521 | ||
![]() |
a27d4f50a2 | ||
![]() |
0a69d7ea77 | ||
![]() |
927c0cca4d | ||
![]() |
132657d003 | ||
![]() |
a684bd6c58 | ||
![]() |
99345b6997 | ||
![]() |
b791002171 | ||
![]() |
149304d94c | ||
![]() |
c133f6bed7 | ||
![]() |
ec72aeb1b4 | ||
![]() |
e66e83c5c1 | ||
![]() |
6d8f80627c | ||
![]() |
28a11ff346 | ||
![]() |
b5f1467a5b | ||
![]() |
45ba38df00 | ||
![]() |
9f49a99d05 | ||
![]() |
c243c473d7 | ||
![]() |
3375618fdc | ||
![]() |
60abcbb787 | ||
![]() |
09c34a395d | ||
![]() |
8e4f0d4c5f | ||
![]() |
75a2e70a01 | ||
![]() |
4ff8668f99 | ||
![]() |
0b262f3aa1 | ||
![]() |
f43566d1d7 | ||
![]() |
7c8f854d35 | ||
![]() |
53dd360a38 | ||
![]() |
7560066cdd | ||
![]() |
d336ba6550 | ||
![]() |
5c275bcefa | ||
![]() |
072a81fe34 | ||
![]() |
eb61ced480 | ||
![]() |
90ecff291c | ||
![]() |
c25be4a52f | ||
![]() |
1d10b66c5e | ||
![]() |
c8c36a6df2 | ||
![]() |
6e910c7641 | ||
![]() |
22687aa350 | ||
![]() |
b4c846af66 | ||
![]() |
9c1ceff633 | ||
![]() |
241ee6590a | ||
![]() |
531cf3deee | ||
![]() |
3ea59386f1 | ||
![]() |
2d2cc67eaa | ||
![]() |
14083f2820 | ||
![]() |
4abeaebf8d | ||
![]() |
cd9cbec732 | ||
![]() |
db4a429863 | ||
![]() |
a8586e25c3 | ||
![]() |
ee5d25e017 | ||
![]() |
62577ab533 | ||
![]() |
ace81d4065 | ||
![]() |
c0946853f4 | ||
![]() |
960fa4fb32 | ||
![]() |
800481cfd5 | ||
![]() |
f476e76f64 | ||
![]() |
d555f5a198 | ||
![]() |
0058a857d7 | ||
![]() |
6c44731739 | ||
![]() |
25b8f932f4 | ||
![]() |
88f41c611c | ||
![]() |
d9d8e7c0c0 | ||
![]() |
0e8ccd369b | ||
![]() |
f950d05bcc | ||
![]() |
4d7b4f635e | ||
![]() |
b2fb0fc5e1 | ||
![]() |
5ae29ae1af | ||
![]() |
be948fe684 | ||
![]() |
f3c10c3027 | ||
![]() |
a493bdfdd4 | ||
![]() |
8c16dfe08e | ||
![]() |
e8f0cfd316 | ||
![]() |
ec34cf924c | ||
![]() |
0de568da4f | ||
![]() |
cafbe36a0e | ||
![]() |
ff5bcafb3b | ||
![]() |
1f5eef0066 | ||
![]() |
2f808b69e7 | ||
![]() |
0806f5ab72 | ||
![]() |
155bea6436 | ||
![]() |
8cba953383 | ||
![]() |
7f8523004b | ||
![]() |
5b2819f291 | ||
![]() |
6c9eb07002 | ||
![]() |
4cbdc1e405 | ||
![]() |
0217710f11 | ||
![]() |
92ac9dfe02 | ||
![]() |
146835140b | ||
![]() |
8cfe02d1d4 | ||
![]() |
12326f60e0 | ||
![]() |
4ccc9b87f3 | ||
![]() |
9356741125 | ||
![]() |
a8914a4417 | ||
![]() |
635728cdff | ||
![]() |
a7e11c868f | ||
![]() |
90a23e3a04 | ||
![]() |
85cdae5a51 | ||
![]() |
22357d5c94 | ||
![]() |
e851447b5c | ||
![]() |
e2b2ddde0c | ||
![]() |
cb17f38a8d | ||
![]() |
fec712e0d8 | ||
![]() |
89c22cd3f5 | ||
![]() |
bd096c6bd8 | ||
![]() |
663048a372 | ||
![]() |
29f63cf868 | ||
![]() |
3e336d1d8c | ||
![]() |
798ac67711 | ||
![]() |
3103b55207 | ||
![]() |
5cece70830 | ||
![]() |
0ed246134d | ||
![]() |
e173c1acc1 | ||
![]() |
ce1255e8bd | ||
![]() |
d4a09c6459 | ||
![]() |
8d0faefe39 | ||
![]() |
76f118fafe | ||
![]() |
da06f8a946 | ||
![]() |
7edc3ca03a | ||
![]() |
c0c3b03023 | ||
![]() |
7f68cda81f | ||
![]() |
9781e7640b | ||
![]() |
e6bf175949 | ||
![]() |
d840bb85ca | ||
![]() |
00cec9b06f | ||
![]() |
7be16461e0 | ||
![]() |
895bbaa252 | ||
![]() |
6c229c1b28 | ||
![]() |
d53069e6bf | ||
![]() |
eb1737f6db | ||
![]() |
d120d07efa | ||
![]() |
be5561847f | ||
![]() |
5404ae6ee5 | ||
![]() |
7a020f58cd | ||
![]() |
28b707c0a6 | ||
![]() |
0d3bc31024 |
0
.ipfsignore
Normal file
871
DungeonGen.js
Normal file
|
@ -0,0 +1,871 @@
|
|||
/*
|
||||
Orteil's crappy dungeon generation library, 2013
|
||||
Unfinished and buggy, use at your own risk (please credit)
|
||||
http://orteil.dashnet.org
|
||||
|
||||
Rough process (might or might not be what actually happens) :
|
||||
1 make a room in the middle
|
||||
2 pick one of its walls (not corners)
|
||||
3 select a free tile on the other side of that wall
|
||||
4 iteratively expand the selection in one (corridors) or two (rooms) directions, stopping when we meet a wall or when we're above the size threshold
|
||||
5 compute that selection into a room
|
||||
6 add decorations to the room (pillars, water) but only on the center tiles, as to leave free passages (sprinkle destructible decorations anywhere)
|
||||
7 take a random floor tile in the room and repeat step 4, but don't stop at the walls of this room (this creates branching) - repeat about 5 times for interesting shapes
|
||||
8 add those branches to the room
|
||||
9 carve the room into the map, and set the initially selected wall as a door - set the new room's parent to the previous room, and add it to its parent's children
|
||||
10 repeat step 2 with any free wall on the map until the amount of tiles dug is above the desired fill ratio
|
||||
|
||||
Note : I should probably switch the rendering to canvas to allow stuff like occlusion shadows and lights
|
||||
*/
|
||||
|
||||
if (1==1 || undefined==Math.seedrandom)
|
||||
{
|
||||
//seeded random function, courtesy of http://davidbau.com/archives/2010/01/30/random_seeds_coded_hints_and_quintillions.html
|
||||
(function(a,b,c,d,e,f){function k(a){var b,c=a.length,e=this,f=0,g=e.i=e.j=0,h=e.S=[];for(c||(a=[c++]);d>f;)h[f]=f++;for(f=0;d>f;f++)h[f]=h[g=j&g+a[f%c]+(b=h[f])],h[g]=b;(e.g=function(a){for(var b,c=0,f=e.i,g=e.j,h=e.S;a--;)b=h[f=j&f+1],c=c*d+h[j&(h[f]=h[g=j&g+b])+(h[g]=b)];return e.i=f,e.j=g,c})(d)}function l(a,b){var e,c=[],d=(typeof a)[0];if(b&&"o"==d)for(e in a)try{c.push(l(a[e],b-1))}catch(f){}return c.length?c:"s"==d?a:a+"\0"}function m(a,b){for(var d,c=a+"",e=0;c.length>e;)b[j&e]=j&(d^=19*b[j&e])+c.charCodeAt(e++);return o(b)}function n(c){try{return a.crypto.getRandomValues(c=new Uint8Array(d)),o(c)}catch(e){return[+new Date,a,a.navigator.plugins,a.screen,o(b)]}}function o(a){return String.fromCharCode.apply(0,a)}var g=c.pow(d,e),h=c.pow(2,f),i=2*h,j=d-1;c.seedrandom=function(a,f){var j=[],p=m(l(f?[a,o(b)]:0 in arguments?a:n(),3),j),q=new k(j);return m(o(q.S),b),c.random=function(){for(var a=q.g(e),b=g,c=0;h>a;)a=(a+c)*d,b*=d,c=q.g(1);for(;a>=i;)a/=2,b/=2,c>>>=1;return(a+c)/b},p},m(c.random(),b)})(this,[],Math,256,6,52);
|
||||
}
|
||||
|
||||
if (1==1 || undefined==choose) {function choose(arr) {if (arr.length==0) return 0; else return arr[Math.floor(Math.random()*arr.length)];}}
|
||||
|
||||
|
||||
var DungeonGen=function()
|
||||
{
|
||||
var TILE_EMPTY=0;//solid
|
||||
var TILE_LIMIT=-100;//can't build anything here; edges of map
|
||||
var TILE_FLOOR_EDGE=100;
|
||||
var TILE_FLOOR_CENTER=110;
|
||||
var TILE_DOOR=200;
|
||||
var TILE_PILLAR=300;//not just pillars, could be any type of repetitive decoration
|
||||
var TILE_WATER=400;
|
||||
var TILE_WALL=500;
|
||||
var TILE_WALL_CORNER=510;
|
||||
var TILE_ENTRANCE=250;
|
||||
var TILE_EXIT=260;
|
||||
|
||||
var colors=[];
|
||||
colors[TILE_EMPTY]='000';
|
||||
colors[TILE_LIMIT]='900';
|
||||
colors[TILE_FLOOR_EDGE]='ffc';
|
||||
colors[TILE_FLOOR_CENTER]='ff9';
|
||||
colors[TILE_DOOR]='f9f';
|
||||
colors[TILE_PILLAR]='990';
|
||||
colors[TILE_WATER]='99f';
|
||||
colors[TILE_WALL]='960';
|
||||
colors[TILE_WALL_CORNER]='630';
|
||||
colors[TILE_ENTRANCE]='f9f';
|
||||
colors[TILE_EXIT]='f9f';
|
||||
|
||||
var rand=function(a,b){return Math.floor(Math.random()*(b-a+1)+a);}//return random value between a and b
|
||||
|
||||
var Patterns=[];
|
||||
this.Pattern=function(name,func)
|
||||
{
|
||||
this.name=name;
|
||||
this.func=func;
|
||||
Patterns.push(this);
|
||||
}
|
||||
new this.Pattern('Pillars',function(x,y,room)
|
||||
{
|
||||
if ((x+room.x)%2==0 && (y+room.y)%2==0 && Math.random()<0.8) return TILE_PILLAR;
|
||||
return 0;
|
||||
});
|
||||
new this.Pattern('Large pillars',function(x,y,room)
|
||||
{
|
||||
if ((x+room.x)%3<2 && (y+room.y)%3<2 && Math.random()<0.8) return TILE_PILLAR;
|
||||
return 0;
|
||||
});
|
||||
new this.Pattern('Sparse pillars',function(x,y,room)
|
||||
{
|
||||
if ((x+room.x)%3==0 && (y+room.y)%3==0 && Math.random()<0.8) return TILE_PILLAR;
|
||||
return 0;
|
||||
});
|
||||
new this.Pattern('Lines',function(x,y,room)
|
||||
{
|
||||
if (room.x%2==0) if ((x+room.x)%2==0 && Math.random()<0.98) return TILE_PILLAR;
|
||||
if (room.x%2==1) if ((y+room.y)%2==0 && Math.random()<0.98) return TILE_PILLAR;
|
||||
return 0;
|
||||
});
|
||||
|
||||
|
||||
var getRandomPattern=function()
|
||||
{return choose(Patterns);}
|
||||
|
||||
var defaultGenerator=function(me)
|
||||
{
|
||||
me.roomSize=10;
|
||||
me.corridorSize=5;
|
||||
me.fillRatio=1/3;
|
||||
me.corridorRatio=0.2;
|
||||
me.pillarRatio=0.2;
|
||||
me.waterRatio=0;
|
||||
me.branching=4;
|
||||
me.sizeVariance=0.2;
|
||||
|
||||
me.fillRatio=0.1+Math.random()*0.4;
|
||||
me.roomSize=Math.ceil(rand(5,15)*me.fillRatio*2);
|
||||
me.corridorSize=Math.ceil(rand(1,7)*me.fillRatio*2);
|
||||
me.corridorRatio=Math.random()*0.8+0.1;
|
||||
me.pillarRatio=Math.random()*0.5+0.5;
|
||||
me.waterRatio=Math.pow(Math.random(),2);
|
||||
me.branching=Math.floor(Math.random()*6);
|
||||
me.sizeVariance=Math.random();
|
||||
}
|
||||
|
||||
|
||||
this.Map=function(w,h,seed,params)
|
||||
{
|
||||
//create a new map
|
||||
//leave the seed out for a random seed
|
||||
//params is an object that contains custom parameters as defined in defaultGenerator
|
||||
//example : MyMap=new DungeonGen.Map(30,30,MySeed,{waterRatio:0.8}); (80 percent of the rooms will contain water)
|
||||
if (undefined!=seed) this.seed=seed; else {Math.seedrandom();this.seed=Math.random();}
|
||||
Math.seedrandom(this.seed);
|
||||
this.seedState=Math.random;
|
||||
this.w=w||20;
|
||||
this.h=h||20;
|
||||
|
||||
this.roomsAreHidden=0;
|
||||
|
||||
this.rooms=[];
|
||||
this.freeWalls=[];//all walls that would be a good spot for a door
|
||||
this.freeTiles=[];//all passable floor tiles
|
||||
this.doors=[];
|
||||
this.tiles=this.w*this.h;
|
||||
this.tilesDug=0;
|
||||
this.digs=0;//amount of digging steps
|
||||
this.stuck=0;//how many times we ran into a problem; stop digging if we get too many of these
|
||||
|
||||
this.data=[];//fill the map with 0
|
||||
for (var x=0;x<this.w;x++)
|
||||
{
|
||||
this.data[x]=[];
|
||||
for (var y=0;y<this.h;y++)
|
||||
{
|
||||
this.data[x][y]=[TILE_EMPTY,-1,0];//data is stored as [tile system type,room id,tile displayed type] (-1 is no room)
|
||||
if (x==0 || y==0 || x==this.w-1 || y==this.h-1) this.data[x][y]=[TILE_LIMIT,-1,0];
|
||||
}
|
||||
}
|
||||
|
||||
defaultGenerator(this);
|
||||
if (params)
|
||||
{
|
||||
for (var i in params)
|
||||
{
|
||||
this[i]=params[i];
|
||||
}
|
||||
}
|
||||
Math.seedrandom();
|
||||
|
||||
}
|
||||
|
||||
this.Map.prototype.getType=function(x,y){return this.data[x][y][0];}
|
||||
this.Map.prototype.getRoom=function(x,y){if (this.data[x][y][1]!=-1) return this.rooms[this.data[x][y][1]]; else return -1;}
|
||||
this.Map.prototype.getTile=function(x,y){return this.rooms[this.data[x][y][2]];}
|
||||
|
||||
this.Map.prototype.isWall=function(x,y)
|
||||
{
|
||||
var n=0;
|
||||
for (var i in this.freeWalls){if (this.freeWalls[i][0]==x && this.freeWalls[i][1]==y) return n; else n++;}
|
||||
return -1;
|
||||
}
|
||||
this.Map.prototype.isFloor=function(x,y)
|
||||
{
|
||||
var n=0;
|
||||
for (var i in this.freeTiles){if (this.freeTiles[i][0]==x && this.freeTiles[i][1]==y) return n; else n++;}
|
||||
return -1;
|
||||
}
|
||||
this.Map.prototype.removeFreeTile=function(x,y)
|
||||
{
|
||||
this.freeTiles.splice(this.isFloor(x,y),1);
|
||||
}
|
||||
|
||||
this.Map.prototype.fill=function(what)
|
||||
{
|
||||
//fill with something (either a set value, or a function that takes the map, a position X and a position Y as arguments)
|
||||
//NOTE : this also resets the rooms!
|
||||
//example : MyMap.fill(function(m,x,y){return Math.floor((Math.random());});
|
||||
//...will fill the map with 0s and 1s
|
||||
var func=0;
|
||||
if (typeof(what)=='function') func=1;
|
||||
for (var x=0;x<this.w;x++){for (var y=0;y<this.h;y++){
|
||||
if (func) this.data[x][y]=[what(this,x,y),-1,0]; else this.data[x][y]=[what,-1,0];
|
||||
}}
|
||||
this.rooms=[];
|
||||
}
|
||||
|
||||
this.Map.prototype.fillZone=function(X,Y,W,H,what)
|
||||
{
|
||||
//just plain fill a rectangle
|
||||
for (var x=X;x<X+W;x++){for (var y=Y;y<Y+H;y++){
|
||||
this.data[x][y][0]=what;
|
||||
}}
|
||||
}
|
||||
|
||||
this.Map.prototype.getRoomTile=function(room,x,y)
|
||||
{
|
||||
var n=0;
|
||||
for (var i in room.tiles) {if (room.tiles[i].x==x && room.tiles[i].y==y) return n; else n++;}
|
||||
return -1;
|
||||
}
|
||||
|
||||
this.Map.prototype.getFloorTileInRoom=function(room)
|
||||
{
|
||||
var tiles=[];
|
||||
for (var i in room.tiles) {if (room.tiles[i].type==TILE_FLOOR_EDGE || room.tiles[i].type==TILE_FLOOR_CENTER) tiles.push(room.tiles[i]);}
|
||||
return choose(tiles);
|
||||
}
|
||||
|
||||
this.Map.prototype.canPlaceRoom=function(rx,ry,rw,rh)
|
||||
{
|
||||
if (rx<2 || ry<2 || rx+rw>=this.w-1 || ry+rh>=this.h-1) return false;
|
||||
for (var x=rx;x<rx+rw;x++)
|
||||
{
|
||||
for (var y=ry;y<ry+rh;y++)
|
||||
{
|
||||
var tile=this.getType(x,y);
|
||||
var room=this.getRoom(x,y);
|
||||
if (tile==TILE_LIMIT) return false;
|
||||
if (room!=-1) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
this.Map.prototype.setRoomTile=function(room,x,y,tile)
|
||||
{
|
||||
//var mapTile=this.getType(x,y);
|
||||
var oldTile=this.getRoomTile(room,x,y);
|
||||
var oldTileType=oldTile!=-1?room.tiles[oldTile].type:-1;
|
||||
if (oldTile!=-1 && (
|
||||
//(tile!=TILE_FLOOR_EDGE && tile!=TILE_FLOOR_CENTER) ||// && (oldTileType!=TILE_FLOOR_EDGE && oldTileType!=TILE_FLOOR_CENTER)) ||
|
||||
//(tile!=TILE_FLOOR_EDGE && tile!=TILE_FLOOR_CENTER && (oldTileType!=TILE_FLOOR_EDGE && oldTileType!=TILE_FLOOR_CENTER)) ||
|
||||
(tile==TILE_WALL || tile==TILE_WALL_CORNER) ||//don't place a wall over an existing room
|
||||
(tile==TILE_FLOOR_EDGE && oldTileType==TILE_FLOOR_CENTER)//don't place an edge floor over a center floor
|
||||
)) {return false;}
|
||||
else
|
||||
{
|
||||
if (oldTile!=-1) room.tiles.splice(oldTile,1);
|
||||
room.tiles.push({x:x,y:y,type:tile,score:0});
|
||||
if ((tile==TILE_FLOOR_EDGE || tile==TILE_FLOOR_CENTER) && (oldTileType!=TILE_FLOOR_EDGE && oldTileType!=TILE_FLOOR_CENTER)) room.freeTiles++;
|
||||
else if (tile!=TILE_FLOOR_EDGE && tile!=TILE_FLOOR_CENTER && (oldTileType==TILE_FLOOR_EDGE || oldTileType==TILE_FLOOR_CENTER)) room.freeTiles--;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
this.Map.prototype.expandRoom=function(room,rx,ry,rw,rh)
|
||||
{
|
||||
var x=0;var y=0;
|
||||
//floor
|
||||
for (var x=rx;x<rx+rw;x++){for (var y=ry;y<ry+rh;y++){
|
||||
this.setRoomTile(room,x,y,TILE_FLOOR_EDGE);
|
||||
}}
|
||||
for (var x=rx+1;x<rx+rw-1;x++){for (var y=ry+1;y<ry+rh-1;y++){
|
||||
this.setRoomTile(room,x,y,TILE_FLOOR_CENTER);
|
||||
}}
|
||||
//walls
|
||||
y=ry-1;
|
||||
for (var x=rx;x<rx+rw;x++){
|
||||
this.setRoomTile(room,x,y,TILE_WALL);
|
||||
}
|
||||
y=ry+rh;
|
||||
for (var x=rx;x<rx+rw;x++){
|
||||
this.setRoomTile(room,x,y,TILE_WALL);
|
||||
}
|
||||
x=rx-1;
|
||||
for (var y=ry;y<ry+rh;y++){
|
||||
this.setRoomTile(room,x,y,TILE_WALL);
|
||||
}
|
||||
x=rx+rw;
|
||||
for (var y=ry;y<ry+rh;y++){
|
||||
this.setRoomTile(room,x,y,TILE_WALL);
|
||||
}
|
||||
//corners
|
||||
x=rx-1;y=ry-1;
|
||||
this.setRoomTile(room,x,y,TILE_WALL_CORNER);
|
||||
x=rx+rw;y=ry-1;
|
||||
this.setRoomTile(room,x,y,TILE_WALL_CORNER);
|
||||
x=rx-1;y=ry+rh;
|
||||
this.setRoomTile(room,x,y,TILE_WALL_CORNER);
|
||||
x=rx+rw;y=ry+rh;
|
||||
this.setRoomTile(room,x,y,TILE_WALL_CORNER);
|
||||
|
||||
//decoration
|
||||
var water=Math.random()<this.waterRatio?1:0;
|
||||
var pattern=Math.random()<this.pillarRatio?getRandomPattern():0;
|
||||
for (var x=rx;x<rx+rw;x++){for (var y=ry;y<ry+rh;y++){
|
||||
if (room.tiles[this.getRoomTile(room,x,y)].type==TILE_FLOOR_CENTER)
|
||||
{
|
||||
var tile=0;
|
||||
if (water!=0) tile=TILE_WATER;
|
||||
if (pattern!=0)
|
||||
{
|
||||
tile=pattern.func(x,y,room)||tile;
|
||||
}
|
||||
if (tile!=0) this.setRoomTile(room,x,y,tile);
|
||||
}
|
||||
}}
|
||||
}
|
||||
|
||||
this.Map.prototype.newRoom=function(x,y,w,h,parent)
|
||||
{
|
||||
//create a new abstract room, ready to be carved
|
||||
var room={};
|
||||
room.id=this.rooms.length;
|
||||
room.w=w;//||rand(2,this.roomSize);
|
||||
room.h=h;//||rand(2,this.roomSize);
|
||||
room.x=x||rand(1,this.w-room.w-1);
|
||||
room.y=y||rand(1,this.h-room.h-1);
|
||||
room.tiles=[];
|
||||
room.freeTiles=0;
|
||||
room.parent=parent?parent:-1;
|
||||
room.children=[];
|
||||
room.gen=0;
|
||||
room.door=0;
|
||||
room.corridor=Math.random()<this.corridorRatio?1:0;
|
||||
room.hidden=this.roomsAreHidden;//if 1, don't draw
|
||||
//if (room.parent!=-1) room.corridor=!room.parent.corridor;//alternate rooms and corridors
|
||||
|
||||
return room;
|
||||
}
|
||||
this.Map.prototype.planRoom=function(room)
|
||||
{
|
||||
var branches=this.branching+1;
|
||||
var forcedExpansions=[];
|
||||
var w=room.w;
|
||||
var h=room.h;
|
||||
while (w>0 && h>0)
|
||||
{
|
||||
if (w>0) {forcedExpansions.push(1,3);w--;}
|
||||
if (h>0) {forcedExpansions.push(2,4);h--;}
|
||||
}
|
||||
|
||||
for (var i=0;i<branches;i++)
|
||||
{
|
||||
var steps=0;
|
||||
var expansions=[];
|
||||
if (!room.corridor)
|
||||
{
|
||||
expansions=[1,2,3,4];
|
||||
steps=this.roomSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
expansions=choose([[1,3],[2,4]]);
|
||||
steps=this.corridorSize;
|
||||
}
|
||||
steps=Math.max(room.w+room.h,Math.ceil(steps*(1-Math.random()*this.sizeVariance)));
|
||||
if (room.tiles.length==0) {var rx=room.x;var ry=room.y;var rw=1;var rh=1;}
|
||||
else {var randomTile=this.getFloorTileInRoom(room);var rx=randomTile.x;var ry=randomTile.y;var rw=1;var rh=1;}
|
||||
for (var ii=0;ii<steps;ii++)
|
||||
{
|
||||
if (expansions.length==0) break;
|
||||
var xd=0;var yd=0;var wd=0;var hd=0;
|
||||
var side=choose(expansions);
|
||||
if (forcedExpansions.length>0) side=forcedExpansions[0];
|
||||
if (side==1) {xd=-1;wd=1;}
|
||||
else if (side==2) {yd=-1;hd=1;}
|
||||
else if (side==3) {wd=1;}
|
||||
else if (side==4) {hd=1;}
|
||||
if (this.canPlaceRoom(rx+xd,ry+yd,rw+wd,rh+hd)) {rx+=xd;ry+=yd;rw+=wd;rh+=hd;} else expansions.splice(expansions.indexOf(side),1);
|
||||
if (forcedExpansions.length>0) forcedExpansions.splice(0,1);
|
||||
}
|
||||
if (rw>1 || rh>1)
|
||||
{
|
||||
this.expandRoom(room,rx,ry,rw,rh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.Map.prototype.carve=function(room)
|
||||
{
|
||||
//carve a room into the map
|
||||
for (var i in room.tiles)
|
||||
{
|
||||
var thisTile=room.tiles[i];
|
||||
var x=thisTile.x;var y=thisTile.y;
|
||||
var myType=this.data[x][y][0];
|
||||
var type=thisTile.type;
|
||||
|
||||
if ((type==TILE_WALL || type==TILE_WALL_CORNER) && this.isWall(x,y)!=-1) {this.freeWalls.splice(this.isWall(x,y),1);}
|
||||
|
||||
if (this.data[x][y][1]!=-1 && (type==TILE_WALL || type==TILE_WALL_CORNER)) {}
|
||||
else
|
||||
{
|
||||
if (this.data[x][y][1]==-1) this.tilesDug++;
|
||||
this.data[x][y]=[thisTile.type,room.id,0];
|
||||
if (x>1 && y>1 && x<this.w-2 && y<this.h-2 && type==TILE_WALL) this.freeWalls.push([x,y]);
|
||||
if (type==TILE_FLOOR_EDGE || type==TILE_FLOOR_CENTER) this.freeTiles.push([x,y]);
|
||||
}
|
||||
var pos=[x,y];
|
||||
}
|
||||
this.rooms[room.id]=room;
|
||||
}
|
||||
|
||||
this.Map.prototype.newRandomRoom=function(params)
|
||||
{
|
||||
var success=1;
|
||||
params=params||{};//params is an object such as {corridor:1}
|
||||
var door=choose(this.freeWalls);//select a free wall to use as a door
|
||||
if (!door) {success=0;}
|
||||
else
|
||||
{
|
||||
//this.data[door[0]][door[1]][0]=TILE_LIMIT;//not door
|
||||
var parentRoom=this.getRoom(door[0],door[1]);
|
||||
var sides=[];//select a free side of that door
|
||||
if (this.getType(door[0]-1,door[1])==TILE_EMPTY) sides.push([-1,0]);
|
||||
if (this.getType(door[0]+1,door[1])==TILE_EMPTY) sides.push([1,0]);
|
||||
if (this.getType(door[0],door[1]-1)==TILE_EMPTY) sides.push([0,-1]);
|
||||
if (this.getType(door[0],door[1]+1)==TILE_EMPTY) sides.push([0,1]);
|
||||
var side=choose(sides);
|
||||
if (!side) {success=0;this.freeWalls.splice(this.isWall(door[0],door[1]),1);}
|
||||
else
|
||||
{
|
||||
var room=this.newRoom(door[0]+side[0],door[1]+side[1],0,0,parentRoom);//try a new room from this spot
|
||||
for (var i in params)
|
||||
{
|
||||
room[i]=params[i];
|
||||
}
|
||||
this.planRoom(room);
|
||||
if (room.tiles.length>0 && room.freeTiles>0)//we got a decent room
|
||||
{
|
||||
this.carve(room);
|
||||
this.data[door[0]][door[1]][0]=TILE_DOOR;//place door
|
||||
room.door=[door[0],door[1]];
|
||||
this.data[door[0]][door[1]][1]=room.id;//set ID
|
||||
this.freeWalls.splice(this.isWall(door[0],door[1]),1);//the door isn't a wall anymore
|
||||
this.doors.push([door[0],door[1],room]);
|
||||
//remove free tiles on either side of the door
|
||||
if (this.isFloor(door[0]+side[0],door[1]+side[1])!=-1) this.removeFreeTile(door[0]+side[0],door[1]+side[1]);
|
||||
if (this.isFloor(door[0]-side[0],door[1]-side[1])!=-1) this.removeFreeTile(door[0]-side[0],door[1]-side[1]);
|
||||
room.parent=parentRoom;
|
||||
parentRoom.children.push(room);
|
||||
room.gen=parentRoom.gen+1;
|
||||
}
|
||||
else//not a good spot; remove this tile from the list of walls
|
||||
{
|
||||
this.freeWalls.splice(this.isWall(door[0],door[1]),1);
|
||||
success=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (success) return room;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
this.Map.prototype.getRandomSpotInRoom=function(room)
|
||||
{
|
||||
var listOfTiles=[];
|
||||
for (var i in room.tiles)
|
||||
{
|
||||
if ((room.tiles[i].type==TILE_FLOOR_EDGE || room.tiles[i].type==TILE_FLOOR_CENTER) && this.isFloor(room.tiles[i].x,room.tiles[i].y)!=-1)
|
||||
{
|
||||
listOfTiles.push(room.tiles[i]);
|
||||
}
|
||||
}
|
||||
if (listOfTiles.length==0) return -1;
|
||||
return choose(listOfTiles);
|
||||
}
|
||||
this.Map.prototype.getBestSpotInRoom=function(room)
|
||||
{
|
||||
var highest=-1;
|
||||
var listOfHighest=[];
|
||||
for (var i in room.tiles)
|
||||
{
|
||||
if ((room.tiles[i].type==TILE_FLOOR_EDGE || room.tiles[i].type==TILE_FLOOR_CENTER) && this.isFloor(room.tiles[i].x,room.tiles[i].y)!=-1)
|
||||
{
|
||||
if (room.tiles[i].score>highest)
|
||||
{
|
||||
listOfHighest=[];
|
||||
highest=room.tiles[i].score;
|
||||
listOfHighest.push(room.tiles[i]);
|
||||
}
|
||||
else if (room.tiles[i].score==highest)
|
||||
{
|
||||
listOfHighest.push(room.tiles[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (listOfHighest.length==0) return -1;
|
||||
return choose(listOfHighest);
|
||||
}
|
||||
this.Map.prototype.getEarliestRoom=function()
|
||||
{
|
||||
return this.rooms[0];
|
||||
}
|
||||
this.Map.prototype.getDeepestRoom=function()
|
||||
{
|
||||
var deepest=0;
|
||||
var deepestRoom=this.rooms[0];
|
||||
for (var i in this.rooms)
|
||||
{
|
||||
if ((this.rooms[i].gen+Math.sqrt(this.rooms[i].freeTiles)*0.05)>=deepest && this.rooms[i].corridor==0 && this.rooms[i].freeTiles>4) {deepest=(this.rooms[i].gen+Math.sqrt(this.rooms[i].freeTiles)*0.05);deepestRoom=this.rooms[i];}
|
||||
}
|
||||
return deepestRoom;
|
||||
}
|
||||
|
||||
this.Map.prototype.dig=function()
|
||||
{
|
||||
//one step in which we try to carve new stuff
|
||||
//returns 0 when we couldn't dig this step, 1 when we could, and 2 when the digging is complete
|
||||
Math.random=this.seedState;
|
||||
|
||||
var badDig=0;
|
||||
|
||||
if (this.digs==0)//first dig : build a starting room in the middle of the map
|
||||
{
|
||||
var w=rand(3,7);
|
||||
var h=rand(3,7);
|
||||
var room=this.newRoom(Math.floor(this.w/2-w/2),Math.floor(this.h/2-h/2),w,h);
|
||||
room.corridor=0;
|
||||
this.planRoom(room);
|
||||
this.carve(room);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.newRandomRoom()==0) badDig++;
|
||||
}
|
||||
if (badDig>0) this.stuck++;
|
||||
|
||||
this.digs++;
|
||||
|
||||
var finished=0;
|
||||
if (this.tilesDug>=this.tiles*this.fillRatio) finished=1;
|
||||
if (this.stuck>100) finished=1;
|
||||
|
||||
if (finished==1)//last touch : try to add a whole room at the end
|
||||
{
|
||||
for (var i=0;i<10;i++)
|
||||
{
|
||||
var newRoom=this.newRandomRoom({corridor:0,w:rand(3,7),h:rand(3,7)});
|
||||
if (newRoom!=0 && newRoom.freeTiles>15) break;
|
||||
}
|
||||
}
|
||||
|
||||
Math.seedrandom();
|
||||
if (finished==1) return 1; else if (badDig>0) return -1; else return 0;
|
||||
}
|
||||
|
||||
this.Map.prototype.finish=function()
|
||||
{
|
||||
//touch up the map : add pillars in corners etc
|
||||
/*
|
||||
//set paths
|
||||
for (var i in this.rooms)
|
||||
{
|
||||
var me=this.rooms[i];
|
||||
if (me.door!=0)
|
||||
{
|
||||
var doors=[];
|
||||
doors.push(me.door);
|
||||
for (var ii in me.children)
|
||||
{
|
||||
if (me.children[ii].door!=0) doors.push(me.children[ii].door);
|
||||
}
|
||||
for (var ii in doors)
|
||||
{
|
||||
this.data[doors[ii][0]][doors[ii][1]][0]=TILE_LIMIT;
|
||||
//ideally we should run agents that step from each door to the next
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
for (var i in this.rooms)
|
||||
{
|
||||
var pillars=Math.random()<this.pillarRatio;
|
||||
for (var ii in this.rooms[i].tiles)
|
||||
{
|
||||
var x=this.rooms[i].tiles[ii].x;
|
||||
var y=this.rooms[i].tiles[ii].y;
|
||||
var me=this.data[x][y][0];
|
||||
var x1=this.data[x-1][y][0];
|
||||
var x2=this.data[x+1][y][0];
|
||||
var y1=this.data[x][y-1][0];
|
||||
var y2=this.data[x][y+1][0];
|
||||
var xy1=this.data[x-1][y-1][0];
|
||||
var xy2=this.data[x+1][y-1][0];
|
||||
var xy3=this.data[x-1][y+1][0];
|
||||
var xy4=this.data[x+1][y+1][0];
|
||||
|
||||
var walls=0;
|
||||
if ((x1==TILE_WALL||x1==TILE_WALL_CORNER)) walls++;
|
||||
if ((y1==TILE_WALL||y1==TILE_WALL_CORNER)) walls++;
|
||||
if ((x2==TILE_WALL||x2==TILE_WALL_CORNER)) walls++;
|
||||
if ((y2==TILE_WALL||y2==TILE_WALL_CORNER)) walls++;
|
||||
if ((xy1==TILE_WALL||xy1==TILE_WALL_CORNER)) walls++;
|
||||
if ((xy2==TILE_WALL||xy2==TILE_WALL_CORNER)) walls++;
|
||||
if ((xy3==TILE_WALL||xy3==TILE_WALL_CORNER)) walls++;
|
||||
if ((xy4==TILE_WALL||xy4==TILE_WALL_CORNER)) walls++;
|
||||
|
||||
var floors=0;
|
||||
if ((x1==TILE_FLOOR_CENTER||x1==TILE_FLOOR_EDGE)) floors++;
|
||||
if ((y1==TILE_FLOOR_CENTER||y1==TILE_FLOOR_EDGE)) floors++;
|
||||
if ((x2==TILE_FLOOR_CENTER||x2==TILE_FLOOR_EDGE)) floors++;
|
||||
if ((y2==TILE_FLOOR_CENTER||y2==TILE_FLOOR_EDGE)) floors++;
|
||||
if ((xy1==TILE_FLOOR_CENTER||xy1==TILE_FLOOR_EDGE)) floors++;
|
||||
if ((xy2==TILE_FLOOR_CENTER||xy2==TILE_FLOOR_EDGE)) floors++;
|
||||
if ((xy3==TILE_FLOOR_CENTER||xy3==TILE_FLOOR_EDGE)) floors++;
|
||||
if ((xy4==TILE_FLOOR_CENTER||xy4==TILE_FLOOR_EDGE)) floors++;
|
||||
|
||||
var complete=0;
|
||||
if (walls+floors==8) complete=1;
|
||||
|
||||
var angle=0;
|
||||
if (complete)
|
||||
{
|
||||
var top=0;
|
||||
var left=0;
|
||||
var right=0;
|
||||
var bottom=0;
|
||||
if ((xy1==TILE_WALL||xy1==TILE_WALL_CORNER) && (y1==TILE_WALL||y1==TILE_WALL_CORNER) && (xy2==TILE_WALL||xy2==TILE_WALL_CORNER)) top=1;
|
||||
else if ((xy1==TILE_FLOOR_CENTER||xy1==TILE_FLOOR_EDGE) && (y1==TILE_FLOOR_CENTER||y1==TILE_FLOOR_EDGE) && (xy2==TILE_FLOOR_CENTER||xy2==TILE_FLOOR_EDGE)) top=-1;
|
||||
if ((xy2==TILE_WALL||xy2==TILE_WALL_CORNER) && (x2==TILE_WALL||x2==TILE_WALL_CORNER) && (xy4==TILE_WALL||xy4==TILE_WALL_CORNER)) right=1;
|
||||
else if ((xy2==TILE_FLOOR_CENTER||xy2==TILE_FLOOR_EDGE) && (x2==TILE_FLOOR_CENTER||x2==TILE_FLOOR_EDGE) && (xy4==TILE_FLOOR_CENTER||xy4==TILE_FLOOR_EDGE)) right=-1;
|
||||
if ((xy1==TILE_WALL||xy1==TILE_WALL_CORNER) && (x1==TILE_WALL||x1==TILE_WALL_CORNER) && (xy3==TILE_WALL||xy3==TILE_WALL_CORNER)) left=1;
|
||||
else if ((xy1==TILE_FLOOR_CENTER||xy1==TILE_FLOOR_EDGE) && (x1==TILE_FLOOR_CENTER||x1==TILE_FLOOR_EDGE) && (xy3==TILE_FLOOR_CENTER||xy3==TILE_FLOOR_EDGE)) left=-1;
|
||||
if ((xy3==TILE_WALL||xy3==TILE_WALL_CORNER) && (y2==TILE_WALL||y2==TILE_WALL_CORNER) && (xy4==TILE_WALL||xy4==TILE_WALL_CORNER)) bottom=1;
|
||||
else if ((xy3==TILE_FLOOR_CENTER||xy3==TILE_FLOOR_EDGE) && (y2==TILE_FLOOR_CENTER||y2==TILE_FLOOR_EDGE) && (xy4==TILE_FLOOR_CENTER||xy4==TILE_FLOOR_EDGE)) bottom=-1;
|
||||
if ((top==1 && bottom==-1) || (top==-1 && bottom==1) || (left==1 && right==-1) || (left==-1 && right==1)) angle=1;
|
||||
}
|
||||
|
||||
if (pillars && Math.random()<0.8 && this.rooms[i].freeTiles>4)
|
||||
{
|
||||
if ((angle==1 || (complete && walls==7)) && me==TILE_FLOOR_EDGE && x1!=TILE_DOOR && x2!=TILE_DOOR && y1!=TILE_DOOR && y2!=TILE_DOOR)
|
||||
{
|
||||
this.data[x][y][0]=TILE_PILLAR;
|
||||
me=TILE_PILLAR;
|
||||
this.removeFreeTile(x,y);
|
||||
this.rooms[i].freeTiles--;
|
||||
}
|
||||
}
|
||||
|
||||
//calculate score (for placing items and exits)
|
||||
if (top==1 || bottom==1 || left==1 || right==1)
|
||||
{
|
||||
this.rooms[i].tiles[ii].score+=2;
|
||||
}
|
||||
if (walls>5 || floors>5)
|
||||
{
|
||||
this.rooms[i].tiles[ii].score+=1;
|
||||
}
|
||||
if (walls==7 || floors==8)
|
||||
{
|
||||
this.rooms[i].tiles[ii].score+=5;
|
||||
}
|
||||
if ((me!=TILE_FLOOR_CENTER && me!=TILE_FLOOR_EDGE) || x1==TILE_DOOR || x2==TILE_DOOR || y1==TILE_DOOR || y2==TILE_DOOR) this.rooms[i].tiles[ii].score=-1;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//carve entrance and exit
|
||||
var entrance=this.getBestSpotInRoom(this.getEarliestRoom());
|
||||
this.data[entrance.x][entrance.y][0]=TILE_ENTRANCE;
|
||||
this.entrance=[entrance.x,entrance.y];
|
||||
entrance.score=0;
|
||||
this.removeFreeTile(entrance.x,entrance.y);
|
||||
var exit=this.getBestSpotInRoom(this.getDeepestRoom());
|
||||
this.data[exit.x][exit.y][0]=TILE_EXIT;
|
||||
this.exit=[exit.x,exit.y];
|
||||
this.removeFreeTile(exit.x,exit.y);
|
||||
exit.score=0;
|
||||
|
||||
/*
|
||||
for (var i in this.doors)//remove door tiles (to add later; replace the tiles by entities that delete themselves when opened)
|
||||
{
|
||||
this.data[this.doors[i][0]][this.doors[i][1]][0]=TILE_FLOOR_EDGE;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
this.Map.prototype.isObstacle=function(x,y)
|
||||
{
|
||||
var free=[TILE_FLOOR_EDGE,TILE_FLOOR_CENTER,TILE_DOOR,TILE_ENTRANCE,TILE_EXIT];
|
||||
for (var i in free)
|
||||
{
|
||||
if (this.data[x][y][0]==free[i]) return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
var joinTile=function(map,x,y,joinWith)
|
||||
{
|
||||
//for the tile at x,y, return 2 if it joins with its horizontal neighbors, 3 if it joins with its vertical neighbors, 1 if it joins with either both or neither.
|
||||
//joinWith contains the tile types that count as joinable, in addition to this tile. (don't add the tested tile to joinWith!)
|
||||
var p=1;
|
||||
var me=map.data[x][y][0];
|
||||
var x1=map.data[x-1][y][0];
|
||||
var x2=map.data[x+1][y][0];
|
||||
var y1=map.data[x][y-1][0];
|
||||
var y2=map.data[x][y+1][0];
|
||||
joinWith.push(me);
|
||||
var joinsX=0;
|
||||
for (var i in joinWith)
|
||||
{
|
||||
if (x1==joinWith[i]) joinsX++;
|
||||
if (x2==joinWith[i]) joinsX++;
|
||||
}
|
||||
var joinsY=0;
|
||||
for (var i in joinWith)
|
||||
{
|
||||
if (y1==joinWith[i]) joinsY++;
|
||||
if (y2==joinWith[i]) joinsY++;
|
||||
}
|
||||
if (joinsX==2 && joinsY==2) p=1;
|
||||
else if (joinsX==2) p=2;
|
||||
else if (joinsY==2) p=3;
|
||||
return p;
|
||||
}
|
||||
this.Map.prototype.getPic=function(x,y)
|
||||
{
|
||||
//return a position [x,y] in the tiles (as 0, 1, 2...) for the tile on the map at position x,y
|
||||
if (Tiles[this.data[x][y][2]])
|
||||
{
|
||||
if (Tiles[this.data[x][y][2]].joinType=='join')
|
||||
{
|
||||
var thisPic=Tiles[this.data[x][y][2]].pic;
|
||||
thisPic=[thisPic[0],thisPic[1]];//why is this even necessary?
|
||||
var joinWith=[];
|
||||
if (this.data[x][y][0]==TILE_WALL) joinWith.push(TILE_WALL_CORNER);
|
||||
else if (this.data[x][y][0]==TILE_DOOR) joinWith.push(TILE_WALL,TILE_WALL_CORNER);
|
||||
thisPic[0]+=joinTile(this,x,y,joinWith)-1;
|
||||
return thisPic;
|
||||
}
|
||||
else if (Tiles[this.data[x][y][2]].joinType=='random3')
|
||||
{
|
||||
var thisPic=Tiles[this.data[x][y][2]].pic;
|
||||
thisPic=[thisPic[0],thisPic[1]];
|
||||
thisPic[0]+=Math.floor(Math.random()*3);
|
||||
return thisPic;
|
||||
}
|
||||
return Tiles[this.data[x][y][2]].pic;
|
||||
}
|
||||
return [0,0];
|
||||
}
|
||||
|
||||
var Tiles=[];
|
||||
var TilesByName=[];
|
||||
this.Tile=function(name,pic,joinType)
|
||||
{
|
||||
this.name=name;
|
||||
this.pic=pic;
|
||||
this.joinType=joinType||'none';
|
||||
this.id=Tiles.length;
|
||||
Tiles[this.id]=this;
|
||||
TilesByName[this.name]=this;
|
||||
}
|
||||
new this.Tile('void',[0,0]);
|
||||
this.loadTiles=function(tiles)
|
||||
{
|
||||
for (var i in tiles)
|
||||
{
|
||||
var name=tiles[i][0];
|
||||
var pic=tiles[i][1];
|
||||
var joinType=tiles[i][2];
|
||||
new this.Tile(name,pic,joinType);
|
||||
}
|
||||
}
|
||||
|
||||
var computeTile=function(tile,tiles,value,name)
|
||||
{
|
||||
if (tile==value && tiles[name]) return TilesByName[tiles[name]];
|
||||
return 0;
|
||||
}
|
||||
this.Map.prototype.assignTiles=function(room,tiles)
|
||||
{
|
||||
//set the displayed tiles for this room
|
||||
for (var i in room.tiles)
|
||||
{
|
||||
var type=Tiles[0];
|
||||
var me=room.tiles[i];
|
||||
var tile=this.data[me.x][me.y][0];
|
||||
type=computeTile(tile,tiles,TILE_WALL_CORNER,'wall corner')||type;
|
||||
type=computeTile(tile,tiles,TILE_WALL,'wall')||type;
|
||||
type=computeTile(tile,tiles,TILE_FLOOR_EDGE,'floor edges')||type;
|
||||
type=computeTile(tile,tiles,TILE_FLOOR_CENTER,'floor')||type;
|
||||
type=computeTile(tile,tiles,TILE_PILLAR,'pillar')||type;
|
||||
type=computeTile(tile,tiles,TILE_DOOR,'door')||type;
|
||||
type=computeTile(tile,tiles,TILE_WATER,'water')||type;
|
||||
type=computeTile(tile,tiles,TILE_ENTRANCE,'entrance')||type;
|
||||
type=computeTile(tile,tiles,TILE_EXIT,'exit')||type;
|
||||
|
||||
this.data[me.x][me.y][2]=type.id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.Map.prototype.draw=function(size)
|
||||
{
|
||||
//return a string containing a rough visual representation of the map
|
||||
var str='';
|
||||
var size=size||10;
|
||||
for (var y=0;y<this.h;y++){for (var x=0;x<this.w;x++){
|
||||
var text='';
|
||||
if (this.isFloor(x,y)!=-1) text='o';
|
||||
if (this.isWall(x,y)!=-1) text+='x';
|
||||
var room=this.getRoom(x,y);
|
||||
var opacity=Math.max(0.1,1-(this.getRoom(x,y).gen/10));
|
||||
var title=room.freeTiles;//this.data[x][y][0].toString();
|
||||
text='';
|
||||
str+='<div style="opacity:'+opacity+';width:'+size+'px;height:'+size+'px;position:absolute;left:'+(x*size)+'px;top:'+(y*size)+'px;display:block;padding:0px;margin:0px;background:#'+colors[this.data[x][y][0]]+';color:#999;" title="'+title+'">'+text+'</div>';
|
||||
}
|
||||
str+='<br>';
|
||||
}
|
||||
str='<div style="position:relative;width:'+(this.w*size)+'px;height:'+(this.h*size)+'px;background:#000;font-family:Courier;font-size:'+size+'px;float:left;margin:10px;">'+str+'</div>';
|
||||
return str;
|
||||
}
|
||||
|
||||
this.Map.prototype.drawDetailed=function()
|
||||
{
|
||||
//return a string containing a rough visual representation of the map (with graphics)
|
||||
var str='';
|
||||
var size=16;
|
||||
for (var y=0;y<this.h;y++){for (var x=0;x<this.w;x++){
|
||||
var room=this.getRoom(x,y);
|
||||
//var opacity=Math.max(0.1,room.tiles[this.getRoomTile(room,x,y)].score);
|
||||
var opacity=1;
|
||||
var title='void';
|
||||
if (room!=-1)
|
||||
{
|
||||
opacity=Math.max(0.1,1-room.gen/5);
|
||||
if (this.data[x][y][0]==TILE_ENTRANCE || this.data[x][y][0]==TILE_EXIT) opacity=1;
|
||||
title=(room.corridor?'corridor':'room')+' '+room.id+' | depth : '+room.gen+' | children : '+room.children.length;
|
||||
}
|
||||
var pic=this.getPic(x,y);
|
||||
str+='<div style="opacity:'+opacity+';width:'+size+'px;height:'+size+'px;position:absolute;left:'+(x*size)+'px;top:'+(y*size)+'px;display:block;padding:0px;margin:0px;background:#'+colors[this.data[x][y][0]]+' url(img/dungeonTiles.png) '+(-pic[0]*16)+'px '+(-pic[1]*16)+'px;color:#999;" title="'+title+'"></div>';
|
||||
}
|
||||
str+='<br>';
|
||||
}
|
||||
str='<div style="box-shadow:0px 0px 12px 6px #00061b;position:relative;width:'+(this.w*size)+'px;height:'+(this.h*size)+'px;background:#00061b;font-family:Courier;font-size:'+size+'px;float:left;margin:10px;">'+str+'</div>';
|
||||
return str;
|
||||
}
|
||||
|
||||
this.Map.prototype.getStr=function()
|
||||
{
|
||||
//return a string containing the map with tile graphics, ready to be pasted in a wrapper
|
||||
var str='';
|
||||
var size=16;
|
||||
for (var y=0;y<this.h;y++){for (var x=0;x<this.w;x++){
|
||||
var room=this.getRoom(x,y);
|
||||
//var opacity=Math.max(0.1,room.tiles[this.getRoomTile(room,x,y)].score);
|
||||
var opacity=1;
|
||||
var title='void';
|
||||
var pic=this.getPic(x,y);
|
||||
if (room!=-1)
|
||||
{
|
||||
/*
|
||||
opacity=Math.max(0.1,1-room.gen/5);
|
||||
if (room.hidden) opacity=0;
|
||||
if (this.data[x][y][0]==TILE_ENTRANCE || this.data[x][y][0]==TILE_EXIT) opacity=1;
|
||||
*/
|
||||
if (room.hidden) pic=[0,0];
|
||||
title=(room.corridor?'corridor':'room')+' '+room.id+' | depth : '+room.gen+' | children : '+room.children.length;
|
||||
}
|
||||
str+='<div style="opacity:'+opacity+';width:'+size+'px;height:'+size+'px;position:absolute;left:'+(x*size)+'px;top:'+(y*size)+'px;display:block;padding:0px;margin:0px;background:#'+colors[this.data[x][y][0]]+' url(img/dungeonTiles.png) '+(-pic[0]*16)+'px '+(-pic[1]*16)+'px;color:#999;" title="'+title+'"></div>';
|
||||
}
|
||||
str+='<br>';
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
}
|
6
README.md
Normal file
|
@ -0,0 +1,6 @@
|
|||
# Cookie-Clicker-Source-Code
|
||||
2.052 source code for... educational purposes... <br>
|
||||
Download and Extract to delete free time. Or just use the website. <br> <br>
|
||||
Do not worry, I will be updating this to be up to date with the current Cookie Clicker version. <br>
|
||||
<!-- Well guess what, 2.021 came out... what happened to 2.020?? -->
|
||||
Credits obviously go Orteil, visit the official website here: http://orteil.dashnet.org/cookieclicker/
|
142
base64.js
Normal file
|
@ -0,0 +1,142 @@
|
|||
/**
|
||||
*
|
||||
* Base64 encode / decode
|
||||
* http://www.webtoolkit.info/
|
||||
*
|
||||
**/
|
||||
|
||||
var Base64 = {
|
||||
|
||||
// private property
|
||||
_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
|
||||
|
||||
// public method for encoding
|
||||
encode : function (input) {
|
||||
var output = "";
|
||||
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
|
||||
var i = 0;
|
||||
|
||||
input = Base64._utf8_encode(input);
|
||||
|
||||
while (i < input.length) {
|
||||
|
||||
chr1 = input.charCodeAt(i++);
|
||||
chr2 = input.charCodeAt(i++);
|
||||
chr3 = input.charCodeAt(i++);
|
||||
|
||||
enc1 = chr1 >> 2;
|
||||
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
|
||||
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
|
||||
enc4 = chr3 & 63;
|
||||
|
||||
if (isNaN(chr2)) {
|
||||
enc3 = enc4 = 64;
|
||||
} else if (isNaN(chr3)) {
|
||||
enc4 = 64;
|
||||
}
|
||||
|
||||
output = output +
|
||||
this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
|
||||
this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
|
||||
|
||||
}
|
||||
|
||||
return output;
|
||||
},
|
||||
|
||||
// public method for decoding
|
||||
decode : function (input) {
|
||||
var output = "";
|
||||
var chr1, chr2, chr3;
|
||||
var enc1, enc2, enc3, enc4;
|
||||
var i = 0;
|
||||
|
||||
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
|
||||
|
||||
while (i < input.length) {
|
||||
|
||||
enc1 = this._keyStr.indexOf(input.charAt(i++));
|
||||
enc2 = this._keyStr.indexOf(input.charAt(i++));
|
||||
enc3 = this._keyStr.indexOf(input.charAt(i++));
|
||||
enc4 = this._keyStr.indexOf(input.charAt(i++));
|
||||
|
||||
chr1 = (enc1 << 2) | (enc2 >> 4);
|
||||
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
|
||||
chr3 = ((enc3 & 3) << 6) | enc4;
|
||||
|
||||
output = output + String.fromCharCode(chr1);
|
||||
|
||||
if (enc3 != 64) {
|
||||
output = output + String.fromCharCode(chr2);
|
||||
}
|
||||
if (enc4 != 64) {
|
||||
output = output + String.fromCharCode(chr3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
output = Base64._utf8_decode(output);
|
||||
|
||||
return output;
|
||||
|
||||
},
|
||||
|
||||
// private method for UTF-8 encoding
|
||||
_utf8_encode : function (string) {
|
||||
string = string.replace(/\r\n/g,"\n");
|
||||
var utftext = "";
|
||||
|
||||
for (var n = 0; n < string.length; n++) {
|
||||
|
||||
var c = string.charCodeAt(n);
|
||||
|
||||
if (c < 128) {
|
||||
utftext += String.fromCharCode(c);
|
||||
}
|
||||
else if((c > 127) && (c < 2048)) {
|
||||
utftext += String.fromCharCode((c >> 6) | 192);
|
||||
utftext += String.fromCharCode((c & 63) | 128);
|
||||
}
|
||||
else {
|
||||
utftext += String.fromCharCode((c >> 12) | 224);
|
||||
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
|
||||
utftext += String.fromCharCode((c & 63) | 128);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return utftext;
|
||||
},
|
||||
|
||||
// private method for UTF-8 decoding
|
||||
_utf8_decode : function (utftext) {
|
||||
var string = "";
|
||||
var i = 0;
|
||||
var c = c1 = c2 = 0;
|
||||
|
||||
while ( i < utftext.length ) {
|
||||
|
||||
c = utftext.charCodeAt(i);
|
||||
|
||||
if (c < 128) {
|
||||
string += String.fromCharCode(c);
|
||||
i++;
|
||||
}
|
||||
else if((c > 191) && (c < 224)) {
|
||||
c2 = utftext.charCodeAt(i+1);
|
||||
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
|
||||
i += 2;
|
||||
}
|
||||
else {
|
||||
c2 = utftext.charCodeAt(i+1);
|
||||
c3 = utftext.charCodeAt(i+2);
|
||||
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
|
||||
i += 3;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
}
|
940
cookie.html
|
@ -1,940 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<script type="text/javascript">
|
||||
window.cookieconsent_options = {"message":"Unsurprisingly, this website uses cookies for ads and traffic analysis.","dismiss":"Got it!","learnMore":"Learn more","link":"http://orteil.dashnet.org/cookieconsentpolicy.html","target":"_blank","theme":"http://orteil.dashnet.org/cookieconsent.css","domain":"dashnet.org"};
|
||||
</script>
|
||||
<script type="text/javascript" src="../cdnjs.cloudflare.com/ajax/libs/cookieconsent2/1.0.9/www_subdomain/cookieconsent.min.js"></script>
|
||||
<title>Cookie Clicker</title>
|
||||
<!--
|
||||
Code and graphics are copyright Orteil, 2013
|
||||
this code is bad don't look
|
||||
to add :
|
||||
-achievements
|
||||
-off-focus running
|
||||
-fix cookie algo
|
||||
-add counter to each purchasable
|
||||
-add counter for general cookie-generation
|
||||
-upgrades
|
||||
-milk (?)
|
||||
January 2014 edit : Cookie Clicker is now viral, welp
|
||||
Remember, cheated cookies taste awful!
|
||||
-->
|
||||
<style>
|
||||
body,html
|
||||
{
|
||||
padding:0px;
|
||||
margin:0px;
|
||||
}
|
||||
body
|
||||
{
|
||||
font-family:Courier new,monospace;
|
||||
-webkit-touch-callout: none;
|
||||
-webkit-user-select: none;
|
||||
-khtml-user-select: none;
|
||||
-moz-user-select: moz-none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
background:#ccc;
|
||||
overflow-y:auto;
|
||||
}
|
||||
body::selection{background:transparent;}
|
||||
body::-moz-selection{background:transparent;}
|
||||
#cookie
|
||||
{
|
||||
width:128px;
|
||||
height:128px;
|
||||
background:url(../cookie/cookie.png);
|
||||
position:absolute;
|
||||
left:-64px;
|
||||
cursor:pointer;
|
||||
}
|
||||
#cookie:hover
|
||||
{
|
||||
background-position:-128px;
|
||||
}
|
||||
#cookie:active
|
||||
{
|
||||
background-position:-256px;
|
||||
}
|
||||
#cookie .cursor
|
||||
{
|
||||
width:32px;
|
||||
height:32px;
|
||||
position:absolute;
|
||||
background:url(../cookie/cursor.png);
|
||||
}
|
||||
#pops
|
||||
{
|
||||
position:absolute;
|
||||
left:0px;
|
||||
top:0px;
|
||||
z-index:10000;
|
||||
pointer-events:none;
|
||||
}
|
||||
.pop
|
||||
{
|
||||
font-weight:bold;
|
||||
color:#fff;
|
||||
width:200px;
|
||||
height:20px;
|
||||
font-size:20px;
|
||||
text-align:center;
|
||||
}
|
||||
#rightPanel
|
||||
{
|
||||
position:absolute;
|
||||
right:0px;
|
||||
top:0px;
|
||||
z-index:100000;
|
||||
}
|
||||
#store
|
||||
{
|
||||
position:relative;
|
||||
}
|
||||
#store>div
|
||||
{
|
||||
background:#eee no-repeat;
|
||||
width:256px;
|
||||
height:64px;
|
||||
padding-left:72px;
|
||||
cursor:pointer;
|
||||
border:#000 2px solid;
|
||||
position:relative;
|
||||
}
|
||||
#store>div:hover
|
||||
{
|
||||
background-color:#fff;
|
||||
}
|
||||
#store>div:active
|
||||
{
|
||||
background-color:#ccc;
|
||||
}
|
||||
#store>div b
|
||||
{
|
||||
display:block;
|
||||
}
|
||||
#store>div.grayed
|
||||
{
|
||||
background-color:#666;
|
||||
color:#f00;
|
||||
}
|
||||
#store>div .amount
|
||||
{
|
||||
position:absolute;
|
||||
right:8px;
|
||||
top:8px;
|
||||
font-size:48px;
|
||||
color:#000;
|
||||
opacity:0.2;
|
||||
}
|
||||
#money
|
||||
{
|
||||
background:url(../cookie/currency.png) no-repeat;
|
||||
background-color:#fff;
|
||||
background-color:rgba(255,255,255,0.75);
|
||||
border-radius:18px;
|
||||
position:absolute;
|
||||
left:0px;
|
||||
top:0px;
|
||||
margin:16px;
|
||||
height:28px;
|
||||
padding:4px 4px 0px 36px;
|
||||
font-weight:bold;
|
||||
font-size:24px;
|
||||
z-index:100;
|
||||
}
|
||||
#saveMenu
|
||||
{
|
||||
position:absolute;
|
||||
left:0px;
|
||||
top:45px;
|
||||
margin:10px 16px;
|
||||
padding:2px 6px;
|
||||
font-weight:bold;
|
||||
font-size:14px;
|
||||
background:#fff;
|
||||
background:rgba(255,255,255,0.75);
|
||||
border-radius:8px;
|
||||
line-height:125%;
|
||||
z-index:100;
|
||||
font-size:12px;
|
||||
}
|
||||
#saveMenu .button
|
||||
{
|
||||
text-decoration:underline;
|
||||
cursor:pointer;
|
||||
font-size:14px;
|
||||
}
|
||||
#updateLog
|
||||
{
|
||||
position:fixed;
|
||||
left:0px;
|
||||
bottom:20px;
|
||||
margin:16px;
|
||||
padding:6px;
|
||||
font-weight:bold;
|
||||
font-size:12px;
|
||||
color:#666;
|
||||
background:#fff;
|
||||
background:rgba(255,255,255,0.75);
|
||||
border-radius:8px;
|
||||
line-height:125%;
|
||||
width:250px;
|
||||
height:300px;
|
||||
overflow-y:auto;
|
||||
z-index:100;
|
||||
}
|
||||
#updateLog b {color:#000;}
|
||||
moni
|
||||
{
|
||||
background:url(../cookie/currencysmall.png) no-repeat;
|
||||
width:16px;
|
||||
height:16px;
|
||||
display:inline-block;
|
||||
position:relative;
|
||||
top:4px;
|
||||
margin-right:-8px;
|
||||
}
|
||||
#grandmas
|
||||
{
|
||||
position:absolute;
|
||||
left:100px;
|
||||
width:240px;
|
||||
}
|
||||
.grandma
|
||||
{
|
||||
position:absolute;
|
||||
background:url(../cookie/grandma.png);
|
||||
width:24px;
|
||||
height:48px;
|
||||
}
|
||||
.goldengrandma{background:url(golden../cookie/grandma.png);}
|
||||
.factorygrandma{background:url(factory../cookie/grandma.png);}
|
||||
.minegrandma{background:url(mine../cookie/grandma.png);}
|
||||
.shipmentgrandma{background:url(shipment../cookie/grandma.png);}
|
||||
.portalgrandma{background:url(portal../cookie/grandma.png);}
|
||||
.pledgedgrandma{background:url(pledged../cookie/grandma.png);}
|
||||
.timegrandma{background:url(time../cookie/grandma.png);}
|
||||
#factories
|
||||
{
|
||||
position:absolute;
|
||||
left:-420px;
|
||||
width:320px;
|
||||
}
|
||||
.factory
|
||||
{
|
||||
position:absolute;
|
||||
background:url(../cookie/factory.png);
|
||||
width:32px;
|
||||
height:48px;
|
||||
}
|
||||
#mines
|
||||
{
|
||||
position:absolute;
|
||||
left:100px;
|
||||
width:160px;
|
||||
top:100px;
|
||||
}
|
||||
.mine
|
||||
{
|
||||
position:absolute;
|
||||
background:url(../cookie/mine.png);
|
||||
width:32px;
|
||||
height:32px;
|
||||
}
|
||||
#shipments
|
||||
{
|
||||
position:absolute;
|
||||
left:-340px;
|
||||
width:240px;
|
||||
top:100px;
|
||||
}
|
||||
.shipment
|
||||
{
|
||||
position:absolute;
|
||||
background:url(../cookie/shipment.png);
|
||||
width:48px;
|
||||
height:48px;
|
||||
}
|
||||
#labs
|
||||
{
|
||||
position:absolute;
|
||||
left:-120px;
|
||||
width:240px;
|
||||
top:180px;
|
||||
}
|
||||
.lab
|
||||
{
|
||||
position:absolute;
|
||||
background:url(../cookie/lab.png);
|
||||
width:24px;
|
||||
height:32px;
|
||||
}
|
||||
#portals
|
||||
{
|
||||
position:absolute;
|
||||
left:-340px;
|
||||
width:240px;
|
||||
top:180px;
|
||||
}
|
||||
.portal
|
||||
{
|
||||
position:absolute;
|
||||
background:url(../cookie/portal.png);
|
||||
width:48px;
|
||||
height:48px;
|
||||
}
|
||||
#times
|
||||
{
|
||||
position:absolute;
|
||||
left:100px;
|
||||
width:240px;
|
||||
top:180px;
|
||||
}
|
||||
.time
|
||||
{
|
||||
position:absolute;
|
||||
background:url(../cookie/timemachine.png);
|
||||
width:48px;
|
||||
height:48px;
|
||||
}
|
||||
#comment
|
||||
{
|
||||
position:absolute;
|
||||
left:-200px;
|
||||
top:-115px;
|
||||
width:400px;
|
||||
font-weight:bold;
|
||||
font-size:16px;
|
||||
text-align:center;
|
||||
background-color:#fff;
|
||||
background-color:rgba(255,255,255,0.75);
|
||||
border-radius:18px;
|
||||
}
|
||||
#middle
|
||||
{
|
||||
position:absolute;
|
||||
left:50%;
|
||||
top:150px;
|
||||
width:0px;
|
||||
}
|
||||
#credits
|
||||
{
|
||||
width:100%;
|
||||
height:20px;
|
||||
background:#666;
|
||||
color:#fff;
|
||||
position:fixed;
|
||||
bottom:0px;
|
||||
margin:0px;
|
||||
font-size:12px;
|
||||
border-top:2px solid #999;
|
||||
z-index:100000;
|
||||
}
|
||||
#credits span
|
||||
{
|
||||
margin:4px;
|
||||
}
|
||||
a {color:#fff;}
|
||||
#alert
|
||||
{
|
||||
background-color:#666;
|
||||
color:#fff;
|
||||
border:2px solid #000;
|
||||
position:fixed;
|
||||
right:0px;
|
||||
bottom:0px;
|
||||
padding:8px;
|
||||
z-index:20000000;
|
||||
visibility:hidden;
|
||||
font-size:14px;
|
||||
}
|
||||
#ads
|
||||
{
|
||||
width:332px;
|
||||
text-align:center;
|
||||
margin-top:16px;
|
||||
}
|
||||
#tip
|
||||
{
|
||||
position:fixed;
|
||||
left:0px;
|
||||
bottom:20px;
|
||||
width:100%;
|
||||
height:20px;
|
||||
}
|
||||
</style>
|
||||
<script src="../cookie/ajax.js"></script>
|
||||
<link rel="shortcut icon" href="favicon.ico" />
|
||||
</head>
|
||||
<body id="whole">
|
||||
<div id="hiddenLoader" style="display:none;"></div>
|
||||
<div id="credits">
|
||||
<span><b>Cookie Clicker</b> © <a href="../index.html">Orteil</a>, 2013 - hosted by <a href="http://dashnet.org">DashNet</a> | check out my <a href="http://twitter.com/orteil42">twitter</a> and <a href="http://orteil42.tumblr.com">tumblr</a> | also : <a href="../nested.html">Nested</a> | the big update is <a href="../cookieclicker.html" target="blank">out</a>!</span>
|
||||
</div>
|
||||
<div id="game">
|
||||
<div id="log"></div>
|
||||
<div id="updateLog">
|
||||
<b>06/09/2013</b><br>
|
||||
<b>0.126</b><br>
|
||||
-technical fixes<br>
|
||||
-better servers!<br>
|
||||
<div style="background:#666;color:#fff;padding:4px 0px;"><b style="color:#fff;">24/08/2013 : the big update is finally out!<br>
|
||||
<a href="../cookieclicker.html" target="blank">Check it out!</a></b></div>
|
||||
<b>0.125</b><br>
|
||||
-added a new object<br>
|
||||
-added option to disable flashing<br>
|
||||
-welp I'm going back to work<br>
|
||||
<b>0.124</b><br>
|
||||
-elder pledge is cheaper and now buffs grandmas and clicking while active<br>
|
||||
-page title now displays cookies<br>
|
||||
<b>0.123</b><br>
|
||||
-added cookies per second<br>
|
||||
-reworked grandmas<br>
|
||||
-still not the big update<br>
|
||||
<br>
|
||||
<b>13/08/2013</b> : this isn't the big update, just a couple features that have been requested often.<br>
|
||||
<b>0.122</b><br>
|
||||
-fixed background flashing<br>
|
||||
-added a new secret end-game item to counter the grandmapocalypse<br>
|
||||
<b>0.121</b><br>
|
||||
-import/export save<br>
|
||||
-ask confirm on reset<br>
|
||||
-speed tweaks<br>
|
||||
</div>
|
||||
<div id="money"></div>
|
||||
<div id="saveMenu">
|
||||
<div id="cps"></div>
|
||||
<div class="button" id="exportSave" onclick="exportSave();">Export save</div>
|
||||
<div class="button" id="importSave" onclick="importSave();">Import save</div>
|
||||
<div class="button" id="reset" onclick="Reset();">Reset</div>
|
||||
<br>
|
||||
<div class="button" id="toggleNumbers" onclick="ToggleNumbers();">Numbers On</div>
|
||||
<div class="button" id="toggleFlash" onclick="ToggleFlash();">Flashing On</div>
|
||||
<br>
|
||||
<div id="version"></div>
|
||||
</div>
|
||||
<div id="rightPanel">
|
||||
<div id="store">
|
||||
</div>
|
||||
<!--
|
||||
<div id="ads">
|
||||
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" id="donate" style="margin:0px 16px;">
|
||||
<--<small style="opacity:0.5;">it ain't gonna host itself</small><br>->
|
||||
<input type="hidden" name="cmd" value="_s-xclick">
|
||||
<input type="hidden" name="hosted_button_id" value="BBN2WL3TC6QH4">
|
||||
<input type="image" src="https://www.paypalobjects.com/en_GB/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="PayPal The safer, easier way to pay online.">
|
||||
<img alt="" border="0" src="https://www.paypalobjects.com/nl_NL/i/scr/pixel.gif" width="1" height="1">
|
||||
</form>
|
||||
<script async src="http://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
|
||||
<-- Cookie Clicker ->
|
||||
<ins class="adsbygoogle"
|
||||
style="display:inline-block;width:120px;height:240px"
|
||||
data-ad-client="ca-pub-8491708950677704"
|
||||
data-ad-slot="3046382095"></ins>
|
||||
<script>
|
||||
(adsbygoogle = window.adsbygoogle || []).push({});
|
||||
</script>
|
||||
<script async src="http://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
|
||||
<-- Cookie Clicker ->
|
||||
<ins class="adsbygoogle"
|
||||
style="display:inline-block;width:120px;height:240px"
|
||||
data-ad-client="ca-pub-8491708950677704"
|
||||
data-ad-slot="3046382095"></ins>
|
||||
<script>
|
||||
(adsbygoogle = window.adsbygoogle || []).push({});
|
||||
</script>
|
||||
</div>
|
||||
-->
|
||||
</div>
|
||||
<div id="middle">
|
||||
<div id="grandmas"></div>
|
||||
<div id="factories"></div>
|
||||
<div id="mines"></div>
|
||||
<div id="shipments"></div>
|
||||
<div id="labs"></div>
|
||||
<div id="portals"></div>
|
||||
<div id="times"></div>
|
||||
<div id="comment">Loading...</div>
|
||||
<div id="cookie" onmouseup="ClickCookie();" onmouseover="HoverCookie();"></div>
|
||||
</div>
|
||||
<div id="pops"></div>
|
||||
</div>
|
||||
<div id="alert"></div>
|
||||
<script>
|
||||
function eventFire(el, etype){
|
||||
if (el.fireEvent) {
|
||||
(el.fireEvent('on' + etype));
|
||||
} else {
|
||||
var evObj = document.createEvent('Events');
|
||||
evObj.initEvent(etype, true, false);
|
||||
el.dispatchEvent(evObj);
|
||||
}
|
||||
}
|
||||
function l(what) {return document.getElementById(what);}
|
||||
Game=l('game');
|
||||
Version=0.1251;
|
||||
l('version').innerHTML='running v.'+Version;
|
||||
Loaded=0;
|
||||
function Beautify(what)//turns 9999999 into 9,999,999
|
||||
{
|
||||
var str='';
|
||||
what=Math.floor(what);
|
||||
what=(what+'').split('').reverse();
|
||||
for (var i in what)
|
||||
{
|
||||
if (i%3==0 && i>0) str=','+str;
|
||||
str=what[i]+str;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
//CookieSave='<?php echo ($_COOKIE['CookieClickerSave']?('1|'.$_COOKIE['CookieClickerSave']):'0'); ?>';
|
||||
var str='';
|
||||
var pics=['cursor','grandma','mine','factory','lab','shipment','goldengrandma','grandmaiconinvert','grandmaiconlustful','portal','skellington','kaleigrandma','factorygrandma','minegrandma','shipmentgrandma','portalgrandma','pledgedgrandma','pledgeicon','timemachine','timegrandma'];
|
||||
for (var i in pics) {str+='<img src="'+pics[i]+'.png"/>';}
|
||||
l('hiddenLoader').innerHTML=str;
|
||||
Cookies=0;
|
||||
CookiesDisplay=0;
|
||||
Clicking=0;
|
||||
Hovering=0;
|
||||
T=0;
|
||||
Cursors=0;
|
||||
Grandmas=0;
|
||||
Factories=0;
|
||||
Mines=0;
|
||||
Shipments=0;
|
||||
Labs=0;
|
||||
Portals=0;
|
||||
Times=0;
|
||||
Pledge=0;
|
||||
NumbersOn=1;
|
||||
Flashing=1;
|
||||
StoreToRebuild=0;
|
||||
function ToggleNumbers()
|
||||
{
|
||||
if (NumbersOn) {NumbersOn=0;l('toggleNumbers').innerHTML='Numbers Off';}
|
||||
else if (!NumbersOn) {NumbersOn=1;l('toggleNumbers').innerHTML='Numbers On';}
|
||||
}
|
||||
function ToggleFlash()
|
||||
{
|
||||
if (Flashing) {Flashing=0;l('toggleFlash').innerHTML='Flashing Off';}
|
||||
else if (!Flashing) {Flashing=1;l('toggleFlash').innerHTML='Flashing On';}
|
||||
}
|
||||
importSave=function()
|
||||
{
|
||||
var save=prompt('Please paste in the text that was given to you on save export.','');
|
||||
if (save && save!='') ImportResponse('1|'+save);
|
||||
Save();
|
||||
}
|
||||
exportSave=function()
|
||||
{
|
||||
var save=prompt('Copypaste this text and keep it somewhere safe! (yes, it\'s easy to edit - but remember : cheated cookies taste terrible!)',MakeSaveString());
|
||||
}
|
||||
ImportResponse=function(response)
|
||||
{
|
||||
var r=response.split('|');
|
||||
if (response!='0' && response)
|
||||
{
|
||||
if (r[0]=='1')
|
||||
{
|
||||
Cookies=parseInt(r[2]);
|
||||
Pledge=0;
|
||||
Cursors=Math.min(1000,parseInt(r[3]));Buyables['Cursor'].price=parseInt(r[4]);
|
||||
Grandmas=Math.min(1000,parseInt(r[5]));Buyables['Grandma'].price=parseInt(r[6]);
|
||||
Factories=Math.min(1000,parseInt(r[7]));Buyables['Factory'].price=parseInt(r[8]);
|
||||
Mines=Math.min(1000,parseInt(r[9]));Buyables['Mine'].price=parseInt(r[10]);
|
||||
Shipments=Math.min(1000,parseInt(r[11]));Buyables['Shipment'].price=parseInt(r[12]);
|
||||
Labs=Math.min(1000,parseInt(r[13]));Buyables['Alchemy lab'].price=parseInt(r[14]);
|
||||
if (r[15]) {Portals=Math.min(1000,parseInt(r[15]));Buyables['Portal'].price=parseInt(r[16]);}
|
||||
if (r[17]) {Times=Math.min(1000,parseInt(r[17]));Buyables['Time machine'].price=parseInt(r[18]);}
|
||||
Buyables['Grandma'].func(0);
|
||||
Buyables['Factory'].func(0);
|
||||
Buyables['Mine'].func(0);
|
||||
Buyables['Shipment'].func(0);
|
||||
Buyables['Alchemy lab'].func(0);
|
||||
Buyables['Portal'].func(0);
|
||||
Buyables['Time machine'].func(0);
|
||||
StoreToRebuild=1;
|
||||
}
|
||||
}
|
||||
new Pop('credits','Imported.');
|
||||
}
|
||||
Reset=function()
|
||||
{
|
||||
if (confirm('Do you REALLY want to start over?'))
|
||||
{
|
||||
document.cookie='CookieClickerSave=0; expires=Fri, 3 Aug 2001 20:47:11 UTC;';
|
||||
ResetResponse();
|
||||
}
|
||||
//ajax('backend.php?q=reset',ResetResponse);
|
||||
}
|
||||
ResetResponse=function()
|
||||
{
|
||||
location.reload(true);
|
||||
}
|
||||
MakeSaveString=function()
|
||||
{
|
||||
var str='';
|
||||
str+=Version+'|'+parseInt(Cookies)+'|'+
|
||||
parseInt(Cursors)+'|'+parseInt(Buyables['Cursor'].price)+'|'+
|
||||
parseInt(Grandmas)+'|'+parseInt(Buyables['Grandma'].price)+'|'+
|
||||
parseInt(Factories)+'|'+parseInt(Buyables['Factory'].price)+'|'+
|
||||
parseInt(Mines)+'|'+parseInt(Buyables['Mine'].price)+'|'+
|
||||
parseInt(Shipments)+'|'+parseInt(Buyables['Shipment'].price)+'|'+
|
||||
parseInt(Labs)+'|'+parseInt(Buyables['Alchemy lab'].price)+'|'+
|
||||
parseInt(Portals)+'|'+parseInt(Buyables['Portal'].price)+'|'+
|
||||
parseInt(Times)+'|'+parseInt(Buyables['Time machine'].price);
|
||||
return str;
|
||||
}
|
||||
SaveTimer=30*60;
|
||||
Save=function()
|
||||
{
|
||||
var str=MakeSaveString();
|
||||
//ajax('backend.php?q=save|'+str,SaveResponse);
|
||||
var now=new Date();//we storin dis for 5 years, people
|
||||
now.setFullYear(now.getFullYear()+5);//mmh stale cookies
|
||||
str='CookieClickerSave='+escape(str)+'; expires='+now.toUTCString()+';';
|
||||
document.cookie=str;//aaand save
|
||||
//alert(document.cookie);
|
||||
if (document.cookie.indexOf('CookieClickerSave')<0) Pop('credits','<span style="color:#f00;">Error while saving.<br>Export your save instead!</span>');
|
||||
else Pop('credits','Saved');
|
||||
SaveTimer=30*60;
|
||||
}
|
||||
SaveResponse=function(response)
|
||||
{
|
||||
var r=response.split('|');
|
||||
if (r[0]=='1' && parseFloat(r[1])>Version)
|
||||
{
|
||||
l('alert').style.visibility='visible';
|
||||
l('alert').innerHTML='New version available ('+r[1]+').<br>Please refresh to see it!';
|
||||
}
|
||||
if (r[0]=='1') new Pop('credits','Saved');
|
||||
else new Pop('credits','<span style="color:#f00;">Error while saving</span>');
|
||||
}
|
||||
Load=function()
|
||||
{
|
||||
var str='0';
|
||||
if (document.cookie.indexOf('CookieClickerSave')>=0) str='1|'+unescape(document.cookie.split('CookieClickerSave=')[1]);//get cookie here
|
||||
//ajax('backend.php?q=load',LoadResponse);
|
||||
LoadResponse(str);
|
||||
l('comment').innerHTML='Loading cookie...';
|
||||
//LoadResponse(CookieSave);
|
||||
}
|
||||
LoadResponse=function(response)
|
||||
{
|
||||
var r=response.split('|');
|
||||
if (response!='0' && response)
|
||||
{
|
||||
if (r[0]=='1')
|
||||
{
|
||||
Cookies=parseInt(r[2]);
|
||||
Pledge=0;
|
||||
Cursors=Math.min(1000,parseInt(r[3]));Buyables['Cursor'].price=parseInt(r[4]);
|
||||
Grandmas=Math.min(1000,parseInt(r[5]));Buyables['Grandma'].price=parseInt(r[6]);
|
||||
Factories=Math.min(1000,parseInt(r[7]));Buyables['Factory'].price=parseInt(r[8]);
|
||||
Mines=Math.min(1000,parseInt(r[9]));Buyables['Mine'].price=parseInt(r[10]);
|
||||
Shipments=Math.min(1000,parseInt(r[11]));Buyables['Shipment'].price=parseInt(r[12]);
|
||||
Labs=Math.min(1000,parseInt(r[13]));Buyables['Alchemy lab'].price=parseInt(r[14]);
|
||||
if (r[15]) {Portals=Math.min(1000,parseInt(r[15]));Buyables['Portal'].price=parseInt(r[16]);}
|
||||
if (r[17]) {Times=Math.min(1000,parseInt(r[17]));Buyables['Time machine'].price=parseInt(r[18]);}
|
||||
Buyables['Grandma'].func(0);
|
||||
Buyables['Factory'].func(0);
|
||||
Buyables['Mine'].func(0);
|
||||
Buyables['Shipment'].func(0);
|
||||
Buyables['Alchemy lab'].func(0);
|
||||
Buyables['Portal'].func(0);
|
||||
Buyables['Time machine'].func(0);
|
||||
StoreToRebuild=1;
|
||||
}
|
||||
}
|
||||
new Pop('credits','Loaded.');
|
||||
Loaded=1;
|
||||
Main();
|
||||
}
|
||||
ClickCookie=function()
|
||||
{
|
||||
var howmany=(Pledge>0?Math.ceil(Cursors*1.5):1);
|
||||
Cookies+=howmany;
|
||||
if (Pops.length<260 && NumbersOn) new Pop('cookie','+'+howmany);
|
||||
Clicking=1;
|
||||
}
|
||||
HoverCookie=function()
|
||||
{
|
||||
Hovering=1;
|
||||
}
|
||||
AddCookie=function(howmany,el)
|
||||
{
|
||||
Cookies+=howmany;
|
||||
if (el && Pops.length<250 && NumbersOn) new Pop(el,'+'+howmany);
|
||||
}
|
||||
RebuildStore=function()
|
||||
{
|
||||
var str='';
|
||||
for (var i in Buyables)
|
||||
{
|
||||
var amount=0;
|
||||
if (Buyables[i].name=='Cursor') amount=Cursors;
|
||||
else if (Buyables[i].name=='Grandma') amount=Grandmas;
|
||||
else if (Buyables[i].name=='Factory') amount=Factories;
|
||||
else if (Buyables[i].name=='Mine') amount=Mines;
|
||||
else if (Buyables[i].name=='Shipment') amount=Shipments;
|
||||
else if (Buyables[i].name=='Alchemy lab') amount=Labs;
|
||||
else if (Buyables[i].name=='Portal') amount=Portals;
|
||||
else if (Buyables[i].name=='Time machine') amount=Times;
|
||||
str+='<div id="buy'+Buyables[i].name+'" onclick="Buy(\''+Buyables[i].name+'\');" style="'+(Buyables[i].name=='Elder Pledge'?'display:none;':'')+(Buyables[i].name=='Time machine'?'font-size:90%;':'')+'background-image:url('+Buyables[i].pic+'.png);"><b>'+Buyables[i].name+' - <moni></moni> '+Beautify(Buyables[i].price)+'</b>'+Buyables[i].desc+''+(amount>0?('<div class="amount">'+amount+'</div>'):'')+'</div>';
|
||||
}
|
||||
l('store').innerHTML=str;
|
||||
StoreToRebuild=0;
|
||||
}
|
||||
Buyables=[];
|
||||
Buyable=function(name,desc,pic,price,func)
|
||||
{
|
||||
this.name=name;
|
||||
this.desc=desc;
|
||||
this.pic=pic;
|
||||
this.price=price;
|
||||
this.func=func;
|
||||
Buyables[name]=this;
|
||||
this.Buy=function()
|
||||
{
|
||||
if (Cookies>=this.price && Loaded)
|
||||
{
|
||||
Cookies-=this.price;
|
||||
this.price=Math.ceil(this.price*1.1);
|
||||
this.func(1);
|
||||
//Buyables[this.name]=0;
|
||||
StoreToRebuild=1;
|
||||
}
|
||||
}
|
||||
StoreToRebuild=1;
|
||||
}
|
||||
Buy=function(what)
|
||||
{
|
||||
Buyables[what].Buy();
|
||||
}
|
||||
new Buyable('Cursor','Autoclicks every 5 seconds.','cursoricon',15,function(){Cursors++;});
|
||||
new Buyable('Grandma','A nice grandma to bake more cookies.','grandmaicon',100,function(buy)
|
||||
{
|
||||
if (buy) Grandmas++;
|
||||
var str='';
|
||||
for (var i=0;i<Grandmas;i++)
|
||||
{
|
||||
var x=Math.floor(Math.random()*20+(i%10)*24);
|
||||
var y=Math.floor(Math.random()*20+Math.floor(i/10)*24);
|
||||
var cl=0;
|
||||
if (Labs && Math.random()<0.2) cl='goldengrandma';
|
||||
if (Factories && Math.random()<0.2) cl='factorygrandma';
|
||||
if (Mines && Math.random()<0.2) cl='minegrandma';
|
||||
if (Shipments && Math.random()<0.2) cl='shipmentgrandma';
|
||||
if (Portals && Pledge<=0 && Math.random()<0.2) cl='portalgrandma';
|
||||
if (Times && Math.random()<0.2) cl='timegrandma';
|
||||
if (Pledge && Math.random()<0.2) cl='pledgedgrandma';
|
||||
str+='<div class="'+(cl?cl+' ':'')+'grandma" style="left:'+x+'px;top:'+y+'px;"></div>';
|
||||
}
|
||||
l('grandmas').innerHTML=str;
|
||||
});
|
||||
new Buyable('Factory','Produces large quantities of cookies.','factoryicon',500,function(buy)
|
||||
{
|
||||
if (buy) Factories++;
|
||||
if (buy && Factories==1) Buyables['Grandma'].func();
|
||||
var str='';
|
||||
for (var i=0;i<Factories;i++)
|
||||
{
|
||||
var x=Math.floor(Math.random()*20+(i%10)*32);
|
||||
var y=Math.floor(Math.random()*20+Math.floor(i/10)*24);
|
||||
str+='<div class="factory" style="right:'+x+'px;top:'+y+'px;"></div>';
|
||||
}
|
||||
l('factories').innerHTML=str;
|
||||
});
|
||||
new Buyable('Mine','Mines out cookie dough and chocolate chips.','mineicon',2000,function(buy)
|
||||
{
|
||||
if (buy) Mines++;
|
||||
if (buy && Mines==1) Buyables['Grandma'].func();
|
||||
var str='';
|
||||
for (var i=0;i<Mines;i++)
|
||||
{
|
||||
var x=Math.floor(Math.random()*20+(i%10)*16);
|
||||
var y=Math.floor(Math.random()*20+Math.floor(i/10)*16);
|
||||
str+='<div class="mine" style="left:'+x+'px;top:'+y+'px;"></div>';
|
||||
}
|
||||
l('mines').innerHTML=str;
|
||||
});
|
||||
new Buyable('Shipment','Brings in fresh cookies from the cookie planet.','shipmenticon',7000,function(buy)
|
||||
{
|
||||
if (buy) Shipments++;
|
||||
if (buy && Shipments==1) Buyables['Grandma'].func();
|
||||
var str='';
|
||||
for (var i=0;i<Shipments;i++)
|
||||
{
|
||||
var x=Math.floor(Math.random()*20+(i%10)*24);
|
||||
var y=Math.floor(Math.random()*20+Math.floor(i/10)*24);
|
||||
str+='<div class="shipment" style="right:'+x+'px;top:'+y+'px;"></div>';
|
||||
}
|
||||
l('shipments').innerHTML=str;
|
||||
});
|
||||
new Buyable('Alchemy lab','Turns gold into cookies!','labicon',50000,function(buy)
|
||||
{
|
||||
if (buy) Labs++;
|
||||
if (buy && Labs==1) Buyables['Grandma'].func();
|
||||
var str='';
|
||||
for (var i=0;i<Labs;i++)
|
||||
{
|
||||
var x=Math.floor(Math.random()*20+(i%10)*24);
|
||||
var y=Math.floor(Math.random()*20+Math.floor(i/10)*16);
|
||||
str+='<div class="lab" style="right:'+x+'px;top:'+y+'px;"></div>';
|
||||
}
|
||||
l('labs').innerHTML=str;
|
||||
});
|
||||
new Buyable('Portal','Opens a door to the Cookieverse.','portalicon',1000000,function(buy)
|
||||
{
|
||||
if (buy) Portals++;
|
||||
if (buy && Portals==1) Buyables['Grandma'].func();
|
||||
var str='';
|
||||
for (var i=0;i<Portals;i++)
|
||||
{
|
||||
var x=Math.floor(Math.random()*20+(i%10)*24);
|
||||
var y=Math.floor(Math.random()*20+Math.floor(i/10)*24);
|
||||
str+='<div class="portal" style="right:'+x+'px;top:'+y+'px;"></div>';
|
||||
}
|
||||
l('portals').innerHTML=str;
|
||||
});
|
||||
new Buyable('Time machine','<span style="font-size:80%;">Brings cookies from the past, before they were even eaten.</span>','timemachineicon',123456789,function(buy)
|
||||
{
|
||||
if (buy) Times++;
|
||||
if (buy && Times==1) Buyables['Grandma'].func();
|
||||
var str='';
|
||||
for (var i=0;i<Times;i++)
|
||||
{
|
||||
var x=Math.floor(Math.random()*20+(i%10)*24);
|
||||
var y=Math.floor(Math.random()*20+Math.floor(i/10)*24);
|
||||
str+='<div class="time" style="right:'+x+'px;top:'+y+'px;"></div>';
|
||||
}
|
||||
l('times').innerHTML=str;
|
||||
});
|
||||
new Buyable('Elder Pledge','<span style="font-size:80%;">Puts an end to the Ancients\' wrath, at least for a while.</span>','pledgeicon',666666,function(buy)
|
||||
{
|
||||
if (buy) {Pledge*=2;Pledge+=30*60*10;}
|
||||
if (buy) Buyables['Grandma'].func();
|
||||
l('buyElder Pledge').style.display='none';
|
||||
});
|
||||
Pops=[];
|
||||
Pop=function(el,str)
|
||||
{
|
||||
this.el=el;
|
||||
this.str=str;
|
||||
this.life=0;
|
||||
this.offx=Math.floor(Math.random()*20-10);
|
||||
this.offy=Math.floor(Math.random()*20-10);
|
||||
Pops.push(this);
|
||||
}
|
||||
Main=function()
|
||||
{
|
||||
var str='';
|
||||
if (StoreToRebuild)
|
||||
{
|
||||
RebuildStore();
|
||||
StoreToRebuild=0;
|
||||
}
|
||||
for (var i in Pops)
|
||||
{
|
||||
var rect=l(Pops[i].el).getBoundingClientRect();
|
||||
var x=Math.floor((rect.left+rect.right)/2+Pops[i].offx)-100;
|
||||
var y=Math.floor((rect.top+rect.bottom)/2-Math.pow(Pops[i].life/100,0.5)*100+Pops[i].offy)-10;
|
||||
var opacity=1-(Math.max(Pops[i].life,80)-80)/20;
|
||||
str+='<div class="pop" style="position:absolute;left:'+x+'px;top:'+y+'px;opacity:'+opacity+';">'+Pops[i].str+'</div>';
|
||||
Pops[i].life+=2;
|
||||
if (Pops[i].life>=100) Pops.splice(i,1);
|
||||
}
|
||||
l('pops').innerHTML=str;
|
||||
var str='';
|
||||
for (var i=0;i<Cursors;i++)
|
||||
{
|
||||
var rot=-Math.floor((360/Cursors)*i);
|
||||
var x=Math.floor(64+Math.sin((Math.PI*2/Cursors)*i)*64)-16;
|
||||
var y=Math.floor(64+Math.cos((Math.PI*2/Cursors)*i)*64)-16;
|
||||
if ((T)%150==Math.ceil((150/Cursors)*i)) y+=2;
|
||||
str+='<div class="cursor" style="left:'+x+'px;top:'+y+'px;transform:rotate('+rot+'deg);-webkit-transform:rotate('+rot+'deg);-moz-transform:rotate('+rot+'deg);-ms-transform:rotate('+rot+'deg);"></div>';
|
||||
}
|
||||
l('cookie').innerHTML=str;
|
||||
var grandmaGain=Math.ceil(4+(Factories?1:0)+(Mines?2:0)+(Shipments?3:0)+(Labs?4:0)+(Portals?(Pledge?5+Portals*0.5:5):0)+(Times?6:0));
|
||||
var cursorGain=(Pledge>0?Math.ceil(Cursors*1.5):1);
|
||||
if (Times && T%Math.ceil(150/Times)==0) AddCookie(123456,'times');
|
||||
if (Portals && T%Math.ceil(150/Portals)==0) AddCookie(6666,'portals');
|
||||
if (Labs && T%Math.ceil(150/Labs)==0) AddCookie(500,'labs');
|
||||
if (Shipments && T%Math.ceil(150/Shipments)==0) AddCookie(100,'shipments');
|
||||
if (Mines && T%Math.ceil(150/Mines)==0) AddCookie(50,'mines');
|
||||
if (Factories && T%Math.ceil(150/Factories)==0) AddCookie(20,'factories');
|
||||
if (Grandmas && T%Math.ceil(150/Grandmas)==0) AddCookie(grandmaGain,'grandmas');
|
||||
if (Cursors && T%Math.ceil(150/Cursors)==0) eventFire(l('cookie'),'mouseup');
|
||||
var cps=0;
|
||||
cps+=Times*123456/5;
|
||||
cps+=Portals*6666/5;
|
||||
cps+=Labs*500/5;
|
||||
cps+=Shipments*100/5;
|
||||
cps+=Mines*50/5;
|
||||
cps+=Factories*20/5;
|
||||
cps+=Grandmas*grandmaGain/5;
|
||||
cps+=Cursors*cursorGain/5;
|
||||
var floater=Math.round(cps*10-Math.floor(cps)*10);
|
||||
cps=Beautify(cps)+(floater?('.'+floater):'');
|
||||
l('cps').innerHTML='cookies/second : '+cps;
|
||||
for (var i in Buyables)
|
||||
{
|
||||
if (Cookies>=Buyables[i].price) l('buy'+Buyables[i].name).className=''; else l('buy'+Buyables[i].name).className='grayed';
|
||||
}
|
||||
CookiesDisplay+=(Cookies-CookiesDisplay)*0.5;
|
||||
l('money').innerHTML=Beautify(Math.round(CookiesDisplay));
|
||||
var str='';
|
||||
if (Cookies<5) str='You feel like making cookies.<br>But nobody wants to eat your cookies.';
|
||||
else if (Cookies<25) str='Your cookies are popular<br>with your dog.';
|
||||
else if (Cookies<50) str='Your cookies are popular<br>with your family.';
|
||||
else if (Cookies<100) str='Your cookies are popular<br>in the neighborhood.';
|
||||
else if (Cookies<500) str='Your cookies are renowned<br>in the whole town!';
|
||||
else if (Cookies<2000) str='Your cookies are worth<br>a lot of money.';
|
||||
else if (Cookies<5000) str='Your cookies bring<br>all the boys to the yard.';
|
||||
else if (Cookies<10000) str='People come from very far away<br>to get a taste of your cookies.';
|
||||
else if (Cookies<17000) str='Kings and queens from all over the world<br>are enjoying your cookies.';
|
||||
else if (Cookies<30000) str='Your cookies have been named<br>a part of the world wonders.';
|
||||
else if (Cookies<60000) str='Your cookies have been placed<br>under government surveillance.';
|
||||
else if (Cookies<100000) str='The whole planet is<br>enjoying your cookies!';
|
||||
else if (Cookies<150000) str='Creatures from neighboring planets<br>wish to try your cookies.';
|
||||
else if (Cookies<250000) str='Elder gods from the whole cosmos<br>have awoken to taste your cookies.';
|
||||
else if (Cookies<400000) str='Your cookies have achieved sentience.';
|
||||
else if (Cookies<1000000) str='The universe has now turned into<br>cookie dough, to the molecular level.';
|
||||
else if (Cookies<1000000000) str='A local news station runs<br>a 10-minute segment about your cookies. Success!<br><span style="font-size:50%;">(you win a cookie)</span>';
|
||||
else str='it\'s time to stop playing<br><span style="font-size:50%;">(more fun milestones in the next update I promise)</span>';
|
||||
l('comment').innerHTML=str;
|
||||
if (Pledge>0) Pledge--;
|
||||
if (Cookies>=1000000 && Pledge<=0 && Flashing)
|
||||
{
|
||||
var r=(Cookies-1000000)/2000000;
|
||||
var r2=Math.max(0,(Cookies-100000000)/400000000);
|
||||
var icon='grandmaicon';
|
||||
if (Cookies>=2000000)
|
||||
{
|
||||
l('buyElder Pledge').style.display='block';
|
||||
if (Math.random()<0.02) icon='grandmaiconinvert';
|
||||
else if (Math.random()<0.02) icon='grandmaiconlustful';
|
||||
}
|
||||
if (Cookies>=10000000 && Math.random()<0.02) icon='skellington';
|
||||
if (Cookies>=1000000000) l('whole').style.background='url(kalei../cookie/grandma.png) '+Math.floor(T*0.2)+'px -'+Math.floor(T*0.1)+'px';
|
||||
else if (Math.random()<r)
|
||||
{
|
||||
l('whole').style.background='url('+icon+'.png) '+Math.floor(Math.random()*4)+'px '+Math.floor(Math.random()*4)+'px';
|
||||
l('whole').style.backgroundSize=Math.floor(r2*Math.random()*64+64)+'px '+Math.floor(r2*Math.random()*64+64)+'px ';
|
||||
}
|
||||
}//sorry
|
||||
else l('whole').style.background='#ccc';
|
||||
if (T%30==0 && Loaded) document.title=Beautify(Cookies)+' cookies - Cookie Clicker';
|
||||
Clicking=0;
|
||||
Hovering=0;
|
||||
SaveTimer--;
|
||||
if (SaveTimer==0 && Loaded) Save();
|
||||
T++;
|
||||
setTimeout(Main,1000/30);
|
||||
}
|
||||
Load();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Before Width: | Height: | Size: 4.4 KiB |
Before Width: | Height: | Size: 401 B |
Before Width: | Height: | Size: 259 B |
Before Width: | Height: | Size: 640 B |
|
@ -1 +0,0 @@
|
|||
|
Before Width: | Height: | Size: 368 B |
Before Width: | Height: | Size: 513 B |
Before Width: | Height: | Size: 425 B |
Before Width: | Height: | Size: 481 B |
Before Width: | Height: | Size: 9.0 KiB |
BIN
cookie/lab.png
Before Width: | Height: | Size: 319 B |
BIN
cookie/mine.png
Before Width: | Height: | Size: 391 B |
Before Width: | Height: | Size: 508 B |
Before Width: | Height: | Size: 367 B |
Before Width: | Height: | Size: 728 B |
Before Width: | Height: | Size: 462 B |
Before Width: | Height: | Size: 536 B |
Before Width: | Height: | Size: 484 B |
Before Width: | Height: | Size: 499 B |
Before Width: | Height: | Size: 477 B |
1136
dungeons.js
Normal file
BIN
img/AQWorlds_CookieClicker_300x40.png
Normal file
After Width: | Height: | Size: 25 KiB |
BIN
img/BGgarden.jpg
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
img/BGgrimoire.jpg
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
img/BGmarket.jpg
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
img/BGpantheon.jpg
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
img/alchemylab.png
Normal file
After Width: | Height: | Size: 779 B |
BIN
img/alchemylabBackground.png
Normal file
After Width: | Height: | Size: 472 B |
BIN
img/alteredGrandma.png
Normal file
After Width: | Height: | Size: 428 B |
BIN
img/alternateGrandma.png
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
img/antiGrandma.png
Normal file
After Width: | Height: | Size: 482 B |
BIN
img/antimattercondenser.png
Normal file
After Width: | Height: | Size: 634 B |
BIN
img/antimattercondenserBackground.png
Normal file
After Width: | Height: | Size: 966 B |
BIN
img/aqworldsbanner.jpg
Normal file
After Width: | Height: | Size: 28 KiB |
BIN
img/ascendBox.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
img/ascendInfo.png
Normal file
After Width: | Height: | Size: 9.8 KiB |
BIN
img/ascendSlot.png
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
img/ascendWisp.png
Normal file
After Width: | Height: | Size: 39 KiB |
BIN
img/ascendedBakingPod.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
img/bank.png
Normal file
After Width: | Height: | Size: 430 B |
BIN
img/bankBackground.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
img/bankGrandma.png
Normal file
After Width: | Height: | Size: 614 B |
BIN
img/bgBW.jpg
Normal file
After Width: | Height: | Size: 69 KiB |
BIN
img/bgBlack.jpg
Normal file
After Width: | Height: | Size: 57 KiB |
BIN
img/bgBlue.jpg
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
img/bgCandy.jpg
Normal file
After Width: | Height: | Size: 100 KiB |
BIN
img/bgChoco.jpg
Normal file
After Width: | Height: | Size: 82 KiB |
BIN
img/bgChocoDark.jpg
Normal file
After Width: | Height: | Size: 66 KiB |
BIN
img/bgCoarse.jpg
Normal file
After Width: | Height: | Size: 79 KiB |
BIN
img/bgFoil.jpg
Normal file
After Width: | Height: | Size: 189 KiB |
BIN
img/bgGold.jpg
Normal file
After Width: | Height: | Size: 92 KiB |
BIN
img/bgMint.jpg
Normal file
After Width: | Height: | Size: 79 KiB |
BIN
img/bgMoney.jpg
Normal file
After Width: | Height: | Size: 64 KiB |
BIN
img/bgMoneyChart.jpg
Normal file
After Width: | Height: | Size: 9.7 KiB |
BIN
img/bgPaint.jpg
Normal file
After Width: | Height: | Size: 95 KiB |
BIN
img/bgPink.jpg
Normal file
After Width: | Height: | Size: 70 KiB |
BIN
img/bgPurple.jpg
Normal file
After Width: | Height: | Size: 92 KiB |
BIN
img/bgRed.jpg
Normal file
After Width: | Height: | Size: 86 KiB |
BIN
img/bgSilver.jpg
Normal file
After Width: | Height: | Size: 92 KiB |
BIN
img/bgSky.jpg
Normal file
After Width: | Height: | Size: 87 KiB |
BIN
img/bgSnowy.jpg
Normal file
After Width: | Height: | Size: 107 KiB |
BIN
img/bgSpectrum.jpg
Normal file
After Width: | Height: | Size: 58 KiB |
BIN
img/bgStars.jpg
Normal file
After Width: | Height: | Size: 61 KiB |
BIN
img/bgWhite.jpg
Normal file
After Width: | Height: | Size: 40 KiB |
BIN
img/bgYellowBlue.jpg
Normal file
After Width: | Height: | Size: 99 KiB |
BIN
img/blackGradient.png
Normal file
After Width: | Height: | Size: 157 B |
BIN
img/blackGradientLeft.png
Normal file
After Width: | Height: | Size: 293 B |
BIN
img/blackGradientSmallTop.png
Normal file
After Width: | Height: | Size: 106 B |
BIN
img/bracketPanelLeftS.png
Normal file
After Width: | Height: | Size: 1.4 KiB |
BIN
img/bracketPanelRightS.png
Normal file
After Width: | Height: | Size: 1.4 KiB |
BIN
img/brainyGrandma.png
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
img/brokenCookie.png
Normal file
After Width: | Height: | Size: 32 KiB |
BIN
img/brokenCookieHalo.png
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
img/brownStripes.png
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
img/brownStripesLeftEdge.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
img/buildings.png
Normal file
After Width: | Height: | Size: 44 KiB |
BIN
img/bunnies.png
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
img/bunnyGrandma.png
Normal file
After Width: | Height: | Size: 593 B |
BIN
img/buttonTile.jpg
Normal file
After Width: | Height: | Size: 7.6 KiB |
BIN
img/caramelWave.png
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
img/chancemaker.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
img/chancemakerBackground.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
img/chocolateMilkWave.png
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
img/clayBG.jpg
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
img/cloneGrandma.png
Normal file
After Width: | Height: | Size: 774 B |
BIN
img/contract.png
Normal file
After Width: | Height: | Size: 4.0 KiB |
BIN
img/control.png
Normal file
After Width: | Height: | Size: 48 KiB |
BIN
img/cookieShadow.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
img/cookieShower1.png
Normal file
After Width: | Height: | Size: 28 KiB |
BIN
img/cookieShower2.png
Normal file
After Width: | Height: | Size: 55 KiB |
BIN
img/cookieShower3.png
Normal file
After Width: | Height: | Size: 76 KiB |
BIN
img/cortex.png
Normal file
After Width: | Height: | Size: 5.9 KiB |
BIN
img/cortexBackground.png
Normal file
After Width: | Height: | Size: 3.9 KiB |
BIN
img/cosmicGrandma.png
Normal file
After Width: | Height: | Size: 588 B |