Exemple #1
0
        /* Add to list */
        public FX addFX(double x, double y, BlitRect blit, Point dir = null, int delay = 0, Boolean push = true, Boolean looped = false, Boolean killOffScreen = true, Boolean room = false)
        {
            var item = new FX(x, y, blit, bitmapData, canvasPoint, dir, delay, looped, killOffScreen);

            if (room)
            {
                if (push)
                {
                    roomFx.push(item);
                }
                else
                {
                    roomFx.unshift(item);
                }
            }
            else
            {
                if (push)
                {
                    fx.push(item);
                }
                else
                {
                    fx.unshift(item);
                }
            }
            return(item);
        }
Exemple #2
0
        public void copyPixels(BitmapData sourceBitmapData, Rectangle sourceRect, Point destPoint, BitmapData alphaBitmapData = null, Point alphaPoint = null, Boolean mergeAlpha = false)
        {
            if (sourceBitmapData.texture == null)
            {
                return;
            }

            XnaGame.Instance.FlashRenderer.CopyPixels(renderTarget, sourceBitmapData, sourceRect, destPoint, alphaBitmapData, alphaPoint, mergeAlpha);
        }
Exemple #3
0
        /* Prepares sprites and bitmaps for a game session */
        public void createRenderLayers(Sprite holder = null)
        {
            if (holder == null)
            {
                holder = game;
            }

            canvasPoint = new Point();
            canvas      = new Sprite();
            holder.addChild(canvas);

            backgroundShape      = new Shape();
            backgroundBitmapData = new BitmapData(16, 16, true, 0x0);

            //CONVERSION - simply made this a texture in the Content project
            //backgroundBitmapData.copyPixels(gameSpriteSheet, new Rectangle(0, 0, 16, 16), new Point());

            bitmapData       = new BitmapData((int)WIDTH, (int)HEIGHT, true, 0x0);
            bitmap           = new Shape();
            bitmapDataShadow = bitmapData.clone();
            bitmapShadow     = new Shape();
            guiBitmapData    = new BitmapData((int)WIDTH, (int)HEIGHT, true, 0x0);
            guiBitmap        = new Shape();

            canvas.addChild(backgroundShape);
            canvas.addChild(bitmapShadow);
            canvas.addChild(bitmap);
            game.addChild(guiBitmap);

            fx     = new Array <FX>();
            roomFx = new Array <FX>();

            camera = new CanvasCamera(canvasPoint, this);

            shakeOffset = new Point();
            shakeDirX   = 0;
            shakeDirY   = 0;
            slideX      = 0;
            slideY      = 0;
            sliding     = false;
            refresh     = true;

            //backgroundBitmapData.renderTarget = _backgroundRenderTarget;
            bitmapData.renderTarget       = _gameRenderTarget;
            bitmapDataShadow.renderTarget = _shadowRenderTarget;
            guiBitmapData.renderTarget    = _guiRenderTarget;
        }
Exemple #4
0
        /* Cyclically throw off pixel debris from where white pixels used to be on the blit
         * use dir to specify bitwise flags for directions able to throw debris in */
        public void bitmapDebris(BlitSprite blit, int x, int y, int dir = 15)
        {
            int    r, c;
            var    blitClip     = blit as BlitClip;
            var    source       = blitClip != null ? blitClip.frames[blitClip.frame] : blit.rect;
            var    compassIndex = 0;
            var    speedIndex   = 0;
            Point  compassPoint;
            var    p = new Point();
            double debrisSpeed;
            uint   u;

            for (r = 0; r < source.height; r++)
            {
                for (c = 0; c < source.width; c++)
                {
                    u = blit.spriteSheet.getPixel32((int)source.x + c, (int)source.y + r);
                    if (u == 0xFFFFFFFF || u == WALL_COL)
                    {
                        //u = 0xFFFFFFFF;
                        compassPoint = Room.compassPoints[compassIndex];
                        debrisSpeed  = DEBRIS_SPEEDS[speedIndex];
                        p.x          = compassPoint.x * debrisSpeed;
                        p.y          = compassPoint.y * debrisSpeed;
                        if ((Room.compass[compassIndex] & dir) > 0)
                        {
                            addFX(x * SCALE + c + blit.dx, y * SCALE + r + blit.dy, u == 0xFFFFFFFF ? debrisBlit : wallDebrisBlit, p.clone(), 0, true, true);
                        }
                        speedIndex++;
                        compassIndex++;
                        if (compassIndex >= Room.compassPoints.length)
                        {
                            compassIndex = 0;
                        }
                        if (speedIndex >= DEBRIS_SPEEDS.length)
                        {
                            speedIndex = 0;
                        }
                    }
                }
            }
        }
Exemple #5
0
 /* Shake the screen in any direction */
 public void shake(int x, int y, Point shakeSource = null)
 {
     if (!refresh)
     {
         return;
     }
     // sourced shakes drop off in intensity by distance
     // it stops the player feeling like they're in a cocktail shaker
     if (shakeSource != null)
     {
         double dist = Math.Abs(game.level.data.player.x - shakeSource.x) + Math.Abs(game.level.data.player.x - shakeSource.y);
         if (dist >= SHAKE_DIST_MAX)
         {
             return;
         }
         x = x * (int)((SHAKE_DIST_MAX - dist) * INV_SHAKE_DIST_MAX);
         y = y * (int)((SHAKE_DIST_MAX - dist) * INV_SHAKE_DIST_MAX);
         if (x == 0 && y == 0)
         {
             return;
         }
     }
     // ignore lesser shakes
     if (Math.Abs(x) < Math.Abs(shakeOffset.x))
     {
         return;
     }
     if (Math.Abs(y) < Math.Abs(shakeOffset.y))
     {
         return;
     }
     shakeOffset.x = x;
     shakeOffset.y = y;
     shakeDirX     = x > 0 ? 1 : -1;
     shakeDirY     = y > 0 ? 1 : -1;
 }
Exemple #6
0
        public void renderTo(double x, double y, BitmapData target)
        {
            var p = new Point(x, y);

            target.copyPixels(bitmapData, bitmapData.rect, p, null, null, true);
        }
Exemple #7
0
        /* Render */
        public void draw()
        {
            _alignXs.Clear();
            drawBorder();

            int       i, j;
            var       point = new Point();
            int       x;
            int       y      = BORDER_ALLOWANCE + offsetY;
            int       alignX = 0;
            int       alignY = 0;
            Rectangle charx;
            Point     offset;
            int       wordBeginning = 0;
            int       linesHeight   = lineSpacing * lines.length;

            for (i = 0; i < lines.length; i++, point.y += lineSpacing)
            {
                x = BORDER_ALLOWANCE + offsetX;

                wordBeginning = 0;
                for (j = 0; j < lines[i].length; j++)
                {
                    charx = lines[i][j];

                    // alignment to bitmap
                    if (align == "left")
                    {
                        alignX = 0;
                    }
                    else if (align == "center")
                    {
                        alignX = (int)(_width * 0.5 - (lineWidths[i] * 0.5 + BORDER_ALLOWANCE));
                    }
                    else if (align == "right")
                    {
                        alignX = (int)(_width - lineWidths[i]);
                    }
                    if (alignVert == "top")
                    {
                        alignY = 0;
                    }
                    else if (alignVert == "center")
                    {
                        alignY = (int)(_height * 0.5 - linesHeight * 0.5);
                    }
                    else if (alignVert == "bottom")
                    {
                        alignY = _height - linesHeight;
                    }

                    // print to bitmapdata
                    if (charx != null)
                    {
                        if (j > wordBeginning)
                        {
                            x += tracking;
                        }
                        point.x = alignX + x;
                        point.y = alignY + y + leading;
                        // mask characters that are outside the boundsRect
                        if (
                            point.x < boundsRect.x ||
                            point.y < boundsRect.y ||
                            point.x + charx.width >= boundsRect.x + boundsRect.width ||
                            point.y + charx.height >= boundsRect.y + boundsRect.height
                            )
                        {
                            // are they even in the bounds rect?
                            if (
                                point.x + charx.width > boundsRect.x &&
                                boundsRect.x + boundsRect.width > point.x &&
                                point.y + charx.height > boundsRect.y &&
                                boundsRect.y + boundsRect.height > point.y
                                )
                            {
                                // going to make a glib assumption that the TextBox won't be smaller than a single character
                                maskRect.x = point.x >= boundsRect.x ? charx.x : charx.x + (point.x - boundsRect.x);
                                maskRect.y = point.y >= boundsRect.y ? charx.y : charx.y + (point.y - boundsRect.y);
                                // NB: just changed this class over to a sprite sheet, no idea if the above lines actually work
                                maskRect.width  = point.x + charx.width <= boundsRect.x + boundsRect.width ? charx.width : (boundsRect.x + boundsRect.width) - point.x;
                                maskRect.height = point.y + charx.height <= boundsRect.y + boundsRect.height ? charx.height : (boundsRect.y + boundsRect.height) - point.y;
                                if (point.x < boundsRect.x)
                                {
                                    maskRect.x = boundsRect.x - point.x;
                                    point.x    = boundsRect.x;
                                }
                                if (point.y < boundsRect.y)
                                {
                                    maskRect.y = boundsRect.y - point.y;
                                    point.y    = boundsRect.y;
                                }
                                //bitmapData.copyPixels(spriteSheet, maskRect, point, null, null, true);
                            }
                        }
                        else
                        {
                            //bitmapData.copyPixels(spriteSheet, charx, point, null, null, true);
                        }
                        x += (int)charx.width;
                    }
                    else
                    {
                        x            += whitespaceLength;
                        wordBeginning = j + 1;
                    }
                }
                y += lineSpacing;
                _alignXs.Add(alignX);
                _position.x = alignX;
                _position.y = alignY;
            }

            if (_color != null)
            {
                transform.colorTransform = _color;
            }

            //CONVERSION - rendered in OnDraw now.
            //graphics.clear();
            //graphics.lineStyle(0, 0, 0);
            //graphics.beginBitmapFill(bitmapData);
            //graphics.drawRect(0, 0, _width, _height);
            //graphics.endFill();
        }
Exemple #8
0
 public void copyPixels(string text, Rectangle sourceRect, Point destPoint, BitmapData alphaBitmapData = null, Point alphaPoint = null, Boolean mergeAlpha = false)
 {
     XnaGame.Instance.FlashRenderer.DrawText(renderTarget, text, sourceRect, destPoint, Color.White, alphaBitmapData, alphaPoint, mergeAlpha);
 }
Exemple #9
0
 public void copyPixels(string text, Rectangle sourceRect, Point destPoint, float alpha)
 {
     XnaGame.Instance.FlashRenderer.DrawText(renderTarget, text, sourceRect, destPoint, Color.White * alpha);
 }
Exemple #10
0
    public void DrawText(RenderTarget2D renderTarget, string text, Rectangle sourceRect, Point destPoint, Color color, BitmapData alphaBitmapData = null, Point alphaPoint = null, Boolean mergeAlpha = false)
    {
        //XnaGame.Instance.SpriteBatch.Draw(sourceBitmapData.texture, new Vector2(destPoint.x, destPoint.y), new Microsoft.Xna.Framework.Rectangle(sourceRect.x, sourceRect.y, sourceRect.width, sourceRect.height), Color.White);

        var info = new RenderInfo
        {
            Text        = text,
            Destination = new Microsoft.Xna.Framework.Rectangle((int)destPoint.x, (int)destPoint.y, (int)sourceRect.width, (int)sourceRect.height),
            Color       = color
        };

        _queues[renderTarget ?? _defaultTarget].Add(info);
    }
Exemple #11
0
 public void DrawText(RenderTarget2D renderTarget, string text, Rectangle sourceRect, Point destPoint, uint color, float alpha)
 {
     this.DrawText(renderTarget, text, sourceRect, destPoint, UIntToColor(color) * alpha);
 }