Page 1 of 4 123 ... LastLast
Results 1 to 10 of 31

Thread: Game Developement

  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
    So, let's see if i got it. Using that instruction that you gave me, i should be able to get the location of my file. It should be an ansistring right?
    And placing it instead of this <path name>, i should get something like this <path name>+'\data\file.bmp' right?
    Sorry if i get it bad, i just figured it out how much lack of knowledge i have in this think.
    Last edited by Realeg; 08-03-2015 at 07:02 PM.

  9. #9
    Method ExtractFilePath does include the TrailingPathDelimiter character so you don't need to add it in your string. This means that instead of

    Code:
    <path name>+'\data\file.bmp'


    you would use

    Code:
    <path name>+'data\file.bmp'


    As for the string type returned it is same string type that is the default string type of your development environment (AnsiString in Delphi 7, Unicode string in Delphi 2009 and newer, not sure for FPC/Lazarus thou).

    As for you being sorry about your lack of knowledge. Don't be. We all have been in your position once but we learned and so will you.
    Just don't be afraid to ask. The main purpose of this community is to help each other.

  10. #10
    So this is the code i just write about *.exe file manipulation:
    Code:
    program TextureLoad;
    
    
    uses crt,SDL2,SDL2_image,SysUtils;
    
    
    type R=array[1..100] of pSDL_Renderer;
    	 T=array[1..100] of pSDL_Texture;
    
    
    var window:pSDL_Window; Render:R; Texture:T; i:byte;
    
    
    procedure Graphic_Initialisation;
    begin
    	clrscr;
    	if SDL_INIT(SDL_INIT_VIDEO)<0 then
    		begin
    			writeln('The graphic mode could not be initializated');
    			writeln('The application will now exit');
    			exit;
    		end
    	else
    		window:=SDL_CreateWindow('Texture Window',50,50,600,480,SDL_WINDOW_SHOWN);
    end;
    
    
    Procedure Load_Texture(ExePath:AnsiString);
    begin
    	Texture[1]:=IMG_LOADTEXTURE(Render[1],ExePath+'data\space_armada1.bmp');
    	Texture[2]:=IMG_LOADTEXTURE(Render[2],ExePath+'data\space_armada2.bmp');
    	Texture[3]:=IMG_LOADTEXTURE(Rrender[3],ExePath+'data\space_armada3.bmp');
    end;
    
    
    
    
    Procedure ComposerFrame;
    var Path:AnsiString;
    begin
    	Path:=ExtractPathFile('Texture.exe');
    	Load_Texture(Path);	
    end;
    			
    	
    	
    procedure Graphic_Destruction;
    begin
    	SDL_DestroyWindow(window);
    	SDL_QUIT;
    end;
    
    
    Begin
    	Graphic_Initialisation;
    	SDL_Delay(2000);
    	ComposerFrame;
    	Graphic_Destruction;
    end.
    The error i recive is this: Incompatible type for arg no. 2: Got "AnsiString", expected "PChar"

Page 1 of 4 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
  •