Log in

Xko #10 [307.5]

378 rounds, 312 wins, 49 losses, 17 draws

Ships

Test Ship 4

{"name": "Test Ship 4", "parts": [{"name": "brain","type": "brain","pos": [0,0],"rot": 0,"welds": [7,9,16,14]},{"name": "gun3","type": "rocket_launcher","pos": [-2,2],"rot": 0,"welds": [11]},{"name": "gun4","type": "rocket_launcher","pos": [-1,2],"rot": 0,"welds": [21]},{"name": "gun5","type": "rocket_launcher","pos": [1,2],"rot": 0,"welds": [22]},{"name": "gun6","type": "rocket_launcher","pos": [2,2],"rot": 0,"welds": [12]},{"name": "gun2","type": "rocket_launcher","pos": [-3,2],"rot": 0,"welds": [10]},{"name": "gun7","type": "rocket_launcher","pos": [3,2],"rot": 0,"welds": [13]},{"name": "gyro","type": "gyroscope","pos": [0,-1],"rot": 0,"welds": [24]},{"name": "ranger","type": "ranger","pos": [0,2],"rot": 0},{"type": "reinforced_hull","pos": [0,1],"rot": 0,"welds": [21,22,8]},{"type": "hull","pos": [-3,1],"rot": 0,"welds": [18]},{"type": "hull","pos": [-2,1],"rot": 0,"welds": [10,21]},{"type": "hull","pos": [2,1],"rot": 0,"welds": [13,22]},{"type": "hull","pos": [3,1],"rot": 0,"welds": [19]},{"name": "thrust_LF","type": "thruster","pos": [-1,0],"rot": 3},{"name": "thrust_LR","type": "thruster","pos": [-1,-2],"rot": 3},{"name": "thrust_RF","type": "thruster","pos": [1,0],"rot": 1},{"name": "thrust_RR","type": "thruster","pos": [1,-2],"rot": 1},{"type": "hull","pos": [-4,1],"rot": 0,"welds": [20]},{"type": "hull","pos": [4,1],"rot": 0,"welds": [23]},{"name": "gun1","type": "rocket_launcher","pos": [-4,2],"rot": 0},{"type": "hull","pos": [-1,1],"rot": 0},{"type": "hull","pos": [1,1],"rot": 0},{"name": "gun8","type": "rocket_launcher","pos": [4,2],"rot": 0},{"type": "hull","pos": [0,-2],"rot": 0,"welds": [15,17]}]}


function SetBrainColor(r,g,b)
	for posX = 0, 2 do
		for posY = 0, 2 do
			brain:SetColor(posX, posY, Color(r,g,b))
		end
	end
end


local turnLeft = false


function Start()
	SetBrainColor(0,0,0)
end


function Update()
	-- Store our angular velocity in a variable to make it easier to use
	local angVel = gyro:AngVel()
 
	if ranger:Range() > 0 and not ranger:IsAlly() then

		-- We see another ship, stop spinning, start ramming,
		-- and remember which way to turn if we lose it again
		SetBrainColor(255,0,0)

		-- Use the standard thrusters to cancel out our angular velocity
		thrust_LR:SetThrust(-angVel)
		thrust_RR:SetThrust(angVel)
		thrust_LF:SetThrust(angVel)
		thrust_RF:SetThrust(-angVel)
 
		
		gun1:Fire()
		gun2:Fire()
		gun3:Fire()
		gun4:Fire()
		gun5:Fire()
		gun6:Fire()
		gun7:Fire()
		gun8:Fire()
		
		-- Figure out which way to turn if we lose the ship again
		if angVel > 0 then
			-- We were spinning left when we saw this target,
			-- so we should turn right if we lose it.
			turnLeft = false
		else
			-- We were spinning right when we saw this target,
			-- so we should turn left if we lose it.
			turnLeft = true
		end
	else
		SetBrainColor(255,255,0)
		-- We don't see another ship, spin around to find one
		
		-- Figure out which way to turn
		local desiredAngVel = turnLeft and 45 or -45
 
		-- Use the standard thrusters to spin the ship at the desired angular speed.
--[[
		thrustFL:SetThrust(desiredAngVel - angVel)
		thrustFR:SetThrust(angVel - desiredAngVel)
		thrustBL:SetThrust(angVel - desiredAngVel)
		thrustBR:SetThrust(desiredAngVel - angVel)
]]

		thrust_LR:SetThrust(desiredAngVel - angVel)
		thrust_RR:SetThrust(angVel - desiredAngVel)
		thrust_LF:SetThrust(angVel - desiredAngVel)
		thrust_RF:SetThrust(desiredAngVel - angVel)
	end
end