Exemplo n.º 1
0
        private byte[] CreateDataForMap(IMapFileProperties mapFileProperties, TileSpec spec, int gfx = 1)
        {
            var ret = new List <byte>();

            var serializer = new MapPropertiesSerializer(nes, ses);

            ret.AddRange(serializer.SerializeToByteArray(mapFileProperties));
            ret.AddRange(nes.EncodeNumber(0, 1)); //npc spawns
            ret.AddRange(nes.EncodeNumber(0, 1)); //unknowns
            ret.AddRange(nes.EncodeNumber(0, 1)); //chest spawns

            //tiles
            ret.AddRange(nes.EncodeNumber(1, 1));          //count
            ret.AddRange(nes.EncodeNumber(1, 1));          //y
            ret.AddRange(nes.EncodeNumber(1, 1));          //count
            ret.AddRange(nes.EncodeNumber(1, 1));          //x
            ret.AddRange(nes.EncodeNumber((byte)spec, 1)); //tilespec

            //warps
            ret.AddRange(nes.EncodeNumber(0, 1));

            //gfx
            foreach (var layer in (MapLayer[])Enum.GetValues(typeof(MapLayer)))
            {
                ret.AddRange(nes.EncodeNumber(1, 1));   //count
                ret.AddRange(nes.EncodeNumber(1, 1));   //y
                ret.AddRange(nes.EncodeNumber(1, 1));   //count
                ret.AddRange(nes.EncodeNumber(1, 1));   //x
                ret.AddRange(nes.EncodeNumber(gfx, 2)); //gfx value
            }

            ret.AddRange(nes.EncodeNumber(0, 1)); //signs

            return(ret.ToArray());
        }
Exemplo n.º 2
0
    public void setTile(IVector2 v, byte foreground, byte background)
    {
        if (!inBounds(v))
        {
            return;
        }
        setByte(v, FOREGROUND_ID, foreground);
        setByte(v, BACKGROUND_ID, background);
        TileSpec t = TileSpecList.getTileSpec(foreground);
        byte     d = 1;

        if (t != null)
        {
            d = t.durability;
        }
        setByte(v, DURABILITY, d);
        for (int x = -1; x <= 1; x++)
        {
            for (int y = -1; y <= 1; y++)
            {
                IVector2 vi = v + new IVector2(x, y);
                updateTileSpec(vi);
                if (inBounds(vi))
                {
                    makeDirty(vi.x / chunkSize, vi.y / chunkSize);
                }
            }
        }
    }
Exemplo n.º 3
0
    public override RectF GetTileSprite(TileSpec top, TileSpec right, TileSpec down, TileSpec left)
    {
        NeighborsState ns = new NeighborsState();

        if (IsThis(top))
        {
            ns.top = true;
        }
        if (IsThis(right))
        {
            ns.right = true;
        }
        if (IsThis(down))
        {
            ns.down = true;
        }
        if (IsThis(left))
        {
            ns.left = true;
        }

        foreach (WeldableTileSpriteSpec spec in specs)
        {
            if (spec.ns == ns)
            {
                return(spec.rect);
            }
        }
        return(m0000.rect);
    }
Exemplo n.º 4
0
    public void AddTileSpec(Texture2D tex)
    {
        TileSpec spec = new TileSpec();

        spec.texture = tex;
        tileSpecs.Add(spec);
        RemakeTexture();
    }
Exemplo n.º 5
0
 public static TileSpec AddSpec(TileSpec spec)
 {
     if (allSpecs.Contains(spec))
     {
         throw new Exception("adding tile spec twice");
     }
     allSpecs.Add(spec);
     return(spec);
 }
Exemplo n.º 6
0
    public TileSpec getBackground(IVector2 v)
    {
        TileSpec t = TileSpecList.getTileSpec(getByte(v, BACKGROUND_ID));

        if (t == null)
        {
            return(TileSpecList.getTileSpec(0));
        }
        return(t);
    }
Exemplo n.º 7
0
        private void HandleTileSpecClick(TileSpec spec)
        {
            switch (spec)
            {
            case TileSpec.Chest: HandleChestClick(); break;

            case TileSpec.BankVault: HandleBankVaultClick(); break;
                //todo: boards, chairs
            }
        }
Exemplo n.º 8
0
 public bool IsThis(TileSpec other)
 {
     if (other == null)
     {
         return(false);
     }
     if (other == this)
     {
         return(true);
     }
     return(false);
 }
 private bool IsWarpWalkable(IWarp warp, TileSpec tile)
 {
     if (warp.DoorType != DoorSpec.NoDoor)
     {
         return(_currentMapStateProvider.OpenDoors.Any(w => w.X == warp.X && w.Y == warp.Y) &&
                _unlockDoorValidator.CanMainCharacterOpenDoor(warp));
     }
     if (warp.LevelRequirement != 0)
     {
         return(warp.LevelRequirement <= _characterProvider.MainCharacter.Stats[CharacterStat.Level]);
     }
     return(IsTileSpecWalkable(tile));
 }
Exemplo n.º 10
0
    void ladderTile(IVector2 t)
    {
        if (!canLadder)
        {
            return;
        }
        currentState = movementState.CLIMBING;
        TileSpec ts = map.getForeground(t);

        if (!ts.solid && ts != TileSpecList.getTileSpec(LADDERINDEX))
        {
            map.setTile(t, (byte)LADDERINDEX, (byte)1);
        }
    }
Exemplo n.º 11
0
        private void UpdateCursorIndexForTileSpec(TileSpec tileSpec)
        {
            switch (tileSpec)
            {
            case TileSpec.Wall:
            case TileSpec.JammedDoor:
            case TileSpec.MapEdge:
            case TileSpec.FakeWall:
            case TileSpec.NPCBoundary:
                _shouldDrawCursor = false;
                break;

            case TileSpec.Chest:
            case TileSpec.BankVault:
            case TileSpec.ChairDown:
            case TileSpec.ChairLeft:
            case TileSpec.ChairRight:
            case TileSpec.ChairUp:
            case TileSpec.ChairDownRight:
            case TileSpec.ChairUpLeft:
            case TileSpec.ChairAll:
            case TileSpec.Board1:
            case TileSpec.Board2:
            case TileSpec.Board3:
            case TileSpec.Board4:
            case TileSpec.Board5:
            case TileSpec.Board6:
            case TileSpec.Board7:
            case TileSpec.Board8:
            case TileSpec.Jukebox:
                _cursorIndex = CursorIndex.HoverNormal;
                break;

            case TileSpec.Jump:
            case TileSpec.Water:
            case TileSpec.Arena:
            case TileSpec.AmbientSource:
            case TileSpec.SpikesStatic:
            case TileSpec.SpikesTrap:
            case TileSpec.SpikesTimed:
            case TileSpec.None:
                _cursorIndex = CursorIndex.Standard;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(tileSpec), tileSpec, null);
            }
        }
Exemplo n.º 12
0
    protected override void mine(IVector2 v)
    {
        byte d = map.getByte(v, Map.DURABILITY);

        if (mineTime <= 0)
        {
            digging = false;
            TileSpec ts = TileSpecList.getTileSpec(map.getByte(v, Map.FOREGROUND_ID));
            map.setTile(v, (byte)spawnedTile, map.getByte(v, Map.BACKGROUND_ID));
            eliminate();
        }
        else
        {
            mineTime -= Time.fixedDeltaTime;
        }
    }
Exemplo n.º 13
0
        private void UpdateCursorForTileSpec(TileSpec spec)
        {
            switch (spec)
            {
            case TileSpec.Wall:
            case TileSpec.JammedDoor:
            case TileSpec.MapEdge:
            case TileSpec.FakeWall:
                _hideCursor = true;
                break;

            case TileSpec.Chest:
            case TileSpec.BankVault:
            case TileSpec.ChairDown:
            case TileSpec.ChairLeft:
            case TileSpec.ChairRight:
            case TileSpec.ChairUp:
            case TileSpec.ChairDownRight:
            case TileSpec.ChairUpLeft:
            case TileSpec.ChairAll:
            case TileSpec.Board1:
            case TileSpec.Board2:
            case TileSpec.Board3:
            case TileSpec.Board4:
            case TileSpec.Board5:
            case TileSpec.Board6:
            case TileSpec.Board7:
            case TileSpec.Board8:
            case TileSpec.Jukebox:
                _cursorSourceRect.Location = new Point(_mouseCursor.Width / 5, 0);
                break;

            case TileSpec.Jump:
            case TileSpec.Water:
            case TileSpec.Arena:
            case TileSpec.AmbientSource:
            case TileSpec.SpikesStatic:
            case TileSpec.SpikesTrap:
            case TileSpec.SpikesTimed:
            case TileSpec.None:
                _cursorSourceRect.Location = new Point(0, 0);
                break;
            }
        }
Exemplo n.º 14
0
    public TileSpec GetWallBottom(TileSpec left, TileSpec right)
    {
        bool l = IsThis(left);
        bool r = IsThis(right);

        if (l && r)
        {
            return(b11);
        }
        if (l)
        {
            return(b10);
        }
        if (r)
        {
            return(b01);
        }
        return(b00);
    }
        private static bool IsTileSpecWalkable(TileSpec tileSpec)
        {
            switch (tileSpec)
            {
            case TileSpec.Wall:
            case TileSpec.ChairDown:
            case TileSpec.ChairLeft:
            case TileSpec.ChairRight:
            case TileSpec.ChairUp:
            case TileSpec.ChairDownRight:
            case TileSpec.ChairUpLeft:
            case TileSpec.ChairAll:
            case TileSpec.JammedDoor:
            case TileSpec.Chest:
            case TileSpec.BankVault:
            case TileSpec.MapEdge:
            case TileSpec.Board1:
            case TileSpec.Board2:
            case TileSpec.Board3:
            case TileSpec.Board4:
            case TileSpec.Board5:
            case TileSpec.Board6:
            case TileSpec.Board7:
            case TileSpec.Board8:
            case TileSpec.Jukebox:
                return(false);

            case TileSpec.NPCBoundary:
            case TileSpec.FakeWall:
            case TileSpec.Jump:
            case TileSpec.Water:
            case TileSpec.Arena:
            case TileSpec.AmbientSource:
            case TileSpec.SpikesTimed:
            case TileSpec.SpikesStatic:
            case TileSpec.SpikesTrap:
            case TileSpec.None:
                return(true);

            default:
                throw new ArgumentOutOfRangeException(nameof(tileSpec), tileSpec, null);
            }
        }
Exemplo n.º 16
0
    public Vector2[] GetLadderNeighbors()
    {
        List <Vector2> neighbors     = new List <Vector2>();
        List <Vector2> goodNeighbors = new List <Vector2>();
        IVector2       pos           = new IVector2(location.x, location.y);

        neighbors.Add(new IVector2(location.x, location.y + 1));

        foreach (IVector2 v in neighbors)
        {
            byte     b = m.getByte(v, Map.FOREGROUND_ID);
            TileSpec t = TileSpecList.getTileSpec(b);
            if (m.unnavigable(v) && m.ladderable(v))
            {
                goodNeighbors.Add(v);
            }
        }

        return(goodNeighbors.ToArray());
    }
Exemplo n.º 17
0
    private int[] makeCollisionIndices(int cx, int cy)
    {
        List <int> indices = new List <int>();
        int        i       = 0;
        int        off     = 4 * map.chunkSize * map.chunkSize;
        IVector2   v;

        for (int y = 0; y < map.chunkSize; y++)
        {
            for (int x = 0; x < map.chunkSize; x++, i++)
            {
                v = new IVector2(cx * map.chunkSize + x, cy * map.chunkSize + y);
                TileSpec tile = map.getForeground(v);
                if (tile.solid)
                {
                    tile.getRender(Map.hash(v.x, v.y)).getCollisionIndices(4 * i, off, (byte)~map.getRenderContext(v), indices);
                }
            }
        }
        return(indices.ToArray());
    }
Exemplo n.º 18
0
    private Vector2[] makeTextures(int cx, int cy)
    {
        Vector2[] textures = new Vector2[8 * map.chunkSize * map.chunkSize];
        float     ix       = 1f / map.tileset.width;
        float     iy       = 1f / map.tileset.height;
        int       i        = 0;

        for (int y = 0; y < map.chunkSize; y++)
        {
            for (int x = 0; x < map.chunkSize; x++)
            {
                IVector2  v     = new IVector2(cx * map.chunkSize + x, cy * map.chunkSize + y);
                TileSpec  tile  = map.getRenderForeground(v);
                int       texID = tile.getRender(Map.hash(v.x, v.y)).getTexID(map.getRenderContext(v));
                Vector2[] tex   = map.tileset.getTex(texID);
                textures [i * 4]     = tex[0];
                textures [i * 4 + 1] = tex[1];
                textures [i * 4 + 2] = tex[2];
                textures [i * 4 + 3] = tex[3];
                i++;
            }
        }
        for (int y = 0; y < map.chunkSize; y++)
        {
            for (int x = 0; x < map.chunkSize; x++)
            {
                IVector2  v     = new IVector2(cx * map.chunkSize + x, cy * map.chunkSize + y);
                TileSpec  tile  = map.getRenderBackground(v);
                int       texID = tile.getRender(Map.hash(v.x, v.y)).getTexID(map.getBackgroundRenderContext(v));
                Vector2[] tex   = map.tileset.getTex(texID);
                textures [i * 4]     = tex[0];
                textures [i * 4 + 1] = tex[1];
                textures [i * 4 + 2] = tex[2];
                textures [i * 4 + 3] = tex[3];
                i++;
            }
        }
        return(textures);
    }
Exemplo n.º 19
0
    protected virtual void mine(IVector2 v)
    {
        if (!canMine)
        {
            return;
        }
        byte d = map.getByte(v, Map.DURABILITY);

        if (d == 0)
        {
            digging = false;
            TileSpec ts = TileSpecList.getTileSpec(map.getByte(v, Map.FOREGROUND_ID));
            InventroyManager.instance.addToInventory(ts.resource);
            map.setTile(v, 0, map.getByte(v, Map.BACKGROUND_ID));
        }
        else
        {
            map.setByte(v, Map.DURABILITY, (byte)(d - 1));
            digTimer = digTime;
        }
        // This element type should be determined by the element being mined
    }
Exemplo n.º 20
0
    public Vector2[] GetDigNeighbors()
    {
        List <Vector2> neighbors     = new List <Vector2>();
        List <Vector2> goodNeighbors = new List <Vector2>();
        IVector2       pos           = new IVector2(location.x, location.y);

        neighbors.Add(new IVector2(location.x - 1, location.y));
        neighbors.Add(new IVector2(location.x + 1, location.y));
        neighbors.Add(new IVector2(location.x, location.y - 1));
        neighbors.Add(new IVector2(location.x, location.y + 1));

        foreach (IVector2 v in neighbors)
        {
            byte     b = m.getByte(v, Map.FOREGROUND_ID);
            TileSpec t = TileSpecList.getTileSpec(b);
            if (t.diggable && t.solid)
            {
                goodNeighbors.Add(v);
            }
        }

        return(goodNeighbors.ToArray());
    }
Exemplo n.º 21
0
    // Update is called once per frame
    private void FixedUpdate()
    {
        base.FixedUpdate();
        if (pPhysics.onWall)
        {
            targetSpeed  = 0;
            currentSpeed = 0;
        }
        targetSpeed = speed * Input.GetAxisRaw("Horizontal");

        float climb = Input.GetAxisRaw("Vertical");

        currentSpeed = IncrementSpeed(currentSpeed, targetSpeed, acceleration);

        moveAmount.x = currentSpeed;

        if (pPhysics.climbing)
        {
            moveAmount.y = climb;
            if (!pPhysics.onLadder())             //|| Mathf.Abs(currentSpeed) > .25){
            {
                pPhysics.ungrab();
                if (Input.GetAxisRaw("Jump") > .5)
                {
                    moveAmount.y = jumpHeight;
                }
            }
        }
        else if (pPhysics.onGround)
        {
            moveAmount.y = 0;
            if (Input.GetAxisRaw("Jump") > .5)
            {
                moveAmount.y = jumpHeight;
            }
        }
        else
        {
            moveAmount.y -= gravity * Time.fixedDeltaTime;
            //Debug.Log (moveAmount);
            if (moveAmount.y <= -fallDeathSpeed)
            {
                Debug.Log(moveAmount);
                reset();
            }
        }

        if (Mathf.Abs(climb) > .1f)
        {
            pPhysics.grab();
        }

        pPhysics.move(moveAmount * Time.fixedDeltaTime);
        currentTile = map.getForeground((Vector2)this.transform.position);
        if (currentTile == TileSpecList.getTileSpec("Die"))
        {
            reset();
        }

        if (Input.GetKey(KeyCode.Home))
        {
            reset();
        }
    }
Exemplo n.º 22
0
		public BasicTileInfoWithSpec(TileSpec spec) 
			: base(TileInfoReturnType.IsTileSpec)
		{
			_spec = spec;
		}
Exemplo n.º 23
0
        //convenience wrapper
        private void _chkWalk(TileSpec spec, EODirection dir, byte destX, byte destY)
        {
            bool walkValid = true;
            switch (spec)
            {
                case TileSpec.ChairDown: //todo: make character sit in chairs
                case TileSpec.ChairLeft:
                case TileSpec.ChairRight:
                case TileSpec.ChairUp:
                case TileSpec.ChairDownRight:
                case TileSpec.ChairUpLeft:
                case TileSpec.ChairAll:
                    walkValid = NoWall;
                    break;
                case TileSpec.Chest:
                    walkValid = NoWall;
                    if (!walkValid)
                    {
                        MapChest chest = World.Instance.ActiveMapRenderer.MapRef.Chests.Find(_c => _c.x == destX && _c.y == destY);
                        if (chest != null)
                        {
                            string requiredKey = null;
                            switch (Character.CanOpenChest(chest))
                            {
                                case ChestKey.Normal: requiredKey = "Normal Key"; break;
                                case ChestKey.Silver: requiredKey = "Silver Key"; break;
                                case ChestKey.Crystal: requiredKey = "Crystal Key"; break;
                                case ChestKey.Wraith: requiredKey = "Wraith Key"; break;
                                default:
                                    EOChestDialog.Show(((EOGame)Game).API, chest.x, chest.y);
                                    break;
                            }

                            if (requiredKey != null)
                            {
                                EODialog.Show(DATCONST1.CHEST_LOCKED, XNADialogButtons.Ok, EODialogStyle.SmallDialogSmallHeader);
                                ((EOGame)Game).Hud.SetStatusLabel(DATCONST2.STATUS_LABEL_TYPE_WARNING, DATCONST2.STATUS_LABEL_THE_CHEST_IS_LOCKED_EXCLAMATION,
                                    " - " + requiredKey);
                            }
                        }
                        else
                        {
                            EOChestDialog.Show(((EOGame)Game).API, destX, destY);
                        }
                    }
                    break;
                case TileSpec.BankVault:
                    walkValid = NoWall;
                    if (!walkValid)
                    {
                        EOLockerDialog.Show(((EOGame)Game).API, destX, destY);
                    }
                    break;
                case TileSpec.Board1: //todo: boards?
                case TileSpec.Board2:
                case TileSpec.Board3:
                case TileSpec.Board4:
                case TileSpec.Board5:
                case TileSpec.Board6:
                case TileSpec.Board7:
                case TileSpec.Board8:
                    walkValid = NoWall;
                    break;
                case TileSpec.Jukebox: //todo: jukebox?
                    walkValid = NoWall;
                    break;
                case TileSpec.MapEdge:
                case TileSpec.Wall:
                    walkValid = NoWall;
                    break;
            }

            if (State != CharacterActionState.Walking && walkValid)
            {
                _char.Walk(dir, destX, destY, NoWall);
                PlayerWalk(spec == TileSpec.Water);
            }
        }
Exemplo n.º 24
0
	// Update is called once per frame
	private void FixedUpdate () {
		base.FixedUpdate();
		if (pPhysics.onWall) {
			targetSpeed = 0;
			currentSpeed = 0;
		}
		targetSpeed = speed * Input.GetAxisRaw("Horizontal");

		float climb = Input.GetAxisRaw("Vertical");

		currentSpeed = IncrementSpeed(currentSpeed,targetSpeed,acceleration);
		
		moveAmount.x = currentSpeed;

		if(pPhysics.climbing){
			moveAmount.y = climb;
			if(!pPhysics.onLadder() ){//|| Mathf.Abs(currentSpeed) > .25){
				pPhysics.ungrab();
				if (Input.GetAxisRaw("Jump") > .5) {
					moveAmount.y = jumpHeight;
				}
			}
		}
		else if (pPhysics.onGround) {
			moveAmount.y = 0;
			if (Input.GetAxisRaw("Jump") > .5) {
				moveAmount.y = jumpHeight;
			}
		}
		else{
			moveAmount.y -= gravity * Time.fixedDeltaTime;
			//Debug.Log (moveAmount);
			if(moveAmount.y <= -fallDeathSpeed){
				Debug.Log (moveAmount);
				reset();
			}
		}

		if(Mathf.Abs(climb) > .1f){
			pPhysics.grab();
		}

		pPhysics.move(moveAmount * Time.fixedDeltaTime);
		currentTile = map.getForeground((Vector2)this.transform.position);
		if(currentTile == TileSpecList.getTileSpec("Die")){
			reset();
		}

		if(Input.GetKey(KeyCode.Home)){
			reset();
		}
	}
Exemplo n.º 25
0
Arquivo: Map.cs Projeto: senkay/SRPGCK
 public void AddTileSpec(Texture2D tex)
 {
     TileSpec spec = new TileSpec();
     spec.texture = tex;
     tileSpecs.Add(spec);
     RemakeTexture();
 }
Exemplo n.º 26
0
 public abstract RectF GetTileSprite(TileSpec top, TileSpec right, TileSpec down, TileSpec left);
Exemplo n.º 27
0
 public override RectF GetTileSprite(TileSpec top, TileSpec right, TileSpec down, TileSpec left)
 {
     return(sprite);
 }