private void saveFileDialog1_FileOk(object sender, CancelEventArgs e) { QuadTree tree = new QuadTree(pictureBoxBG.Width, pictureBoxBG.Height); tree.createSubNode(); tree.getListLeaf(); tree.addObject(listObject); ObjectTile cam = new ObjectTile(0, "Camera", Convert.ToInt32(textBoxCamX.Text.Trim()), Convert.ToInt32(textBoxCamY.Text.Trim()), 256, 240, 0); listObject.Add(cam); ObjectTile character = new ObjectTile(0, "Character", Convert.ToInt32(textBoxChaX.Text.Trim()), Convert.ToInt32(textBoxChaY.Text.Trim()), 36, 46, 0); listObject.Add(character); FileTool.writeFileConfi(saveFileDialog1, listObject, listObNoneTree); FileTool.writeFileOB(saveFileDialog1, listObject, pictureBoxBG.Width, pictureBoxBG.Height); FileTool.writeFileOBNoneQuadTree(saveFileDialog1, listObNoneTree, pictureBoxBG.Width, pictureBoxBG.Height); FileTool.writeFileTree(saveFileDialog1, tree); MessageBox.Show("Lưu file thành công"); }
// check ob nam trong node public bool AABBCheck(ObjectTile ob, QuadTreeNode node) { return(!(ob.PosX + ob.Width < node.PosX || ob.PosX > node.PosX + node.Width || ob.PosY - ob.Height > node.PosY || ob.PosY < node.PosY - node.Height)); }
private void pictureBoxBG_Click(object sender, EventArgs e) { if (CurrentCursor == CursorCur.OBJECT || CurrentCursor == CursorCur.ITEM) { if (textBoxX.Text.Trim() != "?" && textBoxY.Text.Trim() != "?") { // them hinh anh vao pictureBox MouseEventArgs me = (MouseEventArgs)e; Point coordinates = me.Location; PictureBox p = new PictureBox(); p.Image = imageCursor; p.Location = new Point(me.Location.X - imageCursor.Width / 2, me.Location.Y - imageCursor.Height / 2); p.SizeMode = PictureBoxSizeMode.AutoSize; p.BackColor = Color.Transparent; int direction = comboBoxDir.SelectedIndex; if (CurrentCursor == CursorCur.ITEM) { // them vao list ObjectTile ob = new ObjectTile(p, (listObNoneTree.Count + 1), textBoxNameOB.Text, Convert.ToInt32(textBoxX.Text.Trim()), Convert.ToInt32(textBoxY.Text.Trim()), direction); listObNoneTree.Add(ob); listObNoneTree.ElementAt(listObNoneTree.Count - 1).Pic.Click += new System.EventHandler(PictureBoxes_Click); listObNoneTree.ElementAt(listObNoneTree.Count - 1).Pic.MouseMove += new System.Windows.Forms.MouseEventHandler(PictureBoxes_MouseMove); listObNoneTree.ElementAt(listObNoneTree.Count - 1).Pic.MouseLeave += new System.EventHandler(PictureBoxes_MouseLeave); pictureBoxBG.Controls.Add(listObNoneTree.ElementAt(listObNoneTree.Count - 1).Pic); } else { // them vao list string nameOb = textBoxNameOB.Text.Trim(); if (isItemStand) { nameOb = "ItemStand" + comboBoxNameItem.Text.Trim(); } ObjectTile ob = new ObjectTile(p, (listObject.Count + 1), nameOb, Convert.ToInt32(textBoxX.Text.Trim()), Convert.ToInt32(textBoxY.Text.Trim()), direction); if (nameOb == "RockRoll") { ob.Height = 240; } else if (nameOb == "Tank") { ob.Width = 256; ob.PosX -= 256; } listObject.Add(ob); listObject.ElementAt(listObject.Count - 1).Pic.Click += new System.EventHandler(PictureBoxes_Click); listObject.ElementAt(listObject.Count - 1).Pic.MouseMove += new System.Windows.Forms.MouseEventHandler(PictureBoxes_MouseMove); listObject.ElementAt(listObject.Count - 1).Pic.MouseLeave += new System.EventHandler(PictureBoxes_MouseLeave); pictureBoxBG.Controls.Add(listObject.ElementAt(listObject.Count - 1).Pic); if (nameOb == "Boss1") { ObjectTile ob_sniper = new ObjectTile((listObject.Count + 1), "SniperBoss", Convert.ToInt32(textBoxX.Text.Trim()), Convert.ToInt32(textBoxY.Text.Trim()), 32, 32, direction); listObject.Add(ob_sniper); ObjectTile ob_gun1 = new ObjectTile((listObject.Count + 1), "Boss1Gun", Convert.ToInt32(textBoxX.Text.Trim()) - 8, Convert.ToInt32(textBoxY.Text.Trim()) - 85, 32, 32, direction); listObject.Add(ob_gun1); ObjectTile ob_gun2 = new ObjectTile((listObject.Count + 1), "Boss1Gun", Convert.ToInt32(textBoxX.Text.Trim()) + 12, Convert.ToInt32(textBoxY.Text.Trim()) - 85, 32, 32, direction); listObject.Add(ob_gun2); } else if (nameOb == "Boss2") { ObjectTile ob_arm1 = new ObjectTile((listObject.Count + 1), "SniperBoss", Convert.ToInt32(textBoxX.Text.Trim()) + 58, Convert.ToInt32(textBoxY.Text.Trim()) - 72, 32, 32, direction); listObject.Add(ob_arm1); ObjectTile ob_arm2 = new ObjectTile((listObject.Count + 1), "Boss1Gun", Convert.ToInt32(textBoxX.Text.Trim()) + 164, Convert.ToInt32(textBoxY.Text.Trim()) - 72, 32, 32, direction); listObject.Add(ob_arm2); } } } else { MessageBox.Show("Lỗi!!!! Xem lại tọa độ X và Y chưa hợp lệ "); } } }