Made edits to try to make island generation better. It crashes on load a lot on Ubuntu Chrome for some reason. No clue why.

This commit is contained in:
Robbie Antenesse 2016-04-14 23:01:05 -06:00
parent d7201a5eb2
commit 34de633ef3
5 changed files with 41 additions and 41 deletions

View File

@ -11,6 +11,7 @@ var ct_shift = OS.C.Add("Shift", OS.Keycode.shift);
var ct_space = OS.C.Add("Space", OS.Keycode.space);
var ct_z = OS.C.Add("Z", OS.Keycode.z);
var ct_x = OS.C.Add("X", OS.Keycode.x);
var ct_m = OS.C.Add("M", OS.Keycode.m);
var ct_esc = OS.C.Add("Cancel", OS.Keycode.escape);
function loadControls () {}

View File

@ -6,6 +6,7 @@ var pr_island = OS.P.Add("Island", {
solid: true,
imageSrc: "images/island.png",
animations: [ani_island_1],
depth: -50,
mapX: 0,
mapY: 0,

View File

@ -74,7 +74,7 @@ pr_ship.AfterDo = function () {
pr_ship.GetMapPosition = function () {
this.mapX = pixel(Math.round(this.x / pixel(64)));
this.mapY = pixel(Math.round(this.y / pixel(64)));
console.log(this.mapX + ", " + this.mapY);
// console.log(this.mapX + ", " + this.mapY);
}
pr_ship.CheckInteraction = function () {

View File

@ -59,12 +59,16 @@ rm_Ocean.Do = function () {
this.waveTimer = Math.round(Math.randomRange(30, 150));
}
if (guiControl && guiControl.inventory && guiControl.trade) { // Force it to wait until loaded.
if (guiControl && guiControl.inventory && guiControl.map && guiControl.trade) { // Force it to wait until loaded.
if (!guiControl.inventory.show && !guiControl.map.show && !guiControl.trade.show) {
if (ct_cancel().down) {
guiControl.inventory.activateDelay = 5;
guiControl.inventory.show = true;
}
if (ct_m.down) {
guiControl.map.activateDelay = 5;
guiControl.map.show = true;
}
}
}
@ -147,54 +151,47 @@ rm_Ocean.DrawClock = function () {
}
rm_Ocean.GenerateMap = function () {
var island1 = rm_Ocean.AddObject(OS.P["Island"], {
x: pixel(64) * 25, //Exact center of map.
y: pixel(64) * 22
});
console.log(island1.name + " created at " + island1.x + ", " + island1.y);
G.map.push({
island: island1,
drawX: 25,
drawY: 22,
drawWidth: 1,
drawHeight: 1
});
var xSquares = [25];
var ySquares = [22];
var usedXSquares = [];
var usedYSquares = [];
for (var i = 0; i < 9; i++) {
var xSquare = Math.round(Math.randomRange(1, 49));
while (usedXSquares.indexOf(xSquare) != -1 &&
usedXSquares.indexOf(xSquare + 1) != -1 && usedXSquares.indexOf(xSquare - 1) != -1 &&
usedXSquares.indexOf(xSquare + 2) != -1 && usedXSquares.indexOf(xSquare - 2) != -1)
{
xSquare = Math.round(Math.randomRange(1, 49));
while(xSquares.length < 10){
var randomX = Math.round(Math.randomRange(1, 48));
var foundX = false;
for(var i = 0; i < xSquares.length; i++){
// console.log(i + ": " + (xSquares[i] - 3) + " <= " + randomX + " <= " + (xSquares[i] + 3) + "?");
if (randomX >= xSquares[i] - 3 && randomX <= xSquares[i] + 3) {
foundX = true;
break;
}
}
usedXSquares.push(xSquare);
var ySquare = Math.round(Math.randomRange(1, 43));
while (usedYSquares.indexOf(ySquare) != -1 &&
usedYSquares.indexOf(ySquare + 1) != -1 && usedYSquares.indexOf(ySquare - 1) != -1 &&
usedYSquares.indexOf(ySquare + 2) != -1 && usedYSquares.indexOf(ySquare - 2) != -1)
{
ySquare = Math.round(Math.randomRange(1, 49));
if (!foundX) xSquares[xSquares.length] = randomX;
}
while(ySquares.length < 10){
var randomY = Math.round(Math.randomRange(1, 42));
var foundY = false;
for(var i = 0; i < ySquares.length; i++){
// console.log(i + ": " + (ySquares[i] - 3) + " <= " + randomY + " <= " + (ySquares[i] + 3) + "?");
if (randomY >= ySquares[i] - 3 && randomY <= ySquares[i] + 3) {
foundY = true;
// console.log("It's between! Do not add!");
break;
}
}
usedYSquares.push(ySquare);
if (!foundY) ySquares[ySquares.length] = randomY;
}
var xPosition = pixel(64) * xSquare;
var yPosition = pixel(64) * ySquare;
for (var i = 0; i < xSquares.length; i++) {
G.map.push({
island: rm_Ocean.AddObject(OS.P["Island"], {
x: xPosition,
y: yPosition
x: pixel(64) * xSquares[i],
y: pixel(64) * ySquares[i]
}),
drawX: xSquare,
drawY: ySquare,
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(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);
}

View File

@ -1,6 +1,7 @@
OS.S.defaultStep = 1 / 120;
OS.S.numberOfScriptsToLoad = 14; // Excludes the titleScreen.js room, which is not loaded yet.
OS.S.pixelScale = 4;
// Oversimplified.DEBUG.showMessages = false;
OS.SetCamera({
width: pixel(64),
height: pixel(64),