//Gamemodel functions public void Spawn() { //Reset vars canDealDamage = true; SetPlayerGoalPos(); //Position shark Random r = new Random(); var sign = r.Next(-1, 1) >= 0 ? 1 : -1; var x = FastMath.Max(0.3f, (float)r.NextDouble() * sign); var z = FastMath.Max(0.3f, (float)r.NextDouble() * sign); var y = FastMath.Min(yMax, Player.Instance().Position().Y); TGCVector3 playerPos = Player.Instance().Position(); playerPos.Y = y; mesh.Position = playerPos + new TGCVector3(x, 0, z) * 250f; //Check for collisions foreach (var naveMesh in Nave.Instance().obtenerMeshes()) { bool col = TgcCollisionUtils.testAABBAABB(mesh.BoundingBox, naveMesh.BoundingBox); if (col) { mesh.Position = TGCVector3.Empty; break; } } }
//Common functinos /// <param name="goalPos">Posicion en el mundo a la que se quiere llegar</param> /// <param name="speed">Velocidad a la que la entidad se mueve</param> protected void Move(TGCVector3 goalPos, float speed, float ElapsedTime) { TGCVector3 dir = TGCVector3.Normalize(goalPos - mesh.Position); LookAt(dir); TGCVector3 movement = dir * speed * ElapsedTime; mesh.Position += movement; //Check out for collisions foreach (var naveMesh in Nave.Instance().obtenerMeshes()) { bool col = TgcCollisionUtils.testAABBAABB(mesh.BoundingBox, naveMesh.BoundingBox); if (col) { mesh.Position -= movement; ResetMove(); break; } } mesh.Transform = TGCMatrix.Scaling(mesh.Scale) * TGCMatrix.RotationTGCQuaternion(rotation) * TGCMatrix.Translation(mesh.Position); }