(Tutotrial) Kuki's Adding a motorbike for SDL

View previous topic View next topic Go down

(Tutotrial) Kuki's Adding a motorbike for SDL

Post by Officer-M. John (Admin) on Thu Jan 19, 2017 11:14 am

I imported for SDL Adding a motorbike (by Kuki) and works. I modified a little.

WL_DEF.H (gamestate structure):

Code:

    boolean     mbike;   // is the player riding on the mbike
    short       motospeed;   // what's the bike's speed
    boolean     left;    // are you turning left
    boolean     right;   // are you turning right

WL_GAME.CPP:

Code:

    if (!loadedgame)
    {
        gamestate.TimeCount
            = gamestate.secrettotal
            = gamestate.killtotal
            = gamestate.treasuretotal
            = gamestate.secretcount
            = gamestate.killcount
            = gamestate.treasurecount
            = pwallstate = pwallpos = facetimes = 0;
        LastAttacker = NULL;
        killerobj = NULL;
        
     if (gamestate.episode == 0 && gamestate.mapon == 5)
     {
         gamestate.mbike = true;
         gamestate.motospeed = 0;
         gamestate.left = false;
         gamestate.right = false;    
         DrawAmmo();
         DrawWeapon();
        }
     }

WL_AGENT.CPP:

ControlMovement:

Code:

//
// side to side move
//
if (gamestate.mbike!=true) // no strafe on a mbike
{
if (buttonstate[bt_strafe])
{
//
// strafing
//
//
if (controlx > 0)
{
angle = ob->angle - ANGLES/4;
if (angle < 0)
angle += ANGLES;

       angle = ob->angle + ANGLES/2;
        if (angle >= ANGLES)
            angle -= ANGLES;
        Thrust (angle,controly*BACKMOVESCALE);          // move backwards
    }

}
   else
   {
      if (controlx > 0)      // this section sets left & rigth to true/false depending on the keys that player presses
      {
      gamestate.left=true;
      gamestate.right=false;
      }
      else if (controlx < 0)
      {
      gamestate.left=false;
      gamestate.right=true;
      }
      else
      {
      gamestate.left=false;
      gamestate.right=false;
      }

      anglefrac += controlx*.5;      // turning - you may adjust this line and/or add some gamestate.motospeed dependencies
      angleunits = anglefrac/ANGLESCALE;
      anglefrac -= angleunits*ANGLESCALE;
      ob->angle -= angleunits;

      if (ob->angle >= ANGLES)
         ob->angle -= ANGLES;
      if (ob->angle < 0)
         ob->angle += ANGLES;

    if (controly > 0 )               // brakes
   {
   if (gamestate.motospeed>controly)
   gamestate.motospeed-=controly*2;
   else if (gamestate.motospeed>=0-controly)
   gamestate.motospeed=0;
   else
   gamestate.motospeed+=controly*2;    
   SD_PlaySound (DIESND); //use some BRAKESND instead, this may cause problems, not well tested!!!
   }
    else if (controly < 0)            // accelerate
   {
    if (gamestate.motospeed<30000)
    gamestate.motospeed-=controly*.5;
    else
    gamestate.motospeed=30000;
    SD_PlaySound (HITWALLSND); //use some ENGINESND instead, this may cause problems, not well tested!!!
   }
    else   // no keys pressed - bike slowly reduces it's speed
   {
   if (gamestate.motospeed<0)
   gamestate.motospeed+=10;
   else if (gamestate.motospeed>0)
   gamestate.motospeed-=1;
   }
   Thrust (ob->angle,gamestate.motospeed);
    }

    if (gamestate.victoryflag)              // watching the BJ actor
        return;

DrawWeapon:

Code:

void DrawWeapon (void)
{
if (gamestate.mbike!=true)
StatusDrawPic (32,8,KNIFEPIC+gamestate.weapon);
else
StatusDrawPic (32,8,MBIKEPIC); // use your own picture
}

TryMove:

Code:

    for (y=yl;y<=yh;y++)
    {
        for (x=xl;x<=xh;x++)
        {
            check = actorat[x][y];
            if (ISPOINTER(check) && check != player && (check->flags & FL_SHOOTABLE) )
            {
                deltax = ob->x - check->x;
                if (deltax < -MINACTORDIST || deltax > MINACTORDIST)
                    continue;
                deltay = ob->y - check->y;
                if (deltay < -MINACTORDIST || deltay > MINACTORDIST)
                    continue;
                    
                if (gamestate.mbike==true && (gamestate.motospeed>=2000 || gamestate.motospeed<=-2000))   //adjust the speed to your liking
                {
                KillActor(actorat[x][y]);
                return true;
                }    

                return false;
            }
        }
    }

    return true;
}

ClipMove:

Code:

#ifndef REMDEBUG
    if (noclip && ob->x > 2*TILEGLOBAL && ob->y > 2*TILEGLOBAL
        && ob->x < (((int32_t)(mapwidth-1))<<TILESHIFT)
        && ob->y < (((int32_t)(mapheight-1))<<TILESHIFT) )
        return;         // walk through walls
#endif

   if (gamestate.mbike==true)
   {
      if (gamestate.motospeed<=200)      // very slow or backwards movement - just set the speed to 0
      gamestate.motospeed=0;
      else      // if we're riding faster... (you should add crash sound here, probably something like the sound stuff just below this "+" section. I didn't add it cause I have some problems with sound in Wolf and can't test it)
      {
         if (gamestate.motospeed>=5000) // take damage if you're driving really fast, damage depends on the speed
    {
         TakeDamage (gamestate.motospeed/500, NULL);
      SD_PlaySound (EVASND); // use some CRASHSND of your creation instead
    }
      gamestate.motospeed=-0.3*gamestate.motospeed; // bounce
      }      // so that you won't get into a wall
      ob->x=basex;
      ob->y=basey;
      return;
    }

    if (!SD_SoundPlaying())
        SD_PlaySound (HITWALLSND);

T_Player:

Code:

    if (gamestate.mbike!=true) {

    UpdateFace ();
    CheckWeaponChange ();

    if ( buttonstate[bt_use] )

WL_DRAW.CPP (DrawPlayerWeapon):

Code:

#ifndef SPEAR
    if (gamestate.victoryflag)
    {
#ifndef APOGEE_1_0
        if (player->state == &s_deathcam && (GetTimeCount()&32) )
            SimpleScaleShape(viewwidth/2,SPR_DEATHCAM,viewheight+1);
#endif
        return;
    }
#endif
   if (gamestate.mbike == true)
   {
   if (gamestate.left == true)
   {
    SimpleScaleShape(viewwidth/2,SPR_CHAINATK1,viewheight+1); // change SPR_* here and below to your own ones
    return;
   }
   else if (gamestate.right == true)
   {
    SimpleScaleShape(viewwidth/2,SPR_KNIFEATK2,viewheight+1);
    return;
   }
    SimpleScaleShape(viewwidth/2,SPR_PISTOLATK3,viewheight+1);
    return;
   }

    if (gamestate.weapon != -1)
    {
        shapenum = weaponscale[gamestate.weapon]+gamestate.weaponframe;
        SimpleScaleShape((viewwidth/2),shapenum,viewheight+1);
    }

Wow. You get a nice Motorbike.


Last edited by Officer-M. John (Admin) on Fri Feb 10, 2017 1:28 pm; edited 2 times in total
avatar
Officer-M. John (Admin)
Admin

Posts : 328
Join date : 2015-10-02
Age : 19

View user profile http://wolf3dfanboys.usersboard.com

Back to top Go down

Re: (Tutotrial) Kuki's Adding a motorbike for SDL

Post by Ferir987 on Tue Jan 24, 2017 9:00 am

Well this is, as well, very much of those codes and the rest of it!
avatar
Ferir987
Cool mod maker
Cool mod maker

Posts : 211
Join date : 2016-04-15
Age : 19
Location : Hungary,Heves Gyöngyös country

View user profile https://jhoni196.blogspot.hu/

Back to top Go down

Re: (Tutotrial) Kuki's Adding a motorbike for SDL

Post by Officer-M. John (Admin) on Tue Jan 24, 2017 9:22 am

I know.
avatar
Officer-M. John (Admin)
Admin

Posts : 328
Join date : 2015-10-02
Age : 19

View user profile http://wolf3dfanboys.usersboard.com

Back to top Go down

Re: (Tutotrial) Kuki's Adding a motorbike for SDL

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum