dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Need Help, Shooting 360 Degrees (Bugged)

  1. #1
    Robot Master the--flash's Avatar
    Join Date
    Jul 2005
    Location
    The year 20XX...
    Posts
    132

    Need Help, Shooting 360 Degrees (Bugged)

    Well, I have a code for it, but however I have a slight problem. I'm making a tank-turret style shooting game (oh how original!) where the mouse angle determines the turret's rotation. All fine and dandy until I have to make it shoot 360 degrees around.

    The actual shooting works fine, but for some insane reason it doesn't shoot "out" of the turret.

    Here is the culprit code...

    Code:
    onClipEvent (load) {
    	speed = 10;
    	bulletcount = 0;
    }
    onClipEvent (mouseDown) {
    	bulletcount ++;
    	duplicateMovieClip(this, "bullet"+bulletcount, bulletcount);
    	_x = _root.comp._x;
    	_y = _root.comp._y;
    	_rotation = _root.clip.deg
    }
    onClipEvent (enterFrame) {
    	x = Math.sin(_rotation*(Math.PI/180))*speed;
    	y = Math.cos(_rotation*(Math.PI/180))*speed*-1;
    	_x += x;
    	_y += y;
    }
    And I have the .fla file attached, too.

    Thanks for reading,

    the--flash.
    Attached Files Attached Files
    Last edited by the--flash; 04-28-2007 at 07:34 PM.

  2. #2
    Senior Member RangrJay's Avatar
    Join Date
    Sep 2005
    Location
    Las Vegas
    Posts
    163
    I started creating a tank shooter game, a loooooong time ago. I never finished it, but i did get the tank shooting in a 360 degree manner, and made a 3d clip of a car flipping (made it in Swift 3D) based on the angle hit. But never did anything more. I posted the code below, this should save you a lot of time and headache

    This was in the main frame where the game took place.
    Code:
    stop();
    Mouse.hide();
    startDrag(crosshair, true);
    shotx;
    shoty;
    numb = 0;
    canShoot = true;
    this.bullet._visible = false;
    function shotDamage(x, y)
    {
    }
    tx = tankGun._x;
    ty = tankGun._y;
    mouse = new Object();
    
    mouse.onMouseMove = function()
    {
    	xm = _xmouse;
    	ym = _ymouse;
    }
    mouse.onMouseDown = function()
    {
    	if (canShoot == true)
    	{
    		numb++;
    		duplicateMovieClip(bullet, "bullet" + numb, numb);
    		this["bullet" + numb]._visible = true;
    		shotDamage(shotx, shoty);
    	}
    };
    Mouse.addListener(mouse);
    This was on the bullet
    Code:
    onClipEvent (load) 
    {
    	this._x = this._parent.tankGun._x;
    	this._y = this._parent.tankGun._y;
    	distance = Math.sqrt(Math.pow(this._parent.crosshair._x - this._x, 2) + Math.pow(this._parent.crosshair._y - this._y, 2));
    	velX = ((this._parent.crosshair._x - this._x) / distance) * 25;
    	velY = ((this._parent.crosshair._y - this._y) / distance) * 25;
    	this._x = this._parent.tankGun._x;
    	this._y = this._parent.tankGun._y;
    	distance = Math.sqrt(Math.pow(this._parent.crosshair._x - this._x, 2) + Math.pow(this._parent.crosshair._y - this._y, 2));
    	intX = this._x;
    	intY = this._y;
    	this._visible = false;
    	velX = ((this._parent.crosshair._x - this._x) / distance);
    	velY = ((this._parent.crosshair._y - this._y) / distance);
    	bDistance = Math.sqrt(Math.pow(this._parent.tankGun._x - this._x, 2) + Math.pow(this._parent.tankGun._y - this._y, 2));
    	while (bDistance < 150)
    	{
    		this._x += velX;
    		this._y += velY;
    		bDistance = Math.sqrt(Math.pow(this._parent.tankGun._x - this._x, 2) + Math.pow(this._parent.tankGun._y - this._y, 2));
    	}
    	velX = ((this._parent.crosshair._x - intX) / distance) * 15;
    	velY = ((this._parent.crosshair._y - intY) / distance) * 15;
    	this._visible = true;
    }
    onClipEvent (enterFrame)
    {
    	_root.bullet._visible = false;
    	_root.bulletPath();
    	this._x += velX;
    	this._y += velY;
    	_root.bullPos = Math.sqrt(Math.pow(this._x - _parent.tx, 2) + Math.pow(this._y - _parent.ty, 2));
    	_root.mouseDist = Math.sqrt(Math.pow(_root.tx - _parent.shotx, 2) + Math.pow(_root.ty - _parent.shoty, 2));
    	if (_root.bullPos > _root.mouseDist)
    	{
    		this.removeMovieClip();
    		_root.bullPos = 0;
    	}
    	if (this._x > 750 || this._x < 0 || this._y > 750 || this._y < 0)
    	{
    		this.removeMovieClip();
    	}
    }
    This was on the tank
    Code:
    onClipEvent (enterFrame) 
    {
    	POSX = this._x - _root._xmouse;
    	POSY = this._y - _root._ymouse;
    	gunRotate = Math.atan2(POSY, POSX) * 180 / Math.PI - 90;
    	this._rotation = gunRotate;
    }
    And finally, on the crosshair
    Code:
    on (press)
    {
    	_root.shotx = this._x;
    	_root.shoty = this._y;
    }
    Xero Patience Studios
    Web Design
    Software Development
    Graphic/Logo Design

  3. #3
    Robot Master the--flash's Avatar
    Join Date
    Jul 2005
    Location
    The year 20XX...
    Posts
    132
    Ahh, thank you very much!

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