cracker64

controltron

Apr 13th, 2014
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.58 KB | None | 0 0
  1. --THIS IS OUTDATED, DO NOT USE
  2. tron_rx = {-1, 0, 1, 0}
  3. tron_ry = { 0,-1, 0, 1}
  4. activetron = -1
  5. zoompressed = false
  6.  
  7. function newtronhead(x,y,i,direction,tmp)
  8. if (x<4 or y<4 or x>= 608 or y>=380) then
  9. return -1
  10. end
  11. np = tpt.create(x,y,"tron")
  12. if (np==-1) then
  13. return -1
  14. end
  15. --increase tail length
  16. if (tpt.get_property("life",i)>=100 and band(tmp,2)==0) then
  17. tpt.set_property("tmp2",tpt.get_property("tmp2",i)+1,i)
  18. tpt.set_property("life",5,i)
  19. end
  20. --give new head our properties
  21. if (np > i) then
  22. tpt.set_property("tmp",band(tmp,63515)+lsl(direction,5)+4,np)
  23. else
  24. tpt.set_property("tmp",band(tmp,63515)+lsl(direction,5),np)
  25. end
  26. tpt.set_property("ctype",tpt.get_property("ctype",i),np)
  27. tpt.set_property("tmp2",tpt.get_property("tmp2",i),np)
  28. tpt.set_property("life",tpt.get_property("life",i)+2,np)
  29. if (i == activetron) then
  30. activetron = np
  31. end
  32. return 1
  33. end
  34.  
  35. function check(x,y)
  36. if (tpt.get_property("type",x,y) > 0) then return false end
  37. if (x<4 or y<4 or x>= 608 or y>=380) then return false end
  38. return true
  39. end
  40.  
  41. function updatetron(i,x,y,surround_space,nt)
  42. tmp = tpt.get_property("tmp",i)
  43. active = (i==activetron)
  44. --TRON_WAIT check
  45. if (band(tmp,4) == 4) then
  46. tpt.set_property("tmp", tmp-4,i)
  47. return false
  48. end
  49. --Head check
  50. if (band(tmp,1)==1) then
  51. direction = band(lsr(tmp,5),3)
  52. if (not active) then
  53. originaldir = direction
  54. lastdir = 0
  55. rand = 6--math.random(340)
  56. if (rand==1 or rand==3) then
  57. direction = (direction+rand)%4
  58. end
  59. --directly in front
  60. if (not check(x+tron_rx[direction+1],y+tron_ry[direction+1])) then
  61. if (originaldir ~= direction) then --don't pick random twice
  62. lastdir = (direction + 2)%4
  63. direction = originaldir
  64. else
  65. direction = ((direction + (math.random(3)-1)*2)+1)%4
  66. lastdir = (direction + 2)%4
  67. end
  68. if (not check(x+tron_rx[direction+1],y+tron_ry[direction+1])) then
  69. direction = lastdir
  70. end
  71. end
  72. end
  73. if ( newtronhead(x+tron_rx[direction+1],y+tron_ry[direction+1],i,direction,tmp) == -1 ) then
  74. --oh god crash
  75. tpt.set_property("tmp",tmp+16,i)
  76. if (i==activetron) then
  77. activetron = -1
  78. end
  79. end
  80. tpt.set_property("life",tpt.get_property("tmp2",i),i)
  81. tpt.set_property("tmp",band(tmp,63512),i)
  82. end
  83. return false
  84. end
  85.  
  86. function mouseclicky(mousex,mousey,button,event)
  87. if (tpt.selectedl ~= 143 or mousey > 384 or mousex > 612 or zoompressed) then
  88. return true
  89. end
  90. if (event~=1) then
  91. return false
  92. end
  93. if (activetron >= 0 and tpt.get_property("type",activetron)==143) then
  94. tpt.create(mousex,mousey,"tron")
  95. return false
  96. end
  97. activetron = tpt.create(mousex,mousey,"tron")
  98. return false
  99. end
  100.  
  101. function keyclicky(key,nkey,modifier,event)
  102. if (key == 'z' and event == 1) then zoompressed = true end
  103. if (key == 'z' and event == 2) then zoompressed = false end
  104. if (activetron == -1) then return true end
  105. if (event == 2) then return false end
  106. tmp = tpt.get_property("tmp",activetron)
  107. nodirtmp = band(tmp,63515)
  108. direction = band(lsr(tmp,5),3)
  109. --up
  110. if (nkey == 273) then
  111. if (direction == 3) then return false end
  112. tpt.set_property("tmp",nodirtmp+32,activetron)
  113. return false
  114. end
  115. --down
  116. if (nkey == 274) then
  117. if (direction == 1) then return false end
  118. tpt.set_property("tmp",nodirtmp+96,activetron)
  119. return false
  120. end
  121. --right
  122. if (nkey == 275) then
  123. if (direction == 0) then return false end
  124. tpt.set_property("tmp",nodirtmp+64,activetron)
  125. return false
  126. end
  127. --left
  128. if (nkey == 276) then
  129. if (direction == 2) then return false end
  130. tpt.set_property("tmp",nodirtmp,activetron)
  131. return false
  132. end
  133. return true
  134. end
  135.  
  136.  
  137. function status()
  138. if (activetron == -1) then
  139. tpt.drawtext(260,5,"You have no tron, place one")
  140. else
  141. tpt.drawtext(260,5,"Active tron!")
  142. end
  143. end
  144.  
  145. tpt.register_step(status)
  146. tpt.register_keypress(keyclicky)
  147. tpt.register_mouseclick(mouseclicky)
  148. tpt.element_func(updatetron,tpt.element("tron"))
Advertisement
Add Comment
Please, Sign In to add comment