Exemple #1
0
        public List <cAABB> getCollidableBlocks(cAABB with)
        {
            List <cAABB> boxes = new List <cAABB>();

            const int offset = 1; //def: 1

            //Vector2i ctile = ToMapPos(with.center);
            Vector2i minTile = ToMapPos(with.topLeft);
            Vector2i maxTile = ToMapPos(with.rightBottom);

            //int lastTileID = -1;

            for (int y = minTile.Y - offset; y <= maxTile.Y + offset; y++)
            {
                for (int x = minTile.X - offset; x <= maxTile.X + offset; x++)
                {
                    if (y >= 0 && x >= 0 && y < this.m_Level1.Height && x < this.m_Level1.Width)
                    {
                        cTile tile = this.GetCurrentLevel().GetTileAtXY(x, y);

                        TileType tt = tile.Type;
                        //int tid = tile.IdCode;

                        if (/*lastTileID != tid &&*/ (tt == TileType.WALL || tt == TileType.ONEWAY_PLATFORM))
                        {
                            // tile.PlayerCollidable = true;
                            //lastTileID = tid;
                            boxes.Add(this.getAABBFromMapPos(new Vector2i(x, y)));
                        }
                    }
                }
            }

            return(boxes);
        }
Exemple #2
0
        private NeighInfo getNumOfLinearNeighsByCode(cMapData map, Vector2i tile_pos, TileType type)
        {
            NeighInfo returner = new NeighInfo();

            int tx = tile_pos.X;
            int ty = tile_pos.Y;

            cTile left  = map.GetTileAtXY(tx - 1, ty);
            cTile top   = map.GetTileAtXY(tx, ty - 1);
            cTile right = map.GetTileAtXY(tx + 1, ty);
            cTile bot   = map.GetTileAtXY(tx, ty + 1);

            if (left != null && left.Type == type)
            {
                returner.HasLeft = true;
            }

            if (top != null && top.Type == type)
            {
                returner.HasTop = true;
            }

            if (right != null && right.Type == type)
            {
                returner.HasRight = true;
            }

            if (bot != null && bot.Type == type)
            {
                returner.HasBottom = true;
            }

            return(returner);
        }
Exemple #3
0
        public bool isWallOrPlatform(Vector2f world_pos)
        {
            Vector2i map = ToMapPos(world_pos);
            cTile    t   = currentLevel.GetTileAtXY(map.X, map.Y);

            return(t != null ? t.Type == TileType.WALL || t.Type == TileType.ONEWAY_PLATFORM : true);
        }
Exemple #4
0
        public bool IsObastacleAtPos(Vector2f world_pos)
        {
            // TODO: make it elegant
            Vector2i map = ToMapPos(world_pos);
            cTile    t   = currentLevel.GetTileAtXY(map.X, map.Y);

            return(t != null ? !t.IsWalkAble() : true);
        }
Exemple #5
0
        private void renderTilesToTexture(RenderTarget destination)
        {
            //m_TextureOfTiles.Clear(Color.Black);



            cTile    tempTile = null;
            Vector2f drawPos  = new Vector2f();

            const uint spaceOffset = 0;



            const int subTILE_SIZE = 32; //40
                                         //const int diff = (TILE_SIZE > subTILE_SIZE) ? (TILE_SIZE - subTILE_SIZE) : 0;
            int startTileX = (int)drawTileBounds.topLeft.X;
            int startTileY = (int)drawTileBounds.topLeft.Y;
            int endTileX   = (int)drawTileBounds.rightBottom.X;
            int endTileY   = (int)drawTileBounds.rightBottom.Y;
            //m_TextureOfTiles.Draw(m_BcgrSprite);
            Vector2f tempSize = new Vector2f(Constants.TILE_SIZE, Constants.TILE_SIZE);


            for (int y = startTileY; y < endTileY; y++)
            {
                for (int x = startTileX; x < endTileX; x++)
                {
                    tempTile = m_Level1.GetTileAtXY(x, y);

                    drawPos.X = (m_WorldBounds.topLeft.X + x * Constants.TILE_SIZE) + spaceOffset;
                    drawPos.Y = (m_WorldBounds.topLeft.Y + y * Constants.TILE_SIZE) + spaceOffset;


                    //tempRS.setPosition(drawPos);
                    if (tempTile.Type != TileType.EMPTY)
                    {
                        if (tempTile.PlayerCollidable)
                        {
                            tempSprite.Color = Color.Red;
                        }
                        else
                        {
                            tempSprite.Color = Color.White;
                        }

                        tempSprite.Position    = drawPos;
                        tempSprite.TextureRect = tempTile.PosOnTexture;

                        destination.Draw(tempSprite);
                    }
                }
            }

            //m_TextureOfTiles.Display();
        }
Exemple #6
0
        /// <summary>
        /// Itt választjuk ki és állítjuk be előre a kirjazoláshoz, hogy melyik csempéhez milyen al-textúra tartozik (több féle fal van, attól függ, hol és hány másik fal kapcsolódik az adott falhoz)
        /// </summary>
        private void initTileSprites()
        {
            cTile    tempTile      = null;
            Vector2i tilePos       = new Vector2i();
            Vector2f tileCenterTop = new Vector2f();

            for (int y = 0; y < m_Level1.Height; y++)
            {
                for (int x = 0; x < m_Level1.Width; x++)
                {
                    tempTile  = m_Level1.GetTileAtXY(x, y);
                    tilePos.X = x;
                    tilePos.Y = y;

                    tileCenterTop    = this.ToWorldPos(tilePos);
                    tileCenterTop.X += Constants.TILE_SIZE_HALF;
                    tileCenterTop.Y += Constants.TILE_SIZE_HALF;

                    tempTile.PosOnTexture = TileMask.NONE;

                    if (tempTile.Type == TileType.WALL)
                    {
                        NeighInfo info = getNumOfLinearNeighsByCode(m_Level1, tilePos, TileType.WALL);

                        if (info.NumNeighs == 1)
                        {
                            /* cLight l = cLightSystem.GetEnvironLight(tileCenterTop, 32.0f, Color.White);
                             * l.Bleed = 1.6f;
                             * l.LinearizeFactor = 0.4f;
                             * l.Color = new Color(246, 205, 105, 255);
                             * pScene.LightMap.AddStaticLight(l);*/
                        }

                        if (info.isAlone())
                        {
                            tempTile.PosOnTexture = TileMask.ALONE_BOT_WITH_TOP; // alone;

                            /* cLight l = cLightSystem.GetEnvironLight(tileCenterTop, 32.0f, Color.White);
                             * l.Bleed = 1.6f;
                             * l.LinearizeFactor = 0.4f;
                             * l.Color = new Color(246, 205, 105, 255);
                             * pScene.LightMap.AddStaticLight(l);*/
                        }
                        else
                        {
                            //egyedül van-e

                            if (!info.HasTop)
                            {
                                if (!info.HasBottom)
                                {
                                    if (!info.HasLeft)
                                    {
                                        tempTile.PosOnTexture = TileMask.NO_TOPBOT_LEFT;
                                    }
                                    else
                                    if (!info.HasRight)
                                    {
                                        tempTile.PosOnTexture = TileMask.NO_TOPBOT_RIGHT;
                                    }
                                    else
                                    {
                                        tempTile.PosOnTexture = TileMask.NO_TOPBOT_MIDDLE;
                                    }
                                }
                                else
                                {
                                    if (info.HasLeft)
                                    {
                                        if (info.HasRight)
                                        {
                                            tempTile.PosOnTexture = TileMask.TOP_MIDDLE;
                                        }
                                        else
                                        {
                                            tempTile.PosOnTexture = TileMask.TOP_RIGHT;
                                        }
                                    }
                                    else
                                    {
                                        if (info.HasRight)
                                        {
                                            tempTile.PosOnTexture = TileMask.TOP_LEFT;
                                        }
                                        else
                                        {
                                            tempTile.PosOnTexture = TileMask.ALONE_TOP_WITH_BOT;
                                        }
                                    }
                                }
                            }
                            else
                            if (!info.HasBottom)
                            {
                                if (info.HasLeft)
                                {
                                    if (info.HasRight)
                                    {
                                        tempTile.PosOnTexture = TileMask.BOTTOM_MIDDLE;
                                    }
                                    else
                                    {
                                        tempTile.PosOnTexture = TileMask.BOTTOM_RIGHT;
                                    }
                                }
                                else
                                {
                                    if (info.HasRight)
                                    {
                                        tempTile.PosOnTexture = TileMask.BOTTOM_LEFT;
                                    }
                                    else
                                    {
                                        tempTile.PosOnTexture = TileMask.ALONE_BOT_WITH_TOP;
                                    }
                                }
                            }
                            else
                            if (!info.HasLeft)
                            {
                                if (info.HasRight)
                                {
                                    tempTile.PosOnTexture = TileMask.MIDDLE_LEFT;
                                }
                                else
                                {
                                    tempTile.PosOnTexture = TileMask.ALONE;
                                }
                            }
                            else
                            if (!info.HasRight)
                            {
                                tempTile.PosOnTexture = TileMask.MIDDLE_RIGHT;
                            }
                            else
                            {
                                tempTile.PosOnTexture = TileMask.MIDDLE_CENTRE;
                                //tempTile.PosOnTexture = TileMask.EMPTY; //looks weird
                            }
                        }
                    }
                    else
                    if (tempTile.Type == TileType.EMPTY)
                    {
                    }
                    else
                    if (tempTile.Type == TileType.ONEWAY_PLATFORM)
                    {
                        tempTile.PosOnTexture = TileMask.ONE_WAY_PLATFORM;

                        /*
                         * cLight l = cLightSystem.GetEnvironLight(tileCenterTop, 32.0f, Color.White);
                         * l.Bleed = 2.6f;
                         * l.LinearizeFactor = 0.3f;
                         * pScene.LightMap.AddStaticLight(l);*/

                        //pScene.LightMap.AddStaticLight(cLightSystem.GetEnvironLight(this.ToWorldPos(tilePos), 50.0f, Color.Yellow));
                    }
                    else
                    if (tempTile.Type == TileType.LEVEL_START)
                    {
                        //top-left
                        Vector2f levelStartGroundPos = this.ToWorldPos(new Vector2i(x, y));

                        Texture t = cAssetManager.GetTexture("door1_sm");

                        Vector2f textureSize = new Vector2f(t.Size.X, t.Size.Y);

                        cAABB    bounds     = pScene.WolrdEnv.CalcBBOnGroundByTexture(levelStartGroundPos, textureSize);
                        Vector2f texturePos = bounds.topLeft;

                        bounds.Scale(new Vector2f(0.8f, 0.8f), new Vector2f(bounds.center.X, bounds.rightBottom.Y));

                        levelStartRegion = bounds;

                        pScene.WolrdEnv.PlaceOnGround(texturePos, t, bounds);



                        pScene.LightMap.AddStaticLight(cLightSystem.GetEnvironLight(bounds.center, bounds.halfDims.X * 3.0f, Color.Green));
                    }
                    else
                    if (tempTile.Type == TileType.LEVEL_END)
                    {
                        //top-left
                        Vector2f levelEndGroundPos = this.ToWorldPos(new Vector2i(x, y));

                        Texture t = cAssetManager.GetTexture("door1_sm");

                        Vector2f textureSize = new Vector2f(t.Size.X, t.Size.Y);

                        cAABB    bounds     = pScene.WolrdEnv.CalcBBOnGroundByTexture(levelEndGroundPos, textureSize);
                        Vector2f texturePos = bounds.topLeft;

                        bounds.Scale(new Vector2f(0.8f, 0.8f), new Vector2f(bounds.center.X, bounds.rightBottom.Y));

                        levelEndRegion = bounds;

                        pScene.WolrdEnv.PlaceOnGround(texturePos, t, bounds);


                        pScene.LightMap.AddStaticLight(cLightSystem.GetEnvironLight(bounds.center, bounds.halfDims.X * 3.0f, Color.Red));
                    }
                }
            }
        }
Exemple #7
0
        /// <summary>
        /// Négyzetes mintájú vízeket azonosítja
        /// </summary>
        /// <returns></returns>
        public List <cWaterBlock> GetWaterBlocks()
        {
            List <cWaterBlock> waters = new List <cWaterBlock>();

            try
            {
                int h          = 0;
                int lastH      = 0;
                int maxHOffset = 0;

                Vector2f topLeft     = new Vector2f();
                Vector2f bottomRight = new Vector2f();

                bool wasWater = false;
                int  w        = 0;

                while (h < m_Level1.Height)
                {
                    cTile currentTile = m_Level1.GetTileAtXY(w, h);
                    if (currentTile.Type == TileType.WATER && !currentTile.IsCheckedWater)
                    {
                        if (!wasWater)
                        {
                            wasWater  = true;
                            topLeft.X = w * Constants.TILE_SIZE;
                            topLeft.Y = h * Constants.TILE_SIZE;
                            lastH     = h;
                        }

                        int heightOffset = 0;

                        bool  water = true;
                        cTile tile  = null;
                        while (water)
                        {
                            tile = m_Level1.GetTileAtXY(w, h + heightOffset);
                            if (tile.Type == TileType.WATER)
                            {
                                tile.IsCheckedWater = true;
                                heightOffset       += 1;
                            }
                            else
                            {
                                water = false;
                            }
                        }

                        bottomRight.X = (w + 1) * Constants.TILE_SIZE;
                        int a = 0; // heightOffset <= 1 ? 1 : 0;
                        bottomRight.Y = (h + heightOffset + a) * Constants.TILE_SIZE;

                        if (heightOffset > maxHOffset)
                        {
                            maxHOffset = heightOffset;
                        }
                    }
                    else
                    {
                        if (wasWater)
                        {
                            waters.Add(new cWaterBlock(new cAABB(topLeft, new Vector2f(Math.Abs(bottomRight.X - topLeft.X), Math.Abs(bottomRight.Y - topLeft.Y)))));
                            wasWater = false;
                            h        = lastH;
                        }
                    }

                    w++;

                    if (w >= m_Level1.Width)
                    {
                        w = 0;

                        h         += 1; // (maxHOffset + 1);
                        maxHOffset = 0;
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(waters);
        }
Exemple #8
0
 public cTile(cTile other)
 {
     this.IdCode = other.IdCode;
     this.Type   = other.Type;
 }