User prompt
Añade botella de plástico que se puedan recoger, permite recojer la bolsa, plástico y que el pescar el pez, tiburón y medusa aga daño
Code edit (1 edits merged)
Please save this source code
User prompt
Que tengas forma de basura
Code edit (1 edits merged)
Please save this source code
User prompt
Ocean Cleanup: Save the Seas
Initial prompt
1. INICIO 1. Crear escenario principal: Un niño en un barco sobre el mar. El barco puede moverse izquierda y derecha. 2. Generar objetos que caen o flotan en el mar: Basura (botellas, bolsas, latas, plástico, etc.). Peces normales (no dañinos). Animales peligrosos (tiburones, medusas, etc.). --- 2. OBJETIVO DEL JUGADOR Recoger la basura usando un gancho o una red. Evitar los animales peligrosos, que pueden quitar vida. No dañar a los peces normales. --- 3. MECÁNICA PRINCIPAL 1. El jugador mueve el barco. 2. Cuando la basura pasa debajo del barco: El jugador presiona un botón para bajar el gancho/red. 3. Si el gancho toca: Basura → sumar puntos. Peces normales → restar puntos o nada. Animal peligroso → restar vida. 4. La basura recogida se acumula en un contador. --- 4. SISTEMA DE PUNTOS Basura pequeña: +10 puntos Basura mediana: +20 puntos Basura grande: +30 puntos Pescado atrapado por accidente: –5 puntos Animal peligroso: –1 vida --- 5. SISTEMA DE VIDAS El jugador inicia con 3 vidas. Cada animal peligroso que toque el barco o el gancho quita 1 vida. Si la vida llega a 0 → GAME OVER. --- 6. NIVEL DE DIFICULTAD Conforme pasa el tiempo: Aparece más basura. Los animales peligrosos son más rápidos. El barco se mueve un poco más lento (opcional). --- 7. FINAL DEL JUEGO El juego termina si: El jugador pierde todas las vidas. Se acaba el tiempo del nivel (si agregas temporizador). Se recoge una cantidad meta de basura. Mostrar: Basura total recogida. Puntuación final. Mensaje de felicitación o derrota. --- 8. FIN
/****
* 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();
}; ===================================================================
--- original.js
+++ change.js
@@ -281,16 +281,20 @@
}
for (var i = fishArray.length - 1; i >= 0; i--) {
var fish = fishArray[i];
fish.update();
- var boatDistance = Math.sqrt(Math.pow(boat.x - fish.x, 2) + Math.pow(boat.y - fish.y, 2));
- if (boatDistance < 70) {
- score -= 5;
- if (score < 0) {
- score = 0;
- }
+ 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);
}
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