コード例 #1
0
        public ApplicationSprite()
        {
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;

            var fill = new Sprite().AttachTo(this);

            fill.graphics.beginFill(0xB27D51);
            fill.graphics.drawRect(0, 0, this.stage.stageWidth, this.stage.stageHeight);

            this.stage.resize +=
                delegate
                {
                    fill.graphics.beginFill(0xB27D51);
                    fill.graphics.drawRect(0, 0, this.stage.stageWidth, this.stage.stageHeight);
                };


            // http://tournasdimitrios1.wordpress.com/2010/08/27/understanding-embedding-assets-in-flex3/
            // http://www.streamhead.com/how-to-use-vector-graphics-in-flashdevelop-svg-in-flash/s

            // Flex defines imgCls as a reference to a subclass of the mx.core.SpriteAsset class, which is a subclass of the flash.display.Sprite class. Therefore, you can manipulate the image by using the methods and properties of the SpriteAsset class.

            // V:\web\HeatZeekerEmbedSVG\ApplicationSprite.as: Warning: The use of SVG has been deprecated since Flex 4. Please use FXG.
            // http://www.kongregate.com/forums/4/topics/146594
            // The links to the FXG specification no longer work and the project seems to be abandoned.

            Action<double, double> CreateUnit =
                (x, y) =>
                {
                    var unit = new Sprite().AttachTo(this);

                    var shadow = new Sprite().AttachTo(unit);

                    shadow.MoveTo(32, 32);
                    shadow.alpha = 0.3;
                    KnownEmbeddedResources.Default["assets/HeatZeekerEmbedSVG/hind0_shadow.svg"].ToSprite().AttachTo(shadow).MoveTo(-200, -200);


                    KnownEmbeddedResources.Default["assets/HeatZeekerEmbedSVG/hind0_nowings.svg"].ToSprite().AttachTo(unit).MoveTo(-200, -200);

                    var wings = new Sprite().AttachTo(unit);

                    for (int i = 0; i < 5; i++)
                    {
                        var wingloc = new Sprite().AttachTo(wings);

                        KnownEmbeddedResources.Default["assets/HeatZeekerEmbedSVG/hind0_wing1.svg"].ToSprite().AttachTo(wingloc).MoveTo(-200, -200);

                        wingloc.rotation = i * (360 / 5);
                    }


                    var t = new Timer(1000 / 30);

                    t.timer +=
                        delegate
                        {
                            wings.rotation = t.currentCount * 9;
                        };

                    t.start();

                    unit.scaleX = 0.3;
                    unit.scaleY = 0.3;

                    unit.MoveTo(x, y);
                };


            this.click +=
                e =>
                {

                    CreateUnit(e.stageX, e.stageY);
                };

            CreateUnit(200, 200);

            #region fps
            var sw = new Stopwatch();

            sw.Start();

            var ii = 0;

            this.enterFrame +=
                delegate
                {


                    if (sw.ElapsedMilliseconds < 1000)
                    {
                        ii++;
                        return;
                    }


                    if (fps != null)
                        fps("" + ii);

                    ii = 0;

                    sw.Restart();

                };
            #endregion

        }
コード例 #2
0
        public ApplicationSprite()
        {
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;

            #region bg fill
            var fill = new Sprite().AttachTo(this);

            fill.graphics.beginFill(0xA26D41);
            fill.graphics.drawRect(0, 0, this.stage.stageWidth, this.stage.stageHeight);

            this.stage.resize +=
                delegate
                {
                    fill.graphics.beginFill(0xA26D41);
                    fill.graphics.drawRect(0, 0, this.stage.stageWidth, this.stage.stageHeight);
                };
            #endregion

            var egocenter = new Sprite();
            var egorotation = new Sprite().AttachTo(egocenter);

            var map = new Sprite().AttachTo(egorotation);

            map.graphics.beginFill(0xB27D51);
            map.graphics.drawRect(0, 0, 4000, 400);


            // http://wiki.openoffice.org/wiki/SVG_User_Experiences
            //Enclosed Exception:
            //The current document is unable to create an element of the requested type (namespace: http://www.w3.org/2000/svg, name: flowRoot).

            //        [Embed(source = "/assets/FlashHeatZeeker/touchdown.svg", mimeType = "image/svg-xml")]
            //        ^

            //U:\web\FlashHeatZeeker\ApplicationSprite.as(104): col: 9: Error: Unable to transcode /assets/FlashHeatZeeker/touchdown.svg.



            KnownEmbeddedResources.Default["assets/FlashHeatZeeker/touchdown.svg"].ToSprite().AttachTo(map).MoveTo(100, 0).With(
                svg =>
                {
                    svg.scaleX = 0.5;
                    svg.scaleY = 0.5;
                }
            );


            // unit 1

            Func<GameUnit> greentank = delegate
            {
                var unit1_loc = new Sprite().AttachTo(map);
                var unit1_rot = new Sprite().AttachTo(unit1_loc);

                KnownEmbeddedResources.Default["assets/FlashHeatZeeker/greentank.svg"].ToSprite().AttachTo(unit1_rot).MoveTo(-200, -200);

                return new GameUnit { loc = unit1_loc, rot = unit1_rot };
            };

            var unit1 = greentank();
            var unit2 = greentank();
            var unit3 = greentank();

            unit1.loc.MoveTo(300, 200);
            unit2.loc.MoveTo(0, 400);

            var CurrentUnit = unit1;



            KnownEmbeddedResources.Default["assets/FlashHeatZeeker/hill0.svg"].ToSprite().AttachTo(map).MoveTo(0, 0).With(
                svg =>
                {
                    svg.scaleX = 0.2;
                    svg.scaleY = 0.2;
                }
            );

            for (int iy = 0; iy < 128; iy++)
            {
                KnownEmbeddedResources.Default["assets/FlashHeatZeeker/tree0.svg"].ToSprite().AttachTo(map).MoveTo(400, 0).With(
                    svg =>
                    {
                        svg.cacheAsBitmap = true;

                        svg.scaleX = 0.2;
                        svg.scaleY = 0.2;

                        if (iy % 3 == 0)
                            svg.y += 50;

                        if (iy % 3 == 1)
                            svg.y += 100;


                        svg.x += 15 * iy;
                    }
                );
            }

            for (int iy = 0; iy < 128; iy++)
            {
                KnownEmbeddedResources.Default["assets/FlashHeatZeeker/tree0.svg"].ToSprite().AttachTo(map).MoveTo(400, 0).With(
                    svg =>
                    {
                        svg.y += 300;

                        svg.cacheAsBitmap = true;

                        svg.scaleX = 0.2;
                        svg.scaleY = 0.2;

                        if (iy % 3 == 0)
                            svg.y += 50;

                        if (iy % 3 == 1)
                            svg.y += 100;


                        svg.x += 15 * iy;
                    }
                );
            }



            // ego is in center
            map.MoveTo(-300, -200);

            this.stage.keyUp +=
                e =>
                {

                    //Console.WriteLine("keyUp " + new { e.keyCode });

                    if (e.keyCode == (uint)System.Windows.Forms.Keys.D3)
                    {
                        CurrentUnit = unit3;
                        egorotation.rotation = -CurrentUnit.rot.rotation;
                        map.MoveTo(-CurrentUnit.loc.x, -CurrentUnit.loc.y);
                    }

                    if (e.keyCode == (uint)System.Windows.Forms.Keys.D1)
                    {
                        CurrentUnit = unit1;
                        egorotation.rotation = -CurrentUnit.rot.rotation;
                        map.MoveTo(-CurrentUnit.loc.x, -CurrentUnit.loc.y);
                    }

                    if (e.keyCode == (uint)System.Windows.Forms.Keys.D2)
                    {
                        CurrentUnit = unit2;
                        egorotation.rotation = -CurrentUnit.rot.rotation;
                        map.MoveTo(-CurrentUnit.loc.x, -CurrentUnit.loc.y);
                    }


                    if (e.keyCode == (uint)System.Windows.Forms.Keys.F11)
                    {
                        this.stage.SetFullscreen(true);
                    }
                };

            this.stage.keyDown +=
              e =>
              {
                  //Console.WriteLine("keyDown " + new { e.keyCode });

                  if (e.keyCode == (uint)System.Windows.Forms.Keys.Up)
                  {
                      CurrentUnit.loc.x += 2 * Math.Cos((CurrentUnit.rot.rotation + 270).DegreesToRadians());
                      CurrentUnit.loc.y += 2 * Math.Sin((CurrentUnit.rot.rotation + 270).DegreesToRadians());
                  }

                  if (e.keyCode == (uint)System.Windows.Forms.Keys.Down)
                  {
                      CurrentUnit.loc.x += -2 * Math.Cos((CurrentUnit.rot.rotation + 270).DegreesToRadians());
                      CurrentUnit.loc.y += -2 * Math.Sin((CurrentUnit.rot.rotation + 270).DegreesToRadians());
                  }

                  if (e.keyCode == (uint)System.Windows.Forms.Keys.Left)
                  {
                      CurrentUnit.rot.rotation -= 5;
                  }

                  if (e.keyCode == (uint)System.Windows.Forms.Keys.Right)
                  {
                      CurrentUnit.rot.rotation += 5;
                  }


                  egorotation.rotation = -CurrentUnit.rot.rotation;
                  map.MoveTo(-CurrentUnit.loc.x, -CurrentUnit.loc.y);
              };

            #region egocrosshair
            var egocrosshair = new Sprite().AttachTo(egocenter);

            egocrosshair.graphics.lineStyle(2, 0x007f00, 1);

            egocrosshair.graphics.moveTo(-32, 0);
            egocrosshair.graphics.lineTo(32, 0);


            egocrosshair.graphics.moveTo(0, -32);
            egocrosshair.graphics.lineTo(0, 32);
            #endregion

            egocenter.AttachTo(this);



            egocenter.MoveTo(this.stage.stageWidth / 2, this.stage.stageHeight / 2);
            this.stage.resize +=
               delegate
               {
                   egocenter.MoveTo(this.stage.stageWidth / 2, this.stage.stageHeight / 2);
               };


            #region AtInitializeConsoleFormWriter
            this.AtInitializeConsoleFormWriter = (
                Action<string> Console_Write,
                Action<string> Console_WriteLine
            ) =>
            {

                try
                {
                    var w = new __OutWriter();

                    var o = Console.Out;

                    var __reentry = false;

                    w.AtWrite =
                        x =>
                        {
                            o.Write(x);

                            if (!__reentry)
                            {
                                __reentry = true;
                                Console_Write(x);
                                __reentry = false;
                            }
                        };

                    w.AtWriteLine =
                        x =>
                        {
                            o.WriteLine(x);

                            if (!__reentry)
                            {
                                __reentry = true;
                                Console_WriteLine(x);
                                __reentry = false;
                            }
                        };

                    Console.SetOut(w);

                    Console.WriteLine("flash Console.WriteLine should now appear in JavaScript form!");
                }
                catch
                {

                }
            };
            #endregion

            var info = new TextField
            {
                selectable = false,
                mouseEnabled = false,
                autoSize = TextFieldAutoSize.LEFT
            }.AttachTo(this).MoveTo(8, 8);


            var maxframe = new Stopwatch();
            var maxframe_elapsed = 0.0;

            #region fps
            var sw = new Stopwatch();

            sw.Start();

            var ii = 0;

            maxframe.Start();
            this.enterFrame +=
                delegate
                {
                    maxframe.Stop();

                    //                    System.TimeSpan for Boolean op_GreaterThan(System.TimeSpan, System.TimeSpan) used at
                    //FlashHeatZeeker.ApplicationSprite+<>c__DisplayClass11.<.ctor>b__d at offset 001e.

                    //                TypeError: Error #1009: Cannot access a property or method of a null object reference.
                    //at FlashHeatZeeker::ApplicationSprite___c__DisplayClass11/__ctor_b__d_100663322()[U:\web\FlashHeatZeeker\ApplicationSprite___c__DisplayClass11.as:141]

                    if (maxframe.Elapsed.TotalMilliseconds > maxframe_elapsed)
                        maxframe_elapsed = maxframe.Elapsed.TotalMilliseconds;

                    if (sw.ElapsedMilliseconds < 1000)
                    {
                        ii++;

                        maxframe.Restart();

                        return;
                    }

                    info.text = new { fps = ii, maxframe_elapsed }.ToString();

                    //if (fps != null)
                    //    fps("" + ii);

                    ii = 0;
                    maxframe_elapsed = 0;
                    sw.Restart();
                };
            #endregion

        }
コード例 #3
0
        private void AddSprite(Action Reorder, double x, double y)
        {
            var s = new Sprite
            {
                filters = new[] { new DropShadowFilter() }
            };

            s.graphics.beginFill((uint)0xffffff.Random());
            s.graphics.drawRect(-16, -16, 32, 32);
            s.graphics.endFill();

            var drag = default(Point);

            s.mouseDown +=
                e =>
                {
                    foreach (InteractiveObject item in this.GetChildren().Where(i => i is TextField))
                    {
                        item.mouseEnabled = false;
                    }

                    drag = new Point { x = e.localX, y = e.localY };
                };

            s.mouseUp +=
                e =>
                {
                    foreach (InteractiveObject item in this.GetChildren().Where(i => i is TextField))
                    {
                        item.mouseEnabled = true;
                    }

                    drag = null;
                };

            stage.mouseMove +=
                e =>
                {
                   

                    if (drag == null)
                        return;

                    var p = new Point { x = e.stageX, y = e.stageY };

                    s.MoveTo(p - drag);

                    Reorder();
                };

            s.mouseWheel +=
                e =>
                {
                    s.scaleX = (s.scaleX + 0.5 * Math.Sign(e.delta)).Max(1).Min(4);
                    s.scaleY = (s.scaleY + 0.5 * Math.Sign(e.delta)).Max(1).Min(4);
                };

            s.MoveTo(x, y).AttachTo(this);
        }