Artillery play enemy games (with source code)

Source: Internet
Author: User
Tags cos sin
   Animation effect:

Click here to download the source file

Frame contents of ball in main scene:

Main scene as:

gun_mc._rotation=-40;
_root.ang=-40;
_root.total=0;
_root.attachmovie ("Fly", "Fly", 10,{_x:random (+) +220,_y:random (220) +10});
Up_btn.onpress=function () {
Turnangle (5);
if (gun_mc._rotation<-85) {
gun_mc._rotation=-85;
}
}
Down_btn.onpress=function () {
Turnangle (-5);
if (gun_mc._rotation>-5) {
gun_mc._rotation=-5;
}
}
function Turnangle (TMP) {
gun_mc._rotation+=-1*tmp;
_root.ang=gun_mc._rotation;
}
Fire_btn.onpress=function () {
if (_root.ball._currentframe==1) {
_root.ball.gotoandplay (2);
}
}
//------------------------------------

First frame in ball:
Stop ();
_visible = false;
Second frame:
var rad =-_root.ang/180*math.pi;
_x = _root.gun_mc._x+80*math.cos (RAD);
_y = _root.gun_mc._y-80*math.sin (RAD);
var Vx = math.sqrt (750) *math.cos (RAD);
var Vy = -1*math.sqrt (750) *math.sin (RAD);
_visible = true;
Third frame:
var Hitmon = this.hittest (_root.fly);
if (Hitmon) {
gotoAndPlay ("Hitbang");
}
_x + Vx;
_y + = Vy;
vy++;
if (_y>=350 | | _x>550) {
gotoAndPlay ("Bang");
}
Trace (1);
Frame four:
gotoAndPlay (_currentframe-1);
Frame 16th:
gotoAndStop (1);
Frame 17th
: _root.fly.removemovieclip ();
_root.total++;
Frame 26th
: _root.attachmovie ("Fly", "Fly", ten, {_x:random (+220), _y:random (220) +10});
gotoAndStop (1);
//------------------------------------------
You can also try.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.