var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.createAsset('hero', 'Hero character', .5, .5);
self.speed = 20;
self.jump = function () {};
self.shoot = function () {};
self.moveLeft = function () {
self.x -= self.speed;
};
self.moveRight = function () {
self.x += self.speed;
};
self.healthBar = self.createAsset('highQualityHealthBar', 'High Quality Health Bar', 0, 0);
self.healthBar.width = 200;
self.healthBar.height = 20;
self.healthBar.x = 0;
self.healthBar.y = -self.height / 2 - self.healthBar.height / 2;
self.health = 100;
self.update = function (mouseX) {
if (self.x < mouseX) {
self.moveRight();
} else if (self.x > mouseX) {
self.moveLeft();
}
};
});
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.createAsset('enemy', 'Enemy character', .5, .5);
self.speed = 3;
self.health = 100;
self.move = function (targetX, targetY) {
if (self.x < targetX) {
self.x += self.speed;
} else if (self.x > targetX) {
self.x -= self.speed;
}
if (self.y < targetY) {
self.y += self.speed;
} else if (self.y > targetY) {
self.y -= self.speed;
}
};
self.attack = function () {};
});
var HeroBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.createAsset('heroBullet', 'Hero Bullet', .5, .5);
self.speed = 10;
self.target = null;
LK.setTimeout(function () {
self.destroy();
}, 5000);
self.move = function () {
if (self.target) {
var dx = self.target.x - self.x;
var dy = self.target.y - self.y;
var angle = Math.atan2(dy, dx);
self.x += Math.cos(angle) * self.speed;
self.y += Math.sin(angle) * self.speed;
bulletGraphics.rotation = angle;
} else {
self.x += self.speed;
}
};
});
var EnemyBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.createAsset('enemyBullet', 'Enemy Bullet', .5, .5);
self.speed = 7;
self.move = function () {};
});
var Game = Container.expand(function () {
var self = Container.call(this);
var background = self.createAsset('epicBackground', 'Epic Background', 0, 0);
background.width = 2048;
background.height = 2732;
self.on('move', function (obj) {
var event = obj.event;
var pos = event.getLocalPosition(self);
hero.x = pos.x;
hero.y = pos.y;
});
var bulletSpawnInterval = LK.setInterval(function () {
var nearestEnemy = enemies.length > 0 ? enemies.reduce((prev, curr) => {
var d1 = Math.hypot(hero.x - prev.x, hero.y - prev.y);
var d2 = Math.hypot(hero.x - curr.x, hero.y - curr.y);
return d1 < d2 ? prev : curr;
}) : null;
var bullet = new HeroBullet();
bullet.x = hero.x;
bullet.y = hero.y;
bullet.target = nearestEnemy;
heroBullets.push(bullet);
self.addChild(bullet);
}, 1000);
var hero = self.addChild(new Hero());
var enemies = [];
var enemySpawnInterval = LK.setInterval(function () {
for (var i = 0; i < 5; i++) {
var enemy = new Enemy();
enemy.x = Math.random() * 2048;
enemy.y = Math.random() * 2732;
enemies.push(enemy);
self.addChild(enemy);
}
}, 10000);
var heroBullets = [];
var enemyBullets = [];
hero.x = 724;
hero.y = 1366;
LK.on('tick', function () {
hero.update();
for (var i = 0; i < enemies.length; i++) {
enemies[i].move(hero.x, hero.y);
if (enemies[i].intersects(hero)) {
LK.setTimeout(function () {
hero.health -= 10;
hero.healthBar.width = hero.health;
if (hero.health <= 0) {
LK.showGameOver();
}
}, 1000);
}
for (var j = 0; j < heroBullets.length; j++) {
if (enemies[i] && heroBullets[j] && enemies[i].intersects(heroBullets[j])) {
enemies[i].health -= 10;
heroBullets[j].destroy();
if (enemies[i].health <= 0) {
enemies[i].destroy();
enemies.splice(i, 1);
} else {
enemies[i].tint = 0xFF0000 + 0x00FF00 * (enemies[i].health / 100);
}
}
}
}
for (var i = 0; i < heroBullets.length; i++) {
heroBullets[i].move();
}
for (var i = 0; i < enemyBullets.length; i++) {
enemyBullets[i].update();
}
});
LK.on('keydown', function (event) {
switch (event.key) {
case 'ArrowLeft':
hero.moveLeft();
break;
case 'ArrowRight':
hero.moveRight();
break;
case 'Space':
hero.jump();
break;
case 'Control':
hero.shoot();
break;
}
});
});
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.createAsset('hero', 'Hero character', .5, .5);
self.speed = 20;
self.jump = function () {};
self.shoot = function () {};
self.moveLeft = function () {
self.x -= self.speed;
};
self.moveRight = function () {
self.x += self.speed;
};
self.healthBar = self.createAsset('highQualityHealthBar', 'High Quality Health Bar', 0, 0);
self.healthBar.width = 200;
self.healthBar.height = 20;
self.healthBar.x = 0;
self.healthBar.y = -self.height / 2 - self.healthBar.height / 2;
self.health = 100;
self.update = function (mouseX) {
if (self.x < mouseX) {
self.moveRight();
} else if (self.x > mouseX) {
self.moveLeft();
}
};
});
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.createAsset('enemy', 'Enemy character', .5, .5);
self.speed = 3;
self.health = 100;
self.move = function (targetX, targetY) {
if (self.x < targetX) {
self.x += self.speed;
} else if (self.x > targetX) {
self.x -= self.speed;
}
if (self.y < targetY) {
self.y += self.speed;
} else if (self.y > targetY) {
self.y -= self.speed;
}
};
self.attack = function () {};
});
var HeroBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.createAsset('heroBullet', 'Hero Bullet', .5, .5);
self.speed = 10;
self.target = null;
LK.setTimeout(function () {
self.destroy();
}, 5000);
self.move = function () {
if (self.target) {
var dx = self.target.x - self.x;
var dy = self.target.y - self.y;
var angle = Math.atan2(dy, dx);
self.x += Math.cos(angle) * self.speed;
self.y += Math.sin(angle) * self.speed;
bulletGraphics.rotation = angle;
} else {
self.x += self.speed;
}
};
});
var EnemyBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.createAsset('enemyBullet', 'Enemy Bullet', .5, .5);
self.speed = 7;
self.move = function () {};
});
var Game = Container.expand(function () {
var self = Container.call(this);
var background = self.createAsset('epicBackground', 'Epic Background', 0, 0);
background.width = 2048;
background.height = 2732;
self.on('move', function (obj) {
var event = obj.event;
var pos = event.getLocalPosition(self);
hero.x = pos.x;
hero.y = pos.y;
});
var bulletSpawnInterval = LK.setInterval(function () {
var nearestEnemy = enemies.length > 0 ? enemies.reduce((prev, curr) => {
var d1 = Math.hypot(hero.x - prev.x, hero.y - prev.y);
var d2 = Math.hypot(hero.x - curr.x, hero.y - curr.y);
return d1 < d2 ? prev : curr;
}) : null;
var bullet = new HeroBullet();
bullet.x = hero.x;
bullet.y = hero.y;
bullet.target = nearestEnemy;
heroBullets.push(bullet);
self.addChild(bullet);
}, 1000);
var hero = self.addChild(new Hero());
var enemies = [];
var enemySpawnInterval = LK.setInterval(function () {
for (var i = 0; i < 5; i++) {
var enemy = new Enemy();
enemy.x = Math.random() * 2048;
enemy.y = Math.random() * 2732;
enemies.push(enemy);
self.addChild(enemy);
}
}, 10000);
var heroBullets = [];
var enemyBullets = [];
hero.x = 724;
hero.y = 1366;
LK.on('tick', function () {
hero.update();
for (var i = 0; i < enemies.length; i++) {
enemies[i].move(hero.x, hero.y);
if (enemies[i].intersects(hero)) {
LK.setTimeout(function () {
hero.health -= 10;
hero.healthBar.width = hero.health;
if (hero.health <= 0) {
LK.showGameOver();
}
}, 1000);
}
for (var j = 0; j < heroBullets.length; j++) {
if (enemies[i] && heroBullets[j] && enemies[i].intersects(heroBullets[j])) {
enemies[i].health -= 10;
heroBullets[j].destroy();
if (enemies[i].health <= 0) {
enemies[i].destroy();
enemies.splice(i, 1);
} else {
enemies[i].tint = 0xFF0000 + 0x00FF00 * (enemies[i].health / 100);
}
}
}
}
for (var i = 0; i < heroBullets.length; i++) {
heroBullets[i].move();
}
for (var i = 0; i < enemyBullets.length; i++) {
enemyBullets[i].update();
}
});
LK.on('keydown', function (event) {
switch (event.key) {
case 'ArrowLeft':
hero.moveLeft();
break;
case 'ArrowRight':
hero.moveRight();
break;
case 'Space':
hero.jump();
break;
case 'Control':
hero.shoot();
break;
}
});
});
Hero Character for platformer game Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Enemy turtle for survival game Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Bullet from bullethell Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
healthbar Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Epic brawl stars styled Background Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.