       DD @DDÄLÄLÄ@LDDDDDD@D  DDDDD DD @DDDDDDDDDDDDDDDD@D  DDDDD                                                                 ""  ""Â,Â,Â ,"""""  """ """" ""  """""""""""""""  """ """"                                                                 ww pwwÇ|Ç|Çp|wwwww  wwwpwwww ww pwwwwwwwwwwwwwww  wwwpwwww                                                                 ˆˆ €ˆˆÈŒÈŒÈ€Œˆˆˆˆˆ  ˆˆˆ€ˆˆˆˆ ˆˆ €ˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆ  ˆˆˆ€ˆˆˆˆ                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                `fffvgffgvffgvffwwffgvfgffvpww """!""!""!""!""!"!""	€                                                ð                                                             Â<                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      `ff                    """                    ÌÌ       Ì     ÀÌÀÌÀÌ ÀÌ   ÀÌ   ÀÌ                                    fvgf ÀÌ   Ì        Ì   "ÀÌÌ   ÀÀ         Ì ÀÌÀÌ  ÌÌ  ÀÀ Ì Ì Ì   Ì   Ì  ÀÌÌÀ ÀÌ                            fgvf Ì ÀÌ Ì  Ì ÌÌÀÌÌ  "!À ÀÌ  ÌÌ        ÌÌ ÀÌ ÌÀÌ   ÀÀ Ì Ì  Ì ÌÀÌ   ÌÀÀÌÌÌÀ                           fgvf ÀÌ ÌÀÌ ÀÌÀÌ  Ì   "ÀÌ ÌÀÀ         Ì À ÌÌÀÌ   ÀÌ Ì Ì Ì   Ì   Ì ÀÌ                            fwwf  ÌÌ Ì ÀÌ ÀÌ  Ì   "!À  ÌÀÀ         ÌÌ ÀÌÌÌ Ì ÌÌ  À ÀÌÀÌ ÀÌ   ÀÌ   ÀÌÀÌÀÌ                            fgvf ÌÌ ÀÌ ÀÌ Ì ÌÌ ÀÌ  "ÀÌÌÀÌÀ Ì                                                                                 gffv                   """                                                                                            pww                                                                                                                                                                ÌÀ   Ì     ÀÌ                                                                                              À         ÌÌÀÌ ÀÌ  ÀÌÌ ÌÀÌÀÀ                                                                                     Ì         ÌÌÀÌÀÀ  ÀÌÌÀÌÀÀÀÀ                                                                                     À         ÀÌÀÀ  ÀÀÀÀÌ ÀÀÀÀ                                                                                     À          ÀÌÌÀÀ  À À ÌÀÀ Ì                                                                                     ÌÌ                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 "" "                                                                                                                    " "  ""  "                                                                                                             " "   "  "                                                                                                             "" "   " ""                                                                                                             "   " ""  "                                                                                                                      "                                                                                                                                                                                                                                                                                                                                                             ÀÌ    À Ì                                                                                                              Ì ÌÌ ÌÌ  ÌÀÌ ÌÌ                                                                                                     Ì Ì À ÌÀÀÀÀÀÌ                                                                                                      Ì Ì À ÌÀÀÀÀ ÀÌ                                                                                                     ÀÌ ÌÌ  ÌÌ ÌÀÀÀÌ                                                                                                        Ì                                                                                                                                                                                                                                                                                                                                                                    ÌÌ   Ì Ì                                                                                                               Ì  ÌÀ ÀÌÌ                                                                                                              ÌÌ ÀÌ Ì Ì                                                                                                               Ì  ÀÌ Ì Ì                                                                                                               ÌÌÌÀÌ ÀÌ                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               Ì      Ì  À               À            ÀÌÀ       À  Ì          À              Ì   Ì À   ÌÌÀÌ ÌÌ      ÀÌ ÌÀÌÀÌÌ Ì ÌÌ  ÀÌÀ Ì  ÀÌ Ì ÌÌÀÌ ÌÀÌ     Ì   ÌÀÀÌ ÀÌ  ÌÌ À  ÀÌÌÌÀÌ Ì ÀÌ ÌÌ À ÀÌ Ì   ÌÀÌ  ÌÀÌ        ÀÀÀÀÀÀ Ì ÀÌÀ Ì  ÀÀÀ Ì  ÀÀÀÌÀÌ ÀÀÀÀ Ì    ÀÌÌÀÀÌ ÌÀÀ  Ì À  Ì À ÌÀÌ ÌÀÌ ÌÌÌÀÌ ÀÀÌ ÌÌ ÌÌÌ       ÀÀÀÀÀ  Ì ÀÌ À Ì  ÀÀ ÌÌ  ÀÀÀÌ  ÀÌÀÀÀÀ Ì     Ì ÀÀÌ Ì À  Ì ÀÌ   ÌÀ Ì ÀÌ Ì Ì À Ì Ì ÀÀÌ  ÀÌ  À      ÀÌ ÌÀ  ÀÌ Ì ÌÌ  ÀÌ  Ì  ÀÀ ÌÀÌÀÌ ÌÀÌ     Ì ÀÌÀÀÌ ÀÌ  ÌÌ  À  ÌÌ  ÌÀÌ   ÀÌ Ì À ÀÌ ÀÌÀÌÀÌÌ ÀÌ ÌÌ       À                      Ì                                           ÀÌ5 -- title:   Basic Game
-- author:  nesbox & stevenfelix505
-- desc:    Basic PICO-8 Game ported into TIC-80
-- script:  lua

-- only for developers...
debug_mode = 0
developer_mode = 0
-- gamestate (don't change it's value if you insist)
in_progress = 0
start_end_game = 1
game_over = 2
-- ui scrolling state (keep away from 0)
menustate = 0
game_over_menustate = 0
optionsstate = 0
pause_menustate = 0
-- options value
soundval = 0
invincibleval = 0
playerspeedval = 2
enemycountval = 1
enemyspeedval = 1
enemyspeedincrval = 0.0005

left=2 right=3 up=0 down=1
valid_moves = {left,right,up,down}

rnd=math.random
flr=math.floor
sqrt=math.sqrt

function _init()
 player = {}
 player.x = flr(rnd(216)+8)
 player.y = flr(rnd(114)+8)
 player.startsprite = 0
 player.endsprite = 1
 player.sprite = 0
 player.speed = playerspeedval
 player.stuck = 0

 enemy = {}
 enemy.x = flr(rnd(216)+8)
 enemy.y = flr(rnd(114)+8)
 enemy.startsprite = 4
 enemy.endsprite = 5
 enemy.sprite = 4
 enemy.speed = enemyspeedval
 enemy.stuck = 0

 enemy2 = {}
 enemy2.x = flr(rnd(216)+8)
 enemy2.y = flr(rnd(114)+8)
 enemy2.startsprite = 8
 enemy2.endsprite = 9
 enemy2.sprite = 8
 enemy2.speed = enemyspeedval
 enemy2.stuck = 0

 enemy3 = {}
 enemy3.x = flr(rnd(216)+8)
 enemy3.y = flr(rnd(114)+8)
 enemy3.startsprite = 12
 enemy3.endsprite = 13
 enemy3.sprite = 12
 enemy3.speed = enemyspeedval
 enemy3.stuck = 0

 state = menu
 score = 0
end

function menu()
 print("Select   Exit",164,8,12)
 spr(254,154,7)
 spr(255,201,7)
 print("Basic PICO-8 Game",8,8,12)
 print(menustate+1,226,16,12)
 print("Main Menu",8,16,12)
 print("ported by nesbox  fixed by stevenfelix505",7,124,12)
 print("Play",8,26,12)
 print("Options",8,34,12)
 print("Exit",8,42,12)
 if menustate == 0 then
  print("Play",8,26,2)
  if btnp(0) then
   menustate = 2
  elseif btnp(1) then
   menustate = 1
  elseif btnp(4) then
   state = in_progress
  end
 elseif menustate == 1 then
  print("Options",8,34,2)
  if btnp(0) then
   menustate = 0
  elseif btnp(1) then
   menustate = 2
  elseif btnp(4) then
   state = options
  end
 elseif menustate == 2 then
  print("Exit",8,42,2)
  if btnp(0) then
   menustate = 1
  elseif btnp(1) then
   menustate = 0
  elseif btnp(4) then
   exit()
  end
 end
 if btnp(5) then
  exit()
 end
end

function game_over_menu()
 print("Select   Main Menu",136,8,12)
 spr(254,126,7)
 spr(255,173,7)
 print("Final score = "..score,8,8,12)
 print(game_over_menustate+1,226,16,12)
 print("Game Over",8,16,12)
 print("ported by nesbox  fixed by stevenfelix505",7,124,12)
 print("Retry",8,26,12)
 print("Main Menu",8,34,12)
 print("Exit",8,42,12)
 if game_over_menustate == 0 then
  print("Retry",8,26,2)
  if btnp(0) then
   game_over_menustate = 2
  elseif btnp(1) then
   game_over_menustate = 1
  elseif btnp(4) then
   _init()
   state = in_progress
  end
 elseif game_over_menustate == 1 then
  print("Main Menu",8,34,2)
  if btnp(0) then
   game_over_menustate = 0
  elseif btnp(1) then
   game_over_menustate = 2
  elseif btnp(4) then
   _init()
  end
 elseif game_over_menustate == 2 then
  print("Exit",8,42,2)
  if btnp(0) then
   game_over_menustate = 1
  elseif btnp(1) then
   game_over_menustate = 0
  elseif btnp(4) then
   exit()
  end
 end
 if btnp(5) then
  _init()
 end
end

function options()
 print("Select   Back",161,8,12)
 spr(254,151,7)
 spr(255,198,7)
 print("Basic PICO-8 Game",8,8,12)
 print(optionsstate+1,226,16,12)
 print("Options",8,16,12)
 print("ported by nesbox  fixed by stevenfelix505",7,124,12)
 print("Sound Volume = "..soundval,8,26,12)
 if developer_mode == 0 then
  print("Enemy Count = "..enemycountval,8,34,12)
  print("Back",8,42,12)
 elseif developer_mode == 1 then
  print("Invincible = "..invincibleval,8,34,12)
  print("Player Speed = "..playerspeedval,8,42,12)
  print("Enemy Count = "..enemycountval,8,50,12)
  print("Enemy Speed = "..enemyspeedval,8,58,12)
  print("Enemy Speed Increase = "..enemyspeedincrval,8,66,12)
  print("Back",8,74,12)
 end
 if optionsstate == 0 then
  print("Sound Volume = "..soundval,8,26,2)
  if btnp(0) then
   if developer_mode == 0 then
    optionsstate = 2
   elseif developer_mode == 1 then
    optionsstate = 6
   end
  elseif btnp(1) then
   optionsstate = 1
  elseif btnp(2) then
   soundval = soundval-1
  elseif btnp(3) then
   soundval = soundval+1
  end
 elseif optionsstate == 1 then
  if developer_mode == 0 then
   print("Enemy Count = "..enemycountval,8,34,2)
  elseif developer_mode == 1 then
   print("Invincible = "..invincibleval,8,34,2)
  end
  if btnp(0) then
   optionsstate = 0
  elseif btnp(1) then
   optionsstate = 2
  elseif btnp(2) then
   if developer_mode == 0 then
    enemycountval = enemycountval-1
   elseif developer_mode == 1 then
    invincibleval = invincibleval-1
   end
  elseif btnp(3) then
   if developer_mode == 0 then
    enemycountval = enemycountval+1
   elseif developer_mode == 1 then
    invincibleval = invincibleval+1
   end
  end
 elseif optionsstate == 2 then
  if developer_mode == 0 then
   print("Back",8,42,2)
  elseif developer_mode == 1 then
   print("Player Speed = "..playerspeedval,8,42,2)
  end
  if btnp(0) then
   optionsstate = 1
  elseif btnp(1) then
   if developer_mode == 0 then
    optionsstate = 0
   elseif developer_mode == 1 then
    optionsstate = 3
   end
  elseif btnp(2) then
   if developer_mode == 1 then
    playerspeedval = playerspeedval-1
   end
  elseif btnp(3) then
   if developer_mode == 1 then
    playerspeedval = playerspeedval+1
   end
  elseif btnp(4) then
   if developer_mode == 0 then
    _init()
   end
  end
 elseif optionsstate == 3 then
  print("Enemy Count = "..enemycountval,8,50,2)
  if btnp(0) then
   optionsstate = 2
  elseif btnp(1) then
   optionsstate = 4
  elseif btnp(2) then
   enemycountval = enemycountval-1
  elseif btnp(3) then
   enemycountval = enemycountval+1
  end
 elseif optionsstate == 4 then
  print("Enemy Speed = "..enemyspeedval,8,58,2)
  if btnp(0) then
   optionsstate = 3
  elseif btnp(1) then
   optionsstate = 5
  elseif btnp(2) then
   enemyspeedval = enemyspeedval-1
  elseif btnp(3) then
   enemyspeedval = enemyspeedval+1
  end
 elseif optionsstate == 5 then
  print("Enemy Speed Increase = "..enemyspeedincrval,8,66,2)
  if btnp(0) then
   optionsstate = 4
  elseif btnp(1) then
   optionsstate = 6
  elseif btnp(2) then
   enemyspeedincrval = enemyspeedincrval-0.0001
  elseif btnp(3) then
   enemyspeedincrval = enemyspeedincrval+0.0001
  end
 elseif optionsstate == 6 then
  print("Back",8,74,2)
  if btnp(0) then
   optionsstate = 5
  elseif btnp(1) then
   optionsstate = 0
  elseif btnp(4) then
   _init()
  end
 end
 if btnp(5) then
  _init()
 end
end

function pause_menu()
 print("Select   Resume",148,8,12)
 spr(254,138,7)
 spr(255,185,7)
 print("Basic PICO-8 Game",8,8,12)
 print(pause_menustate+1,224,16,12)
 print("Paused",8,16,12)
 print("ported by nesbox  fixed by stevenfelix505",7,124,12)
 print("Resume",8,26,12)
 print("Retry",8,34,12)
 print("Main Menu",8,42,12)
 print("Exit",8,50,12)
 if pause_menustate == 0 then
  print("Resume",8,26,2)
  if btnp(0) then
   pause_menustate = 3
  elseif btnp(1) then
   pause_menustate = 1
  elseif btnp(4) then
   state = in_progress
  end
 elseif pause_menustate == 1 then
  print("Retry",8,34,2)
  if btnp(0) then
   pause_menustate = 0
  elseif btnp(1) then
   pause_menustate = 2
  elseif btnp(4) then
   _init()
   state = in_progress
  end
 elseif pause_menustate == 2 then
  print("Main Menu",8,42,2)
  if btnp(0) then
   pause_menustate = 1
  elseif btnp(1) then
   pause_menustate = 3
  elseif btnp(4) then
   _init()
  end
 elseif pause_menustate == 3 then
  print("Exit",8,50,2)
  if btnp(0) then
   pause_menustate = 2
  elseif btnp(1) then
   pause_menustate = 0
  elseif btnp(4) then
   exit()
  end
 end
 if btnp(5) then
  state = in_progress
 end
end

function move(unit)
 unit.sprite = unit.sprite+1
 if unit.sprite > unit.endsprite then
  unit.sprite = unit.startsprite
 end
end

function draw_unit(unit) spr(unit.sprite, unit.x, unit.y) end
function get_map_cell(unit) return mget(flr((unit.x+4)/8), flr((unit.y-4)/8)) end

function hit_house(unit) return get_map_cell(unit) == 16 end

function move_unit(unit, direction)
 unit.moving = false

 if hit_house(unit) then
  unit.stuck = unit.stuck+1
 if unit.stuck > 4 then
  unit.stuck = 0
 else
 return
 end
end

if direction == left and
unit.x - unit.speed > 8 then
unit.x =unit.x- unit.speed
unit.moving = true
end
if direction == right and
unit.x + unit.speed < 224 then
unit.x =unit.x+ unit.speed
unit.moving = true
end
if direction == up and
unit.y - unit.speed > 12 then
unit.y =unit.y- unit.speed
unit.moving = true
end
if direction == down and
unit.y + unit.speed < 116 then
unit.y =unit.y+ unit.speed
unit.moving = true
end
if not unit.moving then
unit.sprite = unit.startsprite
else
move(unit)
end
end

function move_player()
 for i=1,#valid_moves do
  if btn(valid_moves[i]) then
   move_unit(player, valid_moves[i])
  end
 end
end

function move_enemy()
 if enemy.x > player.x then
  move_unit(enemy, left)
 end
 if enemy.x < player.x then
  move_unit(enemy, right)
 end
 if enemy.y > player.y then
  move_unit(enemy, up)
 end
 if enemy.y < player.y then
  move_unit(enemy, down)
 end
 enemy.speed =enemy.speed+ enemyspeedincrval
end

function move_enemy2()
 if enemy2.x > player.x then
  move_unit(enemy2, left)
 end
 if enemy2.x < player.x then
  move_unit(enemy2, right)
 end
 if enemy2.y > player.y then
  move_unit(enemy2, up)
 end
 if enemy2.y < player.y then
  move_unit(enemy2, down)
 end
 enemy2.speed =enemy2.speed+ enemyspeedincrval
end

function move_enemy3()
 if enemy3.x > player.x then
  move_unit(enemy3, left)
 end
 if enemy3.x < player.x then
  move_unit(enemy3, right)
 end
 if enemy3.y > player.y then
  move_unit(enemy3, up)
 end
 if enemy3.y < player.y then
  move_unit(enemy3, down)
 end
 enemy3.speed =enemy3.speed+ enemyspeedincrval
end

function distance(p0, p1)
 dx=p0.x-p1.x dy=p0.y-p1.y
 return sqrt(dx*dx+dy*dy)
end

function check_game_over()
 if invincibleval == 0 then
  if enemycountval == 1 then
   if distance(enemy,player) < 7
   and state ~= game_over
   then
   state = start_end_game
   end
  elseif enemycountval == 2 then
   if distance(enemy,player) < 7
   and state ~= game_over
   then
   state = start_end_game
   elseif distance(enemy2,player) < 7
   and state ~= game_over
   then
   state = start_end_game
   end
  elseif enemycountval == 3 then
   if distance(enemy,player) < 7
   and state ~= game_over
   then
   state = start_end_game
   elseif distance(enemy2,player) < 7
   and state ~= game_over
   then
   state = start_end_game
   elseif distance(enemy3,player) < 7
   and state ~= game_over
   then
   state = start_end_game
   end
  end
 elseif invincibleval == 1 then
  if enemycountval == 1 then
   if distance(enemy,player) < 0
   and state ~= game_over
   then
   state = start_end_game
   end
  elseif enemycountval == 2 then
   if distance(enemy,player) < 0
   and state ~= game_over
   then
   state = start_end_game
   elseif distance(enemy2,player) < 0
   and state ~= game_over
   then
   state = start_end_game
   end
  elseif enemycountval == 3 then
   if distance(enemy,player) < 0
   and state ~= game_over
   then
   state = start_end_game
   elseif distance(enemy2,player) < 0
   and state ~= game_over
   then
   state = start_end_game
   elseif distance(enemy3,player) < 0
   and state ~= game_over
   then
   state = start_end_game
   end
  end
 end
end

function _update()
 if enemycountval == 1 then
  move_player()
  move_enemy()
 elseif enemycountval == 2 then
  move_player()
  move_enemy()
  move_enemy2()
 elseif enemycountval == 3 then
  move_player()
  move_enemy()
  move_enemy2()
  move_enemy3()
 end
 check_game_over()
end

_init()

function TIC()
 cls()
 if state == menu then
  menu()
 elseif state == in_progress then
  _update()
  map(0,0,0,8,16,15)
  if enemycountval == 1 then
   draw_unit(player)
   draw_unit(enemy)
  elseif enemycountval == 2 then
   draw_unit(player)
   draw_unit(enemy)
   draw_unit(enemy2)
  elseif enemycountval == 3 then
   draw_unit(player)
   draw_unit(enemy)
   draw_unit(enemy2)
   draw_unit(enemy3)
  end
  score =score+ 1
  spr(255,191,7)
  print("Pause",201,8,12)
  print("Score = "..score,8,8,12)
  print("ported by nesbox  fixed by stevenfelix505",7,124,12)
  if btnp(5) then
   state = pause
  end
  if debug_mode == 1 then
   if enemycountval == 1 then
    print(player.x..":"..player.y,8,16,4)
    print(enemy.x..":"..enemy.y,8,24,2)
   elseif enemycountval == 2 then
    print(player.x..":"..player.y,8,16,4)
    print(enemy.x..":"..enemy.y,8,24,2)
    print(enemy2.x..":"..enemy2.y,8,32,7)
   elseif enemycountval == 3 then
    print(player.x..":"..player.y,8,16,4)
    print(enemy.x..":"..enemy.y,8,24,2)
    print(enemy2.x..":"..enemy2.y,8,32,7)
    print(enemy3.x..":"..enemy3.y,8,40,8)
   end
  end
 elseif state == start_end_game then
  sfx(0,43,45,0,soundval)
  print("ported by nesbox  fixed by stevenfelix505",7,124,12)
  state = game_over
 elseif state == game_over then
  game_over_menu()
 elseif state == options then
  options()
 elseif state == pause then
  pause_menu()
 end
 if soundval == -1 then
  soundval = 0
 elseif soundval == 16 then
  soundval = 15
 end
 if invincibleval == -1 then
  invincibleval = 0
 elseif invincibleval == 2 then
  invincibleval = 1
 end
 if enemycountval == 0 then
  enemycountval = 1
 elseif enemycountval == 4 then
  enemycountval = 3
 end
 if btnp(0) or btnp(1) or btnp(2) or btnp(3) or btnp(4) or btnp(5) or btnp(6) or btnp(7) or btnp(8) then
  sfx(1,40,4,0,soundval)
 end
end