Merge branch 'master' into gh-pages
# Conflicts: # index.html
|
@ -0,0 +1,2 @@
|
|||
# LowRez-Jam-2016
|
||||
An OversimplifiedJS game for the 2016 LowRez Jam (https://itch.io/jam/lowrezjam2016)
|
After Width: | Height: | Size: 476 B |
After Width: | Height: | Size: 776 B |
After Width: | Height: | Size: 475 B |
After Width: | Height: | Size: 755 B |
After Width: | Height: | Size: 486 B |
After Width: | Height: | Size: 778 B |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 1002 B |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 136 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 160 KiB |
After Width: | Height: | Size: 153 B |
After Width: | Height: | Size: 2.8 KiB |
After Width: | Height: | Size: 465 B |
After Width: | Height: | Size: 586 B |
After Width: | Height: | Size: 573 B |
After Width: | Height: | Size: 472 B |
After Width: | Height: | Size: 468 B |
After Width: | Height: | Size: 439 B |
After Width: | Height: | Size: 560 B |
After Width: | Height: | Size: 587 B |
After Width: | Height: | Size: 283 B |
After Width: | Height: | Size: 600 B |
|
@ -8,6 +8,7 @@
|
|||
<link rel="stylesheet" href="stylesheets/styles.css">
|
||||
<link rel="stylesheet" href="stylesheets/github-light.css">
|
||||
<script src="javascripts/scale.fix.js"></script>
|
||||
<script src="Oversimplified.js"></script>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
|
||||
<!--[if lt IE 9]>
|
||||
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
||||
|
@ -29,6 +30,12 @@
|
|||
|
||||
|
||||
</header>
|
||||
<section>
|
||||
<canvas style="border:solid 1px black;" id="game">
|
||||
Your browser is really old, dude - no canvas support! Update this thing!
|
||||
</canvas>
|
||||
<div id="audio"></div>
|
||||
</section>
|
||||
<section>
|
||||
<h2>
|
||||
<a id="about" class="anchor" href="#about" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>About</h2>
|
||||
|
@ -63,4 +70,4 @@
|
|||
<!--[if !IE]><script>fixScale(document);</script><![endif]-->
|
||||
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
|
@ -0,0 +1,64 @@
|
|||
var ct_wasd_up = OS.C.Add("WASD Up", OS.Keycode.w);
|
||||
var ct_wasd_left = OS.C.Add("WASD Left", OS.Keycode.a);
|
||||
var ct_wasd_down = OS.C.Add("WASD Down", OS.Keycode.s);
|
||||
var ct_wasd_right = OS.C.Add("WASD Right", OS.Keycode.d);
|
||||
var ct_arrow_up = OS.C.Add("Arrow Up", OS.Keycode.up);
|
||||
var ct_arrow_left = OS.C.Add("Arrow Left", OS.Keycode.left);
|
||||
var ct_arrow_down = OS.C.Add("Arrow Down", OS.Keycode.down);
|
||||
var ct_arrow_right = OS.C.Add("Arrow Right", OS.Keycode.right);
|
||||
|
||||
var ct_shift = OS.C.Add("Shift", OS.Keycode.shift);
|
||||
var ct_space = OS.C.Add("Confirm", OS.Keycode.space);
|
||||
var ct_z = OS.C.Add("Shift", OS.Keycode.z);
|
||||
var ct_x = OS.C.Add("Confirm", OS.Keycode.x);
|
||||
var ct_esc = OS.C.Add("Cancel", OS.Keycode.escape);
|
||||
|
||||
function loadControls () {}
|
||||
|
||||
function ct_up () {
|
||||
return {
|
||||
held : ct_wasd_up.held || ct_arrow_up.held,
|
||||
down : ct_wasd_up.down || ct_arrow_up.down,
|
||||
up : ct_wasd_up.up || ct_arrow_up.up
|
||||
}
|
||||
}
|
||||
|
||||
function ct_left () {
|
||||
return {
|
||||
held : ct_wasd_left.held || ct_arrow_left.held,
|
||||
down : ct_wasd_left.down || ct_arrow_left.down,
|
||||
up : ct_wasd_left.up || ct_arrow_left.up
|
||||
}
|
||||
}
|
||||
|
||||
function ct_down () {
|
||||
return {
|
||||
held : ct_wasd_down.held || ct_arrow_down.held,
|
||||
down : ct_wasd_down.down || ct_arrow_down.down,
|
||||
up : ct_wasd_down.up || ct_arrow_down.up
|
||||
}
|
||||
}
|
||||
|
||||
function ct_right () {
|
||||
return {
|
||||
held : ct_wasd_right.held || ct_arrow_right.held,
|
||||
down : ct_wasd_right.down || ct_arrow_right.down,
|
||||
up : ct_wasd_right.up || ct_arrow_right.up
|
||||
}
|
||||
}
|
||||
|
||||
function ct_confirm () {
|
||||
return {
|
||||
held : ct_space.held || ct_z.held,
|
||||
down : ct_space.down || ct_z.down,
|
||||
up : ct_space.up || ct_z.up
|
||||
}
|
||||
}
|
||||
|
||||
function ct_cancel () {
|
||||
return {
|
||||
held : ct_shift.held || ct_x.held,
|
||||
down : ct_shift.down || ct_x.down,
|
||||
up : ct_shift.up || ct_x.up
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
var Game = {};
|
||||
G = Game;
|
||||
|
||||
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.
|
||||
G.currentScreen = ""; // For pause screen, stats screen, inventory screen
|
||||
G.inventory = {
|
||||
money: 100,
|
||||
food: 10,
|
||||
water: 10,
|
||||
cargo: []
|
||||
};
|
||||
G.stats = {
|
||||
inventory: 3, // Maximum number of different things the inventory can hold.
|
||||
hold: 20, // Maximum number of each individual kind of thing in the inventory.
|
||||
speed: 1, // How many pixels you move.
|
||||
hull: 3, // Your HP, pretty much. How many times you can crash without exploding.
|
||||
maxHull: 3, // How much your hull can refill to.
|
||||
popularity: 1, // Haggle success rate in percentage.
|
||||
haggling: 10, // How much you can increase the asking price by.
|
||||
crew: 2, // How many crew members you have. Influences how fast your energy recovers.
|
||||
energy: 25, // Drains rate determined by current speed. When drained, currentSpeed reduces until you have enough energy to continue.
|
||||
maxEnergy: 50, // How much to refill your energy to. Can increase with upgrades.
|
||||
hunger: 0,
|
||||
thirst: 0
|
||||
}
|
||||
|
||||
G.itemSheet = new Image();
|
||||
G.itemSheet.src = "images/items_sheet.png";
|
||||
|
||||
G.economy = { // Aww yea, supply and demand.
|
||||
// Items are determined by their index, and their position on the sheet determines their index.
|
||||
// So the second item on the top row is index 1, and to get its value, you get `G.economy.cargoItemWorth[1]`
|
||||
cargoItemWorth: [10, 20, 30, 30, //Can be adjusted based on sales.
|
||||
40, 20, 50, 80,
|
||||
65, 20, 20, 30,
|
||||
30, 60, 45, 70],
|
||||
cargoSold: [0, 0, 0, 0, // The more you sell, the lower the price gets
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0],
|
||||
cargoBought: [0, 0, 0, 0, // The more you buy, the higher the price gets
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0],
|
||||
CheckEconomy: function () {
|
||||
for (var i = 0; i < this.cargoSold; i++) {
|
||||
var soldBoughtDifference = this.cargoBought[i] - this.cargoSold[i];
|
||||
|
||||
if (Math.abs(soldBoughtDifference) > (this.cargoItemWorth[i] * 0.75)) { // If the difference is greater than 75% of the worth,
|
||||
this.cargoItemWorth[i] += Math.round(soldBoughtDifference * 0.5); // Adjust the worth by half of the difference.
|
||||
|
||||
if (this.cargoItemWorth[i] < 1) {
|
||||
this.cargoItemWorth[i] = 1; // Make worth never drop below 1.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function loadGameManager () {}
|
|
@ -0,0 +1,6 @@
|
|||
function loadPrefabs() {
|
||||
OS.AddScript("prefabs/shipPrefab.js");
|
||||
OS.AddScript("prefabs/islandPrefab.js");
|
||||
OS.AddScript("prefabs/oceanTilePrefab.js");
|
||||
OS.AddScript("prefabs/wavePrefab.js");
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
// var rm_TitleScreen = OS.R.Add("Default");
|
||||
// var rm_Ocean = OS.R.Add("Ocean", {
|
||||
var rm_Ocean = OS.R.Add("Default", {
|
||||
width: (64 * OS.S.pixelScale) * 64, //32 64x64 squares for the map.
|
||||
height: (64 * OS.S.pixelScale) * 64,
|
||||
backgroundColor: "#1b2632"
|
||||
});
|
||||
|
||||
function loadRooms() {
|
||||
// OS.AddScript("rooms/titleScreen.js");
|
||||
OS.AddScript("rooms/oceanRoom.js");
|
||||
|
||||
// OS.SetRoom(rm_TitleScreen);
|
||||
OS.SetRoom(rm_Ocean);
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
var ani_island_1 = OS.A.Add("Island 1", 256, 256, {});
|
||||
|
||||
function islandPrefab() {}
|
||||
|
||||
var pr_island = OS.P.Add("Island", {
|
||||
solid: true,
|
||||
imageSrc: "images/island.png",
|
||||
animations: [ani_island_1],
|
||||
|
||||
mapX: 0,
|
||||
mapY: 0,
|
||||
mapWidth: 1,
|
||||
mapHeight: 1,
|
||||
mapColor: "#00AB00",
|
||||
|
||||
priceDifferences: [],
|
||||
itemsSold: [0, 0, 0, 0, // The more you sell, the lower the price gets
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0],
|
||||
itemsBought: [0, 0, 0, 0, // The more you buy, the higher the price gets
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0],
|
||||
});
|
||||
|
||||
pr_island.DoFirst = function () {
|
||||
this.GetMapPosition();
|
||||
this.SetUpPrices();
|
||||
}
|
||||
|
||||
pr_island.GetMapPosition = function () {
|
||||
this.mapX = (this.x / OS.S.pixelScale) / (OS.camera.width / OS.S.pixelScale);
|
||||
this.mapY = (this.y / OS.S.pixelScale) / (OS.camera.height / OS.S.pixelScale);
|
||||
}
|
||||
|
||||
pr_island.SetUpPrices = function () {
|
||||
for (var i = 0; i < 15; i++) {
|
||||
this.priceDifferences[i] = Math.randomRange(-100, 100);
|
||||
}
|
||||
}
|
||||
|
||||
pr_island.AdjustPrices = function () {
|
||||
for (var i = 0; i < 15; i++) {
|
||||
var saleDifference = this.itemsSold[i] - this.itemsBought[i];
|
||||
if (saleDifference = 0) {
|
||||
this.priceDifferences[i] += Math.round(Math.randomRange(-1, 1)) * 5;
|
||||
} else {
|
||||
this.priceDifferences[i] += saleDifference * 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pr_island.SellTo = function (itemIndex, amount) {
|
||||
this.itemsBought[itemIndex] += amount;
|
||||
}
|
||||
|
||||
pr_island.BuyFrom = function (itemIndex, amount) {
|
||||
this.itemsSold[itemIndex] += amount;
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
var ani_ocean = OS.A.Add("Ocean", 256, 256, {columns: 10, speed: 1/60});
|
||||
|
||||
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,
|
||||
|
||||
moveTimer: 0,
|
||||
});
|
||||
|
||||
pr_ocean.BeforeDo = function () {
|
||||
this.positionCheckProgress++;
|
||||
if (this.positionCheckProgress >= this.positionCheckStep) {
|
||||
this.positionCheckProgress = 0;
|
||||
this.doCheckPosition = true;
|
||||
}
|
||||
}
|
||||
pr_ocean.Do = function () {
|
||||
// Move around randomly.
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
pr_ocean.CheckPosition = function (checkX, checkY, direction) {
|
||||
if (this.doCheckPosition) {
|
||||
// If it's completely off the screen, then update position.
|
||||
if ((Math.abs(this.x - checkX) > (OS.camera.width + this.xBound)) ||
|
||||
(Math.abs(this.y - checkY) > (OS.camera.height + this.yBound)))
|
||||
{
|
||||
switch (direction) {
|
||||
case 0:
|
||||
this.x = checkX + (OS.camera.width + this.xBound) + randomSmidge();
|
||||
this.y = checkY + randomSmidge();
|
||||
break;
|
||||
case 45:
|
||||
this.x = checkX + (OS.camera.width + this.xBound) + randomSmidge();
|
||||
this.y = checkY - (OS.camera.height + this.yBound) + randomSmidge();
|
||||
break;
|
||||
case 90:
|
||||
this.x = checkX + randomSmidge();
|
||||
this.y = checkY - (OS.camera.height + this.yBound) + randomSmidge();
|
||||
break;
|
||||
case 135:
|
||||
this.x = checkX - (OS.camera.width + this.xBound) + randomSmidge();
|
||||
this.y = checkY - (OS.camera.height + this.yBound) + randomSmidge();
|
||||
break;
|
||||
case 180:
|
||||
this.x = checkX - (OS.camera.width + this.xBound) + randomSmidge();
|
||||
this.y = checkY + randomSmidge();
|
||||
break;
|
||||
case 225:
|
||||
this.x = checkX - (OS.camera.width + this.xBound) + randomSmidge();
|
||||
this.y = checkY + (OS.camera.height + this.yBound) + randomSmidge();
|
||||
break;
|
||||
case 270:
|
||||
this.x = checkX + randomSmidge();
|
||||
this.y = checkY + (OS.camera.height + this.yBound) + randomSmidge();
|
||||
break;
|
||||
case 315:
|
||||
this.x = checkX + (OS.camera.width + this.xBound) + randomSmidge();
|
||||
this.y = checkY + (OS.camera.height + this.yBound) + randomSmidge();
|
||||
break;
|
||||
default:
|
||||
console.log("No valid direction");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this.doCheckPosition = false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,163 @@
|
|||
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});
|
||||
var ani_ship_d = OS.A.Add("Ship Down", 64, 64, {columns: 2, speed: 1/60, yOffset: 64 * 0});
|
||||
var ani_ship_dr = OS.A.Add("Ship Down-Right", 64, 64, {columns: 2, speed: 1/60, yOffset: 64 * 2});
|
||||
|
||||
function shipPrefab() {}
|
||||
|
||||
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,
|
||||
currentSpeed: 0,
|
||||
pointInFront : {x: 0, y: 0 },
|
||||
moveStepSize: 3,
|
||||
moveStepAmount: 5 * Oversimplified.R[Oversimplified.R.currentRoom].stepSpeed,
|
||||
moveStepProgress: 0,
|
||||
doTakeStep: false,
|
||||
|
||||
energyRefillTimer: 0
|
||||
});
|
||||
|
||||
pr_ship.Do = function () {
|
||||
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--;
|
||||
}
|
||||
if (this.currentSpeed > 1 && G.stats.maxEnergy / G.stats.energy > this.currentSpeed + G.stats.crew) {
|
||||
this.currentSpeed--;
|
||||
}
|
||||
this.currentSpeed = Math.clamp(this.currentSpeed, 0, 4);
|
||||
|
||||
this.moveStepProgress += this.currentSpeed * this.moveStepAmount;
|
||||
if (this.moveStepProgress >= this.moveStepSize) {
|
||||
this.moveStepProgress -= this.moveStepSize;
|
||||
this.doTakeStep = true;
|
||||
} else {
|
||||
this.doTakeStep = false;
|
||||
}
|
||||
|
||||
this.SeamlessScroll();
|
||||
// console.log(G.player.name + " created at " + G.player.x + ", " + G.player.y);
|
||||
}
|
||||
|
||||
pr_ship.AfterDo = function () {
|
||||
this.CheckMovement();
|
||||
this.UpdateEnergy();
|
||||
}
|
||||
|
||||
pr_ship.CheckInteraction = function () {
|
||||
|
||||
}
|
||||
|
||||
pr_ship.CheckMovement = function () {
|
||||
var moveAmount = (G.stats.speed + this.currentSpeed) * OS.S.pixelScale;
|
||||
var movedSuccessfully = false;
|
||||
switch (this.direction) {
|
||||
case 0:
|
||||
if (this.image.currentAnimation != "Ship Right") this.SetAnimation("Ship Right");
|
||||
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(moveAmount, 0, true, 8);
|
||||
this.pointInFront.x = this.x + this.xBound + (OS.S.pixelScale * 2) + moveAmount;
|
||||
this.pointInFront.y = this.y;
|
||||
break;
|
||||
case 45:
|
||||
if (this.image.currentAnimation != "Ship Up-Right") this.SetAnimation("Ship Up-Right");
|
||||
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(moveAmount, -moveAmount, true, 8);
|
||||
this.pointInFront.x = this.x + this.xBound + (OS.S.pixelScale * 2) + moveAmount;
|
||||
this.pointInFront.y = this.y - this.yBound - (OS.S.pixelScale * 2) - moveAmount;
|
||||
break;
|
||||
case 90:
|
||||
if (this.image.currentAnimation != "Ship Up") this.SetAnimation("Ship Up");
|
||||
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(0, -moveAmount, true, 8);
|
||||
this.pointInFront.x = this.x;
|
||||
this.pointInFront.y = this.y - this.yBound - (OS.S.pixelScale * 2) - moveAmount;
|
||||
break;
|
||||
case 135:
|
||||
if (this.image.currentAnimation != "Ship Up-Left") this.SetAnimation("Ship Up-Left");
|
||||
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(-moveAmount, -moveAmount, true, 8);
|
||||
this.pointInFront.x = this.x - this.xBound - (OS.S.pixelScale * 2) - moveAmount;
|
||||
this.pointInFront.y = this.y - this.yBound - (OS.S.pixelScale * 2) - moveAmount;
|
||||
break;
|
||||
case 180:
|
||||
if (this.image.currentAnimation != "Ship Left") this.SetAnimation("Ship Left");
|
||||
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(-moveAmount, 0, true, 8);
|
||||
this.pointInFront.x = this.x - this.xBound - (OS.S.pixelScale * 2) - moveAmount;
|
||||
this.pointInFront.y = this.y;
|
||||
break;
|
||||
case 225:
|
||||
if (this.image.currentAnimation != "Ship Down-Left") this.SetAnimation("Ship Down-Left");
|
||||
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(-moveAmount, moveAmount, true, 8);
|
||||
this.pointInFront.x = this.x - this.xBound - (OS.S.pixelScale * 2) - moveAmount;
|
||||
this.pointInFront.y = this.y + this.yBound + (OS.S.pixelScale * 2) + moveAmount;
|
||||
break;
|
||||
case 270:
|
||||
if (this.image.currentAnimation != "Ship Down") this.SetAnimation("Ship Down");
|
||||
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(0, moveAmount, true, 8);
|
||||
this.pointInFront.x = this.x;
|
||||
this.pointInFront.y = this.y + this.yBound + (OS.S.pixelScale * 2) + moveAmount;
|
||||
break;
|
||||
case 315:
|
||||
if (this.image.currentAnimation != "Ship Down-Right") this.SetAnimation("Ship Down-Right");
|
||||
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(moveAmount, moveAmount, true, 8);
|
||||
this.pointInFront.x = this.x + this.xBound + (OS.S.pixelScale * 2) + moveAmount;
|
||||
this.pointInFront.y = this.y + this.yBound + (OS.S.pixelScale * 2) + moveAmount;
|
||||
break;
|
||||
default:
|
||||
console.log("No valid direction");
|
||||
break;
|
||||
}
|
||||
|
||||
if (this.doTakeStep && !movedSuccessfully) {
|
||||
this.currentSpeed = 0;
|
||||
}
|
||||
}
|
||||
|
||||
pr_ship.UpdateEnergy = function () {
|
||||
this.energyRefillTimer++;
|
||||
|
||||
if (this.doTakeStep) {
|
||||
G.stats.energy -= ((this.currentSpeed / G.stats.speed) + ((G.stats.hunger + G.stats.thirst) * 0.1)) * 0.25;
|
||||
|
||||
if (this.energyRefillTimer >= (100 / G.stats.crew) + ((G.stats.hunger + G.stats.thirst) * 10)) {
|
||||
G.stats.energy += G.stats.crew;
|
||||
this.energyRefillTimer = 0;
|
||||
}
|
||||
|
||||
if (G.stats.energy < 0) G.stats.energy = 0;
|
||||
if (G.stats.energy > G.stats.maxEnergy) G.stats.energy = G.stats.maxEnergy;
|
||||
}
|
||||
}
|
||||
|
||||
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});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
function oceanRoom () {
|
||||
// Create objects on room creation for persistence.
|
||||
G.player = rm_Ocean.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;
|
||||
console.log(G.player.name + " created at " + G.player.x + ", " + G.player.y);
|
||||
G.oceanParticle = rm_Ocean.AddObject(OS.P["Ocean Particle"]);
|
||||
G.oceanParticle.x = G.player.x + randomSmidge();
|
||||
G.oceanParticle.y = G.player.y + randomSmidge();
|
||||
|
||||
// When room is loaded, explicitly set room to rm_Ocean, just in case "Default" doesn't work/is loaded too slowly
|
||||
// to make sure DoFirst runs.
|
||||
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";
|
||||
|
||||
var island1 = rm_Ocean.AddObject(OS.P["Island"]);
|
||||
island1.x = (((rm_Ocean.width / OS.S.pixelScale) / 2) + 64) * OS.S.pixelScale;
|
||||
island1.y = ((rm_Ocean.height / OS.S.pixelScale) / 2) * OS.S.pixelScale;
|
||||
|
||||
rm_Ocean.DoFirst = function () {
|
||||
// Reset camera whenever room starts
|
||||
OS.SetCamera({
|
||||
x: G.player.x - (OS.camera.width / 2),
|
||||
y: G.player.y - (OS.camera.height / 2),
|
||||
objectToFollow: G.player
|
||||
});
|
||||
|
||||
this.mapLeftTrigger = OS.camera.hBorder;
|
||||
this.mapLeftTriggerTarget = this.width - (OS.camera.width - OS.camera.hBorder);
|
||||
this.mapRightTrigger = this.width - OS.camera.hBorder;
|
||||
this.mapRightTriggerTarget = OS.camera.width - OS.camera.hBorder;
|
||||
this.mapUpTrigger = OS.camera.vBorder;
|
||||
this.mapUpTriggerTarget = this.height - (OS.camera.height - OS.camera.vBorder);
|
||||
this.mapDownTrigger = this.height - OS.camera.vBorder;
|
||||
this.mapDownTriggerTarget = OS.camera.height - OS.camera.vBorder;
|
||||
}
|
||||
rm_Ocean.Do = function () {
|
||||
// Move G.oceanParticle around based on player's movement.
|
||||
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 () {
|
||||
// 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);
|
||||
|
||||
// Draw Energy Bar
|
||||
this.DrawEnergyBar();
|
||||
|
||||
// drawPixelText("Testing 1 2 3!", 0, 0, 0, "white", 4);
|
||||
// drawPixelText("Testing 1 2 3!", 0, 64, 0, "white", 6);
|
||||
}
|
||||
|
||||
rm_Ocean.DoLast = function () {
|
||||
// Clear Objects on room exit. This is best practice unless you need persistent objects.
|
||||
//rm_Ocean.objects = {};
|
||||
}
|
||||
|
||||
rm_Ocean.DrawEnergyBar = function () {
|
||||
var percentage = G.stats.energy / G.stats.maxEnergy;
|
||||
var barHeight = 2 * OS.S.pixelScale;
|
||||
var maxBarWidth = 32;
|
||||
var barWidth = Math.round(maxBarWidth * percentage) * OS.S.pixelScale;
|
||||
|
||||
var saveFillStyle = OS.context.fillStyle;
|
||||
OS.context.fillStyle = "#0055FF";
|
||||
OS.context.fillRect(64, OS.camera.height - barHeight - 16, barWidth, barHeight);
|
||||
OS.context.fillStyle = saveFillStyle;
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
function titleScreen () {
|
||||
// When room is loaded, explicitly set room to rm_TitleScreen, just in case "Default" doesn't work/is loaded too slowly
|
||||
OS.SetRoom(rm_TitleScreen);
|
||||
}
|
||||
|
||||
rm_TitleScreen.DoFirst = function () {
|
||||
//Hide cursor when playing (only use if masking the cursor with another object)
|
||||
//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"]);
|
||||
}
|
||||
}
|
||||
rm_TitleScreen.Do = function () {
|
||||
if (Game.cowboys <= 0) {
|
||||
OS.SetRoom(rm_TitleScreen);
|
||||
}
|
||||
}
|
||||
rm_TitleScreen.DrawAbove = function () {
|
||||
// Draw the number of cowboys remaining
|
||||
if (Game.ball !== null) {
|
||||
OS.context.font = "18px Impact";
|
||||
OS.context.fillText(Game.cowboys, 15, 30);
|
||||
}
|
||||
}
|
||||
rm_TitleScreen.DoLast = function () {
|
||||
// Clear Objects on room exit. This is best practice unless you need persistent objects.
|
||||
rm_TitleScreen.objects = {};
|
||||
}
|
|
@ -0,0 +1,220 @@
|
|||
OS.S.defaultStep = 1 / 120;
|
||||
OS.S.pixelScale = 4;
|
||||
OS.SetCamera({
|
||||
width: 64 * OS.S.pixelScale,
|
||||
height: 64 * OS.S.pixelScale,
|
||||
hBorder: 24 * OS.S.pixelScale,
|
||||
vBorder: 24 * OS.S.pixelScale
|
||||
});
|
||||
|
||||
function start()
|
||||
{
|
||||
OS.AddScript("loadControls.js");
|
||||
OS.AddScript("loadGameManager.js");
|
||||
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);
|
||||
}
|
||||
|
||||
function drawPixelText(text, x, y, wrapWidth, color, size) {
|
||||
// Draw the text at the given x and y on the canvas using the alphabet images.
|
||||
// Remember to set the pixel scale for x and y when you call the function!
|
||||
// 4x4 font modified from http://pixeljoint.com/forum/forum_posts.asp?TID=18755&PID=185995#185995
|
||||
// 5x6 font modified from http://atariage.com/forums/topic/165697-fonts/page-4#entry2081600
|
||||
text = text.toString().toUpperCase();
|
||||
|
||||
var letterSizeX = ((size == 6) ? size - 1 : size) * OS.S.pixelScale;
|
||||
var letterSizeY = size * OS.S.pixelScale;
|
||||
var maxWrapWidth = Math.floor(OS.camera.width / (letterSizeX + OS.S.pixelScale));
|
||||
|
||||
wrapWidth = (wrapWidth <= 0 || wrapWidth > maxWrapWidth) ? maxWrapWidth : wrapWidth;
|
||||
|
||||
var alphabet = new Image();
|
||||
alphabet.src = "images/alphabet_" + color + "_" + size.toString() + "px.png";
|
||||
|
||||
for (var i = 0; i < text.length; i++) {
|
||||
var letterCellX, letterCellY;
|
||||
switch (text.charAt(i)) {
|
||||
case "A":
|
||||
letterCellX = 0;
|
||||
letterCellY = 0;
|
||||
break;
|
||||
case "B":
|
||||
letterCellX = 1;
|
||||
letterCellY = 0;
|
||||
break;
|
||||
case "C":
|
||||
letterCellX = 2;
|
||||
letterCellY = 0;
|
||||
break;
|
||||
case "D":
|
||||
letterCellX = 3;
|
||||
letterCellY = 0;
|
||||
break;
|
||||
case "E":
|
||||
letterCellX = 4;
|
||||
letterCellY = 0;
|
||||
break;
|
||||
case "F":
|
||||
letterCellX = 5;
|
||||
letterCellY = 0;
|
||||
break;
|
||||
case "G":
|
||||
letterCellX = 0;
|
||||
letterCellY = 1;
|
||||
break;
|
||||
case "H":
|
||||
letterCellX = 1;
|
||||
letterCellY = 1;
|
||||
break;
|
||||
case "I":
|
||||
letterCellX = 2;
|
||||
letterCellY = 1;
|
||||
break;
|
||||
case "J":
|
||||
letterCellX = 3;
|
||||
letterCellY = 1;
|
||||
break;
|
||||
case "K":
|
||||
letterCellX = 4;
|
||||
letterCellY = 1;
|
||||
break;
|
||||
case "L":
|
||||
letterCellX = 5;
|
||||
letterCellY = 1;
|
||||
break;
|
||||
case "M":
|
||||
letterCellX = 0;
|
||||
letterCellY = 2;
|
||||
break;
|
||||
case "N":
|
||||
letterCellX = 1;
|
||||
letterCellY = 2;
|
||||
break;
|
||||
case "O":
|
||||
letterCellX = 2;
|
||||
letterCellY = 2;
|
||||
break;
|
||||
case "P":
|
||||
letterCellX = 3;
|
||||
letterCellY = 2;
|
||||
break;
|
||||
case "Q":
|
||||
letterCellX = 4;
|
||||
letterCellY = 2;
|
||||
break;
|
||||
case "R":
|
||||
letterCellX = 5;
|
||||
letterCellY = 2;
|
||||
break;
|
||||
case "S":
|
||||
letterCellX = 0;
|
||||
letterCellY = 3;
|
||||
break;
|
||||
case "T":
|
||||
letterCellX = 1;
|
||||
letterCellY = 3;
|
||||
break;
|
||||
case "U":
|
||||
letterCellX = 2;
|
||||
letterCellY = 3;
|
||||
break;
|
||||
case "V":
|
||||
letterCellX = 3;
|
||||
letterCellY = 3;
|
||||
break;
|
||||
case "W":
|
||||
letterCellX = 4;
|
||||
letterCellY = 3;
|
||||
break;
|
||||
case "X":
|
||||
letterCellX = 5;
|
||||
letterCellY = 3;
|
||||
break;
|
||||
case "Y":
|
||||
letterCellX = 0;
|
||||
letterCellY = 4;
|
||||
break;
|
||||
case "Z":
|
||||
letterCellX = 1;
|
||||
letterCellY = 4;
|
||||
break;
|
||||
case "1":
|
||||
letterCellX = 2;
|
||||
letterCellY = 4;
|
||||
break;
|
||||
case "2":
|
||||
letterCellX = 3;
|
||||
letterCellY = 4;
|
||||
break;
|
||||
case "3":
|
||||
letterCellX = 4;
|
||||
letterCellY = 4;
|
||||
break;
|
||||
case "4":
|
||||
letterCellX = 5;
|
||||
letterCellY = 4;
|
||||
break;
|
||||
case "5":
|
||||
letterCellX = 0;
|
||||
letterCellY = 5;
|
||||
break;
|
||||
case "6":
|
||||
letterCellX = 1;
|
||||
letterCellY = 5;
|
||||
break;
|
||||
case "7":
|
||||
letterCellX = 2;
|
||||
letterCellY = 5;
|
||||
break;
|
||||
case "8":
|
||||
letterCellX = 3;
|
||||
letterCellY = 5;
|
||||
break;
|
||||
case "9":
|
||||
letterCellX = 4;
|
||||
letterCellY = 5;
|
||||
break;
|
||||
case "0":
|
||||
letterCellX = 5;
|
||||
letterCellY = 5;
|
||||
break;
|
||||
case ".":
|
||||
letterCellX = 0;
|
||||
letterCellY = 6;
|
||||
break;
|
||||
case ",":
|
||||
letterCellX = 1;
|
||||
letterCellY = 6;
|
||||
break;
|
||||
case "-":
|
||||
letterCellX = 2;
|
||||
letterCellY = 6;
|
||||
break;
|
||||
case "?":
|
||||
letterCellX = 3;
|
||||
letterCellY = 6;
|
||||
break;
|
||||
case "!":
|
||||
letterCellX = 4;
|
||||
letterCellY = 6;
|
||||
break;
|
||||
default: // Default to Space
|
||||
letterCellX = 5;
|
||||
letterCellY = 6;
|
||||
break;
|
||||
}
|
||||
|
||||
var lineNumber = Math.floor(i/wrapWidth);
|
||||
var horizontal = i - (wrapWidth * lineNumber);
|
||||
var letterSheetX = letterSizeX * letterCellX;
|
||||
var letterSheetY = letterSizeY * letterCellY;
|
||||
var letterX = x + (letterSizeX * horizontal) + (OS.S.pixelScale * horizontal); //Places a space between characters horizontally
|
||||
var letterY = y + (letterSizeY * lineNumber) + (OS.S.pixelScale * lineNumber); //Places a space between characters vertically
|
||||
OS.context.drawImage(alphabet, letterSheetX, letterSheetY, letterSizeX, letterSizeY, letterX, letterY, letterSizeX, letterSizeY);
|
||||
}
|
||||
}
|