Results 1 to 2 of 2

Thread: Vertical Health recharging.

  1. #1
    New Member
    Join Date
    Apr 12
    Posts
    1

    Vertical Health recharging.

    Hi guys i create my health bar with some help of my friend. It looks good but have a one small issue, just let the look at the screenshot, its recharging from the bottom to the top i want to get opposite situation - from top to the bottom.

    Screen:


    And piece of code:
    Code:
    ' If debug mode, handle error then exit out
        If Options.Debug = 1 Then On Error GoTo errorhandler
        
        Set Buffer = New clsBuffer
        Buffer.WriteBytes Data()
        Player(MyIndex).MaxVital(Vitals.HP) = Buffer.ReadLong
        Call SetPlayerVital(MyIndex, Vitals.HP, Buffer.ReadLong)
    
        If GetPlayerMaxVital(MyIndex, Vitals.HP) > 0 Then
            'frmMain.lblHP.Caption = Int(GetPlayerVital(MyIndex, Vitals.HP) / GetPlayerMaxVital(MyIndex, Vitals.HP) * 100) & "%"
            frmMain.lblHP.Caption = GetPlayerVital(MyIndex, Vitals.HP) & "/" & GetPlayerMaxVital(MyIndex, Vitals.HP)
            ' hp bar
            frmMain.ImgHPBar.height = ((GetPlayerVital(MyIndex, Vitals.HP) / HPBar_Height) / (GetPlayerMaxVital(MyIndex, Vitals.HP) / HPBar_Height)) * HPBar_Height
        End If
    
        ' Error handler
        Exit Sub
    errorhandler:
        HandleError "HandlePlayerHP", "modHandleData", Err.Number, Err.Description, Err.Source, Err.HelpContext
        Err.Clear
        Exit Sub
    End Sub

  2. #2
    The DirectXpert Jacob Roman's Avatar
    Join Date
    Aug 04
    Location
    Miami Beach, FL
    Posts
    4,864

    Re: Vertical Health recharging.

    Basically to do this you (based off my Bosskillers game you'll see in my signature) you'll need a simple formula:

    Health Recharging = (Time / Total Time To Recharge In Seconds) * Length Of Health Bar In Pixels

    Or another way of doing it for just health in general:

    Health = (Current Health / Total Health) * Length Of Health Bar In Pixels

    This can be any direction you choose. Left to Right, Right to Left, Top To Bottom, Bottom To Top, or even circular if you choose. Its all a matter of playing with the values. Lets make a rectangle where top left is 0, top right is 1, bottom left is 2 and bottom right is one. To go from top to bottom you would need this:

    vb Code:
    1. With Health_Bar
    2.         If Player.Stats.Total_Health <> 0 Then HP = (Player.Stats.Current_Health / Player.Stats.Total_Health) * .Frame_Size.Bottom
    3.    
    4.         .Vertex_List(0) = Create_TLVertex(.X + .Frame_Size.Left, .Y + .Frame_Size.Top, 0, 1, D3DColorRGBA(255, 255, 255, 255), 0, 0, 0)
    5.         .Vertex_List(1) = Create_TLVertex(.X + .Frame_Size.Right, .Y + .Frame_Size.Top, 0, 1, D3DColorRGBA(255, 255, 255, 255), 0, 1, 0)
    6.         .Vertex_List(2) = Create_TLVertex(.X + .Frame_Size.Left, .Y + HR, 0, 1, D3DColorRGBA(255, 255, 255, 255), 0, 0, 1)
    7.         .Vertex_List(3) = Create_TLVertex(.X + .Frame_Size.Right, .Y + HR, 0, 1, D3DColorRGBA(255, 255, 255, 255), 0, 1, 1)
    8. End With
    Last edited by Jacob Roman; Apr 25th, 2012 at 10:57 AM.
    Useful Forum Tips:

    - If you found any post that was useful, please consider rating their post

    - Give sensible thread titles, please!
    - Be sure to use [HIGHLIGHT=VB][/HIGHLIGHT] tags when posting code written in VB.
    - Write posts like a conversation, not like an email. That way you can avoid saying "Dear so and so" in every post.
    - When your problem is solved, go up to Thread Tools and click on Mark Thread Resolved

    My Contributions: Massive DirectX 2D Tutorials For VB5/VB6/VB.NET || 3D Engine In Pure VB || Friction Force ||DJ Turntable Simulation || Scratching Wavs || Time Based Movement || Newton Physics Simulation || Managed Game Loop || Rigid Body Collision Detection || World of Warcraft RGB Battle System || Bosskillers (World of Warcraft 2D Clone) || Street Fighter Controls (Flawless Simulation) || A* Pathfinding (VB6 & VB.NET) *UPDATED || *NEW* Nintendo Entertainment System Emulator (VB6) || *NEW* Video Game Making Tips (VB6 & VB.Net)

    Expert. Ask me anything NES!

    My Smilies:


Posting Permissions

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