예제 #1
0
        //See MenuManager::EventDispatcher_MenuChanged to see how it does the reverse i.e. they are mutually exclusive
        protected override void EventDispatcher_MenuChanged(EventData eventData)
        {
            //did the event come from the main menu and is it a start game event
            if (eventData.EventType == EventActionType.OnStart)
            {
                EventDispatcher.Publish(new EventData(EventActionType.OnNonePicked, EventCategoryType.ObjectPicking));
                //turn on update and draw i.e. hide the menu
                this.StatusType = StatusType.Update | StatusType.Drawn;
            }
            //did the event come from the main menu and is it a start game event
            else if (eventData.EventType == EventActionType.OnPause)
            {
                EventDispatcher.Publish(new EventData(EventActionType.OnObjectPicked, EventCategoryType.ObjectPicking));
                //turn off update and draw i.e. show the menu since the game is paused
                this.StatusType = StatusType.Off;

                foreach (Actor2D actor in this.drawList)
                {
                    if (actor.ID == "picking mouseObject")
                    {
                        this.StatusType = StatusType.Update | StatusType.Drawn;
                    }
                }
            }
        }
예제 #2
0
        public override void Update(GameTime gameTime, IActor actor)
        {
            PlayerObject parentActor = actor as PlayerObject;

            this.totalTimeOnIce += gameTime.ElapsedGameTime.Milliseconds;


            if (this.totalTimeOnIce % 1000 == 0)
            {
                this.slipChance++;
                this.randomNum = this.rnd.Next(3, 8);
                if (this.randomNum < this.slipChance)
                {
                    //set the driveable controller on the player to be paused
                    parentActor.SetControllerPlayStatus(PlayStatusType.Pause,
                                                        controller => controller.GetControllerType() == ControllerType.Drive);
                    //reset slipChance
                    this.slipChance = 0;
                    //publish event that the player is slipping now
                    EventDispatcher.Publish(new EventData(EventActionType.OnSlip, EventCategoryType.Obstacle));
                    //start counting timer on slipping
                    this.totalTimeSlipping += gameTime.ElapsedGameTime.Milliseconds;

                    if (this.totalTimeSlipping % 4000 == 0)
                    {
                        //set the driveable controller on the player to be played again after 4 sec
                        parentActor.SetControllerPlayStatus(PlayStatusType.Play,
                                                            controller => controller.GetControllerType() == ControllerType.Drive);
                    }
                }
            }

            base.Update(gameTime, actor);
        }
예제 #3
0
 public override void Publish()
 {
     foreach (EventData eventData in this.eventDataList)
     {
         EventDispatcher.Publish(eventData);
     }
 }
예제 #4
0
        public void ShowMenu()
        {
            //show the menu by setting pause to false
            bPaused = false;
            game.soundManager.StopCue("background", Microsoft.Xna.Framework.Audio.AudioStopOptions.Immediate);
            game.soundManager.StopCue("phoneRing", Microsoft.Xna.Framework.Audio.AudioStopOptions.Immediate);
            game.soundManager.StopCue("footsteps", Microsoft.Xna.Framework.Audio.AudioStopOptions.Immediate);
            game.soundManager.StopCue("clock", Microsoft.Xna.Framework.Audio.AudioStopOptions.Immediate);
            game.soundManager.StopCue("music", Microsoft.Xna.Framework.Audio.AudioStopOptions.Immediate);
            game.soundManager.StopCue("phoneconversation1", Microsoft.Xna.Framework.Audio.AudioStopOptions.Immediate);
            game.soundManager.StopCue("phoneconversation2", Microsoft.Xna.Framework.Audio.AudioStopOptions.Immediate);
            game.soundManager.StopCue("phoneconversation3", Microsoft.Xna.Framework.Audio.AudioStopOptions.Immediate);
            game.soundManager.StopCue("phoneconversation4", Microsoft.Xna.Framework.Audio.AudioStopOptions.Immediate);
            game.soundManager.PlayCue("menu");
            //to do generate an event to tell the object manager to pause...
            EventDispatcher.Publish(new EventData("pause",
                                                  this, EventActionType.OnPause,
                                                  EventCategoryType.MainMenu));


            //if the mouse is invisible then show it
            if (!this.game.IsMouseVisible)
            {
                this.game.IsMouseVisible = true;
            }
        }
예제 #5
0
        /********************************************************************************************/

        //this is where you write the application specific CDCR response for your game
        protected override void HandleCollisionResponse(Actor collidee)
        {
            if (collidee is CollidableZoneObject zone)
            {
                if (zone.ActorType == ActorType.WinZone)
                {
                    EventDispatcher.Publish(new EventData(EventCategoryType.GameState, EventActionType.OnWin, null));
                }

                Collidee = null;
            }
            else if (collidee is CollidablePrimitiveObject obstacle)
            {
                if (collidee.ActorType == ActorType.Obstacle || collidee is CollidableProjectile)
                {
                    Die();
                }
                else if (collidee.ActorType == ActorType.CollidablePickup)
                {
                    EventDispatcher.Publish(new EventData(EventCategoryType.GameState, EventActionType.OnStarPickup, null));
                    EventDispatcher.Publish(new EventData(EventCategoryType.Object, EventActionType.OnRemoveActor, new [] { collidee }));
                    Collidee = null;
                }
            }
        }
예제 #6
0
        /// <summary>
        /// Checks what tile is directly underneath the player and performs an action based on it.
        /// This is called directly after the player's move has finished.
        /// </summary>
        private void CheckGround()
        {
            Actor3D newGround = CheckCollisionAfterTranslation(-Vector3.UnitY) as Actor3D;

            if (newGround == null)
            {
                //No ground detected --> player dies (Water tiles have no collision, so water will kill the player too)
                EventDispatcher.Publish(new EventData(EventCategoryType.Tween, EventActionType.OnAdd, new []
                {
                    new TranslationTween(this, 200, new Vector3(0, -2, 0),
                                         true, actor3D => Die())
                }));
                return;
            }

            //Correcting the X and Y position of the player
            Transform3D groundTransform = newGround.Transform3D;
            Vector3     position        = new Vector3(groundTransform.Translation.X, Transform3D.Translation.Y, groundTransform.Translation.Z);

            Transform3D.Translation = position;

            if (newGround.ActorType == ActorType.WaterPlatform)
            {
                Vector3 platformTrans = (newGround as Actor3D).Transform3D.Translation;
                Transform3D.Translation = new Vector3(platformTrans.X, Transform3D.Translation.Y, platformTrans.Z);
                EventDispatcher.Publish(new EventData(EventCategoryType.Tween, EventActionType.OnAddChild, new [] { newGround as Actor3D, this }));
            }

            //Update the ground
            ground = newGround;
        }
예제 #7
0
        private void HideMenu()
        {
            //hide the menu by setting pause to true
            bPaused = true;
            this.game.CameraManager.ActiveCamera.StatusType = StatusType.Updated | StatusType.Drawn;

            game.soundManager.StopCue("menu", Microsoft.Xna.Framework.Audio.AudioStopOptions.Immediate);
            game.soundManager.PlayCue("background");

            if (!game.keyCreated)
            {
                game.soundManager.PlayCue("phoneRing");
            }

            //to do generate an event to tell the object manager to pause...
            EventDispatcher.Publish(new EventData("play",
                                                  this, EventActionType.OnPlay,
                                                  EventCategoryType.MainMenu));



            //if the mouse is invisible then show it
            if (this.game.IsMouseVisible)
            {
                this.game.IsMouseVisible = false;
            }

            this.game.MouseManager.SetPosition(this.game.ScreenCentre);
        }
예제 #8
0
        private void Move()
        {
            if (!isMoving && moveDir != Vector3.Zero)
            {
                //check if the player's path is blocked
                Actor obstacleCheck = CheckCollisionAfterTranslation(moveDir);
                if (obstacleCheck != null && (obstacleCheck.ActorType == ActorType.BlockingObstacle || obstacleCheck.ActorType == ActorType.Shooter))
                {
                    return;
                }

                //we are currently on a water platform --> detach from it
                if (ground != null && ground.ActorType == ActorType.WaterPlatform)
                {
                    EventDispatcher.Publish(new EventData(EventCategoryType.Tween, EventActionType.OnRemoveChild, new[] { ground as Actor3D, this }));
                }

                //Jump Animation
                TranslationTween jumpDown = new TranslationTween(this, GameConstants.Player_MovementTimeInMs / 2,
                                                                 moveDir / 2 - Vector3.Up, true,
                                                                 MovementCallback, LoopType.PlayOnce, EasingType.easeOut);

                TranslationTween jumpUp = new TranslationTween(this, GameConstants.Player_MovementTimeInMs / 2,
                                                               moveDir / 2 + Vector3.Up, true,
                                                               actor3D => EventDispatcher.Publish(new EventData(EventCategoryType.Tween, EventActionType.OnAdd, new [] { jumpDown })),
                                                               LoopType.PlayOnce, EasingType.easeOut);

                EventDispatcher.Publish(new EventData(EventCategoryType.Tween, EventActionType.OnAdd, new object[] { jumpUp }));
                EventDispatcher.Publish(new EventData(EventCategoryType.Sound, EventActionType.OnPlay3D, new object[] { "jump", Transform3D }));
                isMoving = true;
            }
        }
예제 #9
0
        public override void Update(GameTime gameTime, IActor actor)
        {
            if (paused == false)
            {
                this.parentUITextureActor = actor as UITextureObject;
                //set the source rectangle according to whatever start value the user supplies
                if (game.CameraManager.ActiveCamera.StatusType != 0)
                {
                    this.currentValue += incrementSpeed;

                    //if more then 100 Loose

                    if (this.currentValue >= 93)
                    {
                        EventDispatcher.Publish(new EventData("Lose", this, EventActionType.LoseGame, EventCategoryType.Interaction));
                        this.currentValue = 0;
                    }

                    if (this.currentValue < 0)
                    {
                        this.currentValue = 0;
                    }

                    if (incrementSpeed < 0.005f)
                    {
                        incrementSpeed = 0.005f;
                    }


                    UpdateSourceRectangle();
                }
            }
            base.Update(gameTime, actor);
        }
예제 #10
0
        private void CheckCollisions(GameTime gameTime)
        {
            Ray mouseRay = this.managerParameters.MouseManager.GetMouseRay(this.managerParameters.CameraManager.ActiveCamera);

            foreach (Actor3D actor in this.managerParameters.ObjectManager.OpaqueDrawList)
            {
                collidee = CheckCollision(gameTime, actor, mouseRay);

                if (collidee != null)
                {
                    HandleResponse(gameTime, collidee);
                    break; //if we collide then break and handle collision
                }
            }

            foreach (Actor3D actor in this.managerParameters.ObjectManager.TransparentDrawList)
            {
                collidee = CheckCollision(gameTime, actor, mouseRay);

                if (collidee != null)
                {
                    HandleResponse(gameTime, collidee);
                    break; //if we collide then break and handle collision
                }
            }

            //we're not over anything
            if (collidee == null)
            {
                //notify listeners that we're no longer picking
                object[] additionalParameters = { NoObjectSelectedText };
                EventDispatcher.Publish(new EventData(EventActionType.OnNonePicked, EventCategoryType.ObjectPicking, additionalParameters));
            }
        }
        protected override void HandleCollisionResponse(Actor collidee)
        {
            if (collidee == null)
            {
                return;
            }

            if (collidee.ActorType == ActorType.PC || collidee.ActorType == ActorType.BlockingObstacle || collidee.ActorType == ActorType.Obstacle)
            {
                EventDispatcher.Publish(new EventData(EventCategoryType.Tween, EventActionType.OnRemoveActor, new[] { this }));
                EventDispatcher.Publish(new EventData(EventCategoryType.Object, EventActionType.OnRemoveActor, new[] { this }));
            }
        }
예제 #12
0
        private void DoPickAndRemove(GameTime gameTime)
        {
            if (this.inputManagerParameters.MouseManager.IsLeftButtonClickedOnce())
            {
                this.camera = this.cameraManager.ActiveCamera;
                this.currentPickedObject = this.inputManagerParameters.MouseManager.GetPickedObject(camera, camera.ViewportCentre,
                                                                                                    this.pickStartDistance, this.pickEndDistance, out pos, out normal) as CollidableObject;

                if (this.currentPickedObject != null && IsValidCollision(currentPickedObject, pos, normal))
                {
                    //generate event to tell object manager and physics manager to remove the object
                    EventDispatcher.Publish(new EventData(this.currentPickedObject, EventActionType.OnRemoveActor, EventCategoryType.SystemRemove));
                }
            }
        }
예제 #13
0
        public override void Update(GameTime gameTime, IActor actor)
        {
            DrawnActor3D parentActor = actor as DrawnActor3D;

            //makes the object spin upwards and fade away after its alpha is lower than a threshold value
            parentActor.Transform.RotateAroundYBy(this.rotationRate);
            parentActor.Transform.TranslateBy(this.translationRate * gameTime.ElapsedGameTime.Milliseconds);
            parentActor.Transform.ScaleBy(this.scaleRate);
            parentActor.EffectParameters.Alpha += this.alphaDecayRate;

            //if alpha less than some threshold value then remove
            if (parentActor.EffectParameters.Alpha < this.alphaDecayThreshold)
            {
                EventDispatcher.Publish(new EventData(parentActor, EventActionType.OnRemoveActor, EventCategoryType.SystemRemove));
            }
        }
        //this is where you write the application specific CDCR response for your game
        protected override void HandleCollisionResponse(Actor collidee)
        {
            if (collidee is SimpleZoneObject)
            {
                if (collidee.ID.Equals(AppData.SwitchToThirdPersonZoneID))
                {
                    if (!bThirdPersonZoneEventSent) //add a boolean to stop the event being sent multiple times!
                    {
                        //publish some sort of event - maybe an event to switch the camera?
                        object[] additionalParameters = { AppData.ThirdPersonCameraID };
                        EventDispatcher.Publish(new EventData(EventActionType.OnCameraSetActive, EventCategoryType.Camera, additionalParameters));
                        bThirdPersonZoneEventSent = true;
                    }

                    //setting this to null means that the ApplyInput() method will get called and the player can move through the zone.
                    this.Collidee = null;
                }
            }
            else if (collidee is CollidablePrimitiveObject)
            {
                if (collidee.ActorType == ActorType.CollidableDecorator)
                {
                    //we dont HAVE to do anything here but lets change its color just to see something happen
                    (collidee as DrawnActor3D).EffectParameters.DiffuseColor = Color.Yellow;
                }

                //decide what to do with the thing you've collided with
                else if (collidee.ActorType == ActorType.CollidableAmmo)
                {
                    //do stuff...maybe a remove
                    EventDispatcher.Publish(new EventData(collidee, EventActionType.OnRemoveActor, EventCategoryType.SystemRemove));
                }

                //activate some/all of the controllers when we touch the object
                else if (collidee.ActorType == ActorType.CollidableActivatable)
                {
                    //when we touch get a particular controller to start
                    // collidee.SetAllControllers(PlayStatusType.Play, x => x.GetControllerType().Equals(ControllerType.SineColorLerp));

                    //when we touch get a particular controller to start
                    collidee.SetAllControllers(PlayStatusType.Play, x => x.GetControllerType().Equals(ControllerType.PickupDisappear));
                }
            }
        }
예제 #15
0
        protected void DisplayVolume()
        {
            string volume = "";

            if (SoundEffect.MasterVolume == 1)
            {
                volume = "Max";
            }
            else if (SoundEffect.MasterVolume == 0)
            {
                volume = "Mute";
            }
            else
            {
                volume = ((int)((SoundEffect.MasterVolume + 0.001f) * 100)).ToString();
            }
            string volumeText = ("Volume : " + volume);

            object[] VolumeText = { volumeText };
            EventDispatcher.Publish(new EventData(EventActionType.OnVolumeChange, EventCategoryType.MenuText, VolumeText));
        }
예제 #16
0
 protected override void HandleInput(GameTime gameTime)
 {
     #region Menu Handling
     //if user presses menu button then either show or hide the menu
     if (this.keyboardManager != null && this.keyboardManager.IsFirstKeyPress(this.pauseKey))
     {
         //if game is paused then publish a play event
         if (this.StatusType == StatusType.Off)
         {
             //will be received by the menu manager and screen manager and set the menu to be shown and game to be paused
             EventDispatcher.Publish(new EventData(EventActionType.OnStart, EventCategoryType.MainMenu));
         }
         //if game is playing then publish a pause event
         else if (this.StatusType != StatusType.Off)
         {
             //will be received by the menu manager and screen manager and set the menu to be shown and game to be paused
             EventDispatcher.Publish(new EventData(EventActionType.OnPause, EventCategoryType.MainMenu));
         }
     }
     #endregion
 }
예제 #17
0
        private void RestartGame()
        {
            //hide the menu by setting pause to true
            bPaused = true;

            //to do generate an event to tell the object manager to pause...
            EventDispatcher.Publish(new EventData("play",
                                                  this, EventActionType.OnPlay,
                                                  EventCategoryType.MainMenu));

            //send a restart message to re-load the game
            EventDispatcher.Publish(new EventData("restart",
                                                  this, EventActionType.OnRestart,
                                                  EventCategoryType.MainMenu));


            //if the mouse is invisible then show it
            if (this.game.IsMouseVisible)
            {
                this.game.IsMouseVisible = false;
            }
        }
예제 #18
0
        //See MenuManager::EventDispatcher_MenuChanged to see how it does the reverse i.e. they are mutually exclusive
        protected override void EventDispatcher_MenuChanged(EventData eventData)
        {
            //did the event come from the main menu and is it a start game event
            if (eventData.EventType == EventActionType.OnStart)
            {
                //turn on update and draw i.e. hide the menu
                this.StatusType = StatusType.Update | StatusType.Drawn;

                //Resume Active Camera
                EventDispatcher.Publish(new EventData(EventActionType.OnCameraResume, EventCategoryType.Camera));

                //resume any active timers
                EventDispatcher.Publish(new EventData(EventActionType.OnResume, EventCategoryType.Timer));

                //UnPause Sound Effects
                //Sound effects must be paused as the player can just unmute them from the Audio Menu
                object[] sound = { "Lava" };
                EventDispatcher.Publish(new EventData(EventActionType.OnResume, EventCategoryType.Sound2D, sound));
            }
            //did the event come from the main menu and is it a start game event
            else if (eventData.EventType == EventActionType.OnPause)
            {
                //turn off update and draw i.e. show the menu since the game is paused
                this.StatusType = StatusType.Off;

                //pause Active Camera
                EventDispatcher.Publish(new EventData(EventActionType.OnCameraPause, EventCategoryType.Camera));

                //Pause any Active Timers
                EventDispatcher.Publish(new EventData(EventActionType.OnPause, EventCategoryType.Timer));

                //Pause Sound Effects
                //Lava is the only Sound effect needed to be paused as All other sound events will not be published when game is paused.
                //I also wanted the music to play during the menu
                object[] sound = { "Lava" };
                EventDispatcher.Publish(new EventData(EventActionType.OnPause, EventCategoryType.Sound2D, sound));
            }
        }
        public override void Update(GameTime gameTime, IActor actor)
        {
            UITextureObject parentActor = actor as UITextureObject;

            this.totalTime += gameTime.ElapsedGameTime.Milliseconds;
            this.count++;
            if (this.temperature <= 0)
            {
                this.isDead = true;
            }

            if (this.totalTime % 1000 == 0)
            {
                if (!this.isDead)
                {
                    this.temperature -= this.dropRate;
                    System.Console.WriteLine(this.temperature);
                    parentActor.Transform.Translation += new Vector2(0, (this.dropRate * 8));
                    parentActor.SourceRectangle        =
                        new Rectangle(parentActor.SourceRectangle.X,
                                      parentActor.SourceRectangle.Y + (int)(this.dropRate * 10),
                                      parentActor.SourceRectangle.Width,
                                      parentActor.SourceRectangle.Height - (int)(this.dropRate * 10));// TO DO CALCULATION - MATCH THE BAR WITH TEMP - must be double
                    if (temperature <= 10)
                    {
                        //publish low health event
                        EventDispatcher.Publish(new EventData("critical sound", EventActionType.OnHealthSet, EventCategoryType.LowTemp));
                    }
                }
                else
                {
                    //publish gameover event
                    EventDispatcher.Publish(new EventData("Dead By Frosbite!", EventActionType.OnLose, EventCategoryType.GameLost));
                }
            }

            base.Update(gameTime, actor);
        }
예제 #20
0
        public override void Update(GameTime gameTime, IActor actor)
        {
            DrawnActor2D parentActor = actor as DrawnActor2D;



            if (parentActor.Transform.Bounds.Intersects(this.mouseManager.Bounds))
            {
                TrigonometricParameters trig = new TrigonometricParameters(1, 0.1f);
                this.totalElapsedTime += gameTime.ElapsedGameTime.Milliseconds;

                float lerpFactor = MathUtility.Sin(trig, this.totalElapsedTime);

                parentActor.Color           = MathUtility.Lerp(Color.Red, Color.Blue, lerpFactor);
                parentActor.Transform.Scale = MathUtility.Lerp(parentActor.Transform.Scale * 0.999f, parentActor.Transform.Scale * 1.001f, lerpFactor);
                Console.WriteLine(parentActor.Transform.Scale);

                if (this.mouseManager.IsLeftButtonClicked())
                {
                    if (parentActor.ID.Equals("menu1"))
                    {
                        EventDispatcher.Publish(new EventData("options", null, EventActionType.OnNewMenu, EventCategoryType.Menu));
                    }
                    else if (parentActor.ID.Equals("exit1"))
                    {
                        exit = true;
                    }
                }
            }
            else
            {
                parentActor.Transform.Scale = parentActor.Transform.OriginalTransform2D.Scale;
                parentActor.Color           = parentActor.OriginalColor;
            }

            base.Update(gameTime, actor);
        }
예제 #21
0
        private void DoPickAndPlace(GameTime gameTime)
        {
            if (this.inputManagerParameters.MouseManager.IsMiddleButtonClicked())
            {
                if (!this.bCurrentlyPicking)
                {
                    this.camera = this.cameraManager.ActiveCamera;
                    this.currentPickedObject = this.inputManagerParameters.MouseManager.GetPickedObject(camera, camera.ViewportCentre,
                                                                                                        this.pickStartDistance, this.pickEndDistance, out pos, out normal) as CollidableObject;

                    this.distanceToObject = (float)Math.Round(Vector3.Distance(camera.Transform.Translation, pos), DefaultDistanceToTargetPrecision);

                    if (this.currentPickedObject != null && IsValidCollision(currentPickedObject, pos, normal))
                    {
                        Vector3 vectorDeltaFromCentreOfMass = pos - this.currentPickedObject.Collision.Owner.Position;
                        vectorDeltaFromCentreOfMass = Vector3.Transform(vectorDeltaFromCentreOfMass, Matrix.Transpose(this.currentPickedObject.Collision.Owner.Orientation));
                        cameraPickDistance          = (this.cameraManager.ActiveCamera.Transform.Translation - pos).Length();

                        //remove any controller from any previous pick-release
                        objectController.Destroy();
                        damperController.Destroy();

                        this.currentPickedObject.Collision.Owner.SetActive();
                        //move object by pos (i.e. point of collision and not centre of mass)
                        this.objectController.Initialise(this.currentPickedObject.Collision.Owner, vectorDeltaFromCentreOfMass, pos);
                        //dampen velocity (linear and angular) on object to Zero
                        this.damperController.Initialise(this.currentPickedObject.Collision.Owner, ConstraintVelocity.ReferenceFrame.Body, Vector3.Zero, Vector3.Zero);
                        this.objectController.EnableConstraint();
                        this.damperController.EnableConstraint();
                        //we're picking a valid object for the first time
                        this.bCurrentlyPicking = true;

                        //update mouse text
                        object[] additionalParameters = { currentPickedObject, this.distanceToObject };
                        EventDispatcher.Publish(new EventData(EventActionType.OnObjectPicked, EventCategoryType.ObjectPicking, additionalParameters));
                    }
                }

                //if we have an object picked from the last update then move it according to the mouse pointer
                if (objectController.IsConstraintEnabled && (objectController.Body != null))
                {
                    // Vector3 delta = objectController.Body.Position - this.managerParameters.CameraManager.ActiveCamera.Transform.Translation;
                    Vector3 direction = this.inputManagerParameters.MouseManager.GetMouseRay(this.cameraManager.ActiveCamera).Direction;
                    cameraPickDistance += this.inputManagerParameters.MouseManager.GetDeltaFromScrollWheel() * 0.1f;
                    Vector3 result = this.cameraManager.ActiveCamera.Transform.Translation + cameraPickDistance * direction;
                    //set the desired world position
                    objectController.WorldPosition = this.cameraManager.ActiveCamera.Transform.Translation + cameraPickDistance * direction;
                    objectController.Body.SetActive();
                }
            }
            else //releasing object
            {
                if (this.bCurrentlyPicking)
                {
                    //release object from constraints and allow to behave as defined by gravity etc
                    objectController.DisableConstraint();
                    damperController.DisableConstraint();

                    //notify listeners that we're no longer picking
                    object[] additionalParameters = { NoObjectSelectedText };
                    EventDispatcher.Publish(new EventData(EventActionType.OnNonePicked, EventCategoryType.ObjectPicking, additionalParameters));

                    this.bCurrentlyPicking = false;
                }
            }
        }
예제 #22
0
 private void Die()
 {
     EventDispatcher.Publish(new EventData(EventCategoryType.GameState, EventActionType.OnLose, null));
     EventDispatcher.Publish(new EventData(EventCategoryType.Object, EventActionType.OnRemoveActor, new object[] { this }));
 }
예제 #23
0
 public void Initialize()
 {
     //Notify the GameStateManager that the player has been spawned (used to set the target of the camera)
     EventDispatcher.Publish(new EventData(EventCategoryType.GameState, EventActionType.OnSpawn, new [] { this }));
 }
        public virtual void DoMousePick(GameTime gameTime)
        {
            if (game.CameraManager.ActiveCamera != null)
            {
                float   distance = 7;
                float   startDistance = 1; //if 1st person collidable then start picking outside CD/CR surface
                Vector3 pos, normal;

                //add code for mouse picking from the previous week....
                CollidableObject collidableObject = game.MouseManager.GetPickedObjectFromCenter(
                    game.CameraManager.ActiveCamera,
                    startDistance, distance, out pos, out normal) as CollidableObject;

                if (collidableObject != null) //&& (collidableObject.ActorType == ActorType.Pickup))
                {
                    this.Text = collidableObject.ID;

                    if (collidableObject.ActorType == ActorType.CollidableInteractableProp)
                    {
                        text += " : Interactable Object";
                        this.textDimensions        = this.spriteFont.MeasureString(this.text);
                        this.textOrigin            = new Vector2(this.textDimensions.X / 2, this.textDimensions.Y / 2);
                        textColor                  = Color.DeepPink;
                        this.Color                 = Color.DeepPink;
                        this.Transform2D.Rotation += 0.05f;

                        if (game.MouseManager.IsLeftButtonClickedOnce() || game.KeyboardManager.IsFirstKeyPress(Microsoft.Xna.Framework.Input.Keys.E))
                        {
                            //call event on interaction
                            // PickupCollidableObject pickupObject = collidableObject as PickupCollidableObject;
                            // EventDispatcher.Publish(pickupObject.EventParameters.EventData);
                            if (collidableObject.ID == "door" && game.playerHasKey)
                            {
                                EventDispatcher.Publish(new EventData("Locks Door", this, EventActionType.WinGame, EventCategoryType.Interaction));
                                collidableObject.ActorType = ActorType.Decorator;
                            }
                            if (collidableObject.ID == "phone")
                            {
                                EventDispatcher.Publish(new EventData("Phone", this, EventActionType.PhoneInteraction, EventCategoryType.Interaction));
                            }
                            if (collidableObject.ID == "clock")
                            {
                                EventDispatcher.Publish(new EventData("Clock", this, EventActionType.ClockInteraction, EventCategoryType.Interaction));
                            }
                            if (collidableObject.ID == "painting1")
                            {
                                EventDispatcher.Publish(new EventData("painting1", this, EventActionType.PaintingGoodInteraction, EventCategoryType.Interaction));
                                collidableObject.ActorType = ActorType.Decorator;
                            }
                            if (collidableObject.ID == "painting2")
                            {
                                EventDispatcher.Publish(new EventData("painting2", this, EventActionType.PaintingOtherInteraction, EventCategoryType.Interaction));
                                collidableObject.ActorType = ActorType.Decorator;
                            }
                            if (collidableObject.ID == "painting3")
                            {
                                EventDispatcher.Publish(new EventData("painting3", this, EventActionType.PaintingBadInteraction, EventCategoryType.Interaction));
                                collidableObject.ActorType = ActorType.Decorator;
                            }
                            if (collidableObject.ID == "kettle")
                            {
                                EventDispatcher.Publish(new EventData("Kettle", this, EventActionType.KettleInteraction, EventCategoryType.Interaction));
                                collidableObject.ActorType = ActorType.Decorator;
                            }
                            if (collidableObject.ID == "microwave")
                            {
                                EventDispatcher.Publish(new EventData("Microwave", this, EventActionType.MicrowaveInteraction, EventCategoryType.Interaction));
                                collidableObject.ActorType = ActorType.Decorator;
                            }
                            if (collidableObject.ID == "chair")
                            {
                                EventDispatcher.Publish(new EventData("Chair", this, EventActionType.ChairInteraction, EventCategoryType.Interaction));
                                collidableObject.ActorType = ActorType.Decorator;
                            }
                            if (collidableObject.ID == "toaster")
                            {
                                EventDispatcher.Publish(new EventData("Toaster", this, EventActionType.ToasterInteraction, EventCategoryType.Interaction));
                                collidableObject.ActorType = ActorType.Decorator;
                            }
                            if (collidableObject.ID == "fridge")
                            {
                                EventDispatcher.Publish(new EventData("Fridge", this, EventActionType.FridgeInteraction, EventCategoryType.Interaction));
                                collidableObject.ActorType = ActorType.Decorator;
                            }
                            if (collidableObject.ID == "oven")
                            {
                                EventDispatcher.Publish(new EventData("Oven", this, EventActionType.OvenInteraction, EventCategoryType.Interaction));
                                collidableObject.ActorType = ActorType.Decorator;
                            }
                            if (collidableObject.ID == "sink")
                            {
                                EventDispatcher.Publish(new EventData("Sink", this, EventActionType.SinkInteraction, EventCategoryType.Interaction));
                                collidableObject.ActorType = ActorType.Decorator;
                            }
                            if (collidableObject.ID == "mirror")
                            {
                                EventDispatcher.Publish(new EventData("Mirror", this, EventActionType.MirrorInteraction, EventCategoryType.Interaction));
                                collidableObject.ActorType = ActorType.Decorator;
                            }
                            if (collidableObject.ID == "toilet")
                            {
                                EventDispatcher.Publish(new EventData("Toilet", this, EventActionType.ToiletInteraction, EventCategoryType.Interaction));
                                collidableObject.ActorType = ActorType.Decorator;
                            }
                            if (collidableObject.ID == "radio")
                            {
                                EventDispatcher.Publish(new EventData("Radio", this, EventActionType.RadioInteraction, EventCategoryType.Interaction));
                            }
                            if (collidableObject.ID == "tv")
                            {
                                EventDispatcher.Publish(new EventData("Television", this, EventActionType.TVInteraction, EventCategoryType.Interaction));
                                collidableObject.ActorType = ActorType.Decorator;
                            }
                            if (collidableObject.ID == "remote")
                            {
                                EventDispatcher.Publish(new EventData("Remote", this, EventActionType.RemoteInteraction, EventCategoryType.Interaction));
                                collidableObject.ActorType = ActorType.Decorator;
                            }
                            if (collidableObject.ID == "winebottle")
                            {
                                EventDispatcher.Publish(new EventData("Vino", this, EventActionType.VinoInteraction, EventCategoryType.Interaction));
                                collidableObject.ActorType = ActorType.Decorator;
                            }
                        }
                    }
                    else if (collidableObject.ActorType == ActorType.Pickup)
                    {
                        text += " : Pickup";
                        this.textDimensions        = this.spriteFont.MeasureString(this.text);
                        this.textOrigin            = new Vector2(this.textDimensions.X / 2, this.textDimensions.Y / 2);
                        textColor                  = Color.Yellow;
                        this.Transform2D.Rotation -= 0.05f;
                        this.Color                 = Color.Yellow;
                        if (game.MouseManager.IsLeftButtonClickedOnce() || game.KeyboardManager.IsFirstKeyPress(Microsoft.Xna.Framework.Input.Keys.E))
                        {
                            if (collidableObject.ID == "key")
                            {
                                /* bool aniRun = true;
                                 * collidableObject.AttachController(new KeyPickupController("keyPick",
                                 *   ControllerType.KeyPickupController, new Vector3(0, .01f, 0),
                                 *   new Vector3(.01f, 0, .01f)));
                                 * long startTime = gameTime.ElapsedGameTime.Milliseconds;
                                 * long currentTime;
                                 * long endTime = startTime + 3500;
                                 * while (aniRun)
                                 * {
                                 *   currentTime = gameTime.ElapsedGameTime.Milliseconds;
                                 *   if (currentTime >= endTime)
                                 *   {
                                 *       aniRun = false;
                                 *       //collidableObject.DetachController("keyPick");
                                 *       game.ObjectManager.Remove(collidableObject);
                                 *
                                 *   }
                                 * }*/
                                game.ObjectManager.Remove(collidableObject);
                                EventDispatcher.Publish(new EventData("Has Key", this, EventActionType.PickUpKey, EventCategoryType.Interaction));
                                collidableObject.ActorType = ActorType.Decorator;
                            }

                            //call event on pickup
                            // PickupCollidableObject pickupObject = collidableObject as PickupCollidableObject;
                            // EventDispatcher.Publish(pickupObject.EventParameters.EventData);
                        }
                    }
                    else
                    {
                        text       = "";
                        textColor  = Color.White;
                        this.Color = Color.White;
                        this.Transform2D.Rotation = 0;
                        //do something when not colliding...
                    }
                }
                else
                {
                    text       = "";
                    textColor  = Color.White;
                    this.Color = Color.White;
                    this.Transform2D.Rotation = 0;
                    //do something when not colliding...
                }
            }
        }
예제 #25
0
 public override void Publish()
 {
     EventDispatcher.Publish(this.eventData);
 }