Page 1 of 2

Sega Columns Clone - (help checking colors)

Posted: Thu Sep 24, 2009 4:37 pm
by CR4SH3D
Hey guys

Im working on a sega columns clone and its coming on pretty well

the method im using has an array for each possible block position ( cubes[x][y] ) which holds a value representing that spaces color ( 0 for empty )
the thing i need help with is thinking of the best way to check for matches in block color in order to take them and allow for the different directions and combos
im coming up with a few ideas but i think theyre all pretty inefficient ways to do it

ill release a demo when that bits sorted

cheeers

Re: Sega Columns Clone - (help checking colors)

Posted: Thu Sep 24, 2009 5:10 pm
by CR4SH3D
so far im thinking maybe;

Code: Select all

function checkmatches()
	checkx = heightcubes
	for i = 1, heightcubes do
		for i2 = 1, widthcubes do
			if (cubes[checkx][i2] ~= 0) then
				checkingcol = cubes[checkx][i2]
				--Check right
				if (checkx <= (heightcubes - 1)) then
					--Check down directions
				end
				--Check upwards
			end
		checkx = checkx - 1
	end
end
or creating a new array checking[x][y] where checking[2][2] is the color to be checked for matches around it then store the positions of any matches and use them for further checks

Re: Sega Columns Clone - (help checking colors)

Posted: Thu Sep 24, 2009 7:10 pm
by rude
Awesome, I played that game to death when I was (way) younger. I hope you'll add repetitive and dull music, like in the original.

It has, however, been so long that I can't remember whether you can score diagonally. Can you?

Re: Sega Columns Clone - (help checking colors)

Posted: Thu Sep 24, 2009 7:20 pm
by CR4SH3D
yeah you can, they can also join with verticals and horizontal matches too

ive been trying to get it working just for horizontal and vertical but its going a little weird

if it works and i sort out some nice graphics ill be getting my friend to write a pretty mental tune, definitely keep that 'melody' though :ultrahappy:

Re: Sega Columns Clone - (help checking colors)

Posted: Thu Sep 24, 2009 7:44 pm
by TechnoCat
I had Sega Columns for Game Gear, but I was more a fan of Dr. Robotnik's Mean Bean Machine.

Re: Sega Columns Clone - (help checking colors)

Posted: Thu Sep 24, 2009 7:45 pm
by CR4SH3D
columns all the way, it got insanely quick and you can easily zone out upto level 50 odd
once the prototype is done it should be easy enough to add a few new game types and maybe themes or something

Re: Sega Columns Clone - (help checking colors)

Posted: Thu Sep 24, 2009 9:20 pm
by Almost
you essentially have 4 directions to check, right? horizontal, vertical, and the two main diagonals.

Also: at least three in a row of same color to make a match, but no max length, yes?

something like:

Code: Select all

function checkmatches()
	for cubey = 1, heightcubes do
      for cubex = 1, widthcubes do
         if (cubes[cubex][cubey] ~= 0) then
            
			checkingcol = cubes[cubex][cubey]
            --use dx and dy variables to simulate the directions to be checked
			for dx = -1,1 do -- (down, right, downleft, and downright)
				for dy = 0,1 do
					--special cases that don;t need to be checked
					if not (dx==0 and dy == 0) and not (dx == -1 and dy == 0) then
						
						local rowsize = 1 --how many of this color are in a straight line so far
						while true do
							--find the cube that is, rowsize untis away in direction dx,dy
							local tempx,tempy = cubex+dx*rowsize,cubey+dy*rowsize
							--if out of range, stop now
							if tempx < 1 or tempy < 1 or tempx > #cubes or tempy > #cubes[1] then break end
							 --if same color ,add 1 to rowsize and keep going
							if cubes[tempx][tempy] == checkingcol then rowsize = rowsize + 1
							--if different color, stop now
							else break end
						end
						
						if rowsize >= 3 then
							--found a row of 3 or more items of the same color!
							--do stuff here
						end
						
					end
				end
			end
			
         end
	end
end

Re: Sega Columns Clone - (help checking colors)

Posted: Thu Sep 24, 2009 9:38 pm
by CR4SH3D
yeah that looks good, im going to see how it works, only problem is its got to make a note of the coords for the matching colors to change the values to 0 (empty)

Re: Sega Columns Clone - (help checking colors)

Posted: Fri Sep 25, 2009 8:37 am
by CR4SH3D
ok its working pretty well, but a little off, if you notice the x coordinates of 'matched' colors can exceed the gamewidth
http://codepad.org/j19owk6J

copy and past into a new codepad to generate a new grid, it displays the gird then the checking results

if you could give me a hand working out whats gone weird with it that would be awesome, ive been up all night staring at it :P

Re: Sega Columns Clone - (help checking colors)

Posted: Fri Sep 25, 2009 11:03 am
by Almost
It looks like when you make the grid you make the y values first, so a specific point should be accessed as cubes[y][x], whereas the rowfinder checks [x][y].. I could be wrong, but I think that's it.