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 / Need help with objectspawning

Author
Message
Cyborg ART
17
Years of Service
User Offline
Joined: 14th Jan 2007
Location: Sweden - Sthlm
Posted: 10th Nov 2009 15:55
I got a working code which spawns an object at a certain score, but I want to be able to spawn an object by pressing a key.

I got this working too, but if I hold the key, even for a millisec, it will spawn more than one object.

I tried with wait, but this frozed the loop and then continued (looked laggy). Is there any way to solve this?

What I have is this:


I also wonder if there is a simple way to get collision by the newly created object and another existing object?

Thanks

zeroSlave
15
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 10th Nov 2009 16:53


Are you using sparky's collision or DBP's native collision?

There's something in this room that makes you can't speak well.
gbark
19
Years of Service
User Offline
Joined: 14th Oct 2005
Location: US - Virginia
Posted: 10th Nov 2009 16:54
If you want to check for a key that was *JUST* pressed, and not a key that was held down, you'll need to use a separate variable (for each key!) that essentially holds the state of the key during the PREVIOUS game cycle.

will work for the space key, for example, and the code inside the conditional will only execute once during the first cycle space was pressed, until you release the key and then press it again.


As far as getting collision, DBPro already has a number of default collision commands, look at the help file and see if those help. Alternatively, if you find those a bit limiting, Sparky's collision DLL offers much more freedom with setting up collisions, but it's a bit more advanced. Do a forum search on that if you're interested.


Good luck!
Cyborg ART
17
Years of Service
User Offline
Joined: 14th Jan 2007
Location: Sweden - Sthlm
Posted: 10th Nov 2009 19:20
I use DBPros native collision, not for physics. I use this to add points to player if collision between level and balls.
I am already using collision and it works perfect, I just need to find a way to get collision between my newly created object and an existing object.

Both of your codes seams similliar, but they both worked. Thanks!

zeroSlave
15
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 11th Nov 2009 04:51



This will return the object number that your new ball object is colliding with. You could use it like:



There's something in this room that makes you can't speak well.
Cyborg ART
17
Years of Service
User Offline
Joined: 14th Jan 2007
Location: Sweden - Sthlm
Posted: 14th Nov 2009 15:40
I am trying to increase a boolean when something is spawned.
For each ball there is a boolean. And this doesnt work...

Any ideas?

Quote: "if (keystate(19) = 1) and (keySp = 0) and ball16 = 0
makeball(balls#)

select balls#
case 11
inc ball11
endcase

case 12
inc ball12
endcase

case 13
inc ball13
endcase
endselect

inc balls#

endif
keySp = keystate(19)
"


TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 16th Nov 2009 03:47 Edited at: 16th Nov 2009 03:50
Quote: "I am trying to increase a boolean when something is spawned."


That doesn't sound right. A boolean variable can only be 0 or 1 and without more of your code, it's difficult to see what exactly is going on.

Try using an boolean array (they do exist in DBP don't they?) dimensioned to the max number of bullets you want to be 'in the air' at any one time.

Set the required element of the array to True when a bullet is in use and set it to False when it's not. (An integer array will work the same with 0 and 1).

When you fire, use the 'slot' only if it's currently set to 0 (not in use).

I cover this in my bullet shooting tutorial here.

And while you are there, read up on the difference between integer and float variables - looking at your snippet, you definitely don't understand what the the difference is - unless you know a way to have 3 and a half bullets......

TDK

pcRaider
17
Years of Service
User Offline
Joined: 30th May 2007
Location:
Posted: 16th Nov 2009 05:23
hi, TKD

This code is wrong for DBP.

Cyborg ART
17
Years of Service
User Offline
Joined: 14th Jan 2007
Location: Sweden - Sthlm
Posted: 16th Nov 2009 15:25
Oh... I dont mean increase a boolean, I mean that I want the boolean to be 1 instead of 0.

But I found a way around this. But I will read your tutorial.

Thanks!

TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 16th Nov 2009 17:12
pcRaider:

Is that code snippet taken from the actual tutorial, (which was originally for DBC) or from the update at the end of the thread which contains DBP versions of the tutorial code?

TDK

pcRaider
17
Years of Service
User Offline
Joined: 30th May 2007
Location:
Posted: 17th Nov 2009 11:50
OK, TDK
It was my mistake.
I scroll downed, and there was DBP below.
This is a DBP version.



I like a tutorial of TDK.
Therefore a code wants you to work well.

In comparison with DBC and
A command of DBP is the same.
And commands of DBP are different.
Even if it is a small difference, a program code does not work well.

Will you make a tutorial for exclusive use of DBP?
Thus a person does not make a mistake.

Login to post a reply

Server time is: 2024-11-24 22:41:35
Your offset time is: 2024-11-24 22:41:35