/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Arm = Container.expand(function () { var self = Container.call(this); var armGraphics = self.attachAsset('arm', { anchorX: 0.5, anchorY: 0.8 }); var gunGraphics = self.attachAsset('gun', { anchorX: 0.5, anchorY: 0.9 }); self.gunAngle = 0; self.aimAt = function (x, y) { var dx = x - self.x; var dy = y - self.y; self.gunAngle = Math.atan2(dy, dx); gunGraphics.rotation = self.gunAngle; }; self.getGunTip = function () { var tipDistance = 60; return { x: self.x + Math.cos(self.gunAngle) * tipDistance, y: self.y + Math.sin(self.gunAngle) * tipDistance }; }; return self; }); var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 8; self.direction = 0; self.velocityX = 0; self.velocityY = 0; self.setDirection = function (angle) { self.direction = angle; self.velocityX = Math.cos(angle) * self.speed; self.velocityY = Math.sin(angle) * self.speed; }; self.update = function () { self.x += self.velocityX; self.y += self.velocityY; }; return self; }); var Crocodile = Container.expand(function () { var self = Container.call(this); var crocodileGraphics = self.attachAsset('crocodile', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 1.5; self.targetX = 0; self.targetY = 0; self.angle = 0; self.setTarget = function (x, y) { self.targetX = x; self.targetY = y; var dx = x - self.x; var dy = y - self.y; self.angle = Math.atan2(dy, dx); crocodileGraphics.rotation = self.angle; }; self.update = function () { var dx = self.targetX - self.x; var dy = self.targetY - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 5) { self.x += Math.cos(self.angle) * self.speed; self.y += Math.sin(self.angle) * self.speed; } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2c5530 }); /**** * Game Code ****/ var currentLevel = 1; var crocodiles = []; var bullets = []; var crocodilesRemaining = 0; var crocodilesSpawned = 0; var maxCrocodilesOnScreen = 9; var arm = null; var levelText = null; var crocodilesText = null; var gameStarted = false; var levelCompleted = false; // Initialize UI levelText = new Text2('Level: 1', { size: 80, fill: 0xFFFFFF }); levelText.anchor.set(0, 0); levelText.x = 120; levelText.y = 50; LK.gui.topLeft.addChild(levelText); crocodilesText = new Text2('Crocodiles: 0', { size: 80, fill: 0xFFFFFF }); crocodilesText.anchor.set(1, 0); crocodilesText.x = -50; crocodilesText.y = 50; LK.gui.topRight.addChild(crocodilesText); // Add background image var background = game.addChild(LK.getAsset('background', { anchorX: 0, anchorY: 0, x: 0, y: 0 })); // Create arm at center arm = game.addChild(new Arm()); arm.x = 2048 / 2; arm.y = 2732 / 2; function spawnCrocodile() { var crocodile = new Crocodile(); // Spawn at random edge of screen var edge = Math.floor(Math.random() * 4); switch (edge) { case 0: // Top crocodile.x = Math.random() * 2048; crocodile.y = -100; break; case 1: // Right crocodile.x = 2148; crocodile.y = Math.random() * 2732; break; case 2: // Bottom crocodile.x = Math.random() * 2048; crocodile.y = 2832; break; case 3: // Left crocodile.x = -100; crocodile.y = Math.random() * 2732; break; } crocodile.setTarget(arm.x, arm.y); crocodiles.push(crocodile); game.addChild(crocodile); // Play growl sound LK.getSound('crocodileGrowl').play(); } function startLevel() { crocodiles = []; bullets = []; crocodilesRemaining = currentLevel; crocodilesSpawned = 0; levelCompleted = false; // Spawn initial crocodiles (up to max on screen) var initialSpawn = Math.min(currentLevel, maxCrocodilesOnScreen); for (var i = 0; i < initialSpawn; i++) { LK.setTimeout(function () { spawnCrocodile(); crocodilesSpawned++; }, i * 500); } updateUI(); gameStarted = true; } function updateUI() { levelText.setText('Level: ' + currentLevel); crocodilesText.setText('Crocodiles: ' + crocodilesRemaining); } function checkLevelComplete() { if (crocodilesRemaining <= 0 && !levelCompleted) { levelCompleted = true; currentLevel++; LK.setTimeout(function () { startLevel(); }, 1000); } } function gameOver() { currentLevel = 1; levelCompleted = false; // Clean up for (var i = 0; i < crocodiles.length; i++) { crocodiles[i].destroy(); } for (var i = 0; i < bullets.length; i++) { bullets[i].destroy(); } crocodiles = []; bullets = []; LK.effects.flashScreen(0xff0000, 1000); LK.setTimeout(function () { startLevel(); }, 1500); } // Mouse/touch controls game.move = function (x, y, obj) { if (arm && gameStarted) { arm.aimAt(x, y); } }; game.down = function (x, y, obj) { if (arm && gameStarted) { arm.aimAt(x, y); // Create bullet var bullet = new Bullet(); var gunTip = arm.getGunTip(); bullet.x = gunTip.x; bullet.y = gunTip.y; bullet.setDirection(arm.gunAngle); bullets.push(bullet); game.addChild(bullet); // Play gunshot sound LK.getSound('gunshot').play(); } }; game.update = function () { if (!gameStarted) return; // Update bullets for (var i = bullets.length - 1; i >= 0; i--) { var bullet = bullets[i]; // Remove bullets that go off screen if (bullet.x < -50 || bullet.x > 2098 || bullet.y < -50 || bullet.y > 2782) { bullet.destroy(); bullets.splice(i, 1); continue; } // Check bullet-crocodile collisions for (var j = crocodiles.length - 1; j >= 0; j--) { var crocodile = crocodiles[j]; if (bullet.intersects(crocodile)) { // Remove both bullet and crocodile bullet.destroy(); bullets.splice(i, 1); crocodile.destroy(); crocodiles.splice(j, 1); crocodilesRemaining--; // Spawn new crocodile if we haven't spawned all for this level yet if (crocodilesSpawned < currentLevel) { LK.setTimeout(function () { spawnCrocodile(); crocodilesSpawned++; }, 1000); } updateUI(); break; } } } // Update crocodiles and check if they reach the arm for (var i = crocodiles.length - 1; i >= 0; i--) { var crocodile = crocodiles[i]; if (crocodile.intersects(arm)) { gameOver(); return; } } // Check if level is complete checkLevelComplete(); }; // Start the game LK.playMusic('backgroundMusic'); startLevel();
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Arm = Container.expand(function () {
var self = Container.call(this);
var armGraphics = self.attachAsset('arm', {
anchorX: 0.5,
anchorY: 0.8
});
var gunGraphics = self.attachAsset('gun', {
anchorX: 0.5,
anchorY: 0.9
});
self.gunAngle = 0;
self.aimAt = function (x, y) {
var dx = x - self.x;
var dy = y - self.y;
self.gunAngle = Math.atan2(dy, dx);
gunGraphics.rotation = self.gunAngle;
};
self.getGunTip = function () {
var tipDistance = 60;
return {
x: self.x + Math.cos(self.gunAngle) * tipDistance,
y: self.y + Math.sin(self.gunAngle) * tipDistance
};
};
return self;
});
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
self.direction = 0;
self.velocityX = 0;
self.velocityY = 0;
self.setDirection = function (angle) {
self.direction = angle;
self.velocityX = Math.cos(angle) * self.speed;
self.velocityY = Math.sin(angle) * self.speed;
};
self.update = function () {
self.x += self.velocityX;
self.y += self.velocityY;
};
return self;
});
var Crocodile = Container.expand(function () {
var self = Container.call(this);
var crocodileGraphics = self.attachAsset('crocodile', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 1.5;
self.targetX = 0;
self.targetY = 0;
self.angle = 0;
self.setTarget = function (x, y) {
self.targetX = x;
self.targetY = y;
var dx = x - self.x;
var dy = y - self.y;
self.angle = Math.atan2(dy, dx);
crocodileGraphics.rotation = self.angle;
};
self.update = function () {
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 5) {
self.x += Math.cos(self.angle) * self.speed;
self.y += Math.sin(self.angle) * self.speed;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2c5530
});
/****
* Game Code
****/
var currentLevel = 1;
var crocodiles = [];
var bullets = [];
var crocodilesRemaining = 0;
var crocodilesSpawned = 0;
var maxCrocodilesOnScreen = 9;
var arm = null;
var levelText = null;
var crocodilesText = null;
var gameStarted = false;
var levelCompleted = false;
// Initialize UI
levelText = new Text2('Level: 1', {
size: 80,
fill: 0xFFFFFF
});
levelText.anchor.set(0, 0);
levelText.x = 120;
levelText.y = 50;
LK.gui.topLeft.addChild(levelText);
crocodilesText = new Text2('Crocodiles: 0', {
size: 80,
fill: 0xFFFFFF
});
crocodilesText.anchor.set(1, 0);
crocodilesText.x = -50;
crocodilesText.y = 50;
LK.gui.topRight.addChild(crocodilesText);
// Add background image
var background = game.addChild(LK.getAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
}));
// Create arm at center
arm = game.addChild(new Arm());
arm.x = 2048 / 2;
arm.y = 2732 / 2;
function spawnCrocodile() {
var crocodile = new Crocodile();
// Spawn at random edge of screen
var edge = Math.floor(Math.random() * 4);
switch (edge) {
case 0:
// Top
crocodile.x = Math.random() * 2048;
crocodile.y = -100;
break;
case 1:
// Right
crocodile.x = 2148;
crocodile.y = Math.random() * 2732;
break;
case 2:
// Bottom
crocodile.x = Math.random() * 2048;
crocodile.y = 2832;
break;
case 3:
// Left
crocodile.x = -100;
crocodile.y = Math.random() * 2732;
break;
}
crocodile.setTarget(arm.x, arm.y);
crocodiles.push(crocodile);
game.addChild(crocodile);
// Play growl sound
LK.getSound('crocodileGrowl').play();
}
function startLevel() {
crocodiles = [];
bullets = [];
crocodilesRemaining = currentLevel;
crocodilesSpawned = 0;
levelCompleted = false;
// Spawn initial crocodiles (up to max on screen)
var initialSpawn = Math.min(currentLevel, maxCrocodilesOnScreen);
for (var i = 0; i < initialSpawn; i++) {
LK.setTimeout(function () {
spawnCrocodile();
crocodilesSpawned++;
}, i * 500);
}
updateUI();
gameStarted = true;
}
function updateUI() {
levelText.setText('Level: ' + currentLevel);
crocodilesText.setText('Crocodiles: ' + crocodilesRemaining);
}
function checkLevelComplete() {
if (crocodilesRemaining <= 0 && !levelCompleted) {
levelCompleted = true;
currentLevel++;
LK.setTimeout(function () {
startLevel();
}, 1000);
}
}
function gameOver() {
currentLevel = 1;
levelCompleted = false;
// Clean up
for (var i = 0; i < crocodiles.length; i++) {
crocodiles[i].destroy();
}
for (var i = 0; i < bullets.length; i++) {
bullets[i].destroy();
}
crocodiles = [];
bullets = [];
LK.effects.flashScreen(0xff0000, 1000);
LK.setTimeout(function () {
startLevel();
}, 1500);
}
// Mouse/touch controls
game.move = function (x, y, obj) {
if (arm && gameStarted) {
arm.aimAt(x, y);
}
};
game.down = function (x, y, obj) {
if (arm && gameStarted) {
arm.aimAt(x, y);
// Create bullet
var bullet = new Bullet();
var gunTip = arm.getGunTip();
bullet.x = gunTip.x;
bullet.y = gunTip.y;
bullet.setDirection(arm.gunAngle);
bullets.push(bullet);
game.addChild(bullet);
// Play gunshot sound
LK.getSound('gunshot').play();
}
};
game.update = function () {
if (!gameStarted) return;
// Update bullets
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
// Remove bullets that go off screen
if (bullet.x < -50 || bullet.x > 2098 || bullet.y < -50 || bullet.y > 2782) {
bullet.destroy();
bullets.splice(i, 1);
continue;
}
// Check bullet-crocodile collisions
for (var j = crocodiles.length - 1; j >= 0; j--) {
var crocodile = crocodiles[j];
if (bullet.intersects(crocodile)) {
// Remove both bullet and crocodile
bullet.destroy();
bullets.splice(i, 1);
crocodile.destroy();
crocodiles.splice(j, 1);
crocodilesRemaining--;
// Spawn new crocodile if we haven't spawned all for this level yet
if (crocodilesSpawned < currentLevel) {
LK.setTimeout(function () {
spawnCrocodile();
crocodilesSpawned++;
}, 1000);
}
updateUI();
break;
}
}
}
// Update crocodiles and check if they reach the arm
for (var i = crocodiles.length - 1; i >= 0; i--) {
var crocodile = crocodiles[i];
if (crocodile.intersects(arm)) {
gameOver();
return;
}
}
// Check if level is complete
checkLevelComplete();
};
// Start the game
LK.playMusic('backgroundMusic');
startLevel();
Le bras d'un mec. In-Game asset. 2d. High contrast. No shadows
Arme a feu. In-Game asset. 2d. High contrast. No shadows
Bullet. In-Game asset. 2d. High contrast. No shadows
Crocodile. In-Game asset. 2d. High contrast. No shadows
Fond d'eÌcran mareÌcages. In-Game asset. 2d. High contrast. No shadows