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.

Newcomers DBPro Corner / collision with an unknown object

Author
Message
Mr X
18
Years of Service
User Offline
Joined: 25th Sep 2005
Location: Universe, milkyway, sol-system, Earth...
Posted: 5th Apr 2006 21:54
Hi.

Ive a question about collision. How do you check collision for an object, without knowing what object it collides with? Like if you have made a game where one must navigate through an astroid field, but if you collides with an astroid you die. How do you do that if you just know what the object number of the ship which you try to get through the field? Just as an example.
Me!
19
Years of Service
User Offline
Joined: 26th Jul 2005
Location:
Posted: 5th Apr 2006 22:16
object collision(shipnumber,0)

will return the number of the object your ship collided with, if (for example) all your asteroids are objects numbered 500 or higher then

if object collision(ship,0)>=500
print "BOOM"
dec total_ships
endif

is what you want.



Dr Frankenstiens mum told him to make some new friends, not knowing where this was going to lead.
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 6th Apr 2006 12:30
learning still, didn't know that the 'if object collision(ship,0)' command returned the object it collided with, brilliant, i thought it just returned a 1 or 0 like the normal command.

life's one big game
spec= 1.6ghz, 512mb ram, 128mb gpu, directx 9.0c, dbpro and classic
Mr X
18
Years of Service
User Offline
Joined: 25th Sep 2005
Location: Universe, milkyway, sol-system, Earth...
Posted: 6th Apr 2006 14:31
Thx Me!. Thats useful .

And that astroid game was just something I put together in my mind so you could understand what I meant.
Mr X
18
Years of Service
User Offline
Joined: 25th Sep 2005
Location: Universe, milkyway, sol-system, Earth...
Posted: 6th Apr 2006 17:52 Edited at: 6th Apr 2006 17:55
Ok, the this is that it doesnt work. Im trying to understand collision better with this program.


(I read somewhere that its good to use as many functions as possible). Anyway, the objects in the FOR-NEXT loop dont seem to exist. Why is it so?
Me!
19
Years of Service
User Offline
Joined: 26th Jul 2005
Location:
Posted: 6th Apr 2006 20:28
not tried your code, but be aware that variables inside functions are seperate to the rest of the program, I`m guessing thats your problem, for example if you have a value like xposition in the main loop, then to increment it inside a function will not do anything to the value inside the main loop, just the functions version will be altered, if you want to change something inside a loop and get the value back then you use something like

function locate(xposition)
inc xposition
endfunction xposition

so if the function is called locate then

a=locate(xposition)

or

xposition=locate(xposition)

will return the value of xposition, you pass the number to the function inside the brackets, then the function can use that number in the math and return the new number, if you don`t do that then you can`t alter a main loop variable inside a function, naturaly the normal object commands work ok, they are system wide.



Dr Frankenstiens mum told him to make some new friends, not knowing where this was going to lead.
Mr X
18
Years of Service
User Offline
Joined: 25th Sep 2005
Location: Universe, milkyway, sol-system, Earth...
Posted: 6th Apr 2006 22:14
All the variables I use in the functions are globals (exept the one called "score", I just descovered, but that one is not relevant: It only stores the scores). And besides, they are more focosed on the objects. But I got a new problem. It seems that my compiler cant understand the command "hit()", wich Ive made. It react like if you just type in an random series of letters. Why is that? Is it something Ive done wrong or is it the compiler thats just evil?
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 6th Apr 2006 23:22 Edited at: 6th Apr 2006 23:30
Quote: "All the variables I use in the functions are globals "

you've probably already fixed these but change this:

to this:

and then there's this probable typo

to:


your Next Level routine needs to be cleaned up:



in both for/next loops you are confusing DBP by trying to set "o" and "n" to 2 different things respectively at the same time.

namely,

and

should look something like:

and


in addition, there is some bad practice involved where you are deleting objects only to immediately create them again. try creating the additional obstacle objects, increase nmax accordingly and then reposition all obstacle objects for the next level. delete object is generally an "avoid me" command. let's say you wanted the obstacle to "disappear" if the hero hits it. best practice might be to hide the obstacle and raise it off the ground so the hero can't run into it again, versus deleting it. you get the idea. in your code you are deleting it and creating it again and DBP doesn't appreciate it. it's erroring out so a work-around is necessary.

as far as the problem you are experiencing with hit(), i'm not seeing it. maybe the code you last provided is out of date?

i'm looking forward to seeing your progress good luck!

Virtual Nomad
Athlon XP1800+, Windows XP+SP2, Soyo K7V Dragon+ MB, 1.5Gb 333 RAM, ATI Radeon 8700LT (128Mb)
Mr X
18
Years of Service
User Offline
Joined: 25th Sep 2005
Location: Universe, milkyway, sol-system, Earth...
Posted: 7th Apr 2006 13:10 Edited at: 7th Apr 2006 21:03
Thx for the resbonce . Youve helped me greatly. Ill test it as soon as I can (in a cupple of hours).

Quote: "as far as the problem you are experiencing with hit(), i'm not seeing it. maybe the code you last provided is out of date?"


I dont think so. It didnt react to it earlier. But I might say that I tried to make "hit()" to a subrutine, but then it complaind over the next function. I dont know why. I may be a noob, but Ive done MANY functions, so I know how they work, and this has never happend before. Its like the compiler dont understand that they are functions.

I dont know it it has to do with anything, but Ive got two other problems. One is that once or twice when Ive tried to compile my code, it cant do it because it cant load some strange file (dont know what it is or what it does). Its called CFile something I think.

The other problem is that my computer (accually its my dads, but my entire family uses it) is infected with a trojan that my antivirus cant defeat.

Dont know if this has to do with anything though.

EDIT:

Cant make it work due to the problem with the functions. Do anyone have an idea?
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 7th Apr 2006 23:16 Edited at: 7th Apr 2006 23:23
x, please submit your current code (with the suggestions taken into account) and i'll check it out. i had corrected and tweaked your last code a bit and everything compiled and ran fine here but i didn't save it.

also,
Quote: "I dont know it it has to do with anything, but Ive got two other problems.

"CFile something"...

...my computer is infected with a trojan... "


... (way more than likely) has everything to do with why you can't make it work. a quick search for "cfile trojan" on google reveals they are probably 1 in the same issue. with some research, i'm confident you can rid yourself of the virus. otherwise, you're in for additional bouts of frustration.

Virtual Nomad
Athlon XP1800+, Windows XP+SP2, Soyo K7V Dragon+ MB, 1.5Gb 333 RAM, ATI Radeon 8700LT (128Mb)
Mr X
18
Years of Service
User Offline
Joined: 25th Sep 2005
Location: Universe, milkyway, sol-system, Earth...
Posted: 9th Apr 2006 15:32
Current code? Ok, but its not that diferent from the old one.


Quote: "... (way more than likely) has everything to do with why you can't make it work. a quick search for "cfile trojan" on google reveals they are probably 1 in the same issue. with some research, i'm confident you can rid yourself of the virus. otherwise, you're in for additional bouts of frustration."


Ive searched the internet, first for "cfile trojan", and then for "cfile trojan + darkbasic", but didnt find anything usefull. My guess is that I will HAVE TO UPDATE MY OUTDATED ANTIVIRUS IF I CAN FIGURE OUT HOW!!!
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 9th Apr 2006 15:49 Edited at: 9th Apr 2006 15:49
you still need to change this:

to this:


then set 'level' as global & increment it within the If/Then loop of your level_done() function and it's working perfectly.

Virtual Nomad
Athlon XP1800+, Windows XP+SP2, Soyo K7V Dragon+ MB, 1.5Gb 333 RAM, ATI Radeon 8700LT (128Mb)
Mr X
18
Years of Service
User Offline
Joined: 25th Sep 2005
Location: Universe, milkyway, sol-system, Earth...
Posted: 9th Apr 2006 21:33 Edited at: 9th Apr 2006 21:35
Lol, tought I changed that "position object 50,2000,0,2000" ages ago. But now its done, as the rest of the changes you suggested. The only thing is that my stupid compiler is stupid enough to not understand that a function is a function. But I guess that its just the compiler, and not the code, that is stupid.

Thanks for you help.

EDIT:

If you have any ideas about whats wrong with my compiler and how to fix it, pleace tell me.

Login to post a reply

Server time is: 2024-09-24 19:23:47
Your offset time is: 2024-09-24 19:23:47