Computer Science Canada bullet collision with object |
Author: | sammi [ Sat Nov 12, 2011 12:42 pm ] | ||
Post subject: | bullet collision with object | ||
What is it you are trying to achieve? I am trying to make the bullet and the box disappear when the bullet hits the box What is the problem you are having? I dont know how to remove a value in an array to make the bullet disappear Describe what you have tried to solve this problem <tried making sure the program actually detected the collision but I dont know where to go from there> Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) <Answer Here>
Please specify what version of Turing you are using <Answer Here> |
Author: | Aange10 [ Sat Nov 12, 2011 1:08 pm ] | ||||
Post subject: | Re: bullet collision with object | ||||
Hmm, I'll share some code with you that I made one day when I got bored ![]() DO NOT copy and paste my code. That's counter productive. Use it as a guide.
Also, for your collision:
What are you saying here? You're telling the computer to look for the bullet to be to the right of boxX - 55. So, anytime it's to the right of the box, whether it's touching the box or not, it is true. That is why the collision message is off. |
Author: | sammi [ Sat Nov 12, 2011 1:26 pm ] |
Post subject: | RE:bullet collision with object |
i cant follow your're code, its confusing me |
Author: | Aange10 [ Sat Nov 12, 2011 1:27 pm ] |
Post subject: | Re: RE:bullet collision with object |
sammi @ 12/11/2011, 12:26 pm wrote: i cant follow your're code, its confusing me
What parts? |
Author: | sammi [ Sat Nov 12, 2011 1:43 pm ] |
Post subject: | RE:bullet collision with object |
i just need to know how to remove a bullet from the array so that it disappears when it hits the box. |
Author: | Aange10 [ Sat Nov 12, 2011 1:44 pm ] |
Post subject: | Re: RE:bullet collision with object |
Aange10 @ 12/11/2011, 12:27 pm wrote: sammi @ 12/11/2011, 12:26 pm wrote: i cant follow your're code, its confusing me
What parts? sammi wrote: i just need to know how to remove a bullet from the array so that it disappears when it hits the box. Right. What part of the coding I showed you are you confused about? I can help you understand it; hence solving your problem. ![]() |
Author: | Tony [ Sat Nov 12, 2011 2:10 pm ] |
Post subject: | Re: RE:bullet collision with object |
sammi @ Sat Nov 12, 2011 1:43 pm wrote: how to remove a bullet from the array
you... don't. Because you can't. The type is array 1 .. 10 of int, so you'd always have a block of 10 integers. Someone will probably say something about resizing flexible arrays, but that's not necessary if we have a reasonable bound on the count of bullets. You don't need to "remove" bullets, just to not draw them. In fact, you've already solved this problem elsewhere in your own code. When you fire first 3 shots, you still have an array block of 10, but you draw only 3 (and not all 10). What did you do to those other 7 slots? |
Author: | sammi [ Sat Nov 12, 2011 5:24 pm ] |
Post subject: | Re: RE:bullet collision with object |
Aange10 @ Sat Nov 12, 2011 1:44 pm wrote: Aange10 @ 12/11/2011, 12:27 pm wrote: sammi @ 12/11/2011, 12:26 pm wrote: i cant follow your're code, its confusing me
What parts? sammi wrote: i just need to know how to remove a bullet from the array so that it disappears when it hits the box. Right. What part of the coding I showed you are you confused about? I can help you understand it; hence solving your problem. ![]() Your variables names are really hard to follow......... |
Author: | Aange10 [ Sat Nov 12, 2011 5:32 pm ] | ||
Post subject: | RE:bullet collision with object | ||
Bullet reload, x,y, xv, yv, width, height, used (boolean), time_made / time_past are all hard to follow? Also they are comented, but here, I'll help you decipher it.
|
Author: | sammi [ Sat Nov 12, 2011 6:38 pm ] | ||
Post subject: | Re: RE:bullet collision with object | ||
Aange10 @ Sat Nov 12, 2011 5:32 pm wrote: Bullet reload, x,y, xv, yv, width, height, used (boolean), time_made / time_past are all hard to follow?
Also they are comented, but here, I'll help you decipher it.
alright so where the part where you make the stuff disappear off the screen once you hit it? |
Author: | Aange10 [ Sat Nov 12, 2011 6:49 pm ] |
Post subject: | RE:bullet collision with object |
If you can't read the comments, then you really aren't trying. I'm not getting paid to do this; I'm not going to do it for you. |
Author: | Zren [ Sat Nov 12, 2011 7:57 pm ] | ||||||
Post subject: | RE:bullet collision with object | ||||||
Okay, full blown source code didn't work. Thinking by yourself didn't work. Theory Time! Huzzah! Take a gander at this program:
This is the basic logic for having a fixed amount of bullets.
As you might of noticed before in the sample code, currentIndex would pause even though we we're trying to 'fire'. This is because the value at the currentIndex was already on. That would mean it's still on screen. You could deem to either: 1) Don't continue (like the sample code) and wait until it turns off (leaves the screen). 2) Continue and overwrite the data. This causes the effect of disappearing bullets when the limit is reached. 3) A combination of 1 and 2. Basically you look for an ready (off state) index. Set that as the currentIndex, and continue. Be warned, make sure to only run through the array once when checking or you might generate an infinite loop in the condition that all indexes are on. *) In all cases, you can minimize the chance of catching up to the tail and hitting an 'on state' by increasing the size of the array. Be careful not to make it too big though. Counting (for looping) over large amounts, even when not doing anything else, can slow your program down. Don't believe me? Try this:
|
Author: | sammi [ Sun Nov 13, 2011 12:03 pm ] |
Post subject: | RE:bullet collision with object |
ok sorry Aange10 i just had to read it over some more but i understand it now a little more |
Author: | Aange10 [ Sun Nov 13, 2011 1:06 pm ] | ||
Post subject: | Re: RE:bullet collision with object | ||
sammi @ 13/11/2011, 11:03 am wrote: ok sorry Aange10 i just had to read it over some more but i understand it now a little more
Oh you mean
Yeah, that must have been hard to decipher. |
Author: | sammi [ Sun Nov 13, 2011 7:42 pm ] | ||
Post subject: | Re: RE:bullet collision with object | ||
Aange10 @ Sun Nov 13, 2011 1:06 pm wrote: sammi @ 13/11/2011, 11:03 am wrote: ok sorry Aange10 i just had to read it over some more but i understand it now a little more
Oh you mean
Yeah, that must have been hard to decipher. no lol i meant the entire code |