示例#1
0
    //TODO: THINK ABOUT INPUTS SOME MORE!!!
    //Java version uses KeyMasks to store AvatarActions between updates, and classes like FlakAvatar exploits that.
    //Something about limiting the actions up front, instead of after the fact feels better to me.

    /**
     * This update call is for the game tick() loop.
     * @param game current state of the game.
     */
    public virtual void updateAvatar(VGDLGame game, bool requestInput, List <VGDLAvatarActions> actionMask = null)
    {
        lastMovementType = VGDLMovementTypes.STILL;

        var direction = VGDLUtils.VGDLDirections.NONE.getDirection();

        if (requestInput || actionMask == null)
        {
            //Get the input from the player.
            VGDLAvatarActions action;
            if (player != null && player.isHuman)
            {
                if (inputHandler.ProcessEscapeInput(playerID))
                {
                    game.Abort();
                    action = VGDLAvatarActions.ACTION_ESCAPE;
                }
                //TODO: CHECK IF actions INCLUDE USE KEY!
                else if (inputHandler.ProcessUseInput(playerID))
                {
                    //NOTE: technically we could allow directional input + use
                    action = VGDLAvatarActions.ACTION_USE;
                }
                else
                {
                    //TODO: CHECK IF actions INCLUDE DIRECTIONS!
                    direction = inputHandler.ProcessPlayerMovement(playerID, true);
                    //NOTE: For now we don't handle multiple actions at once, so this is okay.
                    //But if/when that happens, the AvatarActions need to deal with that.
                    action = AvatarAction.fromVector(direction);
                }

                player.logAction(action);
                game.avatarLastAction[playerID] = action;
            }
            else
            {
                if (player == null)
                {
                    Debug.LogError("No player attached to avatar: " + getType());
                    return;
                }

                action    = requestAgentInput(game);
                direction = action.getDirection();
            }
        }
        else
        {
            direction = inputHandler.ProcessPlayerInput(actionMask);
        }

        //Apply the physical movement.
        applyMovement(game, direction);
    }