Research on J2ME platform A-RPG game monster path finding algorithm

Source: Internet
Author: User

Recently, it seems that the A-RPG game is very popular on mobile phones, of course, I recently also help the company to write a A-RPG class game. I've never written a game like this before, and it's written out from there to nothing. Also encountered a lot of problems, including the screen scrolling map title array index Calibration, the entire game frame, map data processing, layered processing, the protagonist skills processing, touch detection.

These questions are free I'll do it as a small topic for one of the written out, this topic we come together to discuss the A-RPG game in the Monster search algorithm to determine.

Obviously, on devices such as mobile phones, A * algorithm is not suitable. Because A * in a large number of nodes will be the phone memory burst, this is my intuitive feeling, did not personally to practice, if someone can accurately implement a * algorithm on the phone, please let me know.

So, how do you deal with the monster seek algorithm in J2ME?

In this game I am using a a simplified version of the algorithm, temporarily called A * simple algorithm.

We can create a class of monsters that include different versions of monsters, corresponding images, corresponding search algorithms, corresponding attack skills, and collision detection. It would be hard to imagine how the game would be extended later if it were not built.

Then we can make the following judgments in this class:

if (!walking) {
if (Spritex < Therolex&&spritey > Theroley)
{
Direction = 3;
Walking = true;
Drawbydirection (g,spriteimage,spritex,spritey,direction*3);
}else if (Spritex < Therolex&&spritey < Theroley)
{
Direction = 2;
Walking = true;
Drawbydirection (g,spriteimage,spritex,spritey,direction*3);
}else if (Spritey < Theroley&&spritex > Therolex)
{
Direction = 0;
Walking = true;
Drawbydirection (g,spriteimage,spritex,spritey,direction*3);
}else if (Spritey > Theroley&&spritex > Therolex)
{
Direction = 1;
Walking = true;
Drawbydirection (g,spriteimage,spritex,spritey,direction*3);
}else if (Therolex-spritex > 8+spritewidth&&spritey = = Theroley)
{
Direction = 2;
Walking = true;
Drawbydirection (g,spriteimage,spritex,spritey,direction*3);
}else if (therolex-spritex <= 8+spritewidth&&spritey = = theroley&&therolex-spritex>0)
{
Spritex = theRoleX-8-spritewidth;
Attackflash (g,2);
}else if (Spritex-therolex > 8+spritewidth&&spritey = = Theroley)
{
Direction = 1;
Walking = true;
Drawbydirection (g,spriteimage,spritex,spritey,direction*3);
}else if (spritex-therolex <= 8+spritewidth&&spritey = = Theroley&&spritex>therolex)
{
Spritex = Therolex+8+spritewidth;
Attackflash (g,1);
}
else if (Spritey-theroley > Spriteheight&&spritex = = Therolex)
{
Direction = 3;
Walking = true;
Drawbydirection (g,spriteimage,spritex,spritey,direction*3);
}else if (Spritey-theroley <= Spriteheight&&spritex = = Therolex&&spritey-theroley > 0)
{
Spritey = Theroley+spriteheight;
Attackflash (g,3);
}else if (Theroley-spritey > Height&&spritex = = Therolex)
{
Direction = 0;
Walking = true;
Drawbydirection (g,spriteimage,spritex,spritey,direction*3);
}else if (theroley-spritey <= Height&&spritex = = Therolex)
{
Spritey = Theroley-height;
Attackflash (g,0);
}

In this algorithm, the Monster class will first determine the "weight", that is, the size of the distance between the horizontal and vertical to the target.

Then make the corresponding action according to the "Weight value".

For example, if the monster is in the lower left of the protagonist, it will approach the protagonist directly below, and then approach the protagonist from below.

Of course, the algorithm can be written more accurately, which is at the expense of performance.

How to balance accuracy and performance is what I'm looking for.

Fellow colleagues with similar experience are welcome to discuss this.

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.