Flash AS 制作生化危机游戏的简单尝试
</script></div><P>这个教程先给大家做一个游戏中的场景,只是简单的尝试着做做!</P><P><STRONG><FONT color=#ff0000>网页教学网友情提醒:由于该教程中演示Flash动画较多,所以打开本页后速度会慢些甚至影响浏览器!请关闭其它所有程序尝试!在教程的最后提供了所有演示的Fla源文件。</FONT></STRONG></P><P>首先布置地图,并且做一个角色。</P><P align=center><IMG alt="Flash AS 制作生化危机游戏的简单尝试" src="http://www.wzsky.net/ddimg/uploadimg/20071023/1043150.jpg"></P>引入一幅地图当作背景,转换为元件。 <P align=center><IMG alt="Flash AS 制作生化危机游戏的简单尝试" src="http://www.wzsky.net/ddimg/uploadimg/20071023/1043151.jpg"></P>角色的建立 <P align=center><IMG alt="Flash AS 制作生化危机游戏的简单尝试" src="http://www.wzsky.net/ddimg/uploadimg/20071023/1043152.jpg"></P><P>做好了上面的就可以了!下面我们开始添加代码。回到第一帧,添加如下代码。</P><P class=code>walk_speed = 3;<BR>radius = 8;<BR>_root.attachMovie("ground", "ground", _root.getNextHighestDepth());<BR>_root.attachMovie("environment", "environment", _root.getNextHighestDepth());<BR>_root.attachMovie("player", "player", _root.getNextHighestDepth(), {_x:250, _y:200});<BR>_root.createEmptyMovieClip("light", _root.getNextHighestDepth());<BR>player.onEnterFrame = function() {<BR> if (Key.isDown(Key.LEFT)) {<BR> this._x -= walk_speed;<BR> }<BR> if (Key.isDown(Key.RIGHT)) {<BR> this._x += walk_speed;<BR> }<BR> if (Key.isDown(Key.UP)) {<BR> this._y -= walk_speed;<BR> }<BR> if (Key.isDown(Key.DOWN)) {<BR> this._y += walk_speed;<BR> }<BR> while (_root.environment.hitTest(this._x, this._y+radius, true)) {<BR> this._y--;<BR> }<BR> while (_root.environment.hitTest(this._x, this._y-radius, true)) {<BR> this._y++;<BR> }<BR> while (_root.environment.hitTest(this._x-radius, this._y, true)) {<BR> this._x++;<BR> }<BR> while (_root.environment.hitTest(this._x+radius, this._y, true)) {<BR> this._x--;<BR> }<BR> dist_x = this._x-_root._xmouse;<BR> dist_y = this._y-_root._ymouse;<BR> angle = -Math.atan2(dist_x, dist_y);<BR> this._rotation = angle/(Math.PI/180);<BR>};</P><P>测试效果,这时有地图和角色了。</P><P><OBJECT codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0 height=400 width=500 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000><PARAM NAME="_cx" VALUE="13229"><PARAM NAME="_cy" VALUE="10583"><PARAM NAME="FlashVars" VALUE=""><PARAM NAME="Movie" VALUE="http://www.webjx.com/upfiles/20071016/20071016233301_survival1.swf"><PARAM NAME="Src" VALUE="http://www.webjx.com/upfiles/20071016/20071016233301_survival1.swf"><PARAM NAME="WMode" VALUE="Window"><PARAM NAME="Play" VALUE="0"><PARAM NAME="Loop" VALUE="-1"><PARAM NAME="Quality" VALUE="High"><PARAM NAME="SAlign" VALUE=""><PARAM NAME="Menu" VALUE="-1"><PARAM NAME="Base" VALUE=""><PARAM NAME="AllowScriptAccess" VALUE=""><PARAM NAME="Scale" VALUE="ShowAll"><PARAM NAME="DeviceFont" VALUE="0"><PARAM NAME="EmbedMovie" VALUE="0"><PARAM NAME="BGColor" VALUE=""><PARAM NAME="SWRemote" VALUE=""><PARAM NAME="MovieData" VALUE=""><PARAM NAME="SeamlessTabbing" VALUE="1"><PARAM NAME="Profile" VALUE="0"><PARAM NAME="ProfileAddress" VALUE=""><PARAM NAME="ProfilePort" VALUE="0"><PARAM NAME="AllowNetworking" VALUE="all"><PARAM NAME="AllowFullScreen" VALUE="false"><embed src=http://www.webjx.com/upfiles/20071016/20071016233301_survival1.swf pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width=500 height=400></embed></OBJECT></P><P>我们再继续修改代码。</P><P class=code>torch_power = 100;<BR>torch_step = 100;<BR>torch_angle = 60;<BR>torch_angle_step = 20;<BR>walk_speed = 3;<BR>radius = 8;<BR>_root.attachMovie("ground", "ground", _root.getNextHighestDepth());<BR>_root.attachMovie("environment", "environment", _root.getNextHighestDepth());<BR>_root.attachMovie("player", "player", _root.getNextHighestDepth(), {_x:250, _y:200});<BR>_root.createEmptyMovieClip("light", _root.getNextHighestDepth());<BR>player.onEnterFrame = function() {<BR> if (Key.isDown(Key.LEFT)) {<BR> this._x -= walk_speed;<BR> }<BR> if (Key.isDown(Key.RIGHT)) {<BR> this._x += walk_speed;<BR> }<BR> if (Key.isDown(Key.UP)) {<BR> this._y -= walk_speed;<BR> }<BR> if (Key.isDown(Key.DOWN)) {<BR> this._y += walk_speed;<BR> }<BR> while (_root.environment.hitTest(this._x, this._y+radius, true)) {<BR> this._y--;<BR> }<BR> while (_root.environment.hitTest(this._x, this._y-radius, true)) {<BR> this._y++;<BR> }<BR> while (_root.environment.hitTest(this._x-radius, this._y, true)) {<BR> this._x++;<BR> }<BR> while (_root.environment.hitTest(this._x+radius, this._y, true)) {<BR> this._x--;<BR> }<BR> dist_x = this._x-_root._xmouse;<BR> dist_y = this._y-_root._ymouse;<BR> angle = -Math.atan2(dist_x, dist_y);<BR> this._rotation = angle/(Math.PI/180);<BR> light.clear();<BR> light.lineStyle(1, 0xffffff);<BR> for (x=0; x<=torch_angle; x += (torch_angle/torch_angle_step)) {<BR> light.moveTo(this._x, this._y);<BR> ray_angle = angle/(Math.PI/180)-90-(torch_angle/2)+x;<BR> ray_angle = ray_angle*(Math.PI/180);<BR> light.lineTo(this._x+(torch_power)*Math.cos(ray_angle), this._y+(torch_power)*Math.sin(ray_angle));<BR> light.lineTo(this._x, this._y);<BR> }<BR>};</P><P>效果如下。</P><P align=center><OBJECT codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0 height=400 width=500 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000><PARAM NAME="_cx" VALUE="13229"><PARAM NAME="_cy" VALUE="10583"><PARAM NAME="FlashVars" VALUE=""><PARAM NAME="Movie" VALUE="http://www.webjx.com/upfiles/20071016/20071016233312_survival2.swf"><PARAM NAME="Src" VALUE="http://www.webjx.com/upfiles/20071016/20071016233312_survival2.swf"><PARAM NAME="WMode" VALUE="Window"><PARAM NAME="Play" VALUE="0"><PARAM NAME="Loop" VALUE="-1"><PARAM NAME="Quality" VALUE="High"><PARAM NAME="SAlign" VALUE=""><PARAM NAME="Menu" VALUE="-1"><PARAM NAME="Base" VALUE=""><PARAM NAME="AllowScriptAccess" VALUE=""><PARAM NAME="Scale" VALUE="ShowAll"><PARAM NAME="DeviceFont" VALUE="0"><PARAM NAME="EmbedMovie" VALUE="0"><PARAM NAME="BGColor" VALUE=""><PARAM NAME="SWRemote" VALUE=""><PARAM NAME="MovieData" VALUE=""><PARAM NAME="SeamlessTabbing" VALUE="1"><PARAM NAME="Profile" VALUE="0"><PARAM NAME="ProfileAddress" VALUE=""><PARAM NAME="ProfilePort" VALUE="0"><PARAM NAME="AllowNetworking" VALUE="all"><PARAM NAME="AllowFullScreen" VALUE="false"><embed src=http://www.webjx.com/upfiles/20071016/20071016233312_survival2.swf pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width=500 height=400></embed></OBJECT></P><P>我们再继续修改代码。</P><P class=code>torch_power = 100;<BR>torch_step = 100;<BR>torch_angle = 60;<BR>torch_angle_step = 20;<BR>walk_speed = 3;<BR>radius = 8;<BR>_root.attachMovie("ground", "ground", _root.getNextHighestDepth());<BR>_root.attachMovie("environment", "environment", _root.getNextHighestDepth());<BR>_root.attachMovie("player", "player", _root.getNextHighestDepth(), {_x:250, _y:200});<BR>_root.createEmptyMovieClip("light", _root.getNextHighestDepth());<BR>player.onEnterFrame = function() {<BR> if (Key.isDown(Key.LEFT)) {<BR> this._x -= walk_speed;<BR> }<BR> if (Key.isDown(Key.RIGHT)) {<BR> this._x += walk_speed;<BR> }<BR> if (Key.isDown(Key.UP)) {<BR> this._y -= walk_speed;<BR> }<BR> if (Key.isDown(Key.DOWN)) {<BR> this._y += walk_speed;<BR> }<BR> while (_root.environment.hitTest(this._x, this._y+radius, true)) {<BR> this._y--;<BR> }<BR> while (_root.environment.hitTest(this._x, this._y-radius, true)) {<BR> this._y++;<BR> }<BR> while (_root.environment.hitTest(this._x-radius, this._y, true)) {<BR> this._x++;<BR> }<BR> while (_root.environment.hitTest(this._x+radius, this._y, true)) {<BR> this._x--;<BR> }<BR> dist_x = this._x-_root._xmouse;<BR> dist_y = this._y-_root._ymouse;<BR> angle = -Math.atan2(dist_x, dist_y);<BR> this._rotation = angle/(Math.PI/180);<BR> light.clear();<BR> light.lineStyle(1, 0xffffff);<BR> for (x=0; x<=torch_angle; x += (torch_angle/torch_angle_step)) {<BR> light.moveTo(this._x, this._y);<BR> ray_angle = angle/(Math.PI/180)-90-(torch_angle/2)+x;<BR> ray_angle = ray_angle*(Math.PI/180);<BR> for (y=1; y<=torch_step; y++) {<BR> if (environment.hitTest(this._x+(torch_power/torch_step*y)*Math.cos(ray_angle), this._y+(torch_power/torch_step*y)*Math.sin(ray_angle), true)) {<BR> break;<BR> }<BR> }<BR> light.lineTo(this._x+(torch_power/torch_step*y)*Math.cos(ray_angle), this._y+(torch_power/torch_step*y)*Math.sin(ray_angle));<BR> }<BR>};</P><P>效果如下。</P><P align=center><OBJECT codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0 height=400 width=500 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000><PARAM NAME="_cx" VALUE="13229"><PARAM NAME="_cy" VALUE="10583"><PARAM NAME="FlashVars" VALUE=""><PARAM NAME="Movie" VALUE="http://www.webjx.com/upfiles/20071016/20071016233323_survival3.swf"><PARAM NAME="Src" VALUE="http://www.webjx.com/upfiles/20071016/20071016233323_survival3.swf"><PARAM NAME="WMode" VALUE="Window"><PARAM NAME="Play" VALUE="0"><PARAM NAME="Loop" VALUE="-1"><PARAM NAME="Quality" VALUE="High"><PARAM NAME="SAlign" VALUE=""><PARAM NAME="Menu" VALUE="-1"><PARAM NAME="Base" VALUE=""><PARAM NAME="AllowScriptAccess" VALUE=""><PARAM NAME="Scale" VALUE="ShowAll"><PARAM NAME="DeviceFont" VALUE="0"><PARAM NAME="EmbedMovie" VALUE="0"><PARAM NAME="BGColor" VALUE=""><PARAM NAME="SWRemote" VALUE=""><PARAM NAME="MovieData" VALUE=""><PARAM NAME="SeamlessTabbing" VALUE="1"><PARAM NAME="Profile" VALUE="0"><PARAM NAME="ProfileAddress" VALUE=""><PARAM NAME="ProfilePort" VALUE="0"><PARAM NAME="AllowNetworking" VALUE="all"><PARAM NAME="AllowFullScreen" VALUE="false"><embed src=http://www.webjx.com/upfiles/20071016/20071016233323_survival3.swf pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width=500 height=400></embed></OBJECT></P><P>我们再继续修改代码。</P><P class=code>torch_power = 100;<BR>torch_step = 100;<BR>torch_angle = 60;<BR>torch_angle_step = 20;<BR>walk_speed = 3;<BR>radius = 8;<BR>_root.attachMovie("ground", "ground", _root.getNextHighestDepth());<BR>_root.attachMovie("environment", "environment", _root.getNextHighestDepth());<BR>_root.attachMovie("player", "player", _root.getNextHighestDepth(), {_x:250, _y:200});<BR>_root.createEmptyMovieClip("light", _root.getNextHighestDepth());<BR>player.onEnterFrame = function() {<BR> if (Key.isDown(Key.LEFT)) {<BR> this._x -= walk_speed;<BR> }<BR> if (Key.isDown(Key.RIGHT)) {<BR> this._x += walk_speed;<BR> }<BR> if (Key.isDown(Key.UP)) {<BR> this._y -= walk_speed;<BR> }<BR> if (Key.isDown(Key.DOWN)) {<BR> this._y += walk_speed;<BR> }<BR> while (_root.environment.hitTest(this._x, this._y+radius, true)) {<BR> this._y--;<BR> }<BR> while (_root.environment.hitTest(this._x, this._y-radius, true)) {<BR> this._y++;<BR> }<BR> while (_root.environment.hitTest(this._x-radius, this._y, true)) {<BR> this._x++;<BR> }<BR> while (_root.environment.hitTest(this._x+radius, this._y, true)) {<BR> this._x--;<BR> }<BR> dist_x = this._x-_root._xmouse;<BR> dist_y = this._y-_root._ymouse;<BR> angle = -Math.atan2(dist_x, dist_y);<BR> this._rotation = angle/(Math.PI/180);<BR> light.clear();<BR> light.lineStyle(1, 0xffffff);<BR> light.moveTo(this._x, this._y);<BR> for (x=0; x<=torch_angle; x += (torch_angle/torch_angle_step)) {<BR> ray_angle = angle/(Math.PI/180)-90-(torch_angle/2)+x;<BR> ray_angle = ray_angle*(Math.PI/180);<BR> for (y=1; y<=torch_step; y++) {<BR> if (environment.hitTest(this._x+(torch_power/torch_step*y)*Math.cos(ray_angle), this._y+(torch_power/torch_step*y)*Math.sin(ray_angle), true)) {<BR> break;<BR> }<BR> }<BR> light.lineTo(this._x+(torch_power/torch_step*y)*Math.cos(ray_angle), this._y+(torch_power/torch_step*y)*Math.sin(ray_angle));<BR> }<BR> light.lineTo(this._x, this._y);<BR>};</P><P>效果如下。</P><P align=center><OBJECT codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0 height=400 width=500 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000><PARAM NAME="_cx" VALUE="13229"><PARAM NAME="_cy" VALUE="10583"><PARAM NAME="FlashVars" VALUE=""><PARAM NAME="Movie" VALUE="http://www.webjx.com/upfiles/20071016/20071016233333_survival4.swf"><PARAM NAME="Src" VALUE="http://www.webjx.com/upfiles/20071016/20071016233333_survival4.swf"><PARAM NAME="WMode" VALUE="Window"><PARAM NAME="Play" VALUE="0"><PARAM NAME="Loop" VALUE="-1"><PARAM NAME="Quality" VALUE="High"><PARAM NAME="SAlign" VALUE=""><PARAM NAME="Menu" VALUE="-1"><PARAM NAME="Base" VALUE=""><PARAM NAME="AllowScriptAccess" VALUE=""><PARAM NAME="Scale" VALUE="ShowAll"><PARAM NAME="DeviceFont" VALUE="0"><PARAM NAME="EmbedMovie" VALUE="0"><PARAM NAME="BGColor" VALUE=""><PARAM NAME="SWRemote" VALUE=""><PARAM NAME="MovieData" VALUE=""><PARAM NAME="SeamlessTabbing" VALUE="1"><PARAM NAME="Profile" VALUE="0"><PARAM NAME="ProfileAddress" VALUE=""><PARAM NAME="ProfilePort" VALUE="0"><PARAM NAME="AllowNetworking" VALUE="all"><PARAM NAME="AllowFullScreen" VALUE="false"><embed src=http://www.webjx.com/upfiles/20071016/20071016233333_survival4.swf pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width=500 height=400></embed></OBJECT></P><P>我们再继续修改代码。</P><P class=code>torch_power = 100;<BR>torch_step = 100;<BR>torch_angle = 60;<BR>torch_angle_step = 20;<BR>walk_speed = 3;<BR>radius = 8;<BR>_root.attachMovie("ground", "ground", _root.getNextHighestDepth());<BR>_root.attachMovie("environment", "environment", _root.getNextHighestDepth());<BR>_root.attachMovie("player", "player", _root.getNextHighestDepth(), {_x:250, _y:200});<BR>_root.createEmptyMovieClip("light", _root.getNextHighestDepth());<BR>player.onEnterFrame = function() {<BR> if (Key.isDown(Key.LEFT)) {<BR> this._x -= walk_speed;<BR> }<BR> if (Key.isDown(Key.RIGHT)) {<BR> this._x += walk_speed;<BR> }<BR> if (Key.isDown(Key.UP)) {<BR> this._y -= walk_speed;<BR> }<BR> if (Key.isDown(Key.DOWN)) {<BR> this._y += walk_speed;<BR> }<BR> while (_root.environment.hitTest(this._x, this._y+radius, true)) {<BR> this._y--;<BR> }<BR> while (_root.environment.hitTest(this._x, this._y-radius, true)) {<BR> this._y++;<BR> }<BR> while (_root.environment.hitTest(this._x-radius, this._y, true)) {<BR> this._x++;<BR> }<BR> while (_root.environment.hitTest(this._x+radius, this._y, true)) {<BR> this._x--;<BR> }<BR> dist_x = this._x-_root._xmouse;<BR> dist_y = this._y-_root._ymouse;<BR> angle = -Math.atan2(dist_x, dist_y);<BR> this._rotation = angle/(Math.PI/180);<BR> light.clear();<BR> light.beginFill(0xffffff, 100);<BR> light.lineStyle(1, 0xffffff);<BR> light.moveTo(this._x, this._y);<BR> for (x=0; x<=torch_angle; x += (torch_angle/torch_angle_step)) {<BR> ray_angle = angle/(Math.PI/180)-90-(torch_angle/2)+x;<BR> ray_angle = ray_angle*(Math.PI/180);<BR> for (y=1; y<=torch_step; y++) {<BR> if (environment.hitTest(this._x+(torch_power/torch_step*y)*Math.cos(ray_angle), this._y+(torch_power/torch_step*y)*Math.sin(ray_angle), true)) {<BR> break;<BR> }<BR> }<BR> light.lineTo(this._x+(torch_power/torch_step*y)*Math.cos(ray_angle), this._y+(torch_power/torch_step*y)*Math.sin(ray_angle));<BR> }<BR> light.lineTo(this._x, this._y);<BR> light.endFill();<BR> ground.setMask(light);<BR>};</P><P>效果如下。</P><P align=center><OBJECT codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0 height=400 width=500 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000><PARAM NAME="_cx" VALUE="13229"><PARAM NAME="_cy" VALUE="10583"><PARAM NAME="FlashVars" VALUE=""><PARAM NAME="Movie" VALUE="http://www.webjx.com/upfiles/20071016/20071016233343_survival5.swf"><PARAM NAME="Src" VALUE="http://www.webjx.com/upfiles/20071016/20071016233343_survival5.swf"><PARAM NAME="WMode" VALUE="Window"><PARAM NAME="Play" VALUE="0"><PARAM NAME="Loop" VALUE="-1"><PARAM NAME="Quality" VALUE="High"><PARAM NAME="SAlign" VALUE=""><PARAM NAME="Menu" VALUE="-1"><PARAM NAME="Base" VALUE=""><PARAM NAME="AllowScriptAccess" VALUE=""><PARAM NAME="Scale" VALUE="ShowAll"><PARAM NAME="DeviceFont" VALUE="0"><PARAM NAME="EmbedMovie" VALUE="0"><PARAM NAME="BGColor" VALUE=""><PARAM NAME="SWRemote" VALUE=""><PARAM NAME="MovieData" VALUE=""><PARAM NAME="SeamlessTabbing" VALUE="1"><PARAM NAME="Profile" VALUE="0"><PARAM NAME="ProfileAddress" VALUE=""><PARAM NAME="ProfilePort" VALUE="0"><PARAM NAME="AllowNetworking" VALUE="all"><PARAM NAME="AllowFullScreen" VALUE="false"><embed src=http://www.webjx.com/upfiles/20071016/20071016233343_survival5.swf pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width=500 height=400></embed></OBJECT></P><P>好了!今天先讲到这里。最后给大家提供上面所有演示的源文件。<A href="http://www.webjx.com/download.php?url=http://www.webjx.com/upfiles/20071016/20071016234159_survival.rar" target=_blank><FONT color=#ff0000><B>点击这里下载Fla源文件</B></FONT></A>(431K自行查杀病毒)</P>页:
[1]