/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// House class to represent each house in the game
var House = Container.expand(function () {
var self = Container.call(this);
var houseGraphics = self.attachAsset('house', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Update logic for house
};
});
// Player class to represent each player in the game
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Update logic for player
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Init game with sky blue background
});
/****
* Game Code
****/
// Initialize arrays and variables
var houses = [];
var players = [];
var selectedHouse = null;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Function to handle house selection
function handleHouseSelection(x, y, obj) {
var game_position = game.toLocal(obj.global);
for (var i = 0; i < houses.length; i++) {
if (houses[i].containsPoint(game_position)) {
selectedHouse = houses[i];
break;
}
}
}
// Function to handle house placement
function handleHousePlacement(x, y, obj) {
if (selectedHouse) {
var game_position = game.toLocal(obj.global);
selectedHouse.x = game_position.x;
selectedHouse.y = game_position.y;
selectedHouse = null;
}
}
// Function to update the score
function updateScore() {
var score = LK.getScore();
scoreTxt.setText(score);
}
// Initialize houses and players
for (var i = 0; i < 5; i++) {
var house = new House();
house.x = Math.random() * 2048;
house.y = Math.random() * 2732;
houses.push(house);
game.addChild(house);
}
for (var i = 0; i < 2; i++) {
var player = new Player();
player.x = Math.random() * 2048;
player.y = Math.random() * 2732;
players.push(player);
game.addChild(player);
}
// Event listeners
game.down = function (x, y, obj) {
handleHouseSelection(x, y, obj);
};
game.up = function (x, y, obj) {
handleHousePlacement(x, y, obj);
};
game.update = function () {
for (var i = 0; i < houses.length; i++) {
houses[i].update();
}
for (var i = 0; i < players.length; i++) {
players[i].update();
}
updateScore();
}; /****
* Classes
****/
//<Assets used in the game will automatically appear here>
// House class to represent each house in the game
var House = Container.expand(function () {
var self = Container.call(this);
var houseGraphics = self.attachAsset('house', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Update logic for house
};
});
// Player class to represent each player in the game
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Update logic for player
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Init game with sky blue background
});
/****
* Game Code
****/
// Initialize arrays and variables
var houses = [];
var players = [];
var selectedHouse = null;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Function to handle house selection
function handleHouseSelection(x, y, obj) {
var game_position = game.toLocal(obj.global);
for (var i = 0; i < houses.length; i++) {
if (houses[i].containsPoint(game_position)) {
selectedHouse = houses[i];
break;
}
}
}
// Function to handle house placement
function handleHousePlacement(x, y, obj) {
if (selectedHouse) {
var game_position = game.toLocal(obj.global);
selectedHouse.x = game_position.x;
selectedHouse.y = game_position.y;
selectedHouse = null;
}
}
// Function to update the score
function updateScore() {
var score = LK.getScore();
scoreTxt.setText(score);
}
// Initialize houses and players
for (var i = 0; i < 5; i++) {
var house = new House();
house.x = Math.random() * 2048;
house.y = Math.random() * 2732;
houses.push(house);
game.addChild(house);
}
for (var i = 0; i < 2; i++) {
var player = new Player();
player.x = Math.random() * 2048;
player.y = Math.random() * 2732;
players.push(player);
game.addChild(player);
}
// Event listeners
game.down = function (x, y, obj) {
handleHouseSelection(x, y, obj);
};
game.up = function (x, y, obj) {
handleHousePlacement(x, y, obj);
};
game.update = function () {
for (var i = 0; i < houses.length; i++) {
houses[i].update();
}
for (var i = 0; i < players.length; i++) {
players[i].update();
}
updateScore();
};