Updated Ocean prefab and got things set up.

This commit is contained in:
Robbie Antenesse 2016-04-05 17:33:38 -06:00
parent cb98da3eee
commit 096ce49334
4 changed files with 54 additions and 26 deletions

View File

@ -1,7 +1,8 @@
var Game = {}; var Game = {};
G = Game; G = Game;
G.player = {}; G.player = {}; // Just a reference until G.player is created at rm_Ocean's load time.
G.map = {}; 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 () {} function loadGameManager () {}

View File

@ -5,47 +5,69 @@ function oceanTilePrefab() {}
var pr_ocean = OS.P.Add("Ocean Particle", { var pr_ocean = OS.P.Add("Ocean Particle", {
imageSrc: "images/ocean_sheet.png", imageSrc: "images/ocean_sheet.png",
animations: [ani_ocean], animations: [ani_ocean],
depth: -100, // Draw below everything.
positionCheckStep: 30, positionCheckStep: 30,
positionCheckProgress: 30, positionCheckProgress: 30,
doCheckPosition: false; doCheckPosition: false;
}); });
pr_ocean.BeforeDo = function () {
this.positionCheckProgress++;
if (this.positionCheckProgress >= this.positionCheckStep) {
this.positionCheckProgress = 0;
doCheckPosition = true;
}
}
pr_ocean.Do = function () { pr_ocean.Do = function () {
// Move around randomly.
}
pr_ocean.CheckPosition = function (checkX, checkY) {
if (this.doCheckPosition) { if (this.doCheckPosition) {
// If it's completely off the screen, then update position. // If it's completely off the screen, then update position.
if ((Math.abs(this.x - pr_ship.x) > (OS.camera.width + this.image.width)) || if ((Math.abs(this.x - checkX) > (OS.camera.width + this.xBound)) ||
(Math.abs(this.y - pr_ship.y) > (OS.camera.height + this.image.height))) (Math.abs(this.y - checkY) > (OS.camera.height + this.yBound)))
{ {
switch (pr_ship.direction) { switch (pr_ship.direction) {
case 0: 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; break;
case 45: 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; break;
case 90: 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; break;
case 135: 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; break;
case 180: 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; break;
case 225: 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; break;
case 270: 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; break;
case 315: 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; break;
default: default:
console.log("No valid direction"); console.log("No valid direction");
break; break;
} }
} }
this.doCheckPosition = false;
} }
} }

View File

@ -8,25 +8,25 @@ rm_Ocean.DoFirst = function () {
//OS.canvas.style.cursor = "none"; //OS.canvas.style.cursor = "none";
// Create objects on room start. This is best practice unless you need persistent objects. // Create objects on room start. This is best practice unless you need persistent objects.
Game.player = this.AddObject(OS.P["UFO"]); G.player = this.AddObject(OS.P["Ship"]);
Game.ball = this.AddObject(OS.P["Ball"]); G.player.x = ((rm_Ocean.width / OS.S.pixelScale) / 2) * OS.S.pixelScale;
Game.cowboys = Math.floor(RandomRange(5, 50)); G.player.y = ((rm_Ocean.height / OS.S.pixelScale) / 2) * OS.S.pixelScale;
for (var i = 0; i < Game.cowboys; i++) {
this.AddObject(OS.P["Cowboy"]); 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 () { rm_Ocean.Do = function () {
if (Game.cowboys <= 0) { // Move G.oceanParticle around based on player's movement.
OS.SetRoom(rm_Ocean); G.oceanParticle.CheckPosition(G.player.x, G.player.y);
}
} }
rm_Ocean.DrawAbove = function () { rm_Ocean.DrawAbove = function () {
// Draw the number of cowboys remaining // Draw the speed indicator in Bottom Left corner.
if (Game.ball !== null) {
OS.context.font = "18px Impact";
OS.context.fillText(Game.cowboys, 15, 30);
}
} }
rm_Ocean.DoLast = function () { rm_Ocean.DoLast = function () {
// Clear Objects on room exit. This is best practice unless you need persistent objects. // Clear Objects on room exit. This is best practice unless you need persistent objects.
rm_Ocean.objects = {}; rm_Ocean.objects = {};

View File

@ -9,3 +9,8 @@ function start()
OS.AddScript("loadPrefabs.js"); OS.AddScript("loadPrefabs.js");
OS.AddScript("loadRooms.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);
}