Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local startx = 869
- local starty = 392
- local movementx = 0
- local movementy = 0
- local numberOfLines = 1
- local lines = {
- {869, 392, 869, 392}
- }
- local mainRectangle = {478, 391, 433, 233}
- local obsticles = {
- {478, 391, 103, 56},
- {492, 462, 103, 56},
- {478, 548, 148, 76},
- {626, 391, 87, 127},
- {653, 539, 70, 85},
- {751, 391, 70, 85},
- {763, 493, 148, 76},
- {780, 577, 41, 47}
- }
- function moveAndCheckSystem()
- checkIfFail()
- lines[numberOfLines][3] = lines[numberOfLines][3] + movementx
- lines[numberOfLines][4] = lines[numberOfLines][4] + movementy
- end
- local moveAndCheckTimer = setTimer(moveAndCheckSystem, 200, 0)
- function checkIfFail()
- if movementx ~= 0 then
- for k, v in pairs(obsticles) do
- if lines[numberOfLines][4] >= v[2] and lines[numberOfLines][4] <= v[2] + v[4] then
- if lines[numberOfLines][3] >= v[1] and lines[numberOfLines][3] <= v[1] + v[3] then
- removeEventHandler("onClientRender", getRootElement(), game)
- removeEventHandler("onClientKey", getRootElement(), onMoveKey)
- killTimer(moveAndCheckTimer)
- end
- end
- end
- elseif movementy ~= 0 then
- for k, v in pairs(obsticles) do
- if lines[numberOfLines][3] >= v[1] and lines[numberOfLines][3] <= v[1] + v[3] then
- if lines[numberOfLines][4] >= v[2] and lines[numberOfLines][4] <= v[2] + v[4] then
- removeEventHandler("onClientRender", getRootElement(), game)
- removeEventHandler("onClientKey", getRootElement(), onMoveKey)
- killTimer(moveAndCheckTimer)
- end
- end
- end
- end
- end
- function newLine()
- local previousLine = numberOfLines
- numberOfLines = numberOfLines + 1
- lines[numberOfLines] = {
- lines[previousLine][3],
- lines[previousLine][4],
- lines[previousLine][3],
- lines[previousLine][4]
- }
- iprint(lines[numberOfLines])
- end
- function game()
- for _index, lineCoordinates in pairs(lines) do
- dxDrawLine(
- lineCoordinates[1],
- lineCoordinates[2],
- lineCoordinates[3],
- lineCoordinates[4],
- tocolor(0, 0, 0, 250),
- 2,
- false
- )
- end
- dxDrawRectangle(
- mainRectangle[1],
- mainRectangle[2],
- mainRectangle[3],
- mainRectangle[4],
- tocolor(0, 0, 0, 100),
- false
- )
- dxDrawRectangle(
- obsticles[1][1],
- obsticles[1][2],
- obsticles[1][3],
- obsticles[1][4],
- tocolor(255, 255, 255, 100),
- false
- )
- dxDrawRectangle(
- obsticles[2][1],
- obsticles[2][2],
- obsticles[2][3],
- obsticles[2][4],
- tocolor(255, 255, 255, 100),
- false
- )
- dxDrawRectangle(
- obsticles[3][1],
- obsticles[3][2],
- obsticles[3][3],
- obsticles[3][4],
- tocolor(255, 255, 255, 100),
- false
- )
- dxDrawRectangle(
- obsticles[4][1],
- obsticles[4][2],
- obsticles[4][3],
- obsticles[4][4],
- tocolor(255, 255, 255, 100),
- false
- )
- dxDrawRectangle(
- obsticles[5][1],
- obsticles[5][2],
- obsticles[5][3],
- obsticles[5][4],
- tocolor(255, 255, 255, 100),
- false
- )
- dxDrawRectangle(
- obsticles[6][1],
- obsticles[6][2],
- obsticles[6][3],
- obsticles[6][4],
- tocolor(255, 255, 255, 100),
- false
- )
- dxDrawRectangle(
- obsticles[7][1],
- obsticles[7][2],
- obsticles[7][3],
- obsticles[7][4],
- tocolor(255, 255, 255, 100),
- false
- )
- dxDrawRectangle(
- obsticles[8][1],
- obsticles[8][2],
- obsticles[8][3],
- obsticles[8][4],
- tocolor(255, 255, 255, 100),
- false
- )
- end
- addEventHandler("onClientRender", getRootElement(), game)
- function onMoveKey(key, PoR)
- if PoR == false then
- if key == "arrow_u" then
- if movementy ~= 0 then
- return
- else
- newLine()
- movementx = 0
- movementy = -10
- end
- elseif key == "arrow_d" then
- if movementy ~= 0 then
- return
- else
- newLine()
- movementx = 0
- movementy = 10
- end
- elseif key == "arrow_l" then
- if movementx ~= 0 then
- return
- else
- newLine()
- movementx = -10
- movementy = 0
- end
- elseif key == "arrow_r" then
- if movementx ~= 0 then
- return
- else
- newLine()
- movementx = 10
- movementy = 0
- end
- end
- end
- end
- addEventHandler("onClientKey", getRootElement(), onMoveKey)
Advertisement
Add Comment
Please, Sign In to add comment