Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Question about collision in 2D

Author
Message
martianxx
13
Years of Service
User Offline
Joined: 19th Feb 2011
Location:
Posted: 15th Jun 2011 04:27
Hi I am making a game and am begining to progress, have loaded data into an array that maps my level, used the arrays to map the data, added character with animation that moves from left to right with user input and the level scrolls when the player is in the center of the screen and the level is not at the start or end. The character even jumps and there is some very basic collision in place (to avoid him walking off the screen/level or falling into abyss when he jumps).

However I am now looking at implementing collision so instead of defining values the character can't go outside of (the screen or ground level) the program intuitavley notices colision. I want to do this by readining in bounds of areas into array from a data stetement which I have done since thats the easy part. Now the hard part, making use of the data. I have tried to make a collision check system myslef but after a long time of theorising and playing around without success I started searching around on the forums without much success. I can't see many other people trying to create collisions in this way yet I am sure it's a viable method. While searching I came accross sparky's collision detection. Now the real aim of my question is to ask if sparky's collision detection can be used in 2D as most if not all of the demos and examples seem to be for 3D and if it can how could I use it in conjunction with a data statement similar to the following where 1's represent tiles I want the player to collide with.



If i were to have a quick attempt I would think about reading the array storing the above data and making an object for each entry of 1 (if you can make objects for tiles) and then use the other commands in sparky's detection system to determing when collision occurs.

If any of the veterans out there could give me a point in the right direction I would be most grateful. Thanks in advance. David
martianxx
13
Years of Service
User Offline
Joined: 19th Feb 2011
Location:
Posted: 15th Jun 2011 19:20
I haven't gotten any replies yet but I will update you with where I am. As far as I can see sparky's collisions is sued for 3D objects so I can's use unless there is some nifty technique (like loading it into a 3D scenario and making 2D plane objects to be used for collision).

Regardless I have done some drawings to try and get it straight in my mind and decided to try and create sprites ontop of the tiles that I want the character to collide with. I can then use the sprite collision(sprite1, sprite2) function to test if there is a colision with the sprites.

I know how to update the sprites on screen for screenscolling as its very similar to my technique for pasting images onto the screen whilst the level is scrolling. However there is a variable number of bound tiles on screen at anytime as the level scroll and the array I use to store the info about the sprites would need to change as the level scrolls.

Is there any ReDim command for this so I can re dim the array when a new bound tile is found or do I need a sepeare loop to store the values for the array then another loop to input the new values into the array by using UNDIM arrayName(x,y) Dim arrayName(var1, var2) where var 1/2 are the values obtained from the previous loop. If I dont use this technique or a similar one then I would have to create a sprite for every tile on screen which seems un necisary.

Here is the code I am currently using to create sprites for collision on screen, is there a more efficient way? I am sure there is:

29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 15th Jun 2011 21:45 Edited at: 15th Jun 2011 21:52
Quote: "I haven't gotten any replies yet "


Give us a chance, you only posted yesterday

There are a couple of ways to use data in data statements to create maps and stuff.

In the example below I've used eleven lines and columns of data to represent a grid. I think use a couple of nested "for to next loops" To read this data. When a "1" is read, a green wall is pasted to the screen, with the coordinates being calculated from the x and y values multiplied by the size of the box

Editing the data essentially edits the map.

You can use different values to hold different images, ie 1 is a wall, 2 is plant pot, 3 is a door etc.

I've then used the "sprite hit" command to detect when the player hits the wall and the player will stop.





Another way of doing this, is to use the data to hold the actual coordinates of all the things on the map. I did this on my "driver 20 parallel line" game on the 20 line challenge board. It's a 3D game but will give you an idea of how to use the data.

Lastly, Sparky's collision only works for 3D objects not 2D sprites. The collision detection and resolution I've used in the above example is very simple. You might want to look at Box 2D, I've never used it and have no idea what it actually does, but someone else might be able to shed some light on it.

I hope this helps.
martianxx
13
Years of Service
User Offline
Joined: 19th Feb 2011
Location:
Posted: 16th Jun 2011 00:27
Thanks you for the example.

Quote: "Give us a chance, you only posted yesterday"


Sorry, I didn't mean it in that way. I just wanted to keep you updated on where I was despite any lack of replies.

I think I can take the example you have given me and apply it to my own game. Here is a slightly different version showing how I intend to use the technique.



As you can see I layer other sprites under the visable ones and make the colour transparent and use the back sprites to test for collision. It's possibly not necessary but for now it's easier to implement (as I dont have to chnage so much of the code I have to paste the visable tiles to the screen). When I have completed this test I can refine the code then making it more efficient I think. Do you think this method will work with a scrolling level where the position of the sprites is being changed constantly? I guess i'll have to see Thanks. David

Ps. Ill look into that Box 2D but looks like its more for Dark GDK as its in c++. Correct?
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 16th Jun 2011 04:19 Edited at: 16th Jun 2011 04:24
Quote: "Ps. Ill look into that Box 2D but looks like its more for Dark GDK as its in c++. Correct? "

There's a commercial plugin for DBPro:
http://www.thegamecreators.com/?m=view_product&id=2257

[edit]
also, I can help with collision stuff, but... most of the stuff I write is a bit math intensive for some people. ex:
http://forum.thegamecreators.com/?m=forum_view&t=179370&b=6


Why does blue text appear every time you are near?
martianxx
13
Years of Service
User Offline
Joined: 19th Feb 2011
Location:
Posted: 16th Jun 2011 22:10
Thanks Neuro thats really helpful for getting it stratight in my mind. Actuall after doing maths for a long time t's quite nice to apply that to my programming

Login to post a reply

Server time is: 2024-11-22 19:07:11
Your offset time is: 2024-11-22 19:07:11