Pacman Development-The behavior of the enemy

Source: Internet
Author: User

In the "Pacman" game, there are 3 different types of enemies planned.

· Loose type: Will not look back until it touches the wall

· Guard type: When the enemy and the protagonist "Big Mouth" in the same row or the same column will be alerted to close to the big mouth.

· Disturbing: Constantly approaching the big mouth.

These three enemies are implemented using the following functions:

Ai ai handles void redone::makedecision (bool b) {int i = rand (); if (b)//Hit the wall, change direction {//counterclockwise if (i% 4 = = 0) {tw = up? twcommand = LE Ft:twcommand = up;} else if (i% 3 = = 0) {tw = down? twcommand = Right:twcommand = down;} else if (i% 2 = = 0) {tw = right? twcommand = Up:twcommand = right;} ELSE{TW = left? twcommand = Down:twcommand = left;} return;}} void Blueone::makedecision (bool b) {const int DR = This->drow-player->getrow (); const int DA = THIS-&GT;DARRAY-PLA Yer->getarray (); if (!b&&dr = = 0) {if (DA <= blue_alert&&da > 0) {twcommand = Left;return;} if (Da < 0 && da >=-blue_alert) {twcommand = Right;return;}} if (!b&&da = = 0) {if (DR <= blue_alert&&dr > 0) {twcommand = Up;return;} if (Dr < 0 && Dr >=-blue_alert) {twcommand = Down;return;}} Redone::makedecision (b);} void Yellowone::makedecision (bool b) {const int DR = This->drow-player->getrow (); const int DA = This->darray-p Layer->getarray (); if (!b) {if (Dr*dr > Da*da) {if (DA > 0) {twcommand = Left;return;} else if (DA < 0) {Twcommand = Right;return;}} Else{if (dr>0) {twcommand = Up;return;} if (DR < 0) {Twcommand = Down;return;}}} Redone::makedecision (b);}

In the Enermy class, a function is used to implement the AI method:

void virtual Makedecision (bool b) = 0; AI implementations



@ Mayuko

Pacman Development-The behavior of the enemy

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.