Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Adding BonusLives...

  1. #1

    Adding BonusLives...

    O/s: WinXP
    Lib: DelphiX

    Hi everyone. I'm feeling realy dumb as I'm sure that this is a question of logic, but I can't seem to figure it out :evil:

    If points scored are 25000, 50000 etc. then the remaining lives must be incremented by 2 and this does not happen. If points reaches 25000 it works but not when points reaches 50000. Any thoughts?

    In the Player collission:
    Lives := Lives - 1;
    LivesLeft := LivesLeft -1;

    procedure TFormGame.BonusLife;
    begin
    if (Points = 25000) then
    begin
    Lives := LivesLeft + 2;
    end
    else if (Points = 50000) then
    begin
    Lives := LivesLeft + 2;
    end

    RenderPlay: dxdrawGame.Surface.Canvas.TextOut(0,715, 'Lives left: '+ IntToStr(Lives));

    Starting state:
    Lives := 3;
    LivesLeft := 3;
    Wake up from the dream and live your life to the full

  2. #2

    Adding BonusLives...

    What's the difference between lives and livesleft?

    Assuming Points is an Integer I would rewrite TFormGame.BonusLife to

    [pascal]
    procedure TFormGame.BonusLife;
    begin
    if Points mod 25000 = 0 then
    Lives := LivesLeft+2;
    end;
    [/pascal]
    Imagine I've written something clever here inspiring you to make something awesome. If that happens give me credits

  3. #3

    Adding BonusLives...

    I can't really understand the difference between Lives and LivesLeft. In my humble opinion, it should be like this:

    [pascal]
    procedure TFormGame.BonusLife;
    begin
    case Points of
    25000: Inc(Lives, 2); // or Lives := Lives + 2;
    50000: Inc(Lives, 2); // or Lives := Lives + 2;
    end;
    end;
    [/pascal]

    This procedure should be constantly performed (i.e. in OnTimer event).

    And a side note: change the name Lives on Lifes.

    Hope that helped a bit.

  4. #4

    Adding BonusLives...

    Thanks for the replies guys :-)

    PStudio, with your solution the Lifes goes to 5 and stays that way ...?

    Brainer, with your solution the lifes climbs to 168 when points reaches 25000....?

    Points and Lifes are integers.
    Wake up from the dream and live your life to the full

  5. #5

    Adding BonusLives...

    When do you call BonusLife (can we see some code)?

    Btw. my code only works if you want the life variable to increase every 25000 points. If you want some more odd rules for when to increase lifes you can use brainers example.
    Imagine I've written something clever here inspiring you to make something awesome. If that happens give me credits

  6. #6

    Adding BonusLives...

    Quote Originally Posted by Wizard
    Thanks for the replies guys :-)

    PStudio, with your solution the Lifes goes to 5 and stays that way ...?
    Becasue LivesLeft is not incremented.

    It should be like this:

    Code:
    procedure TFormGame.BonusLife;
    begin
      if Points mod 25000 = 0 then 
      begin
        Inc(LivesLeft,2);
        Lives := LivesLeft;
      end;
    end;

  7. #7

    Adding BonusLives...

    Wodzu, with your solution lives runs to 643?

    [pascal]procedure TFormGame.PlayingStateMachine;
    var i,j : integer;
    begin
    case fPlayingState of
    _psStarting : begin
    for I:= DXSpriteEngine.Engine.AllCount-1 downto 0 do
    begin
    if (DXSpriteEngine.Engine.Items[i] <> nil) then
    begin
    DXSpriteEngine.Engine.Items[i].dead;
    end;
    end;
    BackGroundCreate;
    Player := TPlayer.create(dxspriteEngine.Engine,dximageList,P layerImageIndex);
    Attacker := TAttacker.create(dxspriteEngine.Engine,dximageList ,AttackerImageIndex);
    SpaceShipDown := TSpaceShipDown.create(dxspriteEngine.Engine,dximag eList,SpaceShipDownImageIndex);
    GreenShip := TGreenShip.create(dxspriteEngine.Engine,dximageLis t,GreenShipImageIndex);
    Enemies := 15;
    for j := 1 to Enemies do
    begin
    Enemy := TEnemy.create(dxspriteEngine.Engine,dximageList,En emyLeftImageIndex);
    end;
    disk := TDisk.Create(dxSpriteEngine.Engine);
    Points := 0;
    EnemyCount := 0;
    SpaceMines := 0;
    Attackers := 0;
    GreenShips := 0;
    Lives := 3;
    LivesLeft := 3;
    fPlayingState:=_psPlaying;
    end;
    _psPlaying : begin
    FormGame.DxdrawGame.Surface.BltFast(0, 0, backscreen.clientrect,1, backscreen);
    DxSpriteEngine.Engine.Move(1);
    formGame.BonusLife;
    if (player.Deaded) and (Lives <0>= 100000) then
    begin
    fGameState := _gsEnd;
    fEndState:=_esPlaySelected;
    formGame.DXWaveList.Items.Find('BlownUp').Play(Fal se);
    for I:= DXSpriteEngine.Engine.AllCount-1 downto 0 do
    begin
    if (DXSpriteEngine.Engine.Items[i] <> nil) then
    begin
    DXSpriteEngine.Engine.Items[i].dead;
    end;
    end;
    formHigh.ShowModal;
    end
    else
    if (Player.Deaded) and (Lives <= 0) then
    begin
    fGameState:=_gsEnd;
    fEndState:=_esPlaySelected;
    formGame.DXWaveList.Items.Find('BlownUp').Play(Fal se);
    for I:= DXSpriteEngine.Engine.AllCount-1 downto 0 do
    begin
    if (DXSpriteEngine.Engine.Items[i] <nil> 0) and (Player.Deaded) then
    begin
    Player := TPlayer.create(dxspriteEngine.Engine,dximageList,P layerImageIndex);
    formGame.dxWaveList.Items.Find('Bonus').Play(false );
    end;
    end;
    end
    end;[/pascal]
    Wake up from the dream and live your life to the full

  8. #8

    Adding BonusLives...

    The problem seems to be that you all try to spent some extra lives when the points reach the EXACT value of 25000 points. But what happens when the player has 24999 Points, shoots an enemy and gains 10 points for this enemy? So, you need a boolean variable that tells you if you already gave bonus lifes for reaching 25000 points.


    Code:
    if &#40;Points >= 25000&#41; and not XtraLife25k then
    begin
      inc&#40;Lifes,2&#41;;
      XtraLife25k &#58;= true;
    end;
    This way you will give 2 extra lifes ONCE and in EVERY CASE when the player reaches 25000 or more points.

    Same should be done with 50000 then....


    EDIT: You should of course use an array of bool when attaching this behaviour to every 25000 points.
    <a href="http://www.greatgamesexperiment.com/game/Valgard/?utm_source=gge&amp;utm_medium=badge_game"><img border="0" alt="GGE" title="GGE" src="http://static.greatgamesexperiment.com/badge/game/valgard/gge400x56.png"></a>

  9. #9

    Adding BonusLives...

    Quote Originally Posted by wodzu
    Quote Originally Posted by Wizard
    Thanks for the replies guys :-)

    PStudio, with your solution the Lifes goes to 5 and stays that way ...?
    Becasue LivesLeft is not incremented.

    It should be like this:

    Code:
    procedure TFormGame.BonusLife;
    begin
      if Points mod 25000 = 0 then 
      begin
        Inc&#40;LivesLeft,2&#41;;
        Lives &#58;= LivesLeft;
      end;
    end;
    You're right. I just missed that part in my confussion as to why those to vars exists.

    @Huehnerschaender
    Actually he doesn't mention that 25001 is life giving score, but else you're right. Unless of course he's incrementing the score with a value that guarentees him to end on 25000.

    @Wizard
    As Dirk points out, you should make sure that the game doesn't increase your life vars. If I were you I would only call BonusLife when the score changes instead of doing it all the time.
    Imagine I've written something clever here inspiring you to make something awesome. If that happens give me credits

  10. #10

    Adding BonusLives...

    Huehnerschaender

    Thanks so much!!! It's working :-)
    Code:
    procedure TFormGame.BonusLife;
    begin
    if &#40;Points >= 25000&#41; and not XtraLife25000 then
    begin
    inc&#40;LiVes,2&#41;;
    XtraLife25000 &#58;= TRUE;
    end;
    
    if &#40;Points >= 50000&#41; and not XtraLife50000 THEN
    begin
    inc&#40;LiVes,2&#41;;
    XtraLife50000 &#58;= TRUE;
    end;
    I'll try to figure out how to do the array of bool.
    Wake up from the dream and live your life to the full

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •