Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local moff = 1
- local mox = 0
- local moy = 0
- local mw = 60
- local mh = 60
- local width = 15
- local height = 13
- local houses = {}
- local people = {}
- local ptext = {}
- local function checkPTCol(pixt, pixel)
- for i=1,#pixt do
- local pix = pixt[i]
- if pix.x == pixel.x and pix.y == pixel.y then
- return true
- end
- end
- return false
- end
- local function checkPCol(pixa1, pixel)
- for i=1,#pixa1.pixs do
- local pix = pixa1.pixs[i]
- if pix.x == pixel.x and pix.y == pixel.y then
- return true
- end
- end
- return false
- end
- local function checkCol(pixa1, pixa2)
- for i=1,#pixa1.pixs do
- local pix1 = pixa1.pixs[i]
- for j=1,#pixa2.pixs do
- local pix2 = pixa2.pixs[j]
- if pix1.x == pix2.x and pix1.y == pix2.y then
- return true
- end
- end
- end
- return false
- end
- local function makePerson(xoff, yoff)
- local amt = math.random(5)
- local texts = {}
- for i=1,amt do
- local type = math.random(10)
- local text = nil
- if type == 1 then text = {"Whats up?"}
- elseif type == 2 then text = {"Hello!"}
- elseif type == 3 then text = {"Hello,", "Good weather we're having!"}
- elseif type == 4 then text = {"Your a new face...", "not many of those these days"}
- elseif type == 5 then text = {"I havn't seen you around", "here before..."}
- elseif type == 6 then text = {"Do you like our village?", "I've never been outside it...", "Mummy won't let me."}
- elseif type == 7 then text = {"The houses around here", "are really pretty,", "don't you think so?"}
- elseif type == 8 then text = {"I can't talk right now,", "Sorry!"}
- elseif type == 9 then text = {"Good day!"}
- elseif type == 10 then text = {"Hi."} end
- texts[#texts + 1] = text
- end
- local pixel = art.createPixel(xoff, yoff, nil, colors.yellow, "A")
- return {pixel, texts}
- end
- local function makeHouse(xoff, yoff, colors)
- local type = math.random(3)
- local house = nil
- local blup = nil
- local cur = colors[1]
- if type == 1 then
- blup = {"@____@",
- "/____\\",
- "|=||=|"}
- elseif type == 2 then
- blup = {"______",
- "|= =|",
- "|=||=|"}
- elseif type == 3 then
- blup = {"@@@.@@@",
- "@_/+\\_@",
- "|+ _ +|",
- "|_|:|_|"}
- elseif type == 4 then
- blup = {"2@#@@",
- "@###@",
- "@1|@@"}
- color = colors.green
- end
- if blup ~= nil then
- house = {}
- for y=1,#blup do
- local line = blup[y]
- for x=1,string.len(line) do
- local c = string.sub(line, x, x)
- if c ~= "@" and c ~= "" and c ~= nil then
- local cn = tonumber(c)
- if cn ~= nil then
- cur = colors[cn]
- else
- house[#house + 1] = art.setPixel(x+xoff, y+yoff, nil, cur, c)
- end
- end
- end
- end
- end
- if house ~= nil then
- house = art.createPixelArray(house)
- end
- return house
- end
- houses[1] = makeHouse(3, 3, {colors.brown, colors.lime})
- ptext[1] = makePerson(2, 2)
- people[1] = ptext[1][1]
- print("OK")
- --create HOUSES
- for n=1,math.random(10, 30) do
- local x = math.random(moff, moff+mw)
- local y = math.random(moff, moff+mh)
- local house = makeHouse(x, y, {colors.brown, colors.lime})
- local ok = true
- if #houses > 0 then
- for i=1,#houses do
- if checkCol(houses[i], house) then
- ok = false
- end
- end
- end
- if ok then houses[#houses + 1] = house end
- end
- --create PEOPLE
- for n=1,math.random(30) do
- local x = math.random(moff, moff+mw)
- local y = math.random(moff, moff+mh)
- local person = makePerson(x, y)
- local ok = true
- for i=1,#houses do
- local house = houses[i]
- if checkPCol(house, person) then ok = false end
- end
- if checkPTCol(people, person[1]) then ok = false end
- if ok then
- people[#people + 1] = person[1]
- ptext[#ptext + 1] = person
- end
- end
- local function getTextBox(text)
- local tx = (moff*2) + width + 2
- local ty = 2
- local tw = tx + 3
- for i=1,#text do
- local l = string.len(text[i])
- if (l+tx+1) > tw then tw = (l+tx+1) end
- end
- local pixels = {}
- local th = #text + 1 + ty
- for x=tx,tw do
- for y=ty,th do
- if x == tx or x == tw or y == ty or y == th then
- pixels[#pixels + 1] = art.setPixel(x, y, nil, colors.blue, "#")
- end
- end
- end
- for i=1,#text do
- pixels[#pixels + 1] = art.setPixel(tx + 1, ty+i, nil, colors.red, text[i])
- end
- textbox = art.createPixelArray(pixels)
- return textbox
- end
- local function getMap(ox, oy)
- local pixels = {}
- for i=1,#houses do
- local house = houses[i]
- for j=1,#house.pixs do
- local pix = house.pixs[j]
- if pix.x > ox and pix.x <= ox+width and pix.y > oy and pix.y <= oy+height then
- pixels[#pixels + 1] = art.setPixel((pix.x)-ox+1, (pix.y)-oy+1, pix.background_color, pix.text_color, pix.character)
- end
- end
- end
- for i=1,#people do
- local pix = people[i]
- if pix.x > ox and pix.x <= ox+width and pix.y > oy and pix.y <= oy+height then
- pixels[#pixels + 1] = art.setPixel((pix.x)-ox+1, (pix.y)-oy+1, pix.background_color, pix.text_color, pix.character)
- end
- end
- local pixarr = art.createPixelArray(pixels)
- --local npixels = {}
- --for i=1,#pixels do
- -- local pix = pixels[i]
- -- npixels[#npixels + 1] = art.createPixel(pix:getX()-ox, pix:getY()-oy, pix:getBackgroundColor(), pix:getTextColor(), pix:getChar())
- --end
- return pixarr
- end
- local background
- local function generate()
- local pixels = {}
- for x=1,(width+(moff*2)) do
- for y=1, (height+(moff*2)) do
- local color = colors.green
- local ch = "+"
- if x == 1 or x == width+(moff*2) or y == 1 or y == height+(moff*2) then
- color = colors.blue
- ch = "#"
- end
- pixels[#pixels + 1] = art.setPixel(x, y, nil, color, ch)
- end
- end
- background = art.createPixelArray(pixels)
- end
- generate()
- local textbox = nil
- local player = art.createPixel(1+moff, 1+moff, nil, colors.red, "@")
- local function check(fromx, fromy)
- if player.x < 1+moff then player:setX(1+moff) end
- if player.x > mw+moff then player:setX(mw+moff) end
- if player.y < 1+moff then player:setY(1+moff) end
- if player.y > mh+moff then player:setY(mh+moff) end
- for i=1,#houses do
- local house = houses[i]
- for j=1,#house.pixs do
- local pixel = house.pixs[j]
- if (player.x)-1 == pixel.x and (player.y)-1 == pixel.y then
- player:setX(fromx)
- player:setY(fromy)
- end
- end
- end
- for i=1,#ptext do
- local person = ptext[i][1]
- local text = ptext[i][2]
- if person.x == (player.x)-1 and person.y == (player.y)-1 then
- player:setX(fromx)
- player:setY(fromy)
- textbox = getTextBox(text[math.random(#text)])
- end
- end
- end
- local function checkClip()
- if player.x <= 1 then player:setX(2) end
- if player.x >= width+2 then player:setX(width+1) end
- if player.y <= 1 then player:setY(2) end
- if player.y >= height+2 then player.setY(height+1) end
- end
- local map = getMap(mox, moy)
- local function updateOffset()
- local oox = mox
- local ooy = moy
- if player.x <= mox+1 then mox = mox - 1 end
- if player.x > mox+1+width then mox = mox + 1 end
- if player.y <= moy+1 then moy = moy - 1 end
- if player.y > moy+1+height then moy = moy + 1 end
- if oox ~= mox or ooy ~= moy or map == nil then
- local difx = oox-mox
- local dify = ooy-moy
- difx = difx * -1
- dify = dify * -1
- return getMap(mox, moy)
- end
- return nil
- end
- local otextbox = nil
- local on = true
- local timer = os.startTimer(0)
- local interval = 0.1
- while on do
- local event, p1, p2 = os.pullEvent()
- if event == "timer" and p1 == timer then
- --term.clear()
- --term.setCursorPos(1,1)
- timer = os.startTimer(interval)
- if otextbox ~= textbox and textbox ~= nil then
- term.clear()
- term.setCursorPos(1,1)
- textbox:draw()
- otextbox = textbox
- end
- background:draw()
- map:draw()
- local oldx = player:getX()
- local oldy = player:getY()
- player:setX(player:getX() - mox)
- player:setY(player:getY() - moy)
- player:draw()
- player:setX(oldx)
- player:setY(oldy)
- term.setCursorPos(1, height + 3)
- print(oldx..":"..oldy)
- print(mox..":"..moy)
- elseif event == "key" then
- local key = p1
- local ox = player.x
- local oy = player.y
- if key == 200 then --up
- player:setY(player.y - 1)
- elseif key == 203 then --left
- player:setX(player.x - 1)
- elseif key == 208 then --down
- player:setY(player.y + 1)
- elseif key == 205 then --right
- player:setX(player.x + 1)
- elseif key == 29 then --control
- on = false
- end
- check(ox, oy)
- local nmap = updateOffset()
- if nmap ~= nil then map = nmap end
- end
- end
- term.clear()
- term.setCursorPos(1,1)
- art.clear()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement