/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Boat = Container.expand(function () {
var self = Container.call(this);
self.boatGraphics = self.attachAsset('boat', {
anchorX: 0.5,
anchorY: 0.5
});
self.hookContainer = new Container();
self.addChild(self.hookContainer);
self.hookContainer.x = 0;
self.hookContainer.y = 40;
var hookGraphics = self.hookContainer.attachAsset('hook', {
anchorX: 0.5,
anchorY: 0
});
self.hookDeployed = false;
self.hookExtension = 0;
self.maxHookExtension = 200;
self.hookSpeed = 8;
self.moveLeft = function () {
if (self.x > 60) {
self.x -= 15;
}
};
self.moveRight = function () {
if (self.x < 1988) {
self.x += 15;
}
};
self.deployHook = function () {
if (!self.hookDeployed) {
self.hookDeployed = true;
}
};
self.update = function () {
if (self.hookDeployed) {
self.hookExtension += self.hookSpeed;
if (self.hookExtension >= self.maxHookExtension) {
self.hookExtension = self.maxHookExtension;
}
} else {
if (self.hookExtension > 0) {
self.hookExtension -= self.hookSpeed;
if (self.hookExtension < 0) {
self.hookExtension = 0;
}
}
}
self.hookContainer.y = 40 + self.hookExtension;
};
return self;
});
var Fish = Container.expand(function () {
var self = Container.call(this);
self.fishGraphics = self.attachAsset('fish', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.direction = 1;
self.update = function () {
self.y += self.speed;
self.x += self.direction * 1.5;
if (self.x < 0 || self.x > 2048) {
self.direction *= -1;
}
};
return self;
});
var Jellyfish = Container.expand(function () {
var self = Container.call(this);
self.jellyfishGraphics = self.attachAsset('jellyfish', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.wobbleAmount = 0;
self.wobblePhase = 0;
self.update = function () {
self.y += self.speed;
self.wobblePhase += 0.05;
self.x += Math.sin(self.wobblePhase) * 2;
};
return self;
});
var Shark = Container.expand(function () {
var self = Container.call(this);
self.sharkGraphics = self.attachAsset('shark', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.direction = 1;
self.huntProgress = 0;
self.update = function () {
self.y += self.speed;
self.x += self.direction * (2 + difficultyLevel * 0.5);
if (self.x < 0 || self.x > 2048) {
self.direction *= -1;
}
};
return self;
});
var Trash = Container.expand(function () {
var self = Container.call(this);
self.trashType = 'bottle';
self.points = 10;
self.speed = 3;
self.setTrashType = function (type) {
self.trashType = type;
var trashGraphics = self.attachAsset(type, {
anchorX: 0.5,
anchorY: 0.5
});
if (type === 'bottle') {
self.points = 10;
} else if (type === 'bag') {
self.points = 20;
} else if (type === 'can') {
self.points = 30;
} else if (type === 'plastic') {
self.points = 15;
}
};
self.update = function () {
self.y += self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1E90FF
});
/****
* Game Code
****/
var difficultyLevel = 1;
var score = 0;
var lives = 3;
var trashCollected = 0;
var gameTime = 0;
var targetTrash = 20;
var spawnRate = 100;
var lastSpawnTick = 0;
var boat = new Boat();
game.addChild(boat);
boat.x = 1024;
boat.y = 2500;
var trashArray = [];
var fishArray = [];
var sharkArray = [];
var jellyfishArray = [];
var scoreText = new Text2('Score: 0', {
size: 100,
fill: '#FFFFFF'
});
scoreText.anchor.set(0, 0);
LK.gui.topRight.addChild(scoreText);
var livesText = new Text2('Lives: 3', {
size: 100,
fill: '#FF6347'
});
livesText.anchor.set(0, 0);
LK.gui.top.addChild(livesText);
var trashText = new Text2('Trash: 0/' + targetTrash, {
size: 100,
fill: '#FFFFFF'
});
trashText.anchor.set(0.5, 0);
LK.gui.top.addChild(trashText);
function updateUI() {
scoreText.setText('Score: ' + score);
livesText.setText('Lives: ' + lives);
trashText.setText('Trash: ' + trashCollected + '/' + targetTrash);
}
function spawnTrash() {
var trashTypes = ['bottle', 'bag', 'can', 'plastic'];
var randomType = trashTypes[Math.floor(Math.random() * trashTypes.length)];
var trash = new Trash();
trash.setTrashType(randomType);
trash.x = Math.random() * 2048;
trash.y = -50;
trash.speed = 2 + difficultyLevel * 0.3;
game.addChild(trash);
trashArray.push(trash);
}
function spawnFish() {
var fish = new Fish();
fish.x = Math.random() * 2048;
fish.y = Math.random() * 1500 + 300;
fish.speed = 1.5 + difficultyLevel * 0.2;
game.addChild(fish);
fishArray.push(fish);
}
function spawnShark() {
var shark = new Shark();
shark.x = Math.random() * 2048;
shark.y = Math.random() * 1000 + 800;
shark.speed = 2.5 + difficultyLevel * 0.4;
game.addChild(shark);
sharkArray.push(shark);
}
function spawnJellyfish() {
var jellyfish = new Jellyfish();
jellyfish.x = Math.random() * 2048;
jellyfish.y = -50;
jellyfish.speed = 2 + difficultyLevel * 0.2;
game.addChild(jellyfish);
jellyfishArray.push(jellyfish);
}
function increaseDifficulty() {
if (difficultyLevel < 5) {
difficultyLevel += 0.5;
spawnRate = Math.max(50, 100 - difficultyLevel * 10);
}
}
game.move = function (x, y, obj) {
boat.x = x;
if (boat.x < 60) {
boat.x = 60;
}
if (boat.x > 1988) {
boat.x = 1988;
}
};
game.down = function (x, y, obj) {
boat.deployHook();
};
game.up = function (x, y, obj) {
boat.hookDeployed = false;
};
game.update = function () {
gameTime += 1;
boat.update();
if (gameTime % 30 === 0) {
increaseDifficulty();
}
if (gameTime % spawnRate === 0) {
spawnTrash();
}
if (gameTime % 200 === 0) {
spawnFish();
}
if (gameTime % 250 === 0 && difficultyLevel > 1) {
spawnShark();
}
if (gameTime % 300 === 0 && difficultyLevel > 2) {
spawnJellyfish();
}
var hookGlobalPos = boat.toGlobal(boat.hookContainer.position);
var hookCheckRadius = 50;
for (var i = trashArray.length - 1; i >= 0; i--) {
var trash = trashArray[i];
trash.update();
var distance = Math.sqrt(Math.pow(hookGlobalPos.x - trash.x, 2) + Math.pow(hookGlobalPos.y - trash.y, 2));
if (boat.hookDeployed && distance < hookCheckRadius) {
score += trash.points;
trashCollected += 1;
trash.destroy();
trashArray.splice(i, 1);
LK.getSound('catch').play();
if (trashCollected >= targetTrash) {
LK.showYouWin();
}
} else if (trash.y > 2732) {
trash.destroy();
trashArray.splice(i, 1);
}
}
for (var i = fishArray.length - 1; i >= 0; i--) {
var fish = fishArray[i];
fish.update();
var hookGlobalPos = boat.toGlobal(boat.hookContainer.position);
var hookCheckRadius = 50;
var hookDistance = Math.sqrt(Math.pow(hookGlobalPos.x - fish.x, 2) + Math.pow(hookGlobalPos.y - fish.y, 2));
if (boat.hookDeployed && hookDistance < hookCheckRadius) {
lives -= 1;
LK.effects.flashScreen(0xFFFF00, 500);
LK.getSound('danger').play();
fish.destroy();
fishArray.splice(i, 1);
if (lives <= 0) {
LK.showGameOver();
}
} else if (fish.y > 2732) {
fish.destroy();
fishArray.splice(i, 1);
}
}
for (var i = sharkArray.length - 1; i >= 0; i--) {
var shark = sharkArray[i];
shark.update();
var sharkDistance = Math.sqrt(Math.pow(boat.x - shark.x, 2) + Math.pow(boat.y - shark.y, 2));
if (sharkDistance < 100) {
lives -= 1;
LK.effects.flashScreen(0xFF0000, 500);
LK.getSound('danger').play();
shark.destroy();
sharkArray.splice(i, 1);
if (lives <= 0) {
LK.showGameOver();
}
} else if (shark.y > 2732) {
shark.destroy();
sharkArray.splice(i, 1);
}
}
for (var i = jellyfishArray.length - 1; i >= 0; i--) {
var jellyfish = jellyfishArray[i];
jellyfish.update();
var jellyDistance = Math.sqrt(Math.pow(boat.x - jellyfish.x, 2) + Math.pow(boat.y - jellyfish.y, 2));
if (jellyDistance < 85) {
lives -= 1;
LK.effects.flashScreen(0xFF00FF, 500);
LK.getSound('danger').play();
jellyfish.destroy();
jellyfishArray.splice(i, 1);
if (lives <= 0) {
LK.showGameOver();
}
} else if (jellyfish.y > 2732) {
jellyfish.destroy();
jellyfishArray.splice(i, 1);
}
}
updateUI();
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Boat = Container.expand(function () {
var self = Container.call(this);
self.boatGraphics = self.attachAsset('boat', {
anchorX: 0.5,
anchorY: 0.5
});
self.hookContainer = new Container();
self.addChild(self.hookContainer);
self.hookContainer.x = 0;
self.hookContainer.y = 40;
var hookGraphics = self.hookContainer.attachAsset('hook', {
anchorX: 0.5,
anchorY: 0
});
self.hookDeployed = false;
self.hookExtension = 0;
self.maxHookExtension = 200;
self.hookSpeed = 8;
self.moveLeft = function () {
if (self.x > 60) {
self.x -= 15;
}
};
self.moveRight = function () {
if (self.x < 1988) {
self.x += 15;
}
};
self.deployHook = function () {
if (!self.hookDeployed) {
self.hookDeployed = true;
}
};
self.update = function () {
if (self.hookDeployed) {
self.hookExtension += self.hookSpeed;
if (self.hookExtension >= self.maxHookExtension) {
self.hookExtension = self.maxHookExtension;
}
} else {
if (self.hookExtension > 0) {
self.hookExtension -= self.hookSpeed;
if (self.hookExtension < 0) {
self.hookExtension = 0;
}
}
}
self.hookContainer.y = 40 + self.hookExtension;
};
return self;
});
var Fish = Container.expand(function () {
var self = Container.call(this);
self.fishGraphics = self.attachAsset('fish', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.direction = 1;
self.update = function () {
self.y += self.speed;
self.x += self.direction * 1.5;
if (self.x < 0 || self.x > 2048) {
self.direction *= -1;
}
};
return self;
});
var Jellyfish = Container.expand(function () {
var self = Container.call(this);
self.jellyfishGraphics = self.attachAsset('jellyfish', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.wobbleAmount = 0;
self.wobblePhase = 0;
self.update = function () {
self.y += self.speed;
self.wobblePhase += 0.05;
self.x += Math.sin(self.wobblePhase) * 2;
};
return self;
});
var Shark = Container.expand(function () {
var self = Container.call(this);
self.sharkGraphics = self.attachAsset('shark', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.direction = 1;
self.huntProgress = 0;
self.update = function () {
self.y += self.speed;
self.x += self.direction * (2 + difficultyLevel * 0.5);
if (self.x < 0 || self.x > 2048) {
self.direction *= -1;
}
};
return self;
});
var Trash = Container.expand(function () {
var self = Container.call(this);
self.trashType = 'bottle';
self.points = 10;
self.speed = 3;
self.setTrashType = function (type) {
self.trashType = type;
var trashGraphics = self.attachAsset(type, {
anchorX: 0.5,
anchorY: 0.5
});
if (type === 'bottle') {
self.points = 10;
} else if (type === 'bag') {
self.points = 20;
} else if (type === 'can') {
self.points = 30;
} else if (type === 'plastic') {
self.points = 15;
}
};
self.update = function () {
self.y += self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1E90FF
});
/****
* Game Code
****/
var difficultyLevel = 1;
var score = 0;
var lives = 3;
var trashCollected = 0;
var gameTime = 0;
var targetTrash = 20;
var spawnRate = 100;
var lastSpawnTick = 0;
var boat = new Boat();
game.addChild(boat);
boat.x = 1024;
boat.y = 2500;
var trashArray = [];
var fishArray = [];
var sharkArray = [];
var jellyfishArray = [];
var scoreText = new Text2('Score: 0', {
size: 100,
fill: '#FFFFFF'
});
scoreText.anchor.set(0, 0);
LK.gui.topRight.addChild(scoreText);
var livesText = new Text2('Lives: 3', {
size: 100,
fill: '#FF6347'
});
livesText.anchor.set(0, 0);
LK.gui.top.addChild(livesText);
var trashText = new Text2('Trash: 0/' + targetTrash, {
size: 100,
fill: '#FFFFFF'
});
trashText.anchor.set(0.5, 0);
LK.gui.top.addChild(trashText);
function updateUI() {
scoreText.setText('Score: ' + score);
livesText.setText('Lives: ' + lives);
trashText.setText('Trash: ' + trashCollected + '/' + targetTrash);
}
function spawnTrash() {
var trashTypes = ['bottle', 'bag', 'can', 'plastic'];
var randomType = trashTypes[Math.floor(Math.random() * trashTypes.length)];
var trash = new Trash();
trash.setTrashType(randomType);
trash.x = Math.random() * 2048;
trash.y = -50;
trash.speed = 2 + difficultyLevel * 0.3;
game.addChild(trash);
trashArray.push(trash);
}
function spawnFish() {
var fish = new Fish();
fish.x = Math.random() * 2048;
fish.y = Math.random() * 1500 + 300;
fish.speed = 1.5 + difficultyLevel * 0.2;
game.addChild(fish);
fishArray.push(fish);
}
function spawnShark() {
var shark = new Shark();
shark.x = Math.random() * 2048;
shark.y = Math.random() * 1000 + 800;
shark.speed = 2.5 + difficultyLevel * 0.4;
game.addChild(shark);
sharkArray.push(shark);
}
function spawnJellyfish() {
var jellyfish = new Jellyfish();
jellyfish.x = Math.random() * 2048;
jellyfish.y = -50;
jellyfish.speed = 2 + difficultyLevel * 0.2;
game.addChild(jellyfish);
jellyfishArray.push(jellyfish);
}
function increaseDifficulty() {
if (difficultyLevel < 5) {
difficultyLevel += 0.5;
spawnRate = Math.max(50, 100 - difficultyLevel * 10);
}
}
game.move = function (x, y, obj) {
boat.x = x;
if (boat.x < 60) {
boat.x = 60;
}
if (boat.x > 1988) {
boat.x = 1988;
}
};
game.down = function (x, y, obj) {
boat.deployHook();
};
game.up = function (x, y, obj) {
boat.hookDeployed = false;
};
game.update = function () {
gameTime += 1;
boat.update();
if (gameTime % 30 === 0) {
increaseDifficulty();
}
if (gameTime % spawnRate === 0) {
spawnTrash();
}
if (gameTime % 200 === 0) {
spawnFish();
}
if (gameTime % 250 === 0 && difficultyLevel > 1) {
spawnShark();
}
if (gameTime % 300 === 0 && difficultyLevel > 2) {
spawnJellyfish();
}
var hookGlobalPos = boat.toGlobal(boat.hookContainer.position);
var hookCheckRadius = 50;
for (var i = trashArray.length - 1; i >= 0; i--) {
var trash = trashArray[i];
trash.update();
var distance = Math.sqrt(Math.pow(hookGlobalPos.x - trash.x, 2) + Math.pow(hookGlobalPos.y - trash.y, 2));
if (boat.hookDeployed && distance < hookCheckRadius) {
score += trash.points;
trashCollected += 1;
trash.destroy();
trashArray.splice(i, 1);
LK.getSound('catch').play();
if (trashCollected >= targetTrash) {
LK.showYouWin();
}
} else if (trash.y > 2732) {
trash.destroy();
trashArray.splice(i, 1);
}
}
for (var i = fishArray.length - 1; i >= 0; i--) {
var fish = fishArray[i];
fish.update();
var hookGlobalPos = boat.toGlobal(boat.hookContainer.position);
var hookCheckRadius = 50;
var hookDistance = Math.sqrt(Math.pow(hookGlobalPos.x - fish.x, 2) + Math.pow(hookGlobalPos.y - fish.y, 2));
if (boat.hookDeployed && hookDistance < hookCheckRadius) {
lives -= 1;
LK.effects.flashScreen(0xFFFF00, 500);
LK.getSound('danger').play();
fish.destroy();
fishArray.splice(i, 1);
if (lives <= 0) {
LK.showGameOver();
}
} else if (fish.y > 2732) {
fish.destroy();
fishArray.splice(i, 1);
}
}
for (var i = sharkArray.length - 1; i >= 0; i--) {
var shark = sharkArray[i];
shark.update();
var sharkDistance = Math.sqrt(Math.pow(boat.x - shark.x, 2) + Math.pow(boat.y - shark.y, 2));
if (sharkDistance < 100) {
lives -= 1;
LK.effects.flashScreen(0xFF0000, 500);
LK.getSound('danger').play();
shark.destroy();
sharkArray.splice(i, 1);
if (lives <= 0) {
LK.showGameOver();
}
} else if (shark.y > 2732) {
shark.destroy();
sharkArray.splice(i, 1);
}
}
for (var i = jellyfishArray.length - 1; i >= 0; i--) {
var jellyfish = jellyfishArray[i];
jellyfish.update();
var jellyDistance = Math.sqrt(Math.pow(boat.x - jellyfish.x, 2) + Math.pow(boat.y - jellyfish.y, 2));
if (jellyDistance < 85) {
lives -= 1;
LK.effects.flashScreen(0xFF00FF, 500);
LK.getSound('danger').play();
jellyfish.destroy();
jellyfishArray.splice(i, 1);
if (lives <= 0) {
LK.showGameOver();
}
} else if (jellyfish.y > 2732) {
jellyfish.destroy();
jellyfishArray.splice(i, 1);
}
}
updateUI();
};
Bolsa de basura. In-Game asset. 2d. High contrast. No shadows
Bote dd pesca. In-Game asset. 2d. High contrast. No shadows
Pez. In-Game asset. 2d. High contrast. No shadows
Medusa de mar. In-Game asset. 2d. High contrast. No shadows
Plástico basura. In-Game asset. 2d. High contrast. No shadows
Caña de pezcar. In-Game asset. 2d. High contrast. No shadows
Tiburón. In-Game asset. 2d. High contrast. No shadows
Agua realista. In-Game asset. 2d. High contrast. No shadows
Botellita de elixir morado. In-Game asset. 2d. High contrast. No shadows