コード例 #1
0
        private bool CheckInteractables(GameObject source, ref BoundingBox boundingBox, Vector3 lookVector)
        {
            bool failMove = false;

            // Check against all the interactive objects
            foreach (GameObject target in CurrentLevel.Collidables)
            {
                IActivatable activatable = target as IActivatable;

                if (activatable == null)
                    continue;

                if (!boundingBox.Intersects (TryGetOrStoreBox (target)))
                {
                    if (source.Tracking.Contains (target.ID))
                    {
                        activatable.Deactivate (source);
                        source.Tracking.Remove (target.ID);
                    }

                    continue;
                }

                activatable.Activate (source, lookVector);
                source.Tracking.Add (target.ID);

                if (target.Dense)
                    failMove = true;
            }

            return failMove;
        }
コード例 #2
0
 public ButtonObject CreateButton(Vector3 location, GameObject target, Action action)
 {
     return new ButtonObject
     {
         ID = ++currentID,
         Mesh = Engine.ContentLoader.Load<Model> ("Button"),
         Translation = location,
         Targets = new List<GameObject> (new [] { target }),
         Action = action
     };
 }
コード例 #3
0
        public void Deactivate(GameObject deactivator)
        {
            if (!Children.Contains (deactivator.ID))
                return;

            if ((DateTime.Now - lastButtonSoundPlayed).TotalSeconds > secondSoundDelay)
            {
                Engine.ContentLoader.Load<SoundEffect> (Path.Combine ("Sound", "Button")).Play (1f, 1f, 0f);
                lastButtonSoundPlayed = DateTime.Now;
            }
            this.Translation.Y += downSunkAmount;
            this.Active = false;

            PerformActionOnTargets (o => o.Deactivate (this));
            Children.Remove (deactivator.ID);
        }
コード例 #4
0
        public Level(string model, bool flipLevel)
        {
            stateHistory = new StateHistory();
            GameObjects = new List<GameObject>();
            Collidables = new List<GameObject> ();
            CollisionGeometry = new List<Collidable> ();

            if (!string.IsNullOrEmpty (model))
            {
                this.levelModel = model;
                levelObject = CreateLevel(flipLevel);
                GameObjects.Add (levelObject);
            }

            collision = Engine.ContentLoader.Load<Texture2D> ("LevelOneCollision");
            Colors = new Color[collision.Width * collision.Height];
            collision.GetData (Colors);
        }
コード例 #5
0
        public void Deactivate(GameObject deactivator)
        {
            if (!(deactivator is ButtonObject))
                return;

            activatedCount--;

            if (activatedCount >= buttonTargetedCount || !this.Active)
                return;

            Translation.Y += downSunkAmount;

            timePassed = 0;
            lerping = true;

            this.Dense = true;
            this.Active = false;
        }
コード例 #6
0
        public void Activate(GameObject activator, Vector3 heading)
        {
            if (Active || Children.Contains (activator.ID))
                return;

            if ((DateTime.Now - lastButtonSoundPlayed).TotalSeconds > secondSoundDelay)
            {
                Engine.ContentLoader.Load<SoundEffect> (Path.Combine ("Sound", "Button")).Play (1f, 1f, 0f);
                lastButtonSoundPlayed = DateTime.Now;
            }
            this.Translation.Y -= downSunkAmount;
            this.Active = true;

            if (!firstActivate)
            {
                if (Action != null) Action ();
                firstActivate = true;
            }

            PerformActionOnTargets (o => o.Activate (this, Vector3.Zero));
            Children.Add (activator.ID);
        }
コード例 #7
0
        public void Activate(GameObject activator, Vector3 heading)
        {
            if (!(activator is ButtonObject))
                return;

            activatedCount++;

            if (activatedCount < buttonTargetedCount)
                return;

            if ((DateTime.Now - lastButtonSoundPlayed).TotalSeconds > secondSoundDelay)
            {
                Engine.ContentLoader.Load<SoundEffect> (Path.Combine ("Sound", "Door")).Play ();
                lastButtonSoundPlayed = DateTime.Now;
            }

            Translation.Y -= downSunkAmount;

            timePassed = 0;
            lerping = true;
            this.Dense = false;

            this.Active = true;
        }
コード例 #8
0
        private bool HasObjectChanged(GameObject gameObject, Snapshot full)
        {
            // No previous snapshot so it obviously changed
            if (full == null || !full.GameObjects.ContainsKey(gameObject.ID))
                return true;

            var oldObject = full.GameObjects[gameObject.ID];

            if (gameObject.Translation != oldObject.Translation)
                return true;

            return false;
        }
コード例 #9
0
 public ButtonObject CreateButton(Vector3 location, GameObject target)
 {
     return this.CreateButton (location, target, null);
 }
コード例 #10
0
 public void SetAtSpawn(GameObject gameObject)
 {
     gameObject.Translation = StartPoint;
 }
コード例 #11
0
        public GameObject CreateLevel(bool flip)
        {
            GameObject level = new GameObject
            {
                ID = ++currentID,
                Mesh = Engine.ContentLoader.Load<Model> (levelModel),
                Translation = new Vector3 (0, 0, 0),
                Rotation = flip ? new Vector3(0, (float)Math.PI, 0) : new Vector3 (0, 0, 0)
            };

            BB = UpdateBoundingBox (level.Mesh, Matrix.Identity);
            level.Translation += new Vector3 ((BB.Max.X - BB.Min.X) / 2, 0, (BB.Max.Z - BB.Min.Z) / 2);

            return level;
        }
コード例 #12
0
        public override void Activate()
        {
            if (!isloaded)
                Load();

            generationCount = 0;

            camera.Target = CurrentLevel.levelObject;
            GameObject start = new GameObject();
            start.Translation = CurrentLevel.StartPoint;
            camera.Target = start;

            if (CurrentLevel != null)
                CurrentLevel.Activate();
        }
コード例 #13
0
        public void MoveObject(GameObject obj, GameObject.Direction direction)
        {
            Vector3 lookVector = obj.lastHeading = GetLookVectorFromDirection (direction);
            Vector3 moveAmount = (lookVector * camera.MoveOffset) * 0.9f;
            Vector3 newLocation = CurrentLevel.CurrentCharacter.Translation + moveAmount;

            // Get data needed for the four corners
            BoundingBox bb = CurrentLevel.UpdateBoundingBox (CurrentLevel.CurrentCharacter.Mesh, Matrix.CreateScale(CurrentLevel.CurrentCharacter.Scale));
            float modelWidth = bb.Max.X - bb.Min.X;
            float modelHeight = bb.Max.Z - bb.Min.Z;
            if (obj is PlayerObject)
            {
                PlayerObject po = obj as PlayerObject;
                Vector3 pos, neg;
                switch (direction)
                {
                    case GameObject.Direction.North:
                        po.SphereRotation.X += camera.MoveOffset;

                        pos = new Vector3(0.0f, 0.0f, 0.0f);
                        neg = new Vector3(0.0f, 0.0f, 0.0f);
                        if((pos - po.Rotation).Length() < (neg - po.Rotation).Length())
                            po.Rotation = Vector3.SmoothStep(po.Rotation, pos, 0.05f);
                        else
                            po.Rotation = Vector3.SmoothStep(po.Rotation, neg, 0.05f);
                        break;
                    case GameObject.Direction.South:
                        po.SphereRotation.X -= camera.MoveOffset;

                        pos = new Vector3(0.0f, MathHelper.ToRadians(180.0f), 0.0f);
                        neg = new Vector3(0.0f, -MathHelper.ToRadians(180.0f), 0.0f);
                        if((pos - po.Rotation).Length() < (neg - po.Rotation).Length())
                            po.Rotation = Vector3.SmoothStep(po.Rotation, pos, 0.05f);
                        else
                            po.Rotation = Vector3.SmoothStep(po.Rotation, neg, 0.05f);
                        break;
                    case GameObject.Direction.East:
                        po.SphereRotation.Z -= camera.MoveOffset;

                        po.Rotation = Vector3.SmoothStep(po.Rotation, new Vector3(0.0f, MathHelper.ToRadians(90.0f), 0.0f), 0.05f);
                        break;
                    case GameObject.Direction.West:
                        po.SphereRotation.Z += camera.MoveOffset;

                        po.Rotation = Vector3.SmoothStep(po.Rotation, new Vector3(0.0f, MathHelper.ToRadians(-90.0f), 0.0f), 0.05f);
                        break;
                    default:
                        break;
                }
            }

            // Reenable this!
               // Vector2 collisionLocation = CurrentLevel.WorldToTexel (newLocation);

            Collidable playerCollidable = new Collidable (
                newLocation.X - (modelWidth / 2f),
                newLocation.Z - (modelHeight / 2f),
                newLocation.X + (modelWidth / 2f),
                newLocation.Z + (modelHeight / 2f));

            Collidable sourceCollidable = new Collidable (
                 CurrentLevel.CurrentCharacter.Translation.X - (modelWidth / 2f),
                 CurrentLevel.CurrentCharacter.Translation.Z - (modelHeight / 2f),
                 CurrentLevel.CurrentCharacter.Translation.X + (modelWidth / 2f),
                 CurrentLevel.CurrentCharacter.Translation.Z + (modelHeight / 2f));

            foreach (Collidable collideGeometry in CurrentLevel.CollisionGeometry)
            {
                if (collideGeometry.Bounds.Intersects (playerCollidable.Bounds))
                {
                    if (collideGeometry.Dense)
                        return;
                }
            }

            if (CheckInteractables (CurrentLevel.CurrentCharacter, ref playerCollidable.Bounds, ref sourceCollidable.Bounds, lookVector))
                return;

            if (CurrentLevel.CurrentCharacter != null)
                CurrentLevel.CurrentCharacter.Translation = newLocation;
        }
コード例 #14
0
        public Vector3 GetLookVectorFromDirection(GameObject.Direction direction)
        {
            switch (direction)
            {
                case GameObject.Direction.North:
                    return new Vector3 (camera.World.Forward.X, 0f, camera.World.Forward.Z);
                case GameObject.Direction.South:
                    return -new Vector3 (camera.World.Forward.X, 0f, camera.World.Forward.Z);
                case GameObject.Direction.East:
                    return new Vector3 (camera.World.Left.X, 0f, camera.World.Left.Z);
                case GameObject.Direction.West:
                    return new Vector3 (camera.World.Right.X, 0f, camera.World.Right.Z);
            }

            return Vector3.Zero;
        }
コード例 #15
0
        public void DrawGameObject(GameObject obj, Matrix? proj = null, Matrix? view = null)
        {
            if (obj.Mesh == null)
                return;

            if (obj is PlayerObject)
            {
                PlayerObject po = obj as PlayerObject;
                Matrix[] transforms = new Matrix[obj.Mesh.Bones.Count];
                obj.Mesh.CopyAbsoluteBoneTransformsTo(transforms);

                foreach (ModelMesh m in obj.Mesh.Meshes)
                {
                    foreach (BasicEffect effect in m.Effects)
                    {
                        effect.EnableDefaultLighting();
                        effect.World = transforms[m.ParentBone.Index] *
                            Matrix.CreateScale(obj.Scale) *
                            Matrix.CreateRotationX(obj.Rotation.X) * Matrix.CreateRotationY(obj.Rotation.Y) * Matrix.CreateRotationZ(obj.Rotation.Z) *
                            Matrix.CreateTranslation(obj.Translation + new Vector3(0.0f, -0.7f, 0.0f));
                        effect.View = view ?? camera.View;
                        effect.Projection = proj ?? projection;
                    }
                    m.Draw();
                }

                transforms = new Matrix[po.Sphere.Bones.Count];
                po.Sphere.CopyAbsoluteBoneTransformsTo(transforms);

                foreach (ModelMesh m in po.Sphere.Meshes)
                {
                    foreach (BasicEffect effect in m.Effects)
                    {
                        effect.EnableDefaultLighting();
                        effect.World = transforms[m.ParentBone.Index] *
                            Matrix.CreateScale(obj.Scale) *
                            Matrix.CreateRotationZ(po.SphereRotation.Z) * Matrix.CreateRotationX(po.SphereRotation.X) * Matrix.CreateRotationY(po.SphereRotation.Y) *
                            Matrix.CreateTranslation(obj.Translation);
                        effect.View = view ?? camera.View;
                        effect.Projection = proj ?? projection;
                    }
                    m.Draw();
                }
            }
            else
            {
                Matrix[] transforms = new Matrix[obj.Mesh.Bones.Count];
                obj.Mesh.CopyAbsoluteBoneTransformsTo(transforms);

                foreach (ModelMesh m in obj.Mesh.Meshes)
                {
                    foreach (BasicEffect effect in m.Effects)
                    {
                        effect.EnableDefaultLighting();
                        effect.World = transforms[m.ParentBone.Index] *
                            Matrix.CreateScale(obj.Scale) *
                            Matrix.CreateRotationX(obj.Rotation.X) * Matrix.CreateRotationY(obj.Rotation.Y) * Matrix.CreateRotationZ(obj.Rotation.Z) *
                            Matrix.CreateTranslation(obj.Translation);
                        effect.View = camera.View;
                        effect.Projection = projection;
                    }
                    m.Draw();
                }
            }
        }
コード例 #16
0
        private BoundingBox TryGetOrStoreBox(GameObject source)
        {
            if (bbTracker.ContainsKey (source.ID))
                return bbTracker[source.ID].Bounds;

            bbTracker.Add (source.ID, new BBContainer(source.GetCurrentBoundingBox ()));
            return bbTracker[source.ID].Bounds;
        }