dome
Code Editing Tutorials
Adding a motorbike.
You want to add a motorbike run to you game, like in Project Weltuntergang? Here's how to do it, by Kuki:
*WL_DEF.H
-add this to the gamestate structure:
boolean mbike; // is the player riding on the mbike
int motospeed; // what's the bike's speed
boolean left; // are you turning left
boolean right; // are you turning right
*WL_GAME.C
- in SetupGameLevel add: (it sets mbike to true, left & right to false and motospeed to 0 on certain level(s))
if (!loadedgame)
{
gamestate.TimeCount=
.
.
.
gamestate.treasurecount=0;
+if (gamestate.mapon==0 && gamestate.episode==0) // first level, first episode
+{
+gamestate.mbike=true;
+gamestate.motospeed=0;
+gamestate.left=false;
+gamestate.right=false;
+}
+else
+gamestate.mbike=false;
}
*WL_AGENT.C
- in T_Player add: (no use (doors, elevators, secrets), fire or weapon change on a mbike)
+if (gamestate.mbike!=true) {
CheckWeaponChange();
if (buttonstate[bt_use]...
.
.
.
Cmd_Fire ();
+ }
- in ControlMovement add: (the most improtant part - driving the bike)
//
// 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;
- in TryMove: (kills an enemy when he's hit with big speed)
for (y=yl;y<=yh;y++)
for (x=xl;x<=xh;x++)
{
check = actorat[x][y];
if (check > objlist
&& (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;
- in DrawWeapon (status bar weapon pic)
void DrawWeapon (void)
{
if (gamestate.mbike!=true)
StatusDrawPic (32,8,KNIFEPIC+gamestate.weapon);
else
StatusDrawPic (32,8,MBIKEPIC); // use your own picture
}
- in ClipMove (what to do after mbike hits an object/wall with a certain speed):
if (noclip && ob->x > 2*TILEGLOBAL && ob->y > 2*TILEGLOBAL &&
ob->x < (((long)(mapwidth-1))<<TILESHIFT)
&& ob->y < (((long)(mapheight-1))<<TILESHIFT) )
return; // walk through walls
+ 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);
* WL_DRAW.C
- in DrawPlayerWeapon (draws sprite appropriate to the side you're turning as the weapon in player's hands)
#ifndef SPEAR
if (gamestate.victoryflag)
{
if (player->state == &s_deathcam && (TimeCount&32) )
SimpleScaleShape(viewwidth/2,SPR_DEATHCAM,viewheight+1);
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);
}
Voila! You should get a nice motorbike. Any questions? Mail [email]Kuki[/email]. Thanks to him for such a nice tutorial!
Code Editing Tutorials
Adding a motorbike.
You want to add a motorbike run to you game, like in Project Weltuntergang? Here's how to do it, by Kuki:
*WL_DEF.H
-add this to the gamestate structure:
boolean mbike; // is the player riding on the mbike
int motospeed; // what's the bike's speed
boolean left; // are you turning left
boolean right; // are you turning right
*WL_GAME.C
- in SetupGameLevel add: (it sets mbike to true, left & right to false and motospeed to 0 on certain level(s))
if (!loadedgame)
{
gamestate.TimeCount=
.
.
.
gamestate.treasurecount=0;
+if (gamestate.mapon==0 && gamestate.episode==0) // first level, first episode
+{
+gamestate.mbike=true;
+gamestate.motospeed=0;
+gamestate.left=false;
+gamestate.right=false;
+}
+else
+gamestate.mbike=false;
}
*WL_AGENT.C
- in T_Player add: (no use (doors, elevators, secrets), fire or weapon change on a mbike)
+if (gamestate.mbike!=true) {
CheckWeaponChange();
if (buttonstate[bt_use]...
.
.
.
Cmd_Fire ();
+ }
- in ControlMovement add: (the most improtant part - driving the bike)
//
// 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;
- in TryMove: (kills an enemy when he's hit with big speed)
for (y=yl;y<=yh;y++)
for (x=xl;x<=xh;x++)
{
check = actorat[x][y];
if (check > objlist
&& (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;
- in DrawWeapon (status bar weapon pic)
void DrawWeapon (void)
{
if (gamestate.mbike!=true)
StatusDrawPic (32,8,KNIFEPIC+gamestate.weapon);
else
StatusDrawPic (32,8,MBIKEPIC); // use your own picture
}
- in ClipMove (what to do after mbike hits an object/wall with a certain speed):
if (noclip && ob->x > 2*TILEGLOBAL && ob->y > 2*TILEGLOBAL &&
ob->x < (((long)(mapwidth-1))<<TILESHIFT)
&& ob->y < (((long)(mapheight-1))<<TILESHIFT) )
return; // walk through walls
+ 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);
* WL_DRAW.C
- in DrawPlayerWeapon (draws sprite appropriate to the side you're turning as the weapon in player's hands)
#ifndef SPEAR
if (gamestate.victoryflag)
{
if (player->state == &s_deathcam && (TimeCount&32) )
SimpleScaleShape(viewwidth/2,SPR_DEATHCAM,viewheight+1);
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);
}
Voila! You should get a nice motorbike. Any questions? Mail [email]Kuki[/email]. Thanks to him for such a nice tutorial!