2016-04-06 01:59:37 +02:00
|
|
|
var ani_ship_r = OS.A.Add("Ship Right", 64, 64, {columns: 2, speed: 1/60, yOffset: 64 * 4});
|
|
|
|
var ani_ship_ur = OS.A.Add("Ship Up-Right", 64, 64, {columns: 2, speed: 1/60, yOffset: 64 * 7});
|
|
|
|
var ani_ship_u = OS.A.Add("Ship Up", 64, 64, {columns: 2, speed: 1/60, yOffset: 64 * 5});
|
|
|
|
var ani_ship_ul = OS.A.Add("Ship Up-Left", 64, 64, {columns: 2, speed: 1/60, yOffset: 64 * 6});
|
|
|
|
var ani_ship_l = OS.A.Add("Ship Left", 64, 64, {columns: 2, speed: 1/60, yOffset: 64 * 3});
|
|
|
|
var ani_ship_dl = OS.A.Add("Ship Down-Left", 64, 64, {columns: 2, speed: 1/60, yOffset: 64 * 1});
|
2016-04-06 00:51:00 +02:00
|
|
|
var ani_ship_d = OS.A.Add("Ship Down", 64, 64, {columns: 2, speed: 1/60, yOffset: 64 * 0});
|
2016-04-06 01:59:37 +02:00
|
|
|
var ani_ship_dr = OS.A.Add("Ship Down-Right", 64, 64, {columns: 2, speed: 1/60, yOffset: 64 * 2});
|
2016-04-05 19:39:18 +02:00
|
|
|
|
|
|
|
function shipPrefab() {}
|
|
|
|
|
2016-04-06 00:51:00 +02:00
|
|
|
var pr_ship = OS.P.Add("Ship", {
|
|
|
|
solid: true,
|
|
|
|
imageSrc: "images/ship_sheet.png",
|
|
|
|
maskImageSrc: "images/ship_mask.png",
|
|
|
|
animations: [ani_ship_r, ani_ship_ur, ani_ship_u, ani_ship_ul, ani_ship_l, ani_ship_dl, ani_ship_d, ani_ship_dr],
|
|
|
|
|
|
|
|
direction: 0,
|
2016-04-06 01:59:37 +02:00
|
|
|
currentSpeed: 0,
|
2016-04-08 15:52:28 +02:00
|
|
|
pointInFront : {x: 0, y: 0 },
|
2016-04-06 00:51:00 +02:00
|
|
|
moveStepSize: 3,
|
2016-04-17 07:35:04 +02:00
|
|
|
moveStepAmount: 5 * OS.R[OS.R.currentRoom].stepSpeed,
|
2016-04-06 00:51:00 +02:00
|
|
|
moveStepProgress: 0,
|
2016-04-08 02:20:23 +02:00
|
|
|
doTakeStep: false,
|
|
|
|
|
2016-04-16 07:15:38 +02:00
|
|
|
energyRefillTimer: 0,
|
|
|
|
|
|
|
|
drawSickIndicator: 0,
|
|
|
|
drawSickIndicatorTime: secondsWorthOfFrames(1.5)
|
2016-04-06 00:51:00 +02:00
|
|
|
});
|
|
|
|
|
2016-04-15 01:09:57 +02:00
|
|
|
pr_ship.BeforeDo = function () {
|
2016-04-17 07:35:04 +02:00
|
|
|
if (G.gameStarted) {
|
|
|
|
this.GetMapPosition();
|
|
|
|
}
|
2016-04-15 01:09:57 +02:00
|
|
|
}
|
|
|
|
|
2016-04-06 00:51:00 +02:00
|
|
|
pr_ship.Do = function () {
|
2016-04-17 07:35:04 +02:00
|
|
|
if (G.gameStarted) {
|
|
|
|
if (guiControl && guiControl.inventory && guiControl.map && guiControl.trade) { // Force it to wait until loaded.
|
|
|
|
if (!guiControl.inventory.show && !guiControl.map.show && !guiControl.trade.show) {
|
|
|
|
if (ct_left().down) {
|
|
|
|
this.direction += 45;
|
|
|
|
} else if (ct_right().down) {
|
|
|
|
this.direction -= 45;
|
|
|
|
}
|
|
|
|
this.direction = Math.clampAngle(this.direction);
|
|
|
|
|
|
|
|
if (ct_up().down) {
|
|
|
|
this.currentSpeed++;
|
|
|
|
} else if (ct_down().down) {
|
|
|
|
this.currentSpeed--;
|
|
|
|
}
|
|
|
|
this.AdjustSpeedBasedOnEnergy();
|
2016-04-12 18:02:27 +02:00
|
|
|
|
2016-04-17 07:35:04 +02:00
|
|
|
this.CheckInteraction();
|
|
|
|
}
|
2016-04-14 22:58:19 +02:00
|
|
|
}
|
2016-04-06 00:51:00 +02:00
|
|
|
|
2016-04-17 07:35:04 +02:00
|
|
|
this.currentSpeed = Math.clamp(this.currentSpeed, 0, 4);
|
|
|
|
|
|
|
|
this.moveStepProgress += this.currentSpeed * this.moveStepAmount;
|
|
|
|
if (this.moveStepProgress >= this.moveStepSize) {
|
|
|
|
this.moveStepProgress -= this.moveStepSize;
|
|
|
|
console.log("take step");
|
|
|
|
this.doTakeStep = true;
|
|
|
|
} else {
|
|
|
|
this.doTakeStep = false;
|
|
|
|
}
|
2016-04-07 20:26:36 +02:00
|
|
|
|
2016-04-12 18:02:27 +02:00
|
|
|
|
2016-04-17 07:35:04 +02:00
|
|
|
this.SeamlessScroll();
|
|
|
|
// console.log(G.player.name + " created at " + G.player.x + ", " + G.player.y);
|
|
|
|
}
|
2016-04-06 00:51:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pr_ship.AfterDo = function () {
|
2016-04-17 07:35:04 +02:00
|
|
|
if (G.gameStarted) {
|
|
|
|
this.CheckMovement();
|
|
|
|
this.UpdateEnergy();
|
|
|
|
}
|
2016-04-06 22:40:42 +02:00
|
|
|
}
|
|
|
|
|
2016-04-16 07:15:38 +02:00
|
|
|
pr_ship.DrawAbove = function () {
|
2016-04-17 07:35:04 +02:00
|
|
|
if (G.gameStarted) {
|
|
|
|
this.drawSickIndicator--;
|
|
|
|
if (this.drawSickIndicator < 0) {
|
|
|
|
this.drawSickIndicator = 0;
|
|
|
|
}
|
|
|
|
if (this.drawSickIndicator > 0) {
|
|
|
|
var sickIndicatorHeight = Math.round((this.drawSickIndicatorTime - this.drawSickIndicator) / 2) / OS.S.pixelScale;
|
|
|
|
var sickIndicatorY = this.y - sickIndicatorHeight - Oversimplified.camera.y - (guiControl.iconScaled / 2);
|
|
|
|
guiControl.drawIcon(4, 1, this.x - Oversimplified.camera.x - (guiControl.iconScaled / 2), sickIndicatorY);
|
|
|
|
}
|
2016-04-16 07:15:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-15 01:09:57 +02:00
|
|
|
pr_ship.GetMapPosition = function () {
|
|
|
|
this.mapX = pixel(Math.round(this.x / pixel(64)));
|
|
|
|
this.mapY = pixel(Math.round(this.y / pixel(64)));
|
2016-04-15 07:01:05 +02:00
|
|
|
// console.log(this.mapX + ", " + this.mapY);
|
2016-04-15 01:09:57 +02:00
|
|
|
}
|
|
|
|
|
2016-04-08 15:52:28 +02:00
|
|
|
pr_ship.CheckInteraction = function () {
|
2016-04-10 04:12:16 +02:00
|
|
|
if (ct_confirm().down) {
|
|
|
|
var objectsFound = OS.GameObjectsAtPoint(this.pointInFront.x, this.pointInFront.y);
|
|
|
|
if (objectsFound.length > 0) {
|
|
|
|
for (var i = 0; i < objectsFound.length; i++) {
|
|
|
|
if (objectsFound[i].canTrade) {
|
2016-04-14 22:58:19 +02:00
|
|
|
// console.log("interacting with island: " + objectsFound[i].name);
|
2016-04-12 18:02:27 +02:00
|
|
|
objectsFound[i].TradeWith();
|
2016-04-10 04:12:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-08 15:52:28 +02:00
|
|
|
}
|
|
|
|
|
2016-04-06 22:40:42 +02:00
|
|
|
pr_ship.CheckMovement = function () {
|
2016-04-13 02:14:09 +02:00
|
|
|
var moveAmount = pixel(G.stats.speed + this.currentSpeed);
|
2016-04-08 02:20:23 +02:00
|
|
|
var movedSuccessfully = false;
|
2016-04-06 00:51:00 +02:00
|
|
|
switch (this.direction) {
|
|
|
|
case 0:
|
|
|
|
if (this.image.currentAnimation != "Ship Right") this.SetAnimation("Ship Right");
|
2016-04-14 07:20:54 +02:00
|
|
|
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(moveAmount, 0, true, pixel(4));
|
2016-04-13 02:14:09 +02:00
|
|
|
this.pointInFront.x = this.x + this.xBound + pixel(2) + moveAmount;
|
2016-04-08 15:52:28 +02:00
|
|
|
this.pointInFront.y = this.y;
|
2016-04-06 00:51:00 +02:00
|
|
|
break;
|
|
|
|
case 45:
|
|
|
|
if (this.image.currentAnimation != "Ship Up-Right") this.SetAnimation("Ship Up-Right");
|
2016-04-14 07:20:54 +02:00
|
|
|
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(moveAmount, -moveAmount, true, pixel(4));
|
2016-04-13 02:14:09 +02:00
|
|
|
this.pointInFront.x = this.x + this.xBound + pixel(2) + moveAmount;
|
|
|
|
this.pointInFront.y = this.y - this.yBound - pixel(2) - moveAmount;
|
2016-04-06 00:51:00 +02:00
|
|
|
break;
|
|
|
|
case 90:
|
|
|
|
if (this.image.currentAnimation != "Ship Up") this.SetAnimation("Ship Up");
|
2016-04-14 07:20:54 +02:00
|
|
|
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(0, -moveAmount, true, pixel(4));
|
2016-04-08 15:52:28 +02:00
|
|
|
this.pointInFront.x = this.x;
|
2016-04-13 02:14:09 +02:00
|
|
|
this.pointInFront.y = this.y - this.yBound - pixel(2) - moveAmount;
|
2016-04-06 00:51:00 +02:00
|
|
|
break;
|
|
|
|
case 135:
|
|
|
|
if (this.image.currentAnimation != "Ship Up-Left") this.SetAnimation("Ship Up-Left");
|
2016-04-14 07:20:54 +02:00
|
|
|
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(-moveAmount, -moveAmount, true, pixel(4));
|
2016-04-13 02:14:09 +02:00
|
|
|
this.pointInFront.x = this.x - this.xBound - pixel(2) - moveAmount;
|
|
|
|
this.pointInFront.y = this.y - this.yBound - pixel(2) - moveAmount;
|
2016-04-06 00:51:00 +02:00
|
|
|
break;
|
|
|
|
case 180:
|
|
|
|
if (this.image.currentAnimation != "Ship Left") this.SetAnimation("Ship Left");
|
2016-04-14 07:20:54 +02:00
|
|
|
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(-moveAmount, 0, true, pixel(4));
|
2016-04-13 02:14:09 +02:00
|
|
|
this.pointInFront.x = this.x - this.xBound - pixel(2) - moveAmount;
|
2016-04-08 15:52:28 +02:00
|
|
|
this.pointInFront.y = this.y;
|
2016-04-06 00:51:00 +02:00
|
|
|
break;
|
|
|
|
case 225:
|
|
|
|
if (this.image.currentAnimation != "Ship Down-Left") this.SetAnimation("Ship Down-Left");
|
2016-04-14 07:20:54 +02:00
|
|
|
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(-moveAmount, moveAmount, true, pixel(4));
|
2016-04-13 02:14:09 +02:00
|
|
|
this.pointInFront.x = this.x - this.xBound - pixel(2) - moveAmount;
|
|
|
|
this.pointInFront.y = this.y + this.yBound + pixel(2) + moveAmount;
|
2016-04-06 00:51:00 +02:00
|
|
|
break;
|
|
|
|
case 270:
|
|
|
|
if (this.image.currentAnimation != "Ship Down") this.SetAnimation("Ship Down");
|
2016-04-14 07:20:54 +02:00
|
|
|
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(0, moveAmount, true, pixel(4));
|
2016-04-08 15:52:28 +02:00
|
|
|
this.pointInFront.x = this.x;
|
2016-04-13 02:14:09 +02:00
|
|
|
this.pointInFront.y = this.y + this.yBound + pixel(2) + moveAmount;
|
2016-04-06 00:51:00 +02:00
|
|
|
break;
|
|
|
|
case 315:
|
|
|
|
if (this.image.currentAnimation != "Ship Down-Right") this.SetAnimation("Ship Down-Right");
|
2016-04-14 07:20:54 +02:00
|
|
|
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(moveAmount, moveAmount, true, pixel(4));
|
2016-04-13 02:14:09 +02:00
|
|
|
this.pointInFront.x = this.x + this.xBound + pixel(2) + moveAmount;
|
|
|
|
this.pointInFront.y = this.y + this.yBound + pixel(2) + moveAmount;
|
2016-04-06 00:51:00 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
console.log("No valid direction");
|
|
|
|
break;
|
|
|
|
}
|
2016-04-08 02:20:23 +02:00
|
|
|
|
|
|
|
if (this.doTakeStep && !movedSuccessfully) {
|
|
|
|
this.currentSpeed = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pr_ship.UpdateEnergy = function () {
|
|
|
|
this.energyRefillTimer++;
|
2016-04-08 22:39:12 +02:00
|
|
|
if (this.energyRefillTimer >= (100 / G.stats.crew) + ((G.stats.illness) * (100 / G.stats.crew))) {
|
|
|
|
G.stats.energy += G.stats.crew;
|
|
|
|
this.energyRefillTimer = 0;
|
|
|
|
}
|
2016-04-08 02:20:23 +02:00
|
|
|
|
|
|
|
if (this.doTakeStep) {
|
2016-04-08 22:39:12 +02:00
|
|
|
G.stats.energy -= ((this.currentSpeed / G.stats.speed) + ((G.stats.illness) * 0.1)) * 0.25;
|
2016-04-08 02:20:23 +02:00
|
|
|
}
|
2016-04-08 22:39:12 +02:00
|
|
|
|
|
|
|
if (G.stats.energy < 0) G.stats.energy = 0;
|
|
|
|
if (G.stats.energy > G.stats.maxEnergy) G.stats.energy = G.stats.maxEnergy;
|
2016-04-06 00:51:00 +02:00
|
|
|
}
|
2016-04-07 20:26:36 +02:00
|
|
|
|
|
|
|
pr_ship.SeamlessScroll = function () {
|
|
|
|
if (this.x <= rm_Ocean.mapLeftTrigger) {
|
|
|
|
this.x = rm_Ocean.mapLeftTriggerTarget;
|
|
|
|
OS.SetCamera({x: rm_Ocean.width});
|
|
|
|
}
|
|
|
|
else if (this.x >= rm_Ocean.mapRightTrigger) {
|
|
|
|
this.x = rm_Ocean.mapRightTriggerTarget;
|
|
|
|
OS.SetCamera({x: 0});
|
|
|
|
}
|
|
|
|
else if (this.y <= rm_Ocean.mapUpTrigger) {
|
|
|
|
this.y = rm_Ocean.mapUpTriggerTarget;
|
|
|
|
OS.SetCamera({y: rm_Ocean.height});
|
|
|
|
}
|
|
|
|
else if (this.y >= rm_Ocean.mapDownTrigger) {
|
|
|
|
this.y = rm_Ocean.mapDownTriggerTarget;
|
|
|
|
OS.SetCamera({y: 0});
|
|
|
|
}
|
|
|
|
}
|
2016-04-08 22:39:12 +02:00
|
|
|
|
|
|
|
pr_ship.AdjustSpeedBasedOnEnergy = function () {
|
|
|
|
if (this.currentSpeed > 3 && G.stats.energy < (G.stats.maxEnergy * 0.3) ||
|
|
|
|
this.currentSpeed > 2 && G.stats.energy < (G.stats.maxEnergy * 0.15) ||
|
|
|
|
this.currentSpeed > 1 && G.stats.energy < (G.stats.maxEnergy * 0.05))
|
|
|
|
{
|
|
|
|
this.currentSpeed--;
|
|
|
|
}
|
|
|
|
}
|
2016-04-16 07:15:38 +02:00
|
|
|
|
|
|
|
pr_ship.CheckIllnessIncrease = function () {
|
|
|
|
var percentChance = G.stats.crew + ((this.currentSpeed / (G.stats.energy + 0.001)) * G.stats.illness); // +0.001 on the off-chance that energy reaches 0.
|
|
|
|
if (Math.randomRange(0, 100) < percentChance) {
|
2016-04-16 23:43:39 +02:00
|
|
|
snd_illness.Play();
|
2016-04-16 07:15:38 +02:00
|
|
|
G.stats.illness++;
|
|
|
|
this.drawSickIndicator += secondsWorthOfFrames(1.5);
|
|
|
|
}
|
|
|
|
}
|