/****
* Classes
****/
var ScoreCounter = Container.expand(function () {
var self = Container.call(this);
var score = 0;
var scoreIcon = self.createAsset('scoreIcon', 'Score Icon', 0, 0.5);
scoreIcon.x += 814;
scoreIcon.y += 150;
var scoreText = new Text2(score.toString(), {
size: 150,
fill: '#ffffff',
align: 'left'
});
scoreText.anchor.set(0.5, 0);
scoreText.x = game.width / 2;
scoreText.y = scoreIcon.height / 2;
self.addChild(scoreIcon);
self.addChild(scoreText);
self.updateScore = function (newScore) {
score = newScore;
scoreText.setText(score.toString());
};
});
var Timer = Container.expand(function () {
var self = Container.call(this);
var timeLeft = 120;
var timerText = new Text2(timeLeft.toString(), {
size: 150,
fill: '#ffffff'
});
self.addChild(timerText);
timerText.setText(timeLeft);
self.update = function () {
if (timeLeft > 0) {
timeLeft -= 1 / 60;
timerText.setText(Math.ceil(timeLeft));
} else {
LK.showGameOver();
}
};
});
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.createAsset('enemy', 'Enemy Graphics', 0.5, 0.5);
self.direction = Math.random() < 0.5 ? 1 : -1;
self.diagonal = Math.random() < 0.33;
self.speed = (2 + Math.random() * 3) * 2;
self.move = function () {
self.x += self.speed * self.direction + Math.sin(LK.ticks / 10) * 5;
if (self.direction === 1) {
enemyGraphics.scale.x = -1;
} else if (self.direction === -1) {
enemyGraphics.scale.x = 1;
}
// Add wiggle movement on the y-axis with increased amplitude
self.y += Math.sin(LK.ticks / 10) * 10;
if (self.diagonal) {
self.y += self.speed * (Math.random() < 0.5 ? 1 : -1);
}
if (self.x < -enemyGraphics.width || self.x > 2048 + enemyGraphics.width || self.y < -enemyGraphics.height || self.y > 2732 + enemyGraphics.height) {
self.destroy();
}
};
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.createAsset('player', 'Player Graphics', 0.5, 0.5);
playerGraphics.scale.set(3);
self.speed = 5;
self.move = function (direction) {
var wiggle = Math.sin(LK.ticks / 5) * 3;
switch (direction) {
case 'left':
self.x -= self.speed + wiggle;
break;
case 'right':
self.x += self.speed + wiggle;
break;
case 'up':
self.y -= self.speed + wiggle;
break;
case 'down':
self.y += self.speed + wiggle;
break;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Add background asset
var background = game.createAsset('background', 'Game Background', 0, 0);
background.width = game.width;
background.height = game.height;
background.x = game.width / 2;
background.y = game.height / 2;
background.pivot.set(background.width / 2, background.height / 2);
game.addChild(background);
var playerInstance = game.addChild(new Player());
playerInstance.x = game.width / 2;
playerInstance.y = game.height - playerInstance.height;
LK.on('tick', function () {
timerInstance.update();
scoreCounterInstance.updateScore(LK.getScore());
});
var enemies = [];
function initializeEnemies() {
for (var i = 0; i < 5; i++) {
var newEnemy = new Enemy();
newEnemy.x = Math.random() * (2048 - newEnemy.width) + newEnemy.width / 2;
newEnemy.y = Math.random() * (2732 - newEnemy.height) + newEnemy.height / 2;
enemies.push(newEnemy);
game.addChild(newEnemy);
}
}
initializeEnemies();
LK.on('tick', function () {
timerInstance.update();
scoreCounterInstance.updateScore(LK.getScore());
manageEnemies();
});
function manageEnemies() {
if (LK.ticks % 60 === 0) {
for (var i = 0; i < 2; i++) {
var newEnemy = new Enemy();
newEnemy.x = Math.random() * (2048 - newEnemy.width) + newEnemy.width / 2;
newEnemy.y = Math.random() * (2732 - newEnemy.height) + newEnemy.height / 2;
enemies.push(newEnemy);
game.addChild(newEnemy);
}
}
for (var i = enemies.length - 1; i >= 0; i--) {
enemies[i].move();
if (playerInstance.intersects(enemies[i])) {
LK.setScore(LK.getScore() + 5);
scoreCounterInstance.updateScore(LK.getScore());
enemies[i].destroy();
enemies.splice(i, 1);
} else if (!enemies[i].parent) {
enemies.splice(i, 1);
}
}
}
var dragNode = null;
function handleMove(obj) {
var event = obj.event;
var pos = event.getLocalPosition(game);
if (dragNode) {
dragNode.x = pos.x;
dragNode.y = pos.y;
}
}
game.on('move', handleMove);
game.on('down', function (obj) {
dragNode = playerInstance;
handleMove(obj);
});
game.on('up', function (obj) {
dragNode = null;
});
var timerInstance = game.addChild(new Timer());
timerInstance.x = game.width - timerInstance.width - 20;
timerInstance.y = 20;
var scoreCounterInstance = game.addChild(new ScoreCounter());
scoreCounterInstance.x = 20;
scoreCounterInstance.y = 20;
game.addChild(scoreCounterInstance); /****
* Classes
****/
var ScoreCounter = Container.expand(function () {
var self = Container.call(this);
var score = 0;
var scoreIcon = self.createAsset('scoreIcon', 'Score Icon', 0, 0.5);
scoreIcon.x += 814;
scoreIcon.y += 150;
var scoreText = new Text2(score.toString(), {
size: 150,
fill: '#ffffff',
align: 'left'
});
scoreText.anchor.set(0.5, 0);
scoreText.x = game.width / 2;
scoreText.y = scoreIcon.height / 2;
self.addChild(scoreIcon);
self.addChild(scoreText);
self.updateScore = function (newScore) {
score = newScore;
scoreText.setText(score.toString());
};
});
var Timer = Container.expand(function () {
var self = Container.call(this);
var timeLeft = 120;
var timerText = new Text2(timeLeft.toString(), {
size: 150,
fill: '#ffffff'
});
self.addChild(timerText);
timerText.setText(timeLeft);
self.update = function () {
if (timeLeft > 0) {
timeLeft -= 1 / 60;
timerText.setText(Math.ceil(timeLeft));
} else {
LK.showGameOver();
}
};
});
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.createAsset('enemy', 'Enemy Graphics', 0.5, 0.5);
self.direction = Math.random() < 0.5 ? 1 : -1;
self.diagonal = Math.random() < 0.33;
self.speed = (2 + Math.random() * 3) * 2;
self.move = function () {
self.x += self.speed * self.direction + Math.sin(LK.ticks / 10) * 5;
if (self.direction === 1) {
enemyGraphics.scale.x = -1;
} else if (self.direction === -1) {
enemyGraphics.scale.x = 1;
}
// Add wiggle movement on the y-axis with increased amplitude
self.y += Math.sin(LK.ticks / 10) * 10;
if (self.diagonal) {
self.y += self.speed * (Math.random() < 0.5 ? 1 : -1);
}
if (self.x < -enemyGraphics.width || self.x > 2048 + enemyGraphics.width || self.y < -enemyGraphics.height || self.y > 2732 + enemyGraphics.height) {
self.destroy();
}
};
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.createAsset('player', 'Player Graphics', 0.5, 0.5);
playerGraphics.scale.set(3);
self.speed = 5;
self.move = function (direction) {
var wiggle = Math.sin(LK.ticks / 5) * 3;
switch (direction) {
case 'left':
self.x -= self.speed + wiggle;
break;
case 'right':
self.x += self.speed + wiggle;
break;
case 'up':
self.y -= self.speed + wiggle;
break;
case 'down':
self.y += self.speed + wiggle;
break;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Add background asset
var background = game.createAsset('background', 'Game Background', 0, 0);
background.width = game.width;
background.height = game.height;
background.x = game.width / 2;
background.y = game.height / 2;
background.pivot.set(background.width / 2, background.height / 2);
game.addChild(background);
var playerInstance = game.addChild(new Player());
playerInstance.x = game.width / 2;
playerInstance.y = game.height - playerInstance.height;
LK.on('tick', function () {
timerInstance.update();
scoreCounterInstance.updateScore(LK.getScore());
});
var enemies = [];
function initializeEnemies() {
for (var i = 0; i < 5; i++) {
var newEnemy = new Enemy();
newEnemy.x = Math.random() * (2048 - newEnemy.width) + newEnemy.width / 2;
newEnemy.y = Math.random() * (2732 - newEnemy.height) + newEnemy.height / 2;
enemies.push(newEnemy);
game.addChild(newEnemy);
}
}
initializeEnemies();
LK.on('tick', function () {
timerInstance.update();
scoreCounterInstance.updateScore(LK.getScore());
manageEnemies();
});
function manageEnemies() {
if (LK.ticks % 60 === 0) {
for (var i = 0; i < 2; i++) {
var newEnemy = new Enemy();
newEnemy.x = Math.random() * (2048 - newEnemy.width) + newEnemy.width / 2;
newEnemy.y = Math.random() * (2732 - newEnemy.height) + newEnemy.height / 2;
enemies.push(newEnemy);
game.addChild(newEnemy);
}
}
for (var i = enemies.length - 1; i >= 0; i--) {
enemies[i].move();
if (playerInstance.intersects(enemies[i])) {
LK.setScore(LK.getScore() + 5);
scoreCounterInstance.updateScore(LK.getScore());
enemies[i].destroy();
enemies.splice(i, 1);
} else if (!enemies[i].parent) {
enemies.splice(i, 1);
}
}
}
var dragNode = null;
function handleMove(obj) {
var event = obj.event;
var pos = event.getLocalPosition(game);
if (dragNode) {
dragNode.x = pos.x;
dragNode.y = pos.y;
}
}
game.on('move', handleMove);
game.on('down', function (obj) {
dragNode = playerInstance;
handleMove(obj);
});
game.on('up', function (obj) {
dragNode = null;
});
var timerInstance = game.addChild(new Timer());
timerInstance.x = game.width - timerInstance.width - 20;
timerInstance.y = 20;
var scoreCounterInstance = game.addChild(new ScoreCounter());
scoreCounterInstance.x = 20;
scoreCounterInstance.y = 20;
game.addChild(scoreCounterInstance);
pixel butterfly. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel butterfly looking left, showing the left profile. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Remove it and make it transparent
pixel sunny field height is bigger than width.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.