some way you can decide how much you want to send
Ai's for other bases(older AI sucked 3:)
things i added
bases have diffrent size with diffrent amount of max citizens
bases grow slowly
Code: Select all
function love.load()
bases = {}
dt = 0
win = false
math.randomseed(os.time())
for i = 1,20 do
base = nil
function choose()
base = {
X = math.floor(math.random(1,7))*100,
Y = math.floor(math.random(1,5))*100,
M = math.random(2,10)*5,
C = 0,
O = math.random(1,3)
}
for i,v in pairs(bases) do--i dont want bases in bases!!!!
if v.X == base.X and v.Y == base.Y then
choose()
end
end
end
choose()
table.insert(bases,base)
end
hold = false
begin = nil
end
function CALCULATE(a,b)
return math.sqrt(a^2+b^2)--MATH IS FOR SUPER MAN
end
function attack(b1,b2)
for i = 1,b1.C-1 do--howmuch can i attack with, you must always hold one citizen, so b.C-1
if b2.C > 0 then--NOT in the -!
b1.C = b1.C-1
b2.C = b2.C-1
if b2.C == 0 then--HIS D:
b2.O = b1.O
end
end
end
end
function givepoints(b1,b2)
for i = 1,b2.M-b2.C do --how much can i give?
if b1.C-1 > 0 then -- how much do I have?
b1.C = b1.C-1
b2.C = b2.C+1
end
end
end
function love.update(d)
dt = dt + d
if dt > 0.5 then
for i,b in pairs(bases) do
if b.C < math.floor(b.M) then
b.C = b.C +1--add citizen
end
if b.M < 50 then
b.M = b.M + 0.1--make base bigger
end
if b.O == 2 or b.O == 3 then
end
end
dt = 0
end
end
function love.draw()
for i,v in pairs(bases) do
if v.O == 1 then
love.graphics.setColor(255,0,0)
elseif v.O == 2 then
love.graphics.setColor(0,255,0)
elseif v.O == 3 then
love.graphics.setColor(0,0,255)
end
love.graphics.circle("fill",v.X,v.Y,v.M,50)
love.graphics.setColor(255,255,255)
love.graphics.print(tostring(v.C),v.X-5,v.Y-5)
end
if hold and begin then
love.graphics.line(begin.X,begin.Y,love.mouse:getX(),love.mouse:getY())
love.graphics.circle("line",begin.X,begin.Y,begin.C*5+begin.M,50)
end
if win then
love.graphics.print("YOU WIN :D!",10,10)
end
end
function love.mousepressed(x,y,mouse)
if mouse == "l" then--right :D?
hold = true
for i,v in pairs(bases) do
if v.O == 1 then
if CALCULATE(x-v.X,y-v.Y) <= v.M then--did i click this circle :O?
begin = v
end
end
end
end
end
function love.mousereleased(x,y,mouse)
if mouse == "l" then--right :D?
hold = false
for i,v in pairs(bases) do
if CALCULATE(x-v.X,y-v.Y) <= v.M then--did i click this circle :O?
if begin == nil then return end
if ((v.M) + (begin.C*5+begin.M))>CALCULATE(begin.X-v.X,begin.Y-v.Y) then--checks if within fancy white circle
if v.O == 1 then --friend so give points
givepoints(begin,v)
elseif v.O == 2 or v.O == 3 then--ENEMY KILL THEM
attack(begin,v)
end
end
end
end
begin = nil
end
end