locallook_dir=wormball.get_look_dir(arena,player)--in globals file; returns a string, one of: px, nx, pz, nz for the approximation of player look direction
--get player direction from current input, first check up or down, then look direction
ifcontrol.jump==truethen--if we are going up
arena.players[pl_name].direction={x=0,y=1,z=0}
elseifcontrol.sneak==truethen--if we are going down
arena.players[pl_name].direction={x=0,y=-1,z=0}
elseiflook_dir=='pz'then-- if we are looking in the +z direction,
arena.players[pl_name].direction={x=0,y=0,z=1}
elseiflook_dir=='nx'then-- if we are looking in the -x direction
arena.players[pl_name].direction={x=-1,y=0,z=0}
elseiflook_dir=='nz'then-- if we are looking in the -z direction
arena.players[pl_name].direction={x=0,y=0,z=-1}
elseiflook_dir=='px'then-- if we are looking in the +x direction
--- if the new node is air, move the head, delete the tail, length remains the same
--- if the new node is a powerup of a different color, move the head, but keep the tail, so the snake grows 1
--- if the new node is a powerup of the same color, set move to false, so the next round, the head will not be moved as the tail is deleted to shrink it
--- if the new node is none of the above, it is an obstacle, and the player loses
----------------------------------------------
--- note: if stats.move is set to false, then the next round, the head will not move, but move will be reset
--- note: if the local var remove_tail is true, then after checking the node, the tail is removed
-----------------
--- note: the function wormball.place_node is in the globals file, and performs the math to place the head and the
--- -- first body segment rotated according to the current and previous movement directions.
----------------------------------------------
--- note: we ALWAYS move forward, unless there is an arena obstacle. However, for the dots of the same color,
--- -- we do not move forward NEXT turn. This is so that dots are always *eaten*
----------------------------------------------
ifnew_node=='air'then
ifarena.players[pl_name].move==truethen
-- place the head location into the player's body locations table
arena_lib.HUD_send_msg('broadcast',pl_name,'Yay! You are now '..arena.players[pl_name].score..' long.',2,'wormball_powerup',0x00FF11)
--move the player's attached entity
localatt=player:get_attach()
ifattthen
att:move_to(new_pos,true)
end
--we will be not removing the tail this round, we are growing
remove_tail=false
else
arena.players[pl_name].move=true
end
else--we have run into an arena obstacle, another snake, or ourselves
-- the player will no longer be alive. For the next few rounds, we may still be in-game,
-- as messages are displayed and our worm is converted back into food, but regular player
-- functions that rely on being alive will not run
arena.players[pl_name].alive=false--being dead, the player will lose a length every round until 0, and then they are eliminated. THey wont lose recorded pts tho