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

Thread: Player Shields how to do in delphix

  1. #1

    Player Shields how to do in delphix

    Hi everyone, can anyone help me. I want my player to have shields i.e. only after 10 bombs has hit my player the player should die and a new player should be created. At the moment my player has three lives and when a bomb hits it the lives are decreased untill zero.

    I played around with the shields in my code and also tried it in the TBomb.DoCollision procedure but it has no effect.

    Thanks for a GREAT site :-)



    [pascal]procedure TForm1.PlayerShield;
    begin
    if form1.DXImageList1.Items.Find('fireball') = form1.DXImageList1.Items.Find('player') then
    Player_Shields := form1.Player_Shields - 10;
    if (form1.player_Shields = 0) then
    player.Dead;
    end;


    procedure TForm1.StartMain;
    begin
    Splash;
    Randomize;
    EnimyCreate;
    AttackerCreate;
    PlayerCreate;
    Player_Shields := 100;
    PlayerShield;
    BackGroundCreate;
    Earthy := DXDraw1.Height - 500;
    Earthx := DXDraw1.Width - 350;
    Planetx := DXDraw1.Width - 700;
    Planety := DXDraw1.Height -600;
    PlanetStrangeX := DXDraw1.Width - 1000;
    PlanetStrangeY :=DXDraw1.Height - 475;
    Disk_Start_No := 1;
    Disk_End_No := 1;
    NewDisk;
    SpaceShipDown_Start_No := 1;
    SpaceShipDown_End_No := 1;
    NewSpaceShipDown;
    Lives := 3;
    Points := 0;
    SpaceMines := 0;
    SpaceMines := 0;
    end;


    procedure TBomb.DoCollision(Sprite: TSprite; var Done: Boolean);
    begin
    If (Sprite is TPlayer) Then
    begin
    Sprite.Collisioned := False;
    Sprite.Dead;
    Dead;
    Done := False;
    end;
    end;[/pascal]
    Wake up from the dream and live your life to the full

  2. #2

    Player Shields how to do in delphix

    How about something like this:
    Code:
    const
     BOMB_DAMAGE = -10;
    
    procedure TBomb.DoCollision((Sprite: TSprite; var Done: Boolean);
    begin
     if sprite is TPlayer then begin
      (sprite as TPlayer).UpdateShields(BOMB_DAMAGE);
      //other collision stuff
     end;
    end;
    
    procedure TPlayer.UpdateShields)amount : integer);
    begin
     Inc(self.FShields,amount);
     if self.FShields < 0  then
      self.Dead;
    end;

  3. #3

    Player Shields how to do in delphix

    Thanks for the reply. Tried it but still no effect, maybe I'm doing something wrong (still learning). Please help me some more :-)

    1) Ok, so I added a global constant before implementation:
    const
    BOMB_DAMAGE = -10;

    2)My Player class now looks like this:
    Code:
     //This is the player class
      TPlayer = class&#40;TImageSprite&#41;
      private
      FShields &#58; Integer;
      FCounter&#58; Integer;
      FMode&#58; Integer;
      FTamaCount&#58; Integer;
      FOldTamaTime&#58; Integer;
      public
      procedure UpdateShields&#40;amount &#58; integer&#41;;
      procedure DoMove&#40;MoveCount&#58; Integer&#41;; override;
      end;
    3)And the 2 procedures looks as follows:

    Code:
    procedure TBomb.DoCollision&#40;Sprite&#58; TSprite; var Done&#58; Boolean&#41;;
    begin
    If &#40;Sprite is TPlayer&#41; Then
      begin
        &#40;Sprite as TPlayer&#41;.UpdateShields&#40;Bomb_Damage&#41;;
        Sprite.Collisioned &#58;= False;
        Sprite.Dead;
        Dead;
        Done &#58;= False;
      end;
    end;
    
    procedure TPlayer.UpdateShields&#40;amount &#58; integer&#41;;
    begin
     Inc&#40;self.fShields,amount&#41;;
     if self.FShields < 0  then
     self.Dead;
    end;
    Wake up from the dream and live your life to the full

  4. #4

    Player Shields how to do in delphix

    Remove the line
    Code:
    Sprite.Dead;
    from the TBomb.DoCollision procedure.

  5. #5

    Player Shields how to do in delphix

    ok, I removed the Sprite.Dead line in the doCollision procedure but still no effect.

    My PlayerCreate and NewPlayer code:

    Code:
    procedure TForm1.PlayerCreate;
    begin
      Player &#58;= TPlayer.Create&#40;DXSpriteEngine1.Engine&#41;;
      Player.Image &#58;= DXImageList1.Items.Find&#40;'Player'&#41;;
      Player.X &#58;= 500;
      Player.Y &#58;= 690;
      Player.Width &#58;= Player.Image.Width;
      Player.Height &#58;= Player.Image.Height;
      Player.PixelCheck &#58;= False;
    end;
    
    function TForm1.NewPlayer;
    begin
      Player_No &#58;= Player_No + 1;
      PlayerCreate;
      Result &#58;= True;
      Lives&#58;= Lives -1;
    end;
    The following is called in the DXTimer event:

    Code:
    if &#40;Player.Deaded&#41; then
      NewPlayer
      else
      GameEnd;
      GameWin;
    Should FShields and amount have values assigned to them?
    Wake up from the dream and live your life to the full

  6. #6

    Player Shields how to do in delphix

    I think things are getting confusing because you're using -10 and counting up. But the test in UpdateShields is checking if shields < 0 when it should be checking > 0

    I feel that this is the wrong way around. Things which are being damaged should lose value. Good things should be positive, bad things should be negative.

    Initialise your player to have 10 shields and count down when hit.
    Then test if your shields < 0, if so, make the player die.

    Then later on, if your player collects a shield powerup, you can add shields to it instead of removing shields... which makes no sense to me.

  7. #7

    Player Shields how to do in delphix

    I tried your suggestion to count down (dec) and still it's not working. My palyer has 3 lives and before a live expires I want it to take 10 bombs. I'll do some further testing...any further suggestions? :-)

    Code:
    const
    BOMB_DAMAGE = 10;
    
    function TForm1.NewPlayer;
    const Bomb_Damage = 10; // does nothing?
    begin
      Player_No &#58;= Player_No + 1;
      PlayerCreate;
      Result &#58;= True;
      Lives&#58;= Lives -1;
    end;
    
    procedure TBomb.DoCollision&#40;Sprite&#58; TSprite; var Done&#58; Boolean&#41;;
    begin
    If &#40;Sprite is TPlayer&#41; Then
      begin
        &#40;Sprite as TPlayer&#41;.UpdateShields&#40;Bomb_Damage&#41;;
        Sprite.Collisioned &#58;= False;
        //Sprite.Dead;
        Dead;
        Done &#58;= False;
      end;
    end;
    
    procedure TPlayer.UpdateShields&#40;amount &#58; integer&#41;;
    begin
     dec&#40;self.fShields,amount&#41;; // was inc
     if self.FShields < 0  then
     self.Dead;
    end;
    Wake up from the dream and live your life to the full

  8. #8

    Player Shields how to do in delphix

    Quote Originally Posted by jasonf
    I think things are getting confusing because you're using -10 and counting up. But the test in UpdateShields is checking if shields <0> 0

    I feel that this is the wrong way around. Things which are being damaged should lose value. Good things should be positive, bad things should be negative.
    It is done like you say. The Inc procedure in TPlayer.UpdateShields increases or decreases player's shields depending on the sign of the passed value. That is why the BOMB_DAMAGE is set to negative value.

    Quote Originally Posted by Wizard
    Should FShields and amount have values assigned to them?
    Each time you initialize player (TForm1.PlayerCreate procedure) you must set FShields to some initial value. The class constructor sets all integer fields to zero by default and that is why first bomb destroys the player.

    Quote Originally Posted by Wizard
    The following is called in the DXTimer event:
    Code:
    if &#40;Player.Deaded&#41; then 
      NewPlayer 
    else 
      GameEnd;
    I think this is not right but I might be wrong since I dont know the GameEnd procedure. I understand this if statement like this.
    If player is destroyed create new player, if it is not then end game.
    I would do that like this:
    Code:
    if Player.deaded then begin
     if Lives > 0 then //if there are lives left create new player
      NewPlayer
     else                   //if not end the game
      GameEnd;
    end;
    //continue with the game

  9. #9

    Player Shields how to do in delphix

    Sorry guys, couln't get the shields to work

    I have decided to give bonus lives for my little fighter at intervals of points scored i.e. 25000,50000 and so on.

    It works well
    Wake up from the dream and live your life to the full

  10. #10

    Player Shields how to do in delphix

    I am sorry I could not help you.

    I have decided to give bonus lives for my little fighter at intervals of points scored i.e. 25000,50000 and so on.

    It works well
    At last some good news .

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
  •