Sunday, December 20, 2009

Feelin' Lucky?



Larger version here.

In a departure from the stuff I normally do, I decided to make an actual game. Here you have a 4-reeled slot machine. You place your bet (top 3 red buttons) and your risk of the spin (bottom 3 red buttons). Then click the purple "roll" button and you're off!

Your winnings are determined by how many of the rings line up once the spin is completed.
No Matches: 0
One Match: (your bet) x (risk/2)
Two Matches or 3 of-a-kind: (your bet) x (risk)
All Four: (your bet) x (risk) x 5

This isn't an absolutely crazy to program game. I use modulus (%) to determine when or if one of the rings should stop. Each ring is simple a tweened animation, and every 1, 2, or 5 frames (based on risk 1, risk 5, or risk 10 respectively) it rolls a counter to see if it should stop or not.

Once all four rings are stopped, the frame number of each is pushed into an array. Each value in the array is compared to the rest of the values to see if they match. Different numbers of matches indicate what the winnings should be. I wasn't quite able to compare a single value against everything else and then exclude it from the array (probably could, but not worth the headache), so a non-match actually shows up as 4 matches (the checked value in the array checks against itself as well).

Oh, and the little "$" button in the corner refills your credits to 100 if you are below 100 credits.

No comments:

Post a Comment