Jscex真的能制作愤怒的小鸟?在我没有接触Jscex之前,我也不相信!但是只要解决了重力场运动和碰撞的两大物理问题,Jscex版的愤怒小鸟,那就是囊中之物

javascript异步编程系列【五】----Jscex制作愤怒的小鸟

如果关注这个系列的话,在javascript异步编程系列【二】----Jscex模拟重力场与google苹果logo的比较中,模拟了苹果在重力场下的自由落体运动。

那么我们可以轻松的帮它扩展一个水平方向上的速度.

 <script type="text/javascript">
function Bird(startPos, speed_X, speed_Y, element) {
this.speed_X = speed_X;
this.speed_Y = speed_Y;
this.startPos = startPos;
this.fly = function () {
flyAsync(element, startPos, speed_X, speed_Y).start();
}
}
var flyAsync = eval(Jscex.compile("async", function (e, startPos, speed_X, speed_Y) {
e.style.left = startPos.x;
e.style.top = startPos.y;
//vt=v0+at
//重力加速度
var a_y = 40;
var speed_YTemp = speed_Y;
var time = 0;
while (Math.abs(speed_Y) <= speed_YTemp) {
$await(Jscex.Async.sleep(50));
time = time + 50;
speed_Y = speed_Y - a_y;
startPos.y -= (speed_Y * 0.05);
e.style.top = startPos.y;
startPos.x += speed_X * 0.05;
e.style.left = startPos.x;
}
}));
function Button1_onclick() {
var bird = new Bird({ x: 0, y: 300 }, 400, 700, document.getElementById("birdDiv"));
bird.fly();
}
</script>
<input id="Button1" type="button" value="发¢射?" onclick="return Button1_onclick()" />
<div id="birdDiv" style="left: 0px; top: 300px; position: absolute;">
<img id="bird" src="bird.jpg" alt="" />
</div>
看效果请按:

相关文章:

  • 2021-12-31
  • 2021-06-21
  • 2021-05-23
  • 2021-12-03
  • 2021-05-28
  • 2022-01-01
猜你喜欢
  • 2022-01-13
  • 2022-12-23
  • 2021-11-09
  • 2022-01-12
  • 2021-04-22
  • 2021-09-28
相关资源
相似解决方案