So while we know that we can use Coda to track our goals, I was wondering if we can also use it to shoot some
How I came up with it
During the shower I had the crazy idea to make some kind of a space invader game in Coda. But playing around with sliders and cells, I got stuck several times, so I wanted to try something different at first. Why not a goalshooting game? I was using some formulas of the space invade tests and came quickly along. Unfortunately there is no goalkeeper emojy, so I had to find a different “enemy”…
The first challenge: A random mechanism
To even make a game possible, I needed a way to have some kind of “random” odds of winning. I thought, at a goalshooting game, a chance of 1:3 would be good.
But how can you make a game mechanism, when you don’t have “randomize” function?
As an inspiration, I found some articles about pseudorandom formulas. It seemed to be possible to generate such things with timestamps. But since there is no timestamp in Coda, I need to use the seconds of the now() formula.
To get my “1 of 3” odds, I created a table with 60 rows. Each Row represend a second of a minute. I filled them with my numbers 1-2-3-1-2-3-1-2-3-1-2-3… All I needed to do now is a formula, that selects the number by the row of the current second. That is not really “random”, it is just a fixed 1:3 chance every second - but enough for the current state of the game.
The second challenge: Making things "move"
This was kind of tricky. Since we currenty can’t do repeats and don’t have the ability to insert data with buttons, I had to find another way. Well, again the time functions were my friends here.
I used the checkbox as my trigger and counted the seconds after that. This was my countdown. Every second, the ball should move 1 field further and at second 4, the game should decide if you win or loose.
Counting the seconds (click to expand)
Checking, when the checkboxes are modified last:
(Shot 1 Shot 2 Shot 3 represent the time a shot was made from left, center or right)
If one of the checkboxes is checked, the counter starts to count the seconds (=the position of the ball):
While the seconds now represent the position on the “field” (1 second after click: 1st position, 2 seconds after click: 2nd position…) , I had to create the field and give out the ball-emoji on the right coordinates.
Give out the ball at the right position (click to expand)
Pos1 is the timer of the left column, pos2 center, pos3 right (I better have named it posleft, poscenter, posright ). At each step, I just check if the timer equals the field of the formula - and if yes, it outputs the ball.
So for the 3rd column, 3rd field from the bottom, it is
pos3 = 3, and so on…
Setting the formula to all of the “grey” fields, makes the ball move after a click now.
Well, the balls are moving now and the odds are set. Whats next?
The third challenge: Goat or Goal?
At first I needed to check, which column is active right now. Where did the player shot at? I did it by calculating, which button was used last, based on the lastmodified variable I created earlier.
To make my formulas shorter, I also wanted the current position in one variable (not one for every colum (pos1,pos2,po3), like it was until now):
Now I have three variables:
- The current position of the ball
- The current column of the shot
- The random number (1, 2 or 3) = goat position
Bringing that together, I was able to execute the last, gamechanging row:
This formula basically checks, if the currentpos of the ball is 4 (so, 4 seconds after the click and directly at the realistcly drawn goal). If yes, it checks if the goat (our random number) will be at this row and show it. If not, it checks if this is our current column (the ball).
BONUS Make the audience go crazy
By checking, if the current column is the same as the goat colum, I made this “win” or “loose” indicator.
Known Issues & limitations by Coda
- Movement: The game is really slow (in the gif on top it is 200%) since it is based on seconds. A timestamp with miliseconds or something similiar could make this easier.
- Random: The selfmade random function is a nice workaround but nothing you can really rely on. A rand() function like in excel or programming languages would do the job.
- Insertion & buttons: My favourite topic. I think I don’t have to mention the creative abilities of buttons or an insertion function
I can’t say it often enough. I really love how creative you can get with the possibilites that Coda already provides. And with the community, alpha tests and such a nice staff, I can’t wait so see how it evolves in the future. It was a nice adventure for today. Now back to something more productive
I’m curious about your thoughts and feedback on that. I will prepare the file for sharing if you want to play around with it on your own.