Oh, good! I’ve been able to split up my sources into different units happily so far. I’m using a simple technique I developed when working with Java; passing the drawing context to other functions in other files to allow them to draw. And this is helping my organization a ton.
Now, I’ve got a bit much to do.. first of all, it’s King of Lands‘ birthday on July 30th, and I like to make big updates for it. On top of that, I’ve got 2 books to read + 200 pages from another random book for school, and somehow I have to squeeze in time to make Sun Defender.

The above screenshot is probably the sum of another chunk of 3+ hours of work, and it’s glitchy. For some ODD reason, key up events are being thrown when no key is released… On top of that, with pascal I can’t find a “isKeyDown” function; so the movement of that ship (it’s currently controllable) is jerky as well.
Of course, there’s some more problems to be worked out if I find a isKeyDown function, like keeping consistent timing across different computers… then I’ll have to redesign my current system
but it would totally be worth it if I find that eluding function + a way to keep the key down events @ the same intervals across all computers…
Now, I also had to hack up the sound system a lot to get it to work the way I wanted. First of all, it’s audioOut.loop didn’t work. So I have to check when the audio is done playing, what screen it’s on, and decide if the music should loop or not. I’d also like to note that when in game (Currently, just not the menu), it’ll select a random song to play and when that’s done it’ll pick another random song.
Getting the random song system to work was also quite problematic, but I got it done. It was ridiculous, the system I eventually slapped down to get the job done involves a timer waiting 100ms before playing the next random song, because even though the darn thing gets out of the while(componentIsBusy) loop, it’s, guess what, still busy for a while longer.
In the screenshot pictured way above, the fire follows the ship of course, but what you can’t tell is that the ship is animated. Got that done too; and I have an idea for the art style of the game. One problem currently is that bullets aren’t ever destroyed yet
Gotta make my own garbage collection system, and maybe learn up on lists or something.. because I desperately need something similar to Java’s vectors to manage these bullets.
I’ve also got this thing fairly customizable already. There’s a settings.txt file, that reads whether or not to go full screen, whether or not to mute, and all of the player controls. The menu and ship are controlled by what keys are specified in the file.


July 24th, 2009 at 8:13 am
Nice progress so far
Can’t wait to play it.
Just a note on your need for Java’s vectors: Aren’t Pascal dynamic arrays enough?
Something like following (it don’t exactly how the Andorra 2D objects look like neither how you managed your classes, so it’s just a simple idea):
TBullet = class
private
fPositon: TPoint; // or something similar
fSprite: TSpriteObject;
public
constructor Create;
procedure Draw;
procedure Update;
end;
TPlayer = class
private
Bullet: array of TBullet;
fNumber: Integer;
public
constructor Create;
procedure Shoot;
procedure Draw;
procedure Update;
end;
TGame = class
private
…
public
constructor Create;
procedure Draw;
procedure Update;
end;
procedure TBullet.Draw;
begin
// Draw Bullet @ fPosition
end;
procedure TBullet.Update;
begin
// Move Bullet to the right
end;
procedure TPlayer.Shoot;
begin
fNumber := fNumber + 1;
SetLength(Bullet, fNumber);
Bullet[fNumber] := TBullet.Create;
end;
procedure TPlayer.Draw;
var i: Integer;
begin
for i := 0 to High(Bullet) do Bullet.Draw;
end;
procedure TPlayer.Update;
var i: Integer;
begin
for i := 0 to High(Bullet) do Bullet.Update;
end;
procedure TGame.Draw;
begin
// Draw TPlayer
end;
procedure TGame.Update;
begin
// Collision detection
// If bullets hit the right of the screen, destroy them
end;
Again, just an idea and not tested. It’s just how I would solve this and the framework I’m using would support something like that.
July 25th, 2009 at 4:14 pm
Yeah, I’m already using dynamic arrays & objects:
pBullet = Object
public
x,y,xspeed,yspeed,img: integer;
end;
{ Later on }
if(not(firing)) then exit;
setlength(PBullets,length(PBullets)+1);
PBullets[length(PBullets)-1].img := 2;
PBullets[length(PBullets)-1].x := round(x)+8;
PBullets[length(PBullets)-1].y := round(y)+5;
PBullets[length(PBullets)-1].xspeed := 350;
PBullets[length(PBullets)-1].yspeed := 0;
I just haven’t added anything in to check if the bullets are outside of the screen, and if they are, delete them.
The main problem I foresee is when removing the bullets – I’m not sure how I’d go about removing them from the array… With Java’s vectors, it’s easy. Just do yourVector.Remove(indexNumber); and it removes the entry at the index + reorders the vector to fill in the gap.
July 26th, 2009 at 5:22 pm
There are few possibilites to solve your concern:
1. You need to store the indexNumber for the bullets that have been removed. That solution is not elegant and it’s a lot of work, so I wouldn’t recommand it.
2. Don’t remove/destroy the bullet objects when you are done with them, just fill them with an empty dummy image and dummy values. And when need the bullet again, just check if the bullet has the dummy image/values and if this is the case fill this dummy bullet object with the real values. It’s not particularly a good solution either, because it can use up a lot of memory, but could be an interesting idea if you want to stick with (dynamic) arrays.
3. I just found a nice example on how to use TList: http://www.delphibasics.co.uk/RTL.asp?Name=TList. You can remove an object with yourList.Delete(indexNumber); but I’m not quite sure if it reorders automatically, so you may need to use yourList.Sort(…) afterwards.
I hope that helps.