public override void Draw(CanvasContext2D context)
 {
     context.Save();
     context.FillStyle = "blue";
     context.FillRect(X - 13, Y - 13, 26, 26);
     context.Restore();
 }
        public override void Update(CanvasContext2D context)
        {
            context.Save();
            context.BeginPath();
            context.Rect(0, 0, 800, 320);
            context.ClosePath();
            context.Clip();

            float speed = -(_level.Curve * _level.Speed * 50);
            if (_level.Left && _level.Speed > 0) speed += 1;
            if (_level.Right && _level.Speed > 0) speed -= 1;

            UpdateExplosions(context, speed);

            UpdateFlak(context, speed);

            foreach (Cloud cloud in _clouds)
            {
                float scale = (400 - cloud.Y) / 400;

                cloud.X = (cloud.X - (0.3f - speed) * scale + 2400) % 2400;

                context.DrawImage(
                    _cloudImage,
                    cloud.X - 1200,
                    cloud.Y - (_cloudImage.NaturalHeight / 2) * scale,
                    _cloudImage.NaturalWidth * scale,
                    _cloudImage.NaturalHeight * scale);
            }
            context.Restore();
        }
        public void Draw(CanvasContext2D context, int wX, int wY, int wWidth, int wHeight)
        {
            context.Save();

            wWidth = Math.Min(wWidth, myTotalRegionWidth);
            wHeight = Math.Min(wHeight, myTotalRegionHeight);

            foreach (var gameMapLayout in GameMapLayouts) {
                ( (DrawGameMap) gameMapLayout.GameMap ).Draw(context, gameMapLayout.X + wX, gameMapLayout.Y + wY, wWidth, wHeight);
            }

            context.Restore();
        }
        public void Draw(CanvasContext2D context, int tileX, int tileY, int wWidth, int wHeight)
        {
            context.Save();

            for (int x = tileX; x < wWidth; x++) {
                for (int y = tileY; y < wHeight; y++) {
                    DrawTile tile = (DrawTile) TileMap.GetSafe(x, y);
                    if (tile == null)
                        continue;
                    tile.Draw(context, tileX, tileY, x, y);
                }
            }
            context.Restore();
        }
        public void Draw(CanvasContext2D context)
        {
            context.Save();
            switch (GameMode) {
                case GameMode.TileEdit:

                    break;
                case GameMode.Play:
                    screenOffset.X = Game.Screen.Width / 2 - WindowManager.Width * Scale.X / 2;
                    screenOffset.Y = Game.Screen.Height / 2 - WindowManager.Height * Scale.Y / 2;
                    context.Translate(screenOffset.X, screenOffset.Y);

                    playDraw(context);

                    break;
            }

            context.Restore();
        }
        public void Draw(CanvasContext2D context, int _x, int _y, int mapX, int mapY)
        {
            context.Save();
            context.Translate(_x + mapX * ZombieGameConfig.TileSize, _y + mapY * ZombieGameConfig.TileSize);

            /*
            context.Translate(ZombieGameConfig.TileSize / 2, ZombieGameConfig.TileSize / 2);
            //context.Rotate(fm);
            context.Translate(-ZombieGameConfig.TileSize / 2, -ZombieGameConfig.TileSize / 2);
            */
            context.DrawImage((CanvasElement) Image.Canvas, 0, 0);
            /*
            context.StrokeStyle = "red";
            context.StrokeRect(0, 0, ZombieGameConfig.TileSize, ZombieGameConfig.TileSize);

            switch (Collision) {
                case CollisionType.Full:
                    context.FillStyle = "rgba(233,12,22,0.6)";
                    context.FillRect(0, 0, ZombieGameConfig.TileSize, ZombieGameConfig.TileSize);
                    break;
                case CollisionType.RightHalf:
                    context.FillStyle = "rgba(233,12,22,0.6)";
                    context.FillRect(ZombieGameConfig.TileSize / 2, 0, ZombieGameConfig.TileSize / 2, ZombieGameConfig.TileSize);
                    break;
                case CollisionType.TopHalf:
                    context.FillStyle = "rgba(233,12,22,0.6)";
                    context.FillRect(0, 0, ZombieGameConfig.TileSize, ZombieGameConfig.TileSize / 2);
                    break;
                case CollisionType.LeftHalf:
                    context.FillStyle = "rgba(233,12,22,0.6)";
                    context.FillRect(0, 0, ZombieGameConfig.TileSize / 2, ZombieGameConfig.TileSize);
                    break;
                case CollisionType.BottomHalf:
                    context.FillStyle = "rgba(233,12,22,0.6)";
                    context.FillRect(0, ZombieGameConfig.TileSize / 2, ZombieGameConfig.TileSize, ZombieGameConfig.TileSize / 2);
                    break;
            }
            */ //todo enable when some sort of edit mode is enabled

            context.Restore();
        }
Exemple #7
0
 public static void RoundRect(CanvasContext2D ctx, int x, int y, int width, int height, int radius = 5, bool fill = true, bool stroke = false)
 {
     ctx.Save();
     ctx.LineWidth = 3;
     ctx.BeginPath();
     ctx.MoveTo(x + radius, y);
     ctx.LineTo(x + width, y);
     //ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
     ctx.LineTo(x + width, y + height);
     // ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
     ctx.LineTo(x, y + height);
     // ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
     ctx.LineTo(x, y + radius);
     ctx.QuadraticCurveTo(x, y, x + radius, y);
     ctx.ClosePath();
     if (stroke)
         ctx.Stroke();
     if (fill)
         ctx.Fill();
     ctx.Restore();
 }
        private void playDraw(CanvasContext2D context)
        {
            var wm = WindowManager;
            int wX = Math.Max(0, wm.X / ZombieGameConfig.TileSize - 3);
            int wY = Math.Max(0, wm.Y / ZombieGameConfig.TileSize - 3);

            int wWidth = wX + wm.Width / ZombieGameConfig.TileSize + 6;
            int wHeight = wY + wm.Height / ZombieGameConfig.TileSize + 6;

            context.Save();

            context.Scale(Scale.X, Scale.Y);

            context.BeginPath();
            context.Rect(0, 0, wm.Width, wm.Height);
            context.Clip();
            context.ClosePath();

            context.Translate(-wm.X, -wm.Y);

            ( (DrawMapManager) MapManager ).Draw(context, wX, wY, wWidth, wHeight);
            ( (DrawUnitManager) UnitManager ).Draw(context);

            context.Restore();
        }
        private bool DrawTriangle(CanvasContext2D ctx, ImageElement im, double x0, double y0, double x1, double y1, double x2, double y2,
                                double sx0, double sy0, double sx1, double sy1, double sx2, double sy2)
        {
            bool inside;

            if (factor == 1.0)
            {
                inside = Intersects(0, Width, 0, Height, x0, y0, x1, y1, x2, y2);
            }
            else
            {
                hw = Width / 2;
                qw = hw * factor;
                hh = Height / 2;
                qh = hh * factor;
                inside = Intersects(hw - qw, hw + qw, hh - qh, hh + qh, x0, y0, x1, y1, x2, y2);
            }

            if (!inside)
            {
                return false;
            }

            double edgeOffset = isOutlined ? ContractionInPixels : ExpansionInPixels;
            Vector2d expandedS0 = GetMiterPoint(Vector2d.Create(x0, y0), Vector2d.Create(x1, y1), Vector2d.Create(x2, y2), edgeOffset);
            Vector2d expandedS1 = GetMiterPoint(Vector2d.Create(x1, y1), Vector2d.Create(x0, y0), Vector2d.Create(x2, y2), edgeOffset);
            Vector2d expandedS2 = GetMiterPoint(Vector2d.Create(x2, y2), Vector2d.Create(x1, y1), Vector2d.Create(x0, y0), edgeOffset);

            x0 = expandedS0.X;
            y0 = expandedS0.Y;
            x1 = expandedS1.X;
            y1 = expandedS1.Y;
            x2 = expandedS2.X;
            y2 = expandedS2.Y;

            ctx.Save();
            ctx.BeginPath();
            ctx.MoveTo(x0, y0);
            ctx.LineTo(x1, y1);
            ctx.LineTo(x2, y2);
            ctx.ClosePath();
            ctx.Clip();

            double denom = sx0 * (sy2 - sy1) - sx1 * sy2 + sx2 * sy1 + (sx1 - sx2) * sy0;
            if (denom == 0)
            {
                ctx.Restore();
                return false;
            }
            double m11 = -(sy0 * (x2 - x1) - sy1 * x2 + sy2 * x1 + (sy1 - sy2) * x0) / denom;
            double m12 = (sy1 * y2 + sy0 * (y1 - y2) - sy2 * y1 + (sy2 - sy1) * y0) / denom;
            double m21 = (sx0 * (x2 - x1) - sx1 * x2 + sx2 * x1 + (sx1 - sx2) * x0) / denom;
            double m22 = -(sx1 * y2 + sx0 * (y1 - y2) - sx2 * y1 + (sx2 - sx1) * y0) / denom;
            double dx = (sx0 * (sy2 * x1 - sy1 * x2) + sy0 * (sx1 * x2 - sx2 * x1) + (sx2 * sy1 - sx1 * sy2) * x0) / denom;
            double dy = (sx0 * (sy2 * y1 - sy1 * y2) + sy0 * (sx1 * y2 - sx2 * y1) + (sx2 * sy1 - sx1 * sy2) * y0) / denom;

            ctx.Transform(m11, m12, m21, m22, dx, dy);

            ctx.DrawImage(im, 0, 0);

            ctx.Restore();

            if (factor != 1.0)
            {
                ctx.BeginPath();
                ctx.MoveTo(hw - qw, hh - qh);
                ctx.LineTo(hw + qw, hh - qh);
                ctx.LineTo(hw + qw, hh + qh);
                ctx.LineTo(hw - qw, hh + qh);
                ctx.ClosePath();
                ctx.StrokeStyle = "yellow";
                ctx.Stroke();

            }

            return true;
        }
        public void Draw(CanvasContext2D canv)
        {
            canv.Save();
            var size = 0;
            canv.StrokeStyle = canv.FillStyle = "white";
            canv.LineWidth = 3;

            canv.Me().dashedRect(Element.TotalX - size,
                                 Element.TotalY - size,
                                 Element.Width + size * 2,
                                 Element.Height + size * 2,
                                 new int[] {2, 2});

            //canv.strokeRect(this.element.totalX() - size, this.element.totalY() - size, this.element.width + size * 2, this.element.height + size * 2);

            var x = Element.TotalX;
            var y = Element.TotalY;
            var w = Element.Width;
            var h = Element.Height;

            foreach (var j in points) {
                canv.FillRect(x + ( w * j.X / 100 ) - j.Size / 2, y + ( h * j.Y / 100 ) - j.Size / 2, j.Size, j.Size);
            }

            canv.Restore();
        }
        public void Render(CanvasContext2D context, bool force)
        {
            var x = Position.X;
            var y = Position.Y;

            context.Save();

            context.Translate(x, y);
            if (Game.DRAWFAST)
                drawCircle(context, obtainGradient(context, this), Size);
            else {
                if (force || cache.Images == null)
                    drawGrad(context, obtainGradient(context, this), Size);
                else
                    drawImage(context, cache.Images[curGradIndex++], Size);
            }

            context.Restore();
        }
Exemple #12
0
        public override void Draw(CanvasContext2D context)
        {
            context.FillStyle = "red";
            context.FillRect(100, 100, 200, 200);

            context.DrawImage(someImage, 250, 250);
            context.DrawImage(someImage, 350, 350, 100, 100, 200, 200, 100, 100);

            for (int i = 0; i < DebugText.Length; i++) {
                if (DebugText[i].Truthy()) {
                    context.Save();
                    context.StrokeStyle = "white";
                    context.StrokeText(DebugText[i].ToString(), Screen.Width - 120, i * 20 + 150);
                    context.Restore();
                }
            }
        }
        public override void Draw(CanvasContext2D canv)
        {
            if (!Visible) return;

            canv.Save();

            canv.FillStyle = BackColor;

            var width = VisibleItems * ( ItemWidth + JWidth ) - 2;

            canv.FillStyle = BackColor;
            canv.LineWidth = 1;
            canv.StrokeStyle = "#333";
            CHelp.RoundRect(canv, TotalX, TotalY, VisibleItems * ( ItemWidth + JWidth ) + 2, ItemHeight + ScrollWidth + 6, 3, true, true);

            canv.FillStyle = "grey";
            canv.LineWidth = 1;
            canv.StrokeStyle = "#444";
            canv.FillRect(TotalX + 2, TotalY + ItemHeight + 6, VisibleItems * ( ItemWidth + JWidth ), ScrollWidth);

            canv.FillStyle = "FFDDFF";
            canv.LineWidth = 1;
            canv.StrokeStyle = "#FFDDFF";
            ScrollPosition = width * ScrollOffset / ( Controls.Count - VisibleItems );

            canv.FillRect(TotalX + ( ScrollPosition ) + 2, TotalY + ItemHeight + 6, 5, ScrollWidth - 2);

            var curX = 3;
            for (var i = ScrollOffset; i < Math.Min(Controls.Count, ScrollOffset + VisibleItems); i++) {
                Controls[i].Parent = this;
                Controls[i].X = curX;
                Controls[i].Y = 2;
                Controls[i].Height = ItemHeight;
                Controls[i].Width = ItemWidth;

                curX += ItemWidth + JWidth;
                Controls[i].Draw(canv);
            }

            canv.Restore();
            base.Draw(canv);
        }
        private bool DrawTriangle(CanvasContext2D ctx, ImageElement im, double x0, double y0, double x1, double y1, double x2, double y2,
                                double sx0, double sy0, double sx1, double sy1, double sx2, double sy2)
        {
            if (!Intersects(0, Width, 0, Height, x0, y0, x1, y1, x2, y2))
            {
                return false;
            }

            //double edgeOffset = isOutlined ? ContractionInPixels : ExpansionInPixels;
            //Vector2d expandedS0 = GetMiterPoint(Vector2d.Create(x0, y0), Vector2d.Create(x1, y1), Vector2d.Create(x2, y2), ExpansionInPixels);
            //Vector2d expandedS1 = GetMiterPoint(Vector2d.Create(x1, y1), Vector2d.Create(x0, y0), Vector2d.Create(x2, y2), ExpansionInPixels);
            //Vector2d expandedS2 = GetMiterPoint(Vector2d.Create(x2, y2), Vector2d.Create(x1, y1), Vector2d.Create(x0, y0), ExpansionInPixels);

            //Vector2d expandedS0 = MiterPoint(x0, y0, x1, y1, x2, y2);
            //Vector2d expandedS1 = MiterPoint(x1, y1, x0, y0, x2, y2);
            //Vector2d expandedS2 = MiterPoint(x2, y2, x1, y1, x0, y0);
            MiterPointOut(expandedS0, x0, y0, x1, y1, x2, y2, ExpansionInPixels);
            MiterPointOut(expandedS1, x1, y1, x0, y0, x2, y2, ExpansionInPixels);
            MiterPointOut(expandedS2, x2, y2, x1, y1, x0, y0, ExpansionInPixels);

            x0 = expandedS0.X;
            y0 = expandedS0.Y;
            x1 = expandedS1.X;
            y1 = expandedS1.Y;
            x2 = expandedS2.X;
            y2 = expandedS2.Y;

            ctx.Save();
            if (RenderingOn)
            {

                ctx.BeginPath();
                ctx.MoveTo(x0, y0);
                ctx.LineTo(x1, y1);
                ctx.LineTo(x2, y2);
                ctx.ClosePath();
                ctx.Clip();
            }
            double denom = sx0 * (sy2 - sy1) - sx1 * sy2 + sx2 * sy1 + (sx1 - sx2) * sy0;
            //if (denom == 0)
            //{
            //    ctx.Restore();
            //    return false;
            //}
            double m11 = -(sy0 * (x2 - x1) - sy1 * x2 + sy2 * x1 + (sy1 - sy2) * x0) / denom;
            double m12 = (sy1 * y2 + sy0 * (y1 - y2) - sy2 * y1 + (sy2 - sy1) * y0) / denom;
            double m21 = (sx0 * (x2 - x1) - sx1 * x2 + sx2 * x1 + (sx1 - sx2) * x0) / denom;
            double m22 = -(sx1 * y2 + sx0 * (y1 - y2) - sx2 * y1 + (sx2 - sx1) * y0) / denom;
            double dx = (sx0 * (sy2 * x1 - sy1 * x2) + sy0 * (sx1 * x2 - sx2 * x1) + (sx2 * sy1 - sx1 * sy2) * x0) / denom;
            double dy = (sx0 * (sy2 * y1 - sy1 * y2) + sy0 * (sx1 * y2 - sx2 * y1) + (sx2 * sy1 - sx1 * sy2) * y0) / denom;

            ctx.Transform(m11, m12, m21, m22, dx, dy);

            if (RenderingOn)
            {
                ctx.Alpha = Opacity;

                if (lighting < 1.0)
                {
                    ctx.Alpha = 1;
                    ctx.FillStyle = "Black";
                    ctx.FillRect(0, 0, Width, Height);
                    ctx.Alpha = lighting * Opacity;
                }

                ctx.DrawImage(im, 0, 0);
            }

            ctx.Restore();
            return true;
        }
        public override void Draw(CanvasContext2D canv)
        {
            if (!Visible) return;
            canv.Save();
            if (!Focused) {
                CursorPosition = -1;
                DragPosition = -1;
            }
            DrawTicks++;
            can = canv;

            canv.StrokeStyle = ButtonBorderGrad;
            canv.FillStyle = Clicking ? Button1Grad : Button2Grad;
            canv.LineWidth = 2;
            CHelp.RoundRect(canv, TotalX, TotalY, Width, Height, 2, true, true);
            if (canv.Font != Font)
                canv.Font = Font;

            if (DragPosition != -1) {
                canv.FillStyle = "#598AFF";

                var w1 = canv.MeasureText(Text.Substring(0, Math.Min(DragPosition, CursorPosition))).Width;
                var w2 = canv.MeasureText(Text.Substring(0, Math.Max(DragPosition, CursorPosition))).Width;
                canv.FillRect(TotalX + 8 + w1,
                              TotalY + 3,
                              w2 - w1,
                              ( Height - 7 ));
            }
            canv.FillStyle = "#000000";

            int hc;
            if (canv.Font.IndexOf("pt") != -1)
                hc = int.Parse(canv.Font.Substr(0, canv.Font.IndexOf("pt")));
            else
                hc = int.Parse(canv.Font.Substr(0, canv.Font.IndexOf("px")));
            canv.FillText(Text, TotalX + 8, TotalY + ( ( Height - hc ) / 2 ) + Height / 2);

            if (Focused && ( ( blinkTick++ % 35 ) == 0 ))
                blinked = !blinked;
            if (Focused && blinked) {
                canv.StrokeStyle = "#000000";
                var w = canv.MeasureText(Text.Substring(0, CursorPosition)).Width;
                canv.BeginPath();
                canv.MoveTo(TotalX + 8 + w, TotalY + 3);
                canv.LineTo(TotalX + 8 + w, TotalY + ( Height - 7 ));
                canv.LineWidth = 2;
                canv.Stroke();
            }
            canv.Restore();

            base.Draw(canv);
        }
        public void Draw(CanvasContext2D canvas)
        {
            canvas.Save();

            foreach (var are in canvasDepths) {
                are.Draw(canvas);
            }

            if (true /*DEBUGs*/) {
                for (var i = 0; i < messages.Count; i++) {
                    canvas.FillText(messages[i], 10, 25 + i * 30);
                }
            }

            canvas.Restore();
        }
Exemple #17
0
        protected override void Update(CanvasContext2D context)
        {
            if (Status != RaceStatus.Fail && Status != RaceStatus.Win)
            {
                context.DrawImage(_timeLeftFrame, 308, 10);

                Type.SetField(context, "textAlign", "right");
                context.FillStyle = "#00AD11";

                if (TimeLeft > 10000 || Math.Floor((TimeLeft / 300) % 2) != 0)
                {
                    if (TimeLeft < 0) TimeLeft = 0;
                    context.Font = "110px Digital";
                    context.FillText(Math.Floor(TimeLeft / 1000).ToString(), 475, 105);
                }

                if (Speed > 0)
                {
                    context.Save();
                    context.Scale(-1, 1);
                    long width = Math.Floor((10 * Speed) / MaxSpeed) * 22;
                    if (width > 0) context.DrawImage(_meterImage, 220 - width, 0, width, 102, -561 - width, 20, width, 102);
                    context.Restore();
                }

                context.Font = "30px Digital";
                context.FillText(Math.Floor(Speed * 5) + " Km/h", 780, 120);

                int rpmWidth = Math.Floor(_rpm / 500) * 22 + 22;

                context.DrawImage(_meterImage, 220 - rpmWidth, 0, rpmWidth, 102, 240 - rpmWidth, 20, rpmWidth, 102);
                context.FillText(Math.Floor(_rpm) + " RPM", 130, 120);

                context.BeginPath();
                context.LineWidth = 3;
                context.StrokeStyle = "#00AD11";
                context.MoveTo(5, 150);
                float x = 5 + Math.Min(Position * 735 / RoadLength, 735);
                context.LineTo(x, 150);
                context.Stroke();
                context.ClosePath();

                context.BeginPath();
                context.StrokeStyle = "#006808";
                context.MoveTo(x, 150);
                context.LineTo(790, 150);
                context.Stroke();
                context.ClosePath();
                context.DrawImage(_markerImage, x, 142);
            }

            if (Status == RaceStatus.Running)
            {
                TimeLeft -= DeltaTime;

                if (TimeLeft < 0)
                {
                    _music.Pause();
                    CarSystem.CarObject.CurrentAnimation = "Forward";
                    Status = RaceStatus.Fail;
                    ShowMessage(_failMessage);
                    RemoveSystem(_engineSoundSystem);
                    RemoveSystem(_npcSystem);
                    pendingTimers.Add(Window.SetTimeout(delegate()
                    {
                        UpdateMessage("<p>Press a key to continue.</p>");
                    }, 3000));
                }
            }
        }
Exemple #18
0
        public override void Draw(CanvasContext2D context)
        {
            foreach (var kingdom in Kingdoms) {
                foreach (var tower in kingdom.Value.Towers) {
                    tower.Drawer.Draw(context, tower.X * Scale.X, tower.Y * Scale.Y);
                }
                foreach (var unit in kingdom.Value.Units) {
                    unit.Draw(context, unit.X * Scale.X, unit.Y * Scale.Y);
                }
            }
            foreach (var waypointMap in WaypointMaps) {
                waypointMap.Drawer.Draw(context, 0, 0);
            }

            for (int i = 0; i < DebugText.Length; i++) {
                if (DebugText[i].Truthy()) {
                    context.Save();
                    context.StrokeStyle = "white";
                    context.StrokeText(DebugText[i].ToString(), Screen.Width - 120, i * 20 + 150);
                    context.Restore();
                }
            }
        }