Update tron

This commit is contained in:
LDDestroier 2018-11-13 20:34:28 -05:00 committed by GitHub
parent 33402c13f0
commit c087bad683
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 33 additions and 16 deletions

49
tron
View File

@ -25,7 +25,7 @@ local player
local resetPlayers = function() local resetPlayers = function()
player = { player = {
[1] = { [1] = {
x = 2, x = -2,
y = -5, y = -5,
direction = -1, direction = -1,
char = "@", char = "@",
@ -44,7 +44,7 @@ local resetPlayers = function()
putTrail = true putTrail = true
}, },
[2] = { [2] = {
x = -2, x = 2,
y = -5, y = -5,
direction = -1, direction = -1,
char = "@", char = "@",
@ -117,6 +117,7 @@ local toblit = {
} }
local you = 1 local you = 1
local nou = 2
local control = { local control = {
up = keys.up, up = keys.up,
@ -397,6 +398,9 @@ local gridDemo = function()
if keysDown[keys.down] then if keysDown[keys.down] then
scrollY = scrollY + 1 scrollY = scrollY + 1
end end
if keysDown[keys.q] then
return "end"
end
drawGrid(scrollX, scrollY) drawGrid(scrollX, scrollY)
ageTrails() ageTrails()
sleep(0.05) sleep(0.05)
@ -405,6 +409,7 @@ end
local moveTick = function() local moveTick = function()
local p local p
local deadGuys = {}
for i = 1, #player do for i = 1, #player do
p = player[i] p = player[i]
if not p.dead then if not p.dead then
@ -412,22 +417,9 @@ local moveTick = function()
p.y = p.y + math.floor(math.sin(math.rad(p.direction * 90))) p.y = p.y + math.floor(math.sin(math.rad(p.direction * 90)))
if getTrail(p.x, p.y) or (p.x == grid.x1 or p.x == grid.x2 or p.y == grid.y1 or p.y == grid.y2) then if getTrail(p.x, p.y) or (p.x == grid.x1 or p.x == grid.x2 or p.y == grid.y1 or p.y == grid.y2) then
p.dead = true p.dead = true
deadGuys[i] = true
p.char = "X" p.char = "X"
lockInput = true lockInput = true
term.setTextColor(colors.white)
if i ~= you then
scrollToPosition(p.x, p.y)
term.setCursorPos(1,scr_y)
term.write("You're winner!")
sleep(1.5)
return "end"
else
sleep(0.5)
term.setCursorPos(1,scr_y)
term.write("You're loser.")
sleep(1.5)
return "end"
end
else else
if p.putTrail then if p.putTrail then
putTrail(p) putTrail(p)
@ -435,6 +427,31 @@ local moveTick = function()
end end
end end
end end
if deadGuys[you] or deadGuys[nou] then
term.setTextColor(colors.white)
if deadGuys[you] and deadGuys[nou] then
scrollToPosition(player[nou].x, player[nou].y)
scrollToPosition(player[you].x, player[you].y)
term.setCursorPos(1,scr_y)
term.write("It's a tie!")
sleep(1.5)
return "end"
else
if deadGuys[you] then
sleep(0.5)
term.setCursorPos(1,scr_y)
term.write("You're loser.")
sleep(1.5)
return "end"
elseif deadGuys[nou] then
scrollToPosition(player[nou].x, player[nou].y)
term.setCursorPos(1,scr_y)
term.write("You're winner!")
sleep(1.5)
return "end"
end
end
end
ageTrails() ageTrails()
end end