/****
* Classes
****/
// Add grass image asset
// Bum class
var Bum = Container.expand(function () {
var self = Container.call(this);
var bumGraphics = self.attachAsset('bum', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.mad = false;
self.shoeThrowing = false;
self.update = function () {
// Move the bum towards the character
var dx = character.x - self.x;
var dy = character.y - self.y;
var dist = Math.sqrt(dx * dx + dy * dy);
if (self.mad) {
self.speed = 5;
if (dist > 100) {
self.x += dx / dist * self.speed;
self.y += dy / dist * self.speed;
} else {
self.x += dx / dist * self.speed + character.vx;
self.y += dy / dist * self.speed + character.vy;
}
if (!self.shoeThrowing) {
self.shoeThrowing = true;
var shoe = new Shoe();
shoe.x = self.x;
shoe.y = self.y;
game.addChild(shoe);
LK.setTimeout(function () {
self.shoeThrowing = false;
}, 300);
}
// Add a timer to limit the duration of madness mode to 3 seconds
if (!self.madnessTimer && Math.random() < 0.65) {
self.madnessTimer = LK.setTimeout(function () {
self.mad = false;
self.speed /= 5;
self.madnessTimer = null;
}, 3000);
}
} else {
self.x += dx / dist * self.speed;
self.y += dy / dist * self.speed;
}
};
});
// Character class
var Character = Container.expand(function () {
var self = Container.call(this);
var characterGraphics = self.attachAsset('character', {
anchorX: 0.5,
anchorY: 0.5
});
self.stun = false;
self.isBig = false; // Add a variable to track if the character is big
self.update = function () {
// Character specific update logic if needed
};
});
//<Assets used in the game will automatically appear here>
// Coin class
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Coin specific update logic if needed
};
});
// Shoe class
var Shoe = Container.expand(function () {
var self = Container.call(this);
var shoeGraphics = self.attachAsset('shoe', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
// Calculate the direction vector once when the shoe is created
if (!self.direction) {
var dx = character.x - self.x;
var dy = character.y - self.y;
var dist = Math.sqrt(dx * dx + dy * dy);
self.direction = {
x: dx / dist,
y: dy / dist
};
}
// Move the shoe in the calculated direction
self.x += self.direction.x * self.speed;
self.y += self.direction.y * self.speed;
// If the shoe hits the character and the character is frozen, the game is over
if (self.intersects(character) && character.stun) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
};
});
// TrashCan class
var TrashCan = Container.expand(function () {
var self = Container.call(this);
var trashCanGraphics = self.attachAsset('trashCan', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// TrashCan specific update logic if needed
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x008000 //Init game with green background
});
/****
* Game Code
****/
var grass = game.addChild(LK.getAsset('grass', {
// Add grass background to the game
anchorX: 0.0,
anchorY: 0.0,
x: 0,
y: 0
}));
// Initialize arrays and variables
var coins = [];
var bums = [];
var score = 0;
var scoreTxt = new Text2('Score: 0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 1);
LK.gui.bottom.addChild(scoreTxt);
// Create character
var character = game.addChild(new Character());
character.x = 2048 / 2;
character.y = 2732 / 2;
// Create trashCan
var trashCan = game.addChild(new TrashCan());
trashCan.x = 2048 / 2;
trashCan.y = 2732 / 2;
// Function to spawn a coin at a random position
function spawnCoin() {
var coin = new Coin();
coin.x = Math.random() * 2048;
coin.y = Math.random() * 2732;
coins.push(coin);
game.addChild(coin);
}
// Function to spawn a bum at a random position
function spawnBum() {
var bum = new Bum();
bum.x = trashCan.x;
bum.y = trashCan.y;
bums.push(bum);
game.addChild(bum);
}
// Handle move events
var dragNode = null;
function handleMove(x, y, obj) {
if (dragNode) {
dragNode.x = x;
dragNode.y = y;
}
// Check for coin collection
for (var i = coins.length - 1; i >= 0; i--) {
if (character.intersects(coins[i])) {
score += 1;
scoreTxt.setText('Score: ' + score.toString());
coins[i].destroy();
coins.splice(i, 1);
// Make the character faster when the score reaches 45
if (score == 45) {
character.speed = 5;
}
// Make all bums go mad after 45 coins
if (score >= 45) {
for (var j = 0; j < bums.length; j++) {
bums[j].mad = true;
}
}
}
}
// Check for collision with bums
for (var j = bums.length - 1; j >= 0; j--) {
if (character.intersects(bums[j])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
// Add score to leaderboard
}
// Check for collision with shoes
if (bums[j].shoeThrowing && character.intersects(bums[j].shoe)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
// Add score to leaderboard
}
}
// Squash the trashCan and show victory message when the big character steps on it
if (character.isBig && character.intersects(trashCan)) {
trashCan.scaleY = 0.5;
LK.gui.center.addChild(new Text2('Victory!', {
size: 150,
fill: "#ffffff"
}));
for (var j = 0; j < bums.length; j++) {
bums[j].destroy();
}
bums = [];
}
}
// Mouse or touch move on game object
game.move = function (x, y, obj) {
if (!character.stun) {
handleMove(x, y, obj);
}
};
// Allow dragging of the character to start from anywhere
game.down = function (x, y, obj) {
dragNode = character;
handleMove(x, y, obj);
};
// Mouse or touch up on game object
game.up = function (x, y, obj) {
dragNode = null;
};
// Update game every tick
game.update = function () {
for (var i = 0; i < coins.length; i++) {
coins[i].update();
}
for (var j = 0; j < bums.length; j++) {
bums[j].update();
// Make the bums go mad forever after 45 coins
if (score >= 45) {
for (var k = 0; k < bums.length; k++) {
bums[k].mad = true;
}
}
}
character.update();
// Spawn coins and bums at intervals
if (LK.ticks % 120 == 0) {
spawnCoin();
}
if (LK.ticks % 300 == 0) {
spawnBum();
}
}; /****
* Classes
****/
// Add grass image asset
// Bum class
var Bum = Container.expand(function () {
var self = Container.call(this);
var bumGraphics = self.attachAsset('bum', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.mad = false;
self.shoeThrowing = false;
self.update = function () {
// Move the bum towards the character
var dx = character.x - self.x;
var dy = character.y - self.y;
var dist = Math.sqrt(dx * dx + dy * dy);
if (self.mad) {
self.speed = 5;
if (dist > 100) {
self.x += dx / dist * self.speed;
self.y += dy / dist * self.speed;
} else {
self.x += dx / dist * self.speed + character.vx;
self.y += dy / dist * self.speed + character.vy;
}
if (!self.shoeThrowing) {
self.shoeThrowing = true;
var shoe = new Shoe();
shoe.x = self.x;
shoe.y = self.y;
game.addChild(shoe);
LK.setTimeout(function () {
self.shoeThrowing = false;
}, 300);
}
// Add a timer to limit the duration of madness mode to 3 seconds
if (!self.madnessTimer && Math.random() < 0.65) {
self.madnessTimer = LK.setTimeout(function () {
self.mad = false;
self.speed /= 5;
self.madnessTimer = null;
}, 3000);
}
} else {
self.x += dx / dist * self.speed;
self.y += dy / dist * self.speed;
}
};
});
// Character class
var Character = Container.expand(function () {
var self = Container.call(this);
var characterGraphics = self.attachAsset('character', {
anchorX: 0.5,
anchorY: 0.5
});
self.stun = false;
self.isBig = false; // Add a variable to track if the character is big
self.update = function () {
// Character specific update logic if needed
};
});
//<Assets used in the game will automatically appear here>
// Coin class
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Coin specific update logic if needed
};
});
// Shoe class
var Shoe = Container.expand(function () {
var self = Container.call(this);
var shoeGraphics = self.attachAsset('shoe', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
// Calculate the direction vector once when the shoe is created
if (!self.direction) {
var dx = character.x - self.x;
var dy = character.y - self.y;
var dist = Math.sqrt(dx * dx + dy * dy);
self.direction = {
x: dx / dist,
y: dy / dist
};
}
// Move the shoe in the calculated direction
self.x += self.direction.x * self.speed;
self.y += self.direction.y * self.speed;
// If the shoe hits the character and the character is frozen, the game is over
if (self.intersects(character) && character.stun) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
};
});
// TrashCan class
var TrashCan = Container.expand(function () {
var self = Container.call(this);
var trashCanGraphics = self.attachAsset('trashCan', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// TrashCan specific update logic if needed
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x008000 //Init game with green background
});
/****
* Game Code
****/
var grass = game.addChild(LK.getAsset('grass', {
// Add grass background to the game
anchorX: 0.0,
anchorY: 0.0,
x: 0,
y: 0
}));
// Initialize arrays and variables
var coins = [];
var bums = [];
var score = 0;
var scoreTxt = new Text2('Score: 0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 1);
LK.gui.bottom.addChild(scoreTxt);
// Create character
var character = game.addChild(new Character());
character.x = 2048 / 2;
character.y = 2732 / 2;
// Create trashCan
var trashCan = game.addChild(new TrashCan());
trashCan.x = 2048 / 2;
trashCan.y = 2732 / 2;
// Function to spawn a coin at a random position
function spawnCoin() {
var coin = new Coin();
coin.x = Math.random() * 2048;
coin.y = Math.random() * 2732;
coins.push(coin);
game.addChild(coin);
}
// Function to spawn a bum at a random position
function spawnBum() {
var bum = new Bum();
bum.x = trashCan.x;
bum.y = trashCan.y;
bums.push(bum);
game.addChild(bum);
}
// Handle move events
var dragNode = null;
function handleMove(x, y, obj) {
if (dragNode) {
dragNode.x = x;
dragNode.y = y;
}
// Check for coin collection
for (var i = coins.length - 1; i >= 0; i--) {
if (character.intersects(coins[i])) {
score += 1;
scoreTxt.setText('Score: ' + score.toString());
coins[i].destroy();
coins.splice(i, 1);
// Make the character faster when the score reaches 45
if (score == 45) {
character.speed = 5;
}
// Make all bums go mad after 45 coins
if (score >= 45) {
for (var j = 0; j < bums.length; j++) {
bums[j].mad = true;
}
}
}
}
// Check for collision with bums
for (var j = bums.length - 1; j >= 0; j--) {
if (character.intersects(bums[j])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
// Add score to leaderboard
}
// Check for collision with shoes
if (bums[j].shoeThrowing && character.intersects(bums[j].shoe)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
// Add score to leaderboard
}
}
// Squash the trashCan and show victory message when the big character steps on it
if (character.isBig && character.intersects(trashCan)) {
trashCan.scaleY = 0.5;
LK.gui.center.addChild(new Text2('Victory!', {
size: 150,
fill: "#ffffff"
}));
for (var j = 0; j < bums.length; j++) {
bums[j].destroy();
}
bums = [];
}
}
// Mouse or touch move on game object
game.move = function (x, y, obj) {
if (!character.stun) {
handleMove(x, y, obj);
}
};
// Allow dragging of the character to start from anywhere
game.down = function (x, y, obj) {
dragNode = character;
handleMove(x, y, obj);
};
// Mouse or touch up on game object
game.up = function (x, y, obj) {
dragNode = null;
};
// Update game every tick
game.update = function () {
for (var i = 0; i < coins.length; i++) {
coins[i].update();
}
for (var j = 0; j < bums.length; j++) {
bums[j].update();
// Make the bums go mad forever after 45 coins
if (score >= 45) {
for (var k = 0; k < bums.length; k++) {
bums[k].mad = true;
}
}
}
character.update();
// Spawn coins and bums at intervals
if (LK.ticks % 120 == 0) {
spawnCoin();
}
if (LK.ticks % 300 == 0) {
spawnBum();
}
};
МАЛЬЧИК ОДНА ШТУКА. Single Game Texture. In-Game asset. Мальчик
МОНЕТА. Single Game Texture. In-Game asset. МОНЕТА
БОМЖ. Single Game Texture. In-Game asset. БОМЖ
МУСОРКА. Single Game Texture. In-Game asset. МУСОРКА
БОТИНОК АДДИДАС. Single Game Texture. In-Game asset. БОТИНОК АДДИДАС
КВАДРАТ ТРАВЫ. Single Game Texture.КВАДРАТ ТРАВЫ