What is the mobile path of an android airplane game enemy plane?

Source: Internet
Author: User

Similar to previous players, basic android aircraft Games use surfaceView to draw game images and control the draw interval to achieve dynamic effects. The self-written automatic flight path code of the enemy plane is attached here. Please give us some comments.

Add this segment to the enemy plane management module. MovePingXing records the deviation values of x and y drawn each time when the aircraft runs in a straight line. MoveYuanHu records the deviation values of x and y drawn by the canvas each time when the plane runs on a circular track. In String, "," must be followed by the x-direction coordinate offset, followed by the y-direction coordinate offset.

 

[Java]
Private static String [] movePingXing = {5 + "," + 0, 5 + "," + 0, 5 + "," + 0,
5 + "," + 0, 5 + "," + 0, 5 + "," + 0, 5 + "," + 0,
5 + "," + 0, 5 + "," + 0, 5 + "," + 0, 5 + "," + 0,
5 + "," + 0, 5 + "," + 0, 5 + "," + 0, 5 + "," + 0,
5 + "," + 0, 5 + "," + 0, 5 + "," + 0, 5 + "," + 0, 5 + ", "+ 0 };
Private static String [] moveYuanHu = {5 + "," + 1, 5 + "," + 1,
4 + "," + 2, 4 + "," + 2,
3 + "," + 3 + "," + 3,
2 + "," + 4, 2 + "," + 4,
1 + "," + 5, 1 + "," + 5,
-1 + "," + 5,-1 + "," + 5,
-2 + "," + 4,-2 + "," + 4,
-3 + "," + 3,-3 + "," + 3,
-4 + "," + 2,-4 + "," + 2,
-5 + "," + 1,-5 + "," + 1,
-5 + "," +-1,-5 + "," +-1,
-4 + "," +-2,-4 + "," +-2,
-3 + "," +-3,-3 + "," +-3,
-2 + "," +-4,-2 + "," +-4,
-1 + "," +-5,-1 + "," +-5,
1 + "," +-5, 1 + "," +-5,
2 + "," +-4, 2 + "," +-4,
3 + "," +-3 + "," +-3,
4 + "," +-2, 4 + "," +-2,
5 + "," +-1, 5 + "," +-1 };

Private static String [] movePingXing = {5 + "," + 0, 5 + "," + 0, 5 + "," + 0,
5 + "," + 0, 5 + "," + 0, 5 + "," + 0, 5 + "," + 0,
5 + "," + 0, 5 + "," + 0, 5 + "," + 0, 5 + "," + 0,
5 + "," + 0, 5 + "," + 0, 5 + "," + 0, 5 + "," + 0,
5 + "," + 0, 5 + "," + 0, 5 + "," + 0, 5 + "," + 0, 5 + ", "+ 0 };
Private static String [] moveYuanHu = {5 + "," + 1, 5 + "," + 1,
4 + "," + 2, 4 + "," + 2,
3 + "," + 3 + "," + 3,
2 + "," + 4, 2 + "," + 4,
1 + "," + 5, 1 + "," + 5,
-1 + "," + 5,-1 + "," + 5,
-2 + "," + 4,-2 + "," + 4,
-3 + "," + 3,-3 + "," + 3,
-4 + "," + 2,-4 + "," + 2,
-5 + "," + 1,-5 + "," + 1,
-5 + "," +-1,-5 + "," +-1,
-4 + "," +-2,-4 + "," +-2,
-3 + "," +-3,-3 + "," +-3,
-2 + "," +-4,-2 + "," +-4,
-1 + "," +-5,-1 + "," +-5,
1 + "," +-5, 1 + "," +-5,
2 + "," +-4, 2 + "," +-4,
3 + "," +-3 + "," +-3,
4 + "," +-2, 4 + "," +-2,
5 + "," +-1, 5 + "," +-1 };
 

Then, the path adding method is provided to add these coordinate offsets to movelist1. The content in moveList1 must be sufficient. Each time the canvas is drawn, the plane can get a valid String path. Otherwise, a null pointer exception occurs.

 

[Java]
Public static boolean initMoveList1 (){
AddPingXing ();
AddYuanHu ();
AddPingXing ();
AddPingXing ();
AddPingXing ();
Return true;
}
Public static void addPingXing (){
Map <String, String> map;
For (int I = 0; I <movePingXing. length; I ++ ){
Map = new HashMap <String, String> ();
Map. put ("way", movePingXing [I]);
MoveList1.add (map );
}
}

Public static void addYuanHu (){
Map <String, String> map;
For (int I = 0; I <moveYuanHu. length; I ++ ){
Map = new HashMap <String, String> ();
Map. put ("way", moveYuanHu [I]);
MoveList1.add (map );
}
}

Public static boolean initMoveList1 (){
AddPingXing ();
AddYuanHu ();
AddPingXing ();
AddPingXing ();
AddPingXing ();
Return true;
}
Public static void addPingXing (){
Map <String, String> map;
For (int I = 0; I <movePingXing. length; I ++ ){
Map = new HashMap <String, String> ();
Map. put ("way", movePingXing [I]);
MoveList1.add (map );
}
}
 
Public static void addYuanHu (){
Map <String, String> map;
For (int I = 0; I <moveYuanHu. length; I ++ ){
Map = new HashMap <String, String> ();
Map. put ("way", moveYuanHu [I]);
MoveList1.add (map );
}
}
 

After the initMoveList1 () method is called, the enemy management class can obtain an ArrayList that records the offset of the flight track of the enemy.

When the enemy machine moves, insert the following code to let the enemy machine move according to its own path every time the canvas is drawn. Here I design a simple straight line-circular line-linear aircraft path.

 

[Java]
Map <String, String> map = moveList1.get (enemy. getCurrentSecond ());
String moveWay = map. get ("way ");
String [] zuobiao = moveWay. split (",");
Enemy. x + = Integer. parseInt (zuobiao [0]);
Enemy. y + = Integer. parseInt (zuobiao [1]);

Map <String, String> map = moveList1.get (enemy. getCurrentSecond ());
String moveWay = map. get ("way ");
String [] zuobiao = moveWay. split (",");
Enemy. x + = Integer. parseInt (zuobiao [0]);
Enemy. y + = Integer. parseInt (zuobiao [1]);
The above currentSecond is an int variable, which is an attribute of the enemy's machine and records the time when the enemy's machine appeared on the screen.

Hope you can give us some comments and see what can be improved.

 

Related Article

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.