Archived

This topic is now archived and is closed to further replies.

VB Problem

This topic is 4949 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey everyone, Im doing a project for my programming class using VB, the problem is i cant figure out how to make colision dectation work to implement the gravity. Im not using a 3d api and the graphics are primitive because A)its a beginner class and B) time limit (2 weeks). I have implemented a random terrain generator using the shapes available with the VB Environment, Now the problem im having is setting up the gravity: for those of you who are familiar with touring, im looking for a WhatDotColor() command or method to use in vb, basically it checks to see the color of a pixel at a set place. Is there a way to do this in Visual Basic??? or if anyone has any other suggestions post em [edited by - TwisteR on May 29, 2004 8:20:58 PM]

Share this post


Link to post
Share on other sites
In order to get the RGB color at a specific location you can use the .Point(x, y) method. Note that this method is dependant on the ScaleMode of the Form or PictureBox.

I'm not quite sure what you need to know about gravity... Usually gravity is implemented in 2D games by applying a downward acceleration to an object, or by subtracting a certain amount from an object's upward velocity every frame.


[edited by - EvilSteve on May 29, 2004 8:31:00 PM]

Share this post


Link to post
Share on other sites
Thnx, i''ll have to try that. I dont really need to know anything about gravity, i got the downward motion and everything, only problem is i cant stop it on the terrain, and i cant use the shape1.top commands and such because the ground is an array of 10 shapes, and there circles so they have that stupid invisible box around them which would stop it on the box, not on the actual circle. Hence why i need to know how to find the color of a certain pixel, that way, i can move the "player" down and if the pixel below is not the same color has the form background it will stop going downward. i think that makes sense, been a long day. lmao

Share this post


Link to post
Share on other sites

Ah, I understand what you''re doing now.

.Point(x, y) should work for you, but you''ll probably have to sample more than one point under the player''s feet.

Also, if the shapes for the terrain are all circles (not ovals), it wouldn''t be too hard to check for collisions mathmatically.

Ex:


For i = 1 to Shapes.Count
If abs(PlayerX - (Shapes(i).left + Shapes(i).height / 2)) ^ 2 _
+ abs(PlayerY - (Shapes(i).top + Shapes(i).width / 2)) ^ 2 _
< (Shapes(i).Width / 2) ^ 2 Then
''Collision detected
End If
Next i

Share this post


Link to post
Share on other sites

.Point(x, y) returning a -1 indicates that you tried to get the color of a point using coordinates outside of the control. If the Shapes are in a PictureBox, use PictureBox.Point rather than Form.Point. Also, double check your ScaleMode settings on the PictureBox or Form containing the shapes, and make sure your coordinates are in the same units.

Share this post


Link to post
Share on other sites
I just have the ovals right on the form, and jsut made a test thing where when you click a msgbox pops up displaying the .Point(x,y) Value and still its always -1....heres the code:

Dim nX As Integer, nY As Integer

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
MsgBox Form1.Point(nX, nY)
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
nX = X
nY = Y
End Sub

Share this post


Link to post
Share on other sites
sorry if the code has bad form or if my questions/comments are wrong, im rather new to visual basic so im not completly firmiliar with all its commands yet..but yeah, still cant get the .Point() code to give anything but -1 for some reason...

Share this post


Link to post
Share on other sites