|
-
Pumpkin Carving 2008
Figure out beforehand how many degrees you want between each bullet. When you fire, take your bullet count and multiply it by this number. That is your spread angle. If you had a space of 15 and 4 bullets, it would be a 60 degree spread. So, take your total spread and center it over the angle your pointing. In this case I'll use 270 degrees since it matches your images. Take that same total spread angle, cut it in half, and subtract it from 270. You get 240. Take the half again and this time add it to the 270. Take these two values as your start and end angle. Starting from the start value in a for loop, iterate to the end value, incrementing by your predetermined space between bullets. Here's an AS2 example: Angle Test 1
And here's the single-frame code, which should be self-explanatory as to what you need to use.
Code:
onEnterFrame = run;
deg2rad = Math.PI/180;
rad2deg = 180/Math.PI;
delay = 7;
timer = 0;
function run() {
timer++;
if (timer%delay == 0 && Key.isDown(Key.CONTROL)) {
fire();
}
dx = _xmouse - _root.spawn._x;
dy = _ymouse - _root.spawn._y;
xd = spawn._x-_root._xmouse;
yd = spawn._y-_root._ymouse;
rot = Math.atan2(yd, xd);
angle.text = rot*(180/Math.PI)+180;;
}
function fire() {
bc = Number(_root.bullets.text)-1;
sa = Number(_root.spreadAngle.text);
trace("SA: " + sa + " || BC: " + bc);
if (!isNaN(bc) && !isNaN(sa)) {
var sh = sa/2;
var sp = sa/bc;
var s = 90 + sh;
var e = 90 - sh;
for (var i = s; i>=e; i-=sp) {
var ang = i;
ang *= deg2rad;
var b = attachMovie("bullet", "b"+getNextHighestDepth(), getNextHighestDepth());
b.xc = 10*Math.cos(ang);
b.yc = 10*Math.sin(ang);
b._x = spawn._x;
b._y = spawn._y;
b.onEnterFrame = function() {
this._x += this.xc;
this._y += this.yc;
if (this._x < 0 || this._x > Stage.width || this._y < 0 || this._y > Stage.height) {
this.removeMovieClip();
}
}
}
}
}
stop();
You ought to note that the method I provided just divides the bullets into the total spread to get the bullet spacing.
Last edited by ImprisonedPride; 04-29-2009 at 06:51 PM.
The 'Boose':
ASUS Sabertooth P67 TUF
Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
8GB G.Skill Ripjaws 1600 DDR3
ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
New addition: OCZ Vertex 240GB SATA III SSD
WEI Score: 7.6
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|