Example #1
0
        public void DrawGorgon(Point offsetPoint, string layerToShow, bool showCollision, float worldScale)
        {
            Point pDest = new Point((int)((this.mapParent.Location.X + this.Location.X + offsetPoint.X) * worldScale),
                                    (int)((this.mapParent.Location.Y + this.Location.Y + offsetPoint.Y) * worldScale));

            Rectangle rectDest = new Rectangle(pDest,
                                               new Size((int)((this.mapParent.TilesWidth * worldScale)),
                                                        (int)((this.mapParent.TilesHeight) * worldScale)));

            if (layerToShow.Equals("ALL") || layerToShow.Equals("TEXTURE"))
            {
                //Dessiner l'image associƩe
                if (this.TileModelTexture != null)
                {
                    GorgonLibrary.Graphics.Sprite sprite = this.TileModelTexture.GorgonSprite;
                    if (sprite != null && sprite.Image != null)
                    {
                        float imgScaleX = (float)this.mapParent.TilesWidth / (float)sprite.Image.Width;
                        float imgScaleY = (float)this.mapParent.TilesHeight / (float)sprite.Image.Height;

                        float finalXScale = worldScale * imgScaleX;
                        float finalYScale = worldScale * imgScaleY;
                        sprite.SetScale(finalXScale, finalYScale);

                        sprite.SetPosition(pDest.X, pDest.Y);
                        sprite.Draw();
                    }
                    else
                    {
                        this.TileModelTexture = null;
                    }
                }


                if (this.TileTextureSequence != null)
                {
                    if (this.mapParent.TextureSequences.Contains(this.TileTextureSequence) && this.TileTextureSequence.Frames.Count > 0)
                    {
                        GorgonLibrary.Graphics.Sprite sprite = this.TileTextureSequence.Frames[0].GorgonSprite;
                        if (sprite != null && sprite.Image != null)
                        {
                            float imgScaleX = (float)this.mapParent.TilesWidth / (float)sprite.Image.Width;
                            float imgScaleY = (float)this.mapParent.TilesHeight / (float)sprite.Image.Height;

                            float finalXScale = worldScale * imgScaleX;
                            float finalYScale = worldScale * imgScaleY;
                            sprite.SetScale(finalXScale, finalYScale);

                            sprite.SetPosition(pDest.X, pDest.Y);
                            sprite.Draw();
                        }
                    }
                    else
                    {
                        this.TileTextureSequence = null;
                    }
                }
            }


            if (layerToShow.Equals("ALL") || layerToShow.Equals("OBJECT"))
            {
                if (this.TileModelImageObject != null)
                {
                    GorgonLibrary.Graphics.Sprite sprite = this.TileModelImageObject.GorgonSprite;
                    if (sprite != null && sprite.Image != null)
                    {
                        float imgScaleX = (float)this.mapParent.TilesWidth / (float)sprite.Image.Width;
                        float imgScaleY = (float)this.mapParent.TilesHeight / (float)sprite.Image.Height;

                        float finalXScale = worldScale * imgScaleX;
                        float finalYScale = worldScale * imgScaleY;
                        sprite.SetScale(finalXScale, finalYScale);

                        sprite.SetPosition(pDest.X, pDest.Y);
                        sprite.Draw();
                    }
                    else
                    {
                        this.TileModelImageObject = null;
                    }
                }


                if (this.TileObjectSequence != null)
                {
                    if (this.mapParent.ObjectSequences.Contains(this.TileObjectSequence) && this.TileObjectSequence.Frames.Count > 0)
                    {
                        GorgonLibrary.Graphics.Sprite sprite = this.TileObjectSequence.Frames[0].GorgonSprite;
                        if (sprite != null && sprite.Image != null)
                        {
                            float imgScaleX = (float)this.mapParent.TilesWidth / (float)sprite.Image.Width;
                            float imgScaleY = (float)this.mapParent.TilesHeight / (float)sprite.Image.Height;

                            float finalXScale = worldScale * imgScaleX;
                            float finalYScale = worldScale * imgScaleY;
                            sprite.SetScale(finalXScale, finalYScale);

                            sprite.SetPosition(pDest.X, pDest.Y);
                            sprite.Draw();
                        }
                        else
                        {
                            this.TileObjectSequence = null;
                        }
                    }
                    else
                    {
                        this.TileObjectSequence = null;
                    }
                }
            }

            if (layerToShow.Equals("ALL") || layerToShow.Equals("EVENT"))
            {
                if (this.TileEvent != null)
                {
                    if (this.mapParent.TileEvents.Contains(this.TileEvent))
                    {
                        GorgonLibrary.Graphics.Sprite sprite = null;
                        if (this.TileEvent.Type == TilesMapping.TileEvent.TileEventType.collision)
                        {
                            sprite = this.mapParent.CollisionEventSprite;
                        }
                        else if (this.TileEvent.Type == TilesMapping.TileEvent.TileEventType.preCollision)
                        {
                            sprite = this.mapParent.PreCollisionEventSprite;
                        }
                        else if (this.TileEvent.Type == TilesMapping.TileEvent.TileEventType.postCollision)
                        {
                            sprite = this.mapParent.PostCollisionEventSprite;
                        }
                        else if (this.TileEvent.Type == TilesMapping.TileEvent.TileEventType.touch)
                        {
                            sprite = this.mapParent.TouchEventSprite;
                        }

                        if (sprite != null)
                        {
                            float imgScaleX = (float)this.mapParent.TilesWidth / 2 / (float)sprite.Image.Width;
                            float imgScaleY = (float)this.mapParent.TilesHeight / 2 / (float)sprite.Image.Height;

                            float finalXScale = worldScale * imgScaleX;
                            float finalYScale = worldScale * imgScaleY;
                            sprite.SetScale(finalXScale, finalYScale);

                            sprite.SetPosition(pDest.X, pDest.Y);
                            sprite.Draw();
                        }
                    }
                    else
                    {
                        this.TileEvent = null;
                    }
                }
            }

            if (showCollision == true)
            {
                Color color;
                if (this.IsCrossable == true)
                {
                    color = Color.FromArgb(50, Color.LightBlue);
                }
                else
                {
                    color = Color.FromArgb(100, Color.Red);
                }


                Rectangle rectCollision = new Rectangle(this.mapParent.Location.X + this.Location.X + offsetPoint.X,
                                                        this.mapParent.Location.Y + this.Location.Y + offsetPoint.Y,
                                                        this.mapParent.TilesWidth, this.mapParent.TilesHeight);

                GorgonGraphicsHelper.Instance.FillRectangle(rectCollision, 1, color, worldScale, false);
            }
        }