示例#1
0
        public Fish(FishTank tank, double x, double y, double z, ImageElement fishStrip, CanvasContext2D context) {
            _tank = tank;

            _x = x;
            _y = y;
            _z = z;
            _zFactor = 1;
            _species = Math.Floor(Math.Random() * FishTank.FishSpecies);
            _cellIndex = Math.Floor(Math.Random() * (FishTank.CellsInFishStrip - 1));
            _cellReverse = -1;

            _angle = 2 * Math.PI * Math.Random();
            _xAngle = Math.Cos(_angle);
            _yAngle = Math.Sin(_angle);
            _zAngle = 1 - 2 * Math.Round(Math.Random());
            _scale = 0.1;
            _flip = 1;
            _velocity = 100;

            // Stop fish from swimming straight up or down
            if ((_angle > Math.PI * 4 / 3) && (_angle < Math.PI * 5 / 3) ||
                (_angle > Math.PI * 1 / 3) && (_angle < Math.PI * 2 / 3)) {
                _angle = Math.PI * 1 / 3 * Math.Random();
                _xAngle = Math.Cos(_angle);
                _yAngle = Math.Sin(_angle);
            }

            // Face the fish the right way if angle is between 6 o'clock and 12 o'clock
            if ((_angle > Math.PI / 2) && (_angle < Math.PI / 2 * 3)) {
                _flip = -1;
            }

            _fishStrip = fishStrip;
            _context = context;
        }
示例#2
0
        public void Run()
        {
            _backgroundImageElement = Document.GetElementById("backgroundImage").As<ImageElement>();
            _imageStripElement = Document.GetElementById("imageStrip").As<ImageElement>();
            _tankCanvas = Document.GetElementById("fishTankCanvas").As<CanvasElement>();
            _fishesCanvas = Document.GetElementById("fishesCanvas").As<CanvasElement>();

            Debug.Assert(_backgroundImageElement != null);
            Debug.Assert(_imageStripElement != null);
            Debug.Assert(_tankCanvas != null);
            Debug.Assert(_fishesCanvas != null);

            _tankCanvasContext = (CanvasContext2D)_tankCanvas.GetContext(Rendering.Render2D);
            _fishesCanvasContext = (CanvasContext2D)_fishesCanvas.GetContext(Rendering.Render2D);

            _fishes = new List<Fish>();
            for (int i = 0; i < FishTank.FishCount; i++) {
                double x = Math.Floor(Math.Random() * (_width - FishTank.FishWidth) + FishTank.FishWidth / 2);
                double y = Math.Floor(Math.Random() * (_height - FishTank.FishHeight) + FishTank.FishHeight / 2);
                double z = Math.Floor(Math.Random() * (FishTank.ZFar - FishTank.ZNear));

                _fishes.Add(new Fish(this, x, y, z, _imageStripElement, _fishesCanvasContext));
            }

            OnWindowResize(null);
            Window.AddEventListener("resize", OnWindowResize, false);

            _tickHandler = OnTick;
            Window.SetTimeout(_tickHandler, (int)(3600 / FramesPerSecond));
        }
示例#3
0
        public override void Init(Scene level)
        {
            _level = (RaceLevel)level;
            _cloudImage = _level.LoadImage("Images/Race/cloud.png", false);

            _explosionImage = _level.LoadImage("Images/Race/explosion.png", false);
            _explosions = new List<Explosion>();

            _flakImage = _level.LoadImage("Images/Race/flak.png", false);
            _flakObjects = new List<FlakObject>();

            // Build the background clouds
            for (int i = 0; i < 30; i++)
            {
                Cloud cloud = new Cloud();
                cloud.X = Math.Floor(Math.Random() * 2401) - 1200;
                cloud.Y = Math.Floor(Math.Random() * 300);
                _clouds.Add(cloud);
            }

            _clouds.Sort(delegate(Cloud x, Cloud y)
            {
                if (x.Y < y.Y) return 1;
                if (x.Y > y.Y) return -1;
                return 0;
            });
        }
示例#4
0
 public static void LoadImageFromUrl(string tileMapFile, Action<ImageElement> loaded)
 {
     ImageElement element = new ImageElement();
     element.Me().crossOrigin = "anonymous"; //FFFFUUUUU CORS!
     element.AddEventListener("load", e => { loaded(element); }, false);
     element.Src = tileMapFile;
 }
示例#5
0
        public static CanvasInformation Create(ImageElement tileImage)
        {
            var item = Create(tileImage.Width, tileImage.Height);

            item.Context.DrawImage(tileImage, 0, 0);

            return item;
        }
 public void AddSprite(ImageElement image, float handleX, float handleY)
 {
     Sprite sprite = new Sprite();
     sprite.Image = image;
     sprite.HandleX = handleX;
     sprite.HandleY = handleY;
     Sprites.Add(sprite);
 }
示例#7
0
        public override void Dispose()
        {
            base.Dispose();

            jQuery.FromElement(_overlay).Empty();
            _titleImage = null;
            _overlay = null;
        }
示例#8
0
 public static GameObject Create(ImageElement defaultImage, float handleX, float handleY)
 {
     GameObject gameObject = new GameObject();
     AnimationSequence sequence = new AnimationSequence();
     sequence.AddSprite(defaultImage, handleX, handleY);
     gameObject.AnimationSequences["Default"] = sequence;
     gameObject.StartAnimation("Default");
     return gameObject;
 }
示例#9
0
 public override void Dispose()
 {
     _level = null;
     _clouds = null;
     _cloudImage = null;
     _explosionImage = null;
     _explosions = null;
     _flakImage = null;
     _flakObjects = null;
 }
示例#10
0
        protected override void Init()
        {
            AddSystem(new MenuBackgroundSystem());

            CanPause = false;
            _overlay = jQuery.Select(".GameOverlay").GetElement(0);
            _titleImage = base.LoadImage("images/title/title.png", false);
            jQuery.FromElement(_overlay).Show();
            BuildMainMenu();
        }
        public static RenderTriangle Create(PositionTexture a, PositionTexture b, PositionTexture c, ImageElement img, int level)
        {
            RenderTriangle temp = new RenderTriangle();

            temp.A = a.Copy();
            temp.B = b.Copy();
            temp.C = c.Copy();
            temp.texture = img;
            temp.TileLevel = level;
            return temp;
        }
示例#12
0
 public void AddSprites(ImageElement[] images, float handleX, float handleY)
 {
     foreach (ImageElement image in images)
     {
         Sprite sprite = new Sprite();
         sprite.Image = image;
         sprite.HandleX = handleX;
         sprite.HandleY = handleY;
         Sprites.Add(sprite);
     }
 }
示例#13
0
 public static RenderTriangle CreateWithMiter(PositionTexture a, PositionTexture b, PositionTexture c, ImageElement img, int level, double expansion)
 {
     RenderTriangle temp = new RenderTriangle();
     temp.ExpansionInPixels = expansion;
     temp.A = a.Copy();
     temp.B = b.Copy();
     temp.C = c.Copy();
     temp.texture = img;
     temp.TileLevel = level;
     temp.MakeNormal();
     return temp;
 }
示例#14
0
 public GameDrawer()
 {
     cardImages = new JsDictionary<string, ImageElement>();
     for (var i = 101; i < 153; i++) {
         var img = new ImageElement();
         var domain = BuildSite.TopLevelURL + "assets";
         var src = domain + "/cards/" + i;
         string jm;
         img.Src = jm = src + ".gif";
         cardImages[jm] = img;
     }
 }
        public void LoadTiles(JsonTileMap jsonTileMap, ImageElement tileImage, Completed completed)
        {
            var canvas = CanvasInformation.Create(tileImage);

            int height = jsonTileMap.MapHeight * jsonTileMap.TileHeight;
            int width = jsonTileMap.MapWidth * jsonTileMap.TileWidth;

            for (int x = 0; x < width; x += jsonTileMap.TileWidth) {
                for (int y = 0; y < height; y += jsonTileMap.TileHeight) {
                    //load just the xy width*height of the canvas into a tile object for caching mostly.
                    var tile = new DrawTile(canvas, x, y, jsonTileMap);
                    //store each tile in a hash of name-x-y
                    loadedTiles[tile.Key] = tile;
                }
            }
            completed();
        }
示例#16
0
        public void Load(string url)
        {
            URL = url;
            if (!Downloading)
            {
                Downloading = true;
                ImageElement = (ImageElement)Document.CreateElement("img");
                CrossDomainImage xdomimg = (CrossDomainImage)(object)ImageElement;

                ImageElement.AddEventListener("load", delegate(ElementEvent e)
                {
                    Ready = true;
                    Downloading = false;
                    Errored = false;
                    MakeTexture();
                }, false);

                ImageElement.AddEventListener("error", delegate(ElementEvent e)
                {
                    if (!ImageElement.HasAttribute("proxyattempt"))
                    {
                        ImageElement.Src = Util.GetProxiedUrl(URL);
                        ImageElement.SetAttribute("proxyattempt", true);
                    }
                    else
                    {
                        Downloading = false;
                        Ready = false;
                        Errored = true;
                    }
                }, false);

                xdomimg.crossOrigin = "anonymous";
              //              texture.Src = this.URL.Replace("cdn.", "www.");

                ImageElement.Src = URL;
            }
        }
示例#17
0
        public static void DrawSaturnsRings(RenderContext renderContext, bool front, double distance)
        {
            if (RingsTriangleLists[0] == null)
            {
                ringImage =  (ImageElement)Document.CreateElement("img");
                CrossDomainImage xdomimg = (CrossDomainImage)(object)ringImage;

                //texture.AddEventListener("load", delegate(ElementEvent e)
                //{
                //    texReady = true;
                //    Downloading = false;
                //    errored = false;
                //    ReadyToRender = texReady && (DemReady || !demTile);
                //    RequestPending = false;
                //    TileCache.RemoveFromQueue(this.Key, true);
                //    MakeTexture();
                //}, false);

                //texture.AddEventListener("error", delegate(ElementEvent e)
                //{
                //    Downloading = false;
                //    ReadyToRender = false;
                //    errored = true;
                //    RequestPending = false;
                //    TileCache.RemoveFromQueue(this.Key, true);
                //}, false);

                xdomimg.crossOrigin = "anonymous";
                ringImage.Src = "/webclient/images/saturnringsshadow.png";

                RingsTriangleLists[0] = new List<RenderTriangle>();
                RingsTriangleLists[1] = new List<RenderTriangle>();

                double ringSize = 2.25;

                Vector3d TopLeft = Vector3d.Create(-ringSize, 0, -ringSize);
                Vector3d TopRight = Vector3d.Create(ringSize, 0, -ringSize);
                Vector3d BottomLeft = Vector3d.Create(-ringSize, 0, ringSize);
                Vector3d BottomRight = Vector3d.Create(ringSize, 0, ringSize);
                Vector3d center = Vector3d.Create(0, 0, 0);
                Vector3d leftCenter = Vector3d.Create(-ringSize, 0, 0);
                Vector3d topCenter = Vector3d.Create(0, 0, -ringSize);
                Vector3d bottomCenter = Vector3d.Create(0, 0, ringSize);
                Vector3d rightCenter = Vector3d.Create(ringSize, 0, 0);

                int level = 6;
                //RingsTriangleLists[0].Add(RenderTriangle.Create(PositionTexture.CreatePosSize(TopLeft, 0, 0, 1024, 1024), PositionTexture.CreatePosSize(leftCenter, 0, .5, 1024, 1024), PositionTexture.CreatePosSize(topCenter, .5, 0, 1024, 1024), ringImage, level));
                //RingsTriangleLists[0].Add(RenderTriangle.Create(PositionTexture.CreatePosSize(leftCenter, 0, 0.5, 1024, 1024), PositionTexture.CreatePosSize(center, .5, .5, 1024, 1024), PositionTexture.CreatePosSize(topCenter, .5, 0, 1024, 1024), ringImage, level));
                //RingsTriangleLists[0].Add(RenderTriangle.Create(PositionTexture.CreatePosSize(topCenter, .5, 0, 1024, 1024), PositionTexture.CreatePosSize(rightCenter, 1, .5, 1024, 1024), PositionTexture.CreatePosSize(TopRight, 1, 0, 1024, 1024), ringImage, level));
                //RingsTriangleLists[0].Add(RenderTriangle.Create(PositionTexture.CreatePosSize(topCenter, .5, 0, 1024, 1024), PositionTexture.CreatePosSize(center, .5, .5, 1024, 1024), PositionTexture.CreatePosSize(rightCenter, 1, .5, 1024, 1024), ringImage, level));
                //RingsTriangleLists[1].Add(RenderTriangle.Create(PositionTexture.CreatePosSize(leftCenter, 0, .5, 1024, 1024), PositionTexture.CreatePosSize(bottomCenter, .5, 1, 1024, 1024), PositionTexture.CreatePosSize(center, .5, .5, 1024, 1024), ringImage, level));
                //RingsTriangleLists[1].Add(RenderTriangle.Create(PositionTexture.CreatePosSize(leftCenter, 0, .5, 1024, 1024), PositionTexture.CreatePosSize(BottomLeft, 0, 1, 1024, 1024), PositionTexture.CreatePosSize(bottomCenter, .5, 1, 1024, 1024), ringImage, level));
                //RingsTriangleLists[1].Add(RenderTriangle.Create(PositionTexture.CreatePosSize(center, .5, .5, 1024, 1024), PositionTexture.CreatePosSize(BottomRight, 1, 1, 1024, 1024), PositionTexture.CreatePosSize(rightCenter, 1, .5, 1024, 1024), ringImage, level));
                //RingsTriangleLists[1].Add(RenderTriangle.Create(PositionTexture.CreatePosSize(center, .5, .5, 1024, 1024), PositionTexture.CreatePosSize(bottomCenter, .5, 1, 1024, 1024), PositionTexture.CreatePosSize(BottomRight, 1, 1, 1024, 1024), ringImage, level));

                List<PositionTexture> vertexList;
                vertexList = new List<PositionTexture>();

                int Width = 1024;
                int Height = 1024;

                vertexList.Add(PositionTexture.CreatePosSize(TopLeft, 0, 0, Width, Height));
                vertexList.Add(PositionTexture.CreatePosSize(TopRight, 1, 0, Width, Height));
                vertexList.Add(PositionTexture.CreatePosSize(BottomLeft, 0, 1, Width, Height));
                vertexList.Add(PositionTexture.CreatePosSize(BottomRight, 1, 1, Width, Height));

                List<Triangle> childTriangleList = new List<Triangle>();

                //if (dataset.BottomsUp)
                //{
                //    childTriangleList.Add(Triangle.Create(0, 1, 2));
                //    childTriangleList.Add(Triangle.Create(2, 1, 3));
                //}
                //else
                {
                    childTriangleList.Add(Triangle.Create(0, 2, 1));
                    childTriangleList.Add(Triangle.Create(2, 3, 1));

                }

                int count = 5;
                while (count-- > 1)
                {
                    List<Triangle> newList = new List<Triangle>();
                    foreach (Triangle tri in childTriangleList)
                    {
                        tri.SubDivideNoNormalize(newList, vertexList);
                    }
                    childTriangleList = newList;
                }

                double miter = .6 / (Width / 256);
                foreach (Triangle tri in childTriangleList)
                {
                    PositionTexture p1 = vertexList[tri.A];
                    PositionTexture p2 = vertexList[tri.B];
                    PositionTexture p3 = vertexList[tri.C];

                    RingsTriangleLists[0].Add(RenderTriangle.CreateWithMiter(p1, p2, p3, ringImage, level, miter));
                }

            }

            if (renderContext.gl == null)
            {
                Vector3d cam = renderContext.CameraPosition;
                Vector3d test = new Vector3d();

                //Matrix3d wv = renderContext.WV;

                Matrix3d worldLocal = Matrix3d.MultiplyMatrix(Matrix3d.RotationY(Math.Atan2(renderContext.SunPosition.X, renderContext.SunPosition.Z)), renderContext.WorldBaseNonRotating);

                Matrix3d wv = Matrix3d.MultiplyMatrix(worldLocal, renderContext.View);
                Matrix3d wvp = Matrix3d.MultiplyMatrix(wv, renderContext.Projection);
                double Width = renderContext.Width;
                double Height = renderContext.Height;

                wvp.Scale(Vector3d.Create(Width / 2, -Height / 2, 1));
                wvp.Translate(Vector3d.Create(Width / 2, Height / 2, 0));
                double td = 0;
               // RenderTriangle.CullInside = !RenderTriangle.CullInside;
                for (int i = 0; i < 2; i++)
                {
                    foreach (RenderTriangle tri in RingsTriangleLists[0])
                    {
                        //test = Vector3d.SubtractVectors(wv.Transform(tri.A.Position), cam);
                        test = wv.Transform(tri.A.Position);
                        td = test.Length();

                        bool draw = td > distance;

                        if (front)
                        {
                            draw = !draw;
                        }

                        if (draw)
                        {
                            tri.Opacity = 1;

                            tri.Draw(renderContext.Device, wvp);
                        }
                    }
                    RenderTriangle.CullInside = !RenderTriangle.CullInside;
                }
            }
            else
            {
                //todo port rings to web gl
                //renderContext.gl.enableVertexAttribArray(renderContext.vertLoc);
                //renderContext.gl.enableVertexAttribArray(renderContext.textureLoc);
                //renderContext.gl.bindBuffer(GL.ARRAY_BUFFER, VertexBuffer);
                //renderContext.gl.vertexAttribPointer(renderContext.vertLoc, 3, GL.FLOAT, false, 20, 0);
                ////renderContext.gl.bindBuffer(GL.ARRAY_BUFFER, VertexBuffer);
                //renderContext.gl.vertexAttribPointer(renderContext.textureLoc, 2, GL.FLOAT, false, 20, 12);
                //renderContext.gl.activeTexture(GL.TEXTURE0);
                //renderContext.gl.bindTexture(GL.TEXTURE_2D, texture2d);

                ////if (tileX == TileTargetX && tileY == TileTargetY && Level == TileTargetLevel)
                ////{
                ////    renderContext.gl.bindTexture(GL.TEXTURE_2D, null);
                ////}

                //renderContext.gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, GetIndexBuffer(part, accomidation));
                //renderContext.gl.drawElements(GL.TRIANGLES, TriangleCount * 3, GL.UNSIGNED_SHORT, 0);
            }
        }
示例#18
0
 public Pattern CreatePattern(ImageElement image, string repetition) {
     return null;
 }
示例#19
0
 public void DrawImage(ImageElement image, double dx, double dy) {
 }
示例#20
0
 public void DrawImage(ImageElement image, double sx, double sy, double sw, double sh, double dx, double dy, double dw, double dh) {
 }
示例#21
0
        protected override void Init()
        {
            #if DEBUG
            if (Current != null) throw Exception.Create("Cannot have more than one ShooterLevel running at the same time!", null);
            #endif
            pendingTimers = new List<int>();

            if (jQuery.Browser.Mozilla)
                _music = LoadAudio("Audio/boss.ogg");
            else
                _music = LoadAudio("Audio/boss.mp3");

            Current = this;
            Status = ShooterStatus.Starting;
            BaseSpeed = 0.05f;
            _backgroundImage = LoadImage("Images/shooter/bg.png", false);
            AddSystem(new CloudSystem());
            AddSystem(Meteor = new MeteorSystem());
            AddSystem(Buildings = new BuildingSystem(700, _length, 3));
            AddSystem(Dinos = new DinosSystem(_length));
            AddSystem(_weapons = new WeaponsSystem());
            AddSystem(Plasma = new PlasmaSystem());
            AddSystem(Bonus = new BonusSystem());

            ShowMessage(_startMessage);
            Window.SetTimeout(delegate()
            {
                HideMessage();
                Status = ShooterStatus.Running;
                _music.Play();

                _music.AddEventListener("ended", delegate(ElementEvent e) { _music.Play(); }, false);
            }, 3000);
        }
		void ShowAjaxIcon()
		{
			if (ajaxIcon == null)
			{
				ajaxIcon = (ImageElement) Document.CreateElement("IMG");
				ajaxIcon.Src = "/Gfx/autocomplete-loading.gif";
				ajaxIcon.Style.Height = "16px";
				ajaxIcon.Style.Width = "16px";
				ajaxIcon.Style.Position = "absolute";
				jQueryPosition offset = jQuery.FromElement(anchor).GetOffset();
				ajaxIcon.Style.Left = (offset.Left + anchor.ClientWidth - 18) + "px";
				ajaxIcon.Style.Top = (offset.Top + 2) + "px";
				ajaxIcon.Style.ZIndex = 200;
				Document.Body.AppendChild(ajaxIcon);
			}
			ajaxIcon.Style.Display = "";
		}
示例#23
0
        private ImageElement cloneImage(ImageElement cardImage)
        {
            var img = new ImageElement();
            img.Src = cardImage.Src;

            return img;
        }
示例#24
0
        public void Load(string data)
        {
            string[] lines = data.Split("\r\n");

            starProfile = (ImageElement)Document.CreateElement("img");
            starProfile.AddEventListener("load", delegate(ElementEvent e)
            {
                imageReady = true;
            }, false);
            starProfile.Src = "images/starProfile.png";
            bool gotHeader = false;
            foreach (string line in lines)
            {
                if (gotHeader)
                {
                    table.Add(line.Split("\t"));
                }
                else
                {
                    header = line.Split("\t");
                    gotHeader = true;
                }
            }
        }
 public override void Init(Scene level)
 {
     if (_backgroundImage != null) return;
     _backgroundImage = level.LoadImage("images/bg.png", false);
 }
示例#26
0
 public override void Dispose()
 {
     base.Dispose();
     _backgroundImage = null;
     _music.Pause();
     _music = null;
     Current = null;
 }
示例#27
0
 public override void Dispose()
 {
     base.Dispose();
     _backgroundImage = null;
     _timeLeftFrame = null;
     _meterImage = null;
     _markerImage = null;
     _music.Pause();
     _music = null;
 }
        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;
        }
示例#29
0
        protected override void Init()
        {
            if (jQuery.Browser.Mozilla)
                _music = LoadAudio("Audio/race.ogg");
            else
                _music = LoadAudio("Audio/race.mp3");

            TimeLeft = RoadLength / 35;

            Position = 0;
            Shift = 0;

            pendingTimers = new List<int>();

            AddSystem(new RoadSystem());
            AddSystem(new CloudSystem());
            AddSystem(new ObstacleSystem());
            AddSystem(_npcSystem = new NpcSystem());
            AddSystem(CarSystem = new CarSystem());
            AddSystem(_engineSoundSystem = new EngineSoundSystem());

            // Get reference to game images
            _backgroundImage = LoadImage("Images/Race/bg.png", false);
            _timeLeftFrame = LoadImage("Images/Race/TimeLeft.png", false);
            _meterImage = LoadImage("Images/Race/rpm10.png", false);
            _markerImage = LoadImage("Images/Race/marker.png", false);

            // Setup the track
            Curve = 0;

            _rpm = 200;
            Status = RaceStatus.Starting;

            // Calculate the distance table for track rendering
            DistanceTable = new float[Lines];
            for (int i = 0; i < Lines + 1; i++)
            {
                DistanceTable[i] = 1000000 / (300 - i);
            }

            ShowMessage(_startMessage);
            Window.SetTimeout(delegate()
            {
                HideMessage();
                Status = RaceStatus.Running;
                _music.Play();

                _music.AddEventListener("ended", delegate(ElementEvent e) { _music.Play(); }, false);
            }, 3000);
        }
示例#30
0
        //int imageCount = 0;
        //int imageLoadCount = 0;
        //bool imagesLoaded = false;
        //bool downloading = false;
        //ImageElement LoadImageElement(string url)
        //{
        //    imageCount++;
        //    imagesLoaded = false;
        //    downloading = true;
        //    ImageElement temp = (ImageElement)Document.CreateElement("img");
        //    temp.Src = url;
        //    temp.AddEventListener("load", delegate(ElementEvent e)
        //    {
        //        ImageLoadCount++;
        //        if (imageLoadCount == imageCount)
        //        {
        //            downloading = false;
        //            ImagesLoaded = true;
        //           // Refresh();
        //        }
        //    }, false);
        //    return temp;
        //}
        public void LoadImages()
        {
            if (!ImagesLoaded && !downloading)
            {
                ImageLoadCount = 0;
                ImagesLoaded = false;
                downloading = true;
                bmpBackground = (ImageElement)Document.CreateElement("img");
                bmpBackground.Src = "images/thumbBackground.png";
                bmpBackground.AddEventListener("load", delegate(ElementEvent e)
                {
                    ImageLoadCount++;
                    if (ImageLoadCount == 5)
                    {
                        downloading = false;
                        ImagesLoaded = true;
                        Refresh();
                    }
                }, false);

                bmpBackgroundHover = (ImageElement)Document.CreateElement("img");
                bmpBackgroundHover.Src = "images/thumbBackgroundHover.png";
                bmpBackgroundHover.AddEventListener("load", delegate(ElementEvent e)
                {
                    ImageLoadCount++;
                    if (ImageLoadCount == 5)
                    {
                        downloading = false;
                        ImagesLoaded = true;
                        Refresh();
                    }
                }, false);
                bmpBackgroundWide = (ImageElement)Document.CreateElement("img");
                bmpBackgroundWide.Src = "images/thumbBackgroundWide.png";
                bmpBackgroundWide.AddEventListener("load", delegate(ElementEvent e)
                {
                    ImageLoadCount++;
                    if (ImageLoadCount == 5)
                    {
                        downloading = false;
                        ImagesLoaded = true;
                        Refresh();
                    }
                }, false);
                bmpBackgroundWideHover = (ImageElement)Document.CreateElement("img");
                bmpBackgroundWideHover.Src = "images/thumbBackgroundWideHover.png";
                bmpBackgroundWideHover.AddEventListener("load", delegate(ElementEvent e)
                {
                    ImageLoadCount++;
                    if (ImageLoadCount == 5)
                    {
                        downloading = false;
                        ImagesLoaded = true;
                        Refresh();
                    }
                }, false);
                bmpDropInsertMarker = (ImageElement)Document.CreateElement("img");
                bmpDropInsertMarker.Src = "images/dragInsertMarker.png";
                bmpDropInsertMarker.AddEventListener("load", delegate(ElementEvent e)
                {
                    ImageLoadCount++;
                    if (ImageLoadCount == 5)
                    {
                        downloading = false;
                        ImagesLoaded = true;
                        Refresh();
                    }
                }, false);
            }
        }