
If you are trying (like us) to create a 2D game using the "Zelda paradigma" you need to create a "walking" character.
For this you need to have 8 .GIFs and to modify the Opacity of each one when the user press the keyboard keys ("i", "k", "l" and "j").
The complete code (and images, sounds etc. ) you will find at the dowloadable material. A fragment:
...
if (e.Key == Key.K ){
TheYj=TheYj+1;
if(TheYj%2==0){
if(doeA.Opacity==1){
doeA2.Opacity=1;
doeA.Opacity=0;
if(Collision(doeA2,wall1)==1){
TheYj=TheYj-10;
boing.Play();
}
transj = new TranslateTransform(TheXj,TheYj);
doeA2.RenderTransform=transj;
}
else{
doeA.Opacity=1;
doeA2.Opacity=0;
if(Collision(doeA2,wall1)==1){
TheYj=TheYj-10;
boing.Play();
}
transj = new TranslateTransform(TheXj,TheYj);
doeA.RenderTransform=transj;
}
doeR.Opacity=0;
doeR2.Opacity=0;
doeB.Opacity=0;
doeB2.Opacity=0;
doeL.Opacity=0;
doeL2.Opacity=0;
}
...
We need to capture only one at 2 "key-presses" using if(TheYj%2==0). Perhaps a bug...
To capture the position of the avatar when he goes to another level (page)
we use the collection myApp.Properties to define flags and variables that can be accessed at any page:
...
if(TheXj>748){
navWindow.Source = new Uri("Window2.xaml", UriKind.RelativeOrAbsolute);
myApp.Properties["trans1_2"]="1";
myApp.Properties["TheYj"]=TheYj.ToString();
}
...
And at the For the demo, create a folder having the name of the .ZIP file and download it - right-clicking the link - and unzip inside the folder :
REMEMBER: The keys to move the avatar are "i", "k", "l" and "j".
If you like only to see the application running you don't need to do the above download. Only liberate the firewall and play this web3d application:
We are doing our tests at a: Notebook DELL Latitude D600 - Intel Pentium M755 2.0 GHZ - Memory: 512 MB - VideoCard ATI Radeon 9000 32MB DDR 4xAGP - Resolution 1400x1050 - Communication: ADSL 256 kbps (Download: 45 kBps, Upload: 14 kBps)
...
private void OnLoaded(object sender, EventArgs e){
...
myApp = (Application)System.Windows.Application.Current;
...
if((String) myApp.Properties["trans1_2"]=="1"){
TheXj=0 ;
TheYj=Convert.ToDouble(myApp.Properties["TheYj"]);
doeR2b.Opacity=0;
doeRb.Opacity=1;
doeLb.Opacity=0;
doeL2b.Opacity=0;
doeAb.Opacity=0;
doeA2b.Opacity=0;
doeBb.Opacity=0;
doeB2b.Opacity=0;
transj = new TranslateTransform(TheXj,TheYj);
doeRb.RenderTransform=transj;
}
...

