Beispiel #1
0
        public static TileMap Instance(Game game, String mapName, Sprite personajePrincipal, int posPersonajeTileX, int posPersonajeTileY)
        {
            if (instance == null)
            {
                instance = new TileMap(game, mapName,  personajePrincipal,  posPersonajeTileX,  posPersonajeTileY);

            }
            return instance;
        }
Beispiel #2
0
        public static TileMap InstanceTileMap(Game game, String mapName, Texture2D parallaxBackground, Sprite spriteScrolling, int posPersonajeTileX, int posPersonajeTileY)
        {
            if (instance == null)
            {
                instance = new TileMap( game,  mapName,  parallaxBackground,  spriteScrolling,  posPersonajeTileX,  posPersonajeTileY);

            }
            return instance;
        }
Beispiel #3
0
        /*
         * Actualiza los sprites con las
         * colisiones de los Tiles y
         * otros Sprites.
         */
        private void actualizarColisiones(Sprite objSprite, long elapsedTime)
        {
            if (objSprite.solidoTiles)
            {
                // Corregir x
                float dx   = objSprite.velocidadX;
                float oldX = objSprite.x;
                float newX = oldX + dx * elapsedTime;
                Point?tile = getColisionTile(objSprite, newX, objSprite.y);
                if (tile != null)
                {
                    // line up with the tile boundary
                    if (dx > 0)
                    {
                        objSprite.x =
                            TileMap.tilesAPixels(tile.Value.X)
                            - objSprite.animacion.obtenerImagen().Width
                            - (objSprite.x - objSprite.x);
                    }
                    else if (dx < 0)
                    {
                        objSprite.x = TileMap.tilesAPixels(tile.Value.X + 1);
                    }
                    objSprite.evento_ColisionHorizontalTile();
                }

                // Corregir y
                float dy   = objSprite.velocidadY;
                float oldY = objSprite.y;
                float newY = oldY + dy * elapsedTime;
                tile = getColisionTile(objSprite, objSprite.x, newY);
                if (tile != null)
                {
                    // line up with the tile boundary
                    if (dy > 0)
                    {
                        objSprite.y = TileMap.tilesAPixels(tile.Value.Y)
                                      - objSprite.animacion.obtenerImagen().Height;
                    }
                    else if (dy < 0)
                    {
                        objSprite.y = TileMap.tilesAPixels(tile.Value.Y + 1);
                    }
                    objSprite.evento_ColisionVerticalTile();
                }
            }

            //if (objSprite.solidoSprites || objSprite is BoxCollisionSprite) {
            if (objSprite.solidoSprites)
            {
                //Colision Horizontal Sprites
                float  dx     = objSprite.velocidadX;
                float  oldX   = objSprite.x;
                float  newX   = oldX + dx * elapsedTime;
                Sprite sprite = getColisionSprite(objSprite, newX, objSprite.y);
                if (sprite != null && sprite.solidoSprites)
                {
                    sprite.evento_ColisionHorizontalSprite(objSprite);
                }
                //Colision Vertical Sprites
                float dy   = objSprite.velocidadY;
                float oldY = objSprite.y;
                float newY = oldY + dy * elapsedTime;
                sprite = getColisionSprite(objSprite, objSprite.x, newY);
                if (sprite != null && sprite.solidoSprites)
                {
                    sprite.evento_ColisionVerticalSprite(objSprite);
                }
            }
        }