March 19th, 2009

Cup-o-Salt Silverlight game beta 1

All Silverlight Examples, Silverlight News, Silverllight Games, by Gavin Wignall.

The below example shows the beginnings of my entry to the Mashooo S Prize Game Contest. The aim of “Cup-o-Salt” is to fill up the cups with the falling salt. You can use the mouse to draw lines that the salt will hit and react to and thus direct the salt into the cups. You only get a limited amount of salt so you need to act fast to fill both cups up before you run out. Until I build in a ‘restart’ feature, you will need to refresh the page to start again.


I use the Random function to make each grain of salt different in the following ways:
Distance between grains height
Distance between grains width ways
Salts level of opacity 
The direction a grain of salt will fall to if it hits a flat object

To get the drag and draw action working I used the method I blogged about titled ‘Building a paint application in Silverlight using the ‘Line’ element‘.

For collision testing I am using VisualTreeHelper.FindElementsInHostCoordinates function, thanks to a little help from my colleague James Hardaker. This allows me to test what objects a specified co-ordinate on screen is touching. Once I have this information I run a check on the amount of items a grain of salt is about to touch directly below it and command it to act accordingly. I run similar checks to detect when a cup is filled with salt.

Still to do

Scoring will be worked out from how many grains of salt were left after filling each cup up.
More levels with different cups, obstacles and challenges.
A ‘how to’ instructions page.
A high scores table.
Possibly an eraser function to remove lines drawn. 

Get the code

Once the game competition is finished and the game complete I will aim to release the source code, until then I’m afraid this ones under lock and key.

All suggestions towards improving the game are most welcome :)

Back Top

Responses to “Cup-o-Salt Silverlight game beta 1”

  1. Love it…

    If I build a funnel to drop the salt into the jars the game is as good as over, why dont you add a bit more dynamism into the game by making the lines disappear and the source move every so often.

    And also the score is always 0

  2. Thanks Harry,

    I have plenty to work on and improve before the project is submitted for the competition – The scoring will be one of the next features to get in ;) . Thanks for the suggestions too.

  3. Love it too! Really intuitive redirecting the flow of grains down the lines. The grains seem to react as if they were real.

    Idea: Maybe an Xmas version with gifts failing into Santas sack, or falling down a chimney?

    Andy B

  4. I remember seeing this post a loooong time ago and being excited about the game. Unfortunately the Mashooo S Prize is now closed for submissions but I definitely would love to see Cup-o-salt finished. Are you working on it? I’m saving a spot for it on Mashooo.

  5. It’s on my list that seems to be ever growing :)

  6. Great! post! :)

  1. Home made Wiimote whiteboard demos Silverlightbuzz! » Silverlight Buzz (,August 1, 2009)

    [...] two examples from this site were my Interactive 3D Cube and my Cup-o-Salt prototype [...]

Leave a Reply

Back Top