Finished ocean & wave particles. Added animated screenshot.

This commit is contained in:
Robbie Antenesse 2016-04-06 08:01:52 -06:00
parent f8f1c77ba2
commit e03607b581
4 changed files with 62 additions and 22 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 136 KiB

View File

@ -9,58 +9,66 @@ var pr_ocean = OS.P.Add("Ocean Particle", {
positionCheckStep: 30, positionCheckStep: 30,
positionCheckProgress: 30, positionCheckProgress: 30,
doCheckPosition: false doCheckPosition: false,
moveTimer: 1 / OS.S.defaultStep,
}); });
pr_ocean.BeforeDo = function () { pr_ocean.BeforeDo = function () {
this.positionCheckProgress++; this.positionCheckProgress++;
if (this.positionCheckProgress >= this.positionCheckStep) { if (this.positionCheckProgress >= this.positionCheckStep) {
this.positionCheckProgress = 0; this.positionCheckProgress = 0;
doCheckPosition = true; this.doCheckPosition = true;
} }
} }
pr_ocean.Do = function () { pr_ocean.Do = function () {
// Move around randomly. // Move around randomly.
this.moveTimer--;
if (this.moveTimer <= 0) {
this.x += Math.round(Math.randomRange(-1, 1)) * OS.S.pixelScale;
this.y += Math.round(Math.randomRange(-1, 1)) * OS.S.pixelScale;
this.moveTimer = 1 / OS.S.defaultStep;
}
} }
pr_ocean.CheckPosition = function (checkX, checkY) { pr_ocean.CheckPosition = function (checkX, checkY, direction) {
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 - checkX) > (OS.camera.width + this.xBound)) || if ((Math.abs(this.x - checkX) > (OS.camera.width + this.xBound)) ||
(Math.abs(this.y - checkY) > (OS.camera.height + this.yBound))) (Math.abs(this.y - checkY) > (OS.camera.height + this.yBound)))
{ {
switch (pr_ship.direction) { switch (direction) {
case 0: case 0:
this.x = G.player.x + (OS.camera.width + this.xBound) + randomSmidge(); this.x = checkX + (OS.camera.width + this.xBound) + randomSmidge();
this.y = G.player.y + randomSmidge(); this.y = checkY + randomSmidge();
break; break;
case 45: case 45:
this.x = G.player.x + (OS.camera.width + this.xBound) + randomSmidge(); this.x = checkX + (OS.camera.width + this.xBound) + randomSmidge();
this.y = G.player.y - (OS.camera.height + this.yBound) + randomSmidge(); this.y = checkY - (OS.camera.height + this.yBound) + randomSmidge();
break; break;
case 90: case 90:
this.x = G.player.x + randomSmidge(); this.x = checkX + randomSmidge();
this.y = G.player.y - (OS.camera.height + this.yBound) + randomSmidge(); this.y = checkY - (OS.camera.height + this.yBound) + randomSmidge();
break; break;
case 135: case 135:
this.x = G.player.x - (OS.camera.width + this.xBound) + randomSmidge(); this.x = checkX - (OS.camera.width + this.xBound) + randomSmidge();
this.y = G.player.y - (OS.camera.height + this.yBound) + randomSmidge(); this.y = checkY - (OS.camera.height + this.yBound) + randomSmidge();
break; break;
case 180: case 180:
this.x = G.player.x - (OS.camera.width + this.xBound) + randomSmidge(); this.x = checkX - (OS.camera.width + this.xBound) + randomSmidge();
this.y = G.player.y + randomSmidge(); this.y = checkY + randomSmidge();
break; break;
case 225: case 225:
this.x = G.player.x - (OS.camera.width + this.xBound) + randomSmidge(); this.x = checkX - (OS.camera.width + this.xBound) + randomSmidge();
this.y = G.player.y + (OS.camera.height + this.yBound) + randomSmidge(); this.y = checkY + (OS.camera.height + this.yBound) + randomSmidge();
break; break;
case 270: case 270:
this.x = G.player.x + randomSmidge(); this.x = checkX + randomSmidge();
this.y = G.player.y + (OS.camera.height + this.yBound) + randomSmidge(); this.y = checkY + (OS.camera.height + this.yBound) + randomSmidge();
break; break;
case 315: case 315:
this.x = G.player.x + (OS.camera.width + this.xBound) + randomSmidge(); this.x = checkX + (OS.camera.width + this.xBound) + randomSmidge();
this.y = G.player.y + (OS.camera.height + this.yBound) + randomSmidge(); this.y = checkY + (OS.camera.height + this.yBound) + randomSmidge();
break; break;
default: default:
console.log("No valid direction"); console.log("No valid direction");

View File

@ -1 +1,19 @@
function wavePrefab() {} var ani_wave = OS.A.Add("Wave", 64, 64, {columns: 10, speed: 1/10});
function wavePrefab() {}
var pr_wave = OS.P.Add("Wave Particle", {
imageSrc: "images/wave_sheet.png",
animations: [ani_wave],
depth: -90, // Draw above ocean, below everything else.
lifeTimer: 100,
});
pr_wave.Do = function () {
// Move around randomly.
this.lifeTimer--;
if (this.lifeTimer <= 0) {
this.Destroy();
}
}

View File

@ -3,6 +3,10 @@ function oceanRoom () {
OS.SetRoom(rm_Ocean); OS.SetRoom(rm_Ocean);
} }
rm_Ocean.waveTimer = Math.round(Math.randomRange(30, 150));
rm_Ocean.speedGaugeImg = new Image();
rm_Ocean.speedGaugeImg.src = "images/speed_gauge_sheet.png";
rm_Ocean.DoFirst = function () { rm_Ocean.DoFirst = function () {
//Hide cursor when playing (only use if masking the cursor with another object) //Hide cursor when playing (only use if masking the cursor with another object)
//OS.canvas.style.cursor = "none"; //OS.canvas.style.cursor = "none";
@ -20,11 +24,21 @@ rm_Ocean.DoFirst = function () {
} }
rm_Ocean.Do = function () { rm_Ocean.Do = function () {
// Move G.oceanParticle around based on player's movement. // Move G.oceanParticle around based on player's movement.
G.oceanParticle.CheckPosition(G.player.x, G.player.y); G.oceanParticle.CheckPosition(G.player.x, G.player.y, G.player.direction);
this.waveTimer--;
if (this.waveTimer <= 0) {
var wave = this.AddObject(OS.P["Wave Particle"]);
wave.x = G.player.x + (randomSmidge() * 4);
wave.y = G.player.y + (randomSmidge() * 4);
this.waveTimer = Math.round(Math.randomRange(30, 150));
}
} }
rm_Ocean.DrawAbove = function () { rm_Ocean.DrawAbove = function () {
// Draw the speed indicator in Bottom Left corner. // Draw the speed indicator in Bottom Left corner.
OS.context.drawImage(rm_Ocean.speedGaugeImg, G.player.currentSpeed * 32, 0, 32, 32, 16, OS.camera.height - 32 - 16, 32, 32);
} }
rm_Ocean.DoLast = function () { rm_Ocean.DoLast = function () {