Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --config
- running = true
- debug = false
- updaterate = 0.1
- --var setup
- local w, h = term.getSize()
- entitys = {}
- entityCount = 0
- ticks = 0
- --classes setup
- local Man = {}
- Man.default = {name = "Noname", strenght = 100, speed = 1, sprite = "", x = 1, y = 1}
- Man.mt = {__index = Man.default}
- function Man:new(t)
- setmetatable(t, Man.mt)
- entitys[entityCount] = t
- entityCount = entityCount + 1
- return t
- end
- local Wall1 = {}
- Wall1.default = {sprite = "|", resistance = 200, x = 1, y = 1}
- Wall1.mt = {__index = Wall1.default}
- function Wall1:new(t)
- setmetatable(t, Wall1.mt)
- entitys[entityCount] = t
- entityCount = entityCount + 1
- return t
- end
- --Game
- --creating objects
- local man = Man:new({sprite = "o", x = 2 + 1, y = 2})
- local wall = Wall1:new({x = 17, y = 6})
- term.clear()
- term.setCursorPos(1,1)
- function checkPosMove(x, y, dir)
- local canMove = true
- if dir == 17 then
- for i = 0,#entitys do if y-1 == entitys[i].y and x == entitys[i].x then canMove = false end end
- end
- if dir == 31 then
- for i = 0,#entitys do if y+1 == entitys[i].y and x == entitys[i].x then canMove = false end end
- end
- if dir == 30 then
- for i = 0,#entitys do if x-1 == entitys[i].x and y == entitys[i].y then canMove = false end end
- end
- if dir == 32 then
- for i = 0,#entitys do if x+1 == entitys[i].x and y == entitys[i].y then canMove = false end end
- end
- return canMove
- end
- function move(Obj, key)
- if key == 17 and checkPosMove(Obj.x, Obj.y, key) then
- Obj.y = Obj.y - 1
- end
- if key == 31 and checkPosMove(Obj.x, Obj.y, key) then
- Obj.y = Obj.y + 1
- end
- if key == 30 and checkPosMove(Obj.x, Obj.y, key) then
- Obj.x = Obj.x - 1
- end
- if key == 32 and checkPosMove(Obj.x, Obj.y, key) then
- Obj.x = Obj.x + 1
- end
- end
- function tick()
- ticks = ticks + 1
- term.clear()
- term.setCursorPos(1,1)
- end
- function draw()
- term.clear()
- term.setCursorPos(1,1)
- for i = 0,#entitys do
- term.setCursorPos(entitys[i].x, entitys[i].y)
- term.write(entitys[i].sprite)
- end
- end
- fps = os.startTimer(updaterate)
- while running do
- local ev, p1 = os.pullEvent()
- draw()
- if ev == "key" then
- move(man, p1)
- if p1 == 16 then
- term.clear()
- term.setCursorPos(1,1)
- running = false
- end
- end
- fps = os.startTimer(updaterate)
- end
Add Comment
Please, Sign In to add comment