/****
* Classes
****/
// FishingLine class to represent the fishing line
var Fish = Container.expand(function () {
var self = Container.call(this);
var fishGraphics = self.attachAsset('fish', {
anchorX: 0.5,
anchorY: 0.5
});
// Define the direction variable
var direction = Math.random() > 0.5 ? 1 : -1;
// Flip the fish image horizontally if it's moving to the left
if (direction == -1) {
fishGraphics.scale.x *= -1;
}
// Initialize lastIntersecting state
self.lastIntersecting = false;
self.update = function () {
// If the fish hits the edge of the screen, change direction
if (self.x <= 0 || self.x >= 2048 - fishGraphics.width) {
direction *= -1;
// Flip the fish image horizontally when it changes direction
fishGraphics.scale.x *= -1;
}
self.x += 5 * direction; // Move the fish horizontally by 5 pixels per frame in the chosen direction
if (!self.stuckToHook) {
self.y -= 4; // Move the fish up along with the backgrounds
} else {
self.x = game.fisherman.fishingLine.x; // Stick to the hook's x position
self.y = game.fisherman.fishingLine.y + game.fisherman.fishingLine.height; // Stick to the hook's y position
}
};
});
var Fisherman = Container.expand(function () {
var self = Container.call(this);
// Attach fisherman asset
var fishermanGraphics = self.attachAsset('fisherman', {
anchorX: 0.5,
anchorY: 0.5
});
// Method to cast the fishing line
self.castLine = function () {
self.fishingLine = new FishingLine();
self.fishingLine.x = self.x;
self.fishingLine.y = self.y;
game.addChild(self.fishingLine);
};
});
var FishingLine = Container.expand(function () {
var self = Container.call(this);
// Attach fishing line asset
var lineGraphics = self.attachAsset('fishingLine', {
anchorX: 0.5,
anchorY: 0.0
});
// Update method to move the line downwards
self.update = function () {
self.y += 5; // Move the line down by 5 pixels per frame
// Stop the line just above the bottom of the screen
if (self.y >= 2100 - lineGraphics.height) {
self.y = 2100 - lineGraphics.height;
// Start moving the backgrounds once the fishing line has stopped moving
game.startBackgroundMovement = true;
}
// Check for collision with fish
game.children.forEach(function (child) {
if (child instanceof Fish && !child.lastIntersecting && self.intersects(child)) {
// Fish gets stuck to the base of the fishing hook and tilts 90 degrees upward
child.x = self.x;
child.y = self.y + lineGraphics.height;
child.rotation = Math.PI / 2; // Tilt the fish 90 degrees upward
child.stuckToHook = true; // Mark the fish as stuck to the hook
// Increase score when a fish is caught
score += 1;
updateScoreDisplay();
// Update lastIntersecting state
child.lastIntersecting = true;
}
});
};
});
var Shark = Container.expand(function () {
var self = Container.call(this);
var sharkGraphics = self.attachAsset('shark', {
anchorX: 0.5,
anchorY: 0.5
});
// Initialize lastIntersecting state
self.lastIntersecting = false;
self.update = function () {
// Move the shark horizontally
// Define the direction variable for shark movement
if (self.direction === undefined) {
self.direction = Math.random() > 0.5 ? 1 : -1;
}
// Move the shark horizontally based on its direction
self.x += 5 * self.direction;
// Flip the shark image horizontally if it's moving to the right
if (self.direction === 1) {
sharkGraphics.scale.x = Math.abs(sharkGraphics.scale.x);
} else {
sharkGraphics.scale.x = -Math.abs(sharkGraphics.scale.x);
}
// If the shark hits the edge of the screen, change direction
if (self.x <= 0 || self.x >= 2048 - sharkGraphics.width) {
self.direction *= -1;
}
self.y -= 4; // Move the shark up along with the backgrounds
// Check if the shark's mouth touches the hook
if (!self.lastIntersecting && self.intersects(game.fisherman.fishingLine)) {
self.lastIntersecting = true;
// If the score is zero, end the game
if (score === 0) {
LK.showGameOver();
} else {
// Eat all the fish on the hook
game.children.forEach(function (child) {
if (child instanceof Fish && child.stuckToHook) {
child.destroy();
}
});
// Reset the score to zero
score = 0;
updateScoreDisplay();
}
}
// Reset shark position if it goes off screen
if (self.x > 2048) {
self.x = -200;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize score display
var scoreTxt = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(1, 0); // Anchor to the top-right corner
LK.gui.topRight.addChild(scoreTxt);
// Initialize score variable
var score = 0;
// Function to update score display
function updateScoreDisplay() {
scoreTxt.setText(score);
}
game.move = function (x, y, obj) {
// Move the fishing line horizontally based on player finger position
// Smoothly move the fishing line horizontally based on player finger position
game.fisherman.fishingLine.x += (x - game.fisherman.fishingLine.x) * 0.1;
};
game.camera = {
x: 0,
y: 0
};
// Flag to control when the background should start moving
game.startBackgroundMovement = false;
// Update method to move backgrounds up and loop using the second background
game.update = function () {
if (game.startBackgroundMovement) {
// Add shark to the game if not already added
if (!game.shark) {
game.shark = new Shark();
game.shark.x = -200; // Start off-screen
game.shark.y = 150; // Position near the top
game.addChild(game.shark);
}
if (LK.ticks % 180 == 0) {
var fish = new Fish();
fish.x = Math.random() * 2048; // Spawn the fish at a random x position
fish.y = 2732; // Spawn the fish out of view
game.addChild(fish);
// Spawn shark in the same way as fish
var shark = new Shark();
shark.x = Math.random() * 2048; // Spawn the shark at a random x position
shark.y = 2732; // Spawn the shark out of view
game.addChild(shark);
}
// Rest of the code...
}
if (game.startBackgroundMovement) {
// Move all backgrounds up
game.background.y -= 4;
game.background2.y -= 4;
game.background3.y -= 4;
game.background4.y -= 4;
game.background5.y -= 4;
// Move the fisherman up
game.fisherman.y -= 4;
// Check if the second background is partially in view
if (game.background2.y <= -380) {
// Reset the second background to be below the previous background2
game.background2.y = game.background5.y + 832;
}
if (game.background3.y <= -380) {
// Reset the fourth background to be below the third background
game.background3.y = game.background2.y + 832;
}
if (game.background4.y <= -380) {
// Reset the fifth background to be below the fourth background
game.background4.y = game.background3.y + 832;
//game.background5.y = game.background4.y + 832;
}
if (game.background5.y <= -380) {
// Reset the fifth background to be below the fourth background
game.background5.y = game.background4.y + 832;
}
}
};
// Initialize the background position
var backgroundGraphics = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5
});
backgroundGraphics.x = 1024; // Center horizontally
backgroundGraphics.y = 1366; // Center vertically
game.addChild(backgroundGraphics);
game.background = backgroundGraphics;
// Initialize the second background position
var backgroundGraphics2 = LK.getAsset('background2', {
anchorX: 0.5,
anchorY: 0.5
});
backgroundGraphics2.x = 1024; // Center horizontally
backgroundGraphics2.y = 1366 + 1440; // Position below the first background
game.addChild(backgroundGraphics2);
game.background2 = backgroundGraphics2;
// Initialize the third background position
var backgroundGraphics3 = LK.getAsset('background3', {
anchorX: 0.5,
anchorY: 0.5
});
backgroundGraphics3.x = 1024; // Center horizontally
backgroundGraphics3.y = 1366 + 1440 + 832; // Position below the second background
game.addChild(backgroundGraphics3);
game.background3 = backgroundGraphics3;
// Initialize the fourth background position
var backgroundGraphics4 = LK.getAsset('background4', {
anchorX: 0.5,
anchorY: 0.5
});
backgroundGraphics4.x = 1024; // Center horizontally
backgroundGraphics4.y = 1366 + 1440 + 832 + 832; // Position below the third background
game.addChild(backgroundGraphics4);
game.background4 = backgroundGraphics4;
// Initialize the fifth background position
var backgroundGraphics5 = LK.getAsset('background5', {
anchorX: 0.5,
anchorY: 0.5
});
backgroundGraphics5.x = 1024; // Center horizontally
backgroundGraphics5.y = 1366 + 1440 + 832 + 832 + 832; // Position below the fourth background
game.addChild(backgroundGraphics5);
game.background5 = backgroundGraphics5;
// Initialize the fisherman and add to the game
game.fisherman = new Fisherman();
game.fisherman.x = 900; // Center horizontally
game.fisherman.y = 200; // Position near the top
game.addChild(game.fisherman);
// Cast the fishing line at the start of the game
game.fisherman.castLine();
; /****
* Classes
****/
// FishingLine class to represent the fishing line
var Fish = Container.expand(function () {
var self = Container.call(this);
var fishGraphics = self.attachAsset('fish', {
anchorX: 0.5,
anchorY: 0.5
});
// Define the direction variable
var direction = Math.random() > 0.5 ? 1 : -1;
// Flip the fish image horizontally if it's moving to the left
if (direction == -1) {
fishGraphics.scale.x *= -1;
}
// Initialize lastIntersecting state
self.lastIntersecting = false;
self.update = function () {
// If the fish hits the edge of the screen, change direction
if (self.x <= 0 || self.x >= 2048 - fishGraphics.width) {
direction *= -1;
// Flip the fish image horizontally when it changes direction
fishGraphics.scale.x *= -1;
}
self.x += 5 * direction; // Move the fish horizontally by 5 pixels per frame in the chosen direction
if (!self.stuckToHook) {
self.y -= 4; // Move the fish up along with the backgrounds
} else {
self.x = game.fisherman.fishingLine.x; // Stick to the hook's x position
self.y = game.fisherman.fishingLine.y + game.fisherman.fishingLine.height; // Stick to the hook's y position
}
};
});
var Fisherman = Container.expand(function () {
var self = Container.call(this);
// Attach fisherman asset
var fishermanGraphics = self.attachAsset('fisherman', {
anchorX: 0.5,
anchorY: 0.5
});
// Method to cast the fishing line
self.castLine = function () {
self.fishingLine = new FishingLine();
self.fishingLine.x = self.x;
self.fishingLine.y = self.y;
game.addChild(self.fishingLine);
};
});
var FishingLine = Container.expand(function () {
var self = Container.call(this);
// Attach fishing line asset
var lineGraphics = self.attachAsset('fishingLine', {
anchorX: 0.5,
anchorY: 0.0
});
// Update method to move the line downwards
self.update = function () {
self.y += 5; // Move the line down by 5 pixels per frame
// Stop the line just above the bottom of the screen
if (self.y >= 2100 - lineGraphics.height) {
self.y = 2100 - lineGraphics.height;
// Start moving the backgrounds once the fishing line has stopped moving
game.startBackgroundMovement = true;
}
// Check for collision with fish
game.children.forEach(function (child) {
if (child instanceof Fish && !child.lastIntersecting && self.intersects(child)) {
// Fish gets stuck to the base of the fishing hook and tilts 90 degrees upward
child.x = self.x;
child.y = self.y + lineGraphics.height;
child.rotation = Math.PI / 2; // Tilt the fish 90 degrees upward
child.stuckToHook = true; // Mark the fish as stuck to the hook
// Increase score when a fish is caught
score += 1;
updateScoreDisplay();
// Update lastIntersecting state
child.lastIntersecting = true;
}
});
};
});
var Shark = Container.expand(function () {
var self = Container.call(this);
var sharkGraphics = self.attachAsset('shark', {
anchorX: 0.5,
anchorY: 0.5
});
// Initialize lastIntersecting state
self.lastIntersecting = false;
self.update = function () {
// Move the shark horizontally
// Define the direction variable for shark movement
if (self.direction === undefined) {
self.direction = Math.random() > 0.5 ? 1 : -1;
}
// Move the shark horizontally based on its direction
self.x += 5 * self.direction;
// Flip the shark image horizontally if it's moving to the right
if (self.direction === 1) {
sharkGraphics.scale.x = Math.abs(sharkGraphics.scale.x);
} else {
sharkGraphics.scale.x = -Math.abs(sharkGraphics.scale.x);
}
// If the shark hits the edge of the screen, change direction
if (self.x <= 0 || self.x >= 2048 - sharkGraphics.width) {
self.direction *= -1;
}
self.y -= 4; // Move the shark up along with the backgrounds
// Check if the shark's mouth touches the hook
if (!self.lastIntersecting && self.intersects(game.fisherman.fishingLine)) {
self.lastIntersecting = true;
// If the score is zero, end the game
if (score === 0) {
LK.showGameOver();
} else {
// Eat all the fish on the hook
game.children.forEach(function (child) {
if (child instanceof Fish && child.stuckToHook) {
child.destroy();
}
});
// Reset the score to zero
score = 0;
updateScoreDisplay();
}
}
// Reset shark position if it goes off screen
if (self.x > 2048) {
self.x = -200;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize score display
var scoreTxt = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(1, 0); // Anchor to the top-right corner
LK.gui.topRight.addChild(scoreTxt);
// Initialize score variable
var score = 0;
// Function to update score display
function updateScoreDisplay() {
scoreTxt.setText(score);
}
game.move = function (x, y, obj) {
// Move the fishing line horizontally based on player finger position
// Smoothly move the fishing line horizontally based on player finger position
game.fisherman.fishingLine.x += (x - game.fisherman.fishingLine.x) * 0.1;
};
game.camera = {
x: 0,
y: 0
};
// Flag to control when the background should start moving
game.startBackgroundMovement = false;
// Update method to move backgrounds up and loop using the second background
game.update = function () {
if (game.startBackgroundMovement) {
// Add shark to the game if not already added
if (!game.shark) {
game.shark = new Shark();
game.shark.x = -200; // Start off-screen
game.shark.y = 150; // Position near the top
game.addChild(game.shark);
}
if (LK.ticks % 180 == 0) {
var fish = new Fish();
fish.x = Math.random() * 2048; // Spawn the fish at a random x position
fish.y = 2732; // Spawn the fish out of view
game.addChild(fish);
// Spawn shark in the same way as fish
var shark = new Shark();
shark.x = Math.random() * 2048; // Spawn the shark at a random x position
shark.y = 2732; // Spawn the shark out of view
game.addChild(shark);
}
// Rest of the code...
}
if (game.startBackgroundMovement) {
// Move all backgrounds up
game.background.y -= 4;
game.background2.y -= 4;
game.background3.y -= 4;
game.background4.y -= 4;
game.background5.y -= 4;
// Move the fisherman up
game.fisherman.y -= 4;
// Check if the second background is partially in view
if (game.background2.y <= -380) {
// Reset the second background to be below the previous background2
game.background2.y = game.background5.y + 832;
}
if (game.background3.y <= -380) {
// Reset the fourth background to be below the third background
game.background3.y = game.background2.y + 832;
}
if (game.background4.y <= -380) {
// Reset the fifth background to be below the fourth background
game.background4.y = game.background3.y + 832;
//game.background5.y = game.background4.y + 832;
}
if (game.background5.y <= -380) {
// Reset the fifth background to be below the fourth background
game.background5.y = game.background4.y + 832;
}
}
};
// Initialize the background position
var backgroundGraphics = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5
});
backgroundGraphics.x = 1024; // Center horizontally
backgroundGraphics.y = 1366; // Center vertically
game.addChild(backgroundGraphics);
game.background = backgroundGraphics;
// Initialize the second background position
var backgroundGraphics2 = LK.getAsset('background2', {
anchorX: 0.5,
anchorY: 0.5
});
backgroundGraphics2.x = 1024; // Center horizontally
backgroundGraphics2.y = 1366 + 1440; // Position below the first background
game.addChild(backgroundGraphics2);
game.background2 = backgroundGraphics2;
// Initialize the third background position
var backgroundGraphics3 = LK.getAsset('background3', {
anchorX: 0.5,
anchorY: 0.5
});
backgroundGraphics3.x = 1024; // Center horizontally
backgroundGraphics3.y = 1366 + 1440 + 832; // Position below the second background
game.addChild(backgroundGraphics3);
game.background3 = backgroundGraphics3;
// Initialize the fourth background position
var backgroundGraphics4 = LK.getAsset('background4', {
anchorX: 0.5,
anchorY: 0.5
});
backgroundGraphics4.x = 1024; // Center horizontally
backgroundGraphics4.y = 1366 + 1440 + 832 + 832; // Position below the third background
game.addChild(backgroundGraphics4);
game.background4 = backgroundGraphics4;
// Initialize the fifth background position
var backgroundGraphics5 = LK.getAsset('background5', {
anchorX: 0.5,
anchorY: 0.5
});
backgroundGraphics5.x = 1024; // Center horizontally
backgroundGraphics5.y = 1366 + 1440 + 832 + 832 + 832; // Position below the fourth background
game.addChild(backgroundGraphics5);
game.background5 = backgroundGraphics5;
// Initialize the fisherman and add to the game
game.fisherman = new Fisherman();
game.fisherman.x = 900; // Center horizontally
game.fisherman.y = 200; // Position near the top
game.addChild(game.fisherman);
// Cast the fishing line at the start of the game
game.fisherman.castLine();
;
Fish. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Fishing hook. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Shark. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Man fishing on boat. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows