Advertisement
guitarplayer616

AI test - (world's hardest game/ frogger)

Jul 3rd, 2015
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.88 KB | None | 0 0
  1. local w,h = term.getSize()
  2. shell.run("clr")
  3. local bloons = {}
  4. fs.open("poidata",'w')
  5.  
  6. function createBloon(xpos,ypos,col,dir)
  7.     local bloon = {}
  8.     bloon.color = col
  9.     bloon.xpos = xpos
  10.     bloon.ypos = ypos
  11.     bloon.xprev = 1
  12.     bloon.yprev = 1
  13.     bloon.dir = dir
  14.     return bloon
  15. end
  16.  
  17. function rand(...)
  18.     local tArgs = {...}
  19.     local decision = math.random(1,#tArgs)
  20.     return tArgs[decision]
  21. end
  22.    
  23. function log(words)
  24.     local h = fs.open("poidata",'a')
  25.     h.writeLine(words)
  26.     h.close()
  27. end
  28.    
  29. --[[    bloons.red = createBloon(w,5,colors.red)
  30.         bloons.blue = createBloon(1,3,colors.blue)
  31.         bloons.green = createBloon(w,7,colors.green)
  32.         bloons.pink = createBloon(1,9,colors.pink)
  33.         bloons.lead = createBloon(1,11,colors.grey)
  34.         bloons.yellow = createBloon(w,13,colors.yellow)
  35.         bloons.ceramic = createBloon(w,15,colors.brown)
  36.         bloons.camo = createBloon(1,17,colors.lime)]]
  37.  
  38. for i = 1, w, 2 do
  39.     bloons[i] = createBloon(math.random(1,w),i,2^math.random(1,15),rand("right","left"))
  40. end
  41.  
  42. function events()
  43.     while true do
  44.         local e = {os.pullEvent("mouse_click")}
  45.         log(textutils.serialize(e))
  46.         for i,v in pairs(bloons) do
  47.             if e[3] == v.xpos or e[3] == v.xprev then
  48.                 log("x match")
  49.                 if e[4] == v.ypos or e[4] == v.yprev then
  50.                     log("hit")
  51.                     v.color = v.color/2
  52.                     log(bloons[i].color)
  53.                     log("^ bloons[i].color")
  54.                     log(v.color/2)
  55.                 end
  56.             end
  57.         end
  58.     end
  59. end
  60.  
  61.  
  62. function ai()
  63.     while true do
  64.         for i,v in pairs(bloons) do
  65.             paintutils.drawPixel(v.xpos,v.ypos,v.color)
  66.             paintutils.drawPixel(v.xprev,v.yprev,colors.black)
  67.             v.xprev,v.yprev = v.xpos,v.ypos
  68.             if v.xpos == 1 then
  69.                 v.dir = "right"
  70.             elseif v.xpos == w then
  71.                 v.dir = "left"
  72.             end
  73.             if v.dir == "right" then
  74.                 v.xpos = v.xpos + 1
  75.             elseif v.dir == "left" then
  76.                 v.xpos = v.xpos - 1
  77.             end
  78.         end
  79.         sleep(.05)
  80.     end
  81. end
  82.  
  83. while true do
  84.     parallel.waitForAny(events,ai)
  85. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement