Invader: arcade strategy game

Show off your games, demos and other (playable) creations.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Invader: arcade strategy game

Post by kikito »

Trappingnoobs wrote: I don't think the planets are big enough to render it time-saving having to select a percentage.

If there were different size planets, that'd, I guess, be helpfull though.
There would be just 3 buttons in total, not three buttons per planet. That would be crazy.
When I write def I mean function.
User avatar
Trappingnoobs
Citizen
Posts: 95
Joined: Tue Oct 12, 2010 8:52 pm

Re: Invader: arcade strategy game

Post by Trappingnoobs »

kikito wrote:
Trappingnoobs wrote: I don't think the planets are big enough to render it time-saving having to select a percentage.

If there were different size planets, that'd, I guess, be helpfull though.
There would be just 3 buttons in total, not three buttons per planet. That would be crazy.
Oh, I thought you meant that when you clicked, three buttons apeared. I guess that makes sense, but I think it should still be planet-by-planet sending, but you should be able to select multiple by dragging a rectangle (and/or maybe shift clicking).
User avatar
GijsB
Party member
Posts: 380
Joined: Wed Jul 20, 2011 10:19 pm
Location: Netherlands

Re: Invader: arcade strategy game

Post by GijsB »

my sorta beginging clone of it xD =

Code: Select all

bases = {}

dt = 0
math.randomseed(os.time())
for i = 1,10 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
			if v.X == base.X and v.Y == base.Y then
				choose()
			end
		end
	end
	choose()
	table.insert(bases,base)
end	

function diffrents(a,b)
	if a > b then
		return a-b
	else
		return b-a
	end
end

function love.update(d)
	dt = dt + d
	if dt > 0.5 then
		for i,v in pairs(bases) do
			if v.C < v.M then
				v.C = v.C +1
			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,30)
		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())
	end
end

hold = false
begin = nil
function love.mousepressed(x,y,mouse)
	if mouse == "l" then
		hold = true
		for i,v in pairs(bases) do
			if v.O == 1 then
				if diffrents(x,v.X) < v.M and diffrents(y,v.Y) < v.M then
					begin = v
				end
			end
		end
	end
end

function love.mousereleased(x,y,mouse)
	pcall(function()if mouse == "l" then
		hold = false
		for i,v in pairs(bases) do
			if diffrents(x,v.X) < v.M and diffrents(y,v.Y) < v.M then


				if v.O == 1 then--friend so give points
					for i = 1,v.M-v.C do	
						if begin.C > 0 then
							begin.C =  begin.C - 1
							v.C = v.C+1
						end
					end
				elseif v.O == 2 or v.O == 3 then
					for i = 1,begin.C do
						if v.C > 0 then
							begin.C = begin.C-1
							v.C = v.C-1
							if v.C < 1 then
								v.O = 1
							end
						end
					end
				end


			end
		end
		begin = nil
	end end)
end
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Invader: arcade strategy game

Post by tentus »

GijsB wrote:my sorta beginging clone of it xD =

Code: Select all

bases = {}

dt = 0
math.randomseed(os.time())
for i = 1,10 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
			if v.X == base.X and v.Y == base.Y then
				choose()
			end
		end
	end
	choose()
	table.insert(bases,base)
end	

function diffrents(a,b)
	if a > b then
		return a-b
	else
		return b-a
	end
end

function love.update(d)
	dt = dt + d
	if dt > 0.5 then
		for i,v in pairs(bases) do
			if v.C < v.M then
				v.C = v.C +1
			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,30)
		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())
	end
end

hold = false
begin = nil
function love.mousepressed(x,y,mouse)
	if mouse == "l" then
		hold = true
		for i,v in pairs(bases) do
			if v.O == 1 then
				if diffrents(x,v.X) < v.M and diffrents(y,v.Y) < v.M then
					begin = v
				end
			end
		end
	end
end

function love.mousereleased(x,y,mouse)
	pcall(function()if mouse == "l" then
		hold = false
		for i,v in pairs(bases) do
			if diffrents(x,v.X) < v.M and diffrents(y,v.Y) < v.M then


				if v.O == 1 then--friend so give points
					for i = 1,v.M-v.C do	
						if begin.C > 0 then
							begin.C =  begin.C - 1
							v.C = v.C+1
						end
					end
				elseif v.O == 2 or v.O == 3 then
					for i = 1,begin.C do
						if v.C > 0 then
							begin.C = begin.C-1
							v.C = v.C-1
							if v.C < 1 then
								v.O = 1
							end
						end
					end
				end


			end
		end
		begin = nil
	end end)
end
That's... a little rude, but OK, whatever. As an effort to help you as a Lover, I made some adjustments to your code:

Code: Select all

function love.load()
	bases = {}
	dt = 0
	math.randomseed(os.time())
	for i = 1,10 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
				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 diffrents(a,b)
	if a > b then
		return a-b
	else
		return b-a
	end
end

function love.update(d)
	dt = dt + d
	if dt > 0.5 then
		for i,v in pairs(bases) do
			if v.C < v.M then
				v.C = v.C +1
			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,30)
		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())
	end
end

function love.mousepressed(x,y,mouse)
	if mouse == "l" then
		hold = true
		for i,v in pairs(bases) do
			if v.O == 1 then
				if diffrents(x,v.X) < v.M and diffrents(y,v.Y) < v.M then
					begin = v
				end
			end
		end
	end
end

function love.mousereleased(x,y,mouse)
	if mouse == "l" then
		hold = false
		for i,v in pairs(bases) do
			if diffrents(x,v.X) < v.M and diffrents(y,v.Y) < v.M then
				if v.O == 1 then --friend so give points
					for i = 1,v.M-v.C do	
						if begin.C > 0 then
							begin.C =  begin.C - 1
							v.C = v.C+1
						end
					end
				elseif v.O == 2 or v.O == 3 then
					for i = 1,begin.C do
						if v.C > 0 then
							begin.C = begin.C-1
							v.C = v.C-1
							if v.C < 1 then
								v.O = 1
							end
						end
					end
				end
			end
		end
		begin = nil
	end 
end
The pcall you had made it impossible to play your version for me, so I took it out. Why was it there?
Kurosuke needs beta testers
User avatar
GijsB
Party member
Posts: 380
Joined: Wed Jul 20, 2011 10:19 pm
Location: Netherlands

Re: Invader: arcade strategy game

Post by GijsB »

theres some bug i cant find in the code there wich glitches up the 'begin' variable :/

but thanks for the code upgrade :D
User avatar
kraftman
Party member
Posts: 277
Joined: Sat May 14, 2011 10:18 am

Re: Invader: arcade strategy game

Post by kraftman »

GijsB wrote:theres some bug i cant find in the code there wich glitches up the 'begin' variable :/

but thanks for the code upgrade :D

Bear with me, this may get complicated:

If you run some code, and it gives you an error, you can use the error message to help find out what the error is!

In this case, if the error says "attempt to index global 'begin' (a nil value.)"

It means that it is attempting to index a global variable called 'begin', but that variable is a nil value.

A good place to start debugging would be to try and work out why begin is a nil value, assuming it shouldn't be.

In this case, a great place to start would be looking at the part of your code which says "begin = nil" (a good indication as to why the variable 'begin' is equal to nil.)
User avatar
GijsB
Party member
Posts: 380
Joined: Wed Jul 20, 2011 10:19 pm
Location: Netherlands

Re: Invader: arcade strategy game

Post by GijsB »

kraftman,

thanks, but i already knew how to debug, and i fixed it now ;)

added circles , but they pretty much have no use yet...

Code: Select all

function love.load()
   bases = {}
   dt = 0
   math.randomseed(os.time())
   for i = 1,10 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
            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 diffrents(a,b)
   if a > b then
      return a-b
   else
      return b-a
   end
end

function love.update(d)
   dt = dt + d
   if dt > 0.5 then
      for i,v in pairs(bases) do
         if v.C < v.M then
            v.C = v.C +1
         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,30)
      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,30)
   end
end

function love.mousepressed(x,y,mouse)
   if mouse == "l" then
      hold = true
      for i,v in pairs(bases) do
         if v.O == 1 then
            if diffrents(x,v.X) < v.M and diffrents(y,v.Y) < v.M then
               begin = v
            end
         end
      end
   end
end

function love.mousereleased(x,y,mouse)
	if mouse == "l" then
		hold = false
		for i,v in pairs(bases) do
			if diffrents(x,v.X) < v.M and diffrents(y,v.Y) < v.M then
				if begin == nil then return end
				--BLABLA CHECK IF IN RADIUS OF begin.C*5+begin.M (FANCY WHITE CIRCLE)
				if v.O == 1 then --friend so give points
					for i = 1,v.M-v.C do   
						if begin.C > 0 then
							begin.C =  begin.C - 1
							v.C = v.C+1
						end
					end
				elseif v.O == 2 or v.O == 3 then
					if begin == nil then return end
					for i = 1,begin.C-1 do
						if v.C > 0 then
							begin.C = begin.C-1
							v.C = v.C-1
							if v.C == 0 then
								v.O = 1
							end
						end
					end
				end
			end
		end
		begin = nil
	end 
end
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Invader: arcade strategy game

Post by Robin »

Guys. Please take this to another thread. This one is about Invader and so the previous 5 post here are off-topic.

Thank you. :)
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: Invader: arcade strategy game

Post by GijsB »

oke xD
User avatar
cattail
Citizen
Posts: 56
Joined: Mon Feb 13, 2012 4:11 pm

Re: Invader: arcade strategy game

Post by cattail »

I have test the great invader.love , it's looks simple but a lot of fun.
I almost win, but a crush.

Error: [string "systemview.lua"]:143: attempt to index local 'arr' (a nil value)
stack traceback:
[string "systemview.lua"]:143: in function 'update'
[string "main.lua"]:31: in function 'update'
[string "boot.lua"]:1: in function <[string "boot.lua"]:1>
[C]: in function 'xpcall'
AL lib: ALc.c:1818: alcCloseDevice(): deleting 32 Buffer(s)

I'm using debian squeeze, love 0.7.2 (from gz, configure,make,make install)
invader.love is from 20 page's link :
viewtopic.php?f=3&t=2198&start=110


I find invader-p2.love , haven't play with it yet .

BTW: Is a way to select the number of stars?
Post Reply

Who is online

Users browsing this forum: pgimeno and 4 guests