private void gameForm_Load(object sender, EventArgs e) { screenBuffer = Image.FromHbitmap(new Bitmap(this.Width, this.Height).GetHbitmap()); cameraPos = new System.Drawing.PointF(0.0f, 0.0f); screenCenter = new System.Drawing.PointF(this.Width * 0.5f, this.Height * 0.5f); graphicsObject = this.CreateGraphics(); gameObjects = new Dictionary <long, gameObject>(); gamePhysics = new Physics(ref gameObjects); playerShip = createObject("player", @"Images\ship.png", new PointF(0.0f, 0.0f), new PointF(0.0f, 0.0f)); for (int i = 0; i < 100; i++) { int rndRoid = random.Next(1, 4); createObject("asteroid" + i, @"Images\asteroid" + rndRoid + ".png", new PointF(random.Next(-500, 500), random.Next(-500, 500)), new PointF(0.0f, 0.0f)); } this.DoubleBuffered = true; this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true); }
private gameObject createObject(string objName, string objImageFileName, PointF objPos, PointF objVel) { long objID = nextObjID; nextObjID++; gameObject newObject = new gameObject(objID, objName, objImageFileName, objPos, objVel); gameObjects.Add(objID, newObject); return(newObject); }
private ArrayList getObjectCells(gameObject curObj) { ArrayList retPoints = new ArrayList(); Point curPoint = new Point(); // Center curPoint.X = (int)Math.Floor(curObj.pos.X / cellSize.X); curPoint.Y = (int)Math.Floor(curObj.pos.Y / cellSize.Y); if (!retPoints.Contains(curPoint)) { retPoints.Add(curPoint); } // Upper Left curPoint.X = (int)Math.Floor(curObj.Min.X / cellSize.X); curPoint.Y = (int)Math.Floor(curObj.Min.Y / cellSize.Y); if (!retPoints.Contains(curPoint)) { retPoints.Add(curPoint); } // Upper Right curPoint.X = (int)Math.Floor(curObj.Max.X / cellSize.X); curPoint.Y = (int)Math.Floor(curObj.Min.Y / cellSize.Y); if (!retPoints.Contains(curPoint)) { retPoints.Add(curPoint); } // Lower Right curPoint.X = (int)Math.Floor(curObj.Max.X / cellSize.X); curPoint.Y = (int)Math.Floor(curObj.Max.Y / cellSize.Y); if (!retPoints.Contains(curPoint)) { retPoints.Add(curPoint); } // Lower Right curPoint.X = (int)Math.Floor(curObj.Min.X / cellSize.X); curPoint.Y = (int)Math.Floor(curObj.Max.Y / cellSize.Y); if (!retPoints.Contains(curPoint)) { retPoints.Add(curPoint); } return(retPoints); }
private void placeInCells(gameObject curObj) { ArrayList curCells = getObjectCells(curObj); ArrayList thisCell; foreach (Point curCell in curCells) { string cellIndex = (curCell.X + "." + curCell.Y); if (!gameCells.ContainsKey(cellIndex)) { gameCells.Add(cellIndex, new ArrayList()); } gameCells.TryGetValue(cellIndex, out thisCell); thisCell.Add(curObj.ID); } }
private void checkForCollision(gameObject toCheck) { ArrayList curCells = getObjectCells(toCheck); }