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 / counting sprite collisions(help please)

Author
Message
sweeteye
13
Years of Service
User Offline
Joined: 18th Nov 2011
Location: OHIO USA
Posted: 19th Nov 2011 04:55
I am working on a 2D wargame.The problem I am having is with counting the number of collisions on a sprite by a bullet.I want to have a sprite deleted after a given number of hits rather than be deleted on the first collision. I am hoping someone might be able to give me a code example of how I might go about this. I have gone through many searches on the forums and have not found what I am looking for. Hopefully I have not overlooked something. I have not included any code as all I really have to work with at this point is the basic deletion of a sprite on collision. dbSpriteCollision and dbDeleteSprite.
sweeteye
13
Years of Service
User Offline
Joined: 18th Nov 2011
Location: OHIO USA
Posted: 19th Nov 2011 14:12 Edited at: 20th Nov 2011 09:43
Here is what I am working with right now.I borrowed some code I found here on the forum that seems relevant.I am really close to having a very basic first version of the game ready to go.This bit of code for counting collisions is the main problem in the way.I have tried numerous approaches but always get the same outcome , either the target is deleted on the first collision or not deleted at all.

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
int z = 2, q = 44, FCOA = 10;
int coll = 2;
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

for(q = 0; q <= 2; q++){
if(dbImageExist(q)) {
coll = dbSpriteCollision(FCOA,EBIIIA);
if(coll){

dbDeleteSprite(FCOA);
}
}
}


sweeteye
13
Years of Service
User Offline
Joined: 18th Nov 2011
Location: OHIO USA
Posted: 20th Nov 2011 02:40
Anyone out there have a response of some sort....Surely someone must be able to answer this. It has to be something simple I am overlooking...
sweeteye
13
Years of Service
User Offline
Joined: 18th Nov 2011
Location: OHIO USA
Posted: 20th Nov 2011 11:18
After looking through this forum and the responses others are getting for their questions I thought I would be able to get a answer to my question....or at least a response of some sort.I do really prefer to figure coding problems out myself and it appears that is what I am going to have to do in this case.Very disappointed...although I do like using Dark GDK for learning how to program. I have been debating on purchasing Dark AI but now I am a bit hesitant because if I do have questions I have to wonder whether or not I will get answers.
TerryRussell
13
Years of Service
User Offline
Joined: 11th Dec 2010
Location: Chichester, UK
Posted: 20th Nov 2011 15:08 Edited at: 20th Nov 2011 15:09
Hi Sweeteye.

You shouldn't expect instant support. It's a weekend and many people have lives in which they do things apart from watch the forums constantly.

But, can I suggest that the problem may be in your use of the variable coll?

You first of all assign it a value of 2. Then you make it equal to the return value of dbSpriteCollision. Why do you do that? Shouldn't you reduce the value of coll every time there is a collision and then when coll==0 you should initiate the dbDeleteSprite command?

Looks like a very basic programming error to me.

Amazing Simulation
www.amazing-forum.com
sweeteye
13
Years of Service
User Offline
Joined: 18th Nov 2011
Location: OHIO USA
Posted: 20th Nov 2011 16:22
Thanks for responding Terry.....I guess I have just been too impatient.I have been stumped by this very basic problem for four days.....Seems like your bit of information should work.I am obviously relatively new to programming and still have a lot to learn about basics.Seems like what should be a simple problem can be more difficult to resolve sometimes than something more complex.Thanks again for your help....going to see if I can get this to work so I can finish this first version and move on to the next steps.
sweeteye
13
Years of Service
User Offline
Joined: 18th Nov 2011
Location: OHIO USA
Posted: 20th Nov 2011 18:28 Edited at: 20th Nov 2011 22:32
This is a dumb question but how do you make collision or "coll" equal to the return value of dbSpriteCollision?
Matty H
16
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 21st Nov 2011 10:44
Quote: "This is a dumb question but how do you make collision or "coll" equal to the return value of dbSpriteCollision?
"


The way you are doing it is correct. But is 'coll' supposed to be the amount of collisions a given sprite can take? If so then use a new variable for the return value of dbSpriteCollision().



What is 'q', you may get problems when q = 0 as for dbImageExist(0), 0 is not a valid input. ID numbers start at 1.

sweeteye
13
Years of Service
User Offline
Joined: 18th Nov 2011
Location: OHIO USA
Posted: 21st Nov 2011 18:08 Edited at: 21st Nov 2011 19:25
Hi Matty..... Yes coll is to be the number of collisions a sprite can take. I was trying to use q as a variable for the bullet sprite for some reason. I eliminated the line for dbImageExist. I still have not figured this out yet although I think I am close. I am still a little confused over making coll equal to the return value of dbSpriteCollision.I know the return value equals one. If I use a new variable for the return value of dbSpriteCollision,how would I write that line out and where would it be placed?I know it is something very simple but I am confused on it.Here is what I have right now without the variable for dbSpriteCollision. All this bit of code does is immediately delete the target sprite.Decided to count down as Terry suggested.No matter how I set the code up I either get an instant deletion of the target or no deletion at all. Cannot seem to get the code to count collisions.

int coll= 2;


for (coll = 2; coll>-1;coll--){


if(coll == 0)


dbDeleteSprite(FCOII_ID);
}
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 22nd Nov 2011 05:34
A bit verbose, but here's a complete example using only the code shown...



This sample creates its own sprites so nothing else needs to be included. Simply: copy, paste, run and trace through the code to get a better understanding.

Regards,
JTK
sweeteye
13
Years of Service
User Offline
Joined: 18th Nov 2011
Location: OHIO USA
Posted: 22nd Nov 2011 11:21
Thanks JTK.....Just by quickly looking at the code I can see some things that might help me. I will compile the code and check it out...looks kind of interesting.Apparently I am just missing something that will activate the hits to be counted??? Seems strange that my "for loop" will not count hits. I have tried countless variations and I am to the point of exhaustion.My little coding problem is something that should only take a minute to set up for each sprite.... I appreciate the help.
Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 27th Nov 2011 17:23
A simpeltons way (my way) of doing that would be to have a separate variable. And each time your sprite colides, add 1 to tah variable. And then just set up an if statement ..
if (varable < 10) dbDeleteSprite
deletes the sprite if it collides 11 times.

sweeteye
13
Years of Service
User Offline
Joined: 18th Nov 2011
Location: OHIO USA
Posted: 30th Nov 2011 04:35
Finally created some code that is working for me....Needs some work yet but at least it is counting the collisions. I want to thank everyone for their input because it has all helped me to understand this problem. I can now move on to coding in all the projectiles for the sprites.Going to take a lot of work but at least I have the main problems of movement and counting collisions resolved to a working solution. I am really tempted to try out Dark AI to help with making the game better... Here is a snippet of what I came up with ....kind of ugly looking but it works... Hope this snippet is done correctly...I apologize if it is not.

int jjjjj, CCC = 112,FCOA = 10000,EBIIIA = 449;

int q = 8;
int coll =0;

if (dbSpriteCollision(EBIIIA,FCOA))
{
q += -1;
dbLoadImage("ENEMYPROJV.bmp", 449);
InitializeBulletIV(ffffff,BULLETIV_ID,dbSpriteX(CCC),dbSpriteY(CCC),BULLETIV_SPEED);
FollowPlayer (ffffff,FCOII_ID);

}

if(dbImageExist(FCOA)) {
coll = dbSpriteCollision(EBIIIA,FCOA);
if(q==0){

dbDeleteSprite(FCOII_ID);
}
}
Jonas
19
Years of Service
User Offline
Joined: 10th Aug 2005
Location: What day is it?
Posted: 4th Dec 2011 21:00
Just a little FYI since you're goal is to deal with a potentially large amount of sprites. Read into Data Structures:

http://www.cplusplus.com/doc/tutorial/structures/

Hopefully that'll save you one or two headaches when it comes to shuffling through them individually.

I just saw a lack of their use is all.
sweeteye
13
Years of Service
User Offline
Joined: 18th Nov 2011
Location: OHIO USA
Posted: 5th Dec 2011 12:32
Thanks for directing me to the tutorial Jonas.....I have been thinking about what you pointed out but just have not been sure how to implement it.I have never taken any formal programming courses and have to study programming on my own...Also have started working with computers kind of late in life....I can remember when the first hand held calculators came out in the 1970's and everyone was amazed by them....Was intimidated by computers for a long time....

Login to post a reply

Server time is: 2024-11-19 06:51:41
Your offset time is: 2024-11-19 06:51:41