home *** CD-ROM | disk | FTP | other *** search
- #include <fastgraf.h>
- #include <stdlib.h> // abs
- #include <string.h>
- #include "game.h"
- #include "fighter.h"
-
- const int MAXFRAMES=6;
- const int CLOSE_LIMIT=25;
- const int DAMAGE_LIMIT=100;
-
- //----------------------------------------------------- data definitions -----
-
- struct nextstateinfo
- {
- int mode;
- int frame;
- };
-
- struct area
- {
- int x,y;
- int r;
- };
-
- struct frameinfo
- {
- int xoffset;
- int yoffset;
- int is_defensive;
-
- int hasattack;
- area attack;
-
- int hastarget;
- area hightarget;
- area lowtarget;
- };
-
- //---------------------------------------------- static data tables -----
-
- static nextstateinfo next[NUMMODES][MAXFRAMES+1]=
- {
- { {0,0},{WAIT,2},{WAIT,3},{WAIT,4},{WAIT,5},{WAIT,6},{WAIT,1} },
- { {0,0}, {PUNCH,2}, {WAIT,1}, {0,0}, }, // PUNCH (goes to WAIT)
- { {0,0}, {KICK,2}, {WAIT,1}, {0,0} }, // KICK (also goes to WAIT)
- { {0,0}, {BLOCK,2}, {BLOCK,3}, {WAIT,1} }, // BLOCK (goes to WAIT)
- { {0,0}, {VICTORY,1}, {0,0}, {0,1} }, // VICTORY (dead end)
- { {0,0}, {DEFEAT,1}, {0,0}, {0,1} }, // DEFEAT (dead end)
- { {0,0}, {HIGH,2}, {WAIT,1}, {0,1} }, // HIGH
- { {0,0}, {LOW,2}, {WAIT,1}, {0,1} }, // LOW
- { {0,0}, {OUT,2}, {OUT,3}, {OUT,4}, {OUT,5}, {OUT,5} }, // OUT
- { {0,0}, {WIN,2}, {WIN,1}, {0,1} } // WIN
- };
-
- static int image_no[NUMMODES][MAXFRAMES+1]=
- {
- { 0,1,1,2,2,3,3 }, // wait
- { 0, 5, 4, 0 }, // punch
- { 0, 6, 7, 0 }, // kick
- { 0, 8, 8, 8 }, // block
- { 0, 12, 0, 0 }, // victory
- { 0, 0, 0, 0,}, // defeat
- { 0, 9, 9, 0,}, // high
- { 0, 10, 10, 0,}, // low
- { 0, 12, 13, 14, 15, 16, 17}, // down
- { 0, 11, 11, 0,} // win
- };
-
- //-------------------------------------- left player data
- static frameinfo frame_wait_1=
- {
- 0,0,FALSE,
- FALSE, { 0,0,0 },
- TRUE, { 29,13,5 }, {21,37,3}
- };
-
- static frameinfo frame_wait_2=
- {
- 0,0,FALSE,
- FALSE, { 0,0,0 },
- TRUE, {30,14,5}, {21,37,3}
- };
-
- static frameinfo frame_wait_3=
- {
- 0,0,FALSE,
- FALSE, { 0,0,0 },
- TRUE, { 30,13,5 }, {21,37,3}
- };
-
- static frameinfo frame_punch_1=
- {
- 0,0,FALSE,
- FALSE, { 33,25,2 },
- TRUE, { 31,12,5}, {21,36,3}
- };
-
- static frameinfo frame_punch_2=
- {
- 0,0,FALSE,
- TRUE, {47,20,2},
- TRUE, {31,12,5 }, {21,36,3}
- };
-
- static frameinfo frame_kick_1=
- {
- 0,0,FALSE,
- TRUE, {49,37,2},
- TRUE, {29,12,5}, {20,36,3}
- };
-
- static frameinfo frame_kick_2=
- {
- 0,0,FALSE,
- FALSE, {36,56,2},
- TRUE, {29,12,5}, {21,36,3}
- };
-
- static frameinfo frame_block_1=
- {
- 0,0,TRUE,
- FALSE, {0,0,0},
- TRUE, { 29,13,5 }, {21,37,3}
- };
-
- static frameinfo frame_high_1=
- {
- 0,0,FALSE,
- FALSE, {0,0,0},
- FALSE, {0,0,0}, {0,0,0}
- };
-
- static frameinfo frame_low_1=
- {
- 0,0,FALSE,
- FALSE, {0,0,0},
- FALSE, {0,0,0}, {0,0,0}
- };
-
- static frameinfo frame_win_1=
- {
- 0,0,FALSE,
- FALSE, {0,0,0},
- FALSE, {0,0,0}, {0,0,0}
- };
-
- static frameinfo frame_down_1=
- {
- 0,0,FALSE,
- FALSE, {0,0,0},
- FALSE, {0,0,0}, {0,0,0}
- };
-
- static frameinfo frame_down_2=
- {
- 0,0,FALSE,
- FALSE, {0,0,0},
- FALSE, {0,0,0}, {0,0,0}
- };
-
- static frameinfo frame_down_3=
- {
- 0,0,FALSE,
- FALSE, {0,0,0},
- FALSE, {0,0,0}, {0,0,0}
- };
-
- static frameinfo frame_down_4=
- {
- 0,0,FALSE,
- FALSE, {0,0,0},
- FALSE, {0,0,0}, {0,0,0}
- };
-
- static frameinfo frame_down_5=
- {
- 0,0,FALSE,
- FALSE, {0,0,0},
- FALSE, {0,0,0}, {0,0,0}
- };
-
- //-------------------------------------- right player data
- static frameinfo rframe_wait_1=
- {
- 0,0,FALSE,
- FALSE, { 0,0,0 },
- TRUE, { 21,14,5 }, {29,36,3}
- };
-
- static frameinfo rframe_wait_2=
- {
- 0,0,FALSE,
- FALSE, { 0,0,0 },
- TRUE, { 20,15,5 }, {29,36,3}
- };
-
- static frameinfo rframe_wait_3=
- {
- 0,0,FALSE,
- FALSE, { 0,0,0 },
- TRUE, { 20,14,5 }, {29,36,3}
- };
-
- static frameinfo rframe_punch_1=
- {
- 0,0,FALSE,
- FALSE, { 17,30,2 },
- TRUE, { 19,14,5 }, {29,35,3}
- };
-
- static frameinfo rframe_punch_2=
- {
- 0,0,FALSE,
- TRUE, { 6,20,2 },
- TRUE, { 19,14,5 }, {29,34,3}
- };
-
- static frameinfo rframe_kick_1=
- {
- 0,0,FALSE,
- TRUE, { 0,40,2 },
- TRUE, { 21,14,5 }, {29,35,3}
- };
-
- static frameinfo rframe_kick_2=
- {
- 0,0,FALSE,
- FALSE, { 16,51,2 },
- TRUE, { 21,14,5 }, {29,35,3}
- };
-
- static frameinfo rframe_block_1=
- {
- 0,0,TRUE,
- FALSE, {0,0,0},
- TRUE, { 21,14,5 }, {29,36,3}
- };
-
- static frameinfo rframe_high_1=
- {
- 0,0,FALSE,
- FALSE, {0,0,0},
- FALSE, {0,0,0}, {0,0,0}
- };
-
- static frameinfo rframe_low_1=
- {
- 0,0,FALSE,
- FALSE, {0,0,0},
- FALSE, {0,0,0}, {0,0,0}
- };
-
- static frameinfo rframe_win_1=
- {
- 0,0,FALSE,
- FALSE, {0,0,0},
- FALSE, {0,0,0}, {0,0,0}
- };
-
- static frameinfo rframe_down_1=
- {
- 0,0,FALSE,
- FALSE, {0,0,0},
- FALSE, {0,0,0}, {0,0,0}
- };
-
- static frameinfo rframe_down_2=
- {
- 0,0,FALSE,
- FALSE, {0,0,0},
- FALSE, {0,0,0}, {0,0,0}
- };
-
- static frameinfo rframe_down_3=
- {
- 0,0,FALSE,
- FALSE, {0,0,0},
- FALSE, {0,0,0}, {0,0,0}
- };
-
- static frameinfo rframe_down_4=
- {
- 0,0,FALSE,
- FALSE, {0,0,0},
- FALSE, {0,0,0}, {0,0,0}
- };
-
- static frameinfo rframe_down_5=
- {
- 0,0,FALSE,
- FALSE, {0,0,0},
- FALSE, {0,0,0}, {0,0,0}
- };
-
- //-------------------------------------- frameinfo list
- static frameinfo* framelist[2][18]=
- {
- {
- NULL,
- &frame_wait_1,
- &frame_wait_2,
- &frame_wait_3,
- &frame_punch_1,
- &frame_punch_2,
- &frame_kick_1,
- &frame_kick_2,
- &frame_block_1,
- &frame_high_1,
- &frame_low_1,
- &frame_win_1,
- &frame_down_1,
- &frame_down_2,
- &frame_down_3,
- &frame_down_4,
- &frame_down_5
- },
- {
- NULL,
- &rframe_wait_1,
- &rframe_wait_2,
- &rframe_wait_3,
- &rframe_punch_1,
- &rframe_punch_2,
- &rframe_kick_1,
- &rframe_kick_2,
- &rframe_block_1,
- &rframe_high_1,
- &rframe_low_1,
- &rframe_win_1,
- &rframe_down_1,
- &rframe_down_2,
- &rframe_down_3,
- &rframe_down_4,
- &rframe_down_5
- }
- };
-
- //----------------------------------------------------------------------
-
- void Fighter::initialize()
- {
- load_gfxlib("lfight.gfx");
- load_gfxlib("rfight.gfx");
- if (side==LEFTGUY)
- set_gfxlib("lfight.gfx");
- else
- set_gfxlib("rfight.gfx");
-
- load_sfxlib("sounds.sfx");
- numsounds=get_num_clips();
- }
-
- void Fighter::update_status()
- {
- if (newmode)
- {
- newmode=FALSE;
- return;
- }
- if (mode!=OUT)
- {
- if (damage>=DAMAGE_LIMIT)
- {
- mode=OUT;
- frame=1;
- play_sound_clip(5);
- opponent->you_win();
- return;
- }
- }
- int m=mode;
- int f=frame;
- mode=next[m][f].mode;
- frame=next[m][f].frame;
- }
-
- void Fighter::display()
- {
- if (side==LEFTGUY)
- x=LEFT_START;
- else
- x=RIGHT_START;
- damage=0;
- y=FIGHTER_Y;
- mode=WAIT;
- frame=1;
-
- int imgno=image_no[mode][frame];
- int xoff=framelist[side][imgno]->xoffset;
- int yoff=framelist[side][imgno]->yoffset;
- show_image(x+xoff,y+yoff,imgno);
- }
-
- void Fighter::update()
- {
- int imgno=image_no[mode][frame];
- int xoff=framelist[side][imgno]->xoffset;
- int yoff=framelist[side][imgno]->yoffset;
- show_image(x+xoff,y+yoff,imgno);
-
- //#define SHOWZONE
- #ifdef SHOWZONE
- frameinfo* ptr=framelist[side][imgno];
- fg_setcolor(2);
- if (ptr->hasattack)
- {
- fg_move(x+ptr->attack.x,y+ptr->attack.y);
- fg_circle(ptr->attack.r);
- }
-
- fg_move(x+ptr->hightarget.x,y+ptr->hightarget.y);
- fg_circle(ptr->hightarget.r);
-
- fg_move(x+ptr->lowtarget.x,y+ptr->lowtarget.y);
- fg_circle(ptr->lowtarget.r);
- #endif
- }
-
- void Fighter::communicate()
- {
- int imgno=image_no[mode][frame];
- frameinfo* mine=framelist[side][imgno];
- if (mine->hasattack)
- {
- area absolute_area=mine->attack;
- absolute_area.x+=x;
- absolute_area.y+=y;
- opponent->evaluate_attack(absolute_area);
- }
- }
-
- #define max(a,b) ((a<b) ? b : a)
- #define min(a,b) ((a<b) ? a : b)
-
- void Fighter::evaluate_attack(area attack)
- {
- if (checkhits==FALSE) return;
-
- int testx,testy,dist;
- int imgno=image_no[mode][frame];
- frameinfo* mine=framelist[side][imgno];
- if (mine->hastarget)
- {
- // check the high target (head)
- testx=abs(attack.x-(x+mine->hightarget.x));
- testy=abs(attack.y-(y+mine->hightarget.y));
- dist=max(testx,testy) + (min(testx,testy)/2);
- if (dist <= attack.r+mine->hightarget.r)
- {
- if (mine->is_defensive)
- {
- post_message(ATTACK_BLOCKED,side);
- if (usenetpacks)
- post_netpack(ATTACK_BLOCKED);
- play_sound_clip(4);
- }
- else
- {
- mode=HIGH;
- frame=1;
- newmode=TRUE;
- damage+=7;
- post_message(GOT_PUNCHED,side);
- if (usenetpacks)
- post_netpack(GOT_PUNCHED);
- play_sound_clip(2);
- calc_impact();
- }
- }
-
- // check the low target
- testx=abs(attack.x-(x+mine->lowtarget.x));
- testy=abs(attack.y-(y+mine->lowtarget.y));
- dist=max(testx,testy) + (min(testx,testy)/2);
- if (dist <= attack.r+mine->lowtarget.r)
- {
- if (mine->is_defensive)
- {
- post_message(ATTACK_BLOCKED,side);
- if (usenetpacks)
- post_netpack(ATTACK_BLOCKED);
- play_sound_clip(4);
- }
- else
- {
- mode=LOW;
- frame=1;
- newmode=TRUE;
- damage+=10;
- post_message(GOT_KICKED,side);
- if (usenetpacks)
- post_netpack(GOT_KICKED);
- play_sound_clip(3);
- calc_impact();
- }
- }
- }
- }
-
- void Fighter::calc_impact()
- {
- if (side==LEFTGUY)
- {
- if (x>MIN_X)
- {
- if (x-IMPACT>MIN_X)
- x-=IMPACT;
- else
- x=MIN_X;
- }
- }
- else // (side==RIGHT)
- {
- if (x+BITMAP_WIDTH < MAX_X)
- {
- if (x+IMPACT+BITMAP_WIDTH < MAX_X)
- x+=IMPACT;
- else
- x=MAX_X-BITMAP_WIDTH;
- }
- }
- }
-
- void Fighter::you_win()
- {
- mode=WIN;
- frame=1;
- post_message(GAME_OVER,side);
- }
-
- int Fighter::kick() // tag
- {
- if (mode==WAIT)
- {
- mode=KICK;
- frame=1;
- newmode=TRUE;
- return 1;
- }
- return 0;
- }
-
- int Fighter::punch()
- {
- if (mode==WAIT)
- {
- mode=PUNCH;
- frame=1;
- newmode=TRUE;
- return 1;
- }
- return 0;
- }
-
- int Fighter::left()
- {
- if (mode!=WAIT) return 0;
-
- if (side==LEFTGUY)
- {
- if (x>MIN_X)
- x-=LOC_INC;
- }
- else
- {
- if (x>opponent->x+CLOSE_LIMIT)
- x-=LOC_INC;
- }
- return 1;
- }
-
- int Fighter::right()
- {
- if (mode!=WAIT) return 0;
-
- if (side==LEFTGUY)
- {
- if (x+CLOSE_LIMIT<opponent->x)
- x+=LOC_INC;
- }
- else
- {
- if (x+BITMAP_WIDTH<MAX_X)
- x+=LOC_INC;
- }
- return 1;
- }
-
- int Fighter::block()
- {
- if (mode==WAIT)
- {
- mode=BLOCK;
- frame=1;
- newmode=TRUE;
- return 1;
- }
- return 0;
- }
-
- void Fighter::got_punched()
- {
- mode=HIGH;
- frame=1;
- newmode=TRUE;
- damage+=7;
- post_message(GOT_PUNCHED,side);
- play_sound_clip(2);
- calc_impact();
- }
-
- void Fighter::got_kicked()
- {
- mode=LOW;
- frame=1;
- newmode=TRUE;
- damage+=10;
- post_message(GOT_KICKED,side);
- play_sound_clip(3);
- calc_impact();
- }
-
- void Fighter::got_blocked()
- {
- post_message(ATTACK_BLOCKED,side);
- play_sound_clip(4);
- }
-