diff --git a/loadGameManager.js b/loadGameManager.js index d89cdf4..011c275 100644 --- a/loadGameManager.js +++ b/loadGameManager.js @@ -1,7 +1,8 @@ var Game = {}; G = Game; -G.player = {}; -G.map = {}; +G.player = {}; // Just a reference until G.player is created at rm_Ocean's load time. +G.oceanParticle = {}; // One ocean particle will exist at any time and move around the boat. +G.map = []; // List of island objects, generated/loaded and saved at game start, loaded on room start. function loadGameManager () {} diff --git a/prefabs/oceanTilePrefab.js b/prefabs/oceanTilePrefab.js index 158755e..dc85691 100644 --- a/prefabs/oceanTilePrefab.js +++ b/prefabs/oceanTilePrefab.js @@ -5,47 +5,69 @@ function oceanTilePrefab() {} var pr_ocean = OS.P.Add("Ocean Particle", { imageSrc: "images/ocean_sheet.png", animations: [ani_ocean], + depth: -100, // Draw below everything. positionCheckStep: 30, positionCheckProgress: 30, doCheckPosition: false; }); +pr_ocean.BeforeDo = function () { + this.positionCheckProgress++; + if (this.positionCheckProgress >= this.positionCheckStep) { + this.positionCheckProgress = 0; + doCheckPosition = true; + } +} pr_ocean.Do = function () { + // Move around randomly. +} + +pr_ocean.CheckPosition = function (checkX, checkY) { if (this.doCheckPosition) { // If it's completely off the screen, then update position. - if ((Math.abs(this.x - pr_ship.x) > (OS.camera.width + this.image.width)) || - (Math.abs(this.y - pr_ship.y) > (OS.camera.height + this.image.height))) + if ((Math.abs(this.x - checkX) > (OS.camera.width + this.xBound)) || + (Math.abs(this.y - checkY) > (OS.camera.height + this.yBound))) { switch (pr_ship.direction) { case 0: - // if (pr_ship.doTakeStep) pr_ship.x += OS.S.pixelScale; + this.x = G.player.x + (OS.camera.width + this.xBound) + randomSmidge(); + this.y = G.player.y + randomSmidge(); break; case 45: - // if (pr_ship.doTakeStep) { pr_ship.x += OS.S.pixelScale; pr_ship.y -= OS.S.pixelScale; } + this.x = G.player.x + (OS.camera.width + this.xBound) + randomSmidge(); + this.y = G.player.y - (OS.camera.height + this.yBound) + randomSmidge(); break; case 90: - // if (pr_ship.doTakeStep) pr_ship.y -= OS.S.pixelScale; + this.x = G.player.x + randomSmidge(); + this.y = G.player.y - (OS.camera.height + this.yBound) + randomSmidge(); break; case 135: - // if (pr_ship.doTakeStep) { pr_ship.x -= OS.S.pixelScale; pr_ship.y -= OS.S.pixelScale; } + this.x = G.player.x - (OS.camera.width + this.xBound) + randomSmidge(); + this.y = G.player.y - (OS.camera.height + this.yBound) + randomSmidge(); break; case 180: - // if (pr_ship.doTakeStep) pr_ship.x -= OS.S.pixelScale; + this.x = G.player.x - (OS.camera.width + this.xBound) + randomSmidge(); + this.y = G.player.y + randomSmidge(); break; case 225: - // if (pr_ship.doTakeStep) { pr_ship.x -= OS.S.pixelScale; pr_ship.y += OS.S.pixelScale; } + this.x = G.player.x - (OS.camera.width + this.xBound) + randomSmidge(); + this.y = G.player.y + (OS.camera.height + this.yBound) + randomSmidge(); break; case 270: - // if (pr_ship.doTakeStep) pr_ship.y -= OS.S.pixelScale; + this.x = G.player.x + randomSmidge(); + this.y = G.player.y + (OS.camera.height + this.yBound) + randomSmidge(); break; case 315: - // if (pr_ship.doTakeStep) { pr_ship.x += OS.S.pixelScale; pr_ship.y += OS.S.pixelScale; } + this.x = G.player.x + (OS.camera.width + this.xBound) + randomSmidge(); + this.y = G.player.y + (OS.camera.height + this.yBound) + randomSmidge(); break; default: console.log("No valid direction"); break; } } + + this.doCheckPosition = false; } } \ No newline at end of file diff --git a/rooms/oceanRoom.js b/rooms/oceanRoom.js index b878666..98e8fb7 100644 --- a/rooms/oceanRoom.js +++ b/rooms/oceanRoom.js @@ -8,25 +8,25 @@ rm_Ocean.DoFirst = function () { //OS.canvas.style.cursor = "none"; // Create objects on room start. This is best practice unless you need persistent objects. - Game.player = this.AddObject(OS.P["UFO"]); - Game.ball = this.AddObject(OS.P["Ball"]); - Game.cowboys = Math.floor(RandomRange(5, 50)); - for (var i = 0; i < Game.cowboys; i++) { - this.AddObject(OS.P["Cowboy"]); - } + G.player = this.AddObject(OS.P["Ship"]); + G.player.x = ((rm_Ocean.width / OS.S.pixelScale) / 2) * OS.S.pixelScale; + G.player.y = ((rm_Ocean.height / OS.S.pixelScale) / 2) * OS.S.pixelScale; + + G.oceanParticle = this.AddObject(OS.P["Ocean Particle"]); + G.oceanParticle.x = G.player.x + randomSmidge(); + G.oceanParticle.y = G.player.y + randomSmidge(); + + OS.camera.Follow(G.player); } rm_Ocean.Do = function () { - if (Game.cowboys <= 0) { - OS.SetRoom(rm_Ocean); - } + // Move G.oceanParticle around based on player's movement. + G.oceanParticle.CheckPosition(G.player.x, G.player.y); } + rm_Ocean.DrawAbove = function () { - // Draw the number of cowboys remaining - if (Game.ball !== null) { - OS.context.font = "18px Impact"; - OS.context.fillText(Game.cowboys, 15, 30); - } + // Draw the speed indicator in Bottom Left corner. } + rm_Ocean.DoLast = function () { // Clear Objects on room exit. This is best practice unless you need persistent objects. rm_Ocean.objects = {}; diff --git a/start.js b/start.js index 2fc09a2..a9fa184 100644 --- a/start.js +++ b/start.js @@ -9,3 +9,8 @@ function start() OS.AddScript("loadPrefabs.js"); OS.AddScript("loadRooms.js"); } + +function randomSmidge() { +// Return a random amount between -10 and 10 on the pixel scale. + return (Math.round(Math.randomRange(-10, 10)) * OS.S.pixelScale); +}