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! / Multiple Sprite Collisions

Author
Message
_RiW_ Lok
15
Years of Service
User Offline
Joined: 8th Dec 2008
Location:
Posted: 9th Dec 2008 03:24
Hey, guys I need some help with my code. I Created a level with multiple box in it. The information of each box is stored into an array of records,but i truly have no idea how to check if the player has hit box one or box two without doing multiple if-statements.

Is there any way that i can check each box without having to do multiple if-statements.

Here is my cod so far.(only the if-statement for the first box, but they the code will look the same for the others)

Zombie 20
17
Years of Service
User Offline
Joined: 26th Nov 2006
Location: Etters, PA
Posted: 28th Dec 2008 20:50
Alright I'm a complete novice in this but I'll take a stab at it.

Possibly something you could do is check if Box A is within Box B's range by creating collision functions for your individual players. Sorry, thats really all i have but thats the first thing that came to mind.


Coffee coffee coffee coffee coffee coffee cappacino, JAVA!
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 29th Dec 2008 04:05
if you use sprite collision(Sprite,0) then the command will return the number of the sprite it's colliding with.


wait i just read your code. what language is that?it doesn't look like dbc or dbp?????
Murloc
15
Years of Service
User Offline
Joined: 28th Dec 2008
Location: Utena,Lithuania
Posted: 29th Dec 2008 12:08
This is dbGDK as I understand.

Theory-When you know everything,but nothing works.
Practice-When everything works,but you don't know why.
Programming merges these two-Nothing works,and you don't know why.
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 29th Dec 2008 17:01
Since you are using an array to store your boxes' IDs, you should be able to use a FOR-NEXT loop to check the collision for each box in the array. I'm not sure how it should look in GDK, but it would be something like this (just to give the basic shape):



[c]
[/c]
prasoc
15
Years of Service
User Offline
Joined: 8th Oct 2008
Location:
Posted: 29th Dec 2008 20:30
You could put it in a for() statement, like what you do with Initbox()
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 30th Dec 2008 01:27
oh ok sorry forgot i changed boards i waas on the darkbasic board lol
Robbee101
17
Years of Service
User Offline
Joined: 28th Jun 2006
Location: England
Posted: 10th Jan 2009 13:03
I happen to be looking for a solution for this exact same problem, but for DBP.

Has anyone any idea how to do this in DBP?
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 10th Jan 2009 15:06
It's basically the same thing. If you have the sprite numbers of each platform in an array, you can use a FOR-NEXT loop to cycle through them and check collision with the player on each one.

Login to post a reply

Server time is: 2024-04-24 10:03:56
Your offset time is: 2024-04-24 10:03:56