Author Topic: BoxColl problem  (Read 1800 times)

Offline MrPlow

  • Prof. Inline
  • *****
  • Posts: 1810
    • View Profile
BoxColl problem
« on: 2011-Nov-04 »
Hi,

I have a screen divided in to 16x16 sections

Using for loops that are stepped by 16 from 1 to 800 and 1 to 512 (high)

An array of an objects is placed within the confines of the grid by a measure of 16x16 squares or a multiple of the same...

But the item I move around the screen (also 16x16) is not flush with some sections of the sprite array and every second section of the grid is out or incorrectly...any ideas??

Code: (glbasic) [Select]
FUNCTION hitobject: xx,yy

FOREACH w IN waters[]

IF BOXCOLL(xx,yy,16,16,w.wx,w.wy,w.width,w.height) THEN RETURN 1
NEXT


ENDFUNCTION


Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

Offline matchy

  • Prof. Inline
  • *****
  • Posts: 1545
    • View Profile
Re: BoxColl problem
« Reply #1 on: 2011-Nov-04 »

The vague issue of flushing only reminds me of rounding to integers someone.  :glare:

Based on your collision thread sample code, I'm not sure where to start although I simply suggest that loops shouldn't be stepped absolutely but perhaps rather relatively with the co-ordinates calculated on the grid position multiplied by the tile sprite width.



Offline fuzzy70

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 828
  • Look left, Look right, LOOK OUT!!
    • View Profile
Re: BoxColl problem
« Reply #2 on: 2011-Nov-04 »
I had a similar problem with my code with the colour selection part

Code: (glbasic) [Select]
// Check Mouse zone
FUNCTION MouseArea:
IF my>=10 AND my<=228 AND mx>=10 AND mx<=228 THEN PieceClicked((mx-10)/22,(my-10)/22) // Mouse clicked in Playarea
IF my>=270 AND my<=276 // Select Colours
IF mx>=207 AND mx<=220 // 200-206=Blue, 207-213=Red, 214-220=Green
    colour=(mx-200)/7
    ELSE
    colour=0
    ENDIF
ENDIF
ENDFUNCTION

Defining the variable at the start as an Integer instead of leaving it as a float fixed the problem. The code  colour=(mx-200)/7 was causing it & took a while to figure out what was going wrong as the math was right.

Lee
"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4175
  • On the shoulders of giants.
    • View Profile
    • My Apps
Re: BoxColl problem
« Reply #3 on: 2011-Nov-04 »
Make sure your variables are returning integers rather than floats. As Matchy stated rounding errors can cause issues (especially if you're testing for a specific integer and you're getting a float returned).

You can of course use ABS to get an integer, but just make the variable INT and it shouldn't be necessary.
I came. I saw. I played.

Offline MrPlow

  • Prof. Inline
  • *****
  • Posts: 1810
    • View Profile
Re: BoxColl problem
« Reply #4 on: 2011-Nov-05 »
I got it working !!

My calcs were wrong... my x and y of the sprite were correct (odd numbers)
but my waters sections x (odd) y(even)

So along the way I evened out a 'y' axis value.

I really need to use my debugger better from now on!!

Thanks Guys!
Comp:
Speccy-48k, Speccy-128k, Amigas, PCs