public TestCircle() { m_pntVel = new EPointF(0,0); m_pntThrust = new EPoint(0,0); aKeysPressedX = new ArrayList(); aKeysPressedY = new ArrayList(); Bitmap bmp = new Bitmap(40,40, PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(bmp); g.FillEllipse(new SolidBrush(Color.Red), 0,0,40,40); g.Dispose(); MemberSpriteBitmap mb = new MemberSpriteBitmap(bmp); mb.CenterRegPoint(); Member = mb; m_aLines = new ArrayList(); for (int i = 0; i < 1; i++) { TestLine line = new TestLine(m_endogine); line.SetLine(new EPointF((i)*150,0), new EPointF((i+1)*150,150)); m_aLines.Add(line); } LocZ = 10; Loc = new EPointF(171,171); m_endogine.KeyEvent+=new KeyEventHandler(m_endogine_KeyEvent); }
//public PicRef(string fileName) //{ // PicRef.LoadPicRef(fileName); //} public PicRef(System.Drawing.Bitmap bmp, string name) { MemberSpriteBitmap mb = new MemberSpriteBitmap(bmp); this.PostConstructor(name); mb.Name = this._originalName; this._mb = mb; }
public static PicRef Create(MemberSpriteBitmap mb, string name) { PicRef pr = new PicRef(name, (MemberSpriteBitmap)mb); pr.Offset = new EPoint(); return(pr); }
public Colorizer() { Bitmap bmp = new Bitmap(1,1); Graphics g = Graphics.FromImage(bmp); g.FillRectangle(new SolidBrush(Color.FromArgb(255,255,255)), 0,0,1,1); Endogine.MemberSpriteBitmap mb = new MemberSpriteBitmap(bmp); this.Member = mb; this.Ink = RasterOps.ROPs.SubtractPin; }
public void Create(int width, int height) { Bitmap bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(bmp); g.FillRectangle(new SolidBrush(Color.White), 0,0,bmp.Width,bmp.Height); MemberSpriteBitmap mb = new MemberSpriteBitmap(bmp); this.Member = mb; this._canvas = this.Member.Canvas; //this._pm = this.Member.PixelManipulator; }
private void PlayerBall_MouseEvent(Sprite sender, System.Windows.Forms.MouseEventArgs e, MouseEventType t) { if (t == Sprite.MouseEventType.Down) { forceMarker.Visible = true; } else if (t == Sprite.MouseEventType.StillDown) { MemberSpriteBitmap mb = forceMarker.Member; if (mb!=null) mb.Dispose(); //this.MouseDownLoc.X, this.MouseDownLoc.Y ERectangleF rctLine = ERectangleF.FromLTRB(this.Loc.X, this.Loc.Y, this.MouseLastLoc.X, this.MouseLastLoc.Y); forceVector = rctLine.Size; if (rctLine.Width != 0 && rctLine.Height != 0) { Bitmap bmp = new Bitmap((int)Math.Abs(rctLine.Width)+1, (int)Math.Abs(rctLine.Height)+1, System.Drawing.Imaging.PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(bmp); ERectangleF rctOrigo = rctLine.Copy(); rctOrigo.MakeTopLeftAtOrigo(); Pen pen = new Pen(Color.Red, 2); g.DrawLine(pen, rctOrigo.X, rctOrigo.Y, rctOrigo.X+rctOrigo.Width, rctOrigo.Y+rctOrigo.Height); g.Dispose(); EPointF locOffset = new EPointF(); if (rctOrigo.Width < 0) locOffset.X = rctOrigo.Width; if (rctOrigo.Height < 0) locOffset.Y = rctOrigo.Height; mb = new MemberSpriteBitmap(bmp); forceMarker.Member = mb; forceMarker.Loc = this.Loc + locOffset; } else forceMarker.Member = null; } else if (t == Sprite.MouseEventType.UpOutside || t == Sprite.MouseEventType.Click) { this.Velocity = forceVector*-0.1f; forceMarker.Visible = false; MemberSpriteBitmap mb = forceMarker.Member; if (mb!=null) { forceMarker.Member = null; mb.Dispose(); } } }
public static List <PicRef> CreatePicRefs(string fileName, int numFramesOnX, int numFramesTotal) { if (fileName.IndexOf("\\") > 0) { fileName = fileName.Remove(0, fileName.LastIndexOf("\\") + 1); } int index = fileName.LastIndexOf("."); if (index > 0) { fileName = fileName.Remove(index); } MemberSpriteBitmap mb = (MemberSpriteBitmap)EH.Instance.CastLib.GetOrCreate(fileName); return(PicRef.CreatePicRefs(mb, numFramesOnX, numFramesTotal)); }
public void SetLine(EPointF a_pnt1, EPointF a_pnt2) { m_rct = ERectangleF.FromLTRB(a_pnt1.X, a_pnt1.Y, a_pnt2.X, a_pnt2.Y); if (Member!=null) Member.Dispose(); Loc = m_rct.Location; Bitmap bmp = new Bitmap((int)Math.Abs(m_rct.Width),(int)Math.Abs(m_rct.Height), PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(bmp); //Point pnt1 = a_pnt1; //if (a_pnt1.Y <= a_pnt2.Y && a_pnt1.X <= a_pnt2.X) g.DrawLine(new Pen(Color.White, 1), new Point(0,0), new Point((int)m_rct.Width, (int)m_rct.Height)); g.Dispose(); MemberSpriteBitmap mb = new MemberSpriteBitmap(bmp); Member = mb; }
private void miGDIPerlin_Click(object sender, System.EventArgs e) { if (m_spProcedural == null) { #region Procedural noise bitmap Random rnd = new Random(); Endogine.Procedural.Noise procedural = null; switch (rnd.Next(4)) { case 0: procedural = new Endogine.Procedural.Plasma(); procedural.Decay = 0.5f; procedural.Frequency = 0.1f; procedural.Octaves = 3; break; case 1: procedural = new Endogine.Procedural.Wood(); procedural.Decay = 0.5f; procedural.Frequency = 0.1f; procedural.Octaves = 3; ((Endogine.Procedural.Wood)procedural).NumCircles = 5; ((Endogine.Procedural.Wood)procedural).Turbulence = 0.3f; break; case 2: procedural = new Endogine.Procedural.Marble(); procedural.Decay = 0.5f; procedural.Frequency = 0.1f; procedural.Octaves = 3; ((Endogine.Procedural.Marble)procedural).Periods = new EPointF(15, 30); ((Endogine.Procedural.Marble)procedural).Turbulence = 3.3f; break; case 3: procedural = new Endogine.Procedural.Noise(); procedural.Decay = 0.5f; procedural.Frequency = 1f; procedural.Octaves = 3; break; } Bitmap bmp; Graphics g; bmp = new Bitmap(200, 200); Endogine.BitmapHelpers.Canvas canvas = Endogine.BitmapHelpers.Canvas.Create(bmp); //create a color table that makes it look like lakes and mountains: System.Collections.SortedList aColors = new System.Collections.SortedList(); aColors.Add(0.0, Color.FromArgb(0, 0, 190)); aColors.Add(0.1, Color.FromArgb(0, 0, 255)); aColors.Add(0.11, Color.FromArgb(0, 200, 0)); aColors.Add(0.5, Color.FromArgb(150, 100, 0)); aColors.Add(1.0, Color.FromArgb(255, 255, 255)); procedural.SetColors(aColors); //write pixels to bitmap: canvas.Locked = true; procedural.WriteToBitmap(canvas); canvas.Locked = false; #endregion #region Create gradient bitmap //Create two gradients using GDI+, and merge them with my CopyPixels for special effects Bitmap bmpGradient = new Bitmap(200, 200); g = Graphics.FromImage(bmpGradient); LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(4, 0, bmpGradient.Width, bmpGradient.Height), Color.FromArgb(255, 0, 0), Color.FromArgb(0, 255, 0), 0f); g.FillRectangle(brush, brush.Rectangle); Bitmap bmp2 = new Bitmap(bmpGradient.Width, bmpGradient.Height); brush = new LinearGradientBrush(new Rectangle(0, 0, bmp2.Width, bmp2.Height), Color.FromArgb(0, 0, 255), Color.FromArgb(0, 0, 0), (float)90); Graphics g2 = Graphics.FromImage(bmp2); g2.FillRectangle(brush, brush.Rectangle); RasterOps.CopyPixels(bmpGradient, bmp2, (int)RasterOps.ROPs.AddPin, 255); RasterOps.CopyPixels(bmp, bmpGradient, (int)RasterOps.ROPs.Lightest, 255); g.Dispose(); #endregion MemberSpriteBitmap mb = new MemberSpriteBitmap(bmp); m_spProcedural = new Sprite(); m_spProcedural.Name = "Procedural"; m_spProcedural.Member = mb; m_spProcedural.Scaling = new EPointF(2, 2); m_spProcedural.Ink = 0; } else { //TODO: the bitmap will still remain in memory, should have an "autodispose" option, //so that resources gets disposed when no sprites are using them m_spProcedural.Dispose(); m_spProcedural = null; } }
public PicRef(string originalName, MemberSpriteBitmap mb) { this._mb = mb; this.PostConstructor(originalName); }
public static void LoadPicRef(string bitmapFilename) { FileInfo bitmapFile = new FileInfo(bitmapFilename); PicRef.Prepare(); if (_originalsToMerged.ContainsValue(bitmapFile.FullName)) return; // throw new Exception("This tiled bitmap has already been loaded: "+bitmapFile.FullName); //For now, load the bitmap immediately. The retrieval process for each PicRef seems to be very slow. MemberSpriteBitmap mb = new MemberSpriteBitmap(bitmapFilename); XmlDocument doc = new XmlDocument(); string xmlFile = bitmapFile.FullName.Substring(0, bitmapFile.FullName.Length-bitmapFile.Extension.Length) + ".xml"; if (File.Exists(xmlFile)) { doc.Load(xmlFile); if (doc["root"]["Files"] != null) { List<string> fileOrder = new List<string>(); foreach (XmlNode node in doc["root"]["Files"]) { string originalFile = node.Attributes["value"].InnerXml; fileOrder.Add(originalFile); //remove file extension: int index = originalFile.LastIndexOf("."); if (index > 0) originalFile = originalFile.Remove(index, originalFile.Length - index); // if (_originalsToMerged.Contains(originalFile) //if (originalFile == "object01_0000") // EH.Put("Jks"); //_originalsToMerged.Add(originalFile, bitmapFile.FullName); PicRef picture = new PicRef(originalFile, mb); picture.SourceRectangle = new ERectangle(node["Rect"].Attributes["value"].InnerXml); picture.Offset = new EPoint(node["Offset"].Attributes["value"].InnerXml); } //TODO: ATM, nothing is done with the animation information in here. //Should be stored in a global animation collection - //accessed by [ if (doc["root"]["Animations"] != null) { foreach (XmlNode node in doc["root"]["Animations"]) { System.Collections.ArrayList anim = Endogine.Animation.AnimationHelpers.ParseAnimationString(node.Attributes["value"].InnerXml); List<string> animPics = new List<string>(); foreach (int frame in anim) animPics.Add(fileOrder[frame]); EH.Instance.CastLib.FrameSets.AddFrameSet(node.Name, animPics); } } } } }
public static PicRef Create(MemberSpriteBitmap mb, string name) { PicRef pr = new PicRef(name, (MemberSpriteBitmap)mb); pr.Offset = new EPoint(); return pr; }
public Car() { this._carType = new CarType(); this._carType.CenterOfMassToFront = 1; //2.5f; this._carType.CenterOfMassToRear = 1; // 1.5f; this._carType.CenterOfMassToGround = 1; // 0.5f; this._carType.Wheelbase = this._carType.CenterOfMassToFront + this._carType.CenterOfMassToRear; //2f; this._carType.Mass = 1500; this._carType.Inertia = 1500; this._carType.Width = 1.5f; // 2; this._carType.Length = 3; // 4.5f; this._carType.WheelLength = 0.7f; this._carType.WheelWidth = 0.3f; this._environment = new Environment(); this._environment.Drag = 5; this._environment.Resistance = 30; this._environment.CornerStiffnessR = -5.2f; this._environment.CornerStiffnessF = -5.0f; this._environment.MaxGrip = 2; float size = 5; Bitmap bmp = new Bitmap((int)(this._carType.Width * size), (int)(this._carType.Length * size), System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(bmp); g.FillRectangle(new SolidBrush(Color.Red), new Rectangle(0, 0, bmp.Width, bmp.Height)); g.FillRectangle(new SolidBrush(Color.Blue), new Rectangle(0, 3 * bmp.Height / 4, bmp.Width, bmp.Height / 4)); g.Dispose(); MemberSpriteBitmap mb = new MemberSpriteBitmap(bmp); this.Member = mb; this._keys = new KeysSteering(Endogine.KeysSteering.KeyPresets.ArrowsSpace); this._keys.AddKeyPreset(KeysSteering.KeyPresets.awsdCtrlShift); this._keys.ReceiveEndogineKeys(null); }
private void CreateVisualization() { if (this.bConstructing) return; this.bmpTopology = this.CreateBitmap(); Bitmap bmp = (Bitmap)this.bmpTopology.Clone(); Endogine.BitmapHelpers.Filters.EmbossFrom24BitGrayscale(bmp); this.bmpInclination = this.CreateInclinationBitmap(this.bmpTopology); bmp = this.bmpInclination; // Bitmap bmp2 = this.SplitInvert(bmp); MemberSpriteBitmap mb = new MemberSpriteBitmap(bmp); //mb.CenterRegPoint(); this.Member = mb; this.Ink = RasterOps.ROPs.AddPin; for (int i = this.ChildCount-1; i >= 0; i--) this.GetChildByIndex(i).Dispose(); // Sprite sp = new Sprite(); // sp.Parent = this; // MemberSpriteBitmap mb2 = new MemberSpriteBitmap(bmp2); // sp.Member = mb2; // sp.Ink = RasterOps.ROPs.SubtractPin; }
public static PicRef Create(string fileName) { MemberSpriteBitmap mb = (MemberSpriteBitmap)EH.Instance.CastLib.GetOrCreate(fileName); return(PicRef.Create(mb, fileName)); }
public static void LoadPicRef(string bitmapFilename) { FileInfo bitmapFile = new FileInfo(bitmapFilename); PicRef.Prepare(); if (_originalsToMerged.ContainsValue(bitmapFile.FullName)) { return; } // throw new Exception("This tiled bitmap has already been loaded: "+bitmapFile.FullName); //For now, load the bitmap immediately. The retrieval process for each PicRef seems to be very slow. MemberSpriteBitmap mb = new MemberSpriteBitmap(bitmapFilename); XmlDocument doc = new XmlDocument(); string xmlFile = bitmapFile.FullName.Substring(0, bitmapFile.FullName.Length - bitmapFile.Extension.Length) + ".xml"; if (File.Exists(xmlFile)) { doc.Load(xmlFile); if (doc["root"]["Files"] != null) { List <string> fileOrder = new List <string>(); foreach (XmlNode node in doc["root"]["Files"]) { string originalFile = node.Attributes["value"].InnerXml; fileOrder.Add(originalFile); //remove file extension: int index = originalFile.LastIndexOf("."); if (index > 0) { originalFile = originalFile.Remove(index, originalFile.Length - index); } // if (_originalsToMerged.Contains(originalFile) //if (originalFile == "object01_0000") // EH.Put("Jks"); //_originalsToMerged.Add(originalFile, bitmapFile.FullName); PicRef picture = new PicRef(originalFile, mb); picture.SourceRectangle = new ERectangle(node["Rect"].Attributes["value"].InnerXml); picture.Offset = new EPoint(node["Offset"].Attributes["value"].InnerXml); } //TODO: ATM, nothing is done with the animation information in here. //Should be stored in a global animation collection - //accessed by [ if (doc["root"]["Animations"] != null) { foreach (XmlNode node in doc["root"]["Animations"]) { System.Collections.ArrayList anim = Endogine.Animation.AnimationHelpers.ParseAnimationString(node.Attributes["value"].InnerXml); List <string> animPics = new List <string>(); foreach (int frame in anim) { animPics.Add(fileOrder[frame]); } EH.Instance.CastLib.FrameSets.AddFrameSet(node.Name, animPics); } } } } }
private void CreateNewTiles(int a_nLocX) { //use perlin noise to generate wall structure ArrayList aNoise = new ArrayList(); for (int x = 0; x < m_nTileWidth; x++) aNoise.Add(0f); m_noise.Offset = new EPointF(a_nLocX, 0); m_noise.FillArray(aNoise); PointF[] aPoints1 = new PointF[m_nTileWidth]; PointF[] aPoints2 = new PointF[m_nTileWidth]; for (int x = 0; x < m_nTileWidth; x++) { m_fCaveHeight*=0.9997f; float fAllowedY = m_rctPlayArea.Height - m_fCaveHeight; m_fMidY=((float)aNoise[x])*fAllowedY; float[] yPair = new float[]{m_fMidY, m_fMidY+m_fCaveHeight}; aPoints1[x] = new PointF(x,yPair[0]); aPoints2[x] = new PointF(x,yPair[1]); m_locYPairs.Add(x+a_nLocX, yPair); } ArrayList aBothTileLines = new ArrayList(); aBothTileLines.Add(new TileLines(aPoints1)); aBothTileLines.Add(new TileLines(aPoints2)); for (int i = 0; i < 2; i++) { TileLines tileLines = (TileLines)aBothTileLines[i]; Bitmap bmp; Graphics g; float fYDiff = tileLines.MaxY-tileLines.MinY+1; bmp = new Bitmap(m_nTileWidth,(int)fYDiff); g = Graphics.FromImage(bmp); g.FillRectangle(new SolidBrush(Color.Black), 0,0,bmp.Width,bmp.Height); //g.DrawLines(new Pen(Color.White, 2), tileLines.Points); //create polygon from lines: PointF[] polygon = tileLines.GetPolygon(i == 1); g.FillPolygon(new SolidBrush(Color.White), polygon); g.Dispose(); MemberSpriteBitmap mb = new MemberSpriteBitmap(bmp); Sprite sp = new Sprite(); sp.Member = mb; sp.LocX = a_nLocX; sp.LocY = tileLines.MinY; if (i == 0) sp.Name = "Ceiling"; else sp.Name = "Floor"; BhReportWhenOutside bh = new BhReportWhenOutside(); sp.AddBehavior(bh); bh.Outside+=new CaveHunter.BhReportWhenOutside.OutsideDelegate(bh_Outside); m_wallSprites.Add(sp); Sprite spFill = new Sprite(); spFill.MemberName = "BG1"; if (i == 0) spFill.Rect = new ERectangleF(sp.LocX, m_rctPlayArea.Top, this.m_nTileWidth, sp.Rect.Top); else spFill.Rect = new ERectangleF(sp.LocX, sp.Rect.Bottom, this.m_nTileWidth, m_rctPlayArea.Bottom-sp.Rect.Bottom); bh = new BhReportWhenOutside(); spFill.AddBehavior(bh); bh.Outside+=new CaveHunter.BhReportWhenOutside.OutsideDelegate(bh_Outside); m_wallSprites.Add(spFill); } }