Light trails for bullets
authorPalewolf
Fri, 12 Nov 2010 22:38:05 +0100
changeset 4279 b697a26ed538
parent 4277 d699d23a6e1d
child 4281 e033cf015b2c
child 4282 46c3c5cf89e4
Light trails for bullets
hedgewars/GSHandlers.inc
hedgewars/GearDrawing.inc
hedgewars/VGSHandlers.inc
hedgewars/uConsts.pas
hedgewars/uStore.pas
hedgewars/uVisualGears.pas
--- a/hedgewars/GSHandlers.inc	Fri Nov 12 16:06:06 2010 -0500
+++ b/hedgewars/GSHandlers.inc	Fri Nov 12 22:38:05 2010 +0100
@@ -705,6 +705,7 @@
 var 
     i, x, y: LongWord;
     oX, oY: hwFloat;
+    trail: PVisualGear;
 begin
     AllInactive := false;
     inc(Gear^.Timer);
@@ -751,6 +752,29 @@
             cLaserSighting := false;
         if (Ammoz[Gear^.AmmoType].Ammo.NumPerTurn <= CurrentHedgehog^.MultiShootAttacks) and
            ((GameFlags and gfArtillery) = 0) then cArtillery := false;
+        
+        // Bullet trail
+        trail := AddVisualGear(
+            hwround(CurrentHedgehog^.Gear^.X) + GetLaunchX(CurrentHedgehog^.CurAmmoType, hwSign(CurrentHedgehog^.Gear^.dX), CurrentHedgehog^.Gear^.Angle), 
+            hwround(CurrentHedgehog^.Gear^.Y) + GetLaunchY(CurrentHedgehog^.CurAmmoType, CurrentHedgehog^.Gear^.Angle),
+            vgtLineTrail
+        );
+        if trail <> nil then
+        begin
+            trail^.dX := Gear^.X.QWordValue / _1.QWordValue;
+            trail^.dY := Gear^.Y.QWordValue / _1.QWordValue;
+            
+            // reached edge of land. assume infinite beam. Extend it way out past camera
+            if (hwRound(Gear^.X) and LAND_WIDTH_MASK <> 0) 
+                or (hwRound(Gear^.Y) and LAND_HEIGHT_MASK <> 0) then
+            begin
+                trail^.dX := trail^.dX + (CurrentHedgehog^.Gear^.dX * LAND_WIDTH).QWordValue / _1.QWordValue;
+                trail^.dY := trail^.dY + (CurrentHedgehog^.Gear^.dY * LAND_WIDTH).QWordValue / _1.QWordValue;
+            end;
+            
+            trail^.Timer := 200;
+        end;
+        
         Gear^.doStep := @doStepShotIdle
     end;
 end;
--- a/hedgewars/GearDrawing.inc	Fri Nov 12 16:06:06 2010 -0500
+++ b/hedgewars/GearDrawing.inc	Fri Nov 12 22:38:05 2010 +0100
@@ -126,22 +126,7 @@
 
             //if (abs(lx-tx)>8) or (abs(ly-ty)>8) then
                 begin
-                glDisable(GL_TEXTURE_2D);
-                glEnable(GL_LINE_SMOOTH);
-
-                glLineWidth(1.0);
-
-                Tint($FF, $00, $00, $C0);
-                VertexBuffer[0].X:= hx + WorldDx;
-                VertexBuffer[0].Y:= hy + WorldDy;
-                VertexBuffer[1].X:= tx + WorldDx;
-                VertexBuffer[1].Y:= ty + WorldDy;
-
-                glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
-                glDrawArrays(GL_LINES, 0, Length(VertexBuffer));
-                Tint($FF, $FF, $FF, $FF);
-                glEnable(GL_TEXTURE_2D);
-                glDisable(GL_LINE_SMOOTH);
+                DrawLine(hx, hy, tx, ty, 1.0, $FF, $00, $00, $C0);
                 end;
             end;
         // draw crosshair
--- a/hedgewars/VGSHandlers.inc	Fri Nov 12 16:06:06 2010 -0500
+++ b/hedgewars/VGSHandlers.inc	Fri Nov 12 22:38:05 2010 +0100
@@ -133,6 +133,16 @@
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
+procedure doStepLineTrail(Gear: PVisualGear; Steps: Longword);
+begin
+Steps := Steps;
+if Gear^.Timer <= Steps then
+    DeleteVisualGear(Gear)
+else
+    dec(Gear^.Timer, Steps)
+end;
+
+////////////////////////////////////////////////////////////////////////////////
 procedure doStepEgg(Gear: PVisualGear; Steps: Longword);
 begin
 Gear^.X:= Gear^.X + Gear^.dX * Steps;
--- a/hedgewars/uConsts.pas	Fri Nov 12 16:06:06 2010 -0500
+++ b/hedgewars/uConsts.pas	Fri Nov 12 22:38:05 2010 +0100
@@ -97,7 +97,7 @@
             vgtSteam, vgtAmmo, vgtSmoke, vgtSmokeWhite, vgtHealth, vgtShell,
             vgtDust, vgtSplash, vgtDroplet, vgtSmokeRing, vgtBeeTrace, vgtEgg,
             vgtFeather, vgtHealthTag, vgtSmokeTrace, vgtEvilTrace, vgtExplosion,
-            vgtBigExplosion, vgtChunk, vgtNote);
+            vgtBigExplosion, vgtChunk, vgtNote, vgtLineTrail);
 
     TGearsType = set of TGearType;
 
--- a/hedgewars/uStore.pas	Fri Nov 12 16:06:06 2010 -0500
+++ b/hedgewars/uStore.pas	Fri Nov 12 22:38:05 2010 +0100
@@ -57,6 +57,7 @@
 procedure DrawFromRect(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
 procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
 procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
+procedure DrawLine(X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte); 
 procedure DrawFillRect(r: TSDL_Rect);
 procedure DrawCircle(X, Y, Radius: LongInt; Width: Single; r, g, b, a: Byte); 
 procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean);
@@ -791,6 +792,32 @@
 glPopMatrix
 end;
 
+procedure DrawLine(X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte);
+var VertexBuffer: array [0..3] of TVertex2f;
+begin
+    glDisable(GL_TEXTURE_2D);
+    glEnable(GL_LINE_SMOOTH);
+
+    glPushMatrix;
+    glTranslatef(WorldDx, WorldDy, 0);
+    glLineWidth(Width);
+
+    Tint(r, g, b, a);
+    VertexBuffer[0].X:= X0;
+    VertexBuffer[0].Y:= Y0;
+    VertexBuffer[1].X:= X1;
+    VertexBuffer[1].Y:= Y1;
+
+    glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
+    glDrawArrays(GL_LINES, 0, Length(VertexBuffer));
+    Tint($FF, $FF, $FF, $FF);
+    
+    glPopMatrix;
+    
+    glEnable(GL_TEXTURE_2D);
+    glDisable(GL_LINE_SMOOTH);
+end;
+
 procedure DrawFillRect(r: TSDL_Rect);
 var VertexBuffer: array [0..3] of TVertex2f;
 begin
--- a/hedgewars/uVisualGears.pas	Fri Nov 12 16:06:06 2010 -0500
+++ b/hedgewars/uVisualGears.pas	Fri Nov 12 22:38:05 2010 +0100
@@ -117,7 +117,8 @@
             @doStepExplosion,
             @doStepBigExplosion,
             @doStepChunk,
-            @doStepNote
+            @doStepNote,
+            @doStepLineTrail
         );
 
 function  AddVisualGear(X, Y: LongInt; Kind: TVisualGearType; State: LongWord = 0): PVisualGear;
@@ -406,6 +407,7 @@
         case Gear^.Kind of
             vgtSmokeTrace: if Gear^.State < 8 then DrawSprite(sprSmokeTrace, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.State);
             vgtEvilTrace: if Gear^.State < 8 then DrawSprite(sprEvilTrace, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.State);
+            vgtLineTrail: DrawLine(Gear^.X, Gear^.Y, Gear^.dX, Gear^.dY, 1.0, $FF, min(Gear^.Timer, $C0), min(Gear^.Timer, $80), min(Gear^.Timer, $FF));
         end;
             if (cReducedQuality and rqFancyBoom) = 0 then
                 case Gear^.Kind of