var Wall = Container.expand(function () {
var self = Container.call(this);
self.createAsset('wall', 'Wall', 0, 0);
self.isBarrier = true;
});
var HeroBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.createAsset('heroBullet', 'Hero Bullet Graphics', .5, .5);
self.speed = -10;
self.move = function () {
self.x += self.speedX;
self.y += self.speedY;
};
self.timer = LK.setTimeout(function () {
self.destroy();
}, 2000);
});
var Hero = Container.expand(function () {
var self = Container.call(this);
self.update = function () {
if (self.dx && self.dy) {
self.x -= self.dx;
self.y -= self.dy;
self.dx *= 0.95;
self.dy *= 0.95;
if (Math.abs(self.dx) < 0.01 && Math.abs(self.dy) < 0.01) {
self.dx = 0;
self.dy = 0;
}
}
};
var heroGraphics = self.createAsset('hero', 'Hero character', .5, .5);
heroGraphics.rotation = 42 * (Math.PI / 180);
self.knockback = function (dx, dy) {
self.dx = -dx * 116.886 * 3.645;
self.dy = -dy * 116.886 * 3.645;
};
});
var Enemy = Container.expand(function () {
var self = Container.call(this);
self.graphics = self.createAsset('enemy', 'Enemy character', .5, .5);
self.followHero = function (hero) {
var dx = hero.x - self.x;
var dy = hero.y - self.y;
var mag = Math.sqrt(dx * dx + dy * dy);
self.x += 10 * dx / mag;
self.y += 10 * dy / mag;
};
});
var Game = Container.expand(function () {
var self = Container.call(this);
var enemies = [];
LK.stageContainer.setBackgroundColor(0x000000);
self.startingScene = true;
var startButton = self.createAsset('startButton', 'Start Button', .5, .5);
startButton.x = 1024;
startButton.y = 1366;
var hero;
startButton.on('down', function () {
self.removeChild(startButton);
hero = self.addChild(new Hero());
var enemies = [];
var newEnemy = self.addChild(new Enemy());
enemies.push(newEnemy);
hero.x = 1024;
hero.y = 1366;
self.startingScene = false;
});
var leftWall = self.addChild(new Wall());
leftWall.width = 81.92;
leftWall.height = 2732;
leftWall.x = 0;
leftWall.y = 0;
var rightWall = self.addChild(new Wall());
rightWall.width = 81.92;
rightWall.height = 2732;
rightWall.x = 2048 - 81.92;
rightWall.y = 0;
var topWall = self.addChild(new Wall());
topWall.width = 2048;
topWall.height = 109.28;
topWall.x = 0;
topWall.y = 0;
var bottomWall = self.addChild(new Wall());
bottomWall.width = 2048;
bottomWall.height = 109.28;
bottomWall.x = 0;
bottomWall.y = 2732 - 109.28;
var spawnEnemy = function () {
var newEnemy = self.addChild(new Enemy());
newEnemy.x = Math.random() * 2048;
newEnemy.y = Math.random() * 2732;
newEnemy.scale.x = newEnemy.scale.y = Math.random() * 2 + 0.5;
enemies.push(newEnemy);
LK.setTimeout(spawnEnemy, 2000);
};
LK.setTimeout(spawnEnemy, 2000);
var heroBullets = [];
var isGameOver = false;
var tickOffset = 0;
var fpsCounter = new Text2('0', {
size: 50,
fill: '#ffffff'
});
LK.gui.topCenter.addChild(fpsCounter);
var gameTimerCounter = new Text2('0', {
size: 50,
fill: '#ffffff'
});
gameTimerCounter.x = -50;
LK.gui.topRight.addChild(gameTimerCounter);
var gameStartTime = Date.now();
var lastTick = Date.now();
var frameCount = 0;
LK.on('tick', function () {
if (self.startingScene) {
return;
}
if (isGameOver) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
frameCount++;
var now = Date.now();
if (now - lastTick >= 1000) {
fpsCounter.setText(frameCount);
frameCount = 0;
lastTick = now;
var gameElapsedTime = Math.floor((now - gameStartTime) / 1000);
gameTimerCounter.setText(gameElapsedTime.toString());
}
hero.update();
if (hero.x < leftWall.width + 0.025 * 2048) hero.x = leftWall.width + 0.025 * 2048;
if (hero.x > 2048 - rightWall.width - 0.025 * 2048) hero.x = 2048 - rightWall.width - 0.025 * 2048;
if (hero.y < topWall.height + 0.025 * 2732) hero.y = topWall.height + 0.025 * 2732;
if (hero.y > 2732 - bottomWall.height - 0.025 * 2732) hero.y = 2732 - bottomWall.height - 0.025 * 2732;
enemies.forEach(function (enemy, index) {
enemy.followHero(hero);
for (var i = 0; i < enemies.length; i++) {
if (i !== index) {
var other = enemies[i];
var dx = enemy.x - other.x;
var dy = enemy.y - other.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < enemy.graphics.width) {
var overlap = enemy.graphics.width - distance;
var adjustX = overlap / 2 * (dx / distance);
var adjustY = overlap / 2 * (dy / distance);
enemy.x += adjustX;
enemy.y += adjustY;
other.x -= adjustX;
other.y -= adjustY;
}
}
}
if (hero.intersects(enemy)) {
isGameOver = true;
}
});
self.updateBullets = function () {
for (var a = heroBullets.length - 1; a >= 0; a--) {
heroBullets[a].move();
if (heroBullets[a].y > 2732 || heroBullets[a].x > 2048) {
heroBullets[a].destroy();
heroBullets.splice(a, 1);
}
for (var e = enemies.length - 1; e >= 0; e--) {
if (heroBullets[a] && enemies[e] && heroBullets[a].intersects(enemies[e])) {
var explosion = self.createAsset('explosion', 'Explosion Animation', .5, .5);
explosion.x = enemies[e].x;
explosion.y = enemies[e].y;
enemies[e].destroy();
enemies.splice(e, 1);
heroBullets[a].destroy();
heroBullets.splice(a, 1);
LK.setTimeout(function () {
explosion.destroy();
}, 1000);
break;
}
}
}
};
self.updateBullets();
var lastBulletTime = 0;
var bulletFireRate = 500;
var lastTouchTime = 0;
var touchDelay = 10000;
stage.on('down', function (obj) {
if (self.startingScene) {
self.startingScene = false;
return;
}
var now = Date.now();
if (now - lastTouchTime < touchDelay) return;
lastTouchTime = now;
if (now - lastBulletTime < bulletFireRate) return;
lastBulletTime = now;
var event = obj.event;
var pos = event.getLocalPosition(self);
var newBullet = new HeroBullet();
newBullet.x = hero.x;
newBullet.y = hero.y;
var dx = pos.x - hero.x;
var dy = pos.y - hero.y;
var mag = Math.sqrt(dx * dx + dy * dy);
newBullet.speedX = 10 * dx / mag;
newBullet.speedY = 10 * dy / mag;
heroBullets.push(newBullet);
self.addChild(newBullet);
hero.knockback(-dx / (mag * 10), -dy / (mag * 10));
if (dx < 0) {
hero.scale.x = 1;
} else {
hero.scale.x = -1;
}
});
});
});
watergun Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
water ball Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
water health bar Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
fire Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
blue play button Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
explosion smoke Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.