Advertisement
Guest User

Game thing

a guest
Nov 11th, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 44.29 KB | None | 0 0
  1.  
  2. --# Main
  3.  
  4.  
  5.  
  6. -- Use this function to perform your initial setup
  7. displayMode(FULLSCREEN)
  8. function setup()
  9.    
  10.     player = {speed = nil, size = .5}
  11.    
  12.     stick = Stick()
  13.    
  14.     dark = false
  15.     wallbut = button(WIDTH-50, HEIGHT*.80, 50, 50, "Stone", 16, 0, 0,0,100)
  16.     floorbut = button(WIDTH-50, (HEIGHT*.80)-50, 50, 50, "Floor", 16, 0,0,0,100)
  17.     grassbut = button(WIDTH-100, (HEIGHT*.80), 50, 50, "Grass", 16, 0, 0, 0,100)
  18.     sandbut = button(WIDTH-100, (HEIGHT*.80)-50, 50, 50, "Sand", 16, 0, 0 , 0, 100)
  19.     forestbut = button(WIDTH-100, (HEIGHT*.80)-100, 50, 50, "Forest", 15, 0 , 0 , 0,100)
  20.     growbut = button(WIDTH-50, (HEIGHT*.80)-100, 50, 50, "Grower", 14, 0,0,0,100)
  21.     savebut = button(WIDTH/2, HEIGHT/2, 100, 50, "Save", 25, 0,0,0,255)
  22.     loadbut = button(WIDTH/2, (HEIGHT/3) + 50 , 100, 50, "Load", 25, 0,0,0,255)
  23.     pausebut = button(50, (HEIGHT*.9)+20, 100, 50, "Pause", 30, 0,0,0,100)
  24.     backbut = button(WIDTH/2, (HEIGHT/3) - 25, 100, 50, "Quit", 25, 0,0,0,255)
  25.     startbut = button(WIDTH/2, HEIGHT/2, 100, 50, "Start", 25, 0,0,0,255)
  26.     invbut = button(WIDTH-75, (HEIGHT*.85) + 20, 100, 50, "Inventory", 24, 0,0,0,100)
  27.     cratebut = button(WIDTH-150, (HEIGHT*.80), 50, 50, "Wood", 16, 0, 0, 0,100)
  28.     wr1but = button(WIDTH-150, (HEIGHT*.80)-50, 50, 50, "Wire", 16, 0, 0, 0,100)
  29.     notbut = button(WIDTH-150, (HEIGHT*.80)-100, 50, 50, "Not", 16, 0, 0, 0,100)
  30.     butbut = button(WIDTH-200, (HEIGHT*.80), 50, 50, "Switch", 16, 0, 0, 0,100)
  31.     gnldbut = button(WIDTH-200, (HEIGHT*.80)-50, 50, 50, "Green", 16, 0, 0, 0,100)
  32.     inslbut = button(WIDTH-200, (HEIGHT*.80)-100, 50, 50, "Insulate", 16, 0, 0, 0,100)
  33.     lnotbut = button(WIDTH-250, (HEIGHT*.80), 50, 50, "ldwire", 16, 0, 0, 0,100)
  34.     ccbut = button(WIDTH-75, (HEIGHT*.85)-30, 100, 50, "CC", 24, 0,0,0,100)
  35.     prevbut = button(WIDTH-50, HEIGHT - 25, 100, 50, "Back", 25, 0,0,0,255)
  36.    
  37.     selected = 5
  38.    
  39.     forest = Floor(1)
  40.     sand = Floor(2)
  41.     plains = Floor(3)
  42.     water = Floor(4)
  43.     woodfloor = Floor(0,"Platformer Art:Crate")
  44.     cactus = Wall(1)
  45.     plainplant = Wall(2)
  46.     forestplant = Wall(3)
  47.     grower = Wall(4)
  48.     crate = Wall(0,"Planet Cute:Wood Block")
  49.     stonewall = Wall(0,"Planet Cute:Ramp South")
  50.     wr1 = Floor(5)
  51.     wr1i = Floor(6)
  52.     nt = Floor(7)
  53.     swt = Floor(8)
  54.     onswt = Floor(9)
  55.     offld = Floor(10)
  56.     gnld = Floor(11)
  57.     ins = Floor(12)
  58.     lnt = Floor(13)
  59.     ldh = Floor(14)
  60.     sprite("Planet Cute:Wood Block")
  61.    
  62.     abut = actbutton()
  63.    
  64.     world = World(50)
  65.    
  66.     spawnx = math.random(1,1000)
  67.     spawnz = math.random(1,1000)
  68.     wrldx = math.ceil(spawnx-.5)
  69.     wrldy = math.ceil(spawnz-.5)
  70.     while world.data[wrldy][wrldx] == 4 do
  71.         spawnx = math.random(1,1000)
  72.         spawnz = math.random(1,1000)
  73.         wrldx = math.ceil(spawnx-.5)
  74.         wrldy = math.ceil(spawnz-.5)
  75.     end
  76.     hero = Hero(spawnx,spawnz)
  77.    
  78.    
  79.     TO_DEG = 180/math.pi
  80.    
  81.     for i = 1,4 do
  82.         print(world.seed[i])
  83.     end
  84.     music("Game Music One:Nothingness",true,0.25)
  85.     state = "start"
  86.    
  87.     loaded = false
  88.    
  89.     frame = 1
  90.    
  91. end
  92.  
  93. -- Creates an image of an ellipse and rect
  94.  
  95. -- This function gets called once every frame
  96. function draw()
  97.     frame = frame + 1
  98.     background(149, 104, 27, 255)
  99.     if state == "playing" or state == "start" or state == "inventory" then
  100.         local TO_DEG = TO_DEG
  101.         local hero = hero
  102.         perspective(60)
  103.         camera(hero.x, hero.y + 15, hero.z, hero.x, 0, hero.z, 0, 1, 0)      
  104.        
  105.         if loaded == false then
  106.             time = ElapsedTime
  107.         elseif loaded then
  108.             time = readLocalData("savedtime")
  109.             time = time + ElapsedTime
  110.         end
  111.        
  112.         -- Draw world
  113.         pushMatrix()
  114.         world:draw()
  115.         popMatrix()
  116.        
  117.        
  118.         hero.px = math.ceil(hero.x-.5)
  119.         hero.py = math.ceil(hero.z-.5)
  120.        
  121.         --make hero face dir that its moving
  122.         pushMatrix()
  123.         translate(hero.x,hero.y,hero.z)
  124.         if stick.active and CurrentTouch.state ~= BEGAN then
  125.             rot = vec4(stick.direction*TO_DEG - 90,0,1,0)
  126.         end
  127.         if rot ~= nil then
  128.             rotate(rot.x,rot.y,rot.z,rot.w)
  129.         end
  130.         scale(player.size,player.size,player.size)
  131.         hero:draw()
  132.         popMatrix()
  133.        
  134.         if state == "playing" or state == "gcmbt" then
  135.             if math.floor(world.data[hero.py][hero.px]) == 4 and hero.y == 0 then
  136.                 player.speed = 25
  137.                 if abut.active and math.floor(time) ~= abut.markedtime then
  138.                     hero.thirst = hero.thirst + 1
  139.                     sound("A Hero's Quest:Drink 2")
  140.                     abut.markedtime = math.floor(time)
  141.                     dhyd = false
  142.                 end
  143.                 if math.floor(time) % 1 == 0 and math.floor(time) ~= airmarkedtime and hero.air > 0 then
  144.                     hero.air = hero.air - 1
  145.                     airmarkedtime = math.floor(time)
  146.                     drowning = false
  147.                 elseif hero.air == 0 then
  148.                     if math.floor(time) % 2 == 0 and math.floor(time) ~= airmarkedtime then
  149.                         drowning = true
  150.                         hero.health = hero.health - 10
  151.                         airmarkedtime = math.floor(time)
  152.                         sound("A Hero's Quest:Hit 3")
  153.                     end
  154.                 end
  155.             else
  156.                 player.speed = 10
  157.                 if math.floor(time) % 1 == 0 and math.floor(time) ~= airmarkedtime and hero.air < 10 then
  158.                     hero.air = hero.air + 1
  159.                     airmarkedtime = math.floor(time)
  160.                     if hero.air > 0 then
  161.                         drowning = false
  162.                     end
  163.                 end
  164.             end
  165.            
  166.             if world.plantdata[hero.py][hero.px] == 1 or world.plantdata[hero.py][hero.px] == 2 then
  167.                 world.plantdata[hero.py][hero.px] = 0
  168.                 hero.food = hero.food + 1
  169.                 sound("A Hero's Quest:Eat 1")
  170.                 starving = false
  171.             end
  172.            
  173.             if math.floor(time) % 2 == 0 and math.floor(time) ~= foodmarkedtime then
  174.                 if math.floor(time) % 20 == 0 and math.floor(time) ~= foodmarkedtime and not starving then
  175.                     hero.food = hero.food - 1
  176.                     foodmarkedtime = math.floor(time)
  177.                 else
  178.                     if hero.food == 0 then
  179.                         hero.health = hero.health - 5
  180.                         sound("A Hero's Quest:Hit 3")
  181.                         foodmarkedtime = math.floor(time)
  182.                         starving = true
  183.                     elseif hero.food >= 20  and hero.health < 96 then
  184.                         hero.health = hero.health + 5
  185.                         foodmarkedtime = math.floor(time)
  186.                         starving = false
  187.                     end
  188.                 end
  189.             end
  190.            
  191.             if math.floor(time) % 2 == 0 and math.floor(time) ~= watermarkedtime then
  192.                 if math.floor(time) % 12 == 0 and math.floor(time) ~= watermarkedtime and hero.thirst > 0 and not dhyd then
  193.                     hero.thirst = hero.thirst - 1
  194.                     watermarkedtime = math.floor(time)
  195.                 else
  196.                     if hero.thirst == 0 then
  197.                         hero.health = hero.health - 5
  198.                         sound("A Hero's Quest:Hit 3")
  199.                         watermarkedtime = math.floor(time)
  200.                         dhyd = true
  201.                     end
  202.                 end
  203.             end
  204.            
  205.             if abut.active and math.floor(world.data[hero.py][hero.px]) ~= 4 and world.data[hero.py][hero.px] ~= 12 and world.data[hero.py][hero.px] ~= 13 then
  206.                 abut.markedtime = math.floor(time)
  207.                 if selected == 1 or selected == 2 or selected == 3 then
  208.                     cost = 1
  209.                 elseif selected == 5 or selected == 9 or selected == 11 or selected == 12 or selected == 14 or selected == 16 or selected == 17 then
  210.                     cost = 2
  211.                 elseif selected == 6 or selected == 8 then
  212.                     cost = 3
  213.                 elseif selected == 7 then
  214.                     cost = 5
  215.                 end
  216.                 if hero.food - cost >= 0 then
  217.                     hero.food = hero.food -  cost
  218.                     if selected > 5 and selected < 9 then
  219.                         world.data[hero.py][hero.px] = selected + ((world.data[hero.py][hero.px]-math.floor(world.data[hero.py][hero.px])) +.01)
  220.                         hero.y = hero.y + 1
  221.                     elseif selected < 6 or selected > 8 then
  222.                         world.data[hero.py][hero.px] = selected
  223.                     end
  224.                     place = true
  225.                     sound("A Hero's Quest:Drop")
  226.                 else
  227.                     if selected ~= math.floor(world.data[hero.py][hero.py]) and selected ~= "str" then
  228.                         sound("Game Sounds One:Wrong")
  229.                     end
  230.                 end
  231.                 abut.active = false
  232.             else
  233.                 place = false
  234.                 if world.data[hero.py][hero.px] == 12 and abut.active then
  235.                     world.data[hero.py][hero.px] = 13
  236.                     abut.active = false
  237.                 elseif world.data[hero.py][hero.px] == 13 and abut.active then
  238.                     world.data[hero.py][hero.px] = 12
  239.                     abut.active = false
  240.                 end
  241.             end
  242.         end
  243.        
  244.         if ((world.data[hero.py][hero.px]-math.floor(world.data[hero.py][hero.px]))*100) < hero.y then
  245.             hero.y = hero.y - 1
  246.         end
  247.        
  248.         if hero.health <= 0 then
  249.             state = "dead"
  250.         end
  251.        
  252.         -- Restore orthographic projection
  253.         ortho()
  254.         viewMatrix(matrix())
  255.         resetMatrix()
  256.        
  257.         if math.floor(time) % 300 == 0 and math.floor(time) ~= daymarkedtime then
  258.             if dark == false then
  259.                 dark = true
  260.                 daymarkedtime = math.floor(time)
  261.             elseif dark == true then
  262.                 dark = false
  263.                 daymarkedtime = math.floor(time)
  264.             end
  265.             if dark == false then
  266.                 marker = 1
  267.                 i1 = 0
  268.                 x1 = {}
  269.                 x1[1] = 0
  270.                 for j = 1,63 do
  271.                     for i = hero.py-100,hero.py+100 do
  272.                         v = world.data[i]
  273.                         for x = hero.px-100, hero.px+100 do
  274.                             if v[x] == 5 or v[x] == 6.01 then
  275.                                 if table.concat(v,"",x,x+5) == "6.016.01556.016.01" and marker == 1 then
  276.                                     print("found1")
  277.                                     table.insert(x1,x)
  278.                                     marker = 2
  279.                                     i1 = i
  280.                                 elseif table.concat(v,"",x,x+5) == "6.017.01557.016.01" and marker == 2 then
  281.                                     marker = 3
  282.                                     i2 = i
  283.                                 elseif table.concat(v,"",x,x+5) == "555555" and marker == 3 then
  284.                                     marker = 4
  285.                                     i3 = i
  286.                                 elseif table.concat(v,"",x,x+5) == "555555" and marker == 4 then
  287.                                     marker = 5
  288.                                     i4 = i
  289.                                 elseif table.concat(v,"",x,x+5) == "6.017.01557.016.01" and marker == 5 then
  290.                                     marker = 6
  291.                                     i5 = i
  292.                                 elseif marker == 6 and table.concat(v,"",x,x+5) == "6.016.01556.016.01" then
  293.                                     print("foundall")
  294.                                     marker = 1
  295.                                     i6 = i
  296.                                     for j,k in ipairs(x1) do
  297.                                         world.plantdata[i2-1][k + 2] = math.random(1,2)
  298.                                         world.plantdata[i2-1][k + 3] = math.random(1,2)
  299.                                         world.plantdata[i1][k + 2] = math.random(1,2)
  300.                                         world.plantdata[i1][k + 3] = math.random(1,2)
  301.                                         world.plantdata[i2][k + 2] = math.random(1,2)
  302.                                         world.plantdata[i2][k + 3] = math.random(1,2)
  303.                                         world.plantdata[i4+1][k] = math.random(1,2)
  304.                                         world.plantdata[i4+1][k + 1] = math.random(1,2)
  305.                                         world.plantdata[i4+1][k + 2] = math.random(1,2)
  306.                                         world.plantdata[i4+1][k + 3] = math.random(1,2)
  307.                                         world.plantdata[i4+1][k + 4] = math.random(1,2)
  308.                                         world.plantdata[i4+1][k + 5] = math.random(1,2)
  309.                                         world.plantdata[i3][k] = math.random(1,2)
  310.                                         world.plantdata[i3][k + 1] = math.random(1,2)
  311.                                         world.plantdata[i3][k + 2] = math.random(1,2)
  312.                                         world.plantdata[i3][k + 3] = math.random(1,2)
  313.                                         world.plantdata[i3][k + 4] = math.random(1,2)
  314.                                         world.plantdata[i3][k + 5] = math.random(1,2)
  315.                                         world.plantdata[i4][k] = math.random(1,2)
  316.                                         world.plantdata[i4][k + 1] = math.random(1,2)
  317.                                         world.plantdata[i4][k + 2] = math.random(1,2)
  318.                                         world.plantdata[i4][k + 3] = math.random(1,2)
  319.                                         world.plantdata[i4][k + 4] = math.random(1,2)
  320.                                         world.plantdata[i4][k + 5] = math.random(1,2)
  321.                                         world.plantdata[i5][k + 2] = math.random(1,2)
  322.                                         world.plantdata[i5][k + 3] = math.random(1,2)
  323.                                         world.plantdata[i6][k + 2] = math.random(1,2)
  324.                                         world.plantdata[i6][k + 3] = math.random(1,2)
  325.                                     end
  326.                                 end
  327.                             end
  328.                         end
  329.                     end
  330.                 end
  331.             end
  332.         end
  333.        
  334.         --fill(night.fillcol.r,night.fillcol.g,night.fillcol.b,night.fillcol.a)
  335.         --rectMode(CENTER)
  336.         --rect(WIDTH/2, HEIGHT/2, WIDTH + 10, HEIGHT + 10)
  337.        
  338.         pausebut:draw()
  339.         invbut:draw()
  340.        
  341.         if pausebut.active then
  342.             state = "paused"
  343.             pausebut.active = false
  344.         elseif invbut.active then
  345.             if state == "inventory" then
  346.                 state = "playing"
  347.                 invbut = button(WIDTH-75, (HEIGHT*.85) + 20, 100, 50, "Inventory", 24, 0,0,0,100)
  348.             elseif state == "playing" then
  349.                 state = "inventory"
  350.                 invbut = button(WIDTH-75, (HEIGHT*.85) + 20, 100, 50, "Inventory", 24, 255,0,0,255)
  351.             end
  352.             invbut.active = false
  353.         end
  354.        
  355.         pushStyle()
  356.         strokeWidth(15)
  357.         if not starving then
  358.             stroke(127, 127, 127, 255)
  359.         else
  360.             stroke(255, 0, 0, 255)
  361.         end
  362.         line((WIDTH*.75 + 10), HEIGHT-15, (WIDTH*.75)+210, HEIGHT-15)
  363.        
  364.         stroke(0, 255, 4, 255)
  365.         if hero.food < 21 then
  366.             line((WIDTH*.75 + 10), HEIGHT-15, (WIDTH*.75 + 10) + hero.food * 10,HEIGHT-15)
  367.         else
  368.             line((WIDTH*.75 + 10), HEIGHT-15, (WIDTH*.75)+210, HEIGHT-15)
  369.         end
  370.        
  371.         if not dhyd then
  372.             stroke(127, 127, 127, 255)
  373.         else
  374.             stroke(255, 0, 0, 255)
  375.         end
  376.         line((WIDTH*.75 + 10), HEIGHT-50, (WIDTH*.75 + 210), HEIGHT-50)
  377.        
  378.         stroke(0, 255, 0, 255)
  379.         if hero.thirst < 21 then
  380.             line((WIDTH*.75 + 10), HEIGHT-50, (WIDTH*.75 + 10) + hero.thirst * 10,HEIGHT-50)
  381.         else
  382.             line((WIDTH*.75 + 10), HEIGHT-50, (WIDTH*.75 + 210), HEIGHT-50)
  383.         end
  384.  
  385.         if hero.health > 66 then
  386.             stroke(0, 255, 4, 255)
  387.         elseif hero.health > 33 then
  388.             stroke(255, 218, 0, 255)
  389.         else
  390.             stroke(255, 0, 0, 255)
  391.         end
  392.         line(120, HEIGHT-15, 120 + hero.health*2,HEIGHT-15)
  393.         if hero.air ~= 10 then
  394.             stroke(0, 71, 255, 255)
  395.             line(((WIDTH/2) - 100), HEIGHT-45, ((WIDTH/2) - 100) + hero.air * 20,HEIGHT-45)
  396.         end
  397.        
  398.         font("AmericanTypewriter-Bold")
  399.         fontSize(30)
  400.         fill(0, 0, 0, 255)
  401.         textMode(CORNER)
  402.         text("Food", WIDTH*.675, HEIGHT-30)
  403.         text("Water", WIDTH*.65, HEIGHT-60)
  404.         text("Health", 0, HEIGHT-30)
  405.         popStyle()
  406.         if state == "playing" then
  407.             abut:draw()
  408.         end
  409.         if stick.active then
  410.             local ceil = math.ceil
  411.             stick:draw()
  412.            
  413.             -- move hero based on stick direction
  414.             mvtx = math.cos(stick.direction)/player.speed*stick.dist --coeficcient is inversely proportional to speed
  415.             mvtz = -math.sin(stick.direction)/player.speed*stick.dist --coeficcient is inversely proportional to speed
  416.             hero.x = hero.x - mvtx
  417.             hero.z = hero.z - mvtz
  418.            
  419.             -- convert to table coordinates
  420.             hero.px = ceil(hero.x - .5)
  421.             hero.py = ceil(hero.z - .5)
  422.             -- lazy collision check
  423.             if world.plantdata[hero.py][hero.px] == 3 and hero.y == 0 then
  424.                 hero.x  = hero.x + (mvtx * 5) -- +1 --noclip debug mode
  425.                 hero.z  = hero.z + (mvtz * 5) -- +1
  426.                 hero.px = ceil(hero.x)
  427.                 hero.py = ceil(hero.z)
  428.                 hero.health = hero.health - 2
  429.                 sound("A Hero's Quest:Hit 3", .25)
  430.             elseif math.floor(world.data[hero.py][hero.px]) > 5 then
  431.                 if ((world.data[hero.py][hero.px]-math.floor(world.data[hero.py][hero.px]))*100) - hero.y == 1 then
  432.                     hero.y = hero.y + 1
  433.                 elseif ((world.data[hero.py][hero.px]-math.floor(world.data[hero.py][hero.px]))*100) - hero.y > 1 then
  434.                     hero.x = hero.x + mvtx
  435.                     hero.z = hero.z + mvtz
  436.                 end
  437.             end
  438.         end
  439.        
  440.         if state == "start" then
  441.             rectMode(CENTER)
  442.             fill(0, 0, 0, 178)
  443.             rect(WIDTH/2,HEIGHT/2, WIDTH+10, HEIGHT+ 10)
  444.             textMode(CENTER)
  445.             fontSize(50)
  446.             fill(38, 125, 30, 255)
  447.             --text("Pocket Pete", WIDTH/2 , HEIGHT*0.75)
  448.             text("<INSERT_TITLE_HERE>",WIDTH/2,HEIGHT*.75)
  449.            
  450.             loadbut:draw()
  451.             startbut:draw()
  452.            
  453.             if startbut.active then
  454.                 state = "playing"
  455.                 starttime = math.floor(time)
  456.                 startbut.active = false
  457.             elseif loadbut.active then
  458.                 hero.x = readLocalData("savedherox")
  459.                 hero.z = readLocalData("savedheroz")
  460.                 hero.food = readLocalData("savedherofood")
  461.                 hero.thirst = readLocalData("savedherothirst")
  462.                 hero.health = readLocalData("savedherohealth")
  463.                 mydata = readLocalData("saveddata")
  464.                 world.data = json.decode(mydata)
  465.                 myplants = readLocalData("savedplants")
  466.                 world.plantdata = json.decode(myplants)
  467.                 dark = readLocalData("saveddark")
  468.                 sound("Game Sounds One:Menu Back")
  469.                 state = "playing"
  470.                 loadbut.active = false
  471.                 loaded = true
  472.             end
  473.         elseif state == "inventory" then
  474.             if selected == 6 then
  475.                 strokeWidth(5)
  476.             end
  477.             wallbut:draw()
  478.             noStroke()
  479.             if selected == 5 then
  480.                 strokeWidth(5)
  481.             end
  482.             floorbut:draw()
  483.             noStroke()
  484.             if selected == 1 then
  485.                 strokeWidth(5)
  486.             end
  487.             grassbut:draw()
  488.             noStroke()
  489.             if selected == 2 then
  490.                 strokeWidth(5)
  491.             end
  492.             forestbut:draw()
  493.             noStroke()
  494.             if selected == 3 then
  495.                 strokeWidth(5)
  496.             end
  497.             sandbut:draw()
  498.             noStroke()
  499.             if selected == 7 then
  500.                 strokeWidth(5)
  501.             end
  502.             growbut:draw()
  503.             noStroke()
  504.             if selected == 8 then
  505.                 strokeWidth(5)
  506.             end
  507.             cratebut:draw()
  508.             noStroke()
  509.             if selected == 9 then
  510.                 strokeWidth(5)
  511.             end
  512.             wr1but:draw()
  513.             noStroke()
  514.             if selected == 11 then
  515.                 strokeWidth(5)
  516.             end
  517.             notbut:draw()
  518.             noStroke()
  519.             if selected == 12 then
  520.                 strokeWidth(5)
  521.             end
  522.             butbut:draw()
  523.             noStroke()
  524.             if selected == 14 then
  525.                 strokeWidth(5)
  526.             end
  527.             gnldbut:draw()
  528.             noStroke()
  529.             if selected == 16 then
  530.                 strokeWidth(5)
  531.             end
  532.             inslbut:draw()
  533.             noStroke()
  534.             if selected == 17 then
  535.                 strokeWidth(5)
  536.             end
  537.             lnotbut:draw()
  538.             noStroke()
  539.            
  540.             if wallbut.active then
  541.                 selected = 6
  542.                 wallbut.active = false
  543.             elseif floorbut.active then
  544.                 selected = 5
  545.                 floorbut.active = false
  546.             elseif grassbut.active then
  547.                 selected = 1
  548.                 grassbut.active = false
  549.             elseif forestbut.active then
  550.                 selected = 2
  551.                 forestbut.active = false
  552.             elseif sandbut.active then
  553.                 selected = 3
  554.                 sandbut.active = false
  555.             elseif growbut.active then
  556.                 selected = 7
  557.                 growbut.active = false
  558.             elseif cratebut.active then
  559.                 selected = 8
  560.                 cratebut.active = false
  561.             elseif wr1but.active then
  562.                 selected = 9
  563.                 wr1but.active = false
  564.             elseif notbut.active then
  565.                 selected = 11
  566.                 notbut.active = false
  567.             elseif butbut.active then
  568.                 selected = 12
  569.                 butbut.active = false
  570.             elseif gnldbut.active then
  571.                 selected = 14
  572.                 gnldbut.active = false
  573.             elseif inslbut.active then
  574.                 selected = 16
  575.                 inslbut.active = false
  576.             elseif lnotbut.active then
  577.                 selected = 17
  578.                 lnotbut.active = false
  579.             end
  580.             rectMode(CENTER)
  581.             fill(0, 0, 0, 91)
  582.             rect(WIDTH/2, HEIGHT/2, WIDTH, HEIGHT)
  583.         end
  584.        
  585.     elseif state == "dead" then
  586.         background(0, 0, 0, 255)
  587.         font("AmericanTypewriter-Bold")
  588.         fontSize(100)
  589.         fill(255, 255, 255, 255)
  590.         textMode(CENTER)
  591.         text("YOU DIED", WIDTH/2 , HEIGHT/2)
  592.         loadbut:draw()
  593.     elseif state == "paused" then
  594.         background(127, 127, 127, 255)
  595.         font("AmericanTypewriter-Bold")
  596.         fontSize(100)
  597.         fill(0, 0, 0, 255)
  598.         textMode(CENTER)
  599.         text("Paused", WIDTH/2 , HEIGHT*.75)
  600.        
  601.         loadbut:draw()
  602.         savebut:draw()
  603.         backbut:draw()
  604.        
  605.         if savebut.active then
  606.             saveLocalData("savedherox", hero.x)
  607.             saveLocalData("savedheroz", hero.z)
  608.             saveLocalData("savedherofood", hero.food)
  609.             saveLocalData("savedherothirst", hero.thirst)
  610.             saveLocalData("savedherohealth", hero.health)
  611.             encodeddata = json.encode(world.data)
  612.             saveLocalData("saveddata", encodeddata)
  613.             encodedplants = json.encode(world.plantdata)
  614.             saveLocalData("savedplants", encodedplants)
  615.             saveLocalData("savedtime", time)
  616.             saveLocalData("saveddark", dark)
  617.             sound("Game Sounds One:Menu Select")
  618.             state = "playing"
  619.             savebut.active = false
  620.         elseif loadbut.active then
  621.             hero.x = readLocalData("savedherox")
  622.             hero.z = readLocalData("savedheroz")
  623.             hero.food = readLocalData("savedherofood")
  624.             hero.thirst = readLocalData("savedherothirst")
  625.             hero.health = readLocalData("savedherohealth")
  626.             mydata = readLocalData("saveddata")
  627.             world.data = json.decode(mydata)
  628.             myplants = readLocalData("savedplants")
  629.             world.plantdata = json.decode(myplants)
  630.             dark = readLocalData("saveddark")
  631.             sound("Game Sounds One:Menu Back")
  632.             state = "playing"
  633.             loadbut.active = false
  634.             loaded = true
  635.         elseif backbut.active then
  636.             close()
  637.             backbut.active = false
  638.         end
  639.     end
  640. end
  641.  
  642. --new nav function
  643. function touched(touch)
  644.     if state == "playing" then
  645.         stick:touched(touch)
  646.         abut:touched(touch)
  647.         pausebut:touched(touch)
  648.         invbut:touched(touch)
  649.     elseif state == "paused" then
  650.         savebut:touched(touch)
  651.         loadbut:touched(touch)
  652.         backbut:touched(touch)
  653.     elseif state == "start" then
  654.         loadbut:touched(touch)
  655.         startbut:touched(touch)
  656.     elseif state == "inventory" then
  657.         wallbut:touched(touch)
  658.         floorbut:touched(touch)
  659.         grassbut:touched(touch)
  660.         sandbut:touched(touch)
  661.         forestbut:touched(touch)
  662.         growbut:touched(touch)
  663.         invbut:touched(touch)
  664.         cratebut:touched(touch)
  665.         wr1but:touched(touch)
  666.         notbut:touched(touch)
  667.         butbut:touched(touch)
  668.         gnldbut:touched(touch)
  669.         inslbut:touched(touch)
  670.         lnotbut:touched(touch)
  671.     end
  672. end
  673. --# hero
  674.  
  675. --# Hero
  676. Hero = class()
  677.  
  678. function Hero:init(x, z)
  679.     self.x, self.y, self.z = x,0,z
  680.     self.px, self.py = math.ceil(x+.5), math.ceil(z+.5)
  681.     self.col = 1
  682.     self.mdl = Character(self.col)
  683.     self.food = 1000
  684.     self.health = 100
  685.     self.thirst = 1000
  686.     self.air = 10
  687. end
  688.  
  689. function Hero:draw()
  690.     self.mdl:draw()
  691. end
  692. --# Characters
  693. --# Floor
  694. Character = class()
  695.  
  696. function Character:init(col)
  697.     -- all the unique vertices that make up a cube
  698.     local vertices =
  699.     {
  700.     vec3( 0.3,  -0.5,0.3), -- Right top    front
  701.     vec3(-0.3,  -0.5,0.3), -- Left  top    front
  702.     vec3( 0.5,  -0.5,-0.5), -- Right top    back
  703.     vec3(-0.5,  -0.5,-0.5), -- Left  top    back
  704.     }
  705.    
  706.    
  707.     -- now construct a cube out of the vertices above
  708.     local verts =
  709.     {
  710.     -- Bottom
  711.     vertices[3], vertices[4], vertices[2],
  712.     vertices[3], vertices[2], vertices[1],
  713.     }
  714.    
  715.     -- all the unique texture positions needed
  716.     local texvertices =
  717.     {
  718.     vec2(0,0),
  719.     vec2(1,0),
  720.     vec2(0,1),
  721.     vec2(1,1)
  722.     }
  723.    
  724.     -- apply the texture coordinates to each triangle
  725.     local texCoords =
  726.     {
  727.     -- Bottom
  728.     texvertices[2], texvertices[1], texvertices[4],
  729.     texvertices[1], texvertices[2], texvertices[3],
  730.     }
  731.    
  732.     self.model = mesh()
  733.     self.model.vertices = verts
  734.     if col == 1 then
  735.         self.model:setColors(255 , 0 , 78 , 255)
  736.     elseif col == 2 then
  737.         self.model:setColors(0, 66, 255, 255)
  738.     end
  739.     color(0, 66, 255, 255)
  740. end
  741.  
  742. function Character:draw()
  743.     self.model:draw()
  744. end
  745. --# world
  746. --# World
  747. World = class()
  748.  
  749. function World:init(render)
  750.    
  751.     -- define the world
  752.     self.seed = {math.random(1,10),math.random(1,10),math.random(1,10),math.random(1,5)}
  753.     self.render = render
  754.     self.data = {}
  755.     self.plantdata = {}
  756.     for x = 1, 1000 do
  757.         self.data[x] = {}
  758.         for y = 1, 1000 do
  759.             Noise = noise(x*(self.seed[3]*.0025),y*(self.seed[3]*.0025),self.seed[1]*(self.seed[3] * .0025)) * 10
  760.             if Noise < -1 then
  761.                 self.data[x][y] = 3
  762.                 Noise = noise(x*(self.seed[3]*.0025),y*(self.seed[3]*.0025),(self.seed[1]+self.seed[4])*(self.seed[3] * .0025)) * 10
  763.                 if Noise < -2 then
  764.                     self.data[x][y] = 4
  765.                 end
  766.             else
  767.                 self.data[x][y] = 1
  768.                 Noise = noise(x*(self.seed[3]*.0025),y*(self.seed[3]*.0025),(self.seed[1]+self.seed[2])*(self.seed[3] * .0025)) * 10
  769.                 if Noise > 3 then
  770.                     self.data[x][y] = 2
  771.                 end
  772.             end
  773.         end
  774.     end
  775.    
  776.     for i, v in ipairs(self.data) do
  777.         self.plantdata[i] = {}
  778.         for x,y in ipairs(v) do
  779.             if y == 1 then
  780.                 plantchance = math.random(1,100)
  781.                 if plantchance == 1 then
  782.                     self.plantdata[i][x] = 1
  783.                 else
  784.                     self.plantdata[i][x] = 0
  785.                 end
  786.             elseif y == 2 then
  787.                 plantchance = math.random(1,50)
  788.                 if plantchance == 1 then
  789.                     self.plantdata[i][x] = 2
  790.                 else
  791.                     self.plantdata[i][x] = 0
  792.                 end
  793.             elseif y == 3 then
  794.                 plantchance = math.random(1,50)
  795.                 if plantchance == 1 then
  796.                     self.plantdata[i][x] = 3
  797.                 else
  798.                     self.plantdata[i][x] = 0
  799.                 end
  800.             else
  801.                 self.plantdata[i][x] = 0
  802.             end
  803.         end
  804.     end
  805. end
  806.  
  807. function World:draw()
  808.     local offSet = self.render
  809.     local px, py = hero.px, hero.py
  810.    
  811.     -- look around the hero to draw whatever is around him
  812.     translate(px - offSet, 0, py - offSet)
  813.     for y = py - offSet, py + offSet do
  814.         for x = px - offSet, px + offSet do
  815.             if self.data[y] then
  816.                 local val = math.floor(self.data[y][x])
  817.                 local heightval = self.data[y][x]-val
  818.                 heightval = heightval * 100
  819.                 local plantval = self.plantdata[y][x]
  820.                 if y > py - 14 and y < py + 14 and x > px - 14 and x < px + 14 then
  821.                     if val == 1 then
  822.                         forest:draw()
  823.                     elseif val == 2 then
  824.                         plains:draw()
  825.                     elseif val == 3 then
  826.                         water:draw()
  827.                     elseif val == 4 then
  828.                         sand:draw()
  829.                     elseif val == 5 then
  830.                         woodfloor:draw()
  831.                     elseif val == 6 then
  832.                         scale(1,heightval,1)
  833.                         stonewall:draw()
  834.                         scale(1,1/(heightval),1)
  835.                     elseif val == 7 then
  836.                         scale(1,heightval,1)
  837.                         grower:draw()
  838.                         scale(1,1/(heightval),1)
  839.                     elseif val == 8 then
  840.                         scale(1,heightval,1)
  841.                         crate:draw()
  842.                         scale(1,1/(heightval),1)
  843.                     end
  844.                     if plantval == 1 then
  845.                         scale(.25,.25,.25)
  846.                         plainplant:draw()
  847.                         scale(4,4,4)
  848.                     elseif plantval == 2 then
  849.                         scale(.25,.25,.25)
  850.                         forestplant:draw()
  851.                         scale(4,4,4)
  852.                     elseif plantval == 3 then
  853.                         scale(.75,1,.75)
  854.                         cactus:draw()
  855.                         scale(1.3333333,1,1.3333333)
  856.                     end
  857.                     if loaded and val<5 then
  858.                         self.data[y][x] = 5
  859.                         self.plantdata[y][x] = 0
  860.                     end
  861.                 end
  862.                 if val == 9 then
  863.                     if self.data[y+1][x] == 10 or self.data[y][x+1] == 10 then
  864.                         self.data[y][x] = 10
  865.                     end
  866.                     wr1:draw()
  867.                 elseif val == 17 then
  868.                     if self.data[y][x-1] == 18 or self.data[y-1][x] == 18 or self.data[y][x-1] == 10 or self.data[y-1][x] == 10 then
  869.                         self.data[y][x] = 18
  870.                     end
  871.                     lnt:draw()
  872.                 elseif val == 10 then
  873.                     if self.data[y+1][x] ~= 10 and self.data[y][x+1] ~= 10 then
  874.                         self.data[y][x] = 9
  875.                     end
  876.                     wr1i:draw()
  877.                 elseif val == 18 then
  878.                     if self.data[y-1][x] ~= 10 and self.data[y][x-1] ~= 10 and self.data[y-1][x] ~= 18 and self.data[y][x-1] ~= 18 then
  879.                         self.data[y][x] = 17
  880.                     end
  881.                     ldh:draw()
  882.                 elseif val == 11 then
  883.                     if self.data[y+1][x] == 10 or self.data[y-1][x] == 10 or self.data[y][x+1] == 10 or self.data[y+1][x] == 18 or self.data[y-1][x] == 18 or self.data[y][x+1] == 18 then
  884.                         if self.data[y][x-1] == 9 then
  885.                             self.data[y][x-1] = 9
  886.                         elseif self.data[y][x-1] == 17 then
  887.                             self.data[y][x-1] = 17
  888.                         end
  889.                     else
  890.                         if self.data[y][x-1] == 9 then
  891.                             self.data[y][x-1] = 10
  892.                         elseif self.data[y][x-1] == 17 then
  893.                             self.data[y][x-1] = 18
  894.                         end
  895.                     end
  896.                     nt:draw()
  897.                 elseif val == 12 then
  898.                     swt:draw()
  899.                 elseif val == 13 then
  900.                     if self.data[y][x-1] == 9 then
  901.                         self.data[y][x-1] = 10
  902.                     elseif self.data[y][x-1] == 17 then
  903.                         self.data[y][x-1] = 18
  904.                     end
  905.                     if self.data[y][x+1] == 9 then
  906.                         self.data[y][x+1] = 10
  907.                     elseif self.data[y][x+1] == 17 then
  908.                         self.data[y][x+1] = 18
  909.                     end
  910.                     onswt:draw()
  911.                 elseif val == 14 then
  912.                     if self.data[y+1][x] == 10 or self.data[y][x+1] == 10 or self.data[y+1][x] == 18 or self.data[y][x+1] == 18 or self.data[y-1][x] == 10 or self.data[y][x-1] == 10 or self.data[y-1][x] == 18 or self.data[y][x-1] == 18 then
  913.                         self.data[y][x] = 15
  914.                     end
  915.                     offld:draw()
  916.                 elseif val == 15 then
  917.                     if self.data[y+1][x] ~= 10 and self.data[y][x+1] ~= 10 and self.data[y+1][x] ~= 18 and self.data[y][x+1] ~= 18 and self.data[y-1][x] ~= 10 and self.data[y][x-1] ~= 10 and self.data[y-1][x] ~= 18 and self.data[y][x-1] ~= 18 then
  918.                         self.data[y][x] = 14
  919.                     end
  920.                     gnld:draw()
  921.                 elseif val == 16 then
  922.                     if self.data[y+1][x] == 10 and self.data[y-1][x] == 9 then
  923.                         self.data[y-1][x] = 10
  924.                     elseif self.data[y+1][x] == 17 and self.data[y-1][x] == 18 then
  925.                         self.data[y+1][x] = 18
  926.                     end
  927.                     if self.data[y][x+1] == 10 and self.data[y][x-1] == 9 then
  928.                         self.data[y][x-1] = 10
  929.                     elseif self.data[y][x+1] == 17 and self.data[y][x-1] == 18 then
  930.                         self.data[y][x+1] = 18
  931.                     end
  932.                     ins:draw()
  933.                 end
  934.             end
  935.             translate(1,0,0)
  936.         end
  937.         translate(-(1 + 2 * offSet), 0, 1)
  938.     end
  939. end
  940.  
  941. --# floor
  942. --# Floor
  943. Floor = class()
  944.  
  945. function Floor:init(col,tex)
  946.     -- all the unique vertices that make up a cube
  947.     local vertices =
  948.     {
  949.     vec3( 0.5, -.5,.5), -- Right top    front
  950.     vec3(-0.5, -.5,.5), -- Left  top    front
  951.     vec3( 0.5, -.5,-.5), -- Right top    back
  952.     vec3(-0.5, -.5,-.5), -- Left  top    back
  953.     }
  954.    
  955.     -- now construct a cube out of the vertices above
  956.     local verts =
  957.     {
  958.     -- Bottom
  959.     vertices[3], vertices[4], vertices[2],
  960.     vertices[3], vertices[2], vertices[1],
  961.     }
  962.    
  963.     local texvertices =
  964.     {
  965.     vec2(0,0),
  966.     vec2(.99,0),
  967.     vec2(0,.99),
  968.     vec2(.99,.99)
  969.     }
  970.    
  971.    
  972.     -- apply the texture coordinates to each triangle
  973.     local texCoords =
  974.     {
  975.     -- Bottom
  976.     texvertices[1], texvertices[2], texvertices[4],
  977.     texvertices[1], texvertices[4], texvertices[3],
  978.     }
  979.    
  980.     self.model = mesh()
  981.     self.model.vertices = verts
  982.     if tex ~= nil then
  983.         self.model.texCoords = texvertices
  984.         self.model.texture = tex
  985.         self.model.texCoords = texCoords
  986.     end
  987.     if col == 1 then
  988.         self.model:setColors(152, 206, 14, 255) -- plains
  989.     elseif col == 2 then
  990.         self.model:setColors(0, 109 , 255 , 255) --water
  991.     elseif col == 3 then
  992.         self.model:setColors(34 , 164 , 24 , 255)--forest
  993.     elseif col == 4 then
  994.         self.model:setColors(255, 213 , 0, 255) -- sand
  995.     elseif col == 5 then
  996.         self.model:setColors(167, 167, 167, 255) -- low wire
  997.     elseif col == 6 then
  998.         self.model:setColors(192, 183, 62, 255) -- high wire
  999.     elseif col == 7 then
  1000.         self.model:setColors(145, 0, 255, 255) -- not gate
  1001.     elseif col == 8 then
  1002.         self.model:setColors(114, 0, 255, 255) -- switch
  1003.     elseif col == 9 then
  1004.         self.model:setColors(22, 145, 174, 255) -- on switch
  1005.     elseif col == 10 then
  1006.         self.model:setColors(0, 0, 0, 255) -- off led
  1007.     elseif col == 11 then
  1008.         self.model:setColors(0, 255, 0, 255) -- green led
  1009.     elseif col == 12 then
  1010.         self.model:setColors(255, 0, 0, 255) -- insulator
  1011.     elseif col == 13 then
  1012.         self.model:setColors(167, 167, 167, 255) -- ldwire
  1013.     elseif col == 14 then
  1014.         self.model:setColors(192, 183, 62, 255) -- ldhighwire
  1015.     elseif col == 0 then
  1016.         self.model:setColors(255,255,255,255)
  1017.     end
  1018.     color(168, 168, 168, 255)
  1019. end
  1020.  
  1021. function Floor:draw()
  1022.     self.model:draw()
  1023. end
  1024. --# wall
  1025. --# Wall
  1026. Wall = class()
  1027.  
  1028.  
  1029. function Wall:init(col,tex)
  1030.     -- all the unique vertices that make up a cube
  1031.     local vertices =
  1032.     {
  1033.     vec3(-0.5, -0.5,  0.5), -- Left  bottom front
  1034.     vec3( 0.5, -0.5,  0.5), -- Right bottom front
  1035.     vec3( 0.5,  0.5,  0.5), -- Right top    front
  1036.     vec3(-0.5,  0.5,  0.5), -- Left  top    front
  1037.     vec3(-0.5, -0.5, -0.5), -- Left  bottom back
  1038.     vec3( 0.5, -0.5, -0.5), -- Right bottom back
  1039.     vec3( 0.5,  0.5, -0.5), -- Right top    back
  1040.     vec3(-0.5,  0.5, -0.5), -- Left  top    back
  1041.     }
  1042.    
  1043.     -- now construct a cube out of the vertices above
  1044.     local verts =
  1045.     {
  1046.     -- Front
  1047.     vertices[1], vertices[2], vertices[3],
  1048.     vertices[1], vertices[3], vertices[4],
  1049.     -- Right
  1050.     vertices[2], vertices[6], vertices[7],
  1051.     vertices[2], vertices[7], vertices[3],
  1052.     -- Back
  1053.     vertices[6], vertices[5], vertices[8],
  1054.     vertices[6], vertices[8], vertices[7],
  1055.     -- Left
  1056.     vertices[5], vertices[1], vertices[4],
  1057.     vertices[5], vertices[4], vertices[8],
  1058.     -- Top
  1059.     vertices[4], vertices[3], vertices[7],
  1060.     vertices[4], vertices[7], vertices[8],
  1061.     -- Bottom
  1062.     vertices[5], vertices[6], vertices[2],
  1063.     vertices[5], vertices[2], vertices[1],
  1064.     }
  1065.    
  1066.     local texvertices =
  1067.     {
  1068.     vec2(0,0),
  1069.     vec2(.99,0),
  1070.     vec2(0,.99),
  1071.     vec2(.99,.99)
  1072.     }
  1073.    
  1074.     if col == .5 then
  1075.         texvertices =
  1076.         {
  1077.         vec2(0,0),
  1078.         vec2(1,0),
  1079.         vec2(0,1),
  1080.         vec2(1,1)
  1081.         }
  1082.     elseif col == 0 then
  1083.         texvertices =
  1084.         {
  1085.         vec2(0,0),
  1086.         vec2(.625,0),
  1087.         vec2(0,.625),
  1088.         vec2(.625,.625)
  1089.         }
  1090.     end
  1091.    
  1092.     -- apply the texture coordinates to each triangle
  1093.     local texCoords =
  1094.     {
  1095.     -- Front
  1096.     texvertices[1], texvertices[2], texvertices[4],
  1097.     texvertices[1], texvertices[4], texvertices[3],
  1098.     -- Right
  1099.     texvertices[1], texvertices[2], texvertices[4],
  1100.     texvertices[1], texvertices[4], texvertices[3],
  1101.     -- Back
  1102.     texvertices[1], texvertices[2], texvertices[4],
  1103.     texvertices[1], texvertices[4], texvertices[3],
  1104.     -- Left
  1105.     texvertices[1], texvertices[2], texvertices[4],
  1106.     texvertices[1], texvertices[4], texvertices[3],
  1107.     -- Top
  1108.     texvertices[1], texvertices[2], texvertices[4],
  1109.     texvertices[1], texvertices[4], texvertices[3],
  1110.     -- Bottom
  1111.     texvertices[1], texvertices[2], texvertices[4],
  1112.     texvertices[1], texvertices[4], texvertices[3],
  1113.     }
  1114.    
  1115.     self.model = mesh()
  1116.     if tex ~= nil then
  1117.         self.model.vertices = verts
  1118.         self.model.texture = tex
  1119.         self.model.texCoords = texCoords
  1120.     end
  1121.     self.model.vertices = verts
  1122.     if col == 1 then
  1123.         self.model:setColors(55, 138 , 28, 255) -- cactus
  1124.     elseif col == 2 then
  1125.         self.model:setColors(184 , 0, 255 , 255) --plain plants
  1126.     elseif col == 3 then
  1127.         self.model:setColors(255, 88 , 0, 255) -- forest plants
  1128.     elseif col == 4 then
  1129.         self.model:setColors(255, 169, 0, 255) -- grower
  1130.     elseif col == 0 or col == .5 then
  1131.         self.model:setColors(255,255,255,255)
  1132.     end
  1133.     color(145, 0, 255, 255)
  1134. end
  1135.  
  1136. function Wall:draw()
  1137.     self.model:draw()
  1138. end
  1139. --# stick
  1140. --# Stick
  1141. Stick = class()
  1142.  
  1143. function Stick:init()
  1144.     self.direction = 0
  1145.     self.dist = 0
  1146.    
  1147.     self.active = false
  1148.     self.origin = vec2(WIDTH*.75, HEIGHT/8)
  1149.     self.center = self.origin
  1150.     self.pos = self.origin
  1151.    
  1152.    
  1153. end
  1154.  
  1155. function Stick:draw()
  1156.     fill(255, 255, 255, 108)
  1157.     ellipse(self.center.x, self.center.y,200)
  1158.     fill(255, 255, 255, 232)
  1159.     ellipse(self.pos.x, self.pos.y,75)
  1160. end
  1161.  
  1162. function Stick:touched(touch)
  1163.     if touch.state == BEGAN then
  1164.         if CurrentTouch.x >= WIDTH/2 then
  1165.             if CurrentTouch.y <= HEIGHT/2 then
  1166.                 self.center = vec2(touch.x, touch.y)
  1167.                 self.active = true
  1168.             end
  1169.         end
  1170.     end
  1171.    
  1172.     self.pos = vec2(touch.x, touch.y)
  1173.     --sets direction will use to invert stick
  1174.     self.direction = math.atan2(self.pos.y - self.center.y, self.pos.x - self.center.x)
  1175.    
  1176.     self.dist = math.min(2, self.pos:dist(self.center)/32)
  1177.    
  1178.     if touch.state == ENDED then
  1179.         self.center = self.origin
  1180.         self.pos = self.center
  1181.         self.active = false
  1182.     end
  1183. end
  1184.  
  1185. actbutton = class()
  1186.  
  1187. function actbutton:init()
  1188.     self.active = false
  1189.     self.markedtime = 0
  1190. end
  1191.  
  1192. function actbutton:draw()
  1193.     fill(255, 255, 255, 160)
  1194.     ellipse(WIDTH/6,HEIGHT/5,100,100)
  1195. end
  1196.  
  1197. function actbutton:touched(touch)
  1198.     if touch.state == BEGAN then
  1199.         if touch.x <= WIDTH/6 + 50 and touch.x >= WIDTH/6 - 50 then
  1200.             if touch.x <= WIDTH/6 + 50 and touch.x >= WIDTH/6 - 50 then
  1201.                 self.active = true
  1202.             else
  1203.                 self.active = false
  1204.             end
  1205.         else
  1206.             self.active = false
  1207.         end
  1208.     else
  1209.         self.active = false
  1210.     end
  1211. end
  1212.  
  1213. button = class()
  1214.  
  1215. function button:init(x,y,w,h,txt,fs)
  1216.     self.x, self.y, self.w, self.h = x, y, w, h
  1217.     self.txt, self.font = txt, fs
  1218.     self.active = false
  1219. end
  1220.  
  1221. function button:draw()
  1222.     spriteMode(CENTER)
  1223.     sprite("Cargo Bot:Level Select Frame",self.x,self.y,self.w,self.h)
  1224.     font("ArialMT")
  1225.     fontSize(self.font)
  1226.     textMode(CENTER)
  1227.     fill(255, 255, 255, 255)
  1228.     text(self.txt, self.x, self.y)
  1229. end
  1230.  
  1231. function button:touched(touch)
  1232.     if touch.state == BEGAN then
  1233.         if touch.x <= self.x + (self.w/2) and touch.x >= self.x - (self.w/2) then
  1234.             if touch.y <= self.y + (self.h/2) and touch.y >= self.y - (self.h/2) then
  1235.                 self.active = true
  1236.             else
  1237.                 self.active = false
  1238.             end
  1239.         else
  1240.             self.active = false
  1241.         end
  1242.     else
  1243.         self.active = false
  1244.     end
  1245. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement