Android development tutorial-how to determine the screen

Source: Internet
Author: User

In actual Android development projects, especially when writing games, we must determine the bullet issue. This is very important. If you do not judge, it will bring poor visual effects to players.

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 ){

// Enemy_bullets [I]. setVisible (false );}

If (enemy_bullets [I]. isVisible () = false ){

// When the bullet is invisible, set it to visible. The position is the corresponding enemy_bullets [I]. setVisible (true); x = enemys [I]. getX ();

Y = enemys [I]. getY ();

// This is the player's direction in the game (top, right, bottom, 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 + 16, y + 5); enemy_bullets [I]. setTransform (Sprite. TRANS_ROT270 );

Break;

Default: break;

}

}

Else {// when the bullet is visible

If (isBullerMeetTank (enemy_bullets [I]. getX (), enemy_bullets [I]. getY (), player. getX (), player. getY ()))

{

// If you encounter a player, the two will not see enemy_bullets [I] at the same time. setVisible (false); 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 whether the bullet can pass through enemy_bullets [I]. setVisible (false );

If (background. getCell (enemy_bullets [I]. getY ()/16, enemy_bullets [I]. getX ()/16 )! = 2 ){

Background. setCell (enemy_bullets [I]. getY ()/16, 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 to move forward or backward. 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 millisecond

}

} Catch (Exception e) {e. printStackTrace ();

} Finally {if (c! = Null) {holder. unlockCanvasAndPost (c );

}

}

}

}

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.