hedgewars/uLandObjects.pas
changeset 1190 73ec31d8bb6f
parent 1186 bf5af791d234
child 1256 2754a6a8c8f1
equal deleted inserted replaced
1189:f66cdbbfc4b6 1190:73ec31d8bb6f
    22 {$include options.inc}
    22 {$include options.inc}
    23 
    23 
    24 procedure AddObjects();
    24 procedure AddObjects();
    25 procedure LoadThemeConfig;
    25 procedure LoadThemeConfig;
    26 procedure BlitImageAndGenerateCollisionInfo(cpX, cpY, Width: Longword; Image: PSDL_Surface);
    26 procedure BlitImageAndGenerateCollisionInfo(cpX, cpY, Width: Longword; Image: PSDL_Surface);
       
    27 procedure AddOnLandObjects(Surface: PSDL_Surface);
    27 
    28 
    28 implementation
    29 implementation
    29 uses uLand, uStore, uConsts, uMisc, uConsole, uRandom, uVisualGears, uFloat, GL, uSound;
    30 uses uLand, uStore, uConsts, uMisc, uConsole, uRandom, uVisualGears, uFloat, GL, uSound;
    30 const MaxRects = 256;
    31 const MaxRects = 512;
    31       MAXOBJECTRECTS = 16;
    32       MAXOBJECTRECTS = 16;
    32       MAXTHEMEOBJECTS = 32;
    33       MAXTHEMEOBJECTS = 32;
    33 
    34 
    34 type PRectArray = ^TRectsArray;
    35 type PRectArray = ^TRectsArray;
    35      TRectsArray = array[0..MaxRects] of TSDL_Rect;
    36      TRectsArray = array[0..MaxRects] of TSDL_Rect;
   295     r: TSDL_Rect;
   296     r: TSDL_Rect;
   296     Result: boolean;
   297     Result: boolean;
   297 begin
   298 begin
   298 cnt:= 0;
   299 cnt:= 0;
   299 with Obj do
   300 with Obj do
   300      begin
   301 	begin
   301      if Maxcnt = 0 then
   302 	if Maxcnt = 0 then
   302         exit(false);
   303 		exit(false);
   303      x:= 0;
   304 	x:= 0;
   304      r.x:= 0;
   305 	r.x:= 0;
   305      r.y:= 0;
   306 	r.y:= 0;
   306      r.w:= Width;
   307 	r.w:= Width;
   307      r.h:= Height + 16;
   308 	r.h:= Height + 16;
   308      repeat
   309 	repeat
   309          y:= 8;
   310 		y:= 8;
   310          repeat
   311 		repeat
   311              if CheckLand(r, x, y - 8, $FFFFFF)
   312 			if CheckLand(r, x, y - 8, $FFFFFF)
   312                 and not CheckIntersect(x, y, Width, Height) then
   313 			and not CheckIntersect(x, y, Width, Height) then
   313                 begin
   314 			begin
   314                 ar[cnt].x:= x;
   315 			ar[cnt].x:= x;
   315                 ar[cnt].y:= y;
   316 			ar[cnt].y:= y;
   316                 inc(cnt);
   317 			inc(cnt);
   317                 if cnt > MaxPointsIndex then // buffer is full, do not check the rest land
   318 			if cnt > MaxPointsIndex then // buffer is full, do not check the rest land
   318                    begin
   319 				begin
   319                    y:= 5000;
   320 				y:= 5000;
   320                    x:= 5000;
   321 				x:= 5000;
   321                    end
   322 				end
   322                 end;
   323 			end;
   323              inc(y, 12);
   324 			inc(y, 12);
   324          until y > 1023 - Height - 8;
   325 		until y > 1023 - Height - 8;
   325          inc(x, getrandom(12) + 12)
   326 		inc(x, getrandom(12) + 12)
   326      until x > 2047 - Width;
   327 	until x > 2047 - Width;
   327      Result:= cnt <> 0;
   328 	Result:= cnt <> 0;
   328      if Result then
   329 	if Result then
   329         begin
   330 		begin
   330         i:= getrandom(cnt);
   331 		i:= getrandom(cnt);
   331         r.x:= ar[i].X;
   332 		r.x:= ar[i].X;
   332         r.y:= ar[i].Y;
   333 		r.y:= ar[i].Y;
   333         r.w:= Width;
   334 		r.w:= Width;
   334         r.h:= Height;
   335 		r.h:= Height;
   335         SDL_UpperBlit(Obj.Surf, nil, Surface, @r);
   336 		SDL_UpperBlit(Obj.Surf, nil, Surface, @r);
   336         AddRect(ar[i].x - 32, ar[i].y - 32, Width + 64, Height + 64);
   337 		AddRect(ar[i].x - 32, ar[i].y - 32, Width + 64, Height + 64);
   337         dec(Maxcnt)
   338 		dec(Maxcnt)
   338         end else Maxcnt:= 0
   339 		end else Maxcnt:= 0
   339      end;
   340 	end;
   340 TryPut:= Result
   341 TryPut:= Result
   341 end;
   342 end;
   342 
   343 
   343 procedure ReadThemeInfo(var ThemeObjects: TThemeObjects; var SprayObjects: TSprayObjects);
   344 procedure ReadThemeInfo(var ThemeObjects: TThemeObjects; var SprayObjects: TSprayObjects);
   344 var s: string;
   345 var s: string;
   459 AddGirder(1280);
   460 AddGirder(1280);
   460 AddGirder(1536);
   461 AddGirder(1536);
   461 AddGirder(1792);
   462 AddGirder(1792);
   462 AddThemeObjects(ThemeObjects, 8);
   463 AddThemeObjects(ThemeObjects, 8);
   463 AddProgress;
   464 AddProgress;
   464 {SDL_UpperBlit(InSurface, nil, Surface, nil);
       
   465 AddSprayObjects(Surface, SprayObjects, 10);}
       
   466 FreeRects
   465 FreeRects
   467 end;
   466 end;
   468 
   467 
       
   468 procedure AddOnLandObjects(Surface: PSDL_Surface);
       
   469 begin
       
   470 InitRects;
       
   471 AddSprayObjects(Surface, SprayObjects, 12);
       
   472 FreeRects
       
   473 end;
       
   474 
   469 procedure LoadThemeConfig;
   475 procedure LoadThemeConfig;
   470 begin
   476 begin
   471 ReadThemeInfo(ThemeObjects, SprayObjects)
   477 ReadThemeInfo(ThemeObjects, SprayObjects)
   472 end;
   478 end;
   473 
   479