[VB.Net]Health Bar

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
8 posts Page 1 of 1
Contributors
User avatar
ChaosOverLord
Member
Member
Posts: 36
Joined: Sun Mar 20, 2011 12:17 am

[VB.Net]Health Bar
ChaosOverLord
ChaosOverLord's Tutorials Present....
A Health Bar In VB.Net
So your making a game and you need a code for a health bar?
Well your in luck today because we got the tutorial for you!

Add 2 buttons and 1 textbox to the form.
Name button 1 Heal
Name button 2 Attack

Now time for some coding!

Declare these when your inside the coding....

Public BMap As New Bitmap(Me.Width, Me.Height, Me.CreateGraphics)
Public GraphicsBuffer As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(BMap)
Public HpBarG As Integer = 100
Public HpBarR As Integer = 100

Form 1 Load code

drawhpbar()

Then make this code below the form load code

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.DrawImage(BMap, 0, 0)
End Sub

Next add this

Private Sub drawhpbar()
If HpBarG < 0 Then
HpBarG = 0
End If
If HpBarG > 100 Then
HpBarG = 100
End If
GraphicsBuffer.DrawRectangle(Pens.Black, New Rectangle(47 - 1, 5 - 1, 100 + 1, 15))
GraphicsBuffer.FillRectangle(Brushes.Red, New Rectangle(47, 5, HpBarR, 14))
GraphicsBuffer.FillRectangle(Brushes.Lime, New Rectangle(47, 5, HpBarG, 14))
Me.Invalidate(New Rectangle(47 - 1, 5 - 1, 100 + 1, 15))
End Sub

For button 1 code add this

HpBarG += textbox1.Text
drawhpbar()

then for button 2 code add this

HpBarG -= textbox1.Text
drawhpbar()

Thank you for using my 3rd of all my tutorials!
You do not have the required permissions to view the files attached to this post.
User avatar
Snyper345
VIP - Donator
VIP - Donator
Posts: 471
Joined: Mon Nov 01, 2010 1:53 am

Re: [VB.Net]Health Bar
Snyper345
Good tut im gonna try it now but next time make to use the code thingo coz people will have a cry , like me :D
Image
Image
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

Re: [VB.Net]Health Bar
MrAksel
PLEASE use the CODE tags:
Code: Select all
[code]
[/code]
You tutorials is good, but use the CODE tags!! Please, im begging!
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
User avatar
zachman61
VIP - Donator
VIP - Donator
Posts: 1891
Joined: Wed Dec 16, 2009 9:56 pm

Re: [VB.Net]Health Bar
zachman61
also how can we use two of these say for an Energy Bar
Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that :)
User avatar
tedhead2
Excellent Poster
Excellent Poster
Posts: 338
Joined: Sun Jan 03, 2010 8:36 am

Re: [VB.Net]Health Bar
tedhead2
Looks nice, I've been trying to code a text based rpg for a while now, but the healthbar I made wasn't good at all...
Image
User avatar
Bogoh67
VIP - Site Partner
VIP - Site Partner
Posts: 656
Joined: Sun Apr 18, 2010 8:20 pm

Re: [VB.Net]Health Bar
Bogoh67
wait i got lost in the code could you explain it to me i know what this means
Code: Select all
End If
GraphicsBuffer.DrawRectangle(Pens.Black, New Rectangle(47 - 1, 5 - 1, 100 + 1, 15))
GraphicsBuffer.FillRectangle(Brushes.Red, New Rectangle(47, 5, HpBarR, 14))
GraphicsBuffer.FillRectangle(Brushes.Lime, New Rectangle(47, 5, HpBarG, 14))
Me.Invalidate(New Rectangle(47 - 1, 5 - 1, 100 + 1, 15))
End Sub
but what does this "do"
Code: Select all
Public BMap As New Bitmap(Me.Width, Me.Height, Me.CreateGraphics)
Public GraphicsBuffer As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(BMap)
Public HpBarG As Integer = 100
Public HpBarR As Integer = 100
User avatar
Jg99
VIP - Site Partner
VIP - Site Partner
Posts: 453
Joined: Sun Mar 20, 2011 5:04 am

Re: [VB.Net]Health Bar
Jg99
Looks Awesome! ty for the tut. Have Fun Coding!
http://www.sctechusa.com SilverCloud Website
User avatar
BlakPilar
New Member
New Member
Posts: 15
Joined: Fri Apr 08, 2011 7:49 pm

Re: [VB.Net]Health Bar
BlakPilar
Ehh... no.
Code: Select all
HpBarG += textbox1.Text
That's a very big no-no. If the user enters anything but a number, you're program will not work the way you want it to. Do this instead:
Code: Select all
Dim newHP As Integer = Val(TextBox1.Text)
HpBarG += newHP
Also, why did you make this cost 5 credits? It's not that hard of a "program" and you have the source listed there.
Image
8 posts Page 1 of 1
Return to “Tutorials”