示例#1
0
        /// <summary>
        /// Get a prototype clone with given name, position, and velocity.
        /// </summary>
        /// <param name="name">Prototype name</param>
        /// <param name="index">Player index</param>
        /// <param name="position">New Position</param>
        /// <returns></returns>
        public static Player getPlayer(string name, PlayerIndex index, Coords position)
        {
            if (racer.ContainsKey(name))
            {
                Player go = Player.cloneShip(racer[name], index);
                go.position = position;
                go.velocity = new Coords();
                return go;
            }
            else if (ship.ContainsKey(name))
            {
                Player go = Player.cloneShip(ship[name], index);
                go.position = position;
                go.velocity = new Coords();
                return go;
            }
            else if (thing.ContainsKey(name))
            {
                Player go = Player.cloneShip(thing[name], index);
                go.position = position;
                go.velocity = new Coords();
                return go;
            }

            Console.WriteLine("Proto.getPlayer() failed!");
            return null;
        }
示例#2
0
 /// <summary>
 /// Clone a Coords object.
 /// </summary>
 /// <returns>A cloned Coords object.</returns>
 public Coords Clone()
 {
     Coords c = new Coords();
     c.R = new Quaternion(R.X, R.Y, R.Z, R.W);
     c.T = Matrix.Identity * T;
     return c;
 }
示例#3
0
        /// <summary>
        /// Get a prototype clone with given name, position, and velocity.
        /// </summary>
        /// <param name="name">Prototype name</param>
        /// <param name="position">New position</param>
        /// <param name="velocity">New velocity</param>
        /// <returns></returns>
        public static Racer getRacer(string name, Coords position, Coords velocity)
        {
            if (racer.ContainsKey(name))
            {
                Racer go = racer[name].clone();
                go.position = position;
                go.velocity = velocity;
                return go;
            }
            else if (ship.ContainsKey(name))
            {
                Racer go = Racer.cloneShip(ship[name]);
                go.position = position;
                go.velocity = velocity;
                return go;
            }
            else if (thing.ContainsKey(name))
            {
                Racer go = Racer.cloneShip(thing[name]);
                go.position = position;
                go.velocity = velocity;
                return go;
            }

            Console.WriteLine("Proto.getRacer() failed!");
            return null;
        }
示例#4
0
 /// <summary>
 /// Construct a bullet with default attributes.
 /// </summary>
 public Bullet()
 {
     rateL = 50f;
     rateR = 1f;
     dragL = 0f;
     dragR = 0f;
     lastPosition = position;
 }
示例#5
0
 // Behaviors
 public Weapon()
 {
     fireFrom = new Coords();
     bullet = new Bullet();
     bullet.damage = 10;
     bullet.timeToLive = 5;
     bullet.mass = 5;
 }
示例#6
0
 public FBXModel(string filename, string effect, float scale)
     : base(GammaDraconis.GetInstance())
 {
     this.filename = filename;
     this.scale = scale;
     shader = effect;
     offset = new Coords();
     GammaDraconis.GetInstance().Components.Add(this);
 }
示例#7
0
        public Track(Coords[] points, bool loop)
        {
            this.loop = loop;
            path = new List<Coords>();

            foreach (Coords point in points)
            {
                path.Add(point);
            }
        }
示例#8
0
        public GameObject()
        {
            position = new Coords();
            velocity = new Coords();
            acceleration = new Coords();

            models = new List<FBXModel>();
            mounts = new List<MountPoint>();
            turrets = new List<Turret>();

            relationalScale = 1.0f;
            relativeLookAt = new Vector3(0f, 0f, -1f);
            relativeLookFrom = new Vector3(0f, 0f, 0f);
        }
示例#9
0
        /// <summary>
        /// Construct a player at the specified PlayerIndex.
        /// </summary>
        /// <param name="index">The player's PlayerIndex.</param>
        public Player(PlayerIndex index)
            : base()
        {
            this.index = index;

            input = GammaDraconis.GetInstance().InputManager.GetPlayerInput(index);
            camera = new Coords();
            viewport = (Renderer.Viewports)index;
            Player.players[(int)index] = this;

            arrow = Proto.getThing("CheckpointArrow", new Coords());
            
            playerHUD = (Interface)GammaDraconis.GetInstance().GameLua.DoString("playerHudIndex = " + ((int)index + 1) + "\nreturn dofile( 'Interfaces/PlayerHUD/PlayerHUD.lua' )")[0];

            dust = new List<GameObject>();

            explosion = new Explosion();
            explosion.size = 2f;
            explosion.particles = 50;
        }
示例#10
0
 public Turret()
 {
     location = new Coords();
     mounts = new List<MountPoint>();
 }
示例#11
0
        /// <summary>
        /// Handle death, input, and dust.
        /// </summary>
        /// <param name="gameTime">The current time.</param>
        public override void think(GameTime gameTime)
        {
            playerHUD.Update(gameTime);

            #region Death handling
            if (health <= 0 && !dead)
            {
                dead = true;
                velocity = new Coords();
                deathTimer = 2000;
                
                OnDeath();
                Engine.GetInstance().gameScene.ignore(this);
                foreach (FBXModel model in models)
                {
                    model.visible = false;
                }
                shieldModel.visible = false;
                Engine.GetInstance().gameScene.track(this, GO_TYPE.THINKABLE);
            }

            if (dead)
            {
                deathTimer -= gameTime.ElapsedGameTime.Milliseconds;

                if (deathTimer <= 0)
                {
                    dead = false;
                    health = maxHealth;
                    shield = maxShield;
                    position = Engine.GetInstance().race.checkpoint(this, 0).position.Clone();
                    invulnerabilityTimer = 2 + gameTime.ElapsedRealTime.TotalSeconds;

                    Engine.GetInstance().gameScene.ignore(this);
                    foreach (FBXModel model in models)
                    {
                        model.visible = true;
                    }
                    Engine.GetInstance().gameScene.track(this, GO_TYPE.PLAYER);
                }
                else
                {
                    base.think(gameTime);
                    return;
                }
            }
            #endregion

            #region Invulnerability Timer
            if (invulnerabilityTimer > 0)
            {
                invincible = true;
                invulnerabilityTimer -= gameTime.ElapsedRealTime.TotalSeconds;
            }
            else
            {
                invincible = false;
            }
            #endregion

            #region Keyboard input handling
            if (input.inputDown("Up"))
            {
                pitch(1);
            }
            if (input.inputDown("Down"))
            {
                pitch(-1);
            }
            if (input.inputDown("Left"))
            {
                yaw(-1);
            }
            if (input.inputDown("Right"))
            {
                yaw(1);
            }
            if (input.inputDown("RollLeft"))
            {
                roll(-1);
            }
            if (input.inputDown("RollRight"))
            {
                roll(1);
            }

            if (input.inputDown("ThrottleUp"))
            {
                throttle(1);
            }
            if (input.inputDown("ThrottleDown"))
            {
                throttle(-1);
            }
            if (input.inputDown("Reset"))
            {
                health = 0;
            }
            if (input.inputPressed("Pause"))
            {
                Engine.GetInstance().enginePaused = !Engine.GetInstance().enginePaused;
            }
            if(input.inputPressed("Menu"))
            {
                Audio.stopAll();
                Audio.play("ambience");
                GammaDraconis.GetInstance().changeState(GammaDraconis.GameStates.MainMenu);
            }
            #endregion

            #region Gamepad input handling
            {
                pitch(input.axis("Pitch"));
                turn(input.axis("Turn"));
                roll(input.axis("Roll"));
                yaw(input.axis("Yaw"));

                throttle(input.axis("Throttle"));

                // Rotate the camera around the player
                camera.R = Quaternion.CreateFromYawPitchRoll((float)Math.PI * input.axis("CameraX"), (float)Math.PI * -input.axis("CameraY"), 0f);
            }
            #endregion

            #region Controller-independent handling
            {
                if (input.inputDown("Fire1"))
                {
                    firePrimary();
                }
				if (input.inputDown("Fire2"))
				{
					fireSecondary();
				}
            }
            #endregion

            #region It's getting dusty in here
            Vector3 pos = position.pos();
            Matrix m = position.matrix();

            float dist = 1f * dustDistance;
            float dist2 = 0.5f * dustDistance;
            float distZ = dustDistance * 0.8f;

            foreach (GameObject dusto in dust)
            {
                if (Vector3.Distance(pos, dusto.position.pos()) > dustDistance)
                {
                    float fx = (float)random.NextDouble() * dist - dist2;
                    float fy = (float)random.NextDouble() * dist - dist2;

                    dusto.position.T = Matrix.CreateTranslation(fx, fy, -distZ) * m;
                }

            }
            #endregion

            base.think(gameTime);
        }
示例#12
0
        /// <summary>
        /// Render a scene in the entire window from an arbirtrary vantage point.
        /// </summary>
        /// <param name="gameTime">Game time</param>
        /// <param name="scene">The scene manager</param>
        /// <param name="coords">The position to view the scene from</param>
        public void render(GameTime gameTime, Scene scene, Coords coords)
        {
            game.GraphicsDevice.Viewport = viewports[(int)Viewports.WholeWindow];
            game.GraphicsDevice.Clear(ClearOptions.DepthBuffer | ClearOptions.Target, Color.Black, 1.0f, 0);
            game.GraphicsDevice.RenderState.DepthBufferEnable = true;
            aspectRatio = game.GraphicsDevice.Viewport.AspectRatio;

            renderBloom = false;

            List<GameObject> gameObjects = scene.visible(coords, null);
            renderObjects(gameObjects, coords.camera(), null);

            // TODO: Render post-process shaders
            if (enableShaders)
            {
                renderBloom = true;
                bloomShader.Reset();

                renderObjects(gameObjects, coords.camera(), null);

                bloomShader.Render();
            }
        }
示例#13
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);
            }
        }
示例#14
0
 /// <summary>
 /// Explode an explosion.
 /// </summary>
 /// <param name="spot">The starting point for the explosion.</param>
 public void explode(Coords spot)
 {
     explode(spot, new Coords());
 }
示例#15
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;
        }
示例#16
0
 /// <summary>
 /// Get a prototype clone with given name, position, and velocity.
 /// </summary>
 /// <param name="name">Prototype name</param>
 /// <param name="position">New position</param>
 /// <param name="velocity">New velocity</param>
 /// <returns></returns>
 public static GameObject getThing(string name, Coords position, Coords velocity)
 {
     if (thing.ContainsKey(name))
     {
         GameObject go = thing[name].clone();
         go.position = position;
         go.velocity = velocity;
         return go;
     }
     else
     {
         return null;
     }
 }
示例#17
0
 /// <summary>
 /// Get a prototype clone with given name and position.
 /// </summary>
 /// <param name="name">Prototype name</param>
 /// <param name="position">New position</param>
 /// <returns></returns>
 public static Racer getRacer(string name, Coords position)
 {
     return getRacer(name, position, new Coords());
 }
示例#18
0
 /// <summary>
 /// 
 /// </summary>
 /// <returns>Where the viewport is looking from</returns>
 public Coords getCamera()
 {
     Coords c = new Coords();
     c.R = position.R * camera.R;
     c.T = Matrix.CreateTranslation(relativeLookFrom) * Matrix.Invert(Matrix.CreateFromQuaternion(velocity.R)) * Matrix.CreateFromQuaternion(camera.R) * Matrix.CreateFromQuaternion(position.R) * position.T * Matrix.CreateTranslation(velocity.pos() * -0.4f);
     return c;
 }
示例#19
0
 /// <summary>
 /// Get a prototype clone with given name and position.
 /// </summary>
 /// <param name="name">Prototype name</param>
 /// <param name="position">New position</param>
 /// <returns></returns>
 public static GameObject getThing(string name, Coords position)
 {
     return getThing(name, position, new Coords());
 }
示例#20
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 public MountPoint()
 {
     location = new Coords();
 }