March 5th, 2009

Silverlight Bugs v1 – Playing with Random

All Silverlight Examples, Silverlight 2 tutorials, Silverlight C# Tutorials, Silverllight Games, by Gavin Wignall.

Using the Random command in Silverlight we can give the impression that elements are thinking for themselves. By clicking the ‘add a bug’ button in the below example the Silverlight will create a new bug with a ‘bugLife’ value of 100. After that everything else that happens is controlled by the Random command starting off with the colour of the bug and then the direction it faces, the speed it moves at and finally how long it is untill the bug makes a new set of decisions.


The bug will lose 1 point of life every time it makes a new decision and a further 4 points if it bumps into the wall (the edge of the screen). When the ‘bugLife’ value reaches zero the bug will die and cease movement.

Future enhancements

I have already got additional values set up so that I can allow the user to customize each bug a little. For example you could give the bug extra life, tell it to make decisions quicker or speed it up. So I plan on making a popup/interface for the user to interact with these settings.

I also plan on adding a trait to each bug that will decide on how each bug will act when it comes in contact with another bug. For example 2 bugs could fight, run away from each other or reproduce and create more bugs. These new bugs would retain qualities from the 2 that produced them.

Finally I want to add the ability for the user to place food on the stage. This will attract bugs within a certain range and replenish their ‘bugLife’ while the food lasts.

Get the code

Feel free to grab the code here and start playing!

Back Top

Responses to “Silverlight Bugs v1 – Playing with Random”

  1. Thanks for providing the code for this. I am currently learning Silverlight and good examples like this help a lot.

  2. I just stumbled on this lastnight, and it is quite fascinatig. it’s really great creative competence.It’ wonderful.

    Chukwuemeka Uba at March 13, 2009 12:29 am
  3. its so nice of you. thanks.

  4. Hi. WHat exactly is this, and why would a person download it? Sorry, Im not trying to offend anyone, I just dont completely understand silverlight. Is it for everyday web users, or is it a tool for pros building web sites? Thank you for your time.

  5. Hi Kelly, Silverlight is a browser plug-in for everyday users. It will allow you to view pages on the web that use Silverlight on them, just like the Flash plug-in does with pages using Flash. You can read more about it at http://www.silverlight.net but unfortunately the only way to see examples of Silverlight in your browser is to download the plug-in.

  6. This is a pretty cool example!

  7. I can’t see what benefit this gives the user. Why would I download yet another plugin? What exactly does Silverlight do that cannot be done using existing Web technologies?

  8. In many ways the Silverlight plug-in is similar to the Flash plug-in, in that it adds a lot of additional functionality to your web experience. Flash has had little competition for many years, now Microsoft are competing with them it will hopefully help to push both companies to produce better products which we can all benefit from. Another key factor is that Silverlight plugs into the .Net framework, meaning that Silverlight is the preferred tool over Flash for many web developers. This allows rich interactive environments to utilise powerful and more useful data and therefore improving the users experience.

    By the way, the plug-in takes seconds to install and can be un-installed if you decide you don’t need/want it.

  9. how about implementing sex and dna ??

    then you get real bugs ;-)

  10. so nice of you,thanks!

  11. It’s reallly helpful for .NET developers like me, who do not want to learn or work in Flash, so thanks.

    mayank nagar at March 23, 2009 8:55 am
  12. Cool…
    Given the weightage of bumping vs normal decision making, the end result makes an interesting study – most bugs(90%+) die at the corner.

    makes me wonder about the modeling tools that can be build easily with Silverlight

  1. No trackbacks yet.

Leave a Reply

Back Top