Hi again. When I know basics of SDL it's time to try write something. But, at start I find a first problem. I wanna load map from file to dynamic table. So first I must do SetLength, right? I write a dwo functions to get X and Y. Here is my map file (data\maps\map1.txt):
Code:
1 1 1 2 1 1 1 1 1
2 2 2 2 2 2 2 2 1
1 1 2 1 1 1 1 2 1
1 1 2 1 1 1 1 2 1
1 1 2 2 2 2 2 2 1
1 1 1 1 1 1 1 2 1
There are two sprites. Map X is a spaces count in one line + 1, right? So there's my funciton:
[pascal]
function GetMapX : integer;
var
count : integer;
StrChain : string;
MapFile : TextFile;
begin
AssignFile(MapFile, MapPath); //Map path is a global cons 'data\maps\map1.txt'
Reset(MapFile);
Read(MapFile, StrChain);
Result := 0;
for count := 0 to Length(StrChain) do
if StrChain[count] = ' ' then
Result := Result + 1;
Result := Result + 1;
CloseFile(MapFile);
end;
[/pascal]

I hope it's clear for u. This function is in "Maps.pas". And there's my project file. Everything works fine:
[pascal]
program SDL_proby;

{$mode objfpc}{$H+}

uses
SDL, SDL_Image, ImagesDraw, SDL_TTF, FontsDraw, Maps, Player;

const

//Wymiary okna
width = 900;
height = 900;

var
screen : PSDL_Surface;
grass : PSDL_Surface;

logo : PSDL_Surface;
road_horizontal : PSDL_Surface;

pos : TSDL_Rect;

i : integer;

loop : boolean;

procedure Init;
begin
SDL.SDL_Init(SDL_Init_Video);
screen := SDL_SetVideoMode(width, height, 32, SDL.SDL_SWSurface);
TTF_Init;
loop := true;
end;

procedure OnQuit;
begin
SDL.SDL_FreeSurface(grass);
SDL.SDL_FreeSurface(screen);
TTF_Quit;
SDL.SDL_Quit;
end;

procedure doGameInput;
var
KeyPress : TSDL_Event;
begin
while (SDL.SDL_PollEvent(@KeyPress) > 0) do
case (KeyPress.Type_) of SDL.SDL_Keydown :
if (KeyPress.Key.keysym.sym = SDL.SDLK_ESCAPE) then loop := false;
end;
end;


//*************************************************
//************ KOD G¬£?ìWNY PROGRAMU*****************
//*************************************************

begin
Init;
for i := 0 to 5 do ImagesDraw.DrawImage('C:\Documents and Settings\WINDOWS XP\Moje dokumenty\Moje obrazy\grass.jpg', i * 64, 0, 64, 64, screen);
for i := 0 to 5 do ImagesDraw.DrawImage('C:\Documents and Settings\WINDOWS XP\Moje dokumenty\Moje obrazy\road.jpg', i * 64, 128, 64, 64, screen);
ImagesDraw.DrawImage('C:\Documents and Settings\WINDOWS XP\Moje dokumenty\Moje obrazy\beczka.bmp', 0, 0, 64, 64, screen);

repeat
SDL.SDL_Delay(30);
doGameInput;
SDL.SDL_Flip(screen);
until loop = false;

OnQuit;
end.
[/pascal]

I know, I know there's a not used vars and it's not optimized yet. Anyway, it works. But when I put "mx : integer" to var and put "mx := GetMapX" to code it's compiling but I get only black screen. Why it don't work? When I compile my GetMapX function in Delphi and do:
[pascal]
mx := GetMapX;
ShowMessage(IntToStr(mx));
[/pascal]

Then I get 9 (it works). I'm trying, and tying but after some tryies I must restar coputer because something is wrong with exe file... So it's very bored And sorry for double posting - I just want to set topic into "New Posts" state.