SpriteHand
Module Border
  Destroy All Invaders! Source
Module Border
Location: BlogsAndy's Blog    
Posted by: host 6/21/2007 3:09 AM

UPDATE 7/22/2009: The source code download and demo have been updated for Silverlight 3 RTW. Also, GPU Acceleration was added to the scrolling and the base class problem described in the comments was fixed.

UPDATE 10/14/2008: The source code download and demo have been updated for Silverlight 2 RTW.

In my last post, I talked a bit about Destroy All Invaders, a scrolling game I am working on using Silverlight which uses Microsoft Virtual Earth oblique (birds-eye) images for the background. In this post, I am making available the source code for Destroy All Invaders, and I'll talk a bit about how the scrolling background is accomplished.

Links to the Goodies!

You can play the game by clicking an image above, and you can get the source code here.

About the Scrolling

In order to do the scrolling background, I used a Canvas called ScrollBackground in Page.xaml to hold all the map tile images from Virtual Earth:

Each map tile for the oblique imagery is 256x256, and if you look at the function SetupTiles in Page.xaml.cs, you can see how these tiles are created and added into the ScrollBackground canvas:

string xaml = "<IMG height=256 width=256 source="\" \>";
_imgTiles[i, j] = (Image)XamlReader.Load(xaml);
_imgTiles[i, j].SetValue(Canvas.TopProperty, i * 256);
_imgTiles[i, j].SetValue(Canvas.LeftProperty, j * 256);
ScrollBackground.Children.Add(_imgTiles[i, j]);

In order to create the scrolling effect, we then only need to change the position of ScrollBackground. This is done with two vars _scrollOffsetX and _scrollOffsetY.

Looking at the CheckScroll method, which controls the scrolling movement, we see that a handy utility function is used to calculate the X and Y position change of an object based on its Direction (angle) and Speed:

Utils.CalculateMovement(_scrollAngle, _scrollSpeed, out xdiff, out ydiff);

 ... after which we can change the location of the scrolled background:

ScrollBackground.SetValue(Canvas.LeftProperty, _scrollOffsetX);
ScrollBackground.SetValue(Canvas.TopProperty, _scrollOffsetY);


So much more...

There is a lot more going on in Destroy All Invaders, like the actual integration with Microsoft Virtual Earth... which I hope to hit on in posts soon to come!

Permalink |  Trackback

Comments (7)   Add Comment
Re: Destroy All Invaders! Source    By Anonymous on 6/29/2007 1:55 PM
I'm finding samples of WPF or SilverLight. This game is very cool, i'll try to translate it to wpf format.
Coming soon in http://www.nears.cn/games/DestroyAll/

Re: Destroy All Invaders! Source    By Anonymous on 7/21/2007 2:04 AM
Great work Andy. Could you please spill some light on the actual integration of the Virtual earth feature or at least suggest a resource where I could find out how to build this kind of functionality.

Thanx,

Philip

Re: Destroy All Invaders! Source    By Anonymous on 9/10/2008 8:25 PM
Can an end user customize the locations used as backdrops?

Re: Destroy All Invaders! Source    By Anonymous on 2/2/2009 12:03 AM
4Errors
1.Partial declarations of 'DestroyAllInvaders.UFO' must not specify different base classes
2. Same error for Helicopter
3.Same for UfoFire
4.and same for LaserFire
How do you get around this to be able to compile DestroyAllInvaders?

Re: Destroy All Invaders! Source    By Anonymous on 2/2/2009 12:03 AM
4Errors
1.Partial declarations of 'DestroyAllInvaders.UFO' must not specify different base classes
2. Same error for Helicopter
3.Same for UfoFire
4.and same for LaserFire
How do you get around this to be able to compile DestroyAllInvaders?

Re: Destroy All Invaders! Source    By Anonymous on 5/22/2009 8:07 AM
I'm getting the same 4 errors as the post above. Andy, please let me know how to fix them.

Re: Destroy All Invaders! Source    By Anonymous on 5/22/2009 8:24 AM
I was able to fix the issue. On the user controls that this error is showing up, do the following:

1. Replace the tag with (don't forget the end tags)
2. Add the namespace to the xaml file
xmlns:DestroyAllInvaders="clr-namespace:DestroyAllInvaders"

The beginning of the xaml should look something like this:

xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:DestroyAllInvaders="clr-namespace:DestroyAllInvaders"
Width="4" Height="40">


Title:
Comment:
Add Comment   Cancel 
Module Border Module Border
Module Border
  Subscribe
Module Border
RSS   Twitter
Module Border Module Border
Module Border
  Diversions
Module Border


PHYSAMAJIG
This Windows app was created using Physics Helper XAML, and the Farseer Physics Engine.
DOWNLOAD

MORE INFO



TALKING RAGDOLL
This Windows Phone app was created using Silverlight, the  Physics Helper Library,  and the Farseer Physics Engine. It gets interesting when you import your friends photos and have your way with them!

MORE INFO



BOSS LAUNCH
This physics game won first place in the Server Quest Contest. Created using Silverlight , the Physics Helper Library,  and the Farseer Physics Engine.
PLAY IT

MORE INFO



DESTROY ALL INVADERS
A scrolling shooter game where the objective is to destroy the invading UFO's flying over a neighborhood of your choosing. Imagery provided by Microsoft Virtual Earth. Created using Silverlight.
PLAY IT

INFO AND CODE



PHYSICS HELPER DEMOS
These demos were created for the Physics Helper Library, which makes it easy to create physics games and simulations using Expression Blend, Silverlight, and the Farseer Physics Engine.
PLAY IT

INFO AND CODE



HOOK SHOT
This little basketball game took first place in the TeamZoneSports Silverlight Contest. Created using Silverlight and the Farseer Physics engine.
PLAY IT

MORE INFO



SORT THE FOOBARS
A game where you need to sort the good foobars from the bad ones. Created using Silverlight and the Farseer Physics engine.
PLAY IT

MORE INFO



POLYGON PHYSICS DEMO
A demo showing polygon physics where the user draws physics objects with the mouse. Created using Silverlight and the Farseer Physics engine.
PLAY IT

MORE INFO



SILVERLIGHT ROCKS!
Destroy the asteroids before they destroy your ship! Created using Silverlight.
PLAY IT

INFO AND CODE



FISH GAME
A simple game of harpoon-the-fish. Written using the AJAX Sprite Toolkit.
PLAY IT

INFO AND CODE

Module Border Module Border
Module Border
  Search_Blog
Module Border
Module Border Module Border
Module Border
  Blog_Archive
Module Border
Module Border Module Border
Copyright (c) 2014 andy.beaulieu.com - Login
cheap Ralph Lauren shirts Ralph Lauren outlet Canada Goose jackets on sale cheap moncler jackets moncler jackets on sale moncler outlet canada goose outlet canada goose outlet canada goose outlet cheap ralph lauren shirts ralph lauren outlet ralph lauren outlet canada goose outlet canada goose outlet kanye west louis vuitton moncler outlet moncler outlet moncler outlet moncler outlet speedy louis vuitton canada goose outlet moncler outlet tiffany outlet moncler outlet speedy louis vuitton kanye west louis vuitton