⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cave.c

📁 game duke3d source
💻 C
📖 第 1 页 / 共 4 页
字号:
        if (pixs == 2) showscreen2pix320200();
        if (pixs == 1) showscreen1pix320200();
    }
    else
    {
        if (pixs == 4) showscreen4pix320400();
        if (pixs == 2) showscreen2pix320400();
        if (pixs == 1) showscreen1pix320400();
    }

    toutp(0x3d4,0xc); toutp(0x3d5,(frameplace&65535)>>8);  //Nextpage
    if (vidmode == 0)
    {
        frameplace += 16384;
        if (frameplace >= 0xb0000) frameplace = 0xa0000;
    }
    else
    {
        frameplace += 32768;
        if (frameplace > 0xa8000) frameplace = 0xa0000;
    }
}

void drawscreen(void)
{
    sortobjectstoview();
    animateobjects();
    drawmap();                                   //Draw to non-video memory
    nextpage();
}


// Object Code

void initobjectlists(void)
{
	long i;

    for(i=0;i<MAXSTATUS;i++)
        map.headobject[i] = -1;
    map.headobject[MAXSTATUS] = 0;
    for(i=0;i<MAXOBJECTS;i++)
	{
        map.prevobject[i] = i-1;
        map.nextobject[i] = i+1;
        map.objectstat[i] = MAXSTATUS;
	}
    map.prevobject[0] = -1;
    map.nextobject[MAXOBJECTS-1] = -1;
}

insertobject(short statnum)
{
	short blanktouse;

    if ((statnum >= MAXSTATUS) || (map.headobject[MAXSTATUS] == -1))
		return(-1);  //list full

    blanktouse = map.headobject[MAXSTATUS];

    map.headobject[MAXSTATUS] = map.nextobject[blanktouse];
    if (map.headobject[MAXSTATUS] >= 0)
        map.prevobject[map.headobject[MAXSTATUS]] = -1;

    map.prevobject[blanktouse] = -1;
    map.nextobject[blanktouse] = map.headobject[statnum];
    if (map.headobject[statnum] >= 0)
        map.prevobject[map.headobject[statnum]] = blanktouse;
    map.headobject[statnum] = blanktouse;

    map.objectstat[blanktouse] = statnum;

	return(blanktouse);
}

deleteobject (short deleteme)
{
    if (map.objectstat[deleteme] == MAXSTATUS)
		return(-1);

    if (map.headobject[map.objectstat[deleteme]] == deleteme)
        map.headobject[map.objectstat[deleteme]] = map.nextobject[deleteme];

    if (map.prevobject[deleteme] >= 0) map.nextobject[map.prevobject[deleteme]] = map.nextobject[deleteme];
    if (map.nextobject[deleteme] >= 0) map.prevobject[map.nextobject[deleteme]] = map.prevobject[deleteme];

    if (map.headobject[MAXSTATUS] >= 0) map.prevobject[map.headobject[MAXSTATUS]] = deleteme;
    map.prevobject[deleteme] = -1;
    map.nextobject[deleteme] = map.headobject[MAXSTATUS];
    map.headobject[MAXSTATUS] = deleteme;

    map.objectstat[deleteme] = MAXSTATUS;
	return(0);
}

long clipmove(long *x, long *y, long *z, long vx, long vy, long vz, unsigned long rad)
{
    long hiz, loz, dax, day, daz, retcode;
    char charx, chary;

    retcode = 0;

    if( vx|vy|vz )
    {
        dax = *x;
        day = *y;
        daz = *z;

        dax += vx;
        day += vy;
        daz += vz;

        charx = (dax>>10)&255;
        chary = (day>>10)&255;

        hiz = map.h1[ (charx << 8) + chary ]<<12;
        loz = map.h2[ (charx << 8) + chary ]<<12;

        if( ( hiz + rad ) > daz )
        {
            daz = ( hiz + rad );
            retcode = CLIP_HITCEILING|CLIP_HALT;
        }

        if( ( loz - rad ) < daz )
        {
            daz = ( loz - rad );
            retcode |= CLIP_HITFLOOR;
        }

        dax &= 0x3ffffff;
        day &= 0x3ffffff;

        if( (retcode&CLIP_HALT) != CLIP_HALT )
        {
            *x = dax;
            *y = day;
        }

        *z += (daz-(*z))>>2;

    }

    return(retcode);

}

void loadboard(char *fn)
{
    iodata(fn,(char *)&map,sizeof(map),IO_LOAD|IO_NOCLOSE);
    iodata(fn,(char *)&self[0],sizeof(self),IO_LOAD|IO_NOCLOSE);
    iodata(fn,(char *)&object[0],sizeof(object),IO_LOAD|IO_NOCLOSE);

    iodata(fn,&map.h1[0],65536L,IO_LOAD|IO_NOCLOSE);
    iodata(fn,&map.c1[0],65536L,IO_LOAD|IO_NOCLOSE);
    iodata(fn,&map.h2[0],65536L,IO_LOAD|IO_NOCLOSE);
    iodata(fn,&map.c2[0],65536L,IO_LOAD);
}

void saveboard(char *fn)
{
    iodata(fn,(char *)&map,sizeof(map),IO_SAVE|IO_NOCLOSE);
    iodata(fn,(char *)&self[0],sizeof(self),IO_SAVE|IO_NOCLOSE);
    iodata(fn,(char *)&object[0],sizeof(object),IO_SAVE|IO_NOCLOSE);

    iodata(fn,&map.h1[0],65536L,IO_SAVE|IO_NOCLOSE);
    iodata(fn,&map.c1[0],65536L,IO_SAVE|IO_NOCLOSE);
    iodata(fn,&map.h2[0],65536L,IO_SAVE|IO_NOCLOSE);
    iodata(fn,&map.c2[0],65536L,IO_SAVE);
}


// Player Code

void processinput(short snum)
{
    long i, xvel, yvel, clipval;

        if(keystatus[sc_F2] > 0)
            saveboard("level_01.map");

        if(keystatus[sc_F3] > 0)
            loadboard("level_01.map");

        if( keystatus[sc_F4] > 0)
            initaboard();

        if( keystatus[sc_P] > 0)
        {
            keystatus[sc_P] = 0;
            while( keystatus[sc_P] == 0);
            keystatus[sc_P] = 0;
        }

        if (keystatus[sc_LeftControl] > 0)
            blast(((self[snum].posx>>10)&255),((self[snum].posy>>10)&255),16,trand()&255);
    
        self[snum].vel = 0L;
        self[snum].svel = 0L;
        self[snum].angvel = 0;
        if (moustat == 1)
        {
            readmouse();
            self[snum].ang += mousx;
            self[snum].vel = (((long)-mousy)<<1);
        }

        if(keystatus[sc_Space] > 0)
        {
            spawn(1, -1);
            keystatus[sc_Space] = 0;
        }

        if (keystatus[sc_kpad_1] > 0)
            self[snum].horiz += 16L;
        if (keystatus[sc_kpad_0] > 0)
            self[snum].horiz -= 16L;

        if ( keystatus[sc_A] > 0 )
            self[snum].posz -= (16384<<1);

//            self[snum].zvel = -(4096*clockspeed>>1);
        if ( keystatus[sc_Z] > 0 )
            self[snum].zvel += (1024*clockspeed>>1);

        if ( keystatus[sc_LeftAlt] == 0 )
        {
            if (keystatus[sc_RightArrow] > 0)
                self[snum].angvel += 32;
            if (keystatus[sc_LeftArrow] > 0)
                self[snum].angvel -= 32;
        }
        else
        {
            if (keystatus[sc_RightArrow] > 0) self[snum].svel = -12L;
            if (keystatus[sc_LeftArrow] > 0) self[snum].svel = 12L;
        }

        if (keystatus[sc_Comma] > 0) self[snum].svel = 12L;
        if (keystatus[sc_Period] > 0) self[snum].svel = -12L;

        if (keystatus[sc_DownArrow] > 0) self[snum].vel = -12L;
        if (keystatus[sc_UpArrow] > 0) self[snum].vel = 12L;

        if(keystatus[sc_F] > 0)
        {
            self[snum].flashlight = 1-self[snum].flashlight;
            keystatus[sc_F] = 0;
        }


        if(keystatus[sc_CapsLock] > 0)
        {
            self[snum].runmode = 1-self[snum].runmode;
            keystatus[sc_CapsLock] = 0;
        }

        if(keystatus[sc_Tab] > 0)
        {
            self[snum].topdown = 1-self[snum].topdown;
            keystatus[sc_Tab] = 0;
        }

        if (keystatus[sc_LeftShift] > 0 || self[snum].runmode )
        {
            self[snum].vel <<= 1;
            self[snum].svel <<= 1;
            self[snum].angvel <<= 1;
        }

        if (self[snum].angvel != 0)
        {
            self[snum].ang += (self[snum].angvel*clockspeed)>>3;
            self[snum].ang = (self[snum].ang+2048)&2047;
        }

        xvel =
            ((self[snum].vel*clockspeed*sintable[(2560+self[snum].ang)&2047])>>12)+
            ((self[snum].svel*clockspeed*sintable[(2048+self[snum].ang)&2047])>>12);
        yvel =
            ((self[snum].vel*clockspeed*sintable[(2048+self[snum].ang)&2047])>>12)-
            ((self[snum].svel*clockspeed*sintable[(2560+self[snum].ang)&2047])>>12);

        clipval = clipmove(
            &self[snum].posx,
            &self[snum].posy,
            &self[snum].posz,
            xvel,
            yvel,
            self[snum].zvel,
            2048<<5);

          if( (clipval&CLIP_HITFLOOR) != CLIP_HITFLOOR )
          {
              if(self[snum].zvel < 0x10000)
                  self[snum].zvel += clockspeed<<9;
          }
          else
              self[snum].zvel = 0;


        if (detmode == 0)
        {
            if ((self[snum].vel|self[snum].svel|self[snum].angvel) == 0)
                pixs = 1;
            else
                pixs = 2;
        }
        if (keystatus[0x10] > 0) keystatus[0x10] = 0, pixs = 1;
        if (keystatus[0x11] > 0) keystatus[0x11] = 0, pixs = 2;
        if (keystatus[0x12] > 0) keystatus[0x12] = 0, pixs = 4;
        if (keystatus[0x13] > 0) keystatus[0x13] = 0, detmode = 1-detmode;
        if ((keystatus[0x1f]|keystatus[0x20]) > 0)
        {
            if (keystatus[0x1f] > 0)
            {
                if (vidmode == 0)
                {
                    frameplace = 0xa0000;
                    vidmode = 1;
                    toutp(0x3d4,0x9); toutp(0x3d5,inp(0x3d5)&254);
                    keystatus[0x1f] = 0;
                    ydim = 400L;
                    self[snum].horiz <<= 1;
                }
            }
            if (keystatus[0x20] > 0)
            {
                if (vidmode == 1)
                {
                    vidmode = 0;
                    toutp(0x3d4,0x9); toutp(0x3d5,inp(0x3d5)|1);
                    keystatus[0x20] = 0;
                    ydim = 200L;
                    self[snum].horiz >>= 1;
                }
            }
        }

        numframes++;
        totalclock += clockspeed;
        clockspeed = 0L;
}


// Object Code

char thinkobject(long i)
{
    long j;
    objecttype *o;
    char killit_flag;

    o = &object[i];
    
    killit_flag = 0;
    switch(o->picnum)
    {
        case 1:
            j = ((o->x>>10)<<8)+(o->y>>10);
            if(map.h2[j] == map.h1[j] )
            {
                killit_flag = 1;
                break;
            }
            object[i].templong++;
            if(object[i].templong > 10)
                killit_flag = 1;
            break;
    }

    if(killit_flag) deleteobject(i);

    return(killit_flag);
}

void processobjects(void)
{
    long i, j, nexti;

    for(j=0;j<MAXSTATUS;j++)
    {
        i = map.headobject[j];
        while(i >= 0)
        {
            nexti = map.nextobject[i];
            if( thinkobject(i) == 0 )
                clipmove(
                    &object[i].x,
                    &object[i].y,
                    &object[i].z,
                    object[i].xvel,
                    object[i].yvel,
                    object[i].zvel,
                    0);
            i = nexti;
        }
    }
}



// Main Game Loop

void gameloop(void)
{

    initaboard();
    drawscreen();
    fadepalette(0,4);

    while (keystatus[sc_Escape] == 0)
    {
        clearbuf(&map.s1[0],65536L>>1,0x1f1f1f1f);

        processobjects();
        processinput(screenpeek);
        drawscreen();
        pan3dsounds(self[screenpeek].i);
    }

    fadepalette(1,4);
}

void main(int argc, char *argv)
{
    initgame();
    gameloop();
    gameexit("Thank you for playing!");
}

// "Duke 2000"
// "Virchua Duke"
// "Son of Death
// "Cromium"
// "Potent"
// "Flotsom"

// Volume One
// "Duke is brain dead",
// "BOOT TO THE HEAD"
// Damage too duke
// Weapons are computer cont.  Only logical thinking
// is disappearing.
// " Flips! "
// Flash on screen, inst.
// "BUMS"
// "JAIL"/"MENTAL WARD (Cop code for looney?  T. asks Cop.)"
// "GUTS OR GLORY"

// ( Duke's Mission

// Duke:    "Looks like some kind of transporter...?"
// Byte:    "...YES"

// Duke:    "Waa, here goes nuthin'. "
// (Duke puts r. arm in device)

// Duke:    AAAAHHHHHHHHHHHHHHHHHHHHHHHHH!!!
// (Duke's arm is seved.)
// Byte:    NO.NO.NO.NO.NO.NO.NO...
// ( Byte directs duke to the nearest heat source)
// (Shut Up Mode)
// ( Duke Staggers, end of arm bleeding, usual oozing arm guts. )
// Byte: Left, Left, Left, Left, Right.
// ( Duke, loozing consc, trips on broken pipe, )
// ( hits temple on edge of step. )
// ( Rats everywhere, byte pushing them away with weapon,
// ( eventually covered, show usual groosums, Duke appears dead
// ( Duke wakes up, in hospital, vision less blurry
// ( Hospital doing brain scan, 1/3 cran. mass MISSING!
// Doc: Hummm?  ( Grabbing upper lip to "appear" smart. )

// Stand back boys

// Schrapnel has busted my scull!
// Now I'nsane, Mental ward, got to escape.
// Search light everywhere.

// (M)Mendor, The Tree Dweller.
// (M)BashMan, The Destructor.
// (M)Lash, The Scavenger.
// (F)Mag, The Slut.
// (F)
// NRA OR SOMETHIN'

// Duke Nukem
// 5th Dimention
// Pentagon Man!


// I Hope your not stupid!
// The 70's meet the future.
// Dirty Harry style.  70's music with futuristic edge
// The Instant De-Welder(tm)
// I think I'm going to puke...
// Badge attitude.
// He's got a Badge, a Bulldog, a Bronco (beat up/bondoed).
// Gfx:
// Lite rail systems
// A church.  Large cross
// Sniper Scope,
// Really use the phone
// The Boiler Room
// The IRS, nuking other government buildings?
// You wouldn't have a belt of booz, would ya?
// Slow turning signes
// More persise shooting/descructions
// Faces, use phoneoms and its lookup.  Talking, getting in fights.
// Drug dealers, pimps, and all galore
// Weapons, Anything lying around.
// Trees to clime, burning trees.
// Sledge Hammer, Sledge hammer with Spike
// sancurary, get away from it all.
// Goodlife = ( War + Greed ) / Peace
// MonsterisM           (ACTION)
//    An exper
// Global Hunter        (RPG)
// Slick a Wick         (PUZZLE)
// Roach Condo          (FUNNY)
// AntiProfit           (RPG)
// Pen Patrol           (TD SIM)
// 97.5 KPIG! - Wanker County
// "Fauna" - Native Indiginouns Animal Life
// Red Mercury


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -