Results 1 to 8 of 8

Thread: Help please!

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    8

    Help please!

    Hi, i have a game which has many different shapes, but i need to know a bit of code which will be able to tell me how many of those shapes are visible at any time. The shapes become invisible and visible, and i need something which will count up every interval, and display the number.

    Thanks

  2. #2
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Re: Help please!

    I'm not too sure what you mean (and i guess others aren't either, since you've got no replies).

    I'll describe what i think you mean and tell me if i'm correct.

    You have lots of (2D) shapes moving on and off screen.
    They can overlap eachother.
    They can be visible or invisible.
    You want to know if any part of an shapes. can be seen (i.e. its visible and not covered completly).
    You want to count the number of these visible shapes.

    Is this about right?
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  3. #3
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Help please!

    If you have your own user defined type of that shape with a variable called Visible and declared it as boolean, you can use this to your advantage (you'll see). You then check the radius of the shape (using X and Y) and make sure that it's within the screen. Then, declare an array called Shape as that user defined type. Then you cycle through them in a For loop. If it's visible, a counter will increment. Here is what I mean:

    VB Code:
    1. Option Explicit
    2.  
    3. Private Type Shape_Type
    4.  
    5.      'These X and Y positions are based on the shapes
    6.      'center
    7.      
    8.      X As Long
    9.      Y As Long
    10.  
    11.      Radius_X As Long
    12.      Radius_Y As Long
    13.      Visible As Boolean
    14.  
    15. End Type
    16.  
    17. Private Type RECT
    18.  
    19.      Left As Long
    20.      Top As Long    
    21.      Right As Long
    22.      Bottom As Long
    23.    
    24. End Type
    25.  
    26. Private Shape(100) As Shape_Type
    27.  
    28. Private I As Long
    29.  
    30. Private Bounding_Box As RECT
    31.  
    32. 'Then you do some code to make the shapes, and calculate their radius,
    33. etc etc etc. Then right here is where you check if they are visible.
    34.  
    35. Private Sub Check_For_Visibility()
    36.  
    37.      Dim Counter As Long 'Counter to keep track of number of shapes visible on screen
    38.  
    39.      'Will put a bounding box around the screen.
    40.  
    41.      Bounding_Box.Left = 0
    42.      Bounding_Box.Top = 0
    43.      Bounding_Box.Right = Form1.ScaleWidth - 1
    44.      Bounding_Box.Bottom = Form1.ScaleHeight - 1
    45.  
    46.      For I = 0 to 100
    47.  
    48.           If Shape(I).X + Shape(I).Radius_X < Bounding_Box.Left Then Shape(I).Visible = False
    49.          
    50.           ElseIf Shape(I).X - Shape(I).Radius_X > Bounding_Box.Right Then Shape(I).Visible = False
    51.  
    52.           ElseIf Shape(I).Y - Shape(I).Radius_Y < Bounding_Box.Top Then Shape(I).Visible = False
    53.  
    54.           ElseIf Shape(I).Y + Shape(I).Radius_Y > Bounding_Box.Bottom Then Shape(I).Visible = False
    55.  
    56.           Else
    57.          
    58.                Shape(I).Visible = True
    59.                Counter = Counter + 1            
    60.  
    61.           End If
    62.  
    63.      Next I
    64.  
    65. End Sub

  4. #4
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Re: Help please!

    Note that Jacob's code only works for rectangles.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  5. #5
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Help please!

    Nope. Any shape. Triangles, Circles, Rectangles, squares, etc. The Bounding_Box variable is the screen. It checks if it is within the screen. I used the radius_X and radius_Y of any shape to determine if it's pass the Bounding_Box. If it is then it's not visible. If it's within the bounding box, then it's visible. You should have read my code more carefully.

  6. #6
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Re: Help please!

    That's all very well, but what would the radius of, say a triangle be?? It varies depending on the rotation of the triangle, so unless you're gonna change it as the shape rotates you're not gonna get 100% results.

    I stand by what i said earlier, although it might work for a circle as well.

    Also, you've put the Radius_X/Y as booleans, i think you ment Long. :P
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  7. #7
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Help please!

    Yeah, that was a typo. I didn't do that in VB. I was typing whatever was on the top of my head. :P

    Ok think of any shape with a circle (or oval for wide/skinny non perfect shapes) wrapped around it. A triangle would be a good example. This is known as a bounding sphere.....errrr actually circle since this is 2D and not 3D. If the circle wrapped around a shape is within the screen, it is visible. If not, then it's invisible.

    And no you won't get 100% results, just like in 3D when you are testing all those complex geometric polygonal objects. A bounding box or bounding sphere can only do so much when you are testing them for visibility, but it's close enough to get the job done.

  8. #8
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Re: Help please!

    Quote Originally Posted by Jacob Roman
    Yeah, that was a typo. I didn't do that in VB. I was typing whatever was on the top of my head. :P

    Ok think of any shape with a circle (or oval for wide/skinny non perfect shapes) wrapped around it. A triangle would be a good example. This is known as a bounding sphere.....errrr actually circle since this is 2D and not 3D. If the circle wrapped around a shape is within the screen, it is visible. If not, then it's invisible.

    And no you won't get 100% results, just like in 3D when you are testing all those complex geometric polygonal objects. A bounding box or bounding sphere can only do so much when you are testing them for visibility, but it's close enough to get the job done.
    I'm well aware of the technique of using bounding boxes / spheres / low-poly objects for this purpose, but i wanted to make clear that as you say, it won't be 100% results.

    It'd be usefull if the original poster posted back with what he wanted. :P
    We may be way off - he might only want to count those with his .visible tag set to true!
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


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