
PIECE: skeleton 4x5x2
PIECE: wall1 13x4x2
Something very used in games (remember "Frogger") is covered by the trick we present now. It's a kind of "template" of a function to be reused for movement of a character from a point A to a point B and his return to A (a cyclic animation) - run the demo to understand better; it's the movement of the skeleton. If the avatar collides against the skeleton he can lost Health or to die (our case). If he losts health (20 points, by example), we can create and put available in the "vista" some glasses of "magic medicine" to reincrease that health. If the health goes to zero, he dies.
Inside the definition of the movement of the character we add the code to test the collision against the avatar :
...
public void moveChar5(int childrenumb, Double charX, Double zInit, Double zNow, Double zFinal){
ModelVisual3D mv3D = VP.Children[0] as ModelVisual3D;
Model3DGroup m3Dg = mv3D.Content as Model3DGroup;
Model3D charac= m3Dg.Children[childrenumb] ;
if(dirChar5=="S") zNow = zInit + loopChar5 ;
if(dirChar5=="N") zNow = zFinal - loopChar5 ;
Matrix3D matMove = new Matrix3D(0.1,0,0,0,0,0.1,0,0,0,0,0.1,0,charX,1.5,zNow,1);
Quaternion qt = new Quaternion(new Vector3D(1, 0, 0),90);
Point3D pt = new Point3D(charX , 1.5,zNow);
matMove.RotateAt(qt,pt);
if(dirChar5=="S")qt = new Quaternion(new Vector3D(0, 1, 0),180);
if(dirChar5=="N")qt = new Quaternion(new Vector3D(0, 1, 0),0);
matMove.RotateAt(qt,pt);
MatrixTransform3D transMove= new MatrixTransform3D(matMove);
charac.Transform= transMove ;
if(zNow > zFinal){
dirChar5="N";
loopChar5=0;
}
if(zNow < zInit){
dirChar5="S";
loopChar5=0;
}
//Collision versus avatar
Point3D pos = new Point3D(TheX ,1.5,TheZ );
Vector3D dist = Point3D.Subtract(pos,pt);
if(dist.Length < 3){
if(avdead==0){
trans = new Matrix3D(0.1,0,0,0,0,0.1,0,0,0,0,0.1,0,TheX ,0.5 ,TheZ,1);
qt = new Quaternion(new Vector3D(1, 0, 0),0);
pt = new Point3D(TheX ,0.5 ,TheZ);
trans.RotateAt(qt,pt);
mtrans= new MatrixTransform3D(trans);
//ModelVisual3D mv3D = VP.Children[0] as ModelVisual3D;//declared before
//Model3DGroup m3Dg = mv3D.Content as Model3DGroup;
m3Dg.Children[4].Transform= mtrans ;
Health.Text = "0";
ChatReceived.Text="SORRY... YOU ARE DEAD! GAME OVER!";
doorbell.Play();
avdead=1;
}
}
}
...
The values for the parameters zInit and zNow are the same (we could to write a better code...).
The "cardinality" of the movement here is North-South-North. It's not dificult to define another.
For each character in movement we need to recriate a new method and to define two global variables like:
... Double loopChar5=0; String dirChar5="S"; ...
And, inside the "main loop" we will have:
...
void OnTimerEvent(object sender, System.EventArgs args){
loopChar5= loopChar5+ 0.2;
moveChar5( 5 ,10,-14,-14,14); //because the skeleton is Children[5] of the Model3DGroup
...
}
...
Pay attention to the fact that the collision against the piece in movement is defined like the static.
IMPORTANT: to note that here we have 2 new types of use of textures: at the skeleton we have a texture used only in the face; at the wall we have a retangular texture not having UVW map.
We are also using the property: Opacity for the skeleton. Sometimes - by example in front of the wall - it doesn't work very well - but you can see the avatar trought it ...
At the demo, we are not defining collision of the avatar against the wall (that usual function).
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 :
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)
PREVIOUS LESSON NEXT LESSON T.CONTENTS HOMEPAGE
