Need Help with a Power Up in My Game
Ok so I have a fruit actor that falls from the top of the screen. If my character touches the fruit he collects it and an icon for that fruit appears on the right side of the screen. If he collects two more they both appear as icons for a total of three icons. Once three are collected the character earns a shield and the icons disappear so that the process can be repeated again. Anyway, I have five different fruits. I want it to work like a slot machine in that you need three of the same fruits to win the prize. If you get a strawberry and you then get an orange then the strawberry icon will be replaced with an orange icon. I only have one actor for the fruits and have it change it's image when spawned. I have a game level attribute called "which fruit." I also have a "fruit count" that adds one to the integer for each fruit collected in it's three and then it goes back to 0.
Here's my problem.
I'm trying to figure out how to effectively change the fruit count to 0 IF the character touches a fruit that does not match the first one or first two that he touched. This is tied to the fruit icons that are displayed showing the amount of fruits collected. He has to touch three of the same type to get the shield power up. I can't as of yet figure out a way and was hoping someone could help me before I spend 10 hours pondering the proper solution. Thanks!
This is the same way Ninjump does it if you would like a reference.
Comments
I think I'll just create five separate fruit actors instead of the one fruit actor changing it's image. I'll have to recode a few things but seems like that's an easy solution. I was just trying to have the coding be as simple as possible and have one fruit actor who's image would change at random when spawned.
One way would be to create a three row table with a high value in each cell (e.g. 99). When a fruit is collected, increase the row number by one and change the table cell value of that row to the value of game.whichFruit. That way, the first fruit is stored in row 1, second fruit in row 2, and third fruit in row 3. Have a rule that says When [numeric expression; condition set to ANY] tableCellValue(tableName,1,1)≠tableCellValue(tableName,2,1) or tableCellValue(tableName,2,1)≠tableCellValue(tableName,3,1), Change Attribute game.fruitCount to 0. You'd also need to change the table values back to 99 or just copy a backup of the original table into the working table to reset it.
This doesn't require tables; it could be done with three attributes just as easily.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@tatiang thanks for the workaround but I wanted to see if the current coding I had would work and I finally got it. It was a pain though! I would have rather done your simpler solution. I actually took a break from my game for a week or two and just got back into it so that I would have a clear head. Now onto the next headache!