@@ -24,7 +24,7 @@ TViewGame = class(TCastleView)
2424 BloodSplash0, BloodSplash1, BloodSplash2: TCastleScene;
2525 Viewport1: TCastleViewport;
2626 ImageWeapon: TCastleImageControl;
27- TimerGame, TimerHint: TCastleTimer;
27+ TimerBlood, TimerGame, TimerHint: TCastleTimer;
2828 function GetMap (): TMap;
2929 property Map: TMap read GetMap;
3030 protected
@@ -46,15 +46,14 @@ TViewGame = class(TCastleView)
4646 FPosFrom, FPosTo: TVector2;
4747 FAnimateWeaponTicks, FGameTicks: Integer;
4848 FRoomFight: TRoomComponent;
49- FBloodTime: Single;
5049 procedure ButtonDefeatClick (Sender: TObject);
5150 procedure ButtonRoomClick (Sender: TObject);
5251 procedure ButtonWeaponClick (Sender: TObject);
5352 procedure RunAnimation (AScene: TCastleScene; ARoom: TCastleUserInterface);
5453 procedure AnimationStopped (const AScene: TCastleSceneCore; const ATimeSensorNode: TTimeSensorNode);
5554 function RandomBloodSplash (): TCastleScene;
5655 procedure DefeatQuestionYes (Sender: TObject);
57- procedure TimerBloodTrigger ( );
56+ procedure TimerBloodTick (ASender: TObject );
5857 procedure TimerGameTick (ASender: TObject);
5958 procedure TimerHintTick (ASender: TObject);
6059 procedure WeaponHint (ADoShow: Boolean; AWeapon: NHeroWeapon = hwNo);
@@ -148,7 +147,9 @@ procedure TViewGame.Start();
148147 FWeapons[1 ] := WeaponPlus;
149148 FWeapons[2 ] := WeaponMinus;
150149 FWeapons[3 ] := WeaponMultiply;
151- WeaponNo.DoClick();
150+ WeaponNo.DoClick();
151+ TimerBlood.Exists := False;
152+ TimerBlood.OnTimer := TimerBloodTick;
152153 TimerHint.OnTimer := TimerHintTick;
153154 TimerGame.OnTimer := TimerGameTick;
154155 TimerGame.IntervalSeconds := 1 ;
@@ -208,7 +209,7 @@ procedure TViewGame.ButtonWeaponClick(Sender: TObject);
208209 LWeaponButton := Sender as TCastleButton;
209210 for i := 0 to High(FWeapons) do
210211 begin
211- LIsWeapon := FWeapons[i] = LWeaponButton;
212+ LIsWeapon := FWeapons[i] = LWeaponButton;
212213 if LIsWeapon then
213214 begin
214215 if not FInternalWeaponSwitch then
@@ -237,7 +238,8 @@ procedure TViewGame.Stop();
237238begin
238239 inherited ;
239240 TMap.Die();
240- FPreviousRoom := nil ;
241+ FPreviousRoom := nil ;
242+ FPause := True;
241243end ;
242244
243245procedure TViewGame.ButtonDefeatClick (Sender: TObject);
@@ -268,20 +270,11 @@ procedure TViewGame.Update(const SecondsPassed: Single; var HandleInput: boolean
268270 begin
269271 ImageWeapon.Url := ' ' ;
270272 WeaponClick(hwNo);
271- end ;
273+ end ;
272274 end ;
273275 if not FPause and (Map.Hero.Weapon <> hwNo) then
274276 with FPreviousRoom.ImageHeroWeapon do
275277 Rotation := Rotation + 4 * SecondsPassed;
276- if not FPause and (FBloodTime > 0 ) then
277- begin
278- FBloodTime := FBloodTime - SecondsPassed;
279- if FBloodTime <= 0 then
280- begin
281- TimerBloodTrigger();
282- FBloodTime := 0 ;
283- end ;
284- end ;
285278end ;
286279
287280function TViewGame.Press (const Event: TInputPressRelease): Boolean;
@@ -306,7 +299,7 @@ function TViewGame.Press(const Event: TInputPressRelease): Boolean;
306299 if Result then Exit; // allow the ancestor to handle keys
307300 if FPause then Exit;
308301
309- if Event.IsKey(keyEscape) or Event.IsKey(keyBackSpace) then
302+ if Event.IsKey(keyEscape) or Event.IsKey(keyBackSpace) or Event.IsKey(keyEnter) then
310303 begin
311304 ButtonDefeat.DoClick();
312305 Exit(True); // key was handled
@@ -317,20 +310,20 @@ function TViewGame.Press(const Event: TInputPressRelease): Boolean;
317310 W := Ord(Map.Hero.Weapon);
318311 repeat
319312 W := (W + 1 ) mod Length(FWeapons);
320- until FWeapons[W].Enabled;
321- WeaponClick(NHeroWeapon(W), True);
313+ until FWeapons[W].Enabled;
314+ WeaponClick(NHeroWeapon(W), True);
322315 Exit(True); // key was handled
323316 end ;
324317
325318 if Event.Key in [key1, key2, key3, key4] then
326319 begin
327- WeaponClick(NHeroWeapon(Ord(Event.Key) - Ord(key1)), True);
320+ WeaponClick(NHeroWeapon(Ord(Event.Key) - Ord(key1)), True);
328321 Exit(True); // key was handled
329322 end ;
330323
331324 if Event.Key in [keyNumpad1, keyNumpad2, keyNumpad3, keyNumpad4] then
332325 begin
333- WeaponClick(NHeroWeapon(Ord(Event.Key) - Ord(keyNumpad1)), True);
326+ WeaponClick(NHeroWeapon(Ord(Event.Key) - Ord(keyNumpad1)), True);
334327 Exit(True); // key was handled
335328 end ;
336329
@@ -366,11 +359,11 @@ procedure TViewGame.ButtonRoomClick(Sender: TObject);
366359 begin
367360 FPreviousRoom.LabelLeft.Caption := ' ' ;
368361 FPreviousRoom.ImageLeft.Url := ' ' ;
369- FPreviousRoom.ImageHeroWeapon.Url := ' ' ;
362+ FPreviousRoom.ImageHeroWeapon.Url := ' ' ;
370363 end ;
371364
372365 // Show image on currently clicked button
373- FPreviousRoom := LRoom;
366+ FPreviousRoom := LRoom;
374367 LRoom.ImageLeft.Url := Map.Hero.AssetId;
375368 LRoom.LabelLeft.Caption := Map.Hero.Visual;
376369 SwitchHeroWeaponImage();
@@ -411,7 +404,7 @@ procedure TViewGame.RoomFight(ARoom: TRoomComponent);
411404
412405 SwitchHeroWeaponImage(True);
413406 FSkip := True;
414- FBloodTime := 1 ;
407+ TimerBlood.Exists := True ;
415408 FRoomFight := ARoom;
416409end ;
417410
@@ -422,7 +415,7 @@ function TViewGame.RandomBloodSplash(): TCastleScene;
422415 1 : Result := BloodSplash1;
423416 2 : Result := BloodSplash2;
424417 end ;
425- end ;
418+ end ;
426419
427420procedure TViewGame.RunAnimation (AScene: TCastleScene; ARoom: TCastleUserInterface);
428421var
@@ -446,10 +439,12 @@ procedure TViewGame.AnimationStopped(const AScene: TCastleSceneCore; const ATime
446439 AScene.Exists := False;
447440end ;
448441
449- procedure TViewGame.TimerBloodTrigger ( );
442+ procedure TViewGame.TimerBloodTick (ASender: TObject );
450443var
451444 LWeapon: NHeroWeapon;
452445begin
446+ TimerBlood.Exists := False;
447+
453448 if Map.Hero.Dead then
454449 Container.View := ViewDefeat
455450 else
@@ -479,7 +474,7 @@ procedure TViewGame.TimerBloodTrigger();
479474 Container.View := ViewWin;
480475 end ;
481476 end ;
482- FSkip := False;
477+ FSkip := False;
483478end ;
484479
485480procedure TViewGame.TimerHintTick (ASender: TObject);
0 commit comments