Results 1 to 14 of 14

Thread: Game - Float Points Away

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fox, OK
    Posts
    381

    Game - Float Points Away

    I'm building a card game called 11-UP.
    See the game here.

    I've gotten to the point where I need to make scores show up when the selected cards have a sum of 11. For example, if the card is worth 200 points, then "200" should become visible for about a second and then "float away".

    I know I can do this with a timer and the location property. I was thinking of creating an array of 22 timers, one for each card. When the selected cards have a sum of eleven, I enable the timers for each selected card. The timer makes the "score" for that card appear, then move up a few times, then vanish.

    Does anyone have a better way to do it? Maybe with only one timer?

    Also, how could I make the "scores" become more transparent as time advances? I'd like to make them not only float away, but also "disolve."

    Anyone?

  2. #2
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: Game - Float Points Away

    I couldn't find anything on opacity in any controls besides a form. You might want to make a class that inherits from system.windows.form.label and then create a function which forces it to draw more and more opaque.

    Justin
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  3. #3
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Game - Float Points Away

    No need, just slowly fade it out to the form's background color. Use this function:
    Code:
    Private Function CombineColors(ByVal color1 As Color,ByVal color2 As Color,ByVal weighting As Single) As Color 'Weighting is from 0.0 (all color1) to 1.0 (all color2).
         Dim c1 As Single = 1.0! - weighting
         Dim c2 As Single = weighting
         Dim color1ret As Color = Color.FromArgb(255,CInt(Math.Round(color1.R * c1)),CInt(Math.Round(color1.G * c1)),CInt(Math.Round(color1.B * c1)))
         Dim color2ret As Color = Color.FromArgb(255,CInt(Math.Round(color2.R * c1)),CInt(Math.Round(color2.G * c1)),CInt(Math.Round(color2.B * c1)))
         Dim colorret As Color = Color.FromArgb(255,color1ret.R+color2ret.R,color1ret.G+color2ret.G,color1ret.B+color2ret.B)
         Return colorret
    End Function
    Like so (this is in a timer):
    Code:
    Me.Label1.ForeColor = CombineColors(Me.BackColor,Me.Label1.ForeColor,0.9!)

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fox, OK
    Posts
    381

    Re: Game - Float Points Away

    mini, I see what you're trying to do but this code doesn't seem to do it. Did you test it first?

  5. #5
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Game - Float Points Away

    I did test the function, not the color code, but I thought that would be simple enough. What do you mean, "it doesn't work"?

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fox, OK
    Posts
    381

    Re: Game - Float Points Away

    I mean I don't get any color change. Do I need to edit something in my code other than enabling the timer?

  7. #7
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Game - Float Points Away

    Can I see your code?

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fox, OK
    Posts
    381

    Re: Game - Float Points Away

    Code:
    Option Explicit On
    Option Strict On
    
    Public Class Form1
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Timer1.Enabled = True
        End Sub
    
        Private Function CombineColors(ByVal color1 As Color, ByVal color2 As Color, ByVal weighting As Single) As Color 'Weighting is from 0.0 (all color1) to 1.0 (all color2).
            Dim c1 As Single = 1.0! - weighting
            Dim c2 As Single = weighting
            Dim color1ret As Color = Color.FromArgb(255, CInt(Math.Round(color1.R * c1)), CInt(Math.Round(color1.G * c1)), CInt(Math.Round(color1.B * c1)))
            Dim color2ret As Color = Color.FromArgb(255, CInt(Math.Round(color2.R * c1)), CInt(Math.Round(color2.G * c1)), CInt(Math.Round(color2.B * c1)))
            Dim colorret As Color = Color.FromArgb(255, color1ret.R + color2ret.R, color1ret.G + color2ret.G, color1ret.B + color2ret.B)
            Return colorret
        End Function
    
    
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            Me.Label1.ForeColor = CombineColors(Me.BackColor, Me.Label1.ForeColor, 0.9!)
        End Sub
    
    End Class

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Game - Float Points Away

    You're not seeing any change because you aren't making any change. You're supposed to change the 'weighting' so that the resulting Color value changes. This is an example of why I tend to avoid posting code.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Game - Float Points Away

    Uh... what? The code does change the weighting, that's what the 0.9! part is for.

    Sorry about that, I guess I did make some changes before using it in my program...
    Code:
    Private Function CombineColors(ByVal color1 As Color,ByVal color2 As Color,ByVal weighting As Single) As Color 'Weighting is from 0.0 (all color1) to 1.0 (all color2).
         Dim c1 As Single = 1.0! - weighting
         Dim c2 As Single = weighting
         Dim color1ret As Color = Color.FromArgb(255,CInt(Math.Round(color1.R * c1)),CInt(Math.Round(color1.G * c1)),CInt(Math.Round(color1.B * c1)))
         Dim color2ret As Color = Color.FromArgb(255,CInt(Math.Round(color2.R * c2)),CInt(Math.Round(color2.G * c2)),CInt(Math.Round(color2.B * c2)))
         Dim colorret As Color = Color.FromArgb(255,color1ret.R+color2ret.R,color1ret.G+color2ret.G,color1ret.B+color2ret.B)
         Return colorret
    End Function
    Last edited by minitech; May 17th, 2010 at 01:11 PM.

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fox, OK
    Posts
    381

    Re: Game - Float Points Away

    Any suggestions how to trigger a stop for the fading? I tried
    Code:
            If Label1.ForeColor = Me.BackColor Then
                Timer1.Enabled = False
                Label1.ForeColor = Color.Black
            End If
    but the colors never are equal. Rounding error.

    I still don't quite understand how .FromArgb works either. Maybe if that made more sense to me, I could do the math.

  12. #12
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Game - Float Points Away

    Sorry, I didn't read the code carefully enough.

    I put this code in my Tick event handler and it stopped the Timer when the Label stopped changing colour:
    Code:
    If colorret = color2 Then
        Me.Timer1.Stop()
    End If
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  13. #13
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Game - Float Points Away

    colorret isn't a variable in that block, and neither is color2... Do you mean put it in the CombineColors function?

  14. #14
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Game - Float Points Away

    I probably do.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

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



Click Here to Expand Forum to Full Width