/****
* Classes
****/
var CooldownButton = Container.expand(function () {
var self = Container.call(this);
self.attachAsset('button', {
anchorX: 0.0,
// Bottom left anchor x-coordinate
anchorY: 1.0 // Bottom left anchor y-coordinate
});
self.x = 0; // Position x-coordinate at bottom left
self.y = 2732; // Position y-coordinate at bottom left
self.on('down', function () {
if (LK.getScore() >= 100) {
var newScore = LK.getScore() - 100;
if (newScore >= 0) {
LK.setScore(newScore);
hero.shootCooldown = Math.max(0, hero.shootCooldown - 15); // Reduce cooldown by 0.25 seconds (15 frames at 60FPS)
}
}
});
});
// Add CooldownButton to the game
var Button = Container.expand(function () {
var self = Container.call(this);
self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
self.on('down', function () {
LK.setScore(LK.getScore() - 100);
hero.shootCooldown = Math.max(0, hero.shootCooldown - 15); // 0.25 seconds at 60FPS
});
});
var Hero = Container.expand(function () {
var self = Container.call(this);
self.update = function () {
if (self.shootTimer > 0) {
self.shootTimer--;
}
};
self.destroyMonsters = function () {
monsters.forEach(function (monster) {
monster.destroy();
});
monsters.length = 0;
LK.setScore(LK.getScore() + monsters.length);
};
var heroGraphics = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.move = function (targetX, targetY) {
var dx = targetX - self.x;
var dy = targetY - self.y;
var angle = Math.atan2(dy, dx);
self.x += Math.cos(angle) * self.speed;
self.y += Math.sin(angle) * self.speed;
};
self.shootCooldown = 120; // 2 seconds at 60FPS
self.shootTimer = 0;
self.shoot = function () {
if (self.shootTimer <= 0) {
var bullet = new Bullet();
bullet.x = self.x;
bullet.y = self.y;
game.addChild(bullet);
self.shootTimer = self.shootCooldown;
return bullet;
}
return null;
};
});
var StrongerMonster = Container.expand(function () {
var self = Container.call(this);
var monsterGraphics = self.attachAsset('strongMonster', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 5;
self.speed = 2;
self.hit = false;
self.hitTimer = 0;
self.update = function () {
if (self.hit) {
self.hitTimer--;
if (self.hitTimer <= 0) {
self.hit = false;
}
}
};
self.moveTowards = function (targetX, targetY) {
var dx = targetX - self.x;
var dy = targetY - self.y;
var angle = Math.atan2(dy, dx);
var newX = self.x + Math.cos(angle) * self.speed;
var newY = self.y + Math.sin(angle) * self.speed;
if (!self.hit) {
self.x = newX;
self.y = newY;
}
};
});
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.move = function () {
self.y -= self.speed;
};
});
var Door = Container.expand(function () {
var self = Container.call(this);
var doorGraphics = self.attachAsset('door', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = 2048 / 2;
self.y = 128;
});
var WeakerMonster = Container.expand(function () {
var self = Container.call(this);
self.animationFrames = ['monster_walk1', 'monster_walk2', 'monster_walk3', 'monster_walk4'];
self.currentFrameIndex = 0;
self.frameCounter = 0;
self.frameChangeRate = 15; // Change frame every 15 ticks (1/4 second at 60FPS)
self.monsterGraphics = self.attachAsset(self.animationFrames[self.currentFrameIndex], {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 2;
self.speed = 2;
self.hit = false;
self.hitTimer = 0;
self.update = function () {
if (self.hit) {
self.hitTimer--;
if (self.hitTimer <= 0) {
self.hit = false;
}
}
// Handle walking animation
self.frameCounter++;
if (self.frameCounter >= self.frameChangeRate) {
self.currentFrameIndex = (self.currentFrameIndex + 1) % self.animationFrames.length;
self.monsterGraphics.texture = LK.getAsset(self.animationFrames[self.currentFrameIndex], {}).texture;
self.frameCounter = 0;
}
};
self.moveTowards = function (targetX, targetY) {
var dx = targetX - self.x;
var dy = targetY - self.y;
var angle = Math.atan2(dy, dx);
var newX = self.x + Math.cos(angle) * self.speed;
var newY = self.y + Math.sin(angle) * self.speed;
if (!self.hit) {
self.x = newX;
self.y = newY;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game();
/****
* Game Code
****/
// Add CooldownButton to the game
game.on('move', function (obj) {
var event = obj.event;
var pos = event.getLocalPosition(game);
hero.move(pos.x, pos.y);
});
var cooldownButton = game.addChild(new CooldownButton());
var button = game.addChild(new Button());
button.x = 100;
button.y = 2732 - 100;
// Score bar at the top
var scoreBar = new Text2('0', {
size: 150,
fill: "#ffffff",
anchorX: 0.5,
anchorY: 0
});
LK.gui.top.addChild(scoreBar);
var background = game.attachAsset('stoneBrickFloor', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
var hero = game.addChild(new Hero());
hero.x = 2048 / 2;
hero.y = 2732 / 2;
// Add keyboard event listeners for arrow key movement and space for destroying monsters
LK.on('keydown', function (obj) {
var event = obj.event;
switch (event.key) {
case 'ArrowLeft':
hero.move('left');
break;
case 'ArrowRight':
hero.move('right');
break;
case 'ArrowUp':
hero.move('up');
break;
case 'ArrowDown':
hero.move('down');
break;
case ' ':
// Space key
hero.destroyMonsters();
break;
}
});
var door = game.addChild(new Door());
var monsters = [];
var bullets = [];
game.on('up', function (obj) {
bullets.push(hero.shoot());
});
LK.on('tick', function () {
// Increment score every second
if (LK.ticks % 60 === 0) {
LK.setScore(LK.getScore() + 1);
scoreBar.setText(LK.getScore().toString());
}
hero.update();
var spawnRate = LK.getScore() >= 80 ? 300 : LK.getScore() >= 50 ? 360 : 420;
var spawnWeakCounter = 0;
var spawnStrong = false;
var strongMonsterExists = false;
var spawnDelayTimer = 0;
var spawnDelayDuration = 300; // 5 seconds at 60FPS
if (strongMonsterExists) {
var strongMonster = monsters.find(function (monster) {
return monster instanceof StrongerMonster;
});
if (!strongMonster) {
strongMonsterExists = false;
spawnDelayTimer = spawnDelayDuration;
}
}
if (spawnDelayTimer > 0) {
spawnDelayTimer--;
} else if (spawnWeakCounter < 4 && LK.ticks % spawnRate === 0) {
var monster = new WeakerMonster();
monster.x = door.x;
monster.y = door.y;
monsters.push(monster);
game.addChild(monster);
spawnWeakCounter++;
} else if (spawnWeakCounter >= 4 && !strongMonsterExists && spawnDelayTimer === 0) {
var strongMonster = new StrongerMonster();
strongMonster.x = door.x;
strongMonster.y = door.y;
monsters.push(strongMonster);
game.addChild(strongMonster);
strongMonsterExists = true;
spawnWeakCounter = 0;
}
monsters.forEach(function (monster, index) {
monster.update();
monster.moveTowards(hero.x, hero.y);
if (monster.intersects(hero)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
if (monster instanceof StrongerMonster && monster.health <= 0) {
strongMonsterExists = false;
}
});
bullets.forEach(function (bullet, index) {
if (bullet) {
bullet.move();
}
if (bullet && bullet.y < 0) {
bullet.destroy();
bullets.splice(index, 1);
} else {
monsters.forEach(function (monster, mIndex) {
if (bullet && bullet.intersects(monster)) {
monster.health -= 1;
monster.hit = true;
monster.hitTimer = 30; // 0.5 seconds at 60FPS
if (monster.health <= 0) {
monster.destroy();
monsters.splice(mIndex, 1);
LK.setScore(LK.getScore() + 1);
}
bullet.destroy();
bullets.splice(index, 1);
}
});
}
});
});
wooden door thats round at the top 8 bit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
wisard 8 bit from the top down. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
tentacle monster 8 bit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
8 bit tentacle monster. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
8 bit stone brick dungeon floor with a tiny amount of moss with tinny little bricks and very low contrast make it darker to. Single Game Texture. In-Game asset. 2d. Blank background.. No shadows.
8 bit fireball with a flame trail that goes down. Single Game Texture. In-Game asset. 2d. Blank background.. No shadows.
just move the tentacles a tinny litle bit
make the monster move
green button 8 bit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.