我有一个游戏,其中一个诱饵被一个功率计的变量决定,当仪表满时,它返回一个变量1,当一半0.5和当低接近0时,我怎么能用它来确定多远我的“诱饵会被扔到屏幕上”? 我已经尝试过X值与我的钓竿放置不一致,当确定这一点时,我必须将我的诱饵移到那一点并停止。
_destinationY = Math.abs(_maxY - (_maxY * power));
_destinationX = Math.abs(_maxX - (_maxX * power));
package
{
import flash.display.MovieClip;
import flash.display.Stage;
import flash.events.Event;
import flash.geom.Point;
/**
* ...
* @author ...
*/
public class Bullet extends MovieClip
{
//variables
private var _stageRef:Stage;
private var _maxX:Number = 1024;
private var _maxY:Number = 768;
private var _destinationY:Number;
private var _destinationX:Number;
private var _speedVector:Point = new Point();
private var _moveFactor:Number = 0.9;
public var hit:MovieClip;
private var _fishes:Vector.<HFish> = new Vector.<HFish>;
private var _bulletLengthVector:Point = new Point();
private var awpSnd:awpSound
private var _power:Number = 1;
public function Bullet(stageRef:Stage,x:Number,y:Number,targetPoint:Point,power:Number)
{
this.x = x;
this.y = y;
_stageRef = stageRef;
_maxX = _stageRef.stageWidth;
_maxY = _stageRef.stageHeight;
//movement
_destinationY = Math.abs(_maxY - (_maxY * power));
_destinationX = Math.abs(_maxX - (_maxX * power));
trace ("landing at Y " + _destinationY);
trace ("landing at X " + _destinationX);
if (_destinationY > _maxY)
_destinationY = _maxY;
if (_destinationX > _maxX)
_destinationX = _maxX;
addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
//determine bullet moving speed
}
private function loop(e:Event) : void
{
//move bullet
this.x += _speedVector.x;
this.y += _speedVector.y;
//remove bullet bound check
if (this.x > _maxX || this.x < 0)
removeSelf();
else if (this.y > _maxY || this.y < 0)
removeSelf();
}
private function removeSelf() : void
{
removeEventListener(Event.ENTER_FRAME, loop);
if (stage.contains(this))
stage.removeChild(this);
}
}
}
游戏截图。
答案 0 :(得分:0)
不太清楚你为什么要使用这么复杂的论坛。如果您只是希望此人能够达到maxX和maxY数,则将maxX和maxY乘以总功率,因为功率范围是0-1。这样,如果您的功率水平为.7,那么投掷将是最大距离的70%。很容易,除非我错过了别的东西。
<强>更新强>
关于找到鱼竿与鱼饵落地之间的角度,只需使用我在谷歌上找到的辅助类来获得诱饵点和杆点之间的角度:
http://www.untoldentertainment.com/blog/2008/12/08/as3-helper-class-findangle/
所以基本上只需要投射一个新的Point对象,将X / Y设置为诱饵的X / Y,然后投射一个secont Point对象,将X / Y设置为你的杆的X / Y然后传递它们这个助手类。该课程将在RADIANS中找到角度。确保将它们转换为度数,因为Flash播放器使用度数进行显示对象旋转。您也可以在帮助程序类中或手动执行此操作:
var degrees:Number = radians * 180 / Math.PI;