Create a turret point and shoot in the direction of the mouse-lecture

  • draw the turret base

turret-base.jpg

  • convert it to a symbol of type move clip.
  • draw a gun

gun.jpg

  • convert the gun to a movie clip and name it “gun”. Put the instance name “gun” in the properties box as well.
  • go to edit the clip “gun” and make sure the end of your turret that attaches to your turret base is the focus.
  • Draw the bullet to be fired
  • Convert the bullet into a movie symbol and name it “shot”. Then select it and in the box under the dropdown box put “shot” there too for the instance name.
  • Select the “gun” clip and put the code:

 

onClipEvent(load)

{

_root.shot._visible=false;

shotcount=1;

}

onClipEvent (enterFrame)

{

myRadians = Math.atan2(_root._ymouse-this._y, _root._xmouse-this._x);

myDegrees = Math.round((myRadians*180/Math.PI));

_root.yChange = Math.round(_root._ymouse-this._y);

_root.xChange = Math.round(_root._xmouse-this._x);

this._rotation = myDegrees+90;

}

onClipEvent(mouseDown)

{

_root.shot.duplicateMovieClip( “shot”+shotcount, shotcount+7000);

_root[“shot”+shotcount]._visible=true;

shotcount++;

if(shotcount>100)

{

shotcount=1;

}

}


<!–[endif]–>

<!–[endif]–>

  • open the “shot” movie clip and put the code

onClipEvent(load)

{

if(this._name==”shot”)

{

this._visible=false;

}

else

{

this._visible=true;

}

this._x=_root.gun._x;

this._y=_root.gun._y;

shotxspeed=40*Math.sin(_root.gun._rotation*(Math.PI/180));

shotyspeed=40*Math.cos(_root.gun._rotation*(Math.PI/180));

}

onClipEvent(enterFrame)

{

this._x+=shotxspeed;

this._y-=shotyspeed;

if(this._x<0)

{

this.removeMovieClip();

}

if(this._x>550)

{

this.removeMovieClip();

}

if(this._y>400)

{

this.removeMovieClip();

}

if(this._y<0)

{

this.removeMovieClip();

}

}

 

10. The finished product

turret.jpg

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: