X-Git-Url: https://deadsoftware.ru/gitweb?p=flatwaifu.git;a=blobdiff_plain;f=src%2Fplayer.c;h=79a5a98968cbd0b2009b80dab942b99362dd2403;hp=06bf44e85210d3f7a14c66a05fd86a60b5da1e96;hb=563dffaf02ff36da4054f937fcc9f99a072e15bf;hpb=a2115940e7643dcb1b87286f3d19fe95f7b79bd3 diff --git a/src/player.c b/src/player.c index 06bf44e..79a5a98 100644 --- a/src/player.c +++ b/src/player.c @@ -23,11 +23,6 @@ #include "glob.h" #include #include -#include "files.h" -#include "memory.h" -#include "vga.h" -#include "error.h" -#include "keyb.h" #include "view.h" #include "dots.h" #include "smoke.h" @@ -38,8 +33,9 @@ #include "switch.h" #include "player.h" #include "misc.h" - -extern int hit_xv,hit_yv; +#include "my.h" +#include "game.h" +#include "input.h" #define PL_RAD 8 #define PL_HT 26 @@ -47,52 +43,35 @@ extern int hit_xv,hit_yv; #define PL_SWUP 4 #define PL_FLYUP 4 -#define PL_AIR 360 #define PL_AQUA_AIR 1091 -byte p_immortal=0,p_fly=0; +byte p_immortal; +byte p_fly; -int PL_JUMP=10,PL_RUN=8; +int PL_JUMP=10; +int PL_RUN=8; -int wp_it[11]={0,I_CSAW,0,I_SGUN,I_SGUN2,I_MGUN,I_LAUN,I_PLAS,I_BFG,I_GUN2,0}; +static int wp_it[11]={0,I_CSAW,0,I_SGUN,I_SGUN2,I_MGUN,I_LAUN,I_PLAS,I_BFG,I_GUN2,0}; enum{STAND,GO,DIE,SLOP,DEAD,MESS,OUT,FALL}; typedef void fire_f(int,int,int,int,int); -player_t pl1,pl2; +player_t pl1; +player_t pl2; static int aitime; static void *aisnd[3]; static void *pdsnd[5]; -static void *spr[27*2],*snd[11]; -static char sprd[27*2]; -static void *wpn[11][6]; -static byte goanim[]="BDACDA", - dieanim[]="HHHHIIIIJJJJKKKKLLLLMMMM", - slopanim[]="OOPPQQRRSSTTUUVVWW"; - - -#pragma pack(1) -struct { - int ku,kd,kl,kr,kf,kj,kwl,kwr,kp; -} _keys; -#pragma pack() - -void PL_savegame(FILE* h) { - myfwrite(&pl1,1,sizeof(pl1)-sizeof(_keys),h);//myfwrite(&pl1,1,sizeof(pl1),h); - if(_2pl) myfwrite(&pl2,1,sizeof(pl2)-sizeof(_keys),h);//myfwrite(&pl2,1,sizeof(pl2),h); - myfwrite(&PL_JUMP,1,4,h);myfwrite(&PL_RUN,1,4,h);myfwrite(&p_immortal,1,1,h); -} +static void *snd[11]; +byte plr_goanim[]="BDACDA"; +byte plr_dieanim[]="HHHHIIIIJJJJKKKKLLLLMMMM"; +byte plr_slopanim[]="OOPPQQRRSSTTUUVVWW"; -void PL_loadgame(FILE* h) { - myfread(&pl1,1,sizeof(pl1)-sizeof(_keys),h);//myfread(&pl1,1,sizeof(pl1),h); - if(_2pl) myfread(&pl2,1,sizeof(pl2)-sizeof(_keys),h);//myfread(&pl2,1,sizeof(pl2),h); - myfread(&PL_JUMP,1,4,h);myfread(&PL_RUN,1,4,h);myfread(&p_immortal,1,1,h); +static int nonz (int a) { + return a ? a : 1; } -static int nonz(int a) {return (a)?a:1;} - static int firediry(player_t *p) { if(p->f&PLF_UP) return -42; if(p->f&PLF_DOWN) return 19; @@ -108,22 +87,22 @@ static void fire(player_t *p) { if(p->cwpn) return; if(p->wpn==8) { if(!p->fire) - if(keys[p->kf] && p->cell>=40) + if(I_pressed(p->kf) && p->cell>=40) {Z_sound(snd[5],128);p->fire=21;p->cell-=40;p->drawst|=PL_DRAWWPN;return;} else return; if(p->fire==1) p->cwpn=12; else return; }else if(p->wpn==1) { if(!p->csnd) { - if(!keys[p->kf]) {Z_sound(snd[7],128);p->csnd=13;return;} + if(!I_pressed(p->kf)) {Z_sound(snd[7],128);p->csnd=13;return;} } - if(keys[p->kf] && !p->fire) { + if(I_pressed(p->kf) && !p->fire) { p->fire=2; WP_chainsaw(p->o.x+((p->d)?4:-4),p->o.y,(g_dm)?9:3,p->id); if(!p->csnd) {Z_sound(snd[8],128);p->csnd=29;} }return; }else if(p->fire) return; - if(keys[p->kf] || p->wpn==8) { + if(I_pressed(p->kf) || p->wpn==8) { switch(p->wpn) { case 2: case 5: if(!p->ammo) return; @@ -158,10 +137,10 @@ static void fire(player_t *p) { static void chgwpn(player_t *p) { if(p->cwpn) return; if(p->fire && p->wpn!=1) return; - if(keys[p->kwl]) { + if(I_pressed(p->kwl)) { do{ if(--p->wpn<0) p->wpn=10; }while(!(p->wpns&(1<wpn))); p->cwpn=3; - }else if(keys[p->kwr]) { + }else if(I_pressed(p->kwr)) { do{ if(++p->wpn>10) p->wpn=0; }while(!(p->wpns&(1<wpn))); p->cwpn=3; } @@ -183,7 +162,7 @@ static void jump(player_t *p,int st) { } p->drawst|=PL_DRAWAIR; } - if(keys[p->kj]) { + if(I_pressed(p->kj)) { if(p_fly) { p->o.yv=-PL_FLYUP; }else{ @@ -193,7 +172,7 @@ static void jump(player_t *p,int st) { } } -int PL_isdead(player_t *p) { +int PL_isdead (player_t *p) { switch(p->st) { case DEAD: case MESS: case OUT: @@ -202,10 +181,13 @@ int PL_isdead(player_t *p) { return 0; } -void PL_init(void) { - p_immortal=0; - PL_JUMP=10;PL_RUN=8; - aitime=0; +void PL_init (void) { + pl1.id = -1; + pl2.id = -2; + p_immortal = 0; + PL_JUMP = 10; + PL_RUN = 8; + aitime = 0; } void PL_alloc(void) { @@ -223,17 +205,7 @@ void PL_alloc(void) { "SAWHIT", "PLFALL" }; - static char s[6]; - - for(i=0;i<27;++i) { - spr[i*2]=Z_getspr("PLAY",i,1,sprd+i*2); - spr[i*2+1]=Z_getspr("PLAY",i,2,sprd+i*2+1); - } - memcpy(s,"PWPx",4); - for(i=1;i<11;++i) { - s[3]=((i<10)?'0':('A'-10))+i; - for(j=0;j<6;++j) wpn[i][j]=Z_getspr(s,j,1,NULL); - } + char s[6]; for(i=0;i<11;++i) snd[i]=Z_getsnd(nm[i]); memcpy(s,"AIx",4); for(i=0;i<3;++i) { @@ -247,7 +219,7 @@ void PL_alloc(void) { } } -void PL_restore(player_t *p) { +static void PL_restore(player_t *p) { p->o.xv=p->o.yv=p->o.vx=p->o.vy=0; p->o.r=PL_RAD;p->o.h=PL_HT; p->pain=0; @@ -269,18 +241,18 @@ void PL_restore(player_t *p) { p->keys=(g_dm)?0x70:0; } -void PL_reset(void) { +void PL_reset (void) { pl1.st=pl2.st=DEAD; pl1.frag=pl2.frag=0; } -void PL_spawn(player_t *p,int x,int y,char d) { +void PL_spawn (player_t *p,int x,int y,char d) { PL_restore(p); p->o.x=x;p->o.y=y;p->d=d; p->kills=p->secrets=0; } -int PL_hit(player_t *p,int d,int o,int t) { +int PL_hit (player_t *p,int d,int o,int t) { if(!d) return 0; switch(p->st) { case DIE: case SLOP: @@ -302,7 +274,7 @@ int PL_hit(player_t *p,int d,int o,int t) { return 1; } -void PL_damage(player_t *p) { +void PL_damage (player_t *p) { int i; if(!p->hit && p->life>0) return; @@ -346,12 +318,12 @@ void PL_damage(player_t *p) { return; } -void PL_cry(player_t *p) { +void PL_cry (player_t *p) { Z_sound(snd[(p->pain>20)?1:0],128); p->f|=PLF_PNSND; } -int PL_give(player_t *p,int t) { +int PL_give (player_t *p, int t) { int i; switch(p->st) { @@ -473,7 +445,7 @@ int PL_give(player_t *p,int t) { } } -void PL_act(player_t *p) { +void PL_act (player_t *p) { int st; if(--aitime<0) aitime=0; @@ -493,14 +465,14 @@ void PL_act(player_t *p) { }else st=0; if(st&Z_HITWATER) Z_splash(&p->o,PL_RAD+PL_HT); if(p->f&PLF_FIRE) if(p->fire!=2) p->f-=PLF_FIRE; - if(keys[p->ku]) {p->f|=PLF_UP;p->looky-=5;} + if(I_pressed(p->ku)) {p->f|=PLF_UP;p->looky-=5;} else{ p->f&=0xFFFF-PLF_UP; - if(keys[p->kd]) + if(I_pressed(p->kd)) {p->f|=PLF_DOWN;p->looky+=5;} else {p->f&=0xFFFF-PLF_DOWN;p->looky=Z_dec(p->looky,5);} } - if(keys[p->kp]) SW_press(p->o.x,p->o.y,p->o.r,p->o.h,1|p->keys,p->id); + if(I_pressed(p->kp)) SW_press(p->o.x,p->o.y,p->o.r,p->o.h,1|p->keys,p->id); if(p->fire) --p->fire; if(p->cwpn) --p->cwpn; if(p->csnd) --p->csnd; @@ -509,12 +481,12 @@ void PL_act(player_t *p) { switch(p->st) { case DIE: p->o.h=7; - if(!dieanim[++p->s]) {p->st=DEAD;MN_killedp();} + if(!plr_dieanim[++p->s]) {p->st=DEAD;MN_killedp();} p->o.xv=Z_dec(p->o.xv,1); break; case SLOP: p->o.h=6; - if(!slopanim[++p->s]) {p->st=MESS;MN_killedp();} + if(!plr_slopanim[++p->s]) {p->st=MESS;MN_killedp();} p->o.xv=Z_dec(p->o.xv,1); break; case GO: @@ -522,15 +494,15 @@ void PL_act(player_t *p) { if(p_fly) SMK_gas(p->o.x,p->o.y-2,2,3,p->o.xv+p->o.vx,p->o.yv+p->o.vy,128); if((p->s+=abs(p->o.xv)/2) >= 24) p->s%=24; - if(!keys[p->kl] && !keys[p->kr]) { + if(!I_pressed(p->kl) && !I_pressed(p->kr)) { if(p->o.xv) p->o.xv=Z_dec(p->o.xv,1); else p->st=STAND; break; } - if(p->o.xvkr]) {p->o.xv+=PL_RUN>>3;p->d=1;} + if(p->o.xvkr)) {p->o.xv+=PL_RUN>>3;p->d=1;} else if(PL_RUN>8) SMK_gas(p->o.x,p->o.y-2,2,3,p->o.xv+p->o.vx,p->o.yv+p->o.vy,32); - if(p->o.xv>-PL_RUN && keys[p->kl]) {p->o.xv-=PL_RUN>>3;p->d=0;} + if(p->o.xv>-PL_RUN && I_pressed(p->kl)) {p->o.xv-=PL_RUN>>3;p->d=0;} else if(PL_RUN>8) SMK_gas(p->o.x,p->o.y-2,2,3,p->o.xv+p->o.vx,p->o.yv+p->o.vy,32); break; @@ -538,15 +510,15 @@ void PL_act(player_t *p) { chgwpn(p);fire(p);jump(p,st); if(p_fly) SMK_gas(p->o.x,p->o.y-2,2,3,p->o.xv+p->o.vx,p->o.yv+p->o.vy,128); - if(keys[p->kl]) {p->st=GO;p->s=0;p->d=0;} - else if(keys[p->kr]) {p->st=GO;p->s=0;p->d=1;} + if(I_pressed(p->kl)) {p->st=GO;p->s=0;p->d=0;} + else if(I_pressed(p->kr)) {p->st=GO;p->s=0;p->d=1;} break; case DEAD: case MESS: case OUT: p->o.xv=Z_dec(p->o.xv,1); - if(keys[p->ku] || keys[p->kd] || keys[p->kl] || keys[p->kr] || - keys[p->kf] || keys[p->kj] || keys[p->kp] || keys[p->kwl] || keys[p->kwr]) { + if(I_pressed(p->ku) || I_pressed(p->kd) || I_pressed(p->kl) || I_pressed(p->kr) || + I_pressed(p->kf) || I_pressed(p->kj) || I_pressed(p->kp) || I_pressed(p->kwl) || I_pressed(p->kwr)) { if(p->st!=OUT) MN_spawn_deadpl(&p->o,p->color,(p->st==MESS)?1:0); PL_restore(p); if(g_dm) {G_respawn_player(p);break;} @@ -565,56 +537,6 @@ void PL_act(player_t *p) { } } -static int standspr(player_t *p) { - if(p->f&PLF_UP) return 'X'; - if(p->f&PLF_DOWN) return 'Z'; - return 'E'; -} - -static int wpnspr(player_t *p) { - if(p->f&PLF_UP) return 'C'; - if(p->f&PLF_DOWN) return 'E'; - return 'A'; -} - -void PL_draw(player_t *p) { - int s,w,wx,wy; - static int wytab[]={-1,-2,-1,0}; - - s='A';w=0;wx=wy=0; - switch(p->st) { - case STAND: - if(p->f&PLF_FIRE) {s=standspr(p)+1;w=wpnspr(p)+1;} - else if(p->pain) {s='G';w='A';wx=p->d?2:-2;wy=1;} - else {s=standspr(p);w=wpnspr(p);} - break; - case DEAD: - s='N';break; - case MESS: - s='W';break; - case GO: - if(p->pain) {s='G';w='A';wx=p->d?2:-2;wy=1;} - else { - s=goanim[p->s/8];w=(p->f&PLF_FIRE)?'B':'A'; - wx=p->d?2:-2;wy=1+wytab[s-'A']; - } - break; - case DIE: - s=dieanim[p->s];break; - case SLOP: - s=slopanim[p->s];break; - case OUT: - s=0;break; - } - if(p->wpn==0) w=0; - if(w) Z_drawspr(p->o.x+wx,p->o.y+wy,wpn[p->wpn][w-'A'],p->d); - if(s) Z_drawmanspr(p->o.x,p->o.y,spr[(s-'A')*2+p->d],sprd[(s-'A')*2+p->d],p->color); -} - -void *PL_getspr(int s,int d) { - return spr[(s-'A')*2+d]; -} - static void chk_bfg(player_t *p,int x,int y) { int dx,dy; @@ -630,40 +552,9 @@ static void chk_bfg(player_t *p,int x,int y) { } } -void bfg_fly(int x,int y,int o) { +void bfg_fly (int x,int y,int o) { // if(!g_dm) return; if(o!=-1) chk_bfg(&pl1,x,y); if(_2pl) if(o!=-2) chk_bfg(&pl2,x,y); if(o==-1 || o==-2) MN_warning(x-50,y-50,x+50,y+50); } - -void PL_drawst(player_t *p) { - V_setrect(WD,120,w_o,HT);Z_clrst(); - int i; - - if(p->drawst&PL_DRAWAIR) - if (p->airair); - if(p->drawst&PL_DRAWLIFE) - Z_drawstprcnt(0,p->life); - if(p->drawst&PL_DRAWARMOR) - Z_drawstprcnt(1,p->armor); - if(p->drawst&PL_DRAWWPN) { - switch(p->wpn) { - case 2: case 5: - i=p->ammo;break; - case 3: case 4: case 9: - i=p->shel;break; - case 6: - i=p->rock;break; - case 10: - i=p->fuel;break; - case 7: case 8: - i=p->cell;break; - } - Z_drawstwpn(p->wpn,i); - } - if(p->drawst&PL_DRAWFRAG) Z_drawstnum(p->frag); - if(p->drawst&PL_DRAWKEYS) Z_drawstkeys(p->keys); - if(!_2pl) if(p->drawst&PL_DRAWLIVES) Z_drawstlives(p->lives); -}