A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [AS3] bullet spawning pattern help

Threaded View

  1. #5
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,377
    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*rad2deg+180;;
    }
    
    function fire() {
    	bc = Number(_root.bullets.text)-1;
    	sa = Number(_root.spreadAngle.text);
    	st = bc * sa;
    	sp = st/2;
    	s = 90 + sp;
    	e = 90 - sp;
    	for (var i = s; i>=e; i-=sa) {
    		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();
    Here's test 2. Play with the numbers again. I got it right this time. Angle Test 2

    You can see an example of a variable pointing angle by replacing the start/end variable lines with
    Code:
    	s = (rot*rad2deg+180) + sp;
    	e = (rot*rad2deg+180) - sp;
    Then hold Control while you move the mouse.
    Last edited by ImprisonedPride; 04-29-2009 at 07:29 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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center