Sega Columns Clone - (help checking colors)

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
CR4SH3D
Citizen
Posts: 67
Joined: Mon Mar 02, 2009 6:00 pm
Location: England
Contact:

Sega Columns Clone - (help checking colors)

Post by CR4SH3D » Thu Sep 24, 2009 4:37 pm

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

User avatar
CR4SH3D
Citizen
Posts: 67
Joined: Mon Mar 02, 2009 6:00 pm
Location: England
Contact:

Re: Sega Columns Clone - (help checking colors)

Post by CR4SH3D » Thu Sep 24, 2009 5:10 pm

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

User avatar
rude
Administrator
Posts: 1051
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Sega Columns Clone - (help checking colors)

Post by rude » Thu Sep 24, 2009 7:10 pm

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?

User avatar
CR4SH3D
Citizen
Posts: 67
Joined: Mon Mar 02, 2009 6:00 pm
Location: England
Contact:

Re: Sega Columns Clone - (help checking colors)

Post by CR4SH3D » Thu Sep 24, 2009 7:20 pm

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:
Attachments
QBZ.love
(249.79 KiB) Downloaded 85 times

User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

Re: Sega Columns Clone - (help checking colors)

Post by TechnoCat » Thu Sep 24, 2009 7:44 pm

I had Sega Columns for Game Gear, but I was more a fan of Dr. Robotnik's Mean Bean Machine.

User avatar
CR4SH3D
Citizen
Posts: 67
Joined: Mon Mar 02, 2009 6:00 pm
Location: England
Contact:

Re: Sega Columns Clone - (help checking colors)

Post by CR4SH3D » Thu Sep 24, 2009 7:45 pm

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

User avatar
Almost
Prole
Posts: 42
Joined: Fri Aug 21, 2009 8:04 pm
Location: Canada
Contact:

Re: Sega Columns Clone - (help checking colors)

Post by Almost » Thu Sep 24, 2009 9:20 pm

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

User avatar
CR4SH3D
Citizen
Posts: 67
Joined: Mon Mar 02, 2009 6:00 pm
Location: England
Contact:

Re: Sega Columns Clone - (help checking colors)

Post by CR4SH3D » Thu Sep 24, 2009 9:38 pm

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)

User avatar
CR4SH3D
Citizen
Posts: 67
Joined: Mon Mar 02, 2009 6:00 pm
Location: England
Contact:

Re: Sega Columns Clone - (help checking colors)

Post by CR4SH3D » Fri Sep 25, 2009 8:37 am

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

User avatar
Almost
Prole
Posts: 42
Joined: Fri Aug 21, 2009 8:04 pm
Location: Canada
Contact:

Re: Sega Columns Clone - (help checking colors)

Post by Almost » Fri Sep 25, 2009 11:03 am

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests