高级:利用Flash制作精彩的迷宫游戏
</script></div><P> <STRONG>网页教学网:</STRONG>在以前的教程中我们讲解了利用Flash制作游戏的一些方法,比如碰撞的检测等,在这个教程中我们利用以前学的知识创建一个不错的迷宫游戏!该教程主要是Flash利用材质和遮照创建真实的小球动画的延续,利用创建好的小球滚动动画制作迷宫游戏。</P><P> 在这篇教程中没有新的知识,就是利用一个舞台(地图),然后还有一个运动的小球实现的一个小的Flash游戏。</P><P> 一共制作了两个迷宫动画效果。</P><P> <STRONG>一、背景不动的迷宫游戏</STRONG></P><P> 准备好一幅背景之后,直接输入下面代码。</P><DIV class=code><P>level = new Array();<BR>_root.attachMovie("starz", "starz", 1);<BR>_root.createEmptyMovieClip("bricks", 2);<BR>level[0] = new Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0);<BR>level[1] = new Array(0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1);<BR>level[2] = new Array(1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1);<BR>level[3] = new Array(1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1);<BR>level[4] = new Array(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);<BR>level[5] = new Array(1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1);<BR>level[6] = new Array(1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1);<BR>level[7] = new Array(1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1);<BR>level[8] = new Array(1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1);<BR>level[9] = new Array(1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1);<BR>level[10] = new Array(0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1);<BR>for (y=0; y<=10; y++) {<BR> for (x=0; x<=11; x++) {<BR> if (level[y][x] == 1) {<BR> place_brick = bricks.attachMovie("brick", "brick_"+bricks.getNextHighestDepth(), bricks.getNextHighestDepth(), {_x:x*40+30, _y:y*40+30});<BR> }<BR> }<BR>}<BR>_root.attachMovie("ball", "ball", _root.getNextHighestDepth(), {_x:30, _y:30});<BR>ball.texture.setMask(ball.ball_itself);<BR>power = 0.4;<BR>yspeed = 0;<BR>xspeed = 0;<BR>friction = 0.99;<BR>ball.onEnterFrame = function() {<BR> if (Key.isDown(Key.LEFT)) {<BR> xspeed -= power;<BR> }<BR> if (Key.isDown(Key.RIGHT)) {<BR> xspeed += power;<BR> }<BR> if (Key.isDown(Key.UP)) {<BR> yspeed -= power;<BR> }<BR> if (Key.isDown(Key.DOWN)) {<BR> yspeed += power;<BR> }<BR> xspeed *= friction;<BR> yspeed *= friction;<BR> this._y += yspeed;<BR> this._x += xspeed;<BR> this.texture._y += yspeed;<BR> this.texture._x += xspeed;<BR> if (this.texture._x>53) {<BR> this.texture._x -= 63;<BR> }<BR> if (this.texture._x<-53) {<BR> this.texture._x += 63;<BR> }<BR> if (this.texture._y>53) {<BR> this.texture._y -= 63;<BR> }<BR> if (this.texture._y<-53) {<BR> this.texture._y += 63;<BR> }<BR> brick_x = Math.floor((this._x-10)/40);<BR> brick_y = Math.floor((this._y-10)/40);<BR> if (level[brick_y][brick_x]!=1) {<BR> this._x = 30;<BR> this._y = 30;<BR> xspeed = 0;<BR> yspeed = 0;<BR> }<BR>};</P></DIV>页:
[1]