/**** * Classes ****/ // Class for Animal var Animal = Container.expand(function () { var self = Container.call(this); var animalGraphics = self.attachAsset('animal', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Logic for animal behavior }; }); // Class for Hero var Hero = Container.expand(function () { var self = Container.call(this); var heroGraphics = self.attachAsset('hero', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Logic for hero behavior }; }); //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Class for Pollution var Pollution = Container.expand(function () { var self = Container.call(this); var pollutionGraphics = self.attachAsset('pollution', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Logic for pollution behavior }; }); // Class for Tree var Tree = Container.expand(function () { var self = Container.call(this); var treeGraphics = self.attachAsset('tree', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Logic for tree behavior }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize arrays for game elements var pollutions = []; var trees = []; var animals = []; var hero; // Initialize game elements function initGameElements() { // Create hero hero = game.addChild(new Hero()); hero.x = 1024; // Center horizontally hero.y = 1366; // Center vertically // Create pollution for (var i = 0; i < 5; i++) { var pollution = new Pollution(); pollution.x = Math.random() * 2048; pollution.y = Math.random() * 2732; pollutions.push(pollution); game.addChild(pollution); } // Create trees for (var i = 0; i < 5; i++) { var tree = new Tree(); tree.x = Math.random() * 2048; tree.y = Math.random() * 2732; trees.push(tree); game.addChild(tree); } // Create animals for (var i = 0; i < 5; i++) { var animal = new Animal(); animal.x = Math.random() * 2048; animal.y = Math.random() * 2732; animals.push(animal); game.addChild(animal); } } // Handle game updates game.update = function () { // Update hero hero.update(); // Update pollution pollutions.forEach(function (pollution) { pollution.update(); }); // Update trees trees.forEach(function (tree) { tree.update(); }); // Update animals animals.forEach(function (animal) { animal.update(); }); }; // Initialize game elements initGameElements();
/****
* Classes
****/
// Class for Animal
var Animal = Container.expand(function () {
var self = Container.call(this);
var animalGraphics = self.attachAsset('animal', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Logic for animal behavior
};
});
// Class for Hero
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Logic for hero behavior
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for Pollution
var Pollution = Container.expand(function () {
var self = Container.call(this);
var pollutionGraphics = self.attachAsset('pollution', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Logic for pollution behavior
};
});
// Class for Tree
var Tree = Container.expand(function () {
var self = Container.call(this);
var treeGraphics = self.attachAsset('tree', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Logic for tree behavior
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize arrays for game elements
var pollutions = [];
var trees = [];
var animals = [];
var hero;
// Initialize game elements
function initGameElements() {
// Create hero
hero = game.addChild(new Hero());
hero.x = 1024; // Center horizontally
hero.y = 1366; // Center vertically
// Create pollution
for (var i = 0; i < 5; i++) {
var pollution = new Pollution();
pollution.x = Math.random() * 2048;
pollution.y = Math.random() * 2732;
pollutions.push(pollution);
game.addChild(pollution);
}
// Create trees
for (var i = 0; i < 5; i++) {
var tree = new Tree();
tree.x = Math.random() * 2048;
tree.y = Math.random() * 2732;
trees.push(tree);
game.addChild(tree);
}
// Create animals
for (var i = 0; i < 5; i++) {
var animal = new Animal();
animal.x = Math.random() * 2048;
animal.y = Math.random() * 2732;
animals.push(animal);
game.addChild(animal);
}
}
// Handle game updates
game.update = function () {
// Update hero
hero.update();
// Update pollution
pollutions.forEach(function (pollution) {
pollution.update();
});
// Update trees
trees.forEach(function (tree) {
tree.update();
});
// Update animals
animals.forEach(function (animal) {
animal.update();
});
};
// Initialize game elements
initGameElements();