Need Help with simple game plz

Hi,

I am making a game similar to the classic game 'lights out'. Mine is basically 'lights on' though. The object of the game is to light up all of the circles to win and proceed to the next level.

The level is a 4x4 group of perfectly spaced yellow circles(light on) 16 circles altogether. If a player touches or clicks a circle, I need the circle pressed and the north, south, east, and west circle to turn off(black circle). And vice versa, if a black circle is touched, I need that circle and the neighbor circles to turn on.

How can I do this? Any help would be appreciated.

Thank you!

Comments

  • KevinCrossKevinCross London, UKMember Posts: 1,894
    Look at tutorials on how to use tables.

    Basically you change the table cell to 0 or 1, depending what it currently is and then you do the same to the 4 adjoining table cells.

    Even though it's a very easy project it's not so easy writing down in a forum post so if you're still struggling tonight I will throw together a basic template for you now that I'm not working on my own game. It's 6AM here so it'll be about 14 hours or so before I can send anything if someone hasn't helped you sooner
  • xjgunsxxjgunsx Member Posts: 4
    @KevinCross,

    I have been looking at some stuff on tables and still having problems. If you could help me with a template that would be AWESOME!

    Thank you
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    I'm sure a template will be helpful to you but in the meantime, here's the basic setup:

    Place a single actor on the scene 16 times in a 4x4 grid. In the actor, create two integer attributes called myRow and myCol. Double-click on each actor on the scene and change its self.myRow and self.myCol attributes to match its physical location on the screen.* For example, if it is the X below, it would be self.myRow=2 and self.myCol=3. Type these values in in the attribute inspector area.

    OOOO
    OOXO
    OOOO
    OOOO

    *There is a known bug that can cause instance attributes such as these to revert back to the last entered value. To check for this bug, add a DisplayText behavior to the actor, change the color to something that will be visible, and in the expression editor select self.Row, add two periods, and then select self.Col (it should look like self.Row..self.Col; the two periods concatenate or join the attributes into a text value that can be displayed).

    If everything worked properly, you should see:

    11 12 13 14
    21 22 23 24
    31 32 33 34
    41 42 43 44

    If not, try saving, quitting, and re-opening your Project File. Then re-enter all of the numbers manually as you did before and test again.

    Moving on...

    Create a table with 4 rows and 4 columns of type Integer and name it TBonoff. Change each cell value to 1. This will represent the "on" state for each grid square actor. In the grid square actor, create a boolean attribute called self.On. Add a constrain attribute behavior and constrain self.On to tableCellValue(TBonoff,myRow,myCol).

    Add a rule that changes the Image or color or displays text based on the value of self.On (either 0 or 1) so you can see the difference when the value changes.

    Add a rule When Touch is Pressed
         Change Table Value
              table: TBonoff; row: myRow+1; col:myCol; value: 1-tableCellValue(TBonoff,myRow+1,myCol)
    Change Table Value
    table: TBonoff; row: myRow-1; col:myCol; value: 1-tableCellValue(TBonoff,myRow-1,myCol)
    Change Table Value
    table: TBonoff; row: myRow; col:myCol+1; value: 1-tableCellValue(TBonoff,myRow,myCol+1)
    Change Table Value
    table: TBonoff; row: myRow; col:myCol-1; value: 1-tableCellValue(TBonoff,myRow,myCol-1)
         Save Table [table: TBonoff]

    Essentially, each behavior is just changing the value of a table cell directly above/below/to the left/to the right to its opposite value. If the current value is 1, it will be changed to 1-1=0. If the current value is 0, it will be changed to 1-0=1.

    That should get you started. I didn't test any of this but I'm fairly confident it should work. If you run into any snags, post your progress here with a description of whatever is not working.

    It's not perfect code; ideally, you wouldn't change a table value for a cell that doesn't exist (e.g. the grid square actor in the top row shouldn't be trying to change the value of tableCellValue(TBonoff,myRow-1,myCol) because there is no actor above row 1 and more importantly there is no table row 0. But you'll have to decide how to handle those cases.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • xjgunsxxjgunsx Member Posts: 4
    @tatiang,

    I will try this tonight when I get off work. Thank you.

    @KevinCross

    I am still open for a template :) Thank you.
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    Yeah sorry, I totally forgot I had a work do >.< making my way home from it now so will see of I can throw one together tomorrow at some point.
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    Sorry for the delay with this one. Here's a template for you: https://www.dropbox.com/s/cq5wy3xqe9onzlj/Lights On.zip

    It doesn't count how many lights are on and off but does do the switching you want. I couldn't think of an easy way of counting how many lights are on without looping through the tables and GameSalad 10.4 doesn't have table loops yet.

    With this example the lights are randomised when the scene is first loaded and the code for this is on the light actor. I don't know how you want to randomise it but you could do it this way or loop through and randomly set the cells in the table.

    The table size is 7x7 even though the grid of lights is 5x5 because in GameSalad if you check a table row or column that doesn't exist in the table it throws a wobbly, so in this example I'm starting the grid from row 2 and column 2. This leaves a blank row and column all around the grid. If you have the table the same size you need to add extra rules so that it doesn't check rows and columns that don't exist.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    it throws a wobbly
    I like that! Never heard it before.

    Nice looking template. >:/

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • KevinCrossKevinCross London, UKMember Posts: 1,894
    Thanks @tatiang!
  • xjgunsxxjgunsx Member Posts: 4
    edited December 2013
    @KevinCross and @tatiang,

    I forgot to mention I am using Windows 7... I can't open the template. noooooooooooooo......

    Is there a way around this? Any help tonight would be greatly appreciated.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • xjgunsxxjgunsx Member Posts: 4
    @tatiang
    Eventually it just opened... wierd.
    Anyway, @KevinCross everything works but the puzzles are randomized (I was hoping to make levels where certain lights are set to be off and the user has to figure out how to turn on the rest of the lights to progress to the next level). Also, I have tried and the puzzles are never solvable, there is always at least 1 light left.
    If Kevin can't help tonight with this, tatiang, could you possibly help with this delimma?

    Thank you both!
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    If you don't want randomized puzzles, just have each spot grab its value from its corresponding table cell. Then set up your tables ahead of time with the correct values for each spot.

    I imagine that Kevin's demo isn't intended to be a solvable puzzle but rather just a random grouping of lights.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • KevinCrossKevinCross London, UKMember Posts: 1,894
    I imagine that Kevin's demo isn't intended to be a solvable puzzle but rather just a random grouping of lights.
    Thanks @tatiang, that's exactly right! I just set up something quickly to show how I would toggle lights on and off if I were attempting to create a similar game.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Just unearthed an old template I have on my hard drive by @DeepBlueApps‌.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Sign In or Register to comment.