private void pbMap_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (curObj != null) { int tilewidth = 16; int tileheight = 16; int x = (mousePicMapX / tilewidth) * tilewidth; int y; if (curObj.bm.Height % tileheight == 0) { y = (mousePicMapY / tileheight) * tileheight; } else { y = (mousePicMapY / tileheight) * tileheight + (tileheight - curObj.bm.Height % tileheight); } Point p = new Point(x, y); DrawImage(pbMap.BackgroundImage, curObj.bm, p, new Rectangle(0, 0, curObj.bm.Width, curObj.bm.Height)); ObjectGame obj = new ObjectGame(curObj.bm, curObj.ID, "Enemy"); obj.SetLocation(p.X, p.Y); listobjmap.Add(obj); curObj = obj; if (flagNewMap == true) { DrawImage(newMap, curObj.bm, p, new Rectangle(0, 0, curObj.bm.Width, curObj.bm.Height)); btnSaveMap.Enabled = true; } } } }
private void btnAddObj_Click(object sender, EventArgs e) //them obj vao list obj map { addObject(); for (int i = 0; i < countRow; i++) { for (int j = 0; j < countCol; j++) { if (matTile[i, j].Equals(curTile.Tag)) { ObjectGame obj = new ObjectGame(curTile, curObj.ID, curObj.objectType.ToString()); obj.SetLocation(j * 16, i * 16); listobjmap.Add(obj); pbMap.Invalidate(); } } } }