The method of judging the screen in the Android development tutorial

Source: Internet
Author: User
Tags gety

In the development of the actual Android project, especially in the writing game, we must judge the problem of a bullet, it is very important. If not judged, it will give the player visually bad effect.

Java code:

for (int i = 0; i < enemy_bullets.length; i++)

{

Enemy_bullets[i].paint (c);

if (Enemy_bullets[i].getx () < 0| | Enemy_bullets[i].getx ()-5 > Max_width

|| Enemy_bullets[i].gety () < 0| | Enemy_bullets[i].gety ()-5 > Max_height) {

A bullet crosses the border to process enemy_bullets[i].setvisible (false); }

if (enemy_bullets[i].isvisible () = = False) {

When the bullet is not visible, it is set to be visible, and the position is corresponding to the enemy launch Enemy_bullets[i].setvisible (true); x = Enemys[i].getx ();

y = enemys[i].gety ();

This is the player in the game in the direction (up, right, down, left) switch (Enemys[i].gettransform ()) {

Case Sprite.trans_none:enemy_bullets[i].setposition (x + 5, y + 16); Enemy_bullets[i].settransform (Sprite.trans_none);

Break

Case Sprite.trans_rot90:enemy_bullets[i].setposition (x-6, y + 5); Enemy_bullets[i].settransform (SPRITE.TRANS_ROT90);

Break

Case Sprite.trans_rot180:enemy_bullets[i].setposition (x + 5, y-6); Enemy_bullets[i].settransform (sprite.trans_rot180);

Break

Case Sprite.trans_rot270:enemy_bullets[i].setposition (x +, y + 5); Enemy_bullets[i].settransform (sprite.trans_rot270);

Break

Default:break;

}

}

else {//when bullets are visible

if (Isbullermeettank (Enemy_bullets[i].getx (), Enemy_bullets[i].gety (), Player.getx (), Player.gety ()))

{

If the player is met, both enemy_bullets[i].setvisible (false) are not seen; Player.setvisible (FALSE); Explodes[4].setvisible (TRUE);//Explosion explodes[4].setposition (Player.getx (), player.gety ()); }

if (enemy_bullets[i].isvisible () &&! Canbulletpass (Enemy_bullets[i].getx (), Enemy_bullets[i].gety ()))

{

Determine if the bullet can pass through enemy_bullets[i].setvisible (false);

if (Background.getcell (Enemy_bullets[i].gety ()/Enemy_bullets[i].getx ()/16)!= 2) {

Background.setcell (Enemy_bullets[i].gety ()/Enemy_bullets[i].getx ()/16, 0); Map[enemy_bullets[i].gety ()/16][enemy_bullets[i].getx ()/16] = 0; }

}

Switch (Enemy_bullets[i].gettransform ()) {

Extend the original direction move forward or back case sprite.trans_none:enemy_bullets[i].move (0, 16); Break

Case Sprite.trans_rot90:enemy_bullets[i].move (-16, 0); Break

Case Sprite.trans_rot180:enemy_bullets[i].move (0,-16); Break

Case Sprite.trans_rot270:enemy_bullets[i].move (16, 0); Break

Default:break; }

}

}

Player.paint (c);

Thread.Sleep (200);//Time is milliseconds

}

catch (Exception e) {e.printstacktrace ();

finally {if (c!= null) {holder.unlockcanvasandpost (c);

}

}

}

}

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.