My 1-script copy of Invader by Robin - WIP

Show off your games, demos and other (playable) creations.
User avatar
GijsB
Party member
Posts: 380
Joined: Wed Jul 20, 2011 10:19 pm
Location: Netherlands

My 1-script copy of Invader by Robin - WIP

Post by GijsB »

things to add
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
Last edited by GijsB on Sat Jul 23, 2011 1:03 pm, edited 5 times in total.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: My 1-script copy of Invader by Robin - WIP

Post by kikito »

Quick tip. If you end up seeying things like this:

Code: Select all

                        end
                     end
                  end
               end
            end
         end
      end
      begin = nil
   end 
end
You should really, really consider using some more functions.
When I write def I mean function.
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: My 1-script copy of Invader by Robin - WIP

Post by ivan »

Or perhaps using the "return" statement a bit more often for example:

Code: Select all

function love.mousepressed(x,y,mouse)
   if mouse == "l" then--right :D?
      hold = true
      for i,v in pairs(bases) do
Could become:

Code: Select all

function love.mousepressed(x,y,mouse)
   if mouse ~= "l" then--right :D?
     return
   end
   hold = true
   for i,v in pairs(bases) do
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: My 1-script copy of Invader by Robin - WIP

Post by Robin »

That is not very helpful, since it only works if there is only something done when the left mouse button is pressed, although in this case that is not a problem.
Help us help you: attach a .love.
User avatar
GijsB
Party member
Posts: 380
Joined: Wed Jul 20, 2011 10:19 pm
Location: Netherlands

Re: My 1-script copy of Invader by Robin - WIP

Post by GijsB »

Robin,

so the code it good?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: My 1-script copy of Invader by Robin - WIP

Post by Robin »

I didn't say that.

You still have much to learn, young grasshopper. With practice, you can get better. You will be ashamed of your old code, everyone is.
Help us help you: attach a .love.
User avatar
GijsB
Party member
Posts: 380
Joined: Wed Jul 20, 2011 10:19 pm
Location: Netherlands

Re: My 1-script copy of Invader by Robin - WIP

Post by GijsB »

oke :). but what has everyone here with Obey ._.?

and im now programming the "AI's" for the other bases .
User avatar
Trappingnoobs
Citizen
Posts: 95
Joined: Tue Oct 12, 2010 8:52 pm

Re: My 1-script copy of Invader by Robin - WIP

Post by Trappingnoobs »

GijsB wrote:oke :). but what has everyone here with Obey ._.?

and im now programming the "AI's" for the other bases .
Somone (Maybe a mod or admin; can't remember; saw the thread a while ago), said that you should. I don't think you have to though.
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

Re: My 1-script copy of Invader by Robin - WIP

Post by TechnoCat »

Trappingnoobs wrote:
GijsB wrote:oke :). but what has everyone here with Obey ._.?

and im now programming the "AI's" for the other bases .
Somone (Maybe a mod or admin; can't remember; saw the thread a while ago), said that you should. I don't think you have to though.
OBEYING IS NOT OPTIONAL!
User avatar
Trappingnoobs
Citizen
Posts: 95
Joined: Tue Oct 12, 2010 8:52 pm

Re: My 1-script copy of Invader by Robin - WIP

Post by Trappingnoobs »

TechnoCat wrote:
Trappingnoobs wrote:
GijsB wrote:oke :). but what has everyone here with Obey ._.?

and im now programming the "AI's" for the other bases .
Somone (Maybe a mod or admin; can't remember; saw the thread a while ago), said that you should. I don't think you have to though.
OBEYING IS NOT OPTIONAL!
Let me guess;
Image

That's obey in either Japanese or Chinese, right?
Post Reply

Who is online

Users browsing this forum: keharriso and 31 guests