Exemplo n.º 1
0
    private void open_message_box()
    {
        int current_message = 0;

        if (map.map_value(x, y + 1.0f) == 1)
        {
            current_message = 1;
        }
        else if (map.map_value(x, y + 1.0f) == 2)
        {
            current_message = 2;
        }
        else if (map.map_value(x, y + 1.0f) == 3)
        {
            current_message = 3;
        }

        if (current_message != last_message)
        {
            if (current_message == 0)
            {
                MAP_MESSAGES.HIDE_MESSAGE(last_message_id);
            }
            if (current_message == 1)
            {
                last_message_id = MAP_MESSAGES.SHOW_MESSAGE("TALO 1");
            }
            if (current_message == 2)
            {
                last_message_id = MAP_MESSAGES.SHOW_MESSAGE("TALO 2");
            }
            if (current_message == 3)
            {
                last_message_id = MAP_MESSAGES.SHOW_MESSAGE("TALO 3");
            }

            if (current_message > 0)
            {
                Debug.Log("MAP_CHARACTER_SCRIPT: näytetään message " + current_message + " (id=" + last_message_id + ")");
            }
            else
            {
                Debug.Log("MAP_CHARACTER_SCRIPT: piilotetaan message " + last_message_id);
            }

            last_message = current_message;
        }
        if (Input.GetKeyDown(KeyCode.Z))
        {
            MAP_MESSAGES.HIDE_MESSAGE();
            Debug.Log("piilotetaan mikä hyvänsä viesti");
        }
        if (Input.GetKeyDown(KeyCode.X))
        {
            int id = MAP_MESSAGES.SHOW_MESSAGE("TEST TEST");
            Debug.Log("näytetään viesti (id=" + id + ")");
        }
    }
Exemplo n.º 2
0
    private void talk_to_character()
    {
        Vector2 pos  = new Vector2(0, 0);
        Vector2 size = new Vector2(0, 0);

        player.get_map_character_position(ref pos, ref size);

        sees_player = false;
        Vector2 seeing_point = new Vector2(x, y + 2 * RADIUS_Y);          // looking up

        if (spritesheet_square_y == 1)
        {
            seeing_point = new Vector2(x, y - 2 * RADIUS_Y);                                    // looking down
        }
        if (spritesheet_square_y == 2)
        {
            seeing_point = new Vector2(x - 2 * RADIUS_X, y);                                    // looking left
        }
        if (spritesheet_square_y == 3)
        {
            seeing_point = new Vector2(x + 2 * RADIUS_X, y);                // looking right
        }
        if (spritesheet_square_y == 0 || spritesheet_square_y == 1)         // looking up or down
        {
            if (pos.x + size.x > seeing_point.x - 0.5f &&
                pos.x - size.x < seeing_point.x + 0.5f &&
                pos.y + size.y > seeing_point.y &&
                pos.y - size.y < seeing_point.y)
            {
                sees_player = true;
            }
        }
        if (spritesheet_square_y == 2 || spritesheet_square_y == 3)         // looking left or right
        {
            if (pos.x + size.x > seeing_point.x &&
                pos.x - size.x < seeing_point.x &&
                pos.y + size.y > seeing_point.y - 0.5f &&
                pos.y - size.y < seeing_point.y + 0.5f)
            {
                sees_player = true;
            }
        }



        talk_timer += Time.deltaTime;
        if (sees_player && talk_id == -1 && talk_timer > 0.1f)
        {
            Debug.Log("REPLIIKKI!!! character pos=" + pos + "   size=" + size + "  sees=" + sees_player);

            if (sentence == 0)
            {
                talk_id = MAP_MESSAGES.SHOW_MESSAGE("HEI OLEN KYLAN", "AINOA IDIOOTTI.", "TAI ONHAN TOI", "NORSUKIN AIKA TYHMEA.");
            }
            if (sentence == 1)
            {
                talk_id = MAP_MESSAGES.SHOW_MESSAGE("POIS EESTA !!!!!!", "!!!!!!!!!!!");
            }
            if (sentence == 2)
            {
                talk_id = MAP_MESSAGES.SHOW_MESSAGE("GOOD AFTERNOON. I AM", "PLEASE TO MEET YOU", "STRANGE GREEN MAN.");
            }
            if (sentence == 3)
            {
                talk_id = MAP_MESSAGES.SHOW_MESSAGE("OSAAN SANOA", "MONTA ERI ASIAA", "KOSKA OLEN AIKA", "SMART.");
            }

            sentence++;
            if (sentence > 3)
            {
                sentence = 0;
            }
            talk_timer = 0.0f;
            spritesheet_animation_timer = 0.0f;
        }
        if (!sees_player && talk_id != -1 && talk_timer > 0.5f)
        {
            MAP_MESSAGES.HIDE_MESSAGE(talk_id);
            talk_id    = -1;
            talk_timer = 0.0f;
        }
    }
Exemplo n.º 3
0
    private void update_textbox()
    {
        if (initialize)
        {
            textbox            = transform.FindChild("textbox");
            textbox_background = textbox.FindChild("textbox_background");
            for (int x = 0; x < TEXTBOX_WIDTH; x++)
            {
                for (int y = 0; y < TEXTBOX_HEIGHT; y++)
                {
                    GameObject temp   = (GameObject)Instantiate(letter_prefab, new Vector3(0, 0, 0), Quaternion.identity);
                    Transform  letter = temp.transform;
                    letter.SetParent(textbox_background);
                    letter.localScale    = new Vector3(1.0f / (TEXTBOX_WIDTH + 2.0f), 1.0f / (TEXTBOX_HEIGHT + 2.0f), 1.0f);
                    letter.localPosition = new Vector3(-0.5f + (x + 1) / (TEXTBOX_WIDTH + 2.0f) + letter.localScale.x * 0.5f,
                                                       0.5f - (y + 1) / (TEXTBOX_HEIGHT + 2.0f) - letter.localScale.y * 0.5f,
                                                       -0.5f);

                    letter_material[x, y] = letter.gameObject.GetComponent <Renderer>().material;
                    letter_material[x, y].mainTextureScale  = new Vector2(1.0f / 94.0f, 1.0f);
                    letter_material[x, y].mainTextureOffset = new Vector2(0 / 94.0f, 0.0f);
                }
            }
            initialize = false;
        }
        textbox.localPosition = new Vector3(0.0f, -textbox_timer * camera_height * 2.0f, 0.0f);

        Vector3 background_position = textbox_background.localPosition;

        if (joystick_type == JOYSTICK_TYPE.SCREEN_PAD)
        {
            background_position.x = 0.0f;
        }
        else if (joystick_type == JOYSTICK_TYPE.VPAD_LEFT)
        {
            background_position.x = (arrow_right.localPosition.x + camera_width) * 0.5f;
        }
        else if (joystick_type == JOYSTICK_TYPE.VPAD_RIGHT)
        {
            background_position.x = (arrow_left.localPosition.x - camera_width) * 0.5f;
        }

        textbox_background.localPosition = background_position;

        /*
         * if (textbox_open == false)
         * {
         *      if (MAP_MESSAGES.is_there_new_message())
         *      {
         *              textbox_open = true;
         *              textbox_timer = 1.0f;
         *              for (int a = 0; a < MAP_MESSAGES.get_new_message_lines(); a++)
         *                      textbox_line[a] = MAP_MESSAGES.get_new_message_line(a);
         *              for (int x = 0; x < TEXTBOX_WIDTH; x++)
         *                      for (int y = 0; y < TEXTBOX_HEIGHT; y++)
         *                              letter_material[x, y].mainTextureOffset = new Vector2(0 / 94.0f, 0.0f);
         *              textbox_x = -1;
         *              textbox_y = 0;
         *      }
         *      else
         *      {
         *              textbox_timer += Time.deltaTime * TEXTBOX_SPEED;
         *              if (textbox_timer > 1.0f) textbox_timer = 1.0f;
         *      }
         * }
         * else
         */
        if (MAP_MESSAGES.is_there_new_message())
        {
            textbox_open  = true;
            textbox_timer = 1.0f;
            for (int a = 0; a < MAP_MESSAGES.get_new_message_lines(); a++)
            {
                textbox_line[a] = MAP_MESSAGES.get_new_message_line(a);
            }
            for (int x = 0; x < TEXTBOX_WIDTH; x++)
            {
                for (int y = 0; y < TEXTBOX_HEIGHT; y++)
                {
                    letter_material[x, y].mainTextureOffset = new Vector2(0 / 94.0f, 0.0f);
                }
            }
            textbox_x = -1;
            textbox_y = 0;
        }
        else if (textbox_open == false)
        {
            textbox_timer += Time.deltaTime * TEXTBOX_SPEED;
            if (textbox_timer > 1.0f)
            {
                textbox_timer = 1.0f;
            }
        }
        if (textbox_open == true)

        {
            textbox_timer -= Time.deltaTime * TEXTBOX_SPEED;
            if (textbox_timer < 0.0f)
            {
                textbox_timer = 0.0f;
            }
            if (textbox_timer < 0.10f)
            {
                text_timer += Time.deltaTime;
                if (text_timer > 0.4f / TEXTBOX_SPEED)
                {
                    textbox_x++;
                    text_timer = 0.0f;
                    if (textbox_x < textbox_line[textbox_y].Length && textbox_x < TEXTBOX_WIDTH)
                    {
                        //Debug.Log("textbox x,y="+textbox_x+","+textbox_y);
                        int letter_value = (int)textbox_line[textbox_y][textbox_x] - 32;
                        letter_material[textbox_x, textbox_y].mainTextureOffset = new Vector2(letter_value / 94.0f, 0.0f);
                        //Debug.Log("printing new letter="+textbox_line[textbox_x]);
                    }
                    else
                    {
                        textbox_x = -1;
                        textbox_y++;
                        if (textbox_y > TEXTBOX_HEIGHT - 1)
                        {
                            textbox_y = TEXTBOX_HEIGHT - 1;
                        }
                    }
                }
            }
            if (MAP_MESSAGES.time_to_hide_message())
            {
                textbox_open = false;
            }
        }
    }