Page 1 of 3 123 LastLast
Results 1 to 10 of 31

Thread: Game Developement

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Game Developement

    Hi everyone! My name is Alex and i'm 17 years old. I'm in 11th grade at highschool with the specialisation in mathematics and informatics. Here, we study Turbo Pascal as programming language. I know most of the pascal programming language till the backtracking and graph theory. I wonder, how could i make games in Turbo Pascal using graphics? I tried to use the "graph unit" integrated with pascal, but i can't use the keyboard in the graphic window.
    So, i'm here to ask you, what i need to start create a graphic game using Pascal language?

  2. #2
    Hello Alex!

    I was wondering the same thing maybe about 10 years ago..
    You can use the keyboard in graphic mode. But you can't use the "console" functionality provided by ReadLn/WriteLn; You can do the following: write a function to handle what will happen if the player presses some key. Also you make function to render your game objects to the screen. Then you cycle both functions until some event occur (like pressing Escape) that will exit the game cycle.

    This is just brief pseudo code, i dont have Turbo Pascal to test it.
    Code:
    var 
      C: Char;
      GameRunning: Boolean;
    
    Function HandleKeypress(Key: Char): Boolean;
    Begin
      Case Key of
        #27: GameRunning := False; //Pressing Escape will cause the game cycle to break;
        'Z': ;//here you write code to handle what happen if the player presses "Z" button, 
        //etc
      End;
    
      Result := True; //Return error(success) code
    End;
    
    Function DrawGameScene: Boolean;
    Begin
      //here you draw all your game objects using graph unit functions
    
      Result := True; 
    End;
    
    Begin
      InitGraph(...) //you initialize graphics here
      GameRunning:= True;
    
      Repeat
        DrawGameScene;
        
        If KeyPressed then Begin
          C := ReadKey;
          HandleKeyPress( C );
        End;
      Until GameRunning = False;
    End.
    I think the last Turbo Pascal is released in the mid 90-ties so it is about 20 years from now. And it can compile only for 16bit DOS (correct me if Im wrong).

    But if your wish to use is Pascal, not concretely Turbo Pascal, you definitely have to make a search for FreePascal / Lazarus. And you have to learn another graphical library, because I doubt Graph will do the work for you. For example some 2d library based on OpenGL.

  3. #3
    Yes, we still use Turbo Pascal as a compiler at our informatics class. I took a peek into this forum and saw all the games released(i never knew Pascal has such a power to render 3D graphics). I downloaded Free Pascal as a compiler and i'm thinking using the SDL library, but i'm not sure which one, because i saw tehre are SDL 1.2 and SDL 2.0. I'm waiting for your suggestion.

  4. #4
    I've been thinking about writing some kind of a tutorial on SDL or programming in general for some time. If you'd be interested and willing to wait a bit, I might give it a try.

    As for SDL, 2.0 is still quite young so there may be some bugs or compatibility issues, but considering that 1.2 is officially EOL and no work will be done on it, I'd say that 2.0 is the safer bet. The workflow doesn't differ much, and the myriad of new features make way more fun to work with.

  5. #5
    SDL might work, but much better choice is ZenGL library. Is very easy to use etc.

    Of course it has also some drawbacks like incomplete documentation but overall there is nothing better.

  6. #6
    Hello!
    I've been learning the SDL2 library for graphic development. And here is where i got stuck. I need to load a texture as a *.bmp file from my computer, and the procedure looks like this: "texture:=IMG_LOADTEXTURE(<render>,<path to file>);"
    The path to the file is for me the big problem. I don't know how to make the application to load a texture file from the folder where the .exe is. For example, if the aplication is in C:\X-FOLDER\Y-FOLDER, how can i load a texture from Y-FOLDER without writing the whole path?To write instead of 'C:\X-FOLDER\Y-FOLDER\file.bmp\, just 'file.bmp'?

  7. #7
    Quote Originally Posted by Realeg View Post
    The path to the file is for me the big problem. I don't know how to make the application to load a texture file from the folder where the .exe is. For example, if the aplication is in C:\X-FOLDER\Y-FOLDER, how can i load a texture from Y-FOLDER without writing the whole path?To write instead of 'C:\X-FOLDER\Y-FOLDER\file.bmp\, just 'file.bmp'?
    You can extract the executable path from the FileName of your executable file using:

    Code:
    MyAppPath := ExtractFilePath(Application.ExeName);
    Also I strongly recomend you don't store your resource files in your application folder but instead create seperate subfolders for this like:
    MyAppPath\Data\Images
    MyAppPath\Data\Sounds
    MyAppPath\Data\Videos
    MyAppDataLevels
    and so on.
    This way you nicely organize your files so you can quickly find specific file manually when you need it.

    When dealing with paths it is also good to make use of IncludeTrailingPathDelimiter method to make sure that all your paths are proprly ended with TrailingPathDelimiter character so you don't need to worry by yourself wheter specific API function returns path with or without the TrailingPathDelimiter

  8. #8
    I've tried the the second solution from the very beginning. The error is now that i got a short string instead of pChar. I've tried this solution, but it had the same result.

    Code:
    path:=pChar(ExtractFilePath('grafica.exe'));
    EDIT: The fact is that i just realise that by writing the upper instruction, the path variable is empty. Only if you write the whole path it is kept in the variable, the problem i want to avoid. In the problem with the short-string to pChar, i solved, the problem is this thing now. Getting the file path, without writing the whole path

    If i write

    Code:
    path:=pChar(ExtractFilePath('C:\Pascal\Projects\grafica.exe');
    the variable will keep C:\Pascal\Projects\, otherwise it will be empty.
    Last edited by Realeg; 13-03-2015 at 09:11 PM.

  9. #9
    When you use

    Code:
    ExtractFilePath('grafica.exe');
    your program tires to search for file named grafica.exe in your current directory also know as working directory which may not be the folder from which your application was launched and then extract its path. If the file can't be found in current directoy you will get empty path as a result.

    So extract your program path using

    Code:
    MyAppPath := ExtractFilePath(Application.ExeName);
    as I have suggested to you in the first place.

    Now you already know what ExtractFilePath method does right.
    And Application.ExeName property returns the full filename of your program executable from which you can extract path to the folder in which your executable resides.
    Last edited by SilverWarior; 13-03-2015 at 09:52 PM.

  10. #10
    For which operating system do you compile your program? For windows or linux?

    About the amount of memory, you should definately be able to get information from the memory manager about the allocated memory size. But when you use external libraries usually they allocate memory using their own memory managers so you cannot catch their memory usage. If you need to monitor you program's memory usage and track for memory leaks and your program is running on windows, i can definately advise you to try this program - VMMap. It can monitor the memory blocks your process has allocated, and it can trace the call stack of each allocation.

    About performance, you could measure execution time of your whole program or separate procedures very easily. For example if you want to measure how much time does it take to execute procedure called DoSomething(), then you can do like this:

    Code:
    var 
      T: Int64;
    begin
      T := GetTickCount;
      DoSomething();
      T := GetTickCount - T; //Now variable T will hold the execution time of your procedure in milisecond units.
      //Output this value somewhere you can see it.
    End;

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •