Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 27th, 2005, 2:39 PM   #1
Fergutron
Newbie
 
Join Date: May 2005
Posts: 5
Rep Power: 0 Fergutron is on a distinguished road
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
Fergutron is offline   Reply With Quote
Old May 27th, 2005, 4:26 PM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
If these are just Image controls, it's quite easy:
imgHeart2.Visible = False
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old May 27th, 2005, 4:57 PM   #3
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
If you've got more than three hearts though you'd probably want to use a control array at the least...
Rory is offline   Reply With Quote
Old May 27th, 2005, 5:13 PM   #4
Fergutron
Newbie
 
Join Date: May 2005
Posts: 5
Rep Power: 0 Fergutron is on a distinguished road
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.
Fergutron is offline   Reply With Quote
Old May 27th, 2005, 6:36 PM   #5
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Control arrays break the Form Designer in .NET, unfortunately.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old May 27th, 2005, 7:57 PM   #6
Fergutron
Newbie
 
Join Date: May 2005
Posts: 5
Rep Power: 0 Fergutron is on a distinguished road
what do i do then?
Fergutron is offline   Reply With Quote
Old May 27th, 2005, 8:04 PM   #7
Wraith Daquell
Programmer
 
Join Date: Feb 2005
Location: Limbo
Posts: 39
Rep Power: 0 Wraith Daquell is on a distinguished road
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 Sub

This 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:
  • Preload the Heart image to improve speed
  • Put the DrawHearts() sub into the imgHearts' Paint event to prevent the hearts being erased when the form is minimized

Hope this helped at all. Good luck!
__________________
The meek will inherit the earth.

-WDaquell
Wraith Daquell is offline   Reply With Quote
Old May 28th, 2005, 1:34 PM   #8
Fergutron
Newbie
 
Join Date: May 2005
Posts: 5
Rep Power: 0 Fergutron is on a distinguished road
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
Fergutron is offline   Reply With Quote
Old May 28th, 2005, 2:44 PM   #9
Wraith Daquell
Programmer
 
Join Date: Feb 2005
Location: Limbo
Posts: 39
Rep Power: 0 Wraith Daquell is on a distinguished road
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 Sub

The 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
Wraith Daquell is offline   Reply With Quote
Old May 28th, 2005, 3:05 PM   #10
Fergutron
Newbie
 
Join Date: May 2005
Posts: 5
Rep Power: 0 Fergutron is on a distinguished road
Lifbar *SOLVED*

Thanks a lot for being so helpful. I'm sure this will work.
Fergutron is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:02 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC