collision help!!!

BlitzMax Forums/BlitzMax Beginners Area/collision help!!!

I have an array that is filled with tiles. Now I have some tiles dropping from above that get added to the array when they hit the bottom of the screen. If I wanted it so that the tiles dropping would collide with the tiles already in the array how would I go about setting something like that up?

Like tetris, The tiles drop and get added to the array. Then the falling tiles collide with the tiles already in the array and they then immediately get added to the array at the current x,y locations.

Any help appreciated. :) I want some hints or tips before I post any code.

Thanks :)

something like this? (assuming it is a tetris clone you are coding)
' psuedo code...

for x = 0 until 4
for y = 0 until 4
   if a_block[ block_type, rotation, x,y] <> 0 then
      if the_playing_field[ blockX+x, blockY+y ] <> 0 then
          ' BAM! This block collided with the ones already placed.
      endif
   endif
next
next



I think I've already tried that.

Heres the code that places the tiles:

	Function set_tiles()

		topLframe = frame1
		topRframe = frame2
		bottomLframe = frame3
		bottomRframe = frame4		
		
		If tilesY > GraphicsHeight()-116-64	
			tilesX = start_position
			setTile = True
			
		EndIf
			
		For Local b:brick = EachIn bricklist
		
		If setTile = True
		
			gamearea[tprXloc,tprYloc] = topRframe
			gamearea[tplXloc,tplYloc] = topLframe
			gamearea[blXloc,blYloc] = bottomLframe
			gamearea[brXloc,brYloc] = bottomRframe	
			brick.newbrick()
			setTile = False
			ListRemove bricklist,(b)
		EndIf		
		
			
			
		Next
		
			
	
	End Function


It places the tiles in the array when a condition is met. Note the locations of the tiles tprXloc etc.

The function below draws to the screen the tiles in the array.

Function draw_gamearea()

	For Local x:Int = 0 To arrX - 1
		For Local y:Int = 0 To arrY -1
			DrawImage tiles,gameareaX+x*32,gameareaY+y*32,gamearea[x,y]
		Next
	Next
		
End Function


I hope the code I posted helps. It's a tetris clone sort of.

ANymore help appreciated :)

Well, the (psuedo) code I posted before is how I did it. What went wrong when you tried it?
DId you try something like this? (If I understand your code correctly)
' I dont know what value gamearea[] uses for non filled blocks. I assume -1 but change that to whatever value you use...
if gamearea[tprXloc,tprYloc] > -1 and gamearea[tplXloc,tplYloc] > -1 and gamearea[blXloc,blYloc] > -1 and gamearea[brXloc,brYloc] > -1 then
  set_tiles()
endif


hmm, it's doing something but not what I want. Can I send you the whole thing via email so you can have a look at it?

Sure. But I can't guarantee a quick response. Must soon leave for work. Only 26 more minutes of sweet sweet freedom...

email with attatchment sent. Hope you can help. :)

26 mins of freedom eh, probably means you're going to work unlike me who's a bum. :)

A bum eh? Are you walking around with a cardboard sign that says "Will code for food"? ;)

Got the email. going to take a look.

Edit:
Oooh. Pretty graphics!

A bum eh? Are you walking around with a cardboard sign that says "Will code for food"? ;)


If I did that I would starve to death. My coding isn't spectacular. :)

Well, it does collide sometimes. But for some reason it just sits in the middle of the playing field and constantly creating a new block...
A problem with tprYloc,tplYloc,brYloc,blYloc?

But I can't track the problem right now. There's too many variables to follow and too little time. Work begins in one minute and I'm still sitting here. :)

And i found a bug. A bug I made. ;)
It should be
		If gamearea[tprXloc,tprYloc] <16 Or gamearea[tplXloc,tplYloc] <16 Or gamearea[blXloc,blYloc] <16 Or gamearea[brXloc,brYloc] <16

since you should be able to collide with just one of the corners... Sorry. :)


I will look some more when I'm home for lunch. Good luck until then.

Thanks mate. I've still a few things to try and I'll change the little mistake in the code.

Now get to work ;)

I got it working. Thanks :)

Goodie! :)