Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   Game Programming (http://www.xtremevbtalk.com/game-programming/)
-   -   Colision Between 2 Images on VB6.0 (http://www.xtremevbtalk.com/game-programming/328694-colision-2-images-vb6-0-a.html)

kaitoby 07-31-2017 01:56 PM

Colision Between 2 Images on VB6.0
 
1 Attachment(s)
Hello, My name its cristobal
im currently doing a project. Its a "Ship" simulator in 2D
im using Visual basic 6.0 my current version to execute my program and until now everything its going well enought
but i had a problem.
i can made my "boat" move througt the module.
but it goes off the limits and doesnt colide with the other imageboxes.
i do literally all the codes
even with Bound the program simply doesnt recognize the codes i use...
Anyone can help me? i give the picture of the program and the code i use


Attachment 33950


Code:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 38 Then
    Bote.Top = Bote.Top - 10
    Bote.Picture = BoteARR.Picture
End If
If KeyCode = 40 Then
    Bote.Top = Bote.Top + 10
    Bote.Picture = BoteABJ.Picture
End If
If KeyCode = 37 Then
    Bote.Left = Bote.Left - 10
    Bote.Picture = BoteIZQ.Picture
End If
If KeyCode = 39 Then
    Bote.Left = Bote.Left + 10
    Bote.Picture = BoteDER.Picture
End If
End Sub


TheRealTinTin 08-01-2017 07:48 AM

Hi kaitoby,

Where is your collision detection logic? Objects will not simply collide, you have to code them to do so.

kaitoby 08-01-2017 01:15 PM

Quote:

Originally Posted by TheRealTinTin (Post 1410997)
Hi kaitoby,

Where is your collision detection logic? Objects will not simply collide, you have to code them to do so.

How do i do that? /: im really good programming

Goggy 08-02-2017 05:14 AM

Simply said....

Check all the corners of your object with all the corners of the other objects. When they overlap you have a collition.

TheRealTinTin 08-03-2017 06:38 AM

As Goggy has said, you need to check where the boat is in comparison to all other objects. Given the simplicity of your map, you could simply create a 2D array that stores whether the relevant pixel is water or an object.

Imagine your image is 600x600. In the top corner, you have 1 square object that is 150x150. You would create an array
Code:

Dim Map(599, 599) As Int
Then define the object:
Code:

Dim x As Int
Dim y As Int

For x = 0 To 149
    For y = 0 To 149
        Map(x, y) = 1
    Next y
Next x

Now, when you move your boat you can use it's .Top, .Left, .Width and .Height properties to determine if it's hit anything by checking those co-ordinates against your array. If any of the array elements where the boat is are 1, it has hit something.


All times are GMT -6. The time now is 06:57 AM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.