Skip to content

Instantly share code, notes, and snippets.

@notbend
Created July 20, 2013 02:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save notbend/6043598 to your computer and use it in GitHub Desktop.
Save notbend/6043598 to your computer and use it in GitHub Desktop.
plain JS
var Terrain = function() {
//TODO windows, sun, building colors
this.sun_x = 0.00;
this.sun_y = 0.00;
this.holes = Array(); //x,y
this.p1_pos = 0; //index of building
this.p2_pos = 7;
var has_p1_pos = has_p2_pos = false;
for (var i=0; i < 15; i++) {
if (i < 5 && !has_p1_pos && Math.random() > 0.6) {
this.p1_pos = i;
has_p1_pos = true;
} else if(i > 6 && !has_p2_pos && Math.random() > 0.6) {
this.p2_pos = i;
has_p2_pos = true;
}
var _height = 100 + Math.random() * 150;
var _width = 50 + Math.random() * 45;
this.buildings[i] = {
height: _height,
width: _width,
windows: (function(h,w){
var lights = Array();
var x_count = Math.floor(h / 24);
var y_count = Math.floor(w / 15);
total_windows = x_count * y_count - 1;
for(z=0; z<total_windows; z++) {
(Math.random() > 0.7) ? lights[z] = 1 : lights[z] = 2;
}
return {
x_count: x_count,
y_count: y_count,
lights: lights
}
})(_height,_width)
};
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment