- New rope
authorunc0rr
Sat, 31 Dec 2005 13:45:09 +0000
changeset 35 9367f246fb5f
parent 34 fbe30de53d1d
child 36 a803a00a3272
- New rope - Increased speed in windowed mode - Surfaces with alpha channel blit poperly in windowed mode - +1 land template
hedgewars/Data/Graphics/RopeNode.png
hedgewars/SDLh.pas
hedgewars/uConsts.pas
hedgewars/uGears.pas
hedgewars/uLand.pas
hedgewars/uLandObjects.pas
hedgewars/uLandTemplates.pas
hedgewars/uStore.pas
Binary file hedgewars/Data/Graphics/RopeNode.png has changed
--- a/hedgewars/SDLh.pas	Wed Dec 28 23:34:22 2005 +0000
+++ b/hedgewars/SDLh.pas	Sat Dec 31 13:45:09 2005 +0000
@@ -223,6 +223,7 @@
 function  SDL_MapRGB(format: PSDL_PixelFormat; r, g, b: Byte): Integer; cdecl; external SDLLibName;
 
 function  SDL_DisplayFormat(Surface: PSDL_Surface): PSDL_Surface; cdecl; external SDLLibName;
+function  SDL_DisplayFormatAlpha(Surface: PSDL_Surface): PSDL_Surface; cdecl; external SDLLibName;
 
 function  SDL_RWFromFile(filename, mode: PChar): PSDL_RWops; cdecl; external SDLLibName;
 function  SDL_SaveBMP_RW(surface: PSDL_Surface; dst: PSDL_RWops; freedst: Integer): Integer; cdecl; external SDLLibName;
--- a/hedgewars/uConsts.pas	Wed Dec 28 23:34:22 2005 +0000
+++ b/hedgewars/uConsts.pas	Sat Dec 31 13:45:09 2005 +0000
@@ -36,7 +36,7 @@
 uses SDLh;
 {$INCLUDE options.inc}
 type TStuff     = (sHorizont, sSky, sConsoleBG, sPowerBar, sQuestion, sWindBar,
-                   sWindL, sWindR);
+                   sWindL, sWindR, sRopeNode);
      TGameState = (gsLandGen, gsStart, gsGame, gsConsole, gsExit);
      TGameType  = (gmtLocal, gmtDemo, gmtNet);
      TPathType  = (ptData, ptGraphics, ptThemes, ptThemeCurrent, ptTeams, ptMaps,
@@ -197,7 +197,8 @@
                                      (FileName: 'thinking.png'; Path: ptGraphics     ),    // sQuestion
                                      (FileName:  'WindBar.png'; Path: ptGraphics     ),    // sWindBar
                                      (FileName:    'WindL.png'; Path: ptGraphics     ),    // sWindL
-                                     (FileName:    'WindR.png'; Path: ptGraphics     )     // sWindR
+                                     (FileName:    'WindR.png'; Path: ptGraphics     ),    // sWindR
+                                     (FileName: 'RopeNode.png'; Path: ptGraphics     )     // sRopeNode
                                      );
       StuffPoz: array[TStuff] of TSDL_Rect = (
                                       (x:   0; y:   0; w: 512; h: 256), // sHorizont
@@ -207,31 +208,33 @@
                                       (x: 256; y: 512; w:  32; h:  32), // sQuestion
                                       (x: 256; y: 800; w: 151; h:  17), // sWindBar
                                       (x: 256; y: 817; w:  80; h:  13), // sWindL
-                                      (x: 336; y: 817; w:  80; h:  13)  // sWindR
+                                      (x: 336; y: 817; w:  80; h:  13), // sWindR
+                                      (x: 256; y: 544; w:   6; h:   6)  // sRopeNode
                                       );
       SpritesData: array[TSprite] of record
-                                         FileName: String[31];
-                                         Path    : TPathType;
-                                         Surface : PSDL_Surface;
-                                         Width, Height: integer;
-                                         end = (
-                                         (FileName: 'BlueWater.png'; Path: ptGraphics; Width: 256; Height: 48),// sprWater
-                                         (FileName:    'Clouds.png'; Path: ptGraphics; Width: 256; Height:128),// sprCloud
-                                         (FileName:      'Bomb.png'; Path: ptGraphics; Width:  16; Height: 16),// sprBomb
-                                         (FileName: 'BigDigits.png'; Path: ptGraphics; Width:  32; Height: 32),// sprBigDigit
-                                         (FileName:     'Frame.png'; Path: ptGraphics; Width:   4; Height: 32),// sprFrame
-                                         (FileName:       'Lag.png'; Path: ptGraphics; Width:  64; Height: 64),// sprLag
-                                         (FileName:     'Arrow.png'; Path: ptGraphics; Width:  16; Height: 16),// sprCursor
-                                         (FileName:   'Grenade.png'; Path: ptGraphics; Width:  32; Height: 32),// sprGrenade
-                                         (FileName:   'Targetp.png'; Path: ptGraphics; Width:  32; Height: 32),// sprTargetP
-                                         (FileName:       'UFO.png'; Path: ptGraphics; Width:  32; Height: 32),// sprUFO
-                                         (FileName:'SmokeTrace.png'; Path: ptGraphics; Width:  32; Height: 32),// sprSmokeTrace
-                                         (FileName:  'RopeHook.png'; Path: ptGraphics; Width:  32; Height: 32),// sprRopeHook
-                                         (FileName:    'Expl50.png'; Path: ptGraphics; Width:  64; Height: 64),// sprExplosion50
-                                         (FileName:   'MineOff.png'; Path: ptGraphics; Width:  16; Height: 16),// sprMineOff
-                                         (FileName:    'MineOn.png'; Path: ptGraphics; Width:  16; Height: 16),// sprMineOn
-                                         (FileName:      'Case.png'; Path: ptGraphics; Width:  32; Height: 32) // sprCase
-                                         );
+                     FileName: String[31];
+                     Path    : TPathType;
+                     Surface : PSDL_Surface;
+                     Width, Height: integer;
+                     hasAlpha: boolean;
+                     end = (
+                     (FileName: 'BlueWater.png'; Path: ptGraphics; Width: 256; Height: 48; hasAlpha: false),// sprWater
+                     (FileName:    'Clouds.png'; Path: ptGraphics; Width: 256; Height:128; hasAlpha: false),// sprCloud
+                     (FileName:      'Bomb.png'; Path: ptGraphics; Width:  16; Height: 16; hasAlpha: false),// sprBomb
+                     (FileName: 'BigDigits.png'; Path: ptGraphics; Width:  32; Height: 32; hasAlpha:  true),// sprBigDigit
+                     (FileName:     'Frame.png'; Path: ptGraphics; Width:   4; Height: 32; hasAlpha:  true),// sprFrame
+                     (FileName:       'Lag.png'; Path: ptGraphics; Width:  64; Height: 64; hasAlpha: false),// sprLag
+                     (FileName:     'Arrow.png'; Path: ptGraphics; Width:  16; Height: 16; hasAlpha: false),// sprCursor
+                     (FileName:   'Grenade.png'; Path: ptGraphics; Width:  32; Height: 32; hasAlpha: false),// sprGrenade
+                     (FileName:   'Targetp.png'; Path: ptGraphics; Width:  32; Height: 32; hasAlpha: false),// sprTargetP
+                     (FileName:       'UFO.png'; Path: ptGraphics; Width:  32; Height: 32; hasAlpha: false),// sprUFO
+                     (FileName:'SmokeTrace.png'; Path: ptGraphics; Width:  32; Height: 32; hasAlpha:  true),// sprSmokeTrace
+                     (FileName:  'RopeHook.png'; Path: ptGraphics; Width:  32; Height: 32; hasAlpha: false),// sprRopeHook
+                     (FileName:    'Expl50.png'; Path: ptGraphics; Width:  64; Height: 64; hasAlpha: false),// sprExplosion50
+                     (FileName:   'MineOff.png'; Path: ptGraphics; Width:  16; Height: 16; hasAlpha: false),// sprMineOff
+                     (FileName:    'MineOn.png'; Path: ptGraphics; Width:  16; Height: 16; hasAlpha: false),// sprMineOn
+                     (FileName:      'Case.png'; Path: ptGraphics; Width:  32; Height: 32; hasAlpha: false) // sprCase
+                     );
       Soundz: array[TSound] of record
                                        FileName: String[31];
                                        Path    : TPathType;
--- a/hedgewars/uGears.pas	Wed Dec 28 23:34:22 2005 +0000
+++ b/hedgewars/uGears.pas	Sat Dec 31 13:45:09 2005 +0000
@@ -362,11 +362,12 @@
 procedure DrawGears(Surface: PSDL_Surface);
 var Gear: PGear;
     i: Longword;
+    roplen: real;
 
     procedure DrawRopeLine(X1, Y1, X2, Y2: integer);
-    var i: integer;
-        t, k: real;
-        r: TSDL_Rect;
+    const nodlen = 5;
+    var i, x, y: integer;
+        t, k, ladd: real;
     begin
     if abs(X1 - X2) > abs(Y1 - Y2) then
        begin
@@ -380,22 +381,23 @@
           Y2:= i
           end;
        k:= (Y2 - Y1) / (X2 - X1);
+       ladd:= sqrt(1 + sqr(k));
        if X1 < 0 then
           begin
           t:= Y1 - 2 - k * X1;
           X1:= 0
           end else t:= Y1 - 2;
        if X2 > cScreenWidth then X2:= cScreenWidth;
-       r.x:= X1;
-       while r.x <= X2 do
-             begin
-             r.y:= round(t);
-             r.w:= 4;
-             r.h:= 4;
-             SDL_FillRect(Surface, @r, cWhiteColor);
-             t:= t + k*3;
-             inc(r.x, 3)
-             end;
+       for x:= X1 to X2 do
+           begin
+           roplen:= roplen + ladd;
+           if roplen > nodlen then
+              begin
+              DrawGear(sRopeNode, x - 2, round(t) - 2, Surface);
+              roplen:= roplen - nodlen;
+              end;
+           t:= t + k;
+           end;
        end else
        begin
        if Y1 > Y2 then
@@ -408,22 +410,23 @@
           Y2:= i
           end;
        k:= (X2 - X1) / (Y2 - Y1);
+       ladd:= sqrt(1 + sqr(k));
        if Y1 < 0 then
           begin
           t:= X1 - 2 - k * Y1;
           Y1:= 0
           end else t:= X1 - 2;
        if Y2 > cScreenHeight then Y2:= cScreenHeight;
-       r.y:= Y1;
-       while r.y <= Y2 do
-             begin
-             r.x:= round(t);
-             r.w:= 4;
-             r.h:= 4;
-             SDL_FillRect(Surface, @r, cWhiteColor);
-             t:= t + k*3;
-             inc(r.y, 3)
-             end;
+       for y:= Y1 to Y2 do
+           begin
+           roplen:= roplen + ladd;
+           if roplen > nodlen then
+              begin
+              DrawGear(sRopeNode, round(t) - 2, y - 2, Surface);
+              roplen:= roplen - nodlen;
+              end;
+           t:= t + k;
+           end;
        end
     end;
 
@@ -443,8 +446,7 @@
              gtUFO: DrawSprite(sprUFO, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, (GameTicks shr 7) mod 4, Surface);
       gtSmokeTrace: if Gear.State < 8 then DrawSprite(sprSmokeTrace, Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.State, Surface);
             gtRope: begin
-                    DrawRopeLine(Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy,
-                                 Round(PHedgehog(Gear.Hedgehog).Gear.X) + WorldDx, Round(PHedgehog(Gear.Hedgehog).Gear.Y) + WorldDy);
+                    roplen:= 0;
                     if RopePoints.Count > 0 then
                        begin
                        i:= 0;
@@ -456,9 +458,15 @@
                              end;
                        DrawRopeLine(Round(RopePoints.ar[i].X) + WorldDx, Round(RopePoints.ar[i].Y) + WorldDy,
                                     Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy);
+                       DrawRopeLine(Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy,
+                                    Round(PHedgehog(Gear.Hedgehog).Gear.X) + WorldDx, Round(PHedgehog(Gear.Hedgehog).Gear.Y) + WorldDy);
                        DrawSprite(sprRopeHook, Round(RopePoints.ar[0].X) + WorldDx - 16, Round(RopePoints.ar[0].Y) + WorldDy - 16, RopePoints.HookAngle, Surface);
                        end else
+                       begin
+                       DrawRopeLine(Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy,
+                                    Round(PHedgehog(Gear.Hedgehog).Gear.X) + WorldDx, Round(PHedgehog(Gear.Hedgehog).Gear.Y) + WorldDy);
                        DrawSprite(sprRopeHook, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, DxDy2Angle32(Gear.dY, Gear.dX), Surface);
+                       end;
                     end;
        gtExplosion: DrawSprite(sprExplosion50, Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.State, Surface);
             gtMine: if ((Gear.State and gstAttacking) = 0)or((Gear.Timer and $3FF) < 420)
--- a/hedgewars/uLand.pas	Wed Dec 28 23:34:22 2005 +0000
+++ b/hedgewars/uLand.pas	Sat Dec 31 13:45:09 2005 +0000
@@ -257,7 +257,7 @@
 var tmpsurf: PSDL_Surface;
     r: TSDL_Rect;
 begin
-tmpsurf:= LoadImage(Pathz[ptThemeCurrent] + 'LandTex.png');
+tmpsurf:= LoadImage(Pathz[ptThemeCurrent] + 'LandTex.png', false);
 r.y:= 0;
 while r.y < 1024 do
       begin
@@ -283,7 +283,7 @@
     r, rr: TSDL_Rect;
     x, yd, yu: integer;
 begin
-tmpsurf:= LoadImage(Pathz[ptThemeCurrent] + 'Border.png');
+tmpsurf:= LoadImage(Pathz[ptThemeCurrent] + 'Border.png', false);
 for x:= 0 to 2047 do
     begin
     yd:= 1023;
@@ -483,13 +483,13 @@
 TryDo(p <> nil, 'No teams on map!', true);
 with PixelFormat^ do
      LandSurface:= SDL_CreateRGBSurface(SDL_HWSURFACE, 2048, 1024, BitsPerPixel, RMask, GMask, BMask, 0);
-tmpsurf:= LoadImage(Pathz[ptForts] + p.FortName + 'L.png');
+tmpsurf:= LoadImage(Pathz[ptForts] + p.FortName + 'L.png', false);
 BlitImageAndGenerateCollisionInfo(0, 0, tmpsurf, LandSurface);
 SDL_FreeSurface(tmpsurf);
 LoadFortPoints(p.FortName, false, TeamSize(p));
 p:= p.Next;
 TryDo(p <> nil, 'Only one team on map!', true);
-tmpsurf:= LoadImage(Pathz[ptForts] + p.FortName + 'R.png');
+tmpsurf:= LoadImage(Pathz[ptForts] + p.FortName + 'R.png', false);
 BlitImageAndGenerateCollisionInfo(1024, 0, tmpsurf, LandSurface);
 SDL_FreeSurface(tmpsurf);
 LoadFortPoints(p.FortName, true, TeamSize(p));
--- a/hedgewars/uLandObjects.pas	Wed Dec 28 23:34:22 2005 +0000
+++ b/hedgewars/uLandObjects.pas	Sat Dec 31 13:45:09 2005 +0000
@@ -152,7 +152,7 @@
 if x1 > 0 then
    begin
    Result:= true;
-   tmpsurf:= LoadImage(Pathz[ptGraphics] + 'Girder.png');
+   tmpsurf:= LoadImage(Pathz[ptGraphics] + 'Girder.png', false);
    rr.x:= x1;
    rr.y:= y;
    while rr.x + 100 < x2 do
@@ -271,7 +271,7 @@
     Readln(f, s); // filename
     with ThemeObjects[i] do
          begin
-         Surf:= LoadImage(Pathz[ptThemeCurrent] + s + '.png');
+         Surf:= LoadImage(Pathz[ptThemeCurrent] + s + '.png', false);
          Read(f, Width, Height);
          with inland do Read(f, x, y, w, h);
          Read(f, rectcnt);
--- a/hedgewars/uLandTemplates.pas	Wed Dec 28 23:34:22 2005 +0000
+++ b/hedgewars/uLandTemplates.pas	Sat Dec 31 13:45:09 2005 +0000
@@ -189,7 +189,36 @@
        (x: 1023; y: 1023)
       );
 
-const EdgeTemplates: array[0..5] of TEdgeTemplate =
+const Template6Points: array[0..20] of TPoint =
+      (
+       (x:  318; y: 1494),
+       (x:  270; y: 1023),
+       (x:  252; y:  921),
+       (x:  480; y:  888),
+       (x:  492; y:  753),
+       (x:  654; y:  756),
+       (x:  687; y:  630),
+       (x:  906; y:  627),
+       (x:  987; y:  813),
+       (x: 1125; y:  825),
+       (x: 1134; y:  645),
+       (x: 1236; y:  558),
+       (x: 1260; y:  438),
+       (x: 1467; y:  462),
+       (x: 1536; y:  348),
+       (x: 1680; y:  402),
+       (x: 1713; y:  594),
+       (x: 1593; y:  693),
+       (x: 1707; y:  774),
+       (x: 1728; y:  894),
+       (x: 1788; y: 1491)
+      );
+      Template6FPoints: array[0..0] of TPoint =
+      (
+       (x: 1023; y: 1023)
+      );
+
+const EdgeTemplates: array[0..6] of TEdgeTemplate =
       (
        (BasePoints: @Template0Points;
         BasePointsCount: Succ(High(Template0Points));
@@ -250,7 +279,17 @@
         FillPoints: @Template5FPoints;
         FillPointsCount: Succ(High(Template5FPoints));
         canMirror: true; canFlip: false;
-       )
+       ),
+      (BasePoints: @Template6Points;
+       BasePointsCount: Succ(High(Template6Points));
+       BezPassCnt: 3;
+       PassMin: 15; PassDelta: 1;
+       WaveAmplMin:    15; WaveAmplDelta: 10;
+       WaveFreqMin: 0.010; WaveFreqDelta: 0.0015;
+       FillPoints: @Template6FPoints;
+       FillPointsCount: Succ(High(Template6FPoints));
+       canMirror: true; canFlip: false;
+      )
        
       );
 
--- a/hedgewars/uStore.pas	Wed Dec 28 23:34:22 2005 +0000
+++ b/hedgewars/uStore.pas	Sat Dec 31 13:45:09 2005 +0000
@@ -56,7 +56,7 @@
 procedure RenderHealth(var Hedgehog: THedgehog);
 function  RenderString(var s: shortstring; Color, Pos: integer): TSDL_Rect;
 procedure AddProgress;
-function  LoadImage(filename: string): PSDL_Surface;
+function  LoadImage(filename: string; hasAlpha: boolean): PSDL_Surface;
 
 var PixelFormat: PSDL_PixelFormat;
  SDLPrimSurface: PSDL_Surface;
@@ -189,9 +189,15 @@
 end;
 
 procedure StoreInit;
+var r: TSDL_Rect;
 begin
 StoreSurface  := SDL_CreateRGBSurface(SDL_HWSURFACE, 576, 1024, cBits, PixelFormat.RMask, PixelFormat.GMask, PixelFormat.BMask, 0);
 TryDo( StoreSurface <> nil, errmsgCreateSurface + ': store' , true);
+r.x:= 0;
+r.y:= 0;
+r.w:= 576;
+r.h:= 1024;
+SDL_FillRect(StoreSurface, @r, 0);
 
 TempSurface   := SDL_CreateRGBSurface(SDL_HWSURFACE, 724, 320, cBits, PixelFormat.RMask, PixelFormat.GMask, PixelFormat.BMask, 0);
 TryDo(  TempSurface <> nil, errmsgCreateSurface + ': temp'  , true);
@@ -205,7 +211,7 @@
 var tmpsurf: PSDL_Surface;
     rr: TSDL_Rect;
 begin
-  tmpsurf:= LoadImage(Filename);
+  tmpsurf:= LoadImage(Filename, false);
   rr.x:= X;
   rr.y:= Y;
   SDL_UpperBlit(tmpsurf, nil, Surface, @rr);
@@ -406,8 +412,8 @@
          WriteLnToConsole(msgOK)
          end;
 AddProgress;
-s:= Pathz[ptMapCurrent] + cLandFileName;
-WriteToConsole(msgLoading + s + ' ');         // загружаем текущее поле
+//s:= Pathz[ptMapCurrent] + cLandFileName;
+//WriteToConsole(msgLoading + s + ' ');         
 //tmpsurf:= IMG_Load(PChar(s));
 tmpsurf:= LandSurface;
 TryDo(tmpsurf <> nil, msgFailed, true);
@@ -416,7 +422,7 @@
    LandSurface:= SDL_DisplayFormat(tmpsurf);
    SDL_FreeSurface(tmpsurf);
    end else LandSurface:= tmpsurf;
-TryDo(SDL_SetColorKey(LandSurface, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
+TryDo(SDL_SetColorKey(LandSurface, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true);
 WriteLnToConsole(msgOK);
 
 GetExplosionBorderColor;
@@ -435,16 +441,13 @@
 AddProgress;
 for ii:= Low(TSprite) to High(TSprite) do
     with SpritesData[ii] do
-         begin
-         Surface:= LoadImage(Pathz[Path] + FileName);
-         TryDo(SDL_SetColorKey(Surface, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true)
-         end;
+         Surface:= LoadImage(Pathz[Path] + FileName, hasAlpha);
 
 AddProgress;
-tmpsurf:= LoadImage(Pathz[ptGraphics] + cHHFileName);
+tmpsurf:= LoadImage(Pathz[ptGraphics] + cHHFileName, false);
+TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
 HHSurface:= SDL_DisplayFormat(tmpsurf);
 SDL_FreeSurface(tmpsurf);
-TryDo(SDL_SetColorKey(HHSurface, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
 
 InitHealth;
 
@@ -583,15 +586,17 @@
    end;
 end;
 
-function  LoadImage(filename: string): PSDL_Surface;
+function  LoadImage(filename: string; hasAlpha: boolean): PSDL_Surface;
 var tmpsurf: PSDL_Surface;
 begin
 WriteToConsole(msgLoading + filename + '... ');
 tmpsurf:= IMG_Load(PChar(filename));
 TryDo(tmpsurf <> nil, msgFailed, true);
+TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
 if cFullScreen then
    begin
-   Result:= SDL_DisplayFormat(tmpsurf);
+   if hasAlpha then Result:= SDL_DisplayFormatAlpha(tmpsurf)
+               else Result:= SDL_DisplayFormat(tmpsurf);
    SDL_FreeSurface(tmpsurf);
    end else Result:= tmpsurf;
 WriteLnToConsole(msgOK)