/****
* Classes
****/
// Bomb class
var Bomb = Container.expand(function () {
var self = Container.call(this);
var bombGraphics = self.attachAsset('bomb', {
anchorX: 0.5,
anchorY: 0.5
});
self.exploded = false;
self.update = function () {
// Update logic for the bomb
};
});
// Fence class
var Fence = Container.expand(function () {
var self = Container.call(this);
var fenceGraphics = self.attachAsset('fence', {
anchorX: 0.5,
anchorY: 0.5
});
});
// GrassPatch class
var GrassPatch = Container.expand(function () {
var self = Container.call(this);
var grassGraphics = self.attachAsset('grass', {
anchorX: 0.5,
anchorY: 0.5
});
self.cut = false;
self.update = function () {
// Update logic for the grass patch
};
});
//<Assets used in the game will automatically appear here>
// LawnMower class
var LawnMower = Container.expand(function () {
var self = Container.call(this);
var mowerGraphics = self.attachAsset('mower', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 1.25;
self.update = function () {
// Update logic for the lawnmower
};
});
// Shit class
var Shit = Container.expand(function () {
var self = Container.call(this);
var shitGraphics = self.attachAsset('shit', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Update logic for the shit
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x008000 // Init game with green background
});
/****
* Game Code
****/
// Define game.reset function to start a new random map
game.reset = function () {
// Clear existing game elements
game.removeChildren();
// Reinitialize game elements
lawnMower = new LawnMower();
lawnMower.x = 2048 / 2;
lawnMower.y = 2732 / 2;
game.addChild(lawnMower);
grassPatches = [];
bombs = [];
shits = [];
score = 0;
scoreTxt.setText('MONEY: ' + score);
// Create and position the fence assets around the sidelines
var fenceTop = [];
var fenceBottom = [];
var fenceLeft = [];
var fenceRight = [];
for (var i = 0; i < 2048; i += 200) {
var top = game.addChild(new Fence());
top.x = i;
top.y = 0;
fenceTop.push(top);
var bottom = game.addChild(new Fence());
bottom.x = i;
bottom.y = 2732 - 200;
fenceBottom.push(bottom);
}
for (var i = 200; i < 2732 - 200; i += 200) {
var left = game.addChild(new Fence());
left.x = 0;
left.y = i;
fenceLeft.push(left);
var right = game.addChild(new Fence());
right.x = 2048 - 200;
right.y = i;
fenceRight.push(right);
}
// Recreate and position grass patches, bombs, and shits randomly
for (var i = 0; i < 24; i++) {
var grassPatch = new GrassPatch();
do {
grassPatch.x = Math.floor(Math.random() * (2048 - 4 * grassPatch.width)) + 2 * grassPatch.width;
grassPatch.y = Math.floor(Math.random() * (2732 - 4 * grassPatch.height)) + 2 * grassPatch.height;
} while (grassPatches.some(function (patch) {
return Math.abs(patch.x - grassPatch.x) < grassPatch.width && Math.abs(patch.y - grassPatch.y) < grassPatch.height;
}) || bombs.some(function (bomb) {
return Math.abs(bomb.x - grassPatch.x) < grassPatch.width && Math.abs(bomb.y - grassPatch.y) < grassPatch.height;
}) || shits.some(function (shit) {
return Math.abs(shit.x - grassPatch.x) < grassPatch.width && Math.abs(shit.y - grassPatch.y) < grassPatch.height;
}) || fenceTop.some(function (fence) {
return Math.abs(fence.x - grassPatch.x) < grassPatch.width && Math.abs(fence.y - grassPatch.y) < grassPatch.height;
}) || fenceBottom.some(function (fence) {
return Math.abs(fence.x - grassPatch.x) < grassPatch.width && Math.abs(fence.y - grassPatch.y) < grassPatch.height;
}) || fenceLeft.some(function (fence) {
return Math.abs(fence.x - grassPatch.x) < grassPatch.width && Math.abs(fence.y - grassPatch.y) < grassPatch.height;
}) || fenceRight.some(function (fence) {
return Math.abs(fence.x - grassPatch.x) < grassPatch.width && Math.abs(fence.y - grassPatch.y) < grassPatch.height;
}));
grassPatches.push(grassPatch);
game.addChild(grassPatch);
}
for (var i = 0; i < 6; i++) {
var bomb = new Bomb();
do {
bomb.x = Math.floor(Math.random() * (2048 - 3 * bomb.width)) + 2 * bomb.width;
bomb.y = Math.floor(Math.random() * (2732 - 3 * bomb.height)) + 2 * bomb.height;
} while (grassPatches.some(function (patch) {
return Math.abs(patch.x - bomb.x) < bomb.width && Math.abs(patch.y - bomb.y) < bomb.height;
}) || fenceTop.some(function (fence) {
return Math.abs(fence.x - bomb.x) < bomb.width && Math.abs(fence.y - bomb.y) < bomb.height;
}) || fenceBottom.some(function (fence) {
return Math.abs(fence.x - bomb.x) < bomb.width && Math.abs(fence.y - bomb.y) < bomb.height;
}) || fenceLeft.some(function (fence) {
return Math.abs(fence.x - bomb.x) < bomb.width && Math.abs(fence.y - bomb.y) < bomb.height;
}) || fenceRight.some(function (fence) {
return Math.abs(fence.x - bomb.x) < bomb.width && Math.abs(fence.y - bomb.y) < bomb.height;
}));
bombs.push(bomb);
game.addChild(bomb);
}
for (var i = 0; i < 4; i++) {
var shit = new Shit();
do {
shit.x = Math.floor(Math.random() * (2048 - 3 * shit.width)) + 2 * shit.width;
shit.y = Math.floor(Math.random() * (2732 - 3 * shit.height)) + 2 * shit.height;
} while (grassPatches.some(function (patch) {
return Math.abs(patch.x - shit.x) < shit.width && Math.abs(patch.y - shit.y) < shit.height;
}) || fenceTop.some(function (fence) {
return Math.abs(fence.x - shit.x) < shit.width && Math.abs(fence.y - shit.y) < shit.height;
}) || fenceBottom.some(function (fence) {
return Math.abs(fence.x - shit.x) < shit.width && Math.abs(fence.y - shit.y) < shit.height;
}) || fenceLeft.some(function (fence) {
return Math.abs(fence.x - shit.x) < shit.width && Math.abs(fence.y - shit.y) < shit.height;
}) || fenceRight.some(function (fence) {
return Math.abs(fence.x - shit.x) < shit.width && Math.abs(fence.y - shit.y) < shit.height;
}));
shits.push(shit);
game.addChild(shit);
}
};
// Define game.start function before calling it
game.start = function () {
var kakasSound = LK.getSound('kakas');
if (kakasSound) {
var kakasSoundInstance = kakasSound.play();
if (kakasSoundInstance) {
kakasSoundInstance.once('end', function () {
var k1Sound = LK.getSound('k1');
if (k1Sound) {
var k1SoundInstance = k1Sound.play();
if (k1SoundInstance) {
k1SoundInstance.once('end', function () {
// Additional logic if needed after k1 sound ends
});
}
}
});
}
}
};
game.start();
// Initialize arrays and variables
var lawnMower;
var grassPatches = [];
var scoreTxt;
var score = 0;
var fenceTop = [];
var fenceBottom = [];
var fenceLeft = [];
var fenceRight = [];
// Create and position the lawnmower at the center of the map
lawnMower = new LawnMower();
lawnMower.x = 2048 / 2;
lawnMower.y = 2732 / 2;
// Play kakas sound only when the game starts
game.start = function () {
var kakasSound = LK.getSound('kakas');
if (kakasSound) {
kakasSound.play().once('end', function () {
var k1Sound = LK.getSound('k1');
if (k1Sound) {
k1Sound.play();
}
});
}
};
// Create and position the fence assets around the sidelines
var fenceTop = [];
var fenceBottom = [];
var fenceLeft = [];
var fenceRight = [];
for (var i = 0; i < 2048; i += 200) {
var top = game.addChild(new Fence());
top.x = i;
top.y = 0;
fenceTop.push(top);
var bottom = game.addChild(new Fence());
bottom.x = i;
bottom.y = 2732 - 200;
fenceBottom.push(bottom);
}
for (var i = 200; i < 2732 - 200; i += 200) {
var left = game.addChild(new Fence());
left.x = 0;
left.y = i;
fenceLeft.push(left);
var right = game.addChild(new Fence());
right.x = 2048 - 200;
right.y = i;
fenceRight.push(right);
}
// Create and position grass patches, bombs, and shits randomly
var bombs = [];
var shits = [];
for (var i = 0; i < 24; i++) {
var grassPatch = new GrassPatch();
do {
grassPatch.x = Math.floor(Math.random() * (2048 - 4 * grassPatch.width)) + 2 * grassPatch.width;
grassPatch.y = Math.floor(Math.random() * (2732 - 4 * grassPatch.height)) + 2 * grassPatch.height;
} while (grassPatches.some(function (patch) {
return Math.abs(patch.x - grassPatch.x) < grassPatch.width && Math.abs(patch.y - grassPatch.y) < grassPatch.height;
}) || bombs.some(function (bomb) {
return Math.abs(bomb.x - grassPatch.x) < grassPatch.width && Math.abs(bomb.y - grassPatch.y) < grassPatch.height;
}) || shits.some(function (shit) {
return Math.abs(shit.x - grassPatch.x) < grassPatch.width && Math.abs(shit.y - grassPatch.y) < grassPatch.height;
}));
grassPatches.push(grassPatch);
game.addChild(grassPatch);
}
// Ensure there are exactly 6 bombs
for (var i = 0; i < 6; i++) {
var bomb = new Bomb();
do {
bomb.x = Math.floor(Math.random() * (2048 - 3 * bomb.width)) + 2 * bomb.width;
bomb.y = Math.floor(Math.random() * (2732 - 3 * bomb.height)) + 2 * bomb.height;
} while (grassPatches.some(function (patch) {
return Math.abs(patch.x - bomb.x) < bomb.width && Math.abs(patch.y - bomb.y) < bomb.height;
}));
bombs.push(bomb);
game.addChild(bomb);
}
// Ensure there are exactly 4 shits
for (var i = 0; i < 4; i++) {
var shit = new Shit();
do {
shit.x = Math.floor(Math.random() * (2048 - 3 * shit.width)) + 2 * shit.width;
shit.y = Math.floor(Math.random() * (2732 - 3 * shit.height)) + 2 * shit.height;
} while (grassPatches.some(function (patch) {
return Math.abs(patch.x - shit.x) < shit.width && Math.abs(patch.y - shit.y) < shit.height;
}));
shits.push(shit);
game.addChild(shit);
}
// Create and position the score text
scoreTxt = new Text2('Score: 0', {
size: 100,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Handle move events
function handleMove(x, y, obj) {
lawnMower.x = x;
lawnMower.y = y;
if (!fenceTop.some(function (f) {
return lawnMower.intersects(f);
}) && !fenceBottom.some(function (f) {
return lawnMower.intersects(f);
}) && !fenceLeft.some(function (f) {
return lawnMower.intersects(f);
}) && !fenceRight.some(function (f) {
return lawnMower.intersects(f);
}) && !bombs.some(function (bomb) {
return lawnMower.intersects(bomb);
}) && !shits.some(function (shit) {
return lawnMower.intersects(shit);
})) {
LK.playMusic('g1');
} else if (fenceTop.some(function (f) {
return lawnMower.intersects(f);
}) || fenceBottom.some(function (f) {
return lawnMower.intersects(f);
}) || fenceLeft.some(function (f) {
return lawnMower.intersects(f);
}) || fenceRight.some(function (f) {
return lawnMower.intersects(f);
}) || shits.some(function (shit) {
if (lawnMower.intersects(shit)) {
var dogsmile = LK.getAsset('Dogsmile', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 - 250,
y: 2732 - 250
});
game.addChild(dogsmile);
LK.setTimeout(function () {
game.removeChild(dogsmile);
}, 3000);
// Play k1 sound
var k1Sound = LK.getSound('k1');
if (k1Sound) {
k1Sound.play();
}
}
return lawnMower.intersects(shit);
}) || bombs.some(function (bomb) {
return lawnMower.intersects(bomb);
})) {
LK.stopMusic();
LK.getSound('k1').stop();
}
// Check for collision with grass patches and bombs
for (var i = 0; i < grassPatches.length; i++) {
if (!grassPatches[i].cut && lawnMower.intersects(grassPatches[i])) {
grassPatches[i].cut = true;
grassPatches[i].alpha = 0.5; // Visually indicate the grass is cut
score++;
scoreTxt.setText('MONEY: ' + score);
if (score === 24) {
// Turn off bombs
bombs.forEach(function (bomb) {
bomb.exploded = true;
bomb.alpha = 0.5; // Visually indicate the bomb is turned off
});
var rewardPopup = LK.getAsset('rewardPopup', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
game.addChild(rewardPopup);
var congratsText = new Text2('Congratulations!\n\nEverything is trimmed.\n\nLevel accomplished.\n\nSh*t up and take my money! ;)', {
size: 100,
fill: "#ffffff",
align: "center"
});
congratsText.anchor.set(0.5, 0.5);
congratsText.x = 2048 / 2;
congratsText.y = 2732 / 2;
game.addChild(congratsText);
// Add new asset for starting a new random map
var newMapButton = LK.getAsset('reward', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2 + rewardPopup.height / 2 - 300 // Move above by 1 piece of grass asset
});
game.addChild(newMapButton);
// Add event listener to the new asset
newMapButton.down = function (x, y, obj) {
// Start a new map
game.reset();
return;
// Logic to start a new random map
game.reset();
};
return;
}
}
}
for (var i = 0; i < bombs.length; i++) {
if (!bombs[i].exploded && lawnMower.intersects(bombs[i])) {
bombs[i].exploded = true;
bombs[i].alpha = 0.5; // Visually indicate the bomb has exploded
// Play bomb detonation sound
var bombDetonationSound = LK.getSound('bombDetonation');
if (bombDetonationSound) {
bombDetonationSound.play();
}
// Stop k1 sound
LK.getSound('k1').stop();
// End the game if a bomb is hit
LK.showGameOver();
}
}
}
// Mouse or touch move on game object
game.move = handleMove;
// Mouse or touch down on game object
game.down = function (x, y, obj) {
handleMove(x, y, obj);
};
// Mouse or touch up on game object
game.up = function (x, y, obj) {
// No action needed on up event
};
// Add the lawnmower to the game
game.addChild(lawnMower);
// Update game logic
game.update = function () {
// Update lawnmower and grass patches
lawnMower.update();
if (grassPatches && grassPatches.length > 0) {
for (var i = 0; i < grassPatches.length; i++) {
grassPatches[i].update();
}
}
};
// Removed undefined LK.init.text call
grass. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
grass mower.
Bomb.
Paving stone. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Congratulation! Green wallpapper.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
dog smile. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
dog shit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
blue and green button with "GO TO THE NEXT MAP" text.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.