2016-04-06 22:47:32 +02:00
|
|
|
var ani_ocean = OS.A.Add("Ocean", 256, 256, {columns: 10, speed: 1/60});
|
2016-04-06 00:51:51 +02:00
|
|
|
|
|
|
|
function oceanTilePrefab() {}
|
|
|
|
|
|
|
|
var pr_ocean = OS.P.Add("Ocean Particle", {
|
|
|
|
imageSrc: "images/ocean_sheet.png",
|
|
|
|
animations: [ani_ocean],
|
2016-04-06 01:33:38 +02:00
|
|
|
depth: -100, // Draw below everything.
|
2016-04-06 00:51:51 +02:00
|
|
|
|
|
|
|
positionCheckStep: 30,
|
|
|
|
positionCheckProgress: 30,
|
2016-04-06 16:01:52 +02:00
|
|
|
doCheckPosition: false,
|
|
|
|
|
2016-04-06 22:47:32 +02:00
|
|
|
moveTimer: 0,
|
2016-04-06 00:51:51 +02:00
|
|
|
});
|
|
|
|
|
2016-04-06 01:33:38 +02:00
|
|
|
pr_ocean.BeforeDo = function () {
|
|
|
|
this.positionCheckProgress++;
|
|
|
|
if (this.positionCheckProgress >= this.positionCheckStep) {
|
|
|
|
this.positionCheckProgress = 0;
|
2016-04-06 16:01:52 +02:00
|
|
|
this.doCheckPosition = true;
|
2016-04-06 01:33:38 +02:00
|
|
|
}
|
|
|
|
}
|
2016-04-06 00:51:51 +02:00
|
|
|
pr_ocean.Do = function () {
|
2016-04-06 01:33:38 +02:00
|
|
|
// Move around randomly.
|
2016-04-06 22:47:32 +02:00
|
|
|
this.moveTimer++;
|
|
|
|
if (this.moveTimer >= 120) {
|
|
|
|
this.x += 1 * Math.round(Math.randomRange(-1, 1)) * OS.S.pixelScale;
|
|
|
|
this.y += 1 * Math.round(Math.randomRange(-1, 1)) * OS.S.pixelScale;
|
|
|
|
this.moveTimer = 0;
|
2016-04-06 16:01:52 +02:00
|
|
|
}
|
2016-04-06 01:33:38 +02:00
|
|
|
}
|
|
|
|
|
2016-04-06 16:01:52 +02:00
|
|
|
pr_ocean.CheckPosition = function (checkX, checkY, direction) {
|
2016-04-06 00:51:51 +02:00
|
|
|
if (this.doCheckPosition) {
|
|
|
|
// If it's completely off the screen, then update position.
|
2016-04-06 01:33:38 +02:00
|
|
|
if ((Math.abs(this.x - checkX) > (OS.camera.width + this.xBound)) ||
|
|
|
|
(Math.abs(this.y - checkY) > (OS.camera.height + this.yBound)))
|
2016-04-06 00:51:51 +02:00
|
|
|
{
|
2016-04-06 16:01:52 +02:00
|
|
|
switch (direction) {
|
2016-04-06 00:51:51 +02:00
|
|
|
case 0:
|
2016-04-06 16:01:52 +02:00
|
|
|
this.x = checkX + (OS.camera.width + this.xBound) + randomSmidge();
|
|
|
|
this.y = checkY + randomSmidge();
|
2016-04-06 00:51:51 +02:00
|
|
|
break;
|
|
|
|
case 45:
|
2016-04-06 16:01:52 +02:00
|
|
|
this.x = checkX + (OS.camera.width + this.xBound) + randomSmidge();
|
|
|
|
this.y = checkY - (OS.camera.height + this.yBound) + randomSmidge();
|
2016-04-06 00:51:51 +02:00
|
|
|
break;
|
|
|
|
case 90:
|
2016-04-06 16:01:52 +02:00
|
|
|
this.x = checkX + randomSmidge();
|
|
|
|
this.y = checkY - (OS.camera.height + this.yBound) + randomSmidge();
|
2016-04-06 00:51:51 +02:00
|
|
|
break;
|
|
|
|
case 135:
|
2016-04-06 16:01:52 +02:00
|
|
|
this.x = checkX - (OS.camera.width + this.xBound) + randomSmidge();
|
|
|
|
this.y = checkY - (OS.camera.height + this.yBound) + randomSmidge();
|
2016-04-06 00:51:51 +02:00
|
|
|
break;
|
|
|
|
case 180:
|
2016-04-06 16:01:52 +02:00
|
|
|
this.x = checkX - (OS.camera.width + this.xBound) + randomSmidge();
|
|
|
|
this.y = checkY + randomSmidge();
|
2016-04-06 00:51:51 +02:00
|
|
|
break;
|
|
|
|
case 225:
|
2016-04-06 16:01:52 +02:00
|
|
|
this.x = checkX - (OS.camera.width + this.xBound) + randomSmidge();
|
|
|
|
this.y = checkY + (OS.camera.height + this.yBound) + randomSmidge();
|
2016-04-06 00:51:51 +02:00
|
|
|
break;
|
|
|
|
case 270:
|
2016-04-06 16:01:52 +02:00
|
|
|
this.x = checkX + randomSmidge();
|
|
|
|
this.y = checkY + (OS.camera.height + this.yBound) + randomSmidge();
|
2016-04-06 00:51:51 +02:00
|
|
|
break;
|
|
|
|
case 315:
|
2016-04-06 16:01:52 +02:00
|
|
|
this.x = checkX + (OS.camera.width + this.xBound) + randomSmidge();
|
|
|
|
this.y = checkY + (OS.camera.height + this.yBound) + randomSmidge();
|
2016-04-06 00:51:51 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
console.log("No valid direction");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-04-06 01:33:38 +02:00
|
|
|
|
|
|
|
this.doCheckPosition = false;
|
2016-04-06 00:51:51 +02:00
|
|
|
}
|
2016-04-06 22:47:32 +02:00
|
|
|
}
|