private void CreateNew(int a_nLocX) { Sprite sp = new Sprite(); sp.Name = "Obstacle"; sp.LocZ = 5; //TODO: new animation system MemberSpriteBitmap mb = (MemberSpriteBitmap)EndogineHub.Instance.CastLib.GetOrCreate("asteroid01"); //mb.NumFramesPerAxis = new EPoint(7,6); sp.Member = mb; if (a_nLocX <= 0) { a_nLocX = GameMain.Instance.CaveWalls.GetMaxX(); } float[] walls = GameMain.Instance.CaveWalls.GetWallsYOnX(a_nLocX); Random rnd = new Random(); sp.Loc = new EPointF(a_nLocX, (walls[1] - walls[0]) * (float)rnd.NextDouble() + walls[0]); //sp.AutoAnimator.StepSize = 0.1f; sp.Scaling = new EPointF(0.3f, 0.3f); BhReportWhenOutside bh = new BhReportWhenOutside(); sp.AddBehavior(bh); bh.Outside += new CaveHunter.BhReportWhenOutside.OutsideDelegate(bh_Outside); m_obstacles.Add(sp); }
private void CreateNew(int a_nLocX) { Sprite sp = new Sprite(); sp.Name = "Obstacle"; sp.LocZ = 5; //TODO: new animation system MemberSpriteBitmap mb = (MemberSpriteBitmap)EndogineHub.Instance.CastLib.GetOrCreate("asteroid01"); //mb.NumFramesPerAxis = new EPoint(7,6); sp.Member = mb; if (a_nLocX <= 0) a_nLocX = GameMain.Instance.CaveWalls.GetMaxX(); float[] walls = GameMain.Instance.CaveWalls.GetWallsYOnX(a_nLocX); Random rnd = new Random(); sp.Loc = new EPointF(a_nLocX, (walls[1]-walls[0])*(float)rnd.NextDouble()+walls[0]); //sp.AutoAnimator.StepSize = 0.1f; sp.Scaling = new EPointF(0.3f,0.3f); BhReportWhenOutside bh = new BhReportWhenOutside(); sp.AddBehavior(bh); bh.Outside+=new CaveHunter.BhReportWhenOutside.OutsideDelegate(bh_Outside); m_obstacles.Add(sp); }
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); } }
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); } }