Hey guys,
First I wish to thank you all guys for helping me get detection and it works now 100% when it comes to collision detection. I have phase 2 now I wish to tackle and would love your help guys on it. I will give you a brief summary of where I am, what I am doing and what advice you guys can give me to do it better. I don't want source code, or solve my coding problem, I want if you guys can help me with psuedo advice like you need to check this and check that kinda of text and then I will take it and turn it into code
Summary: Right now my code when the hero collides with an object it detects it. I can put a simple Boom command and it will make that explosive sound when I collide on something. Perfect, sweet!
Issue: What to do if the player collide with a wall? Require that if the player is moving right and it collides with the wall he cannot move right but can move up, down, left as long as there are no walls on those directions. Such situation remains an issue. Another issue I have, if the player holds down the L key to move left and the character moves too fast the collision detection is missed or hit and miss and will trigger the wall collision event on a key instead of a wall sometimes. The player must push L and release for a second, push L again and release for a second in order for the detection to work correctly 100%. Finally, based on the code I am working if there is lots of objects to detect collision I go through a for loop to loop through the entire array which causes game performance to drop down heavily and make the character when moving around jumping instead of moving smoothly and game slow.
Attempted solution: I have being attempting to solve one problem at a time. My first problem to solve is make the game performance as much as possible not effected by how many objects on screen when checking for collision detection. I have declared couple of arrays below:
Global OBJECTFOUNDCOUNT
Dim HeroLocationX(361)
Dim HeroLocationY(361)
Dim LevelObjects(361)
Dim LevelObjectX(361)
Dim LevelObjectY(361)
Dim ObjectFound(361)
Dim ObjectFoundX(361)
Dim ObjectFoundY(361)
In procedure, I am checking to see which objects in the LevelObject is not SPACe and store that object (based on index) on ObjectFound. Store LevelObjectX and LevelObjectY on ObjectFoundX and ObjectFoundY and increment OBJECTFOUNDCOUNT. This procedure is called OBTAINOBJECTFOUND. Inside the procedure are shared variables such as:
XN, YN, OBJECTFOUNDCOUNT (hopefully from the Global variable at the beginning of the program), LevelObjects(), LevelObjectX(), LevelObjectY(), ObjectFound(), ObjectFoundX, and ObjectFoundY(). In this procedure is a for loop that check if LevelObject(N)<>SPACE then store the information from levelobject, levelobjectx, levelobjecty into objectfound, objectfoundx, and objectfoundy. Finally, increment OBJECTFOUNDCOUNT by using the command
Add OBJECTFOUNDCOUNT,1.
With this...I limit for the for loop from being for loop 1 to 361 each time I move a character a step that for loop have to be executed again from 1 to 361 inside the while loop of the engine which causes a huge drop in performance into for example for 1 to 100. Now the game performance have increased heavily. Problem however there are no values on OBJECTFOUND, OBJECTFOUNDX and OBJECTFOUNDY inside the procedure but they exist outside the procedure. Where did I go wrong here?I have given you guys a summary and where I am about my problem and what attempt of solution I am working at...tell me is this is a good solution? What advice you guys can give me to make a better solution, easy memory and easy in CPU execution and game performance? What is it I am looking for?
I want a function that checks if the collision I am checking at is an obstacle return 1 and on the main engine where it have this command:
x$=inkey$
if x$="l" and <FUNCTION TO CHECK FOR OBSTACLE> <> 1
execute code
End If
Every time I press L it executes that function and sees if I am not hitting an obstacle...returns 0 if I did return 1. Do the same for the right, up, down. This way it checks no obstacle in the way and prevents user from passing through the wall even if the user pressed up and L again it will prevent user from entering left because there is a wall on the left but can go right, down and up as long as there are no walls there too. That is eventually my main goal.
What advice you guys give in order for me to do this?
P.S "I have attached source code with resources here!"
Thanks in advance.