Jump to content
  • Advertisement
Sign in to follow this  
BlackSunStudios

Help With A Game Re-development Problem? (java)

This topic is 2601 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys BlackSun again!

I have developed a game called EXTRON its basically a game in which you have electronic components (that i made up) but it has a flaw :/ The way wire works.
Its tile based so it has 4 tiles next to it. This is how I want the wire to work:

if a power source is hooked up to a wire then it is powered if not then it is off.

how it works now:

if top.power > 0 then this.power += top.power/4
then for left, right and bottom.

this is a very bad way i know.
I would much rather like it to be not based on power integers but based on booleans.
When i tried using a boolean it stayed on when the power source was not there.
If you have any answers than please tell me for i am slightly desperate.
If i did not mke anything clear here then please ask me.

Also:
if you want to download the game and see how it works then visit my blog neutronbombstudios.tumblr.co.uk(.com)
if you know any programs that already have this and source code then please tell me :)

Thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
boolean powered = false;
if (top.powered)
powered = true;
else if (bottom.powered)
powered = true;
else if (left.powered)
powered = true;
else if (right.powered)
powered = true;


Alternatively:

boolean powered = (top.powered || bottom.powered || left.powered || right.powered);

The second uses a Boolean Or to see if the wire should have power or not; if any of the four connected pieces are powered, it will be true, otherwise it will be false.

Share this post


Link to post
Share on other sites

boolean powered = false;
if (top.powered)
powered = true;
else if (bottom.powered)
powered = true;
else if (left.powered)
powered = true;
else if (right.powered)
powered = true;


Alternatively:

boolean powered = (top.powered || bottom.powered || left.powered || right.powered);

The second uses a Boolean Or to see if the wire should have power or not; if any of the four connected pieces are powered, it will be true, otherwise it will be false.


But when a wire above is powered and the power source is turned off then the wire will still be powered if there are 2 or more wires connected to it :/

Share this post


Link to post
Share on other sites
Erm... I don't follow?

Maybe you could post a picture showing exactly what the situation is and how you want the logic to work?

Share this post


Link to post
Share on other sites
So you're saying that once power has been applied to a wire (and propagated to all nearby wires, since it seems wires check their power by polling all immediate neighbors), if you remove the power source your wires continue to think they're powered since they keep noticing their neighbor thinks it is powered? Sounds like you need to change the way you're checking for power flow. As alternate possibilities, you could track the number of power sources (like reference counting) that reach a particular wire tile, or change the way your wires respond to a power source being turned off, like:

when source is powered off
-check all wires that connect to this power source
-if this is their only power source
-- turn them off
-else
-- reduce their source count by 1

Share this post


Link to post
Share on other sites

So you're saying that once power has been applied to a wire (and propagated to all nearby wires, since it seems wires check their power by polling all immediate neighbors), if you remove the power source your wires continue to think they're powered since they keep noticing their neighbor thinks it is powered? Sounds like you need to change the way you're checking for power flow. As alternate possibilities, you could track the number of power sources (like reference counting) that reach a particular wire tile, or change the way your wires respond to a power source being turned off, like:

when source is powered off
-check all wires that connect to this power source
-if this is their only power source
-- turn them off
-else
-- reduce their source count by 1



Thanks! :)

The bit about the neighbour wires was about someone else who posted an answer.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!