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 / Any 2D Terrain Collision Snippet?

Author
Message
Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 1st May 2010 03:27
Someone knows about a good 2d Terrain Collision code maybe i can learn
from or use for my game? Thx
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 1st May 2010 04:08 Edited at: 1st May 2010 04:08
Hi mate!!...Didn´t you like the code of BMacZero ?...it´s a good snippet...or perhaps you are lost with that code ?.

There´s another way to get that....just reading the pixel color of the first map, but I don´t asure you that is gonna be faster than BMacZero.

Here´s an example that will show you the idea.


cheers.

I'm not a grumpy grandpa

Attachments

Login to view attachments
Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 1st May 2010 04:25
Chafari, before i make my next post, i must first ask, do u speak spanish?
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 1st May 2010 04:45
Yes...I can speak it....why?

cheers.

I'm not a grumpy grandpa
Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 1st May 2010 05:37
Mmm... nice, ill tell u y i asked

I'm from Costa Rica, and i speak English (Obviously XD), but i like having my codes in my own language So... i have not been able to share my code to much ppl in the forum XP

But u seem to know spanish, so ill share it with u XD

I wanna show u my code, so maybe u could make an example of how i could use BMacZero collision function in it. Sooo... here it is



This is just the loop for when "Wilson" runs to the right direction. But he doesnt move, the scenario is the one that does

It haves different sprites which r represented by "WCDSprite".

When it "Returns" it's going to the main loop where it can make other actions.

And, just if u wanna know, "F" means, Fondo


So... as u can see, i putted the function in it, idk if i putted it like it should have been putted, but anyways... Ive tried a lot of things to make this work, and it doesnt seem to change much.

So... if u have any idea of what could i do, plz, "Your wisdom I do beg"

Thx
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 1st May 2010 12:56
Ok Yitzu ...dejame que mire en algunos ejemplos que tengo por algun lado en casa.Viendo asi por encima la subrrutina de colision de BMacZero, alcanzo a imaginar lo que el sprite haria, aunque hay muchas formas de hacerlo....te bajaste el ejemplo que te mande??, con esa misma formula, obtines la colision, y si lo que quieres es que tu protagonista simplemente haga el movimiento de correr y subir mas bajar en el mismo sitio mientras el escenario se mueve, solo hay que invertir el objeto que mueves....dejame que te prepare algun ejemplo, aunque mi fuerte no son los sprites, sino mas bien los 3D.

Ok Yitzu ... let me have a look in some examples that I have somewhere at home.I`v seen the BMacZero`s collision subroutine, and I can imagine what the sprite would do, although there are many ways to do the same .... have you downloaded the example I have send to you? with the same way you can get the collision, and if you want your character simply make the movement of runing and climb up and down on the same place as the scene moves, you just need invert the sprite you move .... let me fix some examples, but my wisdom is not the sprites, but rather the 3D.

cheers

I'm not a grumpy grandpa
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 1st May 2010 18:38
You can try this out.



Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 1st May 2010 20:20
Cahari, actually i downloaded ur example, but i didnt see u used the function in it, it worked correctly, but how was it using the collision snippet?
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 1st May 2010 21:47
Hi there !
@Yitzu
I didn´t use BMacZero`s function...there are a lot of ways to do that, like Ashingda 27 method.


cheers.

I'm not a grumpy grandpa
Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 1st May 2010 22:06
Mmm.... i see, ur code seems to be sooo simple i dont understand how it works XD

Lol, what i mean, is that, where does it makes the sprite collide with the terrain? i dont find it...

i think it might be here



But i dont understand how does the program know that the sprite 1 is hitting the image 2...

How does it works?
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 1st May 2010 22:49
The comand POINT(X,Y) gives you the screen value of the color of that point...so you just have to know what colour is a wall or what color must be the floor.


cheers.

I'm not a grumpy grandpa
Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 2nd May 2010 00:53
Mmmm... nice, but its not working right to me.

I think the problem im having is that my terrain is a sprite, not an image, but how can i change the image's size?

And also, as how i have understand ur code, i see that the ball goes up or down depending on if it is touching the color of the terrain or not, but my scenario is composed of various backgrounds, the jungle, the mountains, and the sky. The terrain is a beach in the front of all those backgrounds, so idk if the sprite is recognizing the backgrounds as other colors or something like that. Just if its important, the backgrounds are with lowers sprites priorities than the beach and "Wilson".
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 2nd May 2010 01:44
It doesn´t matter if you use sprites because the image that you paste on screen, is just the wallkable surface...it`s something that you problable won`t see in your game as it must be covered with all your jungle trees and all kind of sprites for you game.You just have to understand the method`s concept.

cheers.

I'm not a grumpy grandpa
Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 2nd May 2010 01:54
Mmm.. ok, is there any way to choose which color specifically i want "Wilson" to walk on?
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 2nd May 2010 02:04
@Yitzu
Point() is not a very good collision method. First of all it's very slow and it does not work off screen. All your terrain data should already be stored into an array and when checking for collision you check the array instead.

If you're new to arrays check out TDK's tutorials. Check out the Part 1 section at least.
http://forum.thegamecreators.com/?m=forum_view&t=99497&b=10

chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 2nd May 2010 02:45
Quote: "Point() is not a very good collision method"

Probabply is not the best...just one more option...

Quote: "First of all it's very slow and it does not work off screen"


Not so slow as the square root....and this method let you get into corners...concerning the screen...no one game woks off screen.

chs.

I'm not a grumpy grandpa
Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 2nd May 2010 02:59
How should i store the data of my terrain? can u explain how that works, not the arrays but the collision with the data...
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 2nd May 2010 03:15 Edited at: 2nd May 2010 03:18
One simple way is to use the DATA statement. Funny I just threw this code into one of the DBPro thread but I guess I can pop it here too for your convenience.


You can clearly see in the data list how it looks like in the program. There are 10 across and 6 down and the MapX and MapY are variables that matches those value.

There are 10 across but MapX=9, that is because 0 is also counted and is considered 1 thus 9 is 10.

In this example I only have 2 different terrains, 0=Sky and 1=Brick. You can easily add more by adjusting here and there...

I not sure exactly what type of game you are making but you now have 2 types of examples.


I recommend you to store your terrain data with it's Image ID.


Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 2nd May 2010 04:15 Edited at: 2nd May 2010 04:17
How would u guys use PIXEL-PERFECT SPRITE COLLISION BY CLOGGY function
in my code?

Code for when "Wilson" runs to the right:



And the function:




Ive tried several things, but nothing seems to work right... Collisions r rly breaking my head!
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 2nd May 2010 08:46
I'm not sure why you would need a pixel perfect collision, would you post a screen shot so I can get a better idea?

I have no idea what type of game you are making and what kind of media you are using.

Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 3rd May 2010 04:11
Ok, here it is.

Attachments

Login to view attachments
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 3rd May 2010 05:03
Hola Yitzu....si vas a utilizar ese escenario para tu juego, no es tan dificil el hacer las coliciones con el suelo.

Hi mate..if you´r gonna use this scene for your game, it isn´t so hard to make collision with the floor.

chs.

I'm not a grumpy grandpa
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 3rd May 2010 05:36
@Yitzu
Is this a screen shot or is this the actual floor media?

Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 3rd May 2010 05:37
Its the media, i know its rly big, i have to fix that later.
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 3rd May 2010 07:38
It will be very difficult to do collision with that kind of media. Cloggy's function will not work with your media as it is right now. What that function does is turn your images into memblocks and check it's color data, the same thing as what the statement Point() is doing but it's faster and it's not restricted to what you see on the screen.

Do you know anything about using tiles? Most 2D games are tile-based, it uses less resource and it's also easier to manage and display. If you didn't know already my examples are tile-based.

chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 3rd May 2010 14:48
@Yitzu

If your scene floor, is just going up and down, it`s very easy to get collision, but you don´t need such a big texture.You can get the same results by different ways.

Veo que en tu escenario es muy sencillo; solamente sube y baja, o sea que no ha de ser dificil el obtener colisiones con el suelo....otra cosa seria lo de la colision perfecta, que en la gran mayoria de los juegos tampoco es exacta.Si has de usar memblocs,y no estas al tanto, te aconsejo que antes le heches un vistazo a los tutoriales de TDK.


cheers.

I'm not a grumpy grandpa
Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 4th May 2010 00:37
What is a tile-based game?
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 4th May 2010 01:36 Edited at: 4th May 2010 01:44
You use small sprites(images) to make your scene by adding for example 50 small pieces to represent the floor.So you can prepare your image to load with all different kind of material you want...bricks....wood...and so on.This little sprite, use to be small, but with this method of tiles, you can make you level as big as you need.



cheers

I'm not a grumpy grandpa

Attachments

Login to view attachments
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 4th May 2010 04:51
Quote: "What is a tile-based game? "

I'm surprised you haven't google it up or search it on the forum. Searching for answers will be your best friend if you want to get anywhere.

Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 4th May 2010 05:19
Asking is the best way for getting answers
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 4th May 2010 06:48
If you have someone sitting in front of you, sure, but when it comes to computers, Google is your professor.


chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 4th May 2010 14:13
Quote: "Asking is the best way for getting answers "


I have to admit that our friends Ashingda 27 and Neuro Fuzzy are right.The first thing we have to do, is search on the forum or google.You won´t want we think you are lazy.

cheers.

I'm not a grumpy grandpa
Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 5th May 2010 01:53
Lol, ok, ill keep that in mind, its just that i like hearing this kind of stuff from ppl who know a lot of it and know how to explain it

Login to post a reply

Server time is: 2024-11-23 16:53:01
Your offset time is: 2024-11-23 16:53:01