Ejemplo n.º 1
0
        /// <summary>
        /// Explode an explosion.
        /// </summary>
        /// <param name="spot">The starting point for the explosion.</param>
        /// <param name="vel">The starting velocity for the explosion.</param>
        public void explode(Coords spot, Coords vel)
        {
            Coords velocity = new Coords(vel.pos());
            Coords position = new Coords(spot.pos());
            Bullet bullet;
            FBXModel model;

            if (bullets.Count < 1)
            {
                Console.WriteLine("Loading Explosion Bullets.");
                bullet = new Bullet();
                bullet.damage = 100 * power;
                bullet.rateL = 35 * size;
                bullet.dragL = 0.3f;
                bullet.dragR = 0.2f;
                bullet.size = 2;
                bullet.timeToLive = 5;
                model = new FBXModel("Resources/Models/Ember1", "", 1.0f);
                model.lighted = false;
                bullet.models.Add(model);
                bullets.Add(bullet);

                bullet = bullet.clone();
                bullet.damage = 100 * power;
                bullet.rateL = 35 * size;
                bullet.dragL = 0.3f;
                bullet.dragR = 0.2f;
                bullet.size = 2;
                bullet.timeToLive = 5;
                model = new FBXModel("Resources/Models/Ember1", "", 1.0f);
                model.lighted = false;
                bullet.models.Add(model);
                bullets.Add(bullet);

                bullet = new Bullet();
                bullet.damage = 150 * power;
                bullet.rateL = 20 * size;
                bullet.dragL = 0.5f;
                bullet.dragR = 0.3f;
                bullet.size = 2;
                bullet.timeToLive = 5;
                model = new FBXModel("Resources/Models/Ember1", "", 2.0f);
                model.lighted = false;
                bullet.models.Add(model);
                bullets.Add(bullet);

                bullet = new Bullet();
                bullet.damage = 80 * power;
                bullet.rateL = 30 * size;
                bullet.dragL = 0.5f;
                bullet.dragR = 0.3f;
                bullet.size = 2;
                bullet.timeToLive = 5;
                model = new FBXModel("Resources/Models/Ember2", "", 1.0f);
                model.lighted = false;
                bullet.models.Add(model);
                bullets.Add(bullet);

                bullet = new Bullet();
                bullet.damage = 100 * power;
                bullet.rateL = 45 * size;
                bullet.dragL = 0.3f;
                bullet.dragR = 0.3f;
                bullet.size = 2;
                bullet.timeToLive = 5;
                model = new FBXModel("Resources/Models/Ember2", "", 0.6f);
                model.lighted = false;
                bullet.models.Add(model);
                bullets.Add(bullet);

                bullet = new Bullet();
                bullet.damage = 100 * power;
                bullet.rateL = 45 * size;
                bullet.dragL = 0.3f;
                bullet.dragR = 0.3f;
                bullet.size = 2;
                bullet.timeToLive = 5;
                model = new FBXModel("Resources/Models/Ember2", "", 0.6f);
                model.lighted = false;
                bullet.models.Add(model);
                bullets.Add(bullet);
            }

            for (int i = 0; i < particles; i++)
            {
                Console.WriteLine("Explosion Bullet");
                int m = rand.Next(bullets.Count);
                bullet = bullets[m].clone();
                bullet.scaleModels(size);

                bullet.lastPosition = position.Clone();
                bullet.velocity = velocity.Clone();

                bullet.position.T = position.T;
                bullet.position.R = Quaternion.CreateFromAxisAngle(Vector3.Up, (float)(MathHelper.TwoPi * rand.NextDouble())) *
                    Quaternion.CreateFromAxisAngle(Vector3.Backward, (float)(MathHelper.TwoPi * rand.NextDouble())) *
                    Quaternion.CreateFromAxisAngle(Vector3.Right, (float)(MathHelper.TwoPi * rand.NextDouble()));

                bullet.throttle(1f);

                Engine.GetInstance().gameScene.track(bullet, GO_TYPE.BULLET);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Return a list of GameObjects that are within range and 
        /// viewing arc of the given vantage point coordinates.
        /// </summary>
        /// <param name="vantage">Vantage point Coords to render from</param>
        /// <param name="player">player relevant to the scene</param>
        /// <returns>List of GameObjects to render</returns>
        public List<GameObject> visible(Coords vantage, Player player)
        {
            Room roomIn = null;
            foreach (Room room in rooms)
            {
                if (room.area.Contains(vantage.pos()) != ContainmentType.Disjoint)
                {
                    roomIn = room;
                    break;
                }
            }
            Dictionary<int, List<GameObject>> visibleObjects = new Dictionary<int, List<GameObject>>();

            if (roomIn == null || roomIn.canSeeOutside)
            {
                updateOctTreeObjects();

                float aspRatio = GammaDraconis.renderer.aspectRatio;
                float viewAngle = GammaDraconis.renderer.viewingAngle;
                float viewDist = GammaDraconis.renderer.viewingDistance;

                Matrix view = Matrix.CreateLookAt(vantage.pos() - Matrix.CreateFromQuaternion(vantage.R).Forward, vantage.pos(), Matrix.CreateFromQuaternion(vantage.R).Up);
                BoundingFrustum viewFrustum = new BoundingFrustum(view * Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(viewAngle), aspRatio, 0.1f, viewDist));

                Dictionary<int, List<GameObject>> optimizedObjects = new Dictionary<int, List<GameObject>>(objects);//sortOctTree(out visibleObjects, viewFrustum);

                foreach (int tempKey in optimizedObjects.Keys)
                {
                    if (!visibleObjects.ContainsKey(tempKey))
                        visibleObjects.Add(tempKey, new List<GameObject>());

                    List<GameObject> tempKeyObjects = optimizedObjects[tempKey];
                    foreach (GameObject gameobject in tempKeyObjects)
                    {
                        // Take care of some quick cases before doing any math.
                        if ((tempKey & GO_TYPE.SKYBOX) == GO_TYPE.SKYBOX)
                        {
                            visibleObjects[GO_TYPE.SKYBOX].Add(gameobject);
                            gameobject.position.T = Matrix.CreateTranslation(vantage.pos());
                        }
                        else
                        {
                            if (viewFrustum.Contains(new BoundingSphere(gameobject.position.pos(), gameobject.size)) != ContainmentType.Disjoint)
                            {
                                visibleObjects[tempKey].Add(gameobject);
                            }
                        }
                    }
                }
            }
            else // roomIn != null
            {
                foreach (int tempKey in objects.Keys)
                {
                    if (!visibleObjects.ContainsKey(tempKey))
                        visibleObjects.Add(tempKey, new List<GameObject>());
                    foreach (GameObject gameobject in objects[tempKey])
                    {
                        if ((tempKey & GO_TYPE.SKYBOX) == GO_TYPE.SKYBOX)
                        {
                            visibleObjects[GO_TYPE.SKYBOX].Add(gameobject);
                            gameobject.position.T = Matrix.CreateTranslation(vantage.pos());
                        }
                        else
                        {
                            bool visible = false;
                            if (roomIn.area.Contains(gameobject.position.pos()) != ContainmentType.Disjoint)
                            {
                                visible = true;
                            }
                            else
                            {
                                foreach (Room room in roomIn.visibleRooms)
                                {
                                    if (room.area.Contains(gameobject.position.pos()) != ContainmentType.Disjoint)
                                    {
                                        visible = true;
                                        break;
                                    }
                                }
                            }
                            if (visible)
                            {
                                if ((tempKey & GO_TYPE.SCENERY) == GO_TYPE.SCENERY)
                                    gameobject.position.R = Quaternion.CreateFromRotationMatrix(Matrix.CreateBillboard(vantage.pos(), gameobject.position.pos(), Vector3.One, Vector3.Forward));
                                visibleObjects[tempKey].Add(gameobject);
                            }
                        }
                    }
                }
            }
            // Player specific visibility logic
            if (visibleObjects.ContainsKey(GO_TYPE.CHECKPOINT))
            {
                foreach (GameObject gameObject in visibleObjects[GO_TYPE.CHECKPOINT])
                {
                    RaceStatus status = Engine.GetInstance().race.status(player, true);
                    int lap = status.lap;
                    int currentLocation = status.checkpoint;
                    int checkpointPosition = ((Checkpoint)gameObject).racePosition;
                    if (checkpointPosition > currentLocation)
                    {
                        // TODO: change differentiation from visible/invisible to differences in how the checkpoints are rendered (color? brightness?)
                        gameObject.models[0].visible = true;
                        gameObject.models[1].visible = false;
                    }
                    else
                    {
                        gameObject.models[0].visible = false;
                        gameObject.models[1].visible = true;
                    }

                }
            }

            if (visibleObjects.ContainsKey(GO_TYPE.DIRECTIONAL_ARROW))
            {
                List<GameObject> removeTheseArrows = new List<GameObject>();
                foreach (GameObject gameObject in visibleObjects[GO_TYPE.DIRECTIONAL_ARROW])
                {
                    if(!player.arrow.Equals(gameObject)){
                        removeTheseArrows.Add(gameObject);
                    }
                }
                foreach (GameObject gameObject in removeTheseArrows)
                {
                    visibleObjects[GO_TYPE.DIRECTIONAL_ARROW].Remove(gameObject);
                }
            }

            List<GameObject> shownObjects = sortObjects(visibleObjects);
            if (player != null)
            {
                shownObjects.AddRange(player.dust);
            }
            return shownObjects;
        }