WEB开发网
开发学院图形图像Flash 用Flash制作一个类似弹弓的小游戏教程 阅读

用Flash制作一个类似弹弓的小游戏教程

 2007-09-20 11:09:31 来源:WEB开发网   
核心提示: 测试效果,在这里我们可以很轻松的计算出小球在线上的角度来,用Flash制作一个类似弹弓的小游戏教程(3),稍微做一下改动,attachMovie("sling", "sling_1", _root.getNextHighestDepth(), {_x

测试效果。

在这里我们可以很轻松的计算出小球在线上的角度来。

用Flash制作一个类似弹弓的小游戏教程

稍微做一下改动。

attachMovie("sling", "sling_1", _root.getNextHighestDepth(), {_x:20, _y:200});
attachMovie("sling", "sling_2", _root.getNextHighestDepth(), {_x:480, _y:200});
attachMovie("ball", "ball", _root.getNextHighestDepth(), {_x:250, _y:100});
_root.createEmptyMovieClip("elastic", _root.getNextHighestDepth());
xspeed = 0;
yspeed = 0;
fire = false;
ball.onPress = function() {
fire = false;
startDrag(this);
};
ball.onRelease = function() {
stopDrag();
fire = true;
};
ball.onEnterFrame = function() {
if (fire) {
 this._x += (xspeed*0.001);
 this._y += (yspeed*0.001);
}
};
elastic.onEnterFrame = function() {
this.clear();
this.lineStyle(2, 0x009900);
this.moveTo(sling_1._x, sling_1._y);
if (ball._y>182) {
 dist_x = ball._x-sling_1._x;
 dist_y = ball._y-sling_1._y;
 distance_from_sling = Math.sqrt(dist_x*dist_x+dist_y*dist_y);
 elastic_length = Math.sqrt(distance_from_sling*distance_from_sling-18*18);
 angle = Math.atan2(dist_y, dist_x)+Math.asin(18/distance_from_sling);
 saved_angle = angle;
 this.lineTo(sling_1._x+elastic_length*Math.cos(angle), sling_1._y+elastic_length*Math.sin(angle));
 this.lineTo(ball._x,ball._y);
} else {
 this.lineTo(sling_2._x, sling_2._y);
}
this.moveTo(sling_2._x, sling_2._y);
if (ball._y>182) {
 dist_x = ball._x-sling_2._x;
 dist_y = ball._y-sling_2._y;
 distance_from_sling = Math.sqrt(dist_x*dist_x+dist_y*dist_y);
 elastic_length = Math.sqrt(distance_from_sling*distance_from_sling-18*18);
 angle = Math.atan2(dist_y, dist_x)+Math.asin(18/distance_from_sling)*-1;
 this.lineTo(sling_2._x+elastic_length*Math.cos(angle), sling_2._y+elastic_length*Math.sin(angle));
 this.lineTo(ball._x,ball._y);
} else {
 this.lineTo(sling_2._x, sling_2._y);
}
};

上一页  1 2 3 4  下一页

Tags:Flash 制作 一个

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接