This little pet-project is a port of my Arkanoid-clone from C/SDL to FreePascal/SDL2. Please keep in mind that I'm 'learning by doing' so eventually I might hit a speedbump Never, ever touched Pascal or any related dialect before downloading FPC a couple of days ago. Can't say that I have any solid OOP experience either, my language of choice has been C since about 1990 when I got my hand on a FredFish disc containing a free C compiler for the Commodore Amiga.
I've spent about two hours on this code, most of the time I've been searching the fpc-wiki for various information, like how to code for-loops and other basic stuff. The aim is to translate it to, if not 'good', 'acceptable' Object Pascal. So far only the SDL_Surface manager has been converted/translated to Pascal using SDL_Texture:s. I'll throw in a snippet for you to criticise
Code:
TTextureList = record
Name: string;
id, refcount: integer;
tx: PSDL_Texture;
end;
{ TTextureManager }
TTextureManager = class(TObject)
private
class var TextureList: array of PTextureList;
class var texcount: integer;
protected
ArkGame: TArkanoid;
function IsLoaded(Name: string): integer;
procedure IncRef(tl: PTextureList);
procedure DecRef(tl: PTextureList);
procedure DeleteTexture(tl: PTextureList);
public
constructor Create(game: TArkanoid);
destructor Destroy; override;
function LoadTexture(Name: string): integer;
function GetTexture(id: integer): PSDL_Texture;
procedure ReleaseTexture(id: integer);
end;
{ TArkanoid is the 'main' game class }
Coming from a procedural language (C) I still have a lot to learn about how and when to use OOP to become a more efficent coder. I've tried C++ but even if it's a 'evolution' of C I find myself lost in the syntax, the fpc object pascal syntax feels more right for me. I've encorporaated a few C++ ideas though, like RAII. Not sure if this is applicable in Pascal, but unless anyone tells me not to do so, I'll continue with it.
[edit] Changed the snippet to be closer to the real code.
Bookmarks