@ -12,9 +12,22 @@ config.objectDir = fs.combine(config.mainDir, "objectdata")
local players = { }
local objects = { }
local projectiles = { }
local game = {
custom = 0 ,
customMax = 200 ,
customSpeed = 1 ,
inChipSelect = true ,
paused = false
}
local you = 1
local yourID = os.getComputerID ( )
local revKeys = { }
for k , v in pairs ( keys ) do
revKeys [ v ] = k
end
-- recommended at 0.1 for netplay, which you'll be doing all the time so yeah
local gameDelayInit = 0.05
@ -82,6 +95,8 @@ local stage = {
scrollY = 6
}
stage.scrollX = - 1 + ( scr_x - ( 6 * stage.panelWidth ) ) / 2
local stageChanged = true
local round = function ( num )
@ -308,8 +323,93 @@ local receive = function()
end
local images = {
win = { { " " , "
" , " " , " " , " " } , { " dd ddfdddfddd dd dd dddddddddf ddfdf " , " ffdfdddd ddddd dd dd fd dd dd ddfd ddfdd " , " dddd dd dddd dd dd ddd dd dd ddddfddddd " , " dd df fdddd dd fdfdfdfd dd dd dfdd dd " , " dd dddddddddddd ddd ddd dddddddd dd dd " } , { " df dfdddddfdf df df dfdddddfdd dfddd " , " ddfddfdf fdfdf df df dd df df dddf dfddd " , " fdff df dfdf df df ddf df df dffdddffdf " , " df dd ddfdf df dddddddd df df fddf ff " , " df fdddfffdddff ddf ddf dddddfdf df df " } } ,
lose = { { " " , " " , "
" , " " , " " } , { " eeeff eeeeeeee eeeeeeeeeeeeeeeeeeeeeff " , " ee eeeee ee ee ee ee ee eee " , " ee eeeeeee ee eeeee ee eeeee ee ee " , " ee feeee ee ee ee ee ee fee " , " eeeee eeeeeeeeeeeeeeeeee ee eeeeeeeeeee " } , { " eeeee eeeeefef eeeeefeeeeefeeeeefeeeee " , " ef fefef ef ef ef ef ef fef " , " ef efeffff ef effff ef effff ef ef " , " ef eefef ef ef ef ef ef eef " , " eeeff eeeeefeeeeefeeeeef ef eeeeefeeeff " } } ,
logo = {
{
" " ,
" " ,
"
" ,
" " ,
" " ,
" " ,
" " ,
"
" ,
"
" ,
" " ,
"
" ,
} ,
{
" f3ff3f333 f333ff3f3333f33f3f3f3ff3f3f3ff333333 " ,
" b ffbfbbbbfbbbbfbfb b fbbfbfbb ffbfbbbbfbb b " ,
" bbbbbbbb bbb bbbb b bbbbbbbbbbbbbbbfbbb b " ,
" a11aa11a11a111a11a1aaa111aaaaaaaaaa3fa " ,
" aaa1aaa1aa1aaaa1aa1aa1aaaaeeeeeeee33aaa " ,
" a1a1a1a1aa1aaaa1aa1aa1aaaeeeeeee00eeeef " ,
" faaa1a1a1aa1aaaa1aaaa11aa1eeeee00eeeeeea " ,
" faaaa1a1111a11a1aaaaaa1a1a1a1a1aaa1eee00eeeeeeeea " ,
" f1a1a11aaaaa1aaa1a11a1a1aa11aa11a1aa33eeeeeeeeea " ,
" f1a1a11aaaaa1aa1aa1aa1a1aa11aa111aaa33aeeeeeeea " ,
" a1aa111111a11aaa11a11aa11111a111a11aaaaaaaaaa " ,
} ,
{
" 3f33f3f3f 3f3f33f3ff3f3ff3f3f3f33f3f3f33ffff3f " ,
" b bbfbfbffbfbffbfbf b bffbfbfb bbfbfbfbbff b " ,
" ffffffff fff ffff f fffffffffffffffffff f " ,
" 1aa11aa1aa1aaa1aa1aaa1aaaaaeeeeeee3aaf " ,
" 111a1111aa1aaa1aa1aaa111aeeeeeeeee333af " ,
" 1aa11aa1aa1aaa1aa1aaa1aaaeeeeeeeeeeeeaa " ,
" a111a1aa1aa1aaa1aa111a111aeeeeeeeeeeeeaa " ,
" a1aa1a1aaaa1aa1aaaaaa1a1a1a1a1a1a1aeeeeeeeeeeeeaf " ,
" a11a1a111aa1aaa1a11a1aa1a1a111a11aa333eeeeeeeeaa " ,
" a1aa1a1aaaa1aaaa11a11aa1a1a1a1a1a1aaaaeeeeaaaaf " ,
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaffffffffff " ,
} ,
} ,
win = {
{
" " ,
"
" ,
" " ,
" " ,
" " ,
} ,
{
" 55 55f555f555 55 55 555555555f 55f5f " ,
" ff5f5555 55555 55 55 f5 55 55 55f5 55f55 " ,
" 5555 55 5555 55 55 555 55 55 5555f55555 " ,
" 55 5f f5555 55 f5f5f5f5 55 55 5f55 55 " ,
" 55 555555555555 555f555 55555555 55 55 " ,
} ,
{
" 5f 5f55555f5f 5f 5f 5f55555f55 5f555 " ,
" 55f55f5f f5f5f 5f 5f 55 5f 5f 555f 5f555 " ,
" f5ff 5f 5f5f 5f 5f 55f 5f 5f 5ff555ff5f " ,
" 5f 55 55f5f 5f 55555555 5f 5f f55f ff " ,
" 5f f555fff555ff 55ff55f 55555f5f 5f 5f " ,
} ,
} ,
lose = {
{
" " ,
" " ,
"
" ,
" " ,
" " ,
} ,
{
" 111ff 11111111 111111111111111111111ff " ,
" 11 11111 11 11 11 11 11 111 " ,
" 11 1111111 11 11111 11 11111 11 11 " ,
" 11 f1111 11 11 11 11 11 f11 " ,
" 11111 111111111111111111 11 11111111111 " ,
} ,
{
" 11111 11111f1f 11111f11111f11111f11111 " ,
" 1f f1f1f 1f 1f 1f 1f 1f f1f " ,
" 1f 1f1ffff 1f 1ffff 1f 1ffff 1f 1f " ,
" 1f 11f1f 1f 1f 1f 1f 1f 11f " ,
" 111ff 11111f11111f11111f 1f 11111f111ff " ,
} ,
} ,
panel = {
normal = { { " " , " " , " " } , { " eeeee7 " , " e78877 " , " eeeeee " } , { " 77777e " , " 78888e " , " eeeeee " } } ,
cracked = { { " " , " " , " " } , { " eeeee7 " , " e88888 " , " eeeeee " } , { " 77777e " , " 87777e " , " eeeeee " } } ,
@ -324,6 +424,12 @@ local images = {
buster = { { " " } , { " f4 " } , { " 4f " } }
}
local cwrite = function ( text , y )
local cx , cy = term.getCursorPos ( )
term.setCursorPos ( scr_x / 2 - # text / 2 , y or ( scr_y / 2 ) )
term.write ( text )
end
local act = { stage = { } , player = { } , projectile = { } , object = { } }
act.stage . newPanel = function ( x , y , panelType , owner )
stage.panels [ y ] = stage.panels [ y ] or { }
@ -409,6 +515,105 @@ act.stage.getDamage = function(x, y, pID, oID, pIDsafeCheck, oIDsafeCheck)
return totalDamage , flinching
end
local premadeFolders = {
[ 1 ] = { -- BN2 starting folder, modified slightly
{ " cannon " , " a " } ,
{ " cannon " , " a " } ,
{ " hicannon " , " b " } ,
{ " hicannon " , " b " } ,
{ " shotgun " , " b " } ,
{ " shotgun " , " b " } ,
{ " vgun " , " l " } ,
{ " vgun " , " l " } ,
{ " crossgun " , " l " } ,
{ " minibomb " , " b " } ,
{ " minibomb " , " b " } ,
{ " lilbomb " , " b " } ,
{ " recov120 " , " a " } ,
{ " recov120 " , " a " } ,
{ " recov80 " , " l " } ,
{ " recov50 " , " l " } ,
{ " recov50 " , " l " } ,
{ " sword " , " s " } ,
{ " sword " , " s " } ,
{ " sword " , " s " } ,
{ " panelreturn " , " s " } ,
{ " widesword " , " s " } ,
{ " widesword " , " s " } ,
{ " longsword " , " s " } ,
{ " busterup " , " s " } ,
{ " crackout " , " b " } ,
{ " shockwave " , " b " } ,
{ " areagrab " , " s " } ,
{ " areagrab " , " s " } ,
{ " panelgrab " , " s " } ,
} ,
[ 2 ] = {
{ " cannon " , " a " } ,
{ " cannon " , " a " } ,
{ " hicannon " , " a " } ,
{ " hicannon " , " a " } ,
{ " mcannon " , " a " } ,
{ " mcannon " , " a " } ,
{ " airshot1 " , " a " } ,
{ " airshot1 " , " a " } ,
{ " airshot2 " , " a " } ,
{ " vulcan1 " , " c " } ,
{ " vulcan1 " , " c " } ,
{ " shockwave " , " c " } ,
{ " minibomb " , " c " } ,
{ " minibomb " , " c " } ,
{ " crossbomb " , " c " } ,
{ " panelreturn " , " s " } ,
{ " sword " , " s " } ,
{ " sword " , " s " } ,
{ " longsword " , " s " } ,
{ " busterup " , " s " } ,
{ " widesword " , " s " } ,
{ " rockcube " , " a " } ,
{ " areagrab " , " s " } ,
{ " areagrab " , " s " } ,
{ " panelgrab " , " s " } ,
{ " panelshot " , " s " } ,
{ " panelshot " , " s " } ,
{ " recov50 " , " l " } ,
{ " recov50 " , " l " } ,
{ " recov50 " , " l " } ,
} ,
[ 3 ] = {
{ " cannon " , " a " } ,
{ " hicannon " , " a " } ,
{ " mcannon " , " b " } ,
{ " airshot2 " , " a " } ,
{ " airshot2 " , " a " } ,
{ " rockcube " , " s " } ,
{ " shockwave " , " a " } ,
{ " lilbomb " , " l " } ,
{ " lilbomb " , " l " } ,
{ " areagrab " , " s " } ,
{ " areagrab " , " s " } ,
{ " fightersword " , " f " } ,
{ " panelreturn " , " s " } ,
{ " panelreturn " , " s " } ,
{ " panelshot " , " f " } ,
{ " panelshot " , " f " } ,
{ " doubleshot " , " f " } ,
{ " tripleshot " , " f " } ,
{ " invis " , " l " } ,
{ " recov30 " , " l " } ,
{ " recov30 " , " l " } ,
{ " vulcan2 " , " c " } ,
{ " vulcan1 " , " c " } ,
{ " vulcan1 " , " c " } ,
{ " geddon1 " , " f " } ,
{ " shotgun " , " d " } ,
{ " shotgun " , " d " } ,
{ " vgun " , " d " } ,
{ " vgun " , " d " } ,
{ " spreader " , " d " } ,
}
}
act.player . newPlayer = function ( x , y , owner , direction , image )
local pID = # players + 1
players [ pID ] = {
@ -417,11 +622,12 @@ act.player.newPlayer = function(x, y, owner, direction, image)
owner = owner , -- Either 1 or 2, indicates the red/blue alignment
type = " player " , -- Used for quickly identifying a player/object/projectile at a glance
direction = direction or 1 , -- Either -1 or 1, indicates facing left or right
health = 10 00, -- Once it hits 0, your player is deleted
maxHealth = 1000, -- You cannot regen past this value
health = 6 00, -- Once it hits 0, your player is deleted
maxHealth = 600, -- You cannot heal past this value
image = image , -- Because of CC limitations, I'm just going to have one player sprite
canMove = true , -- If false, pushing the move buttons won't do diddly fuck
canShoot = true , -- If false, pushing the shoot buttons won't do fuckly did
canShoot = true , -- If false, pushing the shoot buttons won't do fuckly didd
isDead = false , -- If true, the current game is over and the opponent wins
busterPower = 2 , -- Strength of MegaBuster
cooldown = { -- All cooldown values are decremented every tick
move = 0 , -- If above 0, you cannot move
@ -437,11 +643,9 @@ act.player.newPlayer = function(x, y, owner, direction, image)
chip = false ,
custom = false
} ,
chipQueue = { } -- Attacks are used in a queue, which is filled each turn
chipQueue = { } , -- Attacks are used in a queue, which is filled each turn
folder = premadeFolders [ math.random ( 1 , 3 ) ]
}
for k , v in pairs ( chips ) do
players [ pID ] . chipQueue [ # players [ pID ] . chipQueue + 1 ] = k
end
return pID
end
@ -695,12 +899,6 @@ act.projectile.newProjectile = function(x, y, player, chipType, noFlinch, altDam
return id
end
for y = 1 , 3 do
for x = 1 , 6 do
act.stage . newPanel ( x , y , " normal " )
end
end
-- loads all chips and objects from file
local loadChips = function ( env )
local cList = fs.list ( config.chipDir )
@ -734,11 +932,6 @@ local loadChips = function(env)
return cOutput , oOutput
end
chips , objectTypes = loadChips ( getfenv ( ) )
act.player . newPlayer ( 2 , 2 , 1 , 1 , " 6 " )
act.player . newPlayer ( 5 , 2 , 2 , - 1 , " 7 " )
local stageImageStitch
local makeStageImageStitch = function ( )
@ -762,8 +955,8 @@ local makeStageImageStitch = function()
end
buffer [ # buffer + 1 ] = {
im ,
( x - 1 ) * stage.panelWidth + 2 ,
( y - 1 ) * stage.panelHeight + 2
( x - 1 ) * stage.panelWidth + 1 ,
( y - 1 ) * stage.panelHeight + 1
}
end
end
@ -772,7 +965,7 @@ local makeStageImageStitch = function()
return merge ( table.unpack ( buffer ) )
end
local render = function ( )
local render = function ( extraImage )
local buffer , im = { }
local sx , sy
if stageChanged or true then
@ -790,20 +983,29 @@ local render = function()
sortedList [ # sortedList + 1 ] = v
end
table.sort ( sortedList , function ( a , b ) return a.y >= b.y end )
if extraImage then
buffer [ # buffer + 1 ] = {
colorSwap ( extraImage [ 1 ] , { [ " f " ] = " " } ) ,
extraImage [ 2 ] ,
extraImage [ 3 ]
}
end
for k , v in pairs ( sortedList ) do
if v.type == " player " then
if v.cooldown . iframe == 0 or ( FRAME % 2 == 0 ) then
sx = ( v.x - 1 ) * stage.panelWidth + 3 + stage.scrollX
sy = ( v.y - 1 ) * stage.panelHeight - 1 + stage.scrollY
buffer [ # buffer + 1 ] = {
colorSwap ( images.player [ v.image ] , { [ " f " ] = " " } ) ,
sx ,
sy
}
if not v.isDead then
if v.cooldown . iframe == 0 or ( FRAME % 2 == 0 ) then
sx = ( v.x - 1 ) * stage.panelWidth + 2
sy = ( v.y - 1 ) * stage.panelHeight - 2
buffer [ # buffer + 1 ] = {
colorSwap ( images.player [ v.image ] , { [ " f " ] = " " } ) ,
sx + stage.scrollX ,
sy + stage.scrollY
}
end
end
elseif v.type == " projectile " then
sx = math.floor ( ( v.x - 1 ) * stage.panelWidth + 4 + stage.scrollX )
sy = math.floor ( ( v.y - 1 ) * stage.panelHeight + 1 + stage.scrollY )
sx = math.floor ( ( v.x - 1 ) * stage.panelWidth + 4 )
sy = math.floor ( ( v.y - 1 ) * stage.panelHeight )
if sx >= - 1 and sx <= scr_x and v.imageData then
for kk , imd in pairs ( v.imageData ) do
@ -816,12 +1018,12 @@ local render = function()
end
elseif v.type == " object " then
sx = ( v.x - 1 ) * stage.panelWidth + 3 + stage.scrollX
sy = ( v.y - 1 ) * stage.panelHeight - 1 + stage.scrollY
sx = ( v.x - 1 ) * stage.panelWidth + 3
sy = ( v.y - 1 ) * stage.panelHeight
buffer [ # buffer + 1 ] = {
colorSwap ( v.image , { [ " f " ] = " " } ) ,
math.floor ( ( v.x - 1 ) * stage.panelWidth + 3 + stage.scrollX ) ,
math.floor ( ( v.y - 1 ) * stage.panelHeight + 1 + stage.scrollY )
math.floor ( sx + stage.scrollX ) ,
math.floor ( sy + stage.scrollY )
}
end
end
@ -853,6 +1055,32 @@ local render = function()
term.write ( player.health )
end
end
term.setTextColor ( colors.white )
term.setBackgroundColor ( colors.black )
if game.custom == game.customMax and FRAME % 8 <= 5 then
cwrite ( " PUSH ' " .. revKeys [ control.custom ] : upper ( ) .. " '! " , 2 )
end
term.setBackgroundColor ( colors.gray )
term.setCursorPos ( 6 , 1 )
term.write ( " [CUSTOM][ " )
local barLength = scr_x - 20
if game.custom == game.customMax then
term.setBackgroundColor ( colors.lime )
else
term.setBackgroundColor ( colors.green )
end
for i = 1 , barLength do
if ( i / barLength ) <= ( game.custom / game.customMax ) then
term.write ( " = " )
else
term.setBackgroundColor ( colors.gray )
term.write ( " " )
end
end
term.setBackgroundColor ( colors.gray )
term.write ( " ] " )
if showDebug then
term.setCursorPos ( 1 , scr_y - 1 )
term.write ( " Frame: " .. FRAME .. " , isHost = " .. tostring ( isHost ) .. " , you = " .. tostring ( you ) )
@ -881,14 +1109,187 @@ local getInput = function()
end
end
local chipSelectScreen = function ( )
local inQueue = { } -- selected chips in menu, by folder position
local pile = { } -- chips for you to choose from, by folder position
local rPile , r = { }
local player = players [ you ]
for i = 1 , 5 do
repeat
r = math.random ( 1 , # player.folder )
until not rPile [ r ]
pile [ # pile + 1 ] = r
rPile [ r ] = true
end
local cursor = 1
local checkIfChoosable = function ( c )
local chip , compareChip = player.folder [ pile [ c ] ]
local isSameChip = true
local isSameCode = true
for i = 1 , # inQueue do
compareChip = player.folder [ inQueue [ i ] ]
if compareChip [ 1 ] ~= chip [ 1 ] then
isSameChip = false
end
if compareChip [ 2 ] ~= chip [ 2 ] then
isSameCode = false
end
end
return isSameCode or isSameChip
end
local renderMenu = function ( )
local chip
term.setBackgroundColor ( colors.gray )
term.setTextColor ( colors.yellow )
for y = 4 , scr_y - 2 do
term.setCursorPos ( 3 , y )
term.write ( ( " " ) : rep ( scr_x - 4 ) )
end
cwrite ( " Select Chips: " , 3 )
term.setTextColor ( colors.lightGray )
cwrite ( " (Push ' " .. revKeys [ control.chip ] : upper ( ) .. " ' to add / ' " .. revKeys [ control.buster ] : upper ( ) .. " ' to remove) " , 4 )
cwrite ( " (Push ENTER to confirm loadout) " , 5 )
for y = 1 , # pile do
if checkIfChoosable ( y ) then
if y == cursor then
term.setBackgroundColor ( colors.lightGray )
term.setTextColor ( colors.white )
else
term.setBackgroundColor ( colors.gray )
term.setTextColor ( colors.white )
end
else
if y == cursor then
term.setBackgroundColor ( colors.lightGray )
term.setTextColor ( colors.gray )
else
term.setBackgroundColor ( colors.gray )
term.setTextColor ( colors.lightGray )
end
end
chip = player.folder [ pile [ y ] ]
term.setCursorPos ( 4 , y + 5 )
term.write ( chips [ chip [ 1 ] ] . info.name .. " " .. chip [ 2 ] : upper ( ) )
end
term.setBackgroundColor ( colors.gray )
term.setTextColor ( colors.lightBlue )
for y = 1 , # inQueue do
chip = player.folder [ inQueue [ y ] ]
term.setCursorPos ( 20 , y + 5 )
term.write ( chips [ chip [ 1 ] ] . info.name .. " " .. chip [ 2 ] : upper ( ) )
end
term.setTextColor ( colors.white )
if player.folder [ pile [ cursor ] ] then
term.setCursorPos ( 5 , 12 )
term.write ( " Description: " )
term.setCursorPos ( 4 , 13 )
term.write ( chips [ player.folder [ pile [ cursor ] ] [ 1 ] ] . info.description )
end
end
local evt
while true do
-- render()
renderMenu ( )
evt = { os.pullEvent ( ) }
if evt [ 1 ] == " key " then
if evt [ 2 ] == keys.up then
cursor = math.max ( cursor - 1 , 1 )
elseif evt [ 2 ] == keys.down then
cursor = math.min ( cursor + 1 , # pile )
elseif evt [ 2 ] == control.chip then
if pile [ cursor ] then
if checkIfChoosable ( cursor ) then
table.insert ( inQueue , pile [ cursor ] )
table.remove ( pile , cursor )
end
end
elseif evt [ 2 ] == control.buster then
if # inQueue > 0 then
table.insert ( pile , inQueue [ # inQueue ] )
table.remove ( inQueue , # inQueue )
end
elseif evt [ 2 ] == keys.enter then
player.chipQueue = { }
for i = 1 , # inQueue do
player.chipQueue [ # player.chipQueue + 1 ] = player.folder [ inQueue [ i ] ] [ 1 ]
end
table.sort ( inQueue , function ( a , b ) return a > b end )
for i = 1 , # inQueue do
table.remove ( inQueue , i )
end
return
end
cursor = math.min ( math.max ( cursor , 1 ) , # pile )
end
end
end
local checkDeadPlayers = function ( )
local deadPlayers , thereIsDead = { } , false
for id , player in pairs ( players ) do
if player.isDead then
deadPlayers [ id ] = true
thereIsDead = true
end
end
return thereIsDead , deadPlayers
end
local waitingForClientChipSelection = false
local runGame = function ( )
local evt , getStateInfo
render ( )
sleep ( 0.5 )
while true do
FRAME = FRAME + 1
render ( )
if game.inChipSelect then
chipSelectScreen ( )
if isHost then
game.inChipSelect = false
game.custom = 0
local msg
cwrite ( " Waiting... " , scr_y - 3 )
repeat
sleep ( 0 )
until cliChipSelect
players [ cliChipSelect.pID ] . chipQueue = cliChipSelect.chipQueue
players [ cliChipSelect.pID ] . folder = cliChipSelect.folder
cliChipSelect = false
transmit ( {
gameID = gameID ,
command = " turn_ready " ,
pID = you ,
} )
else
transmit ( {
gameID = gameID ,
command = " turn_ready " ,
pID = you ,
chipQueue = players [ you ] . chipQueue ,
folder = players [ you ] . folder ,
} )
cwrite ( " Waiting... " , scr_y - 3 )
repeat
msg = receive ( )
msg = type ( msg ) == " table " and msg or { }
until (
msg.gameID == gameID and
msg.command == " turn_ready " and
players [ msg.pID ]
)
end
end
if isHost then
game.custom = math.min ( game.customMax , game.custom + 1 )
getControls ( )
for id , proj in pairs ( projectiles ) do
local success , imageData = chips [ proj.chipType ] . logic ( proj )
@ -907,40 +1308,42 @@ local runGame = function()
end
for id , player in pairs ( players ) do
if player.canMove then
stage.panels [ player.y ] [ player.x ] . reserved = id
end
local dmg , flinching = act.stage . getDamage ( player.x , player.y , id )
if player.cooldown . iframe == 0 and dmg > 0 then
player.health = player.health - dmg
if player.health <= 0 then
table.remove ( players , id )
elseif flinching then
player.cooldown . iframe = 16
player.cooldown . move = 8
player.cooldown . shoot = 6
if not player.isDead then
if player.canMove then
stage.panels [ player.y ] [ player.x ] . reserved = id
end
elseif player.cooldown . shoot == 0 then
if player.canShoot then
if player.control . chip then
if player.chipQueue [ 1 ] then
if chips [ player.chipQueue [ 1 ] ] then
act.projectile . newProjectile ( player.x , player.y , player , player.chipQueue [ 1 ] )
for k , v in pairs ( chips [ player.chipQueue [ 1 ] ] . info.cooldown or { } ) do
player.cooldown [ k ] = v
end
if false then
table.remove ( player.chipQueue , 1 )
else
player.chipQueue [ # player.chipQueue + 1 ] = player.chipQueue [ 1 ]
table.remove ( player.chipQueue , 1 )
local dmg , flinching = act.stage . getDamage ( player.x , player.y , id )
if player.cooldown . iframe == 0 and dmg > 0 then
player.health = math.max ( 0 , player.health - dmg )
if player.health == 0 then
player.isDead = true
elseif flinching then
player.cooldown . iframe = 16
player.cooldown . move = 8
player.cooldown . shoot = 6
end
elseif player.cooldown . shoot == 0 then
if player.canShoot then
if player.control . chip then
if player.chipQueue [ 1 ] then
if chips [ player.chipQueue [ 1 ] ] then
act.projectile . newProjectile ( player.x , player.y , player , player.chipQueue [ 1 ] )
for k , v in pairs ( chips [ player.chipQueue [ 1 ] ] . info.cooldown or { } ) do
player.cooldown [ k ] = v
end
if true then
table.remove ( player.chipQueue , 1 )
else
player.chipQueue [ # player.chipQueue + 1 ] = player.chipQueue [ 1 ]
table.remove ( player.chipQueue , 1 )
end
end
end
end
elseif player.control . buster then
act.projectile . newProjectile ( player.x , player.y , player , " buster " )
for k , v in pairs ( chips.buster . info.cooldown or { } ) do
player.cooldown [ k ] = v
e lseif player.control . buster then
act.projectile . newProjectile ( player.x , player.y , player , " buster " )
for k , v in pairs ( chips.buster . info.cooldown or { } ) do
player.cooldown [ k ] = v
end
end
end
end
@ -978,6 +1381,11 @@ local runGame = function()
end
reduceCooldowns ( )
movePlayers ( )
if players [ you ] then
if players [ you ] . control.custom and game.custom == game.customMax then
game.inChipSelect = true
end
end
sleep ( gameDelayInit )
transmit ( {
gameID = gameID ,
@ -985,6 +1393,7 @@ local runGame = function()
players = players ,
projectiles = projectiles ,
objects = objects ,
game = game ,
stageDamage = stage.damage ,
stagePanels = stage.panels ,
id = id
@ -1000,14 +1409,47 @@ local runGame = function()
control = players [ you ] . control
} )
end
if players [ you ] then
if players [ you ] . control.custom and game.custom == game.customMax then
transmit ( {
gameID = gameID ,
command = " chip_select " ,
id = yourID ,
} )
end
end
evt , getStateInfo = os.pullEvent ( " ccbn_get_state " )
players = getStateInfo.players
projectiles = getStateInfo.projectiles
objects = getStateInfo.objects
game = getStateInfo.game
stage.damage = getStateInfo.stageDamage
stage.panels = getStateInfo.stagePanels
end
if checkDeadPlayers ( ) then
render ( )
break
end
end
local thereIsDead , deadPlayers = checkDeadPlayers ( )
if thereIsDead then
sleep ( 0.5 )
parallel.waitForAny ( function ( )
while true do
if deadPlayers [ you ] then
render ( { images.lose , true , 6 } )
else
render ( { images.win , true , 6 } )
end
sleep ( 1 )
render ( )
sleep ( 0.5 )
end
end , function ( ) os.pullEvent ( " key " ) end )
sleep ( 0.05 )
end
end
@ -1030,6 +1472,22 @@ local interpretNetMessage = function(msg)
if players [ msg.pID ] then
players [ msg.pID ] . control = msg.control
end
elseif msg.command == " chip_select " then
if game.custom == game.customMax then
game.inChipSelect = true
end
elseif msg.command == " turn_ready " then
if (
type ( msg.chipQueue ) == " table " and
players [ msg.pID ] and
type ( msg.folder ) == " table "
) then
cliChipSelect = {
folder = msg.folder ,
chipQueue = msg.chipQueue ,
pID = msg.pID
}
end
end
else
if msg.command == " get_state " then
@ -1037,6 +1495,7 @@ local interpretNetMessage = function(msg)
players = msg.players ,
projectiles = msg.projectiles ,
objects = msg.objects ,
game = msg.game ,
stageDamage = msg.stageDamage ,
stagePanels = msg.stagePanels
} )
@ -1055,22 +1514,33 @@ local networking = function()
end
end
local cwrite = function ( text , y )
local cx , cy = term.getCursorPos ( )
term.setCursorPos ( scr_x / 2 - # text / 2 , y or ( scr_y / 2 ) )
term.write ( text )
end
local startGame = function ( )
getModem ( )
local time = os.epoch ( " utc " )
chips , objectTypes = loadChips ( getfenv ( ) )
stage.panels = { }
stage.damage = { }
players = { }
objects = { }
projectiles = { }
game.custom = 0
game.customSpeed = 1
game.inChipSelect = true
game.paused = false
act.player . newPlayer ( 2 , 2 , 1 , 1 , " 6 " )
act.player . newPlayer ( 5 , 2 , 2 , - 1 , " 7 " )
for y = 1 , 3 do
for x = 1 , 6 do
act.stage . newPanel ( x , y , " normal " )
end
end
transmit ( {
gameID = gameID ,
command = " find_game " ,
respond = false ,
id = yourID ,
time = time ,
chips = chips
-- chips = chips
} )
local msg
waitingForGame = true
@ -1080,20 +1550,103 @@ local startGame = function()
msg = receive ( )
until interpretNetMessage ( msg )
gameID = isHost and gameID or msg.gameID
chips = isHost and chips or msg.chips
-- chips = isHost and chips or msg.chips
transmit ( {
gameID = gameID ,
command = " find_game " ,
respond = true ,
id = yourID ,
time = isHost and math.huge or - math.huge ,
chips = isHost and chips
-- chips = isHost and chips
} )
waitingForGame = false
parallel.waitForAny ( runGame , networking )
end
parallel.waitForAny ( startGame , getInput )
local makeMenu = function ( x , y , options , _cpos )
local cpos = _cpos or 1
local cursor = " > "
local lastPos = cpos
local rend = function ( )
for i = 1 , # options do
if i == cpos then
term.setCursorPos ( x , y + ( i - 1 ) )
term.setTextColor ( colors.white )
term.write ( cursor .. options [ i ] )
else
if i == lastPos then
term.setCursorPos ( x , y + ( i - 1 ) )
term.write ( ( " " ) : rep ( # cursor ) )
lastPos = nil
else
term.setCursorPos ( x + # cursor , y + ( i - 1 ) )
end
term.setTextColor ( colors.gray )
term.write ( options [ i ] )
end
end
end
local evt
rend ( )
while true do
evt = { os.pullEvent ( ) }
if evt [ 1 ] == " key " then
if evt [ 2 ] == keys.up then
lastPos = cpos
cpos = ( cpos - 2 ) % # options + 1
elseif evt [ 2 ] == keys.down then
lastPos = cpos
cpos = ( cpos % # options ) + 1
elseif evt [ 2 ] == keys.home then
lastPos = cpos
cpos = 1
elseif evt [ 2 ] == keys [ " end " ] then
lastPos = cpos
cpos = # options
elseif evt [ 2 ] == keys.enter then
return cpos
end
elseif evt [ 1 ] == " mouse_click " then
if evt [ 4 ] >= y and evt [ 4 ] < y +# options then
if cpos == evt [ 4 ] - ( y - 1 ) then
return cpos
else
lastPos = cpos
cpos = evt [ 4 ] - ( y - 1 )
rend ( )
end
end
end
if lastPos ~= cpos then
rend ( )
end
end
end
local titleScreen = function ( )
local menuOptions = {
" Start Game " ,
" Exit "
}
local choice
while true do
term.setBackgroundColor ( colors.black )
term.clear ( )
drawImage ( images.logo , 2 , 2 )
if useSkynet then
term.setTextColor ( colors.lightGray )
cwrite ( " Skynet Enabled " , 2 + # images.logo [ 1 ] )
end
choice = makeMenu ( 2 , scr_y - # menuOptions , menuOptions )
if choice == 1 then
parallel.waitForAny ( startGame , getInput )
elseif choice == 2 then
return
end
end
end
titleScreen ( )
term.setBackgroundColor ( colors.black )
term.clear ( )