Exemplo n.º 1
0
 public ActorElement(Game game, int worldPositionXIn, int worldPositionYIn) : base(game, worldPositionXIn, worldPositionYIn)
 {
     elementName             = "Actor Element(Debug)";
     moving                  = false;
     stuck                   = false;
     idle                    = true;
     associatedMovementEvent = null;
     currentJob              = new Job();
 }
Exemplo n.º 2
0
 public void ReplaceLinkedMovement(EventMoveTo newMovementEvent)
 {
     if (moving)
     {
         moving = false;
         newMovementEvent.Suspend(associatedMovementEvent);
         associatedMovementEvent.ShutdownSmoothly();
         this.LinkToMoveEvent(newMovementEvent);
     }
     else
     {
         this.LinkToMoveEvent(newMovementEvent);
     }
 }
Exemplo n.º 3
0
 public void LinkToMoveEvent(EventMoveTo linkedMovement)
 {
     moving = true;
     associatedMovementEvent = linkedMovement;
 }
Exemplo n.º 4
0
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            //Update key presses
            inputManager.Update();

            //Check for key presses
            if (inputManager.EscapeButtonPressed())
            {
                Exit();
            }
            if (inputManager.SpawnTreeButtonReleased())
            {
                eventManager.AddEvent(new EventAddTrees(this, currentMap, 1, 1, 0));
            }
            if (inputManager.SpawnRockButtonReleased())
            {
                eventManager.AddEvent(new EventAddRocks(this, currentMap, 1));
            }

            //Check left mouse functions
            if (inputManager.LeftMouseButtonReleased())
            {
                if (inputManager.DragFinished())
                {
                    elementFocus.Clear();
                    currentMap.GetAllElementsInArea(elementFocus, inputManager.GetMouseDragStartTile(), inputManager.GetMouseDragEndTile());
                }
                else if (inputManager.MouseOverMap() && currentMap.getOccupied(inputManager.GetCurrentMouseTile(currentMap)))
                {
                    currentMap.getOccupyingElement(inputManager.GetCurrentMouseTile(currentMap)).UpdateCurrentHealth(5);
                    elementFocus.Clear();
                    elementFocus.Add(currentMap.getOccupyingElement(inputManager.GetCurrentMouseTile(currentMap)));
                }
                else if (uiManager.OverHarvestIcon(inputManager) && elementFocus.Count > 0)
                {
                    for (int i = 0; i < elementFocus.Count; i++)
                    {
                        if (elementFocus[i].GetMovable())
                        {
                            ((ActorElement)elementFocus[i]).SetJob(new GathererJob());
                        }
                    }
                }
                else if (uiManager.OverMineIcon(inputManager) && elementFocus.Count > 0)
                {
                    for (int i = 0; i < elementFocus.Count; i++)
                    {
                        if (elementFocus[i].GetMovable())
                        {
                            eventManager.AddEvent(new EventHarvestRocks(this, currentMap, eventManager, elementFocus[i], gameTime, true));
                        }
                    }
                }
                else
                {
                    elementFocus.Clear();
                }
            }

            //Check right mouse functions
            if (inputManager.RightMouseButtonReleased())
            {
                //cycle through all focuses
                for (int i = 0; i < elementFocus.Count; i++)
                {
                    if (elementFocus[i].GetMovable())
                    {
                        //This is an actor
                        ActorElement currentActor = (ActorElement)elementFocus[i];
                        //clear any previous stuck condition
                        currentActor.SetStuck(false);
                        EventMoveTo movingEvent = new EventMoveTo(this, currentMap, elementFocus[i], inputManager.GetCurrentMouseTile(currentMap), gameTime);
                        if (currentActor.Moving())
                        {
                            currentActor.ReplaceLinkedMovement(movingEvent);
                            eventManager.AddEvent(movingEvent);
                        }
                        else
                        {
                            currentActor.LinkToMoveEvent(movingEvent);
                            eventManager.AddEvent(movingEvent);
                        }
                    }
                }

                if (elementFocus.Count == 0)
                {
                    //if no focus, spawn elements to test with
                    if (!currentMap.getOccupied(inputManager.GetCurrentMouseTile(currentMap)))
                    {
                        currentMap.setOccupied(inputManager.GetCurrentMouseTile(currentMap), true);
                        //currentMap.setOccupyingElement(inputManager.GetCurrentMouseTile(currentMap), new WorkerElement(this, (int)inputManager.GetCurrentMouseTile(currentMap).X, (int)inputManager.GetCurrentMouseTile(currentMap).Y));
                        currentMap.setOccupyingElement(inputManager.GetCurrentMouseTile(currentMap), new WaterElement(this, (int)inputManager.GetCurrentMouseTile(currentMap).X, (int)inputManager.GetCurrentMouseTile(currentMap).Y, currentMap));
                    }
                }
            }

            //Process jobs
            //TODO make run for everyone
            if (elementFocus.Count > 0)
            {
                if (elementFocus[0].HasJob() && elementFocus[0].Idle())
                {
                    ((ActorElement)elementFocus[0]).SetIdle(true);
                    ((ActorElement)elementFocus[0]).GetJob().ProcessJobPriorities(this, currentMap, eventManager, elementFocus[0], gameTime);
                }
            }

            //Run events
            eventManager.RunEvents();

            base.Update(gameTime);
        }