Flakes concept, still need some development
authorunc0rr
Fri, 07 Mar 2008 19:44:00 +0000
changeset 805 4d75759b38bd
parent 804 30f687f380fa
child 806 d397c502a5dd
Flakes concept, still need some development
hedgewars/uConsts.pas
hedgewars/uLandObjects.pas
hedgewars/uVisualGears.pas
share/hedgewars/Data/Themes/nature/CMakeLists.txt
share/hedgewars/Data/Themes/nature/Flake.png
share/hedgewars/Data/Themes/nature/theme.cfg
--- a/hedgewars/uConsts.pas	Fri Mar 07 19:34:26 2008 +0000
+++ b/hedgewars/uConsts.pas	Fri Mar 07 19:44:00 2008 +0000
@@ -41,7 +41,7 @@
                    sprAirplane, sprAmAirplane, sprAmGirder, sprHHTelepMask,
                    sprSwitch, sprParachute, sprTarget, sprRopeNode, sprConsoleBG,
                    sprQuestion, sprPowerBar, sprWindBar,
-                   sprWindL, sprWindR);
+                   sprWindL, sprWindR, sprFlake);
 
      TGearType  = (gtAmmo_Bomb, gtHedgehog, gtAmmo_Grenade, gtHealthTag,
                    gtGrave, gtUFO, gtShotgunShot, gtPickHammer, gtRope,
@@ -223,7 +223,7 @@
 
       PathPrefix: string = './';
       Pathz: array[TPathType] of string      = (
-                                               '',                              // ptNone      
+                                               '',                              // ptNone
                                                '',                              // ptData
                                                'Graphics',                      // ptGraphics
                                                'Themes',                        // ptThemes
@@ -340,7 +340,9 @@
                      (FileName:      'WindL'; Path: ptGraphics; AltPath: ptNone; Texture: nil; Surface: nil;
                       Width:  80; Height: 13; saveSurf: false),// sprWindL
                      (FileName:      'WindR'; Path: ptGraphics; AltPath: ptNone; Texture: nil; Surface: nil;
-                      Width:  80; Height: 13; saveSurf: false) // sprWindR
+                      Width:  80; Height: 13; saveSurf: false),// sprWindR
+                     (FileName:      'Flake'; Path:ptCurrTheme; AltPath: ptNone; Texture: nil; Surface: nil;
+                      Width:  64; Height: 64; saveSurf: false) // sprFlake
                      );
 
       Soundz: array[TSound] of record
--- a/hedgewars/uLandObjects.pas	Fri Mar 07 19:34:26 2008 +0000
+++ b/hedgewars/uLandObjects.pas	Fri Mar 07 19:44:00 2008 +0000
@@ -25,7 +25,7 @@
 procedure BlitImageAndGenerateCollisionInfo(cpX, cpY: Longword; Image, Surface: PSDL_Surface);
 
 implementation
-uses uLand, uStore, uConsts, uMisc, uConsole, uRandom;
+uses uLand, uStore, uConsts, uMisc, uConsole, uRandom, uVisualGears, uFloat;
 const MaxRects = 256;
       MAXOBJECTRECTS = 16;
       MAXTHEMEOBJECTS = 32;
@@ -353,6 +353,7 @@
 var s: string;
     f: textfile;
     i, ii: LongInt;
+    vobcount: Longword;
 begin
 s:= Pathz[ptCurrTheme] + '/' + cThemeCFGFilename;
 WriteLnToConsole('Reading objects info...');
@@ -394,7 +395,13 @@
     end;
 
 // snowflakes
-//Readln(f, );
+Readln(f, vobCount);
+if vobCount > 0 then
+   Readln(f, vobFramesCount, vobFrameTicks, vobVelocity, vobFallSpeed);
+
+for i:= 0 to Pred(vobCount) do
+    AddVisualGear( -cScreenWidth + random(cScreenWidth * 2 + 2048), random(1000), vgtFlake);
+
 Close(f);
 {$I+}
 TryDo(IOResult = 0, 'Bad data or cannot access file ' + cThemeCFGFilename, true)
--- a/hedgewars/uVisualGears.pas	Fri Mar 07 19:34:26 2008 +0000
+++ b/hedgewars/uVisualGears.pas	Fri Mar 07 19:44:00 2008 +0000
@@ -18,7 +18,7 @@
 
 unit uVisualGears;
 interface
-uses SDLh, uConsts, uFloat;
+uses SDLh, uConsts, uFloat, GL;
 {$INCLUDE options.inc}
 const AllInactive: boolean = false;
 
@@ -26,28 +26,50 @@
      TVGearStepProcedure = procedure (Gear: PVisualGear; Steps: Longword);
      TVisualGear = record
              NextGear, PrevGear: PVisualGear;
-             State : Longword;
+             Frame,
+             FrameTicks: Longword;
              X : hwFloat;
              Y : hwFloat;
              dX: hwFloat;
              dY: hwFloat;
+             Angle, dAngle: real;
              Kind: TVisualGearType;
              doStep: TVGearStepProcedure;
              end;
 
-function  AddVisualGear(X, Y: LongInt; Kind: TVisualGearType; dX, dY: hwFloat): PVisualGear;
+function  AddVisualGear(X, Y: LongInt; Kind: TVisualGearType): PVisualGear;
 procedure ProcessVisualGears(Steps: Longword);
 procedure DrawVisualGears();
 procedure AddClouds;
 
 var VisualGearsList: PVisualGear = nil;
+    vobFrameTicks, vobFramesCount: Longword;
+    vobVelocity, vobFallSpeed: LongInt;
 
 implementation
-uses uWorld, uMisc, uStore, GL;
+uses uWorld, uMisc, uStore;
 
 // ==================================================================
 procedure doStepFlake(Gear: PVisualGear; Steps: Longword);
 begin
+with Gear^ do
+  begin
+  inc(FrameTicks, Steps);
+  if FrameTicks > vobFrameTicks then
+    begin
+    dec(FrameTicks, vobFrameTicks);
+    inc(Frame);
+    if Frame = vobFramesCount then Frame:= 0
+    end
+  end;
+
+Gear^.X:= Gear^.X + (cWindSpeed * 200 + Gear^.dX) * Steps;
+Gear^.Y:= Gear^.Y + (Gear^.dY + cGravity * vobVelocity) * Steps;
+Gear^.Angle:= Gear^.Angle + Gear^.dAngle;
+
+if hwRound(Gear^.X) < -cScreenWidth - 64 then Gear^.X:= int2hwFloat(cScreenWidth + 2048) else
+if hwRound(Gear^.X) > cScreenWidth + 2048 then Gear^.X:= int2hwFloat(-cScreenWidth - 64);
+if hwRound(Gear^.Y) > 1024 then Gear^.Y:= - _128
 end;
 
 procedure doStepCloud(Gear: PVisualGear; Steps: Longword);
@@ -55,7 +77,9 @@
 Gear^.X:= Gear^.X + (cWindSpeed * 200 + Gear^.dX) * Steps;
 if hwRound(Gear^.Y) > -160 then Gear^.dY:= Gear^.dY - _1div50000
                            else Gear^.dY:= Gear^.dY + _1div50000;
+
 Gear^.Y:= Gear^.Y + Gear^.dY * Steps;
+
 if hwRound(Gear^.X) < -cScreenWidth - 256 then Gear^.X:= int2hwFloat(cScreenWidth + 2048) else
 if hwRound(Gear^.X) > cScreenWidth + 2048 then Gear^.X:= int2hwFloat(-cScreenWidth - 256)
 end;
@@ -67,7 +91,7 @@
                           @doStepCloud
                         );
 
-function  AddVisualGear(X, Y: LongInt; Kind: TVisualGearType; dX, dY: hwFloat): PVisualGear;
+function  AddVisualGear(X, Y: LongInt; Kind: TVisualGearType): PVisualGear;
 var Result: PVisualGear;
 begin
 New(Result);
@@ -75,12 +99,28 @@
 Result^.X:= int2hwFloat(X);
 Result^.Y:= int2hwFloat(Y);
 Result^.Kind := Kind;
-Result^.dX:= dX;
-Result^.dY:= dY;
 Result^.doStep:= doStepHandlers[Kind];
 
 case Kind of
-   vgtCloud: Result^.State:= random(4);
+   vgtFlake: with Result^ do
+               begin
+               FrameTicks:= random(vobFrameTicks);
+               Frame:= random(vobFramesCount);
+               Angle:= random * 360;
+               dx.isNegative:= random(2) = 0;
+               dx.QWordValue:= random(100000000);
+               dy.isNegative:= false;
+               dy.QWordValue:= random(20);
+               dAngle:= (random(2) * 2 - 1) * (1 + random) * vobVelocity / 1000
+               end;
+   vgtCloud: with Result^ do
+               begin
+               Frame:= random(4);
+               dx.isNegative:= random(2) = 0;
+               dx.QWordValue:= random(214748364);
+               dy.isNegative:= random(2) = 0;
+               dy.QWordValue:= 21474836 + random(64424509)
+               end;
      end;
 
 if VisualGearsList <> nil then
@@ -115,8 +155,12 @@
 while Gear <> nil do
       begin
       case Gear^.Kind of
-           vgtFlake: ;
-           vgtCloud: DrawSprite(sprCloud, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.State, nil);
+           vgtFlake: if vobVelocity = 0 then
+                        DrawSprite(sprFlake, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.Frame, nil)
+                     else
+                        DrawRotated(sprFlake, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.Angle);
+
+           vgtCloud: DrawSprite(sprCloud, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.Frame, nil);
               end;
       Gear:= Gear^.NextGear
       end;
@@ -127,14 +171,7 @@
     dx, dy: hwFloat;
 begin
 for i:= 0 to cCloudsNumber do
-    begin
-    dx.isNegative:= random(2) = 1;
-    dx.QWordValue:= random(214748364);
-    dy.isNegative:= (i and 1) = 1;
-    dy.QWordValue:= 21474836 + random(64424509);
-    AddVisualGear( - cScreenWidth + i * ((cScreenWidth * 2 + 2304) div cCloudsNumber), -140,
-             vgtCloud, dx, dy)
-    end
+    AddVisualGear( - cScreenWidth + i * ((cScreenWidth * 2 + 2304) div cCloudsNumber), -140, vgtCloud)
 end;
 
 initialization
--- a/share/hedgewars/Data/Themes/nature/CMakeLists.txt	Fri Mar 07 19:34:26 2008 +0000
+++ b/share/hedgewars/Data/Themes/nature/CMakeLists.txt	Fri Mar 07 19:44:00 2008 +0000
@@ -1,5 +1,6 @@
 install(FILES
 	Border.png
+	Flake.png
 	horizont.png
 	LandTex.png
 	plant1.png
Binary file share/hedgewars/Data/Themes/nature/Flake.png has changed
--- a/share/hedgewars/Data/Themes/nature/theme.cfg	Fri Mar 07 19:34:26 2008 +0000
+++ b/share/hedgewars/Data/Themes/nature/theme.cfg	Fri Mar 07 19:44:00 2008 +0000
@@ -10,3 +10,5 @@
 plant4
 98 10 2 25 1 0 0 70 110
 0
+100
+2 500 100 300