PDA

View Full Version : Delphi 6, DelphiX Starfighter game



Wizard
11-12-2006, 09:21 AM
Hi guys and girls, me again :-)

Can someone give me a suggestion on how to reset the fired count of my player's bullets without using a normal Delphi timer? When I add the line "player.fired := 0" in the DelphiX Timer it works but the bullets leave my player too fast, that's why I did it with the normal timer as it's slower.

Here's my code for bullet creation, bullet move and the timer's event handler. I also need to display the time in seconds, can this be done with DXTimer?


If isButton1 in Form1.DXInput1.States Then
begin
if Fired <= 3 then
begin
Inc(Fired);
with TBullet.Create(Form1.DXSpriteEngine1.Engine) do
begin
Image := Form1.DXImageList1.Items.Find('Bullet');
X := MyX + 30;
Y := MyY;
Width := Image.Width;
Height := Image.Height;
end;
end;
end;


procedure TBullet.DoMove(MoveCount: Integer);
begin
Y := Y - 25;
Collision;
if (Y < 0) Then
Dead;
end;


procedure TForm1.Timer1Timer(Sender: TObject);
begin
//Reset the Fired count so the player can fire 3 bullets again
Player.Fired := 0;
//Increase the time
Inc(Seconds);
end;

Thanks very much for your help :)

cairnswm
11-12-2006, 09:26 AM
Store the tick time of the firing action.

When the player presses fire again - deduct the saved tick time fromt he current tick time - if greater than the delay time that you want then allow the player to fire (and update the stored time) else just skip the fire action.

Wizard
11-12-2006, 11:43 AM
Ok, I had a look at the example that ships with delphi x and got it to work:


procedure TPlayer.DoMove&#40;MoveCount&#58; Integer&#41;;
var
MyX&#58; Double;
MyY &#58; Double;
begin
if fMode = 0 then
begin

If moveLeft and
&#40;x>5&#41; then
X &#58;= X - 10;

If moveright and
&#40;&#40;X+Form1.DXImageList1.Items.Find&#40;'Player'&#41;.Wid th&#41;<Form1>5&#41; then
Y &#58;= Y - 10;

if Movedown and
&#40;y<form1.DXDraw1.Height-65&#41;then
Y&#58;= Y + 10;

MyX &#58;= X; //Set Temporary variable
MyY &#58;= y;

If isButton1 in Form1.DXInput1.States Then
begin
if &#40;FTamaCount<300>=35&#41; then
begin
Inc&#40;FTamaCount&#41;;

with TBullet.Create&#40;Form1.DXSpriteEngine1.Engine&#41; do
begin
Image &#58;= Form1.DXImageList1.Items.Find&#40;'Bullet'&#41;;
Form1.DXWaveList1.Items.Find&#40;'Fire'&#41;.Play&#40;False&#41;;
X &#58;= MyX + 30;
Y &#58;= MyY;
Width &#58;= Image.Width;
Height &#58;= Image.Height;
end;
FOldTamaTime &#58;= FCounter;
end;
end;
end;
FCounter &#58;= FCounter + MoveCount;
end;


But, I need to display the time in seconds, can it be done with the dxtimer?

Thanks :-)

Traveler
11-12-2006, 11:54 AM
But, I need to display the time in seconds, can it be done with the dxtimer?

Thanks :-)

Sure, just set the interval at 1000, which is equal to 1 second.

Wizard
11-12-2006, 12:18 PM
Thanks!!!