Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / Collisions

Years of Service
User Offline
Joined: 15th Apr 2003
Location: United Kingdom
Posted: 16th Apr 2003 16:25
Hi, iam trying to find some code for a collision between a bullet and a tile in the background, its a 2D topview game and the tiles make up the environment. john
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 18th Apr 2003 06:42

It would help to have some more information... such as
What size tiles are you using?
How large is the bullet?
Should impact be decided by the front of the bullet? The middle? Does it matter to you?
Does it matter to you how far into the tile the bullet needs to be?
Are you using a 2d array to store your tiles?
Are you using [0][0] as the location of the first tile? (some people start at [1][1])

Ok you get the idea. Also a snippet of code helps.

I'll give you a suggestion
you need to convert the screen coordinate of the missile to world coordinates (the 2d-array values)

I'm not sure if db has a modulous operator which would be your best answer. (i'll look into this)

without a mod operator you would have to (round down):

(note: if you started your array at [1][1] you would need to add 1 after the divisions.

if MissileWorldX=ArrayIndexX and MissileWorldY=ArrayIndexY
rem collision code here
end if

Steven Craft
Years of Service
User Offline
Joined: 15th Apr 2003
Posted: 30th Apr 2003 06:04
I could NOT find a modulus operator in dark basic (classic), I constructed a simple function to achieve this, possibly it will be of some use? I hope so:

To be honest I can't remember if I wrote this small section of code myself or worked it out from other examples or what, but if its someone else's work, my thanks go out to them.


Retired Moderator
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 30th Apr 2003 16:00
Here's a slightly shorter version that relies on the fact that DB is using integer maths for the whole of the calculation.

eg 10 mod 3, should return 1

10/3 (a/b) => 3
result*3 => 9
10-result (a-result) => 1

Years of Service
User Offline
Joined: 26th Nov 2002
Posted: 1st May 2003 05:28
Nice one Ian! handy algorithm for those "mathless" programming languages

Login to post a reply

Server time is: 2023-09-30 02:13:00
Your offset time is: 2023-09-30 02:13:00