Risk Game Map Scrolling Collision Problem
Risk Game Map Scrolling Collision Problem
Risk Game Map Scrolling Collision Problem
Risk Game Map Scrolling Collision Problem
Risk Game Map Scrolling Collision Problem
Risk Game Map Scrolling Collision Problem Risk Game Map Scrolling Collision Problem Risk Game Map Scrolling Collision Problem Risk Game Map Scrolling Collision Problem Risk Game Map Scrolling Collision Problem Risk Game Map Scrolling Collision Problem Risk Game Map Scrolling Collision Problem Risk Game Map Scrolling Collision Problem
Risk Game Map Scrolling Collision Problem Risk Game Map Scrolling Collision Problem
Risk Game Map Scrolling Collision Problem
Go Back  Xtreme Visual Basic Talk > > > Risk Game Map Scrolling Collision Problem


Reply
 
Thread Tools Display Modes
  #1  
Old 11-02-2009, 10:51 PM
Soroshi Soroshi is offline
Newcomer
 
Join Date: Nov 2009
Posts: 2
Default Risk Game Map Scrolling Collision Problem


Ok so I'm Making a Risk Game and I'm designing it so you can scroll around the big map by clicking and dragging a box around on a mini map. The drag around part works fine, but I'm having trouble with preventing draging outside the mini map boundaries. I have it stopping at the edges but when I drag it into the corners or along one side I get some flickering going on, like the map is trying to be in two places at once.
Here is my Code:
Code:
Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
   
    Dim nX As Single
    Dim nY As Single
    
    'movement controll
    'checks if the cursor is over the image box because for some reason when dragging, mousemove works outside the image box's boundaries
    If X >= 0 And X <= (Image1.Left + Image1.Width) And Y >= 0 And Y <= (Image1.Top + Image1.Height) Then
        
    'X and Y movement are separate to allow sliding along the sides
    
        'Y Movement
        If Button = 1 And (imgRef.Top + imgRef.Height - 1) < (Image1.Top + Image1.Height) And imgRef.Top > (Image1.Top - 1) Then
            nY = (Y + (Image1.Top - (imgRef.Height / 2)))
            Call imgRef.Move(imgRef.Left, nY)
            Call imgReal.Move((imgRef.Left * -25), (nY * -25))
        End If
        
        'X movement
        If Button = 1 And (imgRef.Left + imgRef.Width - 1) < (Image1.Left + Image1.Width) And imgRef.Left > (Image1.Left - 1) Then
            nX = (X + (Image1.Left - (imgRef.Width / 2)))
            Call imgRef.Move(nX, imgRef.Top)
            Call imgReal.Move((nX * -25), (imgRef.Top * -25))
        End If
    End If
    
    'snap to edges of minimap
    'checks the four sides of the box to make sure it's not past the edge and move it back in if it is.
    
    If imgRef.Left < Image1.Left Then
    
       Call imgRef.Move(Image1.Left, imgRef.Top)
       Call imgReal.Move((Image1.Left * -25), (imgRef.Top * -25))
       
    End If
    
    If imgRef.Top < Image1.Top Then
    
        Call imgRef.Move(imgRef.Left, Image1.Top)
        Call imgReal.Move((imgRef.Left * -25), (Image1.Top * -25))
        
    End If
        
    If (imgRef.Left + imgRef.Width) > (Image1.Left + Image1.Width) Then
        
        Call imgRef.Move(((Image1.Left + Image1.Width) - imgRef.Width), imgRef.Top)
        Call imgReal.Move((((Image1.Left + Image1.Width) - imgRef.Width) * -25), imgReal.Top)
        
    End If
        
    If (imgRef.Top + imgRef.Height) > (Image1.Top + Image1.Height) Then
    
        Call imgRef.Move(imgRef.Left, ((Image1.Top + Image1.Height) - imgRef.Height))
        Call imgReal.Move(imgReal.Left, (((Image1.Top + Image1.Height) - imgRef.Height) * -25))
        
    End If
End Sub
imgRef is the small box that you drag around.
imgReal is the Large map you drag around.
Image1 is an image box the same size as the minimap but infront of the minimap so that mousemove works even when on top of the box you drag (which is between the two)
The Large map is in an image box that is inside a picture box.
the mini map, the drag box, and Image1 are all in another picture box.
Everything starts out in the top left corner of the picture boxes they are in.
The Large map is 25 times larger than the mini map and the box you drag is 25 times smaller than the image box the large map is inside.
If someone would like the VB files to better understand my program I can post them.
Reply With Quote
  #2  
Old 11-03-2009, 04:32 PM
Soroshi Soroshi is offline
Newcomer
 
Join Date: Nov 2009
Posts: 2
Default Solved!

Ok so a friend of mine help me solve the problem. I was checking for collision AFTER I moved the small box, when I should have checked before. Here is my new and much slimmed down code:
Code:
Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    'movement controll
    'X and Y movement are separate to allow sliding along the sides
    
        'Y Movement
        If Button = 1 Then
            nY = (Y + (Image1.Top - (imgRef.Height / 2)))
            'checks if imgRef would be outside the allowed area and changes nY before calling move
            If nY + imgRef.Height > (Image1.Height) Then nY = Image1.Height - imgRef.Height
            If nY < 0 Then nY = 0
            Call imgRef.Move(imgRef.Left, nY)
            Call imgReal.Move((imgRef.Left * -25), (nY * -25))
        End If
        
        'X movement
        If Button = 1 Then
            nX = (X + (Image1.Left - (imgRef.Width / 2)))
            'checks if imgRef would be outside the allowed area and changes nX before calling move
            If nX + imgRef.Width > (Image1.Width) Then nX = Image1.Width - imgRef.Width
            If nX < 0 Then nX = 0
            Call imgRef.Move(nX, imgRef.Top)
            Call imgReal.Move((nX * -25), (imgRef.Top * -25))
        End If
End Sub

Last edited by Soroshi; 11-03-2009 at 06:12 PM.
Reply With Quote
Reply


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 Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Risk Game Map Scrolling Collision Problem
Risk Game Map Scrolling Collision Problem
Risk Game Map Scrolling Collision Problem Risk Game Map Scrolling Collision Problem
Risk Game Map Scrolling Collision Problem
Risk Game Map Scrolling Collision Problem
Risk Game Map Scrolling Collision Problem Risk Game Map Scrolling Collision Problem Risk Game Map Scrolling Collision Problem Risk Game Map Scrolling Collision Problem Risk Game Map Scrolling Collision Problem Risk Game Map Scrolling Collision Problem Risk Game Map Scrolling Collision Problem
Risk Game Map Scrolling Collision Problem
Risk Game Map Scrolling Collision Problem
 
Risk Game Map Scrolling Collision Problem
Risk Game Map Scrolling Collision Problem
 
-->