1
0
mirror of https://github.com/LDDestroier/CC/ synced 2024-12-15 04:30:28 +00:00

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

37
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,26 +417,38 @@ 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
else
if p.putTrail then
putTrail(p)
end
end
end
end
if deadGuys[you] or deadGuys[nou] then
term.setTextColor(colors.white) term.setTextColor(colors.white)
if i ~= you then if deadGuys[you] and deadGuys[nou] then
scrollToPosition(p.x, p.y) scrollToPosition(player[nou].x, player[nou].y)
scrollToPosition(player[you].x, player[you].y)
term.setCursorPos(1,scr_y) term.setCursorPos(1,scr_y)
term.write("You're winner!") term.write("It's a tie!")
sleep(1.5) sleep(1.5)
return "end" return "end"
else else
if deadGuys[you] then
sleep(0.5) sleep(0.5)
term.setCursorPos(1,scr_y) term.setCursorPos(1,scr_y)
term.write("You're loser.") term.write("You're loser.")
sleep(1.5) sleep(1.5)
return "end" return "end"
end elseif deadGuys[nou] then
else scrollToPosition(player[nou].x, player[nou].y)
if p.putTrail then term.setCursorPos(1,scr_y)
putTrail(p) term.write("You're winner!")
end sleep(1.5)
return "end"
end end
end end
end end