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 = {};
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 () {}

View File

@ -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;
}
}

View File

@ -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 = {};

View File

@ -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);
}