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 / 2d collisions dont work

Author
Message
Nathan C
14
Years of Service
User Offline
Joined: 26th Jan 2010
Location:
Posted: 21st Mar 2010 00:16 Edited at: 21st Mar 2010 03:14
I am making a zelda game, i finaly got collisions on a building to work but then i get stuck.When Link walks to a building, the colisions work but then i cant move becuase he is stuck on the building, he cant move anywhere and i have no idea how to fix this. ive searched the forums for the last 3 hours and cant find a solution.

collisions is near the bottom of the code

=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 21st Mar 2010 15:26 Edited at: 21st Mar 2010 15:29
record his old position

check for collision at new position

if collision=true then move back to old position

simples

[edit]

Sorry, I didn't read your source properly, can you post the media so I can run it plz

Nathan C
14
Years of Service
User Offline
Joined: 26th Jan 2010
Location:
Posted: 21st Mar 2010 20:08
sure, here it is:

Attachments

Login to view attachments
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 21st Mar 2010 20:28 Edited at: 21st Mar 2010 22:46
I believe what =PRoF= said will work. A couple of questions for you:

1. Why do you use different sprites based upon the direction the player is moving? Why not use the same sprite and just alter the images used?

2. Why not setup the background using image numbers (2D tiles) stored in an array? You could create a scrolling background (like Zelda) and it would be fairly easy to check collision. If you need help, you should be able to search for '2d tile' and find something that can help you. I think Zotoaster wrote a tutorial.

3. Are you familiar with TYPE variables? If so, you could store the animation frames within it, making it easier to code.

Good luck with your game.

EDIT: Here is a link to get you started with 2D tile scrolling. It uses text, but you can easily adapt it.

http://forum.thegamecreators.com/?m=forum_view&t=45952&b=6

Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 22nd Mar 2010 03:06 Edited at: 22nd Mar 2010 05:23
Now since you're specific on what you're trying to accomplish I'll help you out.

[Edit]
You are jumping way ahead of yourself here. You must understand what a tile-based game is before you even attempt to make one. I'll help you create a simple tile-based example to get an idea.

Lets start by creating the main loop and setting up the display settings. As you will notice everything is done with subroutines so to not clog up the main loop and for organization purposes.



So far it does nothing. Now lets create some tiles to be used. The character will be red, grass is green and rock is gray.


We have images to use now but it still does nothing. lets create an array to hold the info of the terrain and objects and fill it with random values.


The terrain array is filled with random grass tiles and the object array has a 10% chance of being a random rock tile. Lets now draw the tiles onto the screen.


Now to draw the character onto the screen we need to setup some variables for it CharX and CharY are all we need at this point. We will be adding a subroutine to draw and control the character.


Now lets check for collision.
Nathan C
14
Years of Service
User Offline
Joined: 26th Jan 2010
Location:
Posted: 22nd Mar 2010 04:33 Edited at: 24th Mar 2010 03:08
Right now i changed


to



To try to fix my collision issue like what =PRoF= said, but i get another issue. When Link walks to the house, he gets teleported to his starting position which is (0,0).
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 22nd Mar 2010 05:27 Edited at: 22nd Mar 2010 05:28
Now since you're specific on what you're trying to accomplish I'll help you out.

[Edit]
You are jumping way ahead of yourself here. You must understand what a tile-based game is before you even attempt to make one. I'll help you create a simple tile-based example to get an idea.

Lets start by creating the main loop and setting up the display settings. As you will notice everything is done with subroutines so to not clog up the main loop and for organization purposes.



So far it does nothing. Now lets create some tiles to be used. The character will be red, grass is green and rock is gray.


We have images to use now but it still does nothing. lets create an array to hold the info of the terrain and objects and fill it with random values.


The terrain array is filled with random grass tiles and the object array has a 10% chance of being a random rock tile. Lets now draw the tiles onto the screen.


Now to draw the character onto the screen we need to setup some variables for it CharX and CharY are all we need at this point. We will be adding a subroutine to draw and control the character.


Now lets check for collision.


For your current project, when checking for sprite collision you should check AHEAD of your current position otherwise you will be stuck inside the collision check. So say you are moving down you will check your Y coordinate PLUS your movement rate. So something like CheckCollision(Y+MoveSpeed).
Nathan C
14
Years of Service
User Offline
Joined: 26th Jan 2010
Location:
Posted: 22nd Mar 2010 05:51
Thanks Ashingda 27, i will try that
Nathan C
14
Years of Service
User Offline
Joined: 26th Jan 2010
Location:
Posted: 23rd Mar 2010 03:23 Edited at: 23rd Mar 2010 04:59
OMG i still cant get the collision right. Trying to be make a simple sprite solid is impossible for me. I am about ready to just give up. All i want is for the building to be ONE SOLID sprite so when i walk into it, it will stop my character from going any further.
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 23rd Mar 2010 19:30 Edited at: 23rd Mar 2010 19:34
Nathan C:

Programming can be a very rewarding and enjoyable experience. However, there are times when frustration sets in. Try to look at problems as a challenge to learn new things.

I have modified your code so that there is collision between Link and the house. It prints "Collision = 1" on the screen when they are colliding. Hopefully, this will help you.



Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 23rd Mar 2010 21:42 Edited at: 23rd Mar 2010 22:02
@Nathan C
I would normally handle collision with a custom made function or routine instead of using what's given "Sprite Collision". There are many methods to get the exact same results and you'll have to find one that best works with you.

Perhaps you should look into types of collision and understand it first. You must not jump too far ahead and start small. Learn the little things that makes the kind of game you're making (function) first. Note that a seemingly simple thing like what you're trying to do actually requires a lot of skills and knowledge.

If you haven't already, run through the basic tutorials found on the forum. Try going here: http://forum.thegamecreators.com/?m=forum_view&t=99497&b=10

I'll list out a few things that you may need to focus on.

Pointers
Arrays - Very important!
Loops
Subroutines
Functions
Bitmap

As for a simple Collision Method try the good old CheckArea() function. This really isn't how you are suppose to do it but recreating the method you took and using it with the CheckArea function, example:


Also get the sprite sheet I used for link.

Attachments

Login to view attachments
Nathan C
14
Years of Service
User Offline
Joined: 26th Jan 2010
Location:
Posted: 24th Mar 2010 02:51
Wow, thanks alot you really helped

Login to post a reply

Server time is: 2024-11-23 20:05:59
Your offset time is: 2024-11-23 20:05:59