Log In  

Cart #spacegame_20_minutes-0 | 2020-12-23 | Code ▽ | Embed ▽ | Forks ▽ | No License
2

I made a game in 20 minutes. this is the code:

function _init()
 pos = 2
 ob = nil
 obn = nil
 speed = 3
 gametime = 1
 lost = false
end

function _update()
 if not lost then
  gametime += 1
  if btnp(⬅️) then
   pos -= 1
   if pos < 1 then
    pos = 1
   end
  end
  if btnp(➡️) then
   pos += 1
   if pos > 3 then
    pos = 3
   end
  end

  if not ob then
   if flr(rnd(2)) == 1 then
    ob = pos
   else
    ob = flr(rnd(3))+1
   end
   obn = 8
  end
  if gametime%(ceil(30/speed)) == 0 then
   if obn then
    if obn == 1 then
     if ob == pos then
      lost = true
     end
    elseif obn == 0 then
     ob = nil
     obn = nil
     speed += 0.5
    end
    if obn then
     obn -= 1
    end
   end
  end
 else
  if btnp(❎) then
   _init()
  end
 end
end

function _draw()
 cls(0)
 spr(1,48+pos*8,64)
 if ob then
  spr(2,48+ob*8,64-obn*8)
 end
 if lost then
  local str = "you lost, press ❎ to retry"
  print(str,64-#str*2,32)
 end
end
P#85722 2020-12-23 19:50 ( Edited 2020-12-23 20:00)


[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2022-09-30 18:40:06 | 0.006s | Q:15