//managing already placed objects on the gamefield private void FormLevelEditor_MouseClick(object sender, MouseEventArgs e) { Point p = this.PointToClient(Cursor.Position); foreach (Obstacle obstacle in ObstacleList) { if (p.X >= obstacle.x && p.X <= (obstacle.x + obstacle.width) && p.Y >= obstacle.y && p.Y <= (obstacle.y + obstacle.length)) { currentMovingObject = obstacle; } } if (this.currentMovingObject != null) { this.movingPoint = new Point(p.X - this.currentMovingObject.x, p.Y - this.currentMovingObject.y); if (e.Button == MouseButtons.Left) { panelToolBox.Hide(); } } if (e.Button == MouseButtons.Right) { ObstacleList.Remove(currentMovingObject); } }
/// <summary> /// 控制场景和障碍物移动 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void timer_SceneMovement_Tick(object sender, EventArgs e) { //移动背景 p_bg1.Location = new Point(p_bg1.Location.X - px, 0); p_bg2.Location = new Point(p_bg2.Location.X - px, 0); if (p_bg1.Location.X + p_bg1.Width <= 0) { p_bg1.Location = new Point(785, 0); } else if (p_bg2.Location.X + p_bg2.Width <= 0) { p_bg2.Location = new Point(785, 0); } //移动pipe for (int i = 0; i < ObstacleList.Count; i++) { ObstacleList[i].Location = new Point(ObstacleList[i].Location.X - px, ObstacleList[i].Location.Y); if (ObstacleList[i].Location.X + ObstacleList[i].Width <= p_Brid.Location.X)//加分 { Score++; l_Score.Text = Score.ToString(); } if (ObstacleList[i].Location.X + ObstacleList[i].Width <= 0) { //ObstacleList[i].RandomLocation(this.Width); this.Controls.Remove(ObstacleList[i]); ObstacleList.Remove(ObstacleList[i]); } } }
public bool RemoveObstacle(int x, int y) { foreach (Position position in ObstacleList) { if (position.X == x && position.Y == y) { ObstacleList.Remove(position); return(true); } } return(false); }