![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: May 2005
Posts: 5
Rep Power: 0
![]() |
Help With Lifebar
Hey, whats up everybody? I'm doing a project in programming class and am having trouble with a Lifebar (like in video games). It is very simple, just three pictures of hearts. Every time the label which displays "Computer Wins" is visible, I want a heart to be taken away. How would I go about doing this since I am new?
Thanks |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
If these are just Image controls, it's quite easy:
imgHeart2.Visible = False |
|
|
|
|
|
#3 |
|
Expert Programmer
|
If you've got more than three hearts though you'd probably want to use a control array at the least...
|
|
|
|
|
|
#4 |
|
Newbie
Join Date: May 2005
Posts: 5
Rep Power: 0
![]() |
I understand the .visible = false thing, but the thing is I want heart1 to disappear when the losing message appears, then when it appears again, I want the next one disappear and so on.
|
|
|
|
|
|
#5 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Control arrays break the Form Designer in .NET, unfortunately.
|
|
|
|
|
|
#6 |
|
Newbie
Join Date: May 2005
Posts: 5
Rep Power: 0
![]() |
what do i do then?
|
|
|
|
|
|
#7 |
|
Programmer
Join Date: Feb 2005
Location: Limbo
Posts: 39
Rep Power: 0
![]() |
Are there only going to be three hearts, or will this number possibly change?
Assuming you only have one picture box (I'll call it imgHearts), you could have an integer variable: Dim NumHeartsLeft as Integer = 3 Then, you could dive into GDI+ and have it draw the hearts on that picturebox: Public Sub DrawHearts()
Const HeartPath As String = "C:\Heart.bmp" 'Path to the heart image
Const HeartWidth As Integer = 15 'Width, in pixels, of the heart image
Dim I As Integer 'Traditional loop variable
For I = 1 To NumHeartsLeft
imgHearts.CreateGraphics.DrawImageUnscaled( _
New Bitmap(HeartPath), I * HeartWidth, 0)
Next I
End SubThis draws as many hearts as are in NumHeartsLeft. You should set HeartPath to the location of the Heart image, and HeartWidth to the actual width of the Heart image. Whenever your player gets hurt, when you show the Label, you should subtract 1 from NumHeartsLeft and call DrawHearts: NumHeartsLeft -= 1 DrawHearts() Some suggestions for the above:
Hope this helped at all. Good luck!
__________________
The meek will inherit the earth. -WDaquell |
|
|
|
|
|
#8 |
|
Newbie
Join Date: May 2005
Posts: 5
Rep Power: 0
![]() |
Thanks a lot. But this is a very simple rock paper scissors program. Every time the computer wins, a label displays saying "Computer Wins" and every time that happens, I want a heart's visibility to be turned off. Once all hearts are off I'm going to have it reset a textbox that adds up the total rounds survived back to zero (I already have the textbox working). I don't know if what you helped me with will help that.
thanks |
|
|
|
|
|
#9 |
|
Programmer
Join Date: Feb 2005
Location: Limbo
Posts: 39
Rep Power: 0
![]() |
If it is very simple, then you could just create three Image controls. I'll call them img1, img2, and img3. If you copy the following sub into your program, and call it whenever the label is shown, it will either make an image invisible, or if all are invisible, it will make all three visible again (for restarting and all):
Dim NumHearts As Integer = 3
Public Sub ManageHearts()
Select Case NumHearts
Case 3
img3.Visible = False
Case 2
img2.Visible = False
Case 1
img1.Visible = False
Case 0
img3.Visible = True
img2.Visible = True
img1.Visible = True
NumHearts = 4
End Select
NumHearts -= 1
End SubThe reason NumHearts is set to 4 instead of 3 in 'Case 0' is because it will have 1 subtracted it from it in the next line, making it 3 and ready to start over again. Good Luck!
__________________
The meek will inherit the earth. -WDaquell |
|
|
|
|
|
#10 |
|
Newbie
Join Date: May 2005
Posts: 5
Rep Power: 0
![]() |
Lifbar *SOLVED*
Thanks a lot for being so helpful. I'm sure this will work.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|