Apply a table of truth in a program

0 favourites
  • 6 posts
From the Asset Store
An educational game for Times Table. An easy to use template for developers to build larger games
  • Hi, everybody!

    Look, now I'm at the final stage of a program.

    project

    I have applied a truth table.

    We can have some sprites present or not. These are the possible combinations:

    OOO

    XOO

    OXO

    OOX

    XXO

    XOX

    OXX

    XXX

    Where a 'X'means the sprite is visible, and the 'O' means it is not.

    The opacity of the laser beam changes depending on a formula that includes angles values for each sprite's instance.

    I have thought to act like in the 'case' operation in C or Java.

    But in this case...It seems that it does not work.

    Do you have any idea about the reason?

    Thanks a lot in advance. I left to you this project if it is usefull for somebody someday.

  • You could do it like this:

    global text pattern=""
    
    Every Tick:
    --- set pattern to ""
    
    For each sprite:
    --- sprite is visible:
    ------ add "x" to pattern
    --- else:
    ------ add "o" to pattern
    
    //// cases
    pattern = "ooo":
    --- do this
    
    pattern = "xoo":
    --- do that
    
    ...
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Interesting.

    Such thing could be done as well with two arrays?

    One of them for the sprites values selected by the buttons, and the other as a Registry. Comparing them we can solve the matter and modulate the opacity of the lasers.

    How do you like that?

  • I suppose you could do it with arrays but it's not necessary.

    Here's how I would do it:

    http://dl.dropbox.com/u/5426011/examples14/laserFilter.capx

  • You can represent the 3 postions using binary with 1 variable.

    Like with a 8 bit number the least significant bit is 1 and the next is 2 and the next is 4.

    variable == 4 the result is oox

    variable == 2 the result is oxo

    variable == 1 the result is xoo

    So the variable can be anything between 0-7 which represents a condition you can act on.

  • Thanks to all for your wise advices and dedication. I've properly finished the project, using an unidimensional array with three elements.

    Afterwards, to emulate the switch command of C, a chain of If-else has been made to allow control over the different sprites that make part of the light beam.

    Buttons are active and not only change the visibility of the sprites, they change also the values of that array.

    As it seems that Construct2 does not allow to pick up more than one instance in a condition, this is the way that solved the issue...(Among a handful of other ways, of course.)

    And thanks of the help from the people of the forum!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)