home *** CD-ROM | disk | FTP | other *** search
- // --------- badguy.cpp
-
- #include <stdlib.h>
- #include "shootout.h"
- #include "options.h"
-
- BadGuy::BadGuy(char *gfxfile) : BitPart(gfxfile)
- {
- }
-
- void BadGuy::initialize_bitpart()
- {
- BitPart::initialize_bitpart();
- skill = -1;
- hesitation = 0;
- }
-
- short int BadGuy::drawbead()
- {
- Sheriff *shp = ((Shootout*)director)->sheriff;
- if (!shp->isdead() && abs(shp->zone()-zone()) < 2)
- // --- the sheriff is in range
- if (!((Shootout*)director)->isbadguy_shooting(this))
- // --- no one else is drawing on the sheriff
- return 1;
- return 0;
- }
-
- void BadGuy::update_position()
- {
- if (skill == -1) {
- skill = options->aim->getnum();
- hesitation = 5 - skill;
- }
- BitPart::update_position();
- switch (mode) {
- case standing:
- set_imageno(1);
- setinterval(bpwalkinterval);
- if (drawbead())
- // --- sheriff is in range
- mode = aiming;
- else
- break;
- case aiming:
- if (hesitation-- == 0) {
- mode = drawbead() ? shooting : exiting;
- hesitation = 5 - skill;
- }
- if (mode != shooting)
- break;
- case shooting:
- mode = exiting;
- if (firegun()) {
- Sheriff *shp = ((Shootout*)director)->sheriff;
- shp->getshot();
- }
- break;
- default:
- break;
- }
- }
-
- short int BadGuy::firegun()
- {
- setinterval(bpshootinterval);
- set_imageno(8);
- int rtn = skill ? (random((5-skill)+1) == 0) : 0;
- play_sound_clip(rtn ? 1 : 1); // : = ricochet later
- return rtn;
- }
-