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.

2D All the way! / Tile Collision using arrays

Author
Message
The Viking
15
Years of Service
User Offline
Joined: 21st Oct 2008
Location: Asgard
Posted: 19th Feb 2009 21:46
Hey all, having an issue with collision. I'm using arrays to store all tile information. This is the code for my program.
My problem is that the collision is not working. It seems to either not detect the collision, or make a solid line just above the character not allowing movement upwards, even if the collision layer returns a value of 0 instead of 1. The collision is only being checked currently for movement upwards. Does anyone have any idea as to why this is not working out properly? Thanks

Zergei
19
Years of Service
User Offline
Joined: 9th Feb 2005
Location: Everywhere
Posted: 19th Feb 2009 22:39
Try this...



at line ~163.

Further on my stuff at...
TurboSquid.com
The3dStudio.com
The Viking
15
Years of Service
User Offline
Joined: 21st Oct 2008
Location: Asgard
Posted: 20th Feb 2009 00:20 Edited at: 20th Feb 2009 00:22
No, sorry, that didn't change anything. Though, that area is the problem. It's like a completely straight wall, which the area Layer3 is definitely not a flat wall across.

To make everyone's lives easier: this is the section instead of going through all that code:


And this is the data for it:
Zergei
19
Years of Service
User Offline
Joined: 9th Feb 2005
Location: Everywhere
Posted: 20th Feb 2009 01:13
The problem is with the paste sprite command for the player.
Paste Sprite doesn't change the X and Y position of the sprite, thus the "Sprite Y(SNum# + SAdd#)" always returns 0.

I've noticed that you use 1 diferent sprite for each image of the player, however, you should use the same sprite and only change its image.

I could try fixing your code to work the way your doing it, but in my opinion, its better you change the way you're working with sprites.

Further on my stuff at...
TurboSquid.com
The3dStudio.com
The Viking
15
Years of Service
User Offline
Joined: 21st Oct 2008
Location: Asgard
Posted: 20th Feb 2009 01:24
Thanks for that... I did plan to make it an animated sprite eventually, once i had the rest worked out, but i guess i have to rearrange my priorities. I agree though, I would like to try my own, its the best way to learn. Though my player sprite is positioned at 128,126.

I'll see how that works, one more thing, is it better to make a map out of sprites or tiles? I assumed tiles because they could be reused, but sometimes it seems sprites would be a better option, though it slowed down the fps.
Zergei
19
Years of Service
User Offline
Joined: 9th Feb 2005
Location: Everywhere
Posted: 20th Feb 2009 01:35
Quote: "Though my player sprite is positioned at 128,126."


I added to the code some Text commands to show me the map collision data, the sprite's position and the calculated position, this for each iteration of the collision check and for all of them, the sprite's position was always 0.



This would go right before the collition detection "if".

Quote: "I'll see how that works, one more thing, is it better to make a map out of sprites or tiles? I assumed tiles because they could be reused, but sometimes it seems sprites would be a better option, though it slowed down the fps."


Depends on what type of game your doing. Mostly i'd recommend usign 2.5D . It's like the tiles system, but using partial 3D. It fastens a lot the scenary drawing.

Further on my stuff at...
TurboSquid.com
The3dStudio.com
The Viking
15
Years of Service
User Offline
Joined: 21st Oct 2008
Location: Asgard
Posted: 20th Feb 2009 02:00 Edited at: 20th Feb 2009 02:10
Ok, I see what you mean. Though, when i used:



my sprites position does move on the number map, though the same problem persists. I tried to use just the command:



Instead, though it didn't solve anything, and it also causes problems with the overhead tiles. I have also removed the alternating sprites for an animation, though, there still remained no change. I think there is something i'm still missing here. As for changing the way i am working with sprites, I am not too sure how else to deal with them. Sorry if i'm being pain... Thank you for your help so far though.
Zergei
19
Years of Service
User Offline
Joined: 9th Feb 2005
Location: Everywhere
Posted: 20th Feb 2009 03:48 Edited at: 20th Feb 2009 03:50
Replace you collision code



with this...



I tried this with both, the sprite command and the paste sprite command. For both it works for me, though if you go outbounds of the map it kinda blows up, but it can be easily fix.

Further on my stuff at...
TurboSquid.com
The3dStudio.com
The Viking
15
Years of Service
User Offline
Joined: 21st Oct 2008
Location: Asgard
Posted: 21st Feb 2009 02:07
Hmmm, it does work, although, it seems to enlarge the area, it seems to read 1 tile as multiple, like 4... by adding

to it, it seems to help but it is still off by way more than enough...
Zergei
19
Years of Service
User Offline
Joined: 9th Feb 2005
Location: Everywhere
Posted: 21st Feb 2009 02:26
well, im not totally sure how it looks like since i have no images to show me the map or the player. Rigth now i had to change a bit your code to see the map in numbers regarding the collision.

If you could suply me with the images of the map and player i may better understand your point of view.

Further on my stuff at...
TurboSquid.com
The3dStudio.com
The Viking
15
Years of Service
User Offline
Joined: 21st Oct 2008
Location: Asgard
Posted: 21st Feb 2009 02:38
Sure, thanks for all the help... here's both tilesets Thanks again

Attachments

Login to view attachments
Zergei
19
Years of Service
User Offline
Joined: 9th Feb 2005
Location: Everywhere
Posted: 21st Feb 2009 02:58 Edited at: 21st Feb 2009 03:01
Put the following code right after creating the 16 sprites for your character, before the main loop



this is just a quick fix, but still has the problem that half the players body goes through the wall.

Edit:



Sort of fixed it. Tell me how it works.

Further on my stuff at...
TurboSquid.com
The3dStudio.com
The Viking
15
Years of Service
User Offline
Joined: 21st Oct 2008
Location: Asgard
Posted: 21st Feb 2009 03:05 Edited at: 21st Feb 2009 03:06
No, sorry, it didn't really fix anything. It still seems like the collision tiles are more like a 64 x 64 size instead of 32 x 32, unfortunately. Actually, it seems a lot larger than 64 x 64...
Zergei
19
Years of Service
User Offline
Joined: 9th Feb 2005
Location: Everywhere
Posted: 21st Feb 2009 03:26 Edited at: 21st Feb 2009 03:27
Mmm... just to be sure...
this is my exact code:



Could you also show us in a set of screenshots how it is reacting. Actually a video would be great but that would be asking too much.

Further on my stuff at...
TurboSquid.com
The3dStudio.com
The Viking
15
Years of Service
User Offline
Joined: 21st Oct 2008
Location: Asgard
Posted: 21st Feb 2009 03:45 Edited at: 21st Feb 2009 04:10
i don't know what i changed, but that actually works perfectly... thanks....

Found it! I had this:


Instead of this:


Thanks for all the help!!!!

Though, i noticed now that when i finish it for the other directions, the down doesn't work too well. When i put the down part in, it will actually stop the character in all directions, but if i just leave it with no collision, all other directions work..



EDIT: Nevermind... i got it... just needed to adjust the starting location, because he was starting on a tile which had a 1, instead... thanks
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 23rd Feb 2009 18:20
btw I know you just got it working but wouldn't it be easier to just in one if the for loops find what tile he is on then when he moves in the if statement do it like this


If upkey() and dungeon(currentx,currenty-1,3)=0
Movement code
Endif

I did that in the example for my tile map editor and it worked great

Login to post a reply

Server time is: 2024-04-18 09:13:18
Your offset time is: 2024-04-18 09:13:18