/****
* Classes
****/
var Hero = Container.expand(function () {
  var self = Container.call(this);
  var heroGraphics = self.attachAsset('hero', {
    anchorX: 0.5,
    anchorY: 0.5
  });
  self.speed = 5;
  self.move = function (direction) {
    if (direction === 'left') self.x -= self.speed;
    if (direction === 'right') self.x += self.speed;
    if (direction === 'up') self.y -= self.speed;
    if (direction === 'down') self.y += self.speed;
  };
  self.shoot = function () {
    var bullet = new Bullet();
    bullet.x = self.x;
    bullet.y = self.y;
    game.addChild(bullet);
    return bullet;
  };
});
var Monster = Container.expand(function () {
  var self = Container.call(this);
  var monsterGraphics = self.attachAsset('monster', {
    anchorX: 0.5,
    anchorY: 0.5
  });
  self.speed = 2;
  self.moveTowards = 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;
  };
});
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 Shop = Container.expand(function () {
  var self = Container.call(this);
  var shopGraphics = self.attachAsset('shop', {
    anchorX: 0.5,
    anchorY: 0.5
  });
  self.x = 2048 / 2;
  self.y = 2732 - 128;
});
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;
});
/****
* Initialize Game
****/
var game = new LK.Game({
  backgroundColor: 0x000000
});
/****
* Game Code
****/
var hero = game.addChild(new Hero());
hero.x = 2048 / 2;
hero.y = 2732 / 2;
var shop = game.addChild(new Shop());
var door = game.addChild(new Door());
var monsters = [];
var bullets = [];
game.on('down', function (obj) {
  var touchPos = obj.event.getLocalPosition(game);
  if (touchPos.x < 1024) {
    hero.move('left');
  } else {
    hero.move('right');
  }
});
game.on('up', function (obj) {
  bullets.push(hero.shoot());
});
LK.on('tick', function () {
  if (LK.ticks % 120 === 0) {
    // Spawn a monster every 2 seconds
    var monster = new Monster();
    monster.x = door.x;
    monster.y = door.y;
    monsters.push(monster);
    game.addChild(monster);
  }
  monsters.forEach(function (monster, index) {
    monster.moveTowards(hero.x, hero.y);
    if (monster.intersects(hero)) {
      LK.effects.flashScreen(0xff0000, 1000);
      LK.showGameOver();
    }
  });
  bullets.forEach(function (bullet, index) {
    bullet.move();
    if (bullet.y < 0) {
      bullet.destroy();
      bullets.splice(index, 1);
    } else {
      monsters.forEach(function (monster, mIndex) {
        if (bullet.intersects(monster)) {
          monster.destroy();
          monsters.splice(mIndex, 1);
          bullet.destroy();
          bullets.splice(index, 1);
          LK.setScore(LK.getScore() + 1);
        }
      });
    }
  });
}); /****
* Classes
****/
var Hero = Container.expand(function () {
  var self = Container.call(this);
  var heroGraphics = self.attachAsset('hero', {
    anchorX: 0.5,
    anchorY: 0.5
  });
  self.speed = 5;
  self.move = function (direction) {
    if (direction === 'left') self.x -= self.speed;
    if (direction === 'right') self.x += self.speed;
    if (direction === 'up') self.y -= self.speed;
    if (direction === 'down') self.y += self.speed;
  };
  self.shoot = function () {
    var bullet = new Bullet();
    bullet.x = self.x;
    bullet.y = self.y;
    game.addChild(bullet);
    return bullet;
  };
});
var Monster = Container.expand(function () {
  var self = Container.call(this);
  var monsterGraphics = self.attachAsset('monster', {
    anchorX: 0.5,
    anchorY: 0.5
  });
  self.speed = 2;
  self.moveTowards = 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;
  };
});
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 Shop = Container.expand(function () {
  var self = Container.call(this);
  var shopGraphics = self.attachAsset('shop', {
    anchorX: 0.5,
    anchorY: 0.5
  });
  self.x = 2048 / 2;
  self.y = 2732 - 128;
});
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;
});
/****
* Initialize Game
****/
var game = new LK.Game({
  backgroundColor: 0x000000
});
/****
* Game Code
****/
var hero = game.addChild(new Hero());
hero.x = 2048 / 2;
hero.y = 2732 / 2;
var shop = game.addChild(new Shop());
var door = game.addChild(new Door());
var monsters = [];
var bullets = [];
game.on('down', function (obj) {
  var touchPos = obj.event.getLocalPosition(game);
  if (touchPos.x < 1024) {
    hero.move('left');
  } else {
    hero.move('right');
  }
});
game.on('up', function (obj) {
  bullets.push(hero.shoot());
});
LK.on('tick', function () {
  if (LK.ticks % 120 === 0) {
    // Spawn a monster every 2 seconds
    var monster = new Monster();
    monster.x = door.x;
    monster.y = door.y;
    monsters.push(monster);
    game.addChild(monster);
  }
  monsters.forEach(function (monster, index) {
    monster.moveTowards(hero.x, hero.y);
    if (monster.intersects(hero)) {
      LK.effects.flashScreen(0xff0000, 1000);
      LK.showGameOver();
    }
  });
  bullets.forEach(function (bullet, index) {
    bullet.move();
    if (bullet.y < 0) {
      bullet.destroy();
      bullets.splice(index, 1);
    } else {
      monsters.forEach(function (monster, mIndex) {
        if (bullet.intersects(monster)) {
          monster.destroy();
          monsters.splice(mIndex, 1);
          bullet.destroy();
          bullets.splice(index, 1);
          LK.setScore(LK.getScore() + 1);
        }
      });
    }
  });
});
:quality(85)/https://cdn.frvr.ai/65c3a996c10ed5ddaec9a45d.png%3F3) 
 wooden door thats round at the top 8 bit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
:quality(85)/https://cdn.frvr.ai/65c3ab10c10ed5ddaec9a473.png%3F3) 
 wisard 8 bit from the top down. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
:quality(85)/https://cdn.frvr.ai/65c3ab78c10ed5ddaec9a47d.png%3F3) 
 tentacle monster 8 bit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
:quality(85)/https://cdn.frvr.ai/65c4e49ffc3df84f65ed6192.png%3F3) 
 8 bit tentacle monster. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
:quality(85)/https://cdn.frvr.ai/65c4f8d2fc3df84f65ed61e9.png%3F3) 
 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.
:quality(85)/https://cdn.frvr.ai/65c4fa9cfc3df84f65ed61f7.png%3F3) 
 8 bit fireball with a flame trail that goes down. Single Game Texture. In-Game asset. 2d. Blank background.. No shadows.
:quality(85)/https://cdn.frvr.ai/65c4fe1afc3df84f65ed622e.png%3F3) 
 just move the tentacles a tinny litle bit
:quality(85)/https://cdn.frvr.ai/65c5286cfc3df84f65ed6242.png%3F3) 
 make the monster move
:quality(85)/https://cdn.frvr.ai/65ce33c901cc0d9e6d0a2ef3.png%3F3) 
 green button 8 bit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.