当前位置: 主页 > 网页制作 > Flash > 讲解Flash弹力球小游戏的制作

讲解Flash弹力球小游戏的制作

时间:2009-12-16来源:互联网 点击:

Flash教程:制作弹力球小游戏

来源:qinz(3950) 2007-9-23 【字体:大 中 小】 切换为 繁體中文
添加到QQ书签 雅虎收藏 添加到百度搜藏 有道书签 添加到Google书签 添加到新浪ViVi 添加到奇客发现 添加到和讯网摘 添加到博拉网 添加到挖客 LiveBookmarks YahooBuzz Twitter Mister-wong Del.icio.us Myspace Facebook Ask StumbleUpon Digg Reddit Spurl BlinkList

flash入门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());
ball.onPress = function() {
    startDrag(this);
};
ball.onRelease = function() {
    stopDrag();
};
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);
        this.lineTo(sling_1._x+elastic_length*Math.cos(angle), sling_1._y+elastic_length*Math.sin(angle));
    } 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));
    } else {
        this.lineTo(sling_2._x, sling_2._y);
    }
};

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

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

 

站长资讯网
.
分页: [1] [2] [3] [4]
TAG: Flash弹力球小游戏
推荐内容最近更新人气排行
关于我们 | 友情链接 | 网址推荐 | 常用资讯 | 网站地图 | RSS | 留言