Help with avoiding walls
alyienHey all, having a bit of a problem with a mini RPG sample game I am converting from a mac C++ sample (though I don't know C++ so I am doing the whole thing from VB in scratch, those of you who read "Tricks of the Mac Game Programming Gurus" would have seen this). I have barely gotten into this game yet because I am having trouble with the basics..."movement", also this would be an easy task to accomplish with the keyboard, with with mouse this type of collision detection proves more difficult (for a novice like me anyways :)). If you all look in the Picture1_MouseDown procedure ------------------------------------------------------- Dim OldX As Integer Dim OldY As Integer Dim MonsterIndex As Integer Dim NewTerrain As Integer OldX = Chars(0).X OldY = Chars(0).Y If (X / 32) > (Chars(0).X + 1) Then Chars(0).X = Chars(0).X + 1 End If If (X / 32) < Chars(0).X Then Chars(0).X = Chars(0).X - 1 End If If (Y / 32) > (Chars(0).Y + 1) Then Chars(0).Y = Chars(0).Y + 1 End If If (Y / 32) < Chars(0).Y Then Chars(0).Y = Chars(0).Y - 1 End If NewTerrain = TerrainVal(Mid(MapValues(Chars(0).Y), Chars(0).X, 1)) If NewTerrain = 1 Then Beep Chars(0).X = OldX Chars(0).Y = OldY ElseIf NewTerrain = 2 Then GetGold Chars(0).X, Chars(0).Y ElseIf NewTerrain = 3 Then End End If 'If IsMonster(Chars(0).X, Chars(0).Y) Then ' MonsterIndex = MonsterAt(Chars(0).X, Chars(0).Y) ' Chars(0).X = OldX ' Chars(0).Y = OldY ' Attack 0, MonsterIndex 'End If 'RandomizeMonsters PaintMap End Sub ------------------------------------------------------- (The whole project file is available on the site mentioned at the end of this post) I have tried many variations of this method, however this one seems to be the only light of hope. However it seems that it always detects walls (NewTerrain = 1), though if the following lines are commented out If NewTerrain = 1 Then Beep 'Chars(0).X = OldX 'Chars(0).Y = OldY it moves quite smoothly, however you can tell it is still constantly thinking that you are on a wall which is proven by the ever annoying "Beep". Turn these lines off and you quickly find out that you cannot move far at all. I know this method works fine with the keyboard, but the mouse is the wave of the future :), so I really wanna get that going for this sample :) :). PLuS the original Mac C++ sample used the mouse and I wanna make an exact replica of it for practice, and likely turn it into a PSC code tutorial. Any help is appreciated and will be added to the "Credits" section of the game (once I get the menu created, heh). And I know that code snippet above doesn't tell you guys much so I'll post the whole project here: http://www.geocities.com/ggamer2k3/DUNGEON1.zip BTW I am using VB3 for this code simply because I usually code on an older machine (for now anyway), however I have also included a VB6 version in the above zip file. Any questions or comments send to "alyien@yablue.com" or simply reply to this post ^_^. Keep VBing everyone
cbxby the way before anyone posts msgs about the http://www.geocities.com/ggamer2k3/DUNGEON1.zip link being broken geocities prevents people from file leaching off of there users sites. To down load the DUNGEON1.zip file first visit the site at [url]http://www.geocities.com/ggamer2k3/[/url] then paste http://www.geocities.com/ggamer2k3/DUNGEON1.zip into the addressbar to download the file.