J2ME Game Development Notes integrated version

Source: Internet
Author: User
Tags in degrees

-------------General class Problems--------------

1 j2me table method using trigonometric functions

CLDC and MIDP do not provide trigonometric functions, and there is no floating-point number in the CLDC1.0, so our choice is to check the table. Use the sin and Cos tables with 8-bit fixed-point numbers. The following is the code in the WTK demo, which provides only a limited number of angles, which are used to refine the angle value as needed.

//Sines of angles 0, a, m, 90,all *256

private static final int[] Sines =< br>
{0, N, 128, 165, 196, 222, 241, 252, 256};

//angle is in DEGREES/10, i.e. 0..36 for full circle

private static int sineTimes256 (int angle)
  br> {

angle%= 36; 360 degrees

if (angle <= 9)//0..90 degrees

{

return sines[angle];

}

Else if (angle <=)//90..180 degrees

{

return sines[18-angle];
br>}

Else if (angle <=)//180..270 degrees

{

return-sines[angle-18];

}

Else//270..360 degrees

{

Return-sines[36-angle];

}

}

//angle is in DEGREES/10, i.e. 0..36 to Full circle

private static int C osineTimes256 (int angle)

{

return sineTimes256(angle + 9); i.e. add degrees

}

(2006.5 Note: Some algorithms can generate trigonometric values so that you can save some data by generating a function table when the game is loaded)

2 J2ME Generates random numbers between 0~n with a random number of

:

(Ran.nextint () >>>1)%n

or

(Ran.nextint () &0x7f FFFFFF)%n

produces random numbers between-n~0:

(Ran.nextint () | 0x80000000)%n

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.