Esempio n. 1
0
        public void renderPreview(Library.LevelData obj, double x, double y, BitmapData target)
        {
            BitmapData bitmapData = Level.getLevelBitmapData(obj.map, Level.ROOM_WIDTH, Level.ROOM_HEIGHT);
            var        p          = new Point(x, y);

            target.copyPixels(bitmapData, bitmapData.rect, p);
        }
Esempio n. 2
0
 public void update()
 {
     for (i = cols.length - 1; i > -1; i--)
     {
         g = cols[i];
         if (g.y > TOLERANCE)
         {
             g.y -= Math.random();
         }
         else if (g.y < -TOLERANCE)
         {
             g.y += Math.random();
         }
         else
         {
             cols.splice(i, 1);
         }
     }
     for (i = rows.length - 1; i > -1; i--)
     {
         g = rows[i];
         if (g.x > TOLERANCE)
         {
             g.x -= Math.random();
         }
         else if (g.x < -TOLERANCE)
         {
             g.x += Math.random();
         }
         else
         {
             rows.splice(i, 1);
         }
     }
 }
Esempio n. 3
0
        internal PointF TransformPoint(double x, double y)
        {
            var pt = new flash.geom.Point(x, y);

            pt = native.transformPoint(pt);
            return(new PointF((float)pt.x, (float)pt.y));
        }
Esempio n. 4
0
        public void setFood(double n, double total, double x, double y)
        {
            var ratio = maxFood / total;
            var value = System.Math.Ceiling(ratio * n);

            while (food != value)
            {
                p = pixels[food];
                if (food < value)
                {
                    spriteSheet.setPixel32((int)(p.x + blit.rect.x), (int)(p.y + blit.rect.y), col);
                    food++;
                }
                else if (food > value)
                {
                    if ((1.0 / maxFood) * food <= NEAR_DEATH)
                    {
                        renderer.addFX(x + p.x, y + p.y, renderer.debrisBlit, compassPoints[compassIndex], 0, true, true);
                        if (food == 1)
                        {
                            renderer.bitmapDebris(blit, (int)(x * Renderer.INV_SCALE), (int)(y * Renderer.INV_SCALE), 0);
                        }
                    }
                    spriteSheet.setPixel32((int)(p.x + blit.rect.x), (int)(p.y + blit.rect.y), deadCol);
                    compassIndex++;
                    if (compassIndex >= compassPoints.length)
                    {
                        compassIndex = 0;
                    }
                    food--;
                }
            }
        }
Esempio n. 5
0
 public GlitchMap()
 {
     rows        = new Array <Point>();
     cols        = new Array <Point>();
     p           = new Point();
     rect        = new Rectangle();
     glitchIndex = 0;
 }
Esempio n. 6
0
 public void init(Point door = null, int revealDir = -1)
 {
     if (type == ADVENTURE)
     {
         adventureFill(door, revealDir);
     }
     else if (type == PUZZLE)
     {
         clear();
     }
     roomTurns++;
 }
Esempio n. 7
0
 public void apply(BitmapData target, int offsetX = 0, int offsetY = 0)
 {
     rect.y      = 0;
     rect.width  = 1;
     rect.height = target.height;
     for (i = cols.length - 1; i > -1; i--)
     {
         g      = cols[i];
         rect.x = p.x = g.x + offsetX;
         p.y    = g.y;
         target.copyPixels(target, rect, p);
     }
     rect.x      = 0;
     rect.width  = target.width;
     rect.height = 1;
     for (i = rows.length - 1; i > -1; i--)
     {
         g      = rows[i];
         rect.y = p.y = g.y + offsetY;
         p.x    = g.x;
         target.copyPixels(target, rect, p);
     }
 }
Esempio n. 8
0
        /* Get where the doors should be in a new room (accounting for a door destroyed as well) */
        public Array <Point> getDoors(Point door = null, int revealDir = -1)
        {
            int   i;
            Point p;
            int   value;
            int   skipDir = -1;
            var   doors   = this.doors.slice();

            if (revealDir == NORTH)
            {
                skipDir = SOUTH;
                door.y  = height - 1;
            }
            else if (revealDir == EAST)
            {
                skipDir = WEST;
                door.x  = 0;
            }
            else if (revealDir == SOUTH)
            {
                skipDir = NORTH;
                door.y  = 0;
            }
            else if (revealDir == WEST)
            {
                skipDir = EAST;
                door.x  = width - 1;
            }
            int[] dists = { 0, 0, 0, 0 };
            int   length;
            int   farthestLength = 0;
            int   farthestIndex  = -1;
            int   closestLength  = int.MaxValue;
            int   closestIndex   = -1;

            // randomise door positions
            if (skipDir > -1)
            {
                for (i = 0; i < 4; i++)
                {
                    if (i == skipDir)
                    {
                        dists[i] = 0;
                    }
                    else
                    {
                        p = doors[i];
                        if (i == NORTH || i == SOUTH)
                        {
                            doors[i].x = 1 + random.rangeInt(width - 2);
                        }
                        else if (i == EAST || i == WEST)
                        {
                            doors[i].y = 1 + random.rangeInt(height - 2);
                        }
                        length = (int)(Math.Abs(p.x - door.x) + Math.Abs(p.y - door.y));
                        if (length > farthestLength)
                        {
                            farthestLength = length;
                            farthestIndex  = i;
                        }
                        if (length < closestLength)
                        {
                            closestLength = length;
                            closestIndex  = i;
                        }
                    }
                }
                // the ending is always the farthest away from the door entered
                dists[farthestIndex] = INCREMENT;
            }
            else
            {
                // the inital room must only show EAST or WEST - 1st door must always be visible
                dists[(random.coinFlip() ? EAST : WEST)] = INCREMENT;
            }
            for (i = 0; i < 4; i++)
            {
                value = dists[i];
                if (i == skipDir)
                {
                    doors[i] = door;
                    continue;
                }
                p = doors[i];
                map[(int)p.y][(int)p.x] = DOOR | ENEMY | (1 << (i + M_DIR_SHIFT));
                if (endingDist <= 2 && value == INCREMENT)
                {
                    value = ENDING;
                }
                map[(int)p.y][(int)p.x] |= value;
            }
            return(doors);
        }
Esempio n. 9
0
 extern public virtual uint threshold(BitmapData sourceBitmapData, Rectangle sourceRect, Point destPoint,
                                      string operation, uint threshold, uint color = 0, uint mask = 0xffffffff, bool copySource = false);
Esempio n. 10
0
 extern public virtual int pixelDissolve(BitmapData sourceBitmapData, Rectangle sourceRect, Point destPoint, int randomSeed = 0, int numPixels = 0, uint fillColor = 0);
Esempio n. 11
0
 extern public virtual void merge(BitmapData sourceBitmapData, Rectangle sourceRect, Point destPoint, uint redMultiplier, uint greenMultiplier, uint blueMultiplier, uint alphaMultiplier);
Esempio n. 12
0
 extern public virtual bool hitTest(Point firstPoint, uint firstAlphaThreshold, Object secondObject, Point secondBitmapDataPoint = null, uint secondAlphaThreshold = 1);
Esempio n. 13
0
 extern public virtual void copyPixels(BitmapData sourceBitmapData, Rectangle sourceRect, Point destPoint, BitmapData alphaBitmapData = null, Point alphaPoint = null, bool mergeAlpha = false);
Esempio n. 14
0
 extern public virtual void copyChannel(BitmapData sourceBitmapData, Rectangle sourceRect, Point destPoint, uint sourceChannel, uint destChannel);
Esempio n. 15
0
 public virtual void applyFilter(BitmapData sourceBitmapData, Rectangle sourceRect, Point destPoint,
                                 BitmapFilter filter)
 {
     filter.apply(sourceBitmapData, sourceRect, this, destPoint);
 }
Esempio n. 16
0
        /* Create indestructible walls around unreachable areas and fill insides with VOID */
        public void fillVoid(Point entry)
        {
            Point p       = entry;
            var   voidMap = create2DArray(width, height, 0);
            int   i;
            int   x;
            int   y;
            var   points = new Array <Point> {
                p
            };
            int property = 0;
            int length   = points.Count;

            voidMap[(int)p.y][(int)p.x] = 1;

            while (length > 0)
            {
                while ((length--) > 0)
                {
                    p        = points.shift();
                    x        = (int)p.x;
                    y        = (int)p.y;
                    property = map[y][x];
                    if (((property & WALL) == WALL) && !((property & ENEMY) > 0))
                    {
                        continue;
                    }
                    // cardinals
                    if (y > 0 && voidMap[y - 1][x] == 0)
                    {
                        points.push(new Point(x, y - 1));
                        voidMap[y - 1][x] = 1;
                    }
                    if (x < width - 1 && voidMap[y][x + 1] == 0)
                    {
                        points.push(new Point(x + 1, y));
                        voidMap[y][x + 1] = 1;
                    }
                    if (y < height - 1 && voidMap[y + 1][x] == 0)
                    {
                        points.push(new Point(x, y + 1));
                        voidMap[y + 1][x] = 1;
                    }
                    if (x > 0 && voidMap[y][x - 1] == 0)
                    {
                        points.push(new Point(x - 1, y));
                        voidMap[y][x - 1] = 1;
                    }
                }
                length = points.Count;
            }
            int r, c;

            for (r = 0; r < height; r++)
            {
                for (c = 0; c < width; c++)
                {
                    if (voidMap[r][c] == 0 && !((map[r][c] & INDESTRUCTIBLE) > 0))
                    {
                        map[r][c] = VOID;
                    }
                    if (voidMap[r][c] == 1 && ((property & WALL) == WALL) && !((property & ENEMY) > 0) &&
                        (
                            (r > 0 && voidMap[r - 1][c] == 0) ||
                            (c < width - 1 && voidMap[r][c + 1] == 0) ||
                            (r < height - 1 && voidMap[r + 1][c] == 0) ||
                            (c > 0 && voidMap[r][c - 1] == 0)
                        )
                        )
                    {
                        map[r][c] = WALL | INDESTRUCTIBLE;
                    }
                }
            }
        }
Esempio n. 17
0
        /* Creates a random room with enemies and doors to escape towards an ending
         * -
         * also used for debugging
         */
        public void adventureFill(Point door = null, int revealDir = -1)
        {
            clear();
            var doors = getDoors(door, revealDir);
            var walls = random.rangeInt(width + height) + width + height;

            scatterFill(1, 1, width - 2, height - 2, map, WALL, walls);
            //scatterStrips(1, 1, width - 2, height - 2, map, WALL, (roomTurns % 10) + (width + height) * 2, 2 + random.rangeInt(2), 2 + random.rangeInt(2));
            //fill(1, 1, width - 2, height - 2, map, WALL);

            var recipes = new [] {
                ENEMY | VIRUS,
                ENEMY | TRAP,
                ENEMY | TURNER,
                ENEMY | MOVER,
                ENEMY | MOVER | M_LEFT | M_RIGHT | M_UP | M_DOWN,
                ALLY | SWAP,
                SWAP | WALL
            };
            // when changing the recipe list, update this index
            int allyIndex = 5;

            var enemySpice = new [] {
                0,
                GENERATOR | TIMER_3,
                WALL,
                BOMB,
                BOMB | WALL,
                GENERATOR | TIMER_3 | WALL,
                BOMB | GENERATOR | TIMER_3,
                BOMB | GENERATOR | TIMER_3 | WALL
            };

            // change to 0 for a blank room to debug in
            int total = width + height + random.rangeInt(width);
            int turns;
            int dir;
            int compassPos = NORTH;
            int item;
            int bombSpice      = 1 << 0;
            int wallSpice      = 1 << 1;
            int generatorSpice = 1 << 2;
            int recipeRange    = Math.Min((DIST_TO_ENDING - endingDist) + 3, recipes.Length);
            int spiceRange     = Math.Min((DIST_TO_ENDING - endingDist) + 1, enemySpice.Length);
            int spice;
            int n;
            int generatorVirii = 0;

            while ((total--) > 0)
            {
                n = random.rangeInt(recipeRange);
                // reroll swap recipes every second pick
                while (
                    (((total & 1) == 1) && ((recipes[n] & SWAP) == SWAP))
                    )
                {
                    n = random.rangeInt(recipeRange);
                }
                item = recipes[n];
                if ((item & ENEMY) == ENEMY)
                {
                    if ((item & TURNER) == TURNER)
                    {
                        dir   = compass[random.rangeInt(compass.Length)];
                        item |= dir;
                    }
                    else if ((item & TRAP) == TRAP)
                    {
                        dir   = 1 + random.rangeInt(15);
                        dir <<= M_DIR_SHIFT;
                        item |= dir;
                    }
                    else if ((item & MOVER) == MOVER)
                    {
                        if (!((item & M_UP_DOWN_LEFT_RIGHT) > 0))
                        {
                            item |= random.coinFlip() ? (M_UP | M_DOWN) : (M_LEFT | M_RIGHT);
                        }
                    }
                    if (random.coinFlip())
                    {
                        spice = random.rangeInt(spiceRange);
                        if (((enemySpice[spice] & GENERATOR) == GENERATOR) && ((item & VIRUS) == VIRUS))
                        {
                            if (generatorVirii == 0)
                            {
                                item |= enemySpice[spice];
                            }
                            generatorVirii++;
                        }
                        else
                        {
                            item |= enemySpice[spice];
                        }
                    }
                }
                else if ((item & SWAP) == SWAP)
                {
                    spice = random.rangeInt(spiceRange);
                    if ((enemySpice[spice] & BOMB) == BOMB)
                    {
                        item |= BOMB;
                    }
                }
                //item = VIRUS | ENEMY;
                placeRandom(1, 1, width - 2, height - 2, map, item, WALL);
            }
            // clear a path to the doors
            connectDoors(doors);

            fillVoid(revealDir == -1 ?  new Point(startX, startY) : doors[revealDir]);

            // debugging recipes:
            //map[startY][startX + 1] = ENEMY | VIRUS;
            //map[startY + 1][startX + 1] = ENEMY | VIRUS;
            //map[startY][startX + 3] = ENEMY | VIRUS;
            //map[startY + 1][startX + 3] = ALLY | SWAP;
            //map[startY + 3][startX] = ENEMY | WALL | VIRUS | GENERATOR | TIMER_3;
            //map[startY][startX + 2] = ENEMY | MOVER | BOMB;
            //map[startY][startX + 3] = ENEMY | MOVER | BOMB;
            //map[startY][startX + 1] = WALL | SWAP;
            //map[startY][startX + 2] = ALLY | SWAP;
            //map[startY][startX + 3] = ALLY | SWAP;
            //map[startY][startX] = ENEMY | TURNER | UP | WALL | GENERATOR | TIMER_3;
            //map[startY][startX] = ENEMY | TURNER | RIGHT | WALL;
        }
Esempio n. 18
0
 extern public virtual void paletteMap(BitmapData sourceBitmapData, Rectangle sourceRect, Point destPoint, Array redArray = null, Array greenArray = null, Array blueArray = null, Array alphaArray = null);