Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        for (int i = 0; i < 4; i++)
        {
            if (i > characters.Count - 1)
            {
                huds [i].SetActive(false);
            }
            else
            {
                huds [i].SetActive(true);

                RLCharacter  c  = characters [i];
                HudComponent hc = huds [i].GetComponent <HudComponent> ();
                hc.portrait.GetComponent <SpriteRenderer> ().sprite = GetSprite(c.name);
                for (int h = 0; h < 4; h++)
                {
                    if (c.health > h)
                    {
                        hc.hearts [h].GetComponent <SpriteRenderer> ().sprite = GetSprite("health");
                    }
                    else
                    {
                        hc.hearts [h].GetComponent <SpriteRenderer> ().sprite = GetSprite("health_empty");
                    }
                }
                for (int h = 0; h < 5; h++)
                {
                    if (c != null && c.GetComponent <ActionCounter>().actionsRemaining > h)
                    {
                        hc.potions [h].GetComponent <SpriteRenderer> ().sprite = GetSprite("action");
                    }
                    else
                    {
                        hc.potions [h].GetComponent <SpriteRenderer> ().sprite = GetSprite("action_empty");
                    }
                }
            }
        }
    }
Exemplo n.º 2
0
    void GenLevel()
    {
        currentLevel++;
        // clear the map and all current objects
        foreach (RLCharacter c in objects)
        {
            Destroy(c.gameObject);
        }
        objects.Clear();

        // rebuild the map
        // build the map
        map = new RL.Map(14, 12);

        // build the walls based on the underlying tiles
        for (int x = 0; x < map.sx; x++)
        {
            for (int y = 0; y < map.sy; y++)
            {
                /*
                 * assuming there is a sprite in the middle, here are the potential fills
                 * ...
                 * .x.
                 * ...
                 *
                 * ...
                 * xxx
                 * ...
                 *
                 * .x.
                 * .x.
                 * .x.
                 *
                 * oxi // note, need to do two for each, depending on the direction of internal / external
                 * oxx
                 * ooo
                 *
                 * ...
                 * .xx
                 * .x.
                 *
                 * .x.
                 * xx.
                 * ...
                 *
                 * what a pain in the butt. I am not going to f**k with this for right now, because it makes tons of assumptions
                 * about the map structure and room layout and stuff
                 */

                Sprite toInsert    = tl;
                bool   needsInsert = false;
                if (!map.IsOpenTile(x, y))
                {
                    toInsert    = t;
                    needsInsert = true;
                }
                if (needsInsert)
                {
                    GameObject s = (GameObject)Instantiate(spriteHolder, new Vector3(x, y, 0), Quaternion.identity);
                    s.GetComponent <SpriteRenderer> ().sprite = toInsert;
                    s.AddComponent <RLCharacter> ();
                    objects.Add(s.GetComponent <RLCharacter>());
                }
            }
        }

        GameObject playerGO = (GameObject)Instantiate(spriteHolder, new Vector3(4, 3, 0), Quaternion.identity);

        player = playerGO.AddComponent <RLCharacter> ();
//		player = playerGO.GetComponent<RLCharacter> ();
        player.GetComponent <SpriteRenderer> ().sprite = playerR;
        player.name = "player";
        objects.Add(player);
        currentFacing = Facing.RIGHT;

        // add a random number of monsters
        int nMonsters = currentLevel;

        for (int i = 0; i < nMonsters; i++)
        {
            GameObject m = (GameObject)Instantiate(monster, new Vector3(Random.Range(1, map.sx - 1), Random.Range(1, map.sy - 1)), Quaternion.identity);
            m.GetComponent <RLCharacter> ().AddType(RLCharacter.RLTypes.MONSTER);
            objects.Add(m.GetComponent <RLCharacter> ());
        }

        // add some downward facing stairs
        GameObject stair = (GameObject)Instantiate(spriteHolder, new Vector3(Random.Range(1, map.sx - 1), Random.Range(1, map.sy - 1)), Quaternion.identity);

        stair.GetComponent <SpriteRenderer> ().sprite = stairsDown;
        stair.AddComponent <RLCharacter> ();
        stair.GetComponent <RLCharacter> ().AddType(RLCharacter.RLTypes.STAIRS_DOWN);
        objects.Add(stair.GetComponent <RLCharacter> ());
    }
Exemplo n.º 3
0
    // Update is called once per frame
    void PlayerUpdate()
    {
        bool shouldTransition = false;

        // should stop the player from making moves into enemies
        if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            player.SetPosition(player.positionI.x, player.positionI.y - 1);
            currentFacing = Facing.DOWN;
            player.GetComponent <SpriteRenderer> ().sprite = playerD;
            shouldTransition = true;
        }
        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            player.SetPosition(player.positionI.x, player.positionI.y + 1);
            currentFacing = Facing.UP;
            player.GetComponent <SpriteRenderer> ().sprite = playerU;
            shouldTransition = true;
        }
        if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            player.SetPosition(player.positionI.x + 1, player.positionI.y);
            currentFacing = Facing.RIGHT;
            player.GetComponent <SpriteRenderer> ().sprite = playerR;
            shouldTransition = true;
        }
        if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            player.SetPosition(player.positionI.x - 1, player.positionI.y);
            currentFacing = Facing.LEFT;
            player.GetComponent <SpriteRenderer> ().sprite = playerL;
            shouldTransition = true;
        }
        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (currentBullets <= 0)
            {
                return;
            }
            currentBullets--;
            bulletDisplay [currentBullets].gameObject.SetActive(false);
            // fire current weapon
            GameObject  bulletGO = (GameObject)Instantiate(spriteHolder, new Vector3(player.positionI.x, player.positionI.y, 0), Quaternion.identity);
            RLCharacter bullet   = bulletGO.AddComponent <RLCharacter> ();
            bullet.direction = currentFacing;
            // move the bullet out of the player
            if (bullet.direction == Facing.LEFT || bullet.direction == Facing.RIGHT)
            {
                bullet.GetComponent <SpriteRenderer> ().sprite = bulletH;
            }
            else
            {
                bullet.GetComponent <SpriteRenderer> ().sprite = bulletV;
            }
            bullet.name = "bullet";
            bullet.AddType(RLCharacter.RLTypes.BULLET);
            bullet.GetComponent <SpriteRenderer> ().color = Color.grey;
            objects.Add(bullet);
            // push the player away from the facing direction if possible
            Facing opposite = oppositeDirection(currentFacing);
            if (map.IsOpenTile(player.positionI.x + RL.Map.nDir [(int)opposite, 0], player.positionI.y + RL.Map.nDir [(int)opposite, 1]) &&
                !ContainsType(player.positionI.x + RL.Map.nDir [(int)opposite, 0], player.positionI.y + RL.Map.nDir [(int)opposite, 1], RLCharacter.RLTypes.MONSTER))
            {
                player.SetPosition(player.positionI.x + RL.Map.nDir [(int)opposite, 0], player.positionI.y + RL.Map.nDir [(int)opposite, 1]);
            }
            shouldTransition = true;
        }
        // check to see if the player is on the stairs, and if so, regen the level
        if (ContainsType(player.positionI.x, player.positionI.y, RLCharacter.RLTypes.STAIRS_DOWN))
        {
            GenLevel();
        }
        else if (shouldTransition)
        {
            fsm.PerformTransition(FsmTransitionId.Complete);
        }
    }
Exemplo n.º 4
-1
    void GenLevel()
    {
        currentLevel++;
        // clear the map and all current objects
        foreach (RLCharacter c in objects) {
            Destroy (c.gameObject);
        }
        objects.Clear ();

        // rebuild the map
        // build the map
        map = new RL.Map (14, 12);

        // build the walls based on the underlying tiles
        for (int x = 0; x < map.sx; x++) {
            for (int y = 0; y < map.sy; y++) {
                /*
                 * assuming there is a sprite in the middle, here are the potential fills
                 * ...
                 * .x.
                 * ...
                 *
                 * ...
                 * xxx
                 * ...
                 *
                 * .x.
                 * .x.
                 * .x.
                 *
                 * oxi // note, need to do two for each, depending on the direction of internal / external
                 * oxx
                 * ooo
                 *
                 * ...
                 * .xx
                 * .x.
                 *
                 * .x.
                 * xx.
                 * ...
                 *
                 * what a pain in the butt. I am not going to f**k with this for right now, because it makes tons of assumptions
                 * about the map structure and room layout and stuff
                */

                Sprite toInsert = tl;
                bool needsInsert = false;
                if (!map.IsOpenTile (x, y)) {
                    toInsert = t;
                    needsInsert = true;
                }
                if (needsInsert) {
                    GameObject s = (GameObject)Instantiate (spriteHolder, new Vector3 (x, y, 0), Quaternion.identity);
                    s.GetComponent<SpriteRenderer> ().sprite = toInsert;
                    s.AddComponent<RLCharacter> ();
                    objects.Add (s.GetComponent<RLCharacter>());
                }
            }
        }

        GameObject playerGO = (GameObject)Instantiate (spriteHolder, new Vector3 (4, 3, 0), Quaternion.identity);
        player = playerGO.AddComponent<RLCharacter> ();
        //		player = playerGO.GetComponent<RLCharacter> ();
        player.GetComponent<SpriteRenderer> ().sprite = playerR;
        player.name = "player";
        objects.Add (player);
        currentFacing = Facing.RIGHT;

        // add a random number of monsters
        int nMonsters = currentLevel;
        for (int i = 0; i < nMonsters; i++) {
            GameObject m = (GameObject)Instantiate (monster, new Vector3 (Random.Range (1, map.sx - 1), Random.Range (1, map.sy - 1)), Quaternion.identity);
            m.GetComponent<RLCharacter> ().AddType (RLCharacter.RLTypes.MONSTER);
            objects.Add (m.GetComponent<RLCharacter> ());
        }

        // add some downward facing stairs
        GameObject stair = (GameObject)Instantiate (spriteHolder, new Vector3 (Random.Range (1, map.sx - 1), Random.Range (1, map.sy - 1)), Quaternion.identity);
        stair.GetComponent<SpriteRenderer> ().sprite = stairsDown;
        stair.AddComponent<RLCharacter> ();
        stair.GetComponent<RLCharacter> ().AddType (RLCharacter.RLTypes.STAIRS_DOWN);
        objects.Add (stair.GetComponent<RLCharacter> ());
    }