System: Windows Vista
Compiler/IDE: Lazarus .9.28.2, FPC 2.2.4
Libraries/API: Andorra 2D (Not quite relevant, please try to ignore the superfluous code that deals with Andorra if you can.)
Well, I'm trying to flesh out a very flexible system at the moment for game development with Andorra, but to do so, I need to override some key procedures that are already overridden...
Here is the current class, taken from a tutorial and modified very slightly.
[pascal]
TSpr = class(TImageSpriteEx)
protected
procedure DoMove(timegap:double);override;
procedure DoDraw;override;
public
procedure onDraw;virtual;
col:boolean;
xspeed,yspeed: integer;
end;
[/pascal]
The thing is, I have other units that create instances of TSpr, but I'd like to override DoDraw again, for example.
Instantiating a TSpr:
[pascal]
spr := TSpr.Create(engine);
with spr do
begin
Image := gui.Items[1];
X := 0;
Y := 0;
CollisionTester := ColTest;
end;
[/pascal]
What I would like to do would be something along the lines of
[pascal]
spr := TSpr.Create(engine);
elGUI.add(spr);
with spr do
begin
Image := gui.Items[1];
X := 0;
Y := 0;
CollisionTester := ColTest;
DoDraw := SecondOverride;
end;
procedure SecondOverride;
begin
Color := rgb(200,200,200);
end;
[/pascal]
The idea is that there would be one main "object" class, where I can specify which functions handle collisions, drawing, and so on, while also having that main object track some variables such as the current x and y speeds.
With my hacked up idea above, a few things:
1. Is that even possible?
2. If that code was even going to work, wouldn't I have to make a class of TSpr, and change it to procedure TSpr.SecondOverride; ?
3. PS: Color is a property of TImageSpriteEx, and thus of TSpr, so the thing I'd hope is that if I was able to override this function again, it would realize that Color was a property of TSpr which is a property of TImageSpriteEx, so I'd be able to throw that variable in there and have it affect the image as expected.
The other idea that I had, that I've now thrown out would be this:
(Forward declaration of DoDraw of TSpr, how it currently is)
[pascal]
procedure TSpr.DoDraw;
begin
if not col then
Color := rgb(200,200,200);
inherited;
Color := rgb(255,255,255);
end;
[/pascal]
I was thinking (and tried) doing this:
[pascal]
procedure TSpr.DoDraw;
begin
onDraw;
inherited;
end;
procedure TSpr.onDraw;
begin
if not col then
Color := rgb(200,200,200);
Color := rgb(255,255,255);
end;
[/pascal]
But this resulted in the TSpr not being visible at all.
Still learning! Thanks for your patience.
Bookmarks