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.

Dark GDK / Shooting?

Author
Message
Tylerman35
15
Years of Service
User Offline
Joined: 23rd Jul 2009
Location:
Posted: 18th Aug 2009 01:14
if(dbSpriteCollision(20,6) && dbMouseClick() == 1){
health--;
}

when ever i do that code it doesnt work when i shoot colonel-x.x. The health doesnt go down?
Mista Wilson
16
Years of Service
User Offline
Joined: 27th Aug 2008
Location: Brisbane, Australia
Posted: 18th Aug 2009 01:19
Firstly, you are checking sprite collision, when you want to be checking 3d object collision. In DarkGDK, different kinds of "things" ... objects, sprites, images, memblocks, etc.. for the most part, all have their own unique ID's.

What this means is that it is completely legal to have an Object Number 1, an Image number 1 and a memblock number 1.

You need to make sure you are using the correct commands for what you want to achieve.

If it ain't broke.... DONT FIX IT !!!
heyufool1
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location: My quiet place
Posted: 18th Aug 2009 01:20 Edited at: 18th Aug 2009 01:20
well colonel-x.x isn't a sprite, its a model. So I don't understand what you are trying to accomplish.

EDIT: Dah! Mista you beat me

Use Google first... it's not rocket surgery!
Tylerman35
15
Years of Service
User Offline
Joined: 23rd Jul 2009
Location:
Posted: 18th Aug 2009 01:21
im sorry but the real code was

if(dbObjectCollision(20, 6) && dbMouseClick() == 1){
health--;

it still doesnt work.
Mista Wilson
16
Years of Service
User Offline
Joined: 27th Aug 2008
Location: Brisbane, Australia
Posted: 18th Aug 2009 01:51
Have you turned on object collisions ? You either need to turn on global object collisions, or set each object to have collision turned on.

Also, where is your variable "health" defined ? How are you assigning and managing its value....

At the moment according to your code logic what you want is that whenever object 20 and 6 collide, the health will be reduced.

You do realise that your game loop will loop around 60 times per second, which means that loop will be called around 60 times per second... Thus, you "health" variable could end up being reduced 60 times per second, which would probably put it into the negatives quite quickly(it will still loop at least 20-30 times with a single really fast mouse click aswell... windows messages are quick, but not instant..you need to have a 3rd variable that you set to true and false, to make sure that your loop will only execute once when the mouse is clicked and not again until it's released and re-clicked.)

If it ain't broke.... DONT FIX IT !!!
Matty H
16
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 18th Aug 2009 01:51
Try this:



If that does not work you might want to look into whether it is detecting the collision.
Mista Wilson
16
Years of Service
User Offline
Joined: 27th Aug 2008
Location: Brisbane, Australia
Posted: 18th Aug 2009 05:56
In this case, those parenz will make no difference to the way the compiler interprets the commands. There are cases where you can use parenz though to control the operator flow of calculations...

This is mainly used in maths calculations though to make things more readable, take for example :

1 + 2 * 3

If we add 1 set of parenz : (1 + 2) * 3 = 9
Now change the parenz : 1 + (2 * 3) = 7

If you are not sure on why this occurs then do some reading up on Operator Precedence, its a very similar concept to the precedence of operators that people are taught in school for basic maths, (B)rackets, (I)ndices, (M)ultiplication, (D)ivision, (A)ddition, (S)ubraction....

C++ uses alot more operators than just the standard maths ones though, and precedence becomes alot more important, especially knowing what order your calculations are going to be done in.

I do the same thing though in my own coding, sometimes if I have complex calculations happening, ill add in parenthesis just to make sure that I know at a glance what is supposed to be happening, even though they usually function the same regardless, its always good to make things more readable both for yourself and anybody else that may read your code.

If it ain't broke.... DONT FIX IT !!!

Login to post a reply

Server time is: 2024-11-20 17:36:27
Your offset time is: 2024-11-20 17:36:27