Click here to Skip to main content
15,891,136 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: open file directory [modified] Pin
Alan N18-Mar-09 8:54
Alan N18-Mar-09 8:54 
GeneralRe: open file directory Pin
captainmogo18-Mar-09 9:04
captainmogo18-Mar-09 9:04 
GeneralRe: open file directory [modified] Pin
Alan N18-Mar-09 9:27
Alan N18-Mar-09 9:27 
GeneralRe: open file directory Pin
captainmogo19-Mar-09 3:28
captainmogo19-Mar-09 3:28 
Questioncalling a menu form from another menu Pin
Member 462416918-Mar-09 7:04
Member 462416918-Mar-09 7:04 
AnswerRe: calling a menu form from another menu Pin
iamalik18-Mar-09 7:38
professionaliamalik18-Mar-09 7:38 
GeneralRe: calling a menu form from another menu Pin
0x3c018-Mar-09 8:21
0x3c018-Mar-09 8:21 
Questionhow to improve my 2D collision detection system? [modified] Pin
O.G.I.18-Mar-09 4:08
O.G.I.18-Mar-09 4:08 
Hi everyone,
I started writing programs on VB .NET in the year of 2006, reading Jim Buyens book "Faster Smarter Beginning Programming" and that's only skill I got in programming, so I could say that I'm new in writing programs. My dream was to make my own game, I searched the net to find a simple collision detect system, but all I found was "detecting collisions between 2 or three, or maximum 10 objects" which is pretty simple because there is very small count of objects and we know exactly how much they are. There was nothing like "collision detect between various number of objects", so I've made myself one using the following logic:
I've created a string array which size is equal to the count of the pixels that the playground is made of - if my playground is 9000 x 9000 then the array is something like this: strWorldArr(81000000) - each element in the array represents a single pixel of the playground and all objects that move on the playground fill their name in the elements of the array using their coordinates to locate the elements of the array which represents the pixels beneath them. Here is the code of the main part of my collision detect system:

<pre>REM: checking the pixels before moving the object if the values of the array elements which they present are clean then its good to go:
Function CleanChecker(ByVal panHero As HeroBody, ByVal szeSize As Size, _
ByVal intStartPos As Integer, ByVal intEndPos As Integer, _
ByVal intCycle As Integer)
Dim intCount As Integer = 0
For i = 0 To intCycle
For e = intStartPos To intEndPos
If strWorldArr(e) <> panHero.Name And strWorldArr(e) <> "†" Then
intCount += 1
End If
Next
intStartPos += szeSize.Width
intEndPos += szeSize.Width
Next
Return intCount
End Function

REM: this subroutine cleans behind the object, or fills it's new positions:
Sub CleanOrFill(ByVal panHero As HeroBody, ByVal strChar As String, _
ByVal szeSize As Size, ByVal intStartPos As Integer, _
ByVal intEndPos As Integer, ByVal intCycle As Integer)
For i = 0 To intCycle
For e = intStartPos To intEndPos
strWorldArr(e) = strChar
Next
intStartPos += szeSize.Width
intEndPos += szeSize.Width
Next
End Sub

REM: this subroutine is one of 4 which call the CleanChecker and CleanOrFill to detect a collision:
Private Sub mUP(ByVal panHero As HeroBody, ByVal szeSize As Size, _
ByVal intObjSpeed As Integer, ByVal intTolerance As Integer)

Dim intChkStart As Integer = panHero.Left + intStartNum(panHero.Top - intObjSpeed)
Dim intChkEnd As Integer = intChkStart + panHero.Width
Dim intCleanStart As Integer = panHero.Left + intStartNum(panHero.Bottom - intObjSpeed)
Dim intCleanEnd As Integer = intCleanStart + panHero.Width

If CleanChecker(panHero, szeSize, intChkStart, intChkEnd, intObjSpeed) >= intTolerance Then
REM: the path is blocked
Else
REM: the path is passable
panHero.Top -= intObjSpeed
CleanOrFill(panHero, panHero.Name, szeSize, intChkStart, intChkEnd, intObjSpeed)
CleanOrFill(panHero, "†", szeSize, intCleanStart, intCleanEnd, intObjSpeed)
End If
End Sub</pre>

To pass this code through all of the objects I use For Each... Next statement.
On core2 duo CPU 2GHz 4mb l2 cache and 2GB RAM this system can support smoothly up to 100
objects, on intel Pentium4 1800 MHz 512 kb l2 cache and 1GB RAM this system works so badly that it
can't move even one object normally.
I think that this code is pretty simple, why it takes so much power to run? Is this slow calculation have
anything to do with the programming language - Visual Basic 2008 - .NET Framework 3.5? Is there anyway to
improve the collision detect performance of this system or this project is doomed?
Sorry for my bad english, and thank you in advance.

<div class="ForumMod">modified on Wednesday, March 18, 2009 10:39 AM</div>
AnswerRe: how to improve my 2D collision detection system? Pin
Dave Kreskowiak18-Mar-09 6:04
mveDave Kreskowiak18-Mar-09 6:04 
GeneralRe: how to improve my 2D collision detection system? Pin
O.G.I.18-Mar-09 9:18
O.G.I.18-Mar-09 9:18 
GeneralRe: how to improve my 2D collision detection system? Pin
Dave Kreskowiak18-Mar-09 10:26
mveDave Kreskowiak18-Mar-09 10:26 
AnswerRe: how to improve my 2D collision detection system? Pin
riced18-Mar-09 7:32
riced18-Mar-09 7:32 
AnswerRe: how to improve my 2D collision detection system? Pin
Luc Pattyn18-Mar-09 8:39
sitebuilderLuc Pattyn18-Mar-09 8:39 
QuestionIs there a way to bypass the form_load event of vb.net windows application? Pin
rains197918-Mar-09 1:42
rains197918-Mar-09 1:42 
AnswerRe: Is there a way to bypass the form_load event of vb.net windows application? Pin
Eddy Vluggen18-Mar-09 1:58
professionalEddy Vluggen18-Mar-09 1:58 
GeneralRe: Is there a way to bypass the form_load event of vb.net windows application? Pin
rains197918-Mar-09 2:49
rains197918-Mar-09 2:49 
GeneralRe: Is there a way to bypass the form_load event of vb.net windows application? Pin
Eddy Vluggen18-Mar-09 2:57
professionalEddy Vluggen18-Mar-09 2:57 
GeneralRe: Is there a way to bypass the form_load event of vb.net windows application? Pin
rains197918-Mar-09 3:08
rains197918-Mar-09 3:08 
GeneralRe: Is there a way to bypass the form_load event of vb.net windows application? Pin
Eddy Vluggen18-Mar-09 3:19
professionalEddy Vluggen18-Mar-09 3:19 
AnswerRe: Is there a way to bypass the form_load event of vb.net windows application? Pin
Alan N18-Mar-09 4:52
Alan N18-Mar-09 4:52 
AnswerRe: Is there a way to bypass the form_load event of vb.net windows application? Pin
Dave Kreskowiak18-Mar-09 5:52
mveDave Kreskowiak18-Mar-09 5:52 
GeneralRe: Is there a way to bypass the form_load event of vb.net windows application? Pin
rains197918-Mar-09 23:42
rains197918-Mar-09 23:42 
GeneralRe: Is there a way to bypass the form_load event of vb.net windows application? Pin
Dave Kreskowiak19-Mar-09 2:15
mveDave Kreskowiak19-Mar-09 2:15 
Questioncombine and run two projects with diffrent menus forms Pin
Member 462416918-Mar-09 0:22
Member 462416918-Mar-09 0:22 
AnswerRe: combine and run two projects with diffrent menus forms Pin
Christian Graus18-Mar-09 0:25
protectorChristian Graus18-Mar-09 0:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.