Esempio n. 1
0
 public override void decorate(Level level, int x, int y)
 {
     Random random = new Random((x + y * 1000) * 341871231);
     double r = 0.4;
     for (int i = 0; i < 1000; i++)
     {
         int face = random.Next(4);
         if (face == 0 && level.getBlock(x - 1, y).solidRender)
         {
             torchSprite.x -= r;
             break;
         }
         if (face == 1 && level.getBlock(x, y - 1).solidRender)
         {
             torchSprite.z -= r;
             break;
         }
         if (face == 2 && level.getBlock(x + 1, y).solidRender)
         {
             torchSprite.x += r;
             break;
         }
         if (face == 3 && level.getBlock(x, y + 1).solidRender)
         {
             torchSprite.z += r;
             break;
         }
     }
 }
Esempio n. 2
0
 public void switchLevel(LevelEnum levelEnum, int id)
 {
     pauseTime = 30;
     level.removeEntityImmediately(player);
     level = Level.LoadLevel(this, levelEnum);
     level.findSpawn(id);
     player.x = level.xSpawn;
     player.z = level.ySpawn;
     ((LadderBlock) level.getBlock(level.xSpawn, level.ySpawn)).wait = true;
     player.x += Math.Sin(player.rot) * 0.2;
     player.z += Math.Cos(player.rot) * 0.2;
     level.addEntity(player);
 }
Esempio n. 3
0
        private void renderFloor(Level level)
        {
            for (int y = 0; y < height; y++)
            {
                double yd = ((y + 0.5) - yCenter) / fov;

                bool floor = true;
                double zd = (4 - zCam * 8) / yd;
                if (yd < 0)
                {
                    floor = false;
                    zd = (4 + zCam * 8) / -yd;
                }

                for (int x = 0; x < width; x++)
                {
                    if (zBuffer[x + y * width] <= zd) continue;

                    double xd = (xCenter - x) / fov;
                    xd *= zd;

                    double xx = xd * rCos + zd * rSin + (xCam + 0.5) * 8;
                    double yy = zd * rCos - xd * rSin + (yCam + 0.5) * 8;

                    int xPix = (int)(xx * 2);
                    int yPix = (int)(yy * 2);
                    int xTile = xPix >> 4;
                    int yTile = yPix >> 4;

                    Block block = level.getBlock(xTile, yTile);
                    int col = block.floorCol;
                    int tex = block.floorTex;
                    if (!floor)
                    {
                        col = block.ceilCol;
                        tex = block.ceilTex;
                    }

                    if (tex < 0)
                    {
                        zBuffer[x + y * width] = -1;
                    }
                    else
                    {
                        zBuffer[x + y * width] = zd;
                        pixels[x + y * width] = Art.floors.pixels[((xPix & 15) + (tex % 8) * 16) + ((yPix & 15) + (tex / 8) * 16) * 128] * col;
                    }
                }
            }
        }