Пример #1
0
        public void TurnTowardsPlayer()
        {
            MoveableCharacter player     = event_manager.GetPlayerMover();
            Vector3           player_dir = player.transform.position - transform.position;

            if (Mathf.Abs(player_dir.x) > Mathf.Abs(player_dir.y))
            {
                if (player_dir.x > 0)
                {
                    TurnRight();
                }
                else
                {
                    TurnLeft();
                }
            }
            else
            {
                if (player_dir.y > 0)
                {
                    TurnUp();
                }
                else
                {
                    TurnDown();
                }
            }
        }
Пример #2
0
        public void EnableEvent(Event e)
        {
            e.enabled = true;
            MoveableCharacter moveable_character = e.GetComponent <MoveableCharacter>();

            moveable_character.enabled = true;
        }
Пример #3
0
        public IEnumerator SetPlayerMoveRoute(MoveRoutePackage package)
        {
            MoveableCharacter character = event_manager.GetPlayerMover();

            yield return(new WaitUntil(() => !character.GetInMoveRoute()));

            StartCoroutine(character.StartMoveRoute(package.move_route));

            if (package.wait_for_moves_completion)
            {
                yield return(new WaitUntil(() => !character.GetInMoveRoute()));
            }

            effect_playing = false;
        }
Пример #4
0
        // TODO: ShowMessageBubble that takes in a moveable character as well, makes bubble speech

        public IEnumerator SetMoveRoute(MoveableCharacter character, MoveRoutePackage package)
        {
            if (character == null)
            {
                character = GetComponent <MoveableCharacter>();
            }
            yield return(new WaitUntil(() => !character.GetInMoveRoute()));

            StartCoroutine(character.StartMoveRoute(package.move_route));

            if (package.wait_for_moves_completion)
            {
                yield return(new WaitUntil(() => !character.GetInMoveRoute()));
            }

            effect_playing = false;
        }
Пример #5
0
        // Returns the events directly around a moveable character
        public Event[] GetNeighborEvents(MoveableCharacter character)
        {
            Event on_event    = null;
            Event up_event    = null;
            Event left_event  = null;
            Event right_event = null;
            Event down_event  = null;

            Vector3 pos = character.transform.position;

            for (int i = 0; i < events.Count; i++)
            {
                Event this_event = events[i];
                if (on_event == null && this_event.transform.position == pos)
                {
                    on_event = this_event;
                }
                if (up_event == null && this_event.transform.position == pos + Vector3.up)
                {
                    up_event = this_event;
                }
                if (left_event == null && this_event.transform.position == pos + Vector3.left)
                {
                    left_event = this_event;
                }
                if (right_event == null && this_event.transform.position == pos + Vector3.right)
                {
                    right_event = this_event;
                }
                if (down_event == null && this_event.transform.position == pos + Vector3.down)
                {
                    down_event = this_event;
                }
            }

            return(new Event[] { on_event, up_event, left_event, right_event, down_event });
        }
Пример #6
0
        public IEnumerator PlayEvent()
        {
            // Start Event Processing
            event_playing = true;
            if (trigger != Triggers.ParallelProcess)
            {
                event_manager.DisablePlayerControl();
            }
            // Turn towards player on activation
            MoveableCharacter character = GetComponent <MoveableCharacter>();

            if (trigger == Triggers.ActionButton && character != null)
            {
                character.TurnTowardsPlayer();
            }

            // Run through all effects
            for (int i = 0; i < event_entries.Length; i++)
            {
                Effects    effect      = event_entries[i].effect;
                EventEntry event_entry = event_entries[i];
                effect_playing = true;

                switch (effect)
                {
                case Effects.ShowMessage:
                    StartCoroutine(ShowMessage(event_entry.message)); break;

                case Effects.ShowChoices:
                    StartCoroutine(ShowChoices(event_entry.message, event_entry.choice_package)); break;

                case Effects.ShowMessageBubble:
                    StartCoroutine(ShowMessage(event_entry.message)); break;

                case Effects.SetMoveRoute:
                    StartCoroutine(SetMoveRoute(event_entry.character, event_entry.move_route_package)); break;

                case Effects.SetPlayerMoveRoute:
                    StartCoroutine(SetPlayerMoveRoute(event_entry.move_route_package)); break;

                case Effects.AddPokemon:
                    StartCoroutine(AddPokemon(event_entry.pokemon_package)); break;

                case Effects.WildBattle:
                    StartCoroutine(WildBattle(event_entry.pokemon_package)); break;

                default:
                    Debug.Log("Unknown effect played: " + effect); break;
                }

                // Wait for effect to finish playing
                yield return(new WaitUntil(() => !effect_playing));
            }

            // End Event Processing
            if (trigger != Triggers.ParallelProcess)
            {
                event_manager.EnablePlayerControl();
            }
            event_playing = false;
        }
Пример #7
0
 private void Start()
 {
     player_mover = GetComponent <MoveableCharacter>();
     ui_manager   = FindObjectOfType <UIManager>();
 }
Пример #8
0
        private void Update()
        {
            // Update Animator
            animator.SetInteger(Constants.DIRECTION_ANIMATION, (int)direction);
            if (walking_animation && !stepping_animation)
            {
                animator.SetBool(Constants.WALK_ANIMATION, moved);
            }
            else if (stepping_animation)
            {
                animator.SetBool(Constants.WALK_ANIMATION, true);
            }
            if (invisible)
            {
                foreach (SpriteRenderer sprite in sprites)
                {
                    sprite.enabled = false;
                }
            }
            else
            {
                foreach (SpriteRenderer sprite in sprites)
                {
                    sprite.enabled = true;
                }
            }
            if (in_bush)
            {
                bush_mask.enabled = true;
            }
            else
            {
                bush_mask.enabled = false;
            }

            // Apply Movement
            if (moved)
            {
                // Activate the tile being moved onto
                if (!tile_activated)
                {
                    Vector3 move_dir = pos - transform.position;
                    tile_activated = ActivateTile(move_dir);
                }

                // Move in that direction
                transform.position = Vector3.MoveTowards(transform.position, pos, Time.deltaTime * speed);
            }

            // Tilemap and Event awareness check
            if ((other_moved || moved) && transform.position == pos)
            {
                // Get neighboring tiles
                AdvancedTileBase[] neighbor_tiles = map_manager.GetNeighborTiles(this);
                on_tile    = neighbor_tiles[0];
                up_tile    = neighbor_tiles[1];
                left_tile  = neighbor_tiles[2];
                right_tile = neighbor_tiles[3];
                down_tile  = neighbor_tiles[4];

                // Notify old neighbor events
                foreach (Event e in neighbor_events)
                {
                    if (e != null)
                    {
                        MoveableCharacter character = e.GetComponent <MoveableCharacter>();
                        if (character != null)
                        {
                            character.other_moved = true;
                        }
                    }
                }

                // Get neighboring events
                neighbor_events = event_manager.GetNeighborEvents(this);
                on_event        = neighbor_events[0];
                up_event        = neighbor_events[1];
                left_event      = neighbor_events[2];
                right_event     = neighbor_events[3];
                down_event      = neighbor_events[4];

                // Notify new neighbor events
                foreach (Event e in neighbor_events)
                {
                    if (e != null)
                    {
                        MoveableCharacter character = e.GetComponent <MoveableCharacter>();
                        if (character != null)
                        {
                            character.other_moved = true;
                        }
                    }
                }

                moved       = false;
                other_moved = false;
                if (!tile_activated)
                {
                    tile_activated = ActivateTile(on_tile);
                }
            }
        }