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

📄 p_weapon.pas

📁 delphi编的不错的贪吃蛇
💻 PAS
📖 第 1 页 / 共 4 页
字号:
procedure Weapon_Machinegun (edict_t *ent);
const
  pause_frames : array [0..2] of integer = (23, 45, 0);
  fire_frames  : array [0..2] of integer = (4, 5, 0);
begin
  Weapon_Generic (ent, 3, 5, 45, 49, pause_frames, fire_frames, Machinegun_Fire);
end;//procedure (GAME=CTF)

// (GAME=CTF)
procedure Chaingun_Fire (edict_t *ent);
var
  i,
  shots,
  damage              : integer;
  start,
  forward_, right, up,
  offset              : vec3_t;
  r, u                : float;
	int			kick = 2;
begin
  if (deathmatch.value)
  then damage := 6
  else damage := 8;

  if (ent.client.ps.gunframe = 5) then
    gi.sound(ent, CHAN_AUTO, gi.soundindex('weapons/chngnu1a.wav'), 1, ATTN_IDLE, 0);

  if ((ent.client.ps.gunframe = 14) AND !(ent.client.buttons & BUTTON_ATTACK))
  then begin
    ent.client.ps.gunframe := 32;
    ent.client.weapon_sound := 0;
    Exit;
  end
  else
    if ( (ent.client.ps.gunframe = 21) AND ((ent.client.buttons AND BUTTON_ATTACK) <> 0 ) AND
         (ent.client.pers.inventory[ent.client.ammo_index]) )
    then ent.client.ps.gunframe := 15
    else ent.client.ps.gunframe++;

  if (ent.client.ps.gunframe = 22) then
  begin begin
    ent.client.weapon_sound := 0;
    gi.sound(ent, CHAN_AUTO, gi.soundindex('weapons/chngnd1a.wav'), 1, ATTN_IDLE, 0);
  end
  else
    ent.client.weapon_sound := gi.soundindex('weapons/chngnl1a.wav');

  ent.client.anim_priority := ANIM_ATTACK;
  if (ent.client.ps.pmove.pm_flags & PMF_DUCKED)
  then begin
    ent.s.frame := FRAME_crattak1 - (ent.client.ps.gunframe & 1);
    ent.client.anim_end := FRAME_crattak9;
  end
  else begin
    ent.s.frame := FRAME_attack1 - (ent.client.ps.gunframe & 1);
    ent.client.anim_end := FRAME_attack8;
  end;

  if (ent.client.ps.gunframe <= 9)
  then shots := 1
  else
    if (ent.client.ps.gunframe <= 14)
    then begin
      if (ent.client.buttons & BUTTON_ATTACK)
      then shots := 2
      else shots := 1;
    end
    else
      shots := 3;

  if (ent.client.pers.inventory[ent.client.ammo_index] < shots) then
    shots := ent.client.pers.inventory[ent.client.ammo_index];

  if (!shots) then
  begin
    if (level.time >= ent.pain_debounce_time) then
    begin
      gi.sound(ent, CHAN_VOICE, gi.soundindex('weapons/noammo.wav'), 1, ATTN_NORM, 0);
      ent.pain_debounce_time := level.time + 1;
    end;
    NoAmmoWeaponChange (ent);
    return;
  end;

  if (is_quad) then
  begin
    damage := damage *4;
    kick := kick *4;
  end;

  for i:=0 to 2 do
  begin
    ent.client.kick_origin[i] := crandom() * 0.35;
    ent.client.kick_angles[i] := crandom() * 0.7;
  end;

  for i:=0 to shots-1 do
  begin
    // get start / end positions
    AngleVectors (ent.client.v_angle, forward_, right, up);
    r := 7 + crandom()*4;
    u := crandom()*4;
    VectorSet(offset, 0, r, u + ent.viewheight-8);
    P_ProjectSource (ent.client, ent.s.origin, offset, forward_, right, start);

    fire_bullet (ent, start, forward_, damage, kick, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MOD_CHAINGUN);
  end;

  // send muzzle flash
  gi.WriteByte (svc_muzzleflash);
  gi.WriteShort (ent-g_edicts);
  gi.WriteByte ((MZ_CHAINGUN1 + shots - 1) OR is_silenced);
  gi.multicast (ent.s.origin, MULTICAST_PVS);

  PlayerNoise(ent, start, PNOISE_WEAPON);

//  if (! ( (int)dmflags.value & DF_INFINITE_AMMO ) ) then
  if ( (Trunc(dmflags.value) AND DF_INFINITE_AMMO) = 0 ) then
    ent.client.pers.inventory[ent.client.ammo_index] := ent.client.pers.inventory[ent.client.ammo_index] -shots;
end;//procedure (GAME=CTF)

// (GAME=CTF)
procedure Weapon_Chaingun (edict_t *ent);
const
  pause_frames : array [0..4] of integer = (38, 43, 51, 61, 0);
  fire_frames  : array [0..17] of integer = (5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 0};
begin
  Weapon_Generic (ent, 4, 31, 61, 64, pause_frames, fire_frames, Chaingun_Fire);
end;//procedure (GAME=CTF)


{*
======================================================================

SHOTGUN / SUPERSHOTGUN

======================================================================
*}
// (GAME=CTF)
procedure weapon_shotgun_fire (edict_t *ent);
var
  start,
  forward, right,
  offset         : vec3_t;
	int			damage = 4;
	int			kick = 8;
begin
  if (ent.client.ps.gunframe = 9) then
  begin
    ent.client.ps.gunframe++;
    Exit;
  end;

  AngleVectors (ent.client.v_angle, forward_, right, NULL);

  VectorScale (forward_, -2, ent.client.kick_origin);
  ent.client.kick_angles[0] := -2;

  VectorSet(offset, 0, 8,  ent.viewheight-8);
  P_ProjectSource (ent.client, ent.s.origin, offset, forward_, right, start);

  if (is_quad) then
  begin
    damage := damage *4;
    kick := kick *4;
  end;

  if (deathmatch.value)
  then fire_shotgun (ent, start, forward_, damage, kick, 500, 500, DEFAULT_DEATHMATCH_SHOTGUN_COUNT, MOD_SHOTGUN)
  else fire_shotgun (ent, start, forward_, damage, kick, 500, 500, DEFAULT_SHOTGUN_COUNT, MOD_SHOTGUN);

  // send muzzle flash
  gi.WriteByte (svc_muzzleflash);
  gi.WriteShort (ent-g_edicts);
  gi.WriteByte (MZ_SHOTGUN or is_silenced);
  gi.multicast (ent.s.origin, MULTICAST_PVS);

  ent.client.ps.gunframe++;
  PlayerNoise(ent, start, PNOISE_WEAPON);

//  if (! ( (int)dmflags.value & DF_INFINITE_AMMO ) ) then
  if ( (Trunc(dmflags.value) AND DF_INFINITE_AMMO) = 0 ) then
    ent.client.pers.inventory[ent.client.ammo_index]--;
end;//procedure (GAME=CTF)

// (GAME=CTF)
procedure Weapon_Shotgun (edict_t *ent);
const
  pause_frames : array [0..3] of integer = (22, 28, 34, 0);
  fire_frames  : array [0..2] of integer = (8, 9, 0);
begin
  Weapon_Generic (ent, 7, 18, 36, 39, pause_frames, fire_frames, weapon_shotgun_fire);
end;//procedure (GAME=CTF)

// (GAME=CTF)
procedure weapon_supershotgun_fire (edict_t *ent);
var
  start,
  forward, right,
  offset,
  v              : vec3_t;
	int			damage = 6;
	int			kick = 12;
begin
  AngleVectors (ent.client.v_angle, forward_, right, NULL);

  VectorScale (forward_, -2, ent.client.kick_origin);
  ent.client.kick_angles[0] := -2;

  VectorSet(offset, 0, 8,  ent.viewheight-8);
  P_ProjectSource (ent.client, ent.s.origin, offset, forward_, right, start);

  if (is_quad) then
  begin
    damage := damage *4;
    kick := kick *4;
  end;

  v[PITCH] := ent.client.v_angle[PITCH];
  v[YAW]   := ent.client.v_angle[YAW] - 5;
  v[ROLL]  := ent.client.v_angle[ROLL];
  AngleVectors (v, forward_, NULL, NULL);
  fire_shotgun (ent, start, forward_, damage, kick, DEFAULT_SHOTGUN_HSPREAD, DEFAULT_SHOTGUN_VSPREAD, DEFAULT_SSHOTGUN_COUNT/2, MOD_SSHOTGUN);
  v[YAW]   := ent.client.v_angle[YAW] + 5;
  AngleVectors (v, forward_, NULL, NULL);
  fire_shotgun (ent, start, forward_, damage, kick, DEFAULT_SHOTGUN_HSPREAD, DEFAULT_SHOTGUN_VSPREAD, DEFAULT_SSHOTGUN_COUNT/2, MOD_SSHOTGUN);

  // send muzzle flash
  gi.WriteByte (svc_muzzleflash);
  gi.WriteShort (ent-g_edicts);
  gi.WriteByte (MZ_SSHOTGUN or is_silenced);
  gi.multicast (ent.s.origin, MULTICAST_PVS);

  ent.client.ps.gunframe++;
  PlayerNoise(ent, start, PNOISE_WEAPON);

//  if (! ( (int)dmflags.value & DF_INFINITE_AMMO ) )
  if ( (TRunc(dmflags.value) AND DF_INFINITE_AMMO) = 0 ) then
    ent.client.pers.inventory[ent.client.ammo_index] := ent.client.pers.inventory[ent.client.ammo_index] -2;
end;//procedure (GAME=CTF)

// (GAME=CTF)
procedure Weapon_SuperShotgun (edict_t *ent)
const
  pause_frames : array [0..3] of integer = (29, 42, 57, 0);
  fire_frames  : array [0..1] of integer = (7, 0);
begin
  Weapon_Generic (ent, 6, 17, 57, 61, pause_frames, fire_frames, weapon_supershotgun_fire);
end;//procedure (GAME=CTF)



{*
======================================================================

RAILGUN

======================================================================
*}
// (GAME=CTF)
procedure weapon_railgun_fire (edict_t *ent);
var
  start,
  forward_, right,
  offset          : vec3_t;
  damage,
  kick            : integer;
begin
  if (deathmatch.value)
  then begin
  // normal damage is too extreme in dm
    damage := 100;
    kick := 200;
  end
  else begin
    damage := 150;
    kick := 250;
  end;

  if (is_quad) then
  begin
    damage := damage *4;
    kick := kick *4;
  end;

  AngleVectors (ent.client.v_angle, forward_, right, NULL);

  VectorScale (forward_, -3, ent.client.kick_origin);
  ent.client.kick_angles[0] := -3;

  VectorSet(offset, 0, 7,  ent.viewheight-8);
  P_ProjectSource (ent.client, ent.s.origin, offset, forward_, right, start);
  fire_rail (ent, start, forward_, damage, kick);

  // send muzzle flash
  gi.WriteByte (svc_muzzleflash);
  gi.WriteShort (ent-g_edicts);
  gi.WriteByte (MZ_RAILGUN or is_silenced);
  gi.multicast (ent.s.origin, MULTICAST_PVS);

  ent.client.ps.gunframe++;
  PlayerNoise(ent, start, PNOISE_WEAPON);

//  if (! ( (int)dmflags.value & DF_INFINITE_AMMO ) )
  if ( (Trunc(dmflags.value) AND DF_INFINITE_AMMO) = 0 )
    ent.client.pers.inventory[ent.client.ammo_index]--;
end;//procedure (GAME=CTF)

// (GAME=CTF)
procedure Weapon_Railgun (edict_t *ent);
const
  pause_frames : array [0..1] of integer = (56, 0);
  fire_frames  : array [0..1] of integer = (4, 0);
begin
  Weapon_Generic (ent, 3, 18, 56, 61, pause_frames, fire_frames, weapon_railgun_fire);
end;//procedure (GAME=CTF)


{*
======================================================================

BFG10K

======================================================================
*}
// (GAME=CTF)
procedure weapon_bfg_fire (edict_t *ent);
var
  offset, start,
  forward_, right  : vec3_t;
  damage           : integer;
	float	damage_radius = 1000;
begin
  if (deathmatch.value)
  then damage := 200
  else damage := 500;

  if (ent.client.ps.gunframe = 9) then
  begin
    // send muzzle flash
    gi.WriteByte (svc_muzzleflash);
    gi.WriteShort (ent-g_edicts);
    gi.WriteByte (MZ_BFG or is_silenced);
    gi.multicast (ent.s.origin, MULTICAST_PVS);

    ent.client.ps.gunframe++;

    PlayerNoise(ent, ent.s.origin, PNOISE_WEAPON);
    Exit;
  end;

  // cells can go down during windup (from power armor hits), so
  // check again and abort firing if we don't have enough now
  if (ent.client.pers.inventory[ent.client.ammo_index] < 50) then
  begin
    ent.client.ps.gunframe++;
    Exut;
  end;

  if (is_quad) then
    damage := damage *4;

  AngleVectors (ent.client.v_angle, forward_, right, NULL);

  VectorScale (forward_, -2, ent.client.kick_origin);

  // make a big pitch kick with an inverse fall
  ent.client.v_dmg_pitch := -40;
  ent.client.v_dmg_roll := crandom()*8;
  ent.client.v_dmg_time := level.time + DAMAGE_TIME;

  VectorSet(offset, 8, 8, ent.viewheight-8);
  P_ProjectSource (ent.client, ent.s.origin, offset, forward_, right, start);
  fire_bfg (ent, start, forward_, damage, 400, damage_radius);

  ent.client.ps.gunframe++;

  PlayerNoise(ent, start, PNOISE_WEAPON);

//  if (! ( (int)dmflags.value & DF_INFINITE_AMMO ) )
  if ( (Trunc(dmflags.value) AND DF_INFINITE_AMMO) = 0 )
    ent.client.pers.inventory[ent.client.ammo_index] := ent.client.pers.inventory[ent.client.ammo_index] -50;
end;//procedure (GAME=CTF)

// (GAME=CTF)
procedure Weapon_BFG (edict_t *ent);
const
  pause_frames : array [0..4] of integer = (39, 45, 50, 55, 0);
  fire_frames  : array [0..2] of integer = (9, 17, 0);
begin
  Weapon_Generic (ent, 8, 32, 55, 58, pause_frames, fire_frames, weapon_bfg_fire);
end;//procedure (GAME=CTF)


//======================================================================

// End of file


My current problems:
--------------------
1) all local variable

2) C2PAS: "if" & "for"

   C-code:
     if (pause_frames) then
      for (n = 0; pause_frames[n]; n++)
   PAS-code:
     if Assigned(pause_frames) then
     begin
       n := 0;
       while pause_frames[n] <> 0 do
       begin
         ...
         Inc(n);
       end;
     end;

3) OK!

⌨️ 快捷键说明

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