mirror of
https://github.com/LDDestroier/CC/
synced 2025-01-19 13:42:54 +00:00
Optimized panel rendering
This commit is contained in:
parent
94383cb44f
commit
04275c732d
113
ccbn.lua
113
ccbn.lua
@ -8,7 +8,7 @@ local you = 1
|
|||||||
local yourID = os.getComputerID()
|
local yourID = os.getComputerID()
|
||||||
|
|
||||||
-- recommended at 0.1 for netplay, which you'll be doing all the time so yeah
|
-- recommended at 0.1 for netplay, which you'll be doing all the time so yeah
|
||||||
local gameDelayInit = 0.1
|
local gameDelayInit = 0.05
|
||||||
|
|
||||||
local gameID = math.random(0, 2^30)
|
local gameID = math.random(0, 2^30)
|
||||||
local waitingForGame = false
|
local waitingForGame = false
|
||||||
@ -516,7 +516,11 @@ local movePlayer = function(pID, xmove, ymove, doCooldown)
|
|||||||
player.x = player.x + xmove
|
player.x = player.x + xmove
|
||||||
player.y = player.y + ymove
|
player.y = player.y + ymove
|
||||||
if doCooldown then
|
if doCooldown then
|
||||||
player.cooldown.move = 2
|
if gameDelayInit < 0.1 then
|
||||||
|
player.cooldown.move = 3
|
||||||
|
else
|
||||||
|
player.cooldown.move = 2
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
@ -629,7 +633,7 @@ local chips = {
|
|||||||
name = "RockCube",
|
name = "RockCube",
|
||||||
description = "Creates a cube-shaped rock!",
|
description = "Creates a cube-shaped rock!",
|
||||||
cooldown = {
|
cooldown = {
|
||||||
shoot = 10,
|
shoot = 6,
|
||||||
move = 4
|
move = 4
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -644,7 +648,7 @@ local chips = {
|
|||||||
name = "Cannon",
|
name = "Cannon",
|
||||||
description = "Fires a shot forwards!",
|
description = "Fires a shot forwards!",
|
||||||
cooldown = {
|
cooldown = {
|
||||||
shoot = 10,
|
shoot = 6,
|
||||||
move = 4
|
move = 4
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -668,8 +672,8 @@ local chips = {
|
|||||||
name = "Dash",
|
name = "Dash",
|
||||||
description = "Dash forwards to deal massive damage!",
|
description = "Dash forwards to deal massive damage!",
|
||||||
cooldown = {
|
cooldown = {
|
||||||
shoot = 10,
|
shoot = 6,
|
||||||
move = 4
|
move = 2
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
logic = function(info)
|
logic = function(info)
|
||||||
@ -678,16 +682,20 @@ local chips = {
|
|||||||
info.playerInitX = info.player.x
|
info.playerInitX = info.player.x
|
||||||
info.playerInitY = info.player.y
|
info.playerInitY = info.player.y
|
||||||
end
|
end
|
||||||
if info.player.x > 7 or info.player.x < 0 then
|
if info.frame > 2 then -- start on frame 3
|
||||||
info.player.x = info.playerInitX
|
if info.player.x > 7 or info.player.x < 0 then
|
||||||
info.player.y = info.playerInitY
|
info.player.x = info.playerInitX
|
||||||
info.player.cooldown.shoot = 10
|
info.player.y = info.playerInitY
|
||||||
info.player.cooldown.move = 4
|
info.player.cooldown.shoot = 6
|
||||||
info.player.canMove = true
|
info.player.cooldown.move = 2
|
||||||
return false
|
info.player.canMove = true
|
||||||
|
return false
|
||||||
|
else
|
||||||
|
info.player.x = info.player.x + (5 / stage.panelWidth) * info.player.direction
|
||||||
|
act.stage.setDamage(info.player.x, info.player.y, 80, info.owner, 4, false)
|
||||||
|
return true
|
||||||
|
end
|
||||||
else
|
else
|
||||||
info.player.x = info.player.x + (5 / stage.panelWidth) * info.player.direction
|
|
||||||
act.stage.setDamage(info.player.x, info.player.y, 80, info.owner, 4, false)
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -728,7 +736,7 @@ local chips = {
|
|||||||
name = "Shotgun",
|
name = "Shotgun",
|
||||||
description = "Hits enemy as well as the panel behind!",
|
description = "Hits enemy as well as the panel behind!",
|
||||||
cooldown = {
|
cooldown = {
|
||||||
shoot = 10,
|
shoot = 6,
|
||||||
move = 4
|
move = 4
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -756,7 +764,7 @@ local chips = {
|
|||||||
name = "CrossGun",
|
name = "CrossGun",
|
||||||
description = "Shoots four diagonal panels around enemy!",
|
description = "Shoots four diagonal panels around enemy!",
|
||||||
cooldown = {
|
cooldown = {
|
||||||
shoot = 10,
|
shoot = 6,
|
||||||
move = 4
|
move = 4
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -914,7 +922,7 @@ local chips = {
|
|||||||
name = "LifeSword",
|
name = "LifeSword",
|
||||||
description = "Slash 2x3 area with devastating power!",
|
description = "Slash 2x3 area with devastating power!",
|
||||||
cooldown = {
|
cooldown = {
|
||||||
shoot = 10,
|
shoot = 6,
|
||||||
move = 5
|
move = 5
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -936,7 +944,7 @@ local chips = {
|
|||||||
name = "Invis",
|
name = "Invis",
|
||||||
description = "Makes you invincible for a short time!",
|
description = "Makes you invincible for a short time!",
|
||||||
cooldown = {
|
cooldown = {
|
||||||
shoot = 10,
|
shoot = 6,
|
||||||
move = 5
|
move = 5
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -951,7 +959,7 @@ local chips = {
|
|||||||
name = "Boomer",
|
name = "Boomer",
|
||||||
description = "Boomerang that orbits stage!",
|
description = "Boomerang that orbits stage!",
|
||||||
cooldown = {
|
cooldown = {
|
||||||
shoot = 10,
|
shoot = 6,
|
||||||
move = 5
|
move = 5
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -1005,7 +1013,7 @@ local chips = {
|
|||||||
name = "MiniBomb",
|
name = "MiniBomb",
|
||||||
description = "Lob a small bomb 2 panels forward!",
|
description = "Lob a small bomb 2 panels forward!",
|
||||||
cooldown = {
|
cooldown = {
|
||||||
shoot = 10,
|
shoot = 6,
|
||||||
move = 5
|
move = 5
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -1028,7 +1036,7 @@ local chips = {
|
|||||||
name = "LilBomb",
|
name = "LilBomb",
|
||||||
description = "Lob a little bomb 2 panels forward!",
|
description = "Lob a little bomb 2 panels forward!",
|
||||||
cooldown = {
|
cooldown = {
|
||||||
shoot = 10,
|
shoot = 6,
|
||||||
move = 5
|
move = 5
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -1053,7 +1061,7 @@ local chips = {
|
|||||||
name = "CrossBomb",
|
name = "CrossBomb",
|
||||||
description = "Lob a cross-shaped bomb 2 panels forward!",
|
description = "Lob a cross-shaped bomb 2 panels forward!",
|
||||||
cooldown = {
|
cooldown = {
|
||||||
shoot = 10,
|
shoot = 6,
|
||||||
move = 5
|
move = 5
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -1079,7 +1087,7 @@ local chips = {
|
|||||||
name = "BigBomb",
|
name = "BigBomb",
|
||||||
description = "Lob a 3x3 grenade 2 panels forward!",
|
description = "Lob a 3x3 grenade 2 panels forward!",
|
||||||
cooldown = {
|
cooldown = {
|
||||||
shoot = 10,
|
shoot = 6,
|
||||||
move = 5
|
move = 5
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -1131,9 +1139,37 @@ end
|
|||||||
act.player.newPlayer(2, 2, 1, 1, "6")
|
act.player.newPlayer(2, 2, 1, 1, "6")
|
||||||
act.player.newPlayer(5, 2, 2, -1, "7")
|
act.player.newPlayer(5, 2, 2, -1, "7")
|
||||||
|
|
||||||
|
local stageImageStitch
|
||||||
|
local stageChanged = true
|
||||||
|
|
||||||
|
local makeStageImageStitch = function()
|
||||||
|
local buffer = {}
|
||||||
|
local im
|
||||||
|
for y = #stage.panels, 1, -1 do
|
||||||
|
for x = 1, #stage.panels[y] do
|
||||||
|
im = images.panel[stage.panels[y][x].panelType]
|
||||||
|
if stage.panels[y][x].owner == 2 then
|
||||||
|
im = colorSwap(im, {e = "b"})
|
||||||
|
end
|
||||||
|
if act.stage.getDamage(x, y) > 0 then
|
||||||
|
im = colorSwap(im, {["7"] = "4", ["8"] = "4"})
|
||||||
|
end
|
||||||
|
buffer[#buffer + 1] = {
|
||||||
|
im,
|
||||||
|
(x - 1) * stage.panelWidth + 2,
|
||||||
|
(y - 1) * stage.panelHeight + 2
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return merge(table.unpack(buffer))
|
||||||
|
end
|
||||||
|
|
||||||
local render = function()
|
local render = function()
|
||||||
local buffer, im = {}
|
local buffer, im = {}
|
||||||
local sx, sy
|
local sx, sy
|
||||||
|
if stageChanged then
|
||||||
|
stageImageStitch = makeStageImageStitch()
|
||||||
|
end
|
||||||
local sortedList = {}
|
local sortedList = {}
|
||||||
for k,v in pairs(projectiles) do
|
for k,v in pairs(projectiles) do
|
||||||
sortedList[#sortedList+1] = v
|
sortedList[#sortedList+1] = v
|
||||||
@ -1180,22 +1216,11 @@ local render = function()
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for y = #stage.panels, 1, -1 do
|
buffer[#buffer + 1] = {
|
||||||
for x = 1, #stage.panels[y] do
|
stageImageStitch,
|
||||||
im = images.panel[stage.panels[y][x].panelType]
|
stage.scrollX + 1,
|
||||||
if stage.panels[y][x].owner == 2 then
|
stage.scrollY + 1
|
||||||
im = colorSwap(im, {e = "b"})
|
}
|
||||||
end
|
|
||||||
if act.stage.getDamage(x, y) > 0 then
|
|
||||||
im = colorSwap(im, {["7"] = "4", ["8"] = "4"})
|
|
||||||
end
|
|
||||||
buffer[#buffer + 1] = {
|
|
||||||
im,
|
|
||||||
(x - 1) * stage.panelWidth + 2 + stage.scrollX,
|
|
||||||
(y - 1) * stage.panelHeight + 2 + stage.scrollY
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
buffer[#buffer + 1] = {makeRectangle(scr_x, scr_y, "f", "f", "f"), 1, 1}
|
buffer[#buffer + 1] = {makeRectangle(scr_x, scr_y, "f", "f", "f"), 1, 1}
|
||||||
drawImage(colorSwap(merge(table.unpack(buffer)), {[" "] = "f"}), 1, 1)
|
drawImage(colorSwap(merge(table.unpack(buffer)), {[" "] = "f"}), 1, 1)
|
||||||
|
|
||||||
@ -1320,7 +1345,7 @@ local runGame = function()
|
|||||||
end
|
end
|
||||||
if object.xvel ~= 0 or object.yvel ~= 0 then
|
if object.xvel ~= 0 or object.yvel ~= 0 then
|
||||||
if not moveObject(id, object.xvel, object.yvel) then
|
if not moveObject(id, object.xvel, object.yvel) then
|
||||||
if checkPlayerAtPos(object.x + 1, object.y) or checkObjectAtPos(object.x + 1, object.y) then
|
if checkPlayerAtPos(object.x + object.xvel, object.y) or checkObjectAtPos(object.x + 1, object.y) then
|
||||||
act.stage.setDamage(object.x + object.xvel, object.y + object.yvel, object.smackDamage, 0, 2, false)
|
act.stage.setDamage(object.x + object.xvel, object.y + object.yvel, object.smackDamage, 0, 2, false)
|
||||||
table.remove(objects, id)
|
table.remove(objects, id)
|
||||||
else
|
else
|
||||||
@ -1334,6 +1359,7 @@ local runGame = function()
|
|||||||
end
|
end
|
||||||
reduceCooldowns()
|
reduceCooldowns()
|
||||||
movePlayers()
|
movePlayers()
|
||||||
|
sleep(gameDelayInit)
|
||||||
transmit({
|
transmit({
|
||||||
gameID = gameID,
|
gameID = gameID,
|
||||||
command = "get_state",
|
command = "get_state",
|
||||||
@ -1344,7 +1370,6 @@ local runGame = function()
|
|||||||
stagePanels = stage.panels,
|
stagePanels = stage.panels,
|
||||||
id = id
|
id = id
|
||||||
})
|
})
|
||||||
sleep(gameDelayInit)
|
|
||||||
else
|
else
|
||||||
getControls()
|
getControls()
|
||||||
if players[you] then
|
if players[you] then
|
||||||
@ -1385,9 +1410,7 @@ local interpretNetMessage = function(msg)
|
|||||||
elseif msg.gameID == gameID then
|
elseif msg.gameID == gameID then
|
||||||
if isHost then
|
if isHost then
|
||||||
if msg.command == "set_controls" then
|
if msg.command == "set_controls" then
|
||||||
if players[msg.pID] then
|
players[msg.pID].control = msg.control
|
||||||
players[msg.pID].control = msg.control
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if msg.command == "get_state" then
|
if msg.command == "get_state" then
|
||||||
|
Loading…
Reference in New Issue
Block a user