拼图游戏雏形--分割美女图
</script></div><SPAN class=bold>无聊的时候就来把美女分割![由讨厌原创==>无聊+乱整]</SPAN><BR><BR><DIV style="FONT-SIZE: 12px">能把一张图片分割成若干份,份数由输入数字自由决定。分割后自动随机打乱位置,可以拖到,拖到到正确位置自动吸附,并不允许再抛动。基本能算一个拼图游戏的雏形了吧。但整到这里就不想整了。能用右键加载自己的图片。以下是无聊的代码:<BR><DIV class=code>import flash.net.FileReference; <BR>import flash.display.BitmapData; <BR>import flash.geom.Matrix; <BR>///////////////////////////////// <BR>var img_bmp:BitmapData = new BitmapData(mc._width, mc._height); <BR>var txt_fmt:TextFormat = new TextFormat(); <BR>txt_fmt.color = 0xff00ff; <BR>txt_fmt.size = 22; <BR>txt_fmt.font = "华文新魏"; <BR>///////////////////// <BR>for (var d:Number = 2; d>0; d--) { <BR>this.createTextField("wh_txt"+d, 9000+d, d*100, 20, 50, 26); <BR>this["wh_txt"+d].setNewTextFormat(txt_fmt); <BR>this["wh_txt"+d].border = true; <BR>this["wh_txt"+d].input = true; <BR>this["wh_txt"+d].type = "input"; <BR>this["wh_txt"+d].maxChars = 1; <BR>this["wh_txt"+d].restrict("0-9"); <BR>this["wh_txt"+d].background = true; <BR>this["wh_txt"+d].borderColor = 0xff9900; <BR>this["wh_txt"+d].backgroundColor = 0x33cccc; <BR>} <BR>Selection.setFocus("wh_txt1"); <BR>////////////////// <BR>wh_txt1.onChanged = wh_txt2.onChanged=function () { <BR>if (wh_txt1.text == "") { <BR> Selection.setFocus("wh_txt1"); <BR>} else if (wh_txt2.text == "") { <BR> Selection.setFocus("wh_txt2"); <BR>} else { <BR> fenge_func(wh_txt1.text, wh_txt2.text); <BR>} <BR>}; <BR>//////////////////////// <BR>var xwpos:Number = 0; <BR>var yhpos:Number = 0; <BR>function fuwei_func() { <BR>for (var d:Number = xwpos-1; d>=0; d--) { <BR> for (var c:Number = yhpos-1; c>=0; c--) { <BR> this["pic_mc"+d+c].removeMovieClip(); <BR> } <BR>} <BR>} <BR>////// <BR>function fenge_func(xw:Number, yh:Number) { <BR>fuwei_func(); <BR>xwpos = xw; <BR>yhpos = yh; <BR>img_bmp.draw(mc, new Matrix()); <BR>var xy_array:Array = new Array(); <BR>var b_num:Number = new Number(); <BR>//////////////// <BR>for (var d:Number = xw-1; d>=0; d--) { <BR> for (var c:Number = yh-1; c>=0; c--) { <BR> this.createEmptyMovieClip("pic_mc"+d+c, 200+d+""+c); <BR> this["pic_mc"+d+c].lineStyle(1, 0xfff000, 100); <BR> this["pic_mc"+d+c].beginBitmapFill(img_bmp, new Matrix(), false); <BR> this["pic_mc"+d+c].moveTo(d*Stage.width/xw, c*Stage.height/yh); <BR> this["pic_mc"+d+c].lineTo((d+1)*Stage.width/xw, c*Stage.height/yh); <BR> this["pic_mc"+d+c].lineTo((d+1)*Stage.width/xw, (c+1)*Stage.height/yh); <BR> this["pic_mc"+d+c].lineTo(d*Stage.width/xw, (c+1)*Stage.height/yh); <BR> this["pic_mc"+d+c].lineTo(d*Stage.width/xw, c*Stage.height/yh); <BR> this["pic_mc"+d+c].endFill(); <BR> this["pic_mc"+d+c].obj = new Object(); <BR> this["pic_mc"+d+c].obj = this["pic_mc"+d+c].getBounds(_root); <BR> this["pic_mc"+d+c].xpos = this["pic_mc"+d+c].obj.xMin; <BR> this["pic_mc"+d+c].ypos = this["pic_mc"+d+c].obj.yMin; <BR> //////////////// <BR> var xy2_array:Array = new Array(); <BR> xy2_array.push(this["pic_mc"+d+c].obj.xMin, this["pic_mc"+d+c].obj.yMin); <BR> xy_array.push(xy2_array); <BR> this["pic_mc"+d+c].id = d+""+c; <BR> ////////////////// <BR> this["pic_mc"+d+c].onPress = function() { <BR> b_num = this.id; <BR> this.swapDepths(this._parent.getNextHighestDepth()); <BR> this.startDrag(); <BR> }; <BR> } <BR>} <BR>//////////////// <BR>for (var d:Number = xw-1; d>=0; d--) { <BR> for (var c:Number = yh-1; c>=0; c--) { <BR> num = Math.floor(Math.random()*xy_array.length); <BR> this["pic_mc"+d+c]._x = xy_array[num][0]-this["pic_mc"+d+c].xpos; <BR> this["pic_mc"+d+c]._y = xy_array[num][1]-this["pic_mc"+d+c].ypos; <BR> xy_array.splice(num, 1); <BR> } <BR>} <BR>////////////////// <BR>onMouseUp = function () { <BR> stopDrag(); <BR> if (this["pic_mc"+b_num].hitTest(this["pic_mc"+b_num].xpos+this["pic_mc"+b_num]._width/2, this["pic_mc"+b_num].ypos+this["pic_mc"+b_num]._height/2)) { <BR> this["pic_mc"+b_num]._x = 0; <BR> this["pic_mc"+b_num]._y = 0; <BR> this["pic_mc"+b_num].swapDepths(-this["pic_mc"+b_num].getDepth()); <BR> this["pic_mc"+b_num].enabled = false; <BR> } <BR>}; <BR>//////////// <BR>mc._visible = false; <BR>} <BR>///////////////////////////// <BR>var listener:Object = new Object(); <BR>//////// <BR>var loadpic:MovieClipLoader = new MovieClipLoader(); <BR>listener.onLoadInit = function(target:MovieClip) { <BR>target._width = Stage.width; <BR>target._height = Stage.height; <BR>fuwei_func(); <BR>wh_txt1.text = ""; <BR>wh_txt2.text = ""; <BR>Selection.setFocus("wh_txt1"); <BR>}; <BR>loadpic.addListener(listener); <BR>///////////////// <BR>var fileRef:FileReference = new FileReference(); <BR>var allTypes:Array = []; <BR>var 浏览类型:Object = new Object(); <BR>浏览类型.description = "浏览类型(*.jpg)"; <BR>浏览类型.extension = "*.jpg"; <BR>allTypes.push(浏览类型); <BR>listener.onSelect = function(file:FileReference) { <BR>loadpic.loadClip("/"+file.name, mc); <BR>}; <BR>fileRef.addListener(listener); <BR>///////////////////////// <BR>var pic_menu:ContextMenu = new ContextMenu(); <BR>function browse_func() { <BR>fileRef.browse(allTypes); <BR>} <BR>pic_menu.hideBuiltInItems(); <BR>var loadpic_menu:ContextMenuItem = new ContextMenuItem("加载新图片", browse_func); <BR>pic_menu.customItems.push(loadpic_menu); <BR>_root.menu = pic_menu;</DIV><STRONG>swf. fla 下载:<IMG src="http://www2.flash8.net/x/webx/Images/file/rar.gif" border=0> </STRONG><A href="http://www2.flash8.net/UploadTeach/200705/20070520152207564.rar" target=_blank><STRONG><U><FONT color=#000000>分割图片.rar</FONT></U></STRONG></A></DIV>页:
[1]