Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --# Main
- -- Use this function to perform your initial setup
- displayMode(FULLSCREEN)
- function setup()
- player = {speed = nil, size = .5}
- stick = Stick()
- dark = false
- wallbut = button(WIDTH-50, HEIGHT*.80, 50, 50, "Stone", 16, 0, 0,0,100)
- floorbut = button(WIDTH-50, (HEIGHT*.80)-50, 50, 50, "Floor", 16, 0,0,0,100)
- grassbut = button(WIDTH-100, (HEIGHT*.80), 50, 50, "Grass", 16, 0, 0, 0,100)
- sandbut = button(WIDTH-100, (HEIGHT*.80)-50, 50, 50, "Sand", 16, 0, 0 , 0, 100)
- forestbut = button(WIDTH-100, (HEIGHT*.80)-100, 50, 50, "Forest", 15, 0 , 0 , 0,100)
- growbut = button(WIDTH-50, (HEIGHT*.80)-100, 50, 50, "Grower", 14, 0,0,0,100)
- savebut = button(WIDTH/2, HEIGHT/2, 100, 50, "Save", 25, 0,0,0,255)
- loadbut = button(WIDTH/2, (HEIGHT/3) + 50 , 100, 50, "Load", 25, 0,0,0,255)
- pausebut = button(50, (HEIGHT*.9)+20, 100, 50, "Pause", 30, 0,0,0,100)
- backbut = button(WIDTH/2, (HEIGHT/3) - 25, 100, 50, "Quit", 25, 0,0,0,255)
- startbut = button(WIDTH/2, HEIGHT/2, 100, 50, "Start", 25, 0,0,0,255)
- invbut = button(WIDTH-75, (HEIGHT*.85) + 20, 100, 50, "Inventory", 24, 0,0,0,100)
- cratebut = button(WIDTH-150, (HEIGHT*.80), 50, 50, "Wood", 16, 0, 0, 0,100)
- wr1but = button(WIDTH-150, (HEIGHT*.80)-50, 50, 50, "Wire", 16, 0, 0, 0,100)
- notbut = button(WIDTH-150, (HEIGHT*.80)-100, 50, 50, "Not", 16, 0, 0, 0,100)
- butbut = button(WIDTH-200, (HEIGHT*.80), 50, 50, "Switch", 16, 0, 0, 0,100)
- gnldbut = button(WIDTH-200, (HEIGHT*.80)-50, 50, 50, "Green", 16, 0, 0, 0,100)
- inslbut = button(WIDTH-200, (HEIGHT*.80)-100, 50, 50, "Insulate", 16, 0, 0, 0,100)
- lnotbut = button(WIDTH-250, (HEIGHT*.80), 50, 50, "ldwire", 16, 0, 0, 0,100)
- ccbut = button(WIDTH-75, (HEIGHT*.85)-30, 100, 50, "CC", 24, 0,0,0,100)
- prevbut = button(WIDTH-50, HEIGHT - 25, 100, 50, "Back", 25, 0,0,0,255)
- selected = 5
- forest = Floor(1)
- sand = Floor(2)
- plains = Floor(3)
- water = Floor(4)
- woodfloor = Floor(0,"Platformer Art:Crate")
- cactus = Wall(1)
- plainplant = Wall(2)
- forestplant = Wall(3)
- grower = Wall(4)
- crate = Wall(0,"Planet Cute:Wood Block")
- stonewall = Wall(0,"Planet Cute:Ramp South")
- wr1 = Floor(5)
- wr1i = Floor(6)
- nt = Floor(7)
- swt = Floor(8)
- onswt = Floor(9)
- offld = Floor(10)
- gnld = Floor(11)
- ins = Floor(12)
- lnt = Floor(13)
- ldh = Floor(14)
- sprite("Planet Cute:Wood Block")
- abut = actbutton()
- world = World(50)
- spawnx = math.random(1,1000)
- spawnz = math.random(1,1000)
- wrldx = math.ceil(spawnx-.5)
- wrldy = math.ceil(spawnz-.5)
- while world.data[wrldy][wrldx] == 4 do
- spawnx = math.random(1,1000)
- spawnz = math.random(1,1000)
- wrldx = math.ceil(spawnx-.5)
- wrldy = math.ceil(spawnz-.5)
- end
- hero = Hero(spawnx,spawnz)
- TO_DEG = 180/math.pi
- for i = 1,4 do
- print(world.seed[i])
- end
- music("Game Music One:Nothingness",true,0.25)
- state = "start"
- loaded = false
- frame = 1
- end
- -- Creates an image of an ellipse and rect
- -- This function gets called once every frame
- function draw()
- frame = frame + 1
- background(149, 104, 27, 255)
- if state == "playing" or state == "start" or state == "inventory" then
- local TO_DEG = TO_DEG
- local hero = hero
- perspective(60)
- camera(hero.x, hero.y + 15, hero.z, hero.x, 0, hero.z, 0, 1, 0)
- if loaded == false then
- time = ElapsedTime
- elseif loaded then
- time = readLocalData("savedtime")
- time = time + ElapsedTime
- end
- -- Draw world
- pushMatrix()
- world:draw()
- popMatrix()
- hero.px = math.ceil(hero.x-.5)
- hero.py = math.ceil(hero.z-.5)
- --make hero face dir that its moving
- pushMatrix()
- translate(hero.x,hero.y,hero.z)
- if stick.active and CurrentTouch.state ~= BEGAN then
- rot = vec4(stick.direction*TO_DEG - 90,0,1,0)
- end
- if rot ~= nil then
- rotate(rot.x,rot.y,rot.z,rot.w)
- end
- scale(player.size,player.size,player.size)
- hero:draw()
- popMatrix()
- if state == "playing" or state == "gcmbt" then
- if math.floor(world.data[hero.py][hero.px]) == 4 and hero.y == 0 then
- player.speed = 25
- if abut.active and math.floor(time) ~= abut.markedtime then
- hero.thirst = hero.thirst + 1
- sound("A Hero's Quest:Drink 2")
- abut.markedtime = math.floor(time)
- dhyd = false
- end
- if math.floor(time) % 1 == 0 and math.floor(time) ~= airmarkedtime and hero.air > 0 then
- hero.air = hero.air - 1
- airmarkedtime = math.floor(time)
- drowning = false
- elseif hero.air == 0 then
- if math.floor(time) % 2 == 0 and math.floor(time) ~= airmarkedtime then
- drowning = true
- hero.health = hero.health - 10
- airmarkedtime = math.floor(time)
- sound("A Hero's Quest:Hit 3")
- end
- end
- else
- player.speed = 10
- if math.floor(time) % 1 == 0 and math.floor(time) ~= airmarkedtime and hero.air < 10 then
- hero.air = hero.air + 1
- airmarkedtime = math.floor(time)
- if hero.air > 0 then
- drowning = false
- end
- end
- end
- if world.plantdata[hero.py][hero.px] == 1 or world.plantdata[hero.py][hero.px] == 2 then
- world.plantdata[hero.py][hero.px] = 0
- hero.food = hero.food + 1
- sound("A Hero's Quest:Eat 1")
- starving = false
- end
- if math.floor(time) % 2 == 0 and math.floor(time) ~= foodmarkedtime then
- if math.floor(time) % 20 == 0 and math.floor(time) ~= foodmarkedtime and not starving then
- hero.food = hero.food - 1
- foodmarkedtime = math.floor(time)
- else
- if hero.food == 0 then
- hero.health = hero.health - 5
- sound("A Hero's Quest:Hit 3")
- foodmarkedtime = math.floor(time)
- starving = true
- elseif hero.food >= 20 and hero.health < 96 then
- hero.health = hero.health + 5
- foodmarkedtime = math.floor(time)
- starving = false
- end
- end
- end
- if math.floor(time) % 2 == 0 and math.floor(time) ~= watermarkedtime then
- if math.floor(time) % 12 == 0 and math.floor(time) ~= watermarkedtime and hero.thirst > 0 and not dhyd then
- hero.thirst = hero.thirst - 1
- watermarkedtime = math.floor(time)
- else
- if hero.thirst == 0 then
- hero.health = hero.health - 5
- sound("A Hero's Quest:Hit 3")
- watermarkedtime = math.floor(time)
- dhyd = true
- end
- end
- end
- 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
- abut.markedtime = math.floor(time)
- if selected == 1 or selected == 2 or selected == 3 then
- cost = 1
- elseif selected == 5 or selected == 9 or selected == 11 or selected == 12 or selected == 14 or selected == 16 or selected == 17 then
- cost = 2
- elseif selected == 6 or selected == 8 then
- cost = 3
- elseif selected == 7 then
- cost = 5
- end
- if hero.food - cost >= 0 then
- hero.food = hero.food - cost
- if selected > 5 and selected < 9 then
- world.data[hero.py][hero.px] = selected + ((world.data[hero.py][hero.px]-math.floor(world.data[hero.py][hero.px])) +.01)
- hero.y = hero.y + 1
- elseif selected < 6 or selected > 8 then
- world.data[hero.py][hero.px] = selected
- end
- place = true
- sound("A Hero's Quest:Drop")
- else
- if selected ~= math.floor(world.data[hero.py][hero.py]) and selected ~= "str" then
- sound("Game Sounds One:Wrong")
- end
- end
- abut.active = false
- else
- place = false
- if world.data[hero.py][hero.px] == 12 and abut.active then
- world.data[hero.py][hero.px] = 13
- abut.active = false
- elseif world.data[hero.py][hero.px] == 13 and abut.active then
- world.data[hero.py][hero.px] = 12
- abut.active = false
- end
- end
- end
- if ((world.data[hero.py][hero.px]-math.floor(world.data[hero.py][hero.px]))*100) < hero.y then
- hero.y = hero.y - 1
- end
- if hero.health <= 0 then
- state = "dead"
- end
- -- Restore orthographic projection
- ortho()
- viewMatrix(matrix())
- resetMatrix()
- if math.floor(time) % 300 == 0 and math.floor(time) ~= daymarkedtime then
- if dark == false then
- dark = true
- daymarkedtime = math.floor(time)
- elseif dark == true then
- dark = false
- daymarkedtime = math.floor(time)
- end
- if dark == false then
- marker = 1
- i1 = 0
- x1 = {}
- x1[1] = 0
- for j = 1,63 do
- for i = hero.py-100,hero.py+100 do
- v = world.data[i]
- for x = hero.px-100, hero.px+100 do
- if v[x] == 5 or v[x] == 6.01 then
- if table.concat(v,"",x,x+5) == "6.016.01556.016.01" and marker == 1 then
- print("found1")
- table.insert(x1,x)
- marker = 2
- i1 = i
- elseif table.concat(v,"",x,x+5) == "6.017.01557.016.01" and marker == 2 then
- marker = 3
- i2 = i
- elseif table.concat(v,"",x,x+5) == "555555" and marker == 3 then
- marker = 4
- i3 = i
- elseif table.concat(v,"",x,x+5) == "555555" and marker == 4 then
- marker = 5
- i4 = i
- elseif table.concat(v,"",x,x+5) == "6.017.01557.016.01" and marker == 5 then
- marker = 6
- i5 = i
- elseif marker == 6 and table.concat(v,"",x,x+5) == "6.016.01556.016.01" then
- print("foundall")
- marker = 1
- i6 = i
- for j,k in ipairs(x1) do
- world.plantdata[i2-1][k + 2] = math.random(1,2)
- world.plantdata[i2-1][k + 3] = math.random(1,2)
- world.plantdata[i1][k + 2] = math.random(1,2)
- world.plantdata[i1][k + 3] = math.random(1,2)
- world.plantdata[i2][k + 2] = math.random(1,2)
- world.plantdata[i2][k + 3] = math.random(1,2)
- world.plantdata[i4+1][k] = math.random(1,2)
- world.plantdata[i4+1][k + 1] = math.random(1,2)
- world.plantdata[i4+1][k + 2] = math.random(1,2)
- world.plantdata[i4+1][k + 3] = math.random(1,2)
- world.plantdata[i4+1][k + 4] = math.random(1,2)
- world.plantdata[i4+1][k + 5] = math.random(1,2)
- world.plantdata[i3][k] = math.random(1,2)
- world.plantdata[i3][k + 1] = math.random(1,2)
- world.plantdata[i3][k + 2] = math.random(1,2)
- world.plantdata[i3][k + 3] = math.random(1,2)
- world.plantdata[i3][k + 4] = math.random(1,2)
- world.plantdata[i3][k + 5] = math.random(1,2)
- world.plantdata[i4][k] = math.random(1,2)
- world.plantdata[i4][k + 1] = math.random(1,2)
- world.plantdata[i4][k + 2] = math.random(1,2)
- world.plantdata[i4][k + 3] = math.random(1,2)
- world.plantdata[i4][k + 4] = math.random(1,2)
- world.plantdata[i4][k + 5] = math.random(1,2)
- world.plantdata[i5][k + 2] = math.random(1,2)
- world.plantdata[i5][k + 3] = math.random(1,2)
- world.plantdata[i6][k + 2] = math.random(1,2)
- world.plantdata[i6][k + 3] = math.random(1,2)
- end
- end
- end
- end
- end
- end
- end
- end
- --fill(night.fillcol.r,night.fillcol.g,night.fillcol.b,night.fillcol.a)
- --rectMode(CENTER)
- --rect(WIDTH/2, HEIGHT/2, WIDTH + 10, HEIGHT + 10)
- pausebut:draw()
- invbut:draw()
- if pausebut.active then
- state = "paused"
- pausebut.active = false
- elseif invbut.active then
- if state == "inventory" then
- state = "playing"
- invbut = button(WIDTH-75, (HEIGHT*.85) + 20, 100, 50, "Inventory", 24, 0,0,0,100)
- elseif state == "playing" then
- state = "inventory"
- invbut = button(WIDTH-75, (HEIGHT*.85) + 20, 100, 50, "Inventory", 24, 255,0,0,255)
- end
- invbut.active = false
- end
- pushStyle()
- strokeWidth(15)
- if not starving then
- stroke(127, 127, 127, 255)
- else
- stroke(255, 0, 0, 255)
- end
- line((WIDTH*.75 + 10), HEIGHT-15, (WIDTH*.75)+210, HEIGHT-15)
- stroke(0, 255, 4, 255)
- if hero.food < 21 then
- line((WIDTH*.75 + 10), HEIGHT-15, (WIDTH*.75 + 10) + hero.food * 10,HEIGHT-15)
- else
- line((WIDTH*.75 + 10), HEIGHT-15, (WIDTH*.75)+210, HEIGHT-15)
- end
- if not dhyd then
- stroke(127, 127, 127, 255)
- else
- stroke(255, 0, 0, 255)
- end
- line((WIDTH*.75 + 10), HEIGHT-50, (WIDTH*.75 + 210), HEIGHT-50)
- stroke(0, 255, 0, 255)
- if hero.thirst < 21 then
- line((WIDTH*.75 + 10), HEIGHT-50, (WIDTH*.75 + 10) + hero.thirst * 10,HEIGHT-50)
- else
- line((WIDTH*.75 + 10), HEIGHT-50, (WIDTH*.75 + 210), HEIGHT-50)
- end
- if hero.health > 66 then
- stroke(0, 255, 4, 255)
- elseif hero.health > 33 then
- stroke(255, 218, 0, 255)
- else
- stroke(255, 0, 0, 255)
- end
- line(120, HEIGHT-15, 120 + hero.health*2,HEIGHT-15)
- if hero.air ~= 10 then
- stroke(0, 71, 255, 255)
- line(((WIDTH/2) - 100), HEIGHT-45, ((WIDTH/2) - 100) + hero.air * 20,HEIGHT-45)
- end
- font("AmericanTypewriter-Bold")
- fontSize(30)
- fill(0, 0, 0, 255)
- textMode(CORNER)
- text("Food", WIDTH*.675, HEIGHT-30)
- text("Water", WIDTH*.65, HEIGHT-60)
- text("Health", 0, HEIGHT-30)
- popStyle()
- if state == "playing" then
- abut:draw()
- end
- if stick.active then
- local ceil = math.ceil
- stick:draw()
- -- move hero based on stick direction
- mvtx = math.cos(stick.direction)/player.speed*stick.dist --coeficcient is inversely proportional to speed
- mvtz = -math.sin(stick.direction)/player.speed*stick.dist --coeficcient is inversely proportional to speed
- hero.x = hero.x - mvtx
- hero.z = hero.z - mvtz
- -- convert to table coordinates
- hero.px = ceil(hero.x - .5)
- hero.py = ceil(hero.z - .5)
- -- lazy collision check
- if world.plantdata[hero.py][hero.px] == 3 and hero.y == 0 then
- hero.x = hero.x + (mvtx * 5) -- +1 --noclip debug mode
- hero.z = hero.z + (mvtz * 5) -- +1
- hero.px = ceil(hero.x)
- hero.py = ceil(hero.z)
- hero.health = hero.health - 2
- sound("A Hero's Quest:Hit 3", .25)
- elseif math.floor(world.data[hero.py][hero.px]) > 5 then
- if ((world.data[hero.py][hero.px]-math.floor(world.data[hero.py][hero.px]))*100) - hero.y == 1 then
- hero.y = hero.y + 1
- elseif ((world.data[hero.py][hero.px]-math.floor(world.data[hero.py][hero.px]))*100) - hero.y > 1 then
- hero.x = hero.x + mvtx
- hero.z = hero.z + mvtz
- end
- end
- end
- if state == "start" then
- rectMode(CENTER)
- fill(0, 0, 0, 178)
- rect(WIDTH/2,HEIGHT/2, WIDTH+10, HEIGHT+ 10)
- textMode(CENTER)
- fontSize(50)
- fill(38, 125, 30, 255)
- --text("Pocket Pete", WIDTH/2 , HEIGHT*0.75)
- text("<INSERT_TITLE_HERE>",WIDTH/2,HEIGHT*.75)
- loadbut:draw()
- startbut:draw()
- if startbut.active then
- state = "playing"
- starttime = math.floor(time)
- startbut.active = false
- elseif loadbut.active then
- hero.x = readLocalData("savedherox")
- hero.z = readLocalData("savedheroz")
- hero.food = readLocalData("savedherofood")
- hero.thirst = readLocalData("savedherothirst")
- hero.health = readLocalData("savedherohealth")
- mydata = readLocalData("saveddata")
- world.data = json.decode(mydata)
- myplants = readLocalData("savedplants")
- world.plantdata = json.decode(myplants)
- dark = readLocalData("saveddark")
- sound("Game Sounds One:Menu Back")
- state = "playing"
- loadbut.active = false
- loaded = true
- end
- elseif state == "inventory" then
- if selected == 6 then
- strokeWidth(5)
- end
- wallbut:draw()
- noStroke()
- if selected == 5 then
- strokeWidth(5)
- end
- floorbut:draw()
- noStroke()
- if selected == 1 then
- strokeWidth(5)
- end
- grassbut:draw()
- noStroke()
- if selected == 2 then
- strokeWidth(5)
- end
- forestbut:draw()
- noStroke()
- if selected == 3 then
- strokeWidth(5)
- end
- sandbut:draw()
- noStroke()
- if selected == 7 then
- strokeWidth(5)
- end
- growbut:draw()
- noStroke()
- if selected == 8 then
- strokeWidth(5)
- end
- cratebut:draw()
- noStroke()
- if selected == 9 then
- strokeWidth(5)
- end
- wr1but:draw()
- noStroke()
- if selected == 11 then
- strokeWidth(5)
- end
- notbut:draw()
- noStroke()
- if selected == 12 then
- strokeWidth(5)
- end
- butbut:draw()
- noStroke()
- if selected == 14 then
- strokeWidth(5)
- end
- gnldbut:draw()
- noStroke()
- if selected == 16 then
- strokeWidth(5)
- end
- inslbut:draw()
- noStroke()
- if selected == 17 then
- strokeWidth(5)
- end
- lnotbut:draw()
- noStroke()
- if wallbut.active then
- selected = 6
- wallbut.active = false
- elseif floorbut.active then
- selected = 5
- floorbut.active = false
- elseif grassbut.active then
- selected = 1
- grassbut.active = false
- elseif forestbut.active then
- selected = 2
- forestbut.active = false
- elseif sandbut.active then
- selected = 3
- sandbut.active = false
- elseif growbut.active then
- selected = 7
- growbut.active = false
- elseif cratebut.active then
- selected = 8
- cratebut.active = false
- elseif wr1but.active then
- selected = 9
- wr1but.active = false
- elseif notbut.active then
- selected = 11
- notbut.active = false
- elseif butbut.active then
- selected = 12
- butbut.active = false
- elseif gnldbut.active then
- selected = 14
- gnldbut.active = false
- elseif inslbut.active then
- selected = 16
- inslbut.active = false
- elseif lnotbut.active then
- selected = 17
- lnotbut.active = false
- end
- rectMode(CENTER)
- fill(0, 0, 0, 91)
- rect(WIDTH/2, HEIGHT/2, WIDTH, HEIGHT)
- end
- elseif state == "dead" then
- background(0, 0, 0, 255)
- font("AmericanTypewriter-Bold")
- fontSize(100)
- fill(255, 255, 255, 255)
- textMode(CENTER)
- text("YOU DIED", WIDTH/2 , HEIGHT/2)
- loadbut:draw()
- elseif state == "paused" then
- background(127, 127, 127, 255)
- font("AmericanTypewriter-Bold")
- fontSize(100)
- fill(0, 0, 0, 255)
- textMode(CENTER)
- text("Paused", WIDTH/2 , HEIGHT*.75)
- loadbut:draw()
- savebut:draw()
- backbut:draw()
- if savebut.active then
- saveLocalData("savedherox", hero.x)
- saveLocalData("savedheroz", hero.z)
- saveLocalData("savedherofood", hero.food)
- saveLocalData("savedherothirst", hero.thirst)
- saveLocalData("savedherohealth", hero.health)
- encodeddata = json.encode(world.data)
- saveLocalData("saveddata", encodeddata)
- encodedplants = json.encode(world.plantdata)
- saveLocalData("savedplants", encodedplants)
- saveLocalData("savedtime", time)
- saveLocalData("saveddark", dark)
- sound("Game Sounds One:Menu Select")
- state = "playing"
- savebut.active = false
- elseif loadbut.active then
- hero.x = readLocalData("savedherox")
- hero.z = readLocalData("savedheroz")
- hero.food = readLocalData("savedherofood")
- hero.thirst = readLocalData("savedherothirst")
- hero.health = readLocalData("savedherohealth")
- mydata = readLocalData("saveddata")
- world.data = json.decode(mydata)
- myplants = readLocalData("savedplants")
- world.plantdata = json.decode(myplants)
- dark = readLocalData("saveddark")
- sound("Game Sounds One:Menu Back")
- state = "playing"
- loadbut.active = false
- loaded = true
- elseif backbut.active then
- close()
- backbut.active = false
- end
- end
- end
- --new nav function
- function touched(touch)
- if state == "playing" then
- stick:touched(touch)
- abut:touched(touch)
- pausebut:touched(touch)
- invbut:touched(touch)
- elseif state == "paused" then
- savebut:touched(touch)
- loadbut:touched(touch)
- backbut:touched(touch)
- elseif state == "start" then
- loadbut:touched(touch)
- startbut:touched(touch)
- elseif state == "inventory" then
- wallbut:touched(touch)
- floorbut:touched(touch)
- grassbut:touched(touch)
- sandbut:touched(touch)
- forestbut:touched(touch)
- growbut:touched(touch)
- invbut:touched(touch)
- cratebut:touched(touch)
- wr1but:touched(touch)
- notbut:touched(touch)
- butbut:touched(touch)
- gnldbut:touched(touch)
- inslbut:touched(touch)
- lnotbut:touched(touch)
- end
- end
- --# hero
- --# Hero
- Hero = class()
- function Hero:init(x, z)
- self.x, self.y, self.z = x,0,z
- self.px, self.py = math.ceil(x+.5), math.ceil(z+.5)
- self.col = 1
- self.mdl = Character(self.col)
- self.food = 1000
- self.health = 100
- self.thirst = 1000
- self.air = 10
- end
- function Hero:draw()
- self.mdl:draw()
- end
- --# Characters
- --# Floor
- Character = class()
- function Character:init(col)
- -- all the unique vertices that make up a cube
- local vertices =
- {
- vec3( 0.3, -0.5,0.3), -- Right top front
- vec3(-0.3, -0.5,0.3), -- Left top front
- vec3( 0.5, -0.5,-0.5), -- Right top back
- vec3(-0.5, -0.5,-0.5), -- Left top back
- }
- -- now construct a cube out of the vertices above
- local verts =
- {
- -- Bottom
- vertices[3], vertices[4], vertices[2],
- vertices[3], vertices[2], vertices[1],
- }
- -- all the unique texture positions needed
- local texvertices =
- {
- vec2(0,0),
- vec2(1,0),
- vec2(0,1),
- vec2(1,1)
- }
- -- apply the texture coordinates to each triangle
- local texCoords =
- {
- -- Bottom
- texvertices[2], texvertices[1], texvertices[4],
- texvertices[1], texvertices[2], texvertices[3],
- }
- self.model = mesh()
- self.model.vertices = verts
- if col == 1 then
- self.model:setColors(255 , 0 , 78 , 255)
- elseif col == 2 then
- self.model:setColors(0, 66, 255, 255)
- end
- color(0, 66, 255, 255)
- end
- function Character:draw()
- self.model:draw()
- end
- --# world
- --# World
- World = class()
- function World:init(render)
- -- define the world
- self.seed = {math.random(1,10),math.random(1,10),math.random(1,10),math.random(1,5)}
- self.render = render
- self.data = {}
- self.plantdata = {}
- for x = 1, 1000 do
- self.data[x] = {}
- for y = 1, 1000 do
- Noise = noise(x*(self.seed[3]*.0025),y*(self.seed[3]*.0025),self.seed[1]*(self.seed[3] * .0025)) * 10
- if Noise < -1 then
- self.data[x][y] = 3
- Noise = noise(x*(self.seed[3]*.0025),y*(self.seed[3]*.0025),(self.seed[1]+self.seed[4])*(self.seed[3] * .0025)) * 10
- if Noise < -2 then
- self.data[x][y] = 4
- end
- else
- self.data[x][y] = 1
- Noise = noise(x*(self.seed[3]*.0025),y*(self.seed[3]*.0025),(self.seed[1]+self.seed[2])*(self.seed[3] * .0025)) * 10
- if Noise > 3 then
- self.data[x][y] = 2
- end
- end
- end
- end
- for i, v in ipairs(self.data) do
- self.plantdata[i] = {}
- for x,y in ipairs(v) do
- if y == 1 then
- plantchance = math.random(1,100)
- if plantchance == 1 then
- self.plantdata[i][x] = 1
- else
- self.plantdata[i][x] = 0
- end
- elseif y == 2 then
- plantchance = math.random(1,50)
- if plantchance == 1 then
- self.plantdata[i][x] = 2
- else
- self.plantdata[i][x] = 0
- end
- elseif y == 3 then
- plantchance = math.random(1,50)
- if plantchance == 1 then
- self.plantdata[i][x] = 3
- else
- self.plantdata[i][x] = 0
- end
- else
- self.plantdata[i][x] = 0
- end
- end
- end
- end
- function World:draw()
- local offSet = self.render
- local px, py = hero.px, hero.py
- -- look around the hero to draw whatever is around him
- translate(px - offSet, 0, py - offSet)
- for y = py - offSet, py + offSet do
- for x = px - offSet, px + offSet do
- if self.data[y] then
- local val = math.floor(self.data[y][x])
- local heightval = self.data[y][x]-val
- heightval = heightval * 100
- local plantval = self.plantdata[y][x]
- if y > py - 14 and y < py + 14 and x > px - 14 and x < px + 14 then
- if val == 1 then
- forest:draw()
- elseif val == 2 then
- plains:draw()
- elseif val == 3 then
- water:draw()
- elseif val == 4 then
- sand:draw()
- elseif val == 5 then
- woodfloor:draw()
- elseif val == 6 then
- scale(1,heightval,1)
- stonewall:draw()
- scale(1,1/(heightval),1)
- elseif val == 7 then
- scale(1,heightval,1)
- grower:draw()
- scale(1,1/(heightval),1)
- elseif val == 8 then
- scale(1,heightval,1)
- crate:draw()
- scale(1,1/(heightval),1)
- end
- if plantval == 1 then
- scale(.25,.25,.25)
- plainplant:draw()
- scale(4,4,4)
- elseif plantval == 2 then
- scale(.25,.25,.25)
- forestplant:draw()
- scale(4,4,4)
- elseif plantval == 3 then
- scale(.75,1,.75)
- cactus:draw()
- scale(1.3333333,1,1.3333333)
- end
- if loaded and val<5 then
- self.data[y][x] = 5
- self.plantdata[y][x] = 0
- end
- end
- if val == 9 then
- if self.data[y+1][x] == 10 or self.data[y][x+1] == 10 then
- self.data[y][x] = 10
- end
- wr1:draw()
- elseif val == 17 then
- 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
- self.data[y][x] = 18
- end
- lnt:draw()
- elseif val == 10 then
- if self.data[y+1][x] ~= 10 and self.data[y][x+1] ~= 10 then
- self.data[y][x] = 9
- end
- wr1i:draw()
- elseif val == 18 then
- 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
- self.data[y][x] = 17
- end
- ldh:draw()
- elseif val == 11 then
- 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
- if self.data[y][x-1] == 9 then
- self.data[y][x-1] = 9
- elseif self.data[y][x-1] == 17 then
- self.data[y][x-1] = 17
- end
- else
- if self.data[y][x-1] == 9 then
- self.data[y][x-1] = 10
- elseif self.data[y][x-1] == 17 then
- self.data[y][x-1] = 18
- end
- end
- nt:draw()
- elseif val == 12 then
- swt:draw()
- elseif val == 13 then
- if self.data[y][x-1] == 9 then
- self.data[y][x-1] = 10
- elseif self.data[y][x-1] == 17 then
- self.data[y][x-1] = 18
- end
- if self.data[y][x+1] == 9 then
- self.data[y][x+1] = 10
- elseif self.data[y][x+1] == 17 then
- self.data[y][x+1] = 18
- end
- onswt:draw()
- elseif val == 14 then
- 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
- self.data[y][x] = 15
- end
- offld:draw()
- elseif val == 15 then
- 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
- self.data[y][x] = 14
- end
- gnld:draw()
- elseif val == 16 then
- if self.data[y+1][x] == 10 and self.data[y-1][x] == 9 then
- self.data[y-1][x] = 10
- elseif self.data[y+1][x] == 17 and self.data[y-1][x] == 18 then
- self.data[y+1][x] = 18
- end
- if self.data[y][x+1] == 10 and self.data[y][x-1] == 9 then
- self.data[y][x-1] = 10
- elseif self.data[y][x+1] == 17 and self.data[y][x-1] == 18 then
- self.data[y][x+1] = 18
- end
- ins:draw()
- end
- end
- translate(1,0,0)
- end
- translate(-(1 + 2 * offSet), 0, 1)
- end
- end
- --# floor
- --# Floor
- Floor = class()
- function Floor:init(col,tex)
- -- all the unique vertices that make up a cube
- local vertices =
- {
- vec3( 0.5, -.5,.5), -- Right top front
- vec3(-0.5, -.5,.5), -- Left top front
- vec3( 0.5, -.5,-.5), -- Right top back
- vec3(-0.5, -.5,-.5), -- Left top back
- }
- -- now construct a cube out of the vertices above
- local verts =
- {
- -- Bottom
- vertices[3], vertices[4], vertices[2],
- vertices[3], vertices[2], vertices[1],
- }
- local texvertices =
- {
- vec2(0,0),
- vec2(.99,0),
- vec2(0,.99),
- vec2(.99,.99)
- }
- -- apply the texture coordinates to each triangle
- local texCoords =
- {
- -- Bottom
- texvertices[1], texvertices[2], texvertices[4],
- texvertices[1], texvertices[4], texvertices[3],
- }
- self.model = mesh()
- self.model.vertices = verts
- if tex ~= nil then
- self.model.texCoords = texvertices
- self.model.texture = tex
- self.model.texCoords = texCoords
- end
- if col == 1 then
- self.model:setColors(152, 206, 14, 255) -- plains
- elseif col == 2 then
- self.model:setColors(0, 109 , 255 , 255) --water
- elseif col == 3 then
- self.model:setColors(34 , 164 , 24 , 255)--forest
- elseif col == 4 then
- self.model:setColors(255, 213 , 0, 255) -- sand
- elseif col == 5 then
- self.model:setColors(167, 167, 167, 255) -- low wire
- elseif col == 6 then
- self.model:setColors(192, 183, 62, 255) -- high wire
- elseif col == 7 then
- self.model:setColors(145, 0, 255, 255) -- not gate
- elseif col == 8 then
- self.model:setColors(114, 0, 255, 255) -- switch
- elseif col == 9 then
- self.model:setColors(22, 145, 174, 255) -- on switch
- elseif col == 10 then
- self.model:setColors(0, 0, 0, 255) -- off led
- elseif col == 11 then
- self.model:setColors(0, 255, 0, 255) -- green led
- elseif col == 12 then
- self.model:setColors(255, 0, 0, 255) -- insulator
- elseif col == 13 then
- self.model:setColors(167, 167, 167, 255) -- ldwire
- elseif col == 14 then
- self.model:setColors(192, 183, 62, 255) -- ldhighwire
- elseif col == 0 then
- self.model:setColors(255,255,255,255)
- end
- color(168, 168, 168, 255)
- end
- function Floor:draw()
- self.model:draw()
- end
- --# wall
- --# Wall
- Wall = class()
- function Wall:init(col,tex)
- -- all the unique vertices that make up a cube
- local vertices =
- {
- vec3(-0.5, -0.5, 0.5), -- Left bottom front
- vec3( 0.5, -0.5, 0.5), -- Right bottom front
- vec3( 0.5, 0.5, 0.5), -- Right top front
- vec3(-0.5, 0.5, 0.5), -- Left top front
- vec3(-0.5, -0.5, -0.5), -- Left bottom back
- vec3( 0.5, -0.5, -0.5), -- Right bottom back
- vec3( 0.5, 0.5, -0.5), -- Right top back
- vec3(-0.5, 0.5, -0.5), -- Left top back
- }
- -- now construct a cube out of the vertices above
- local verts =
- {
- -- Front
- vertices[1], vertices[2], vertices[3],
- vertices[1], vertices[3], vertices[4],
- -- Right
- vertices[2], vertices[6], vertices[7],
- vertices[2], vertices[7], vertices[3],
- -- Back
- vertices[6], vertices[5], vertices[8],
- vertices[6], vertices[8], vertices[7],
- -- Left
- vertices[5], vertices[1], vertices[4],
- vertices[5], vertices[4], vertices[8],
- -- Top
- vertices[4], vertices[3], vertices[7],
- vertices[4], vertices[7], vertices[8],
- -- Bottom
- vertices[5], vertices[6], vertices[2],
- vertices[5], vertices[2], vertices[1],
- }
- local texvertices =
- {
- vec2(0,0),
- vec2(.99,0),
- vec2(0,.99),
- vec2(.99,.99)
- }
- if col == .5 then
- texvertices =
- {
- vec2(0,0),
- vec2(1,0),
- vec2(0,1),
- vec2(1,1)
- }
- elseif col == 0 then
- texvertices =
- {
- vec2(0,0),
- vec2(.625,0),
- vec2(0,.625),
- vec2(.625,.625)
- }
- end
- -- apply the texture coordinates to each triangle
- local texCoords =
- {
- -- Front
- texvertices[1], texvertices[2], texvertices[4],
- texvertices[1], texvertices[4], texvertices[3],
- -- Right
- texvertices[1], texvertices[2], texvertices[4],
- texvertices[1], texvertices[4], texvertices[3],
- -- Back
- texvertices[1], texvertices[2], texvertices[4],
- texvertices[1], texvertices[4], texvertices[3],
- -- Left
- texvertices[1], texvertices[2], texvertices[4],
- texvertices[1], texvertices[4], texvertices[3],
- -- Top
- texvertices[1], texvertices[2], texvertices[4],
- texvertices[1], texvertices[4], texvertices[3],
- -- Bottom
- texvertices[1], texvertices[2], texvertices[4],
- texvertices[1], texvertices[4], texvertices[3],
- }
- self.model = mesh()
- if tex ~= nil then
- self.model.vertices = verts
- self.model.texture = tex
- self.model.texCoords = texCoords
- end
- self.model.vertices = verts
- if col == 1 then
- self.model:setColors(55, 138 , 28, 255) -- cactus
- elseif col == 2 then
- self.model:setColors(184 , 0, 255 , 255) --plain plants
- elseif col == 3 then
- self.model:setColors(255, 88 , 0, 255) -- forest plants
- elseif col == 4 then
- self.model:setColors(255, 169, 0, 255) -- grower
- elseif col == 0 or col == .5 then
- self.model:setColors(255,255,255,255)
- end
- color(145, 0, 255, 255)
- end
- function Wall:draw()
- self.model:draw()
- end
- --# stick
- --# Stick
- Stick = class()
- function Stick:init()
- self.direction = 0
- self.dist = 0
- self.active = false
- self.origin = vec2(WIDTH*.75, HEIGHT/8)
- self.center = self.origin
- self.pos = self.origin
- end
- function Stick:draw()
- fill(255, 255, 255, 108)
- ellipse(self.center.x, self.center.y,200)
- fill(255, 255, 255, 232)
- ellipse(self.pos.x, self.pos.y,75)
- end
- function Stick:touched(touch)
- if touch.state == BEGAN then
- if CurrentTouch.x >= WIDTH/2 then
- if CurrentTouch.y <= HEIGHT/2 then
- self.center = vec2(touch.x, touch.y)
- self.active = true
- end
- end
- end
- self.pos = vec2(touch.x, touch.y)
- --sets direction will use to invert stick
- self.direction = math.atan2(self.pos.y - self.center.y, self.pos.x - self.center.x)
- self.dist = math.min(2, self.pos:dist(self.center)/32)
- if touch.state == ENDED then
- self.center = self.origin
- self.pos = self.center
- self.active = false
- end
- end
- actbutton = class()
- function actbutton:init()
- self.active = false
- self.markedtime = 0
- end
- function actbutton:draw()
- fill(255, 255, 255, 160)
- ellipse(WIDTH/6,HEIGHT/5,100,100)
- end
- function actbutton:touched(touch)
- if touch.state == BEGAN then
- if touch.x <= WIDTH/6 + 50 and touch.x >= WIDTH/6 - 50 then
- if touch.x <= WIDTH/6 + 50 and touch.x >= WIDTH/6 - 50 then
- self.active = true
- else
- self.active = false
- end
- else
- self.active = false
- end
- else
- self.active = false
- end
- end
- button = class()
- function button:init(x,y,w,h,txt,fs)
- self.x, self.y, self.w, self.h = x, y, w, h
- self.txt, self.font = txt, fs
- self.active = false
- end
- function button:draw()
- spriteMode(CENTER)
- sprite("Cargo Bot:Level Select Frame",self.x,self.y,self.w,self.h)
- font("ArialMT")
- fontSize(self.font)
- textMode(CENTER)
- fill(255, 255, 255, 255)
- text(self.txt, self.x, self.y)
- end
- function button:touched(touch)
- if touch.state == BEGAN then
- if touch.x <= self.x + (self.w/2) and touch.x >= self.x - (self.w/2) then
- if touch.y <= self.y + (self.h/2) and touch.y >= self.y - (self.h/2) then
- self.active = true
- else
- self.active = false
- end
- else
- self.active = false
- end
- else
- self.active = false
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement