formula to determine designation point given a variable
i have a game inwhich a bait is thrown determined by a variable of a power meter, when the meter is full it returns a variable of 1 when half 0.5 and when low near 0, how can i use this to determine how far my "bait will be thrown" onto the screen? i have tried how ever the X value would not be consistent with my fishing rod placement, and when the point is decided i will have to move my bait to that point and stop.
_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:P开发者_C百科oint = 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);
}
}
}
a screenshot of the game.
Not quite sure why you're using such a complex forumla for this. If you simply want the person to be able to reach a maxX and maxY number, then multiply maxX and maxY by the total power, since the power range is from 0-1. This way if your power level is .7, then the throw will be 70 percent of the max distance. Easy, unless I'm missing something else.
Update
Regarding finding the angle between your fishing rod and where the bait landed, just use this helper class I found on google to get the angle between the bait point and your rod point:
http://www.untoldentertainment.com/blog/2008/12/08/as3-helper-class-findangle/
So basically just cast a new Point object, set the X/Y to the X/Y of your bait, then cast a secont Point object, set the X/Y to the X/Y of your rod and then pass them to this helper class. The class will find the angle in RADIANS. Ensure that you convert them to degrees since the flash player uses degrees for display object rotation. You can do this also inside the helper class or by hand:
var degrees:Number = radians * 180 / Math.PI;
精彩评论