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.

DarkBASIC Professional Discussion / Detecting sprite number?

Author
Message
Zeus
20
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 6th Jul 2010 20:29
I have a code where you place a residential plot (separate sprite) and eventually turns into a property as you can see in the code. However, there is no way to prevent them from colliding with each other. How can I get the sprite number to detect if a rplot is colliding with a different rplot?

Here is my code,


Functions.dba


Image 1(property_forsale.png) is attached. Image 2 will be attached in the post below.

Thanks!
Zeus

Zeus
20
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 6th Jul 2010 20:30
Image 2 (Property.png)

Dark Dragon
19
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 6th Jul 2010 21:50
Quote: "How can I get the sprite number to detect if a rplot is colliding with a different rplot?"



Try....



If thats what you are asking....

Zeus
20
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 6th Jul 2010 23:12 Edited at: 6th Jul 2010 23:12
I don't quite think you understand, let me post an image to show an example.

C0wbox
20
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 6th Jul 2010 23:29
Your best bet would probably be to scrap sprite collisions and use a 2 dimensional array with all the sprite numbers stored in it then detect if filled slots are adjacent to each other.

0 0 0 0 0 0
0 0 1 2 0 0
0 0 0 0 0 0
0 0 0 0 0 0

^ Just run a search (of some kind) through that and when it finds a number, test to see if there is a number greater than 0 in any of the 4 (or 8 if you're counting diagonals) adjacent squares. If there is then you have the sprite number because that is what is stored in the array.

Zeus
20
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 7th Jul 2010 05:42
I am so sorry C0wbox, you lost me.

Can I have an example with code, I suck at arrays.

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 7th Jul 2010 06:09 Edited at: 7th Jul 2010 06:12
What he means is to create a 2d array for your entire city or 1 for each section. Then where ever a plot is placed, make the array position at that plot position assigned the value of the plot sprite. So for example we start out with our city array, say our city is 5 units long and wide. Therefor an empty city would be:
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0


defined as


Then say the residential plot is sprite number 2 and placed at the position 3,4:
CityArray(3,4)=residential plot sprite number

Therefore the array now looks like this:
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 2 0 0
0 0 0 0 0


So you place sprites in that fasion. To check for collisions, goto each array position and check the sprite numbers adjacent to it to check if they are colliding. So the basic code would be:



This will check if Sprite1 is next to Sprite2 including diagnals.

Hope I cleared up some array stuff also.

If it hasn't exploded yet, I haven't touched it.
C0wbox
20
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 7th Jul 2010 13:19
Yeah, that^ xD

(I can never tell how people are with arrays these days: whether they know them and love them, or they've never used them )

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 7th Jul 2010 16:20
Arrays are the best way for organized data. I use them for even storing object numbers so you only worry about the array index but not the actual object number. So much easier than having to keep track of each object number.

If it hasn't exploded yet, I haven't touched it.
Zeus
20
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 7th Jul 2010 17:46
Thanks for your help! I will see what I can do.

Login to post a reply

Server time is: 2026-07-25 08:30:04
Your offset time is: 2026-07-25 08:30:04