LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

I'm attempting to cause two objects/images to disappear on contact

Hello all.

 

I'm currently creating a space invaders style game for a university coursework, I've so far managed to create player movement, firing and enemy movement. I'm now a little stuck on how to basically have the enemy 'be destroyed' upon contact with the bullet from the player. I've tried to use a comparison of the position property nodes and used an AND gate to provide the source for a case structure, but this doesn't seem to work. I'm not sure whether this is bad code, or whether the bullet misses it by a few pixels and the event doesn't run, but I'm not sure how to provide the bullet with a larger area than one pixel location. Any help would be appreciated. 

0 Kudos
Message 1 of 9
(3,563 Views)

What you've described all sounds like good possibilities as to why your code might not work.

 

But it is impossible to provide any help based on just a written description and without seeing any of your actual code.

0 Kudos
Message 2 of 9
(3,555 Views)

Apologies, I've attached a screen grab of the current structures. I've managed to make some small progress in that as soon as the Top value is equal then the case structure executes, and I'm now going to attempt to link this with the left property as well and see if I can get some semblance of a working program. 

0 Kudos
Message 3 of 9
(3,550 Views)

I've also amended the increment that the enemy image moves to even increments in an attempt to make it easier to marry up the positions by limiting the possible values and having a predictable path.

0 Kudos
Message 4 of 9
(3,548 Views)

Hi Jamie,

 

do you think you need so many local variables (or "value" properties)?

 

Don't you think you could put the "game engine" into a statemachine? (I imagine states like "draw playfield", "move objects", "check collisions", "update player statistics" - just to mention a few…)

And keep all relevant data in a cluster, stored in a shiftregister?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 9
(3,500 Views)

Thank you for the advice,  I will give your suggestion a go and see if I can get it to work! I've been pretty much teaching myself as I've been developing this as my experience with labview is rather limited, and it has been quite difficult to find resources to use!

0 Kudos
Message 6 of 9
(3,479 Views)

You have a race condition with Player Bullet that may cause the bullet to "skip" over the enemy.  As Gerd mentioned, you have too many property nodes.

player bullet.PNG

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 7 of 9
(3,466 Views)

@JamieMoly97 wrote:

Apologies, I've attached a screen grab of the current structures. I've managed to make some small progress in that as soon as the Top value is equal then the case structure executes, and I'm now going to attempt to link this with the left property as well and see if I can get some semblance of a working program. 


OK, none of your code makes any sense. What's up with the FOR loop at the bottom, for example?

Please attach the actual VI so we get a better idea what you are trying to do.

 

All you probably need is a 2D array indicator of flat booleans, with one state colored transparent (or background color). Now overlay a 2D picture with transparent background over it with the same size. Draw the ball using this function. Keep the array in a shift register and switch elements to transparent on collisions (you do the math!). No property nodes or local variables needed at all. For ideas how to bounce the ball, have a look at this old code, for example (posted here).

0 Kudos
Message 8 of 9
(3,440 Views)

Thank you all for your advice! It's been very useful, and I've managed to get it working, now to attempt to integrate it to the main program. 

 

Once again, thank you!

 

Kind Regards,

 

Jamie

0 Kudos
Message 9 of 9
(3,412 Views)