Fixed island generation!

My while statements were looping forever because the ranges were too big!
This commit is contained in:
Robbie Antenesse 2016-04-15 15:10:24 -06:00
parent 8e09e8b2a0
commit 55ce2e7c1f
1 changed files with 41 additions and 58 deletions

View File

@ -11,19 +11,12 @@ function oceanRoom () {
} }
rm_Ocean.waveTimer = Math.round(Math.randomRange(30, 150)); rm_Ocean.waveTimer = Math.round(Math.randomRange(30, 150));
rm_Ocean.speedGaugeImg = new Image();
rm_Ocean.speedGaugeImg.src = "images/speed_gauge_sheet.png";
rm_Ocean.clockTimerCutoff = (1 / OS.S.defaultStep) * 60 * 5; // 5 minute day.
rm_Ocean.clockTimerCount = 0; rm_Ocean.clockTimerCount = 0;
rm_Ocean.clockImg = new Image();
rm_Ocean.clockImg.src = "images/clock_sheet.png";
rm_Ocean.DoFirst = function () { rm_Ocean.DoFirst = function () {
G.player.x = (pixel(64) * 25) - pixel(32) - G.player.xBound; G.player.x = (this.squareSize * (this.squaresX / 2)) - (this.squareSize / 2) - G.player.xBound;
G.player.y = pixel(64) * 22; G.player.y = (this.squareSize * (this.squaresY / 2));
console.log(G.player.name + " created at " + G.player.x + ", " + G.player.y); // console.log(G.player.name + " created at " + G.player.x + ", " + G.player.y);
G.oceanParticle.x = G.player.x + randomSmidge(); G.oceanParticle.x = G.player.x + randomSmidge();
G.oceanParticle.y = G.player.y + randomSmidge(); G.oceanParticle.y = G.player.y + randomSmidge();
@ -59,16 +52,12 @@ rm_Ocean.Do = function () {
this.waveTimer = Math.round(Math.randomRange(30, 150)); this.waveTimer = Math.round(Math.randomRange(30, 150));
} }
if (guiControl && guiControl.inventory && guiControl.map && guiControl.trade) { // Force it to wait until loaded. if (guiControl && guiControl.inventory && guiControl.trade) { // Force it to wait until loaded.
if (!guiControl.inventory.show && !guiControl.map.show && !guiControl.trade.show) { if (!guiControl.inventory.show && !guiControl.map.show && !guiControl.trade.show) {
if (ct_cancel().down) { if (ct_cancel().down) {
guiControl.inventory.activateDelay = 5; guiControl.inventory.activateDelay = 5;
guiControl.inventory.show = true; guiControl.inventory.show = true;
} }
if (ct_m.down) {
guiControl.map.activateDelay = 5;
guiControl.map.show = true;
}
} }
} }
@ -151,47 +140,41 @@ rm_Ocean.DrawClock = function () {
} }
rm_Ocean.GenerateMap = function () { rm_Ocean.GenerateMap = function () {
var xSquares = [25]; var xSquares = [25];
var ySquares = [22]; var ySquares = [22];
while (xSquares.length < this.numberOfIslands) {
while(xSquares.length < 10){ var randomNumber = Math.round(Math.randomRange(2, this.squaresX - 2));
var randomX = Math.round(Math.randomRange(1, 48)); var found = false;
var foundX = false; for (var i = 0; i < xSquares.length; i++) {
for(var i = 0; i < xSquares.length; i++){ if (xSquares[i] - ((this.squaresX / this.numberOfIslands) / 2) < randomNumber && randomNumber < xSquares[i] + ((this.squaresX / this.numberOfIslands) / 2)) {
// console.log(i + ": " + (xSquares[i] - 3) + " <= " + randomX + " <= " + (xSquares[i] + 3) + "?"); found = true;
if (randomX >= xSquares[i] - 3 && randomX <= xSquares[i] + 3) { break;
foundX = true; }
break; }
} if (!found) xSquares.push(randomNumber);
} }
if (!foundX) xSquares[xSquares.length] = randomX; while (ySquares.length < this.numberOfIslands) {
} var randomNumber = Math.round(Math.randomRange(2, this.squaresY - 2));
while(ySquares.length < 10){ var found = false;
var randomY = Math.round(Math.randomRange(1, 42)); for (var i = 0; i < ySquares.length; i++) {
var foundY = false; if (ySquares[i] - ((this.squaresY / this.numberOfIslands) / 2) < randomNumber && randomNumber < ySquares[i] + ((this.squaresY / this.numberOfIslands) / 2)) {
for(var i = 0; i < ySquares.length; i++){ found = true;
// console.log(i + ": " + (ySquares[i] - 3) + " <= " + randomY + " <= " + (ySquares[i] + 3) + "?"); break;
if (randomY >= ySquares[i] - 3 && randomY <= ySquares[i] + 3) { }
foundY = true; }
// console.log("It's between! Do not add!"); if (!found) ySquares.push(randomNumber);
break; }
}
} for (var i = 0; i < this.numberOfIslands; i++) {
if (!foundY) ySquares[ySquares.length] = randomY; G.map.push({
} island: rm_Ocean.AddObject(OS.P["Island"], {
x: this.squareSize * xSquares[i],
for (var i = 0; i < xSquares.length; i++) { y: this.squareSize * ySquares[i]
G.map.push({ }),
island: rm_Ocean.AddObject(OS.P["Island"], { drawX: xSquares[i],
x: pixel(64) * xSquares[i], drawY: ySquares[i],
y: pixel(64) * ySquares[i] drawWidth: 1,
}), drawHeight: 1
drawX: xSquares[i], });
drawY: ySquares[i], }
drawWidth: 1,
drawHeight: 1
});
// console.log(G.map[i + 1].island.name + " created at " + G.map[i + 1].island.x + ", " + G.map[i + 1].island.y);
}
console.log(xSquares + "\n" + ySquares);
} }