Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --THIS IS OUTDATED, DO NOT USE
- tron_rx = {-1, 0, 1, 0}
- tron_ry = { 0,-1, 0, 1}
- activetron = -1
- zoompressed = false
- function newtronhead(x,y,i,direction,tmp)
- if (x<4 or y<4 or x>= 608 or y>=380) then
- return -1
- end
- np = tpt.create(x,y,"tron")
- if (np==-1) then
- return -1
- end
- --increase tail length
- if (tpt.get_property("life",i)>=100 and band(tmp,2)==0) then
- tpt.set_property("tmp2",tpt.get_property("tmp2",i)+1,i)
- tpt.set_property("life",5,i)
- end
- --give new head our properties
- if (np > i) then
- tpt.set_property("tmp",band(tmp,63515)+lsl(direction,5)+4,np)
- else
- tpt.set_property("tmp",band(tmp,63515)+lsl(direction,5),np)
- end
- tpt.set_property("ctype",tpt.get_property("ctype",i),np)
- tpt.set_property("tmp2",tpt.get_property("tmp2",i),np)
- tpt.set_property("life",tpt.get_property("life",i)+2,np)
- if (i == activetron) then
- activetron = np
- end
- return 1
- end
- function check(x,y)
- if (tpt.get_property("type",x,y) > 0) then return false end
- if (x<4 or y<4 or x>= 608 or y>=380) then return false end
- return true
- end
- function updatetron(i,x,y,surround_space,nt)
- tmp = tpt.get_property("tmp",i)
- active = (i==activetron)
- --TRON_WAIT check
- if (band(tmp,4) == 4) then
- tpt.set_property("tmp", tmp-4,i)
- return false
- end
- --Head check
- if (band(tmp,1)==1) then
- direction = band(lsr(tmp,5),3)
- if (not active) then
- originaldir = direction
- lastdir = 0
- rand = 6--math.random(340)
- if (rand==1 or rand==3) then
- direction = (direction+rand)%4
- end
- --directly in front
- if (not check(x+tron_rx[direction+1],y+tron_ry[direction+1])) then
- if (originaldir ~= direction) then --don't pick random twice
- lastdir = (direction + 2)%4
- direction = originaldir
- else
- direction = ((direction + (math.random(3)-1)*2)+1)%4
- lastdir = (direction + 2)%4
- end
- if (not check(x+tron_rx[direction+1],y+tron_ry[direction+1])) then
- direction = lastdir
- end
- end
- end
- if ( newtronhead(x+tron_rx[direction+1],y+tron_ry[direction+1],i,direction,tmp) == -1 ) then
- --oh god crash
- tpt.set_property("tmp",tmp+16,i)
- if (i==activetron) then
- activetron = -1
- end
- end
- tpt.set_property("life",tpt.get_property("tmp2",i),i)
- tpt.set_property("tmp",band(tmp,63512),i)
- end
- return false
- end
- function mouseclicky(mousex,mousey,button,event)
- if (tpt.selectedl ~= 143 or mousey > 384 or mousex > 612 or zoompressed) then
- return true
- end
- if (event~=1) then
- return false
- end
- if (activetron >= 0 and tpt.get_property("type",activetron)==143) then
- tpt.create(mousex,mousey,"tron")
- return false
- end
- activetron = tpt.create(mousex,mousey,"tron")
- return false
- end
- function keyclicky(key,nkey,modifier,event)
- if (key == 'z' and event == 1) then zoompressed = true end
- if (key == 'z' and event == 2) then zoompressed = false end
- if (activetron == -1) then return true end
- if (event == 2) then return false end
- tmp = tpt.get_property("tmp",activetron)
- nodirtmp = band(tmp,63515)
- direction = band(lsr(tmp,5),3)
- --up
- if (nkey == 273) then
- if (direction == 3) then return false end
- tpt.set_property("tmp",nodirtmp+32,activetron)
- return false
- end
- --down
- if (nkey == 274) then
- if (direction == 1) then return false end
- tpt.set_property("tmp",nodirtmp+96,activetron)
- return false
- end
- --right
- if (nkey == 275) then
- if (direction == 0) then return false end
- tpt.set_property("tmp",nodirtmp+64,activetron)
- return false
- end
- --left
- if (nkey == 276) then
- if (direction == 2) then return false end
- tpt.set_property("tmp",nodirtmp,activetron)
- return false
- end
- return true
- end
- function status()
- if (activetron == -1) then
- tpt.drawtext(260,5,"You have no tron, place one")
- else
- tpt.drawtext(260,5,"Active tron!")
- end
- end
- tpt.register_step(status)
- tpt.register_keypress(keyclicky)
- tpt.register_mouseclick(mouseclicky)
- tpt.element_func(updatetron,tpt.element("tron"))
Advertisement
Add Comment
Please, Sign In to add comment