//--------------------------------------------------- //-------------------Constructors-------------------- //--------------------------------------------------- public TileModel(string name,Point location, Size size, GorgonLibrary.Graphics.Sprite sprite, bool isCrossable, bool isTexture) { this.surfaceRect = new Rectangle(location, new Size(32,32)); this.OriginalSize = size; this.GorgonSprite = sprite; this.IsCrossable = isCrossable; this.IsTexture = isTexture; this.Name = name; }
//--------------------------------------------------- //-------------------Constructors-------------------- //--------------------------------------------------- public TileModel(string name, Point location, Size size, GorgonLibrary.Graphics.Sprite sprite, bool isCrossable, bool isTexture) { this.surfaceRect = new Rectangle(location, new Size(32, 32)); this.OriginalSize = size; this.GorgonSprite = sprite; this.IsCrossable = isCrossable; this.IsTexture = isTexture; this.Name = name; }
private void addToPaletteToolStripMenuItem_Click(object sender, EventArgs e) { if (this.TilesSelection != null) { TilesMap currentMap = this.TilesSelection.TilesMapParent; if (currentMap != null) { for (int i = 0; i < this.TilesSelection.ListModelsSelected.Count; i++) { TileModel model = this.TilesSelection.ListModelsSelected[i]; if (model != null) { string finalName = model.Name.Replace("_MODEL", ""); if (model.IsTexture == true) { if (!currentMap.IsTileModelExists(currentMap.TileModelsTextureUsed, finalName)) { //Clone gorgon image Image img = model.GorgonSprite.Image.SaveBitmap(); GorgonLibrary.Graphics.Image newImage = GorgonLibrary.Graphics.Image.FromBitmap(finalName, img); GorgonLibrary.Graphics.Sprite sprite = new GorgonLibrary.Graphics.Sprite(finalName, newImage); TileModel newModel = new TileModel(finalName, model.surfaceRect.Location, model.surfaceRect.Size, sprite, false, true); img.Dispose(); img = null; currentMap.TileModelsTextureUsed.Add(newModel); currentMap.UpdateGorgonTileModel(newModel, true); } } else { if (!currentMap.IsTileModelExists(currentMap.TileModelsObjectsUsed, finalName)) { //Clone gorgon image Image img = model.GorgonSprite.Image.SaveBitmap(); GorgonLibrary.Graphics.Image newImage = GorgonLibrary.Graphics.Image.FromBitmap(finalName, img); GorgonLibrary.Graphics.Sprite sprite = new GorgonLibrary.Graphics.Sprite(finalName, newImage); TileModel newModel = new TileModel(finalName, model.surfaceRect.Location, model.surfaceRect.Size, sprite, false, false); img.Dispose(); img = null; currentMap.TileModelsObjectsUsed.Add(newModel); currentMap.UpdateGorgonTileModel(newModel, true); } } } } GorgonLibrary.Gorgon.Go(); } } }
public DisplayObject(GorgonLibrary.Graphics.Sprite gorgonSprite, Point location, CoronaObject coronaObjectParent) { this.surfaceRect = new Rectangle(); this.GorgonSprite = gorgonSprite; this.surfaceRect.Size = new Size(GorgonSprite.Image.Width, GorgonSprite.Image.Height) ; this.surfaceRect.Location = location; InitialRect = this.surfaceRect; this.Name = ""; this.type = "IMAGE"; CurrentFrame = 0; Alpha = 1.0F; this.GradientColor = new GradientColor(); this.CoronaObjectParent = coronaObjectParent; }
public DisplayObject(GorgonLibrary.Graphics.Sprite gorgonSprite, Point location, CoronaObject coronaObjectParent) { this.surfaceRect = new Rectangle(); this.GorgonSprite = gorgonSprite; this.surfaceRect.Size = new Size(GorgonSprite.Image.Width, GorgonSprite.Image.Height); this.surfaceRect.Location = location; InitialRect = this.surfaceRect; this.Name = ""; this.type = "IMAGE"; CurrentFrame = 0; Alpha = 1.0F; this.GradientColor = new GradientColor(); this.CoronaObjectParent = coronaObjectParent; }
private void addTextureSetToList(string pathImage, string name, Size tilesSize) { TileSheetModel sheetModel = new TileSheetModel(name, pathImage, true); //Charger la texture set Bitmap textureSet = new Bitmap(Image.FromFile(pathImage)); //Recuperer le nombre de texture par ligne et colonne int nbTexturesLigne = textureSet.Width / tilesSize.Width; int nbTexturesColonne = textureSet.Height / tilesSize.Height; //Creer et ajouter les textures for (int i = 0; i < nbTexturesColonne; i++) { for (int j = 0; j < nbTexturesLigne; j++) { //Recuperer l'image de la texture Bitmap texture = textureSet.Clone(new Rectangle(new Point(j * tilesSize.Width, i * tilesSize.Height), new Size(tilesSize.Width, tilesSize.Height)), System.Drawing.Imaging.PixelFormat.Format32bppArgb); //Creer une texture model et l'ajouter a la liste int index = i * nbTexturesLigne + j; string modelName = "TEXTURE_" + sheetModel.ToString() + "_" + index + "_MODEL"; GorgonLibrary.Graphics.Sprite sprite = new GorgonLibrary.Graphics.Sprite(modelName, GorgonLibrary.Graphics.Image.FromBitmap(modelName, texture)); texture.Dispose(); TileModel model = new TileModel(modelName, new Point(0, 0), tilesSize, sprite, true, true); sheetModel.TileModels.Add(model); } } //Relacher la texture Set principale textureSet.Dispose(); this.textureSheetCombBx.Items.Add(sheetModel); }
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); } }
public void UpdateTileMapGraphicsContent() { try { if (this.TileModelsTextureUsed != null) { for (int i = 0; i < this.TileModelsTextureUsed.Count; i++) { TileModel tileModel = this.TileModelsTextureUsed[i]; if (tileModel.Name == null || tileModel.Name.Equals("")) { tileModel.Name = "TEXTURE_" + this.TilesMapName + "_" + i; } this.UpdateGorgonTileModel(tileModel, true); } } if (this.TileModelsObjectsUsed != null) { for (int i = 0; i < this.TileModelsObjectsUsed.Count; i++) { TileModel tileModel = this.TileModelsObjectsUsed[i]; if (tileModel.Name == null || tileModel.Name.Equals("")) { tileModel.Name = "OBJECT_" + this.TilesMapName + "_" + i; } this.UpdateGorgonTileModel(tileModel, true); } } if (this.TextureSequences != null) { for (int i = 0; i < this.TextureSequences.Count; i++) { TileSequence seq = this.TextureSequences[i]; for (int j = 0; j < seq.Frames.Count; j++) { TileModel tileModel = seq.Frames[j]; if (tileModel.Name == null || tileModel.Name.Equals("")) { tileModel.Name = "TEXTURESEQUENCE_" + this.TilesMapName + "_" + i + "_" + j; } this.UpdateGorgonTileModel(tileModel, true); } } } if (this.ObjectSequences != null) { for (int i = 0; i < this.ObjectSequences.Count; i++) { TileSequence seq = this.ObjectSequences[i]; for (int j = 0; j < seq.Frames.Count; j++) { TileModel tileModel = seq.Frames[j]; if (tileModel.Name == null || tileModel.Name.Equals("")) { tileModel.Name = "OBJECTSEQUENCE_" + this.TilesMapName + "_" + i+"_"+j; } this.UpdateGorgonTileModel(tileModel, true); } } } //Icons EVENTS if (this.TouchEventSprite == null) { this.TouchEventSprite = new GorgonLibrary.Graphics.Sprite("TouchEventSprite", GorgonLibrary.Graphics.Image.FromBitmap("TouchEventSprite", Properties.Resources.touchIcon)); } if (this.CollisionEventSprite == null) { this.CollisionEventSprite = new GorgonLibrary.Graphics.Sprite("CollisionEventSprite", GorgonLibrary.Graphics.Image.FromBitmap("CollisionEventSprite", Properties.Resources.collisionIcon2)); } if (this.PreCollisionEventSprite == null) { this.PreCollisionEventSprite = new GorgonLibrary.Graphics.Sprite("PreCollisionEventSprite", GorgonLibrary.Graphics.Image.FromBitmap("PreCollisionEventSprite", Properties.Resources.preCollisionIcon)); } if (this.PostCollisionEventSprite == null) { this.PostCollisionEventSprite = new GorgonLibrary.Graphics.Sprite("PostCollisionEventSprite", GorgonLibrary.Graphics.Image.FromBitmap("PostCollisionEventSprite", Properties.Resources.postCollisionIcon)); } } catch (Exception ex) { } }
public void UpdateGorgonTileModel(TileModel model, bool shouldExport) { if (model != null) { if (shouldExport == true) { this.ExportTileModelToProjectResources(model); } this.CleanTileModel(model, true, false, true); string projectPath = this.LayerParent.SceneParent.projectParent.ProjectPath; string filename = Path.Combine(projectPath + "\\Resources\\TileMaps\\" + this.TilesMapName , model.Name + ".png"); if (File.Exists(filename)) { GorgonLibrary.Graphics.Sprite sprite = new GorgonLibrary.Graphics.Sprite(model.Name, GorgonLibrary.Graphics.Image.FromFile(filename)); model.GorgonSprite = sprite; sprite.Color = Color.White; } } }
public DisplayObject cloneInstance(bool keepLocation) { if (this.type.Equals("SPRITE")) { Point pDest; if (keepLocation == true) { pDest = new Point(this.SurfaceRect.X, this.SurfaceRect.Y); } else { pDest = new Point(this.SurfaceRect.X + 20, this.SurfaceRect.Y); } DisplayObject obj = new DisplayObject(this.SpriteSet, pDest, this.CoronaObjectParent); obj.OriginalAssetName = this.OriginalAssetName; obj.Name = this.Name; obj.setSequence(this.CurrentSequence); obj.CurrentFrame = this.CurrentFrame; obj.AutoPlay = this.AutoPlay; return(obj); } else if (this.type.Equals("IMAGE")) { //Creer une nouvelle Image Image newImage = null; DisplayObject newDisplayObject = null; if (this.GorgonSprite != null) { GorgonLibrary.Graphics.Sprite newGorgonSprite = (GorgonLibrary.Graphics.Sprite) this.GorgonSprite.Clone(); newDisplayObject = new DisplayObject(newGorgonSprite, new Point(0, 0), this.CoronaObjectParent); } else if (this.image != null) { newImage = new Bitmap(this.image); newDisplayObject = new DisplayObject(newImage, new Point(0, 0), this.CoronaObjectParent); } else { return(null); } newDisplayObject.OriginalAssetName = this.OriginalAssetName; newDisplayObject.Name = this.Name; //Changer la position de l'objet Point pDest; if (keepLocation == true) { pDest = new Point(this.SurfaceRect.X, this.SurfaceRect.Y); } else { pDest = new Point(this.SurfaceRect.X + 20, this.SurfaceRect.Y); } newDisplayObject.surfaceRect = new Rectangle(pDest, this.surfaceRect.Size); newDisplayObject.InitialRect = new Rectangle(this.InitialRect.X, this.InitialRect.Y, this.InitialRect.Width, this.InitialRect.Height); newDisplayObject.ImageFillColor = this.ImageFillColor; return(newDisplayObject); } else if (this.type.Equals("FIGURE")) { //Recuperer le clone de la figure Figure newFig = this.Figure.CloneInstance(keepLocation); DisplayObject newDisplayObject = new DisplayObject(newFig, this.CoronaObjectParent); newFig.DisplayObjectParent = newDisplayObject; newDisplayObject.OriginalAssetName = this.OriginalAssetName; newDisplayObject.Name = this.Name; //Copy the gradient color newDisplayObject.GradientColor.color1 = this.GradientColor.color1; newDisplayObject.GradientColor.color2 = this.GradientColor.color2; newDisplayObject.GradientColor.isEnabled = this.GradientColor.isEnabled; newDisplayObject.GradientColor.direction = this.GradientColor.direction; if (newFig.ShapeType.Equals("TEXT")) { Texte text = (Texte)newFig; if (this.GorgonSprite != null) { newDisplayObject.GorgonSprite = (GorgonLibrary.Graphics.Sprite) this.GorgonSprite.Clone(); } Point pDest; if (keepLocation == true) { pDest = new Point(text.Position.X, text.Position.Y); } else { pDest = new Point(text.Position.X + 20, text.Position.Y); } newDisplayObject.SurfaceRect = new Rectangle(pDest, this.surfaceRect.Size); } return(newDisplayObject); } return(null); }
private void addTextureSetToList(string pathImage,string name,Size tilesSize) { TileSheetModel sheetModel = new TileSheetModel(name,pathImage, true); //Charger la texture set Bitmap textureSet = new Bitmap(Image.FromFile(pathImage)); //Recuperer le nombre de texture par ligne et colonne int nbTexturesLigne = textureSet.Width / tilesSize.Width; int nbTexturesColonne = textureSet.Height / tilesSize.Height; //Creer et ajouter les textures for (int i = 0; i < nbTexturesColonne; i++) { for (int j = 0; j < nbTexturesLigne; j++) { //Recuperer l'image de la texture Bitmap texture = textureSet.Clone(new Rectangle(new Point(j * tilesSize.Width, i * tilesSize.Height), new Size(tilesSize.Width, tilesSize.Height)), System.Drawing.Imaging.PixelFormat.Format32bppArgb); //Creer une texture model et l'ajouter a la liste int index = i * nbTexturesLigne + j; string modelName = "TEXTURE_" + sheetModel.ToString() + "_" + index + "_MODEL"; GorgonLibrary.Graphics.Sprite sprite = new GorgonLibrary.Graphics.Sprite(modelName, GorgonLibrary.Graphics.Image.FromBitmap(modelName,texture)); texture.Dispose(); TileModel model = new TileModel(modelName, new Point(0, 0), tilesSize, sprite, true, true); sheetModel.TileModels.Add(model); } } //Relacher la texture Set principale textureSet.Dispose(); this.textureSheetCombBx.Items.Add(sheetModel); }