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.

Dark GDK / Dead Toms Collision System

Author
Message
Oster200
13
Years of Service
User Offline
Joined: 21st Jan 2011
Location:
Posted: 23rd Mar 2011 00:59
Okay i had a thread for gravity that Dead Tom wrote on and i was looking trough that and i dont understand how to Collision system workd if some one could explain this to me that would be great thank you.
WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 23rd Mar 2011 01:52
Have you implemented any of the code into your own program yet?

That would be a great help for any of us to show were you're going wrong.

Warning! May contain Nuts!
Oster200
13
Years of Service
User Offline
Joined: 21st Jan 2011
Location:
Posted: 23rd Mar 2011 05:34 Edited at: 23rd Mar 2011 05:36
Okay this is the main code:

player code:

okay so on the main code I want were when I jump on to "i" it is solid but I dont know how he does his collosion on that btw i put in the "i"
DeadTomGC
13
Years of Service
User Offline
Joined: 11th Aug 2010
Location: LU
Posted: 24th Mar 2011 02:09
The way the program works is as follows:

The jump method starts by updating the objects y velocity and location without respect for collisions.

Then the program does a simple check to see if the object has gone below ground level and if it should be restored to ground.

Then the position is updated but I don't believe you actually need this line.


Then, the code checks to see if a collision has occurred. If one has, the program will know to only alter the y coordinates due to the collision. This, of course, only works if the sprites are not rotated.

The above code could be looped using several objects allowing the creation of large worlds.
In more detail:
If vely>0 then the object is moving down. Therefore, the object must be on top of the object with which it collided.
The object is moved to just above the top of the static object.

This way there is no longer a collision. However there will be a visible gap unless the visible sprite is not the same as the collision sprite.

Since we went down, we are standing on something that is facing up. Therefore, we can jump.
"jumpok=true;"

The opposite happens when you are going up and of course in either case your new velocity is 0.

Then the position is updated again.

In leftright:
The object is moved according to the left and right keys.

Once again, the only movement is in the x so we know how to reposition the object when there is a collision.
Here instead of using the velocity to determine which side the object should be on I used the position just because it is easier.
However, the velocity method is more reliable when the velocity is extremely high, but you should never have your objects moving that fast because you risk passing the object without touching it.

We update the position.


I hope this answers your question!

Oster200
13
Years of Service
User Offline
Joined: 21st Jan 2011
Location:
Posted: 24th Mar 2011 02:27 Edited at: 24th Mar 2011 02:53
Thank you very much that helped me know more. But how can i put that in my for loop.
DeadTomGC
13
Years of Service
User Offline
Joined: 11th Aug 2010
Location: LU
Posted: 24th Mar 2011 18:11
Do you mean that you want to loop through and check the collisions for many objects?

If this is what you mean, you will need to loop the check for collisions inside the functions jump and leftright.

Oster200
13
Years of Service
User Offline
Joined: 21st Jan 2011
Location:
Posted: 25th Mar 2011 01:55 Edited at: 25th Mar 2011 02:08
Well i mean i made a platform like the ground with a for loop and i want it just like your example the one that you fall on

i want it with your collision but i dont know how to do that.

edit:

okay i got it sort of im going to start off with my code

okay this makes it so if i hit "i" on the bottom it works fine but if i jump ontop of "i" then i appear under it then fall i dont know how to fix this?
DeadTomGC
13
Years of Service
User Offline
Joined: 11th Aug 2010
Location: LU
Posted: 25th Mar 2011 05:09 Edited at: 25th Mar 2011 05:13
You have the right idea, almost.
Want you will want to do is put that for loop around the
in jump. Just replace 1003 with i.
Oh, You'll also want to replace "if(vely>0){" with "if(y<dbSpriteY(blocks[count])){" to make the collsions more reliable now that you have lots of objects that could be overlapping.


Also put this for loop around
in leftright and replace 1003 with i.

Now that I am also done a sample that uses parts from questions that you and other people on the forum asked me and I know what kind of game you are going for, here is a demo that demonstrates a lot of useful features for 2D games. One of which is having many platform objects.

Forum: Look at this one first.
http://forum.thegamecreators.com/?m=forum_view&t=182892&b=22&msg=2179754#m2179754
Codebase:
http://www.thegamecreators.com/?m=codebase_view_code&i=11a532fa1b1f75a010c980b8fababe41

Oster200
13
Years of Service
User Offline
Joined: 21st Jan 2011
Location:
Posted: 25th Mar 2011 05:37
Oh my Gosh this helps me so much!!!!!This is perfect it shows you every thing that is basic for a 2d game!How did you become so good at programming?Did you just ask like i do go off that and eventually remember these things and make them better along the way?I love helping people but i just dont know enough about this yet so i am worried that i might give them the wrong code or somthing. Well my next thing is going to be making enemies. My idea for this is to have invisiable object that when the enemy collides with they change direction backwords and this would be for the patrol type thing. Or maby a range where when the player gets in the range of the enemy it follows. just some ideas. Oh btw if your wondering about why im so newbish at this its beacuse i used to do a drag and drop type of game maker but that was too easy and i wanted more of a challenge. Well i got it. Well the bad part is that its getting late im going to have to go to bed soon. i dont even know who i will get too bed now that i know this. Well thank you very much for teaching me how to do this. i guess im going to look over your code and learn from it.
DeadTomGC
13
Years of Service
User Offline
Joined: 11th Aug 2010
Location: LU
Posted: 25th Mar 2011 15:49
Thanks for the compliments. Just so you know, I started programming about 4 maybe 5 years ago on a TI 84 calculator. Believe it or not, those things have a pretty extensive language built into them. When I started trying to make games for it I realized that I would need to be very resourceful if I wanted to make a descent game. I managed to make pong, checkers, snake, and card memory games. So, I got very good training from that. However, C++ adds a lot of complexity, and I haven't really learned that much of it, but I have learned to be resourceful with what I do know. -Life lessons...

So ya, I was working on a 2D game for a while, but right when I started adding enemies I quit working on it (I still have the code) and started making 3D games which have been going pretty well but I actually haven't worked on my main project in a while. I probably should.

Anyway, There are a lot of ways you could make your enemies, but I definitely would suggest having an array to keep track of them all just like the way I used an array to keep track of the blocks in the demo.
Also, I would suggest that you make one 2D array that tracks all (maybe with the exception of bosses) enemies and uses an element of the array for each enemy to tell the update system that you make what type of enemy it is.

An important thing here is to code with the rest of your code in mind so that you can make life easier on yourself. ie, write the update of one type of enemy knowing that there will be many.

Oster200
13
Years of Service
User Offline
Joined: 21st Jan 2011
Location:
Posted: 25th Mar 2011 20:50 Edited at: 25th Mar 2011 20:51
wow you have been making games for quite a while i started 2 years ago but i have a question how do you get rid of that invisible floor?
DeadTomGC
13
Years of Service
User Offline
Joined: 11th Aug 2010
Location: LU
Posted: 25th Mar 2011 23:39
Just comment out or remove the
in jump.

Oster200
13
Years of Service
User Offline
Joined: 21st Jan 2011
Location:
Posted: 26th Mar 2011 00:25
okay i commented it out and now i can just keep tapping space and ill be going up.
DeadTomGC
13
Years of Service
User Offline
Joined: 11th Aug 2010
Location: LU
Posted: 26th Mar 2011 04:53 Edited at: 26th Mar 2011 04:55
OOPS! Add
where the code I told you to take out was.

Oster200
13
Years of Service
User Offline
Joined: 21st Jan 2011
Location:
Posted: 26th Mar 2011 16:24 Edited at: 26th Mar 2011 16:35
Np thats okay any ways i have a little question what does ! mean again.and a while is a loop that dosent stop till it reaches zero right just some questions i had.Oh how did you make screen move was it this code

somthing with that?
DeadTomGC
13
Years of Service
User Offline
Joined: 11th Aug 2010
Location: LU
Posted: 26th Mar 2011 21:46
! means not, sort of, I probably don't know all the uses for it, but it is used for != which means not equal to like 4!=5.
A while loop only starts to run the commands in it if the boolean in the parentheses is true. ie: 1==1 or 2>=1. It will then only repeat if the statement is still true after every loop.

Yes that code gives the appearance of moving the screen.
This does as well
when you go off the screen to the left.

Oster200
13
Years of Service
User Offline
Joined: 21st Jan 2011
Location:
Posted: 27th Mar 2011 19:32 Edited at: 28th Mar 2011 01:36
okay it feels like you making my game lol. but im trying to make enemys like you made the blocks and ill tell you what i did. so i have an array for the enemys but when i move the enemy just stick where they are on the screen so i made my while loop and copied everything from your for moving the screen and i put the enemies stuff in their but now when i play it it freezes the game. i dont care for collision right now i just want it to have the enemies like the blocks where if i move it gives that effect.
DeadTomGC
13
Years of Service
User Offline
Joined: 11th Aug 2010
Location: LU
Posted: 29th Mar 2011 03:42
The freezing is probably caused by the program trying to access members of the an array that did not exist.
There are so many way you could be doing this. Could you post your code?

Oster200
13
Years of Service
User Offline
Joined: 21st Jan 2011
Location:
Posted: 30th Mar 2011 05:08 Edited at: 30th Mar 2011 05:11
well i deleted it. i think my problem was with the screen moving because is moves the object so i created another while loop thing but that i think froze it wont i have to do that though to make an array of enemys move across screen well here is the code that i did use sort of...

pretty much i just kept the one that is there and added another one and changed every thing for it. by the way i did this for both of them
DeadTomGC
13
Years of Service
User Offline
Joined: 11th Aug 2010
Location: LU
Posted: 31st Mar 2011 15:57
What you really should do is create a second array for baddies with different start and end values. ( When you start make a lot of arrays it may be best to store the info about the arrays in the arrays instead of in separate variables.) Eventually what you need to do is recreate everything I did with the blocks array for your enemies.
For now though, just make a loop which loops through the used portion of the array adjusting the position so that the screen will scroll.
Don't forget to reset the start value before entering the loop.
If you're not sure why I programmed it the way I did, then you probably won't be able to make it work right.
So, if you need some clarification on how the program is setup, let me know.

Oster200
13
Years of Service
User Offline
Joined: 21st Jan 2011
Location:
Posted: 1st Apr 2011 01:43 Edited at: 2nd Apr 2011 23:01
i still dont understand how to make the screen move for another sprite i tried to put another while loop but that dosent work this is how im placing it
this freezes the game how do i make the enemys move left and right i dont understand how to put that in.
DeadTomGC
13
Years of Service
User Offline
Joined: 11th Aug 2010
Location: LU
Posted: 3rd Apr 2011 07:50
Ok, lets say that you want sprite 1000 to move like the blocks do.
Just Add this line of code after all the other blocks are updated in leftright and before x=100; or x=500;



Here is the complete leftright function.

From here you can choose to put any number of update commands where I put that one. This is best accomplished with loops (what I did for the blocks).

Oster200
13
Years of Service
User Offline
Joined: 21st Jan 2011
Location:
Posted: 3rd Apr 2011 08:18
Okay, well i put that code in and when i push left or right button it moves over a lttle bit and then goes back. so i copied your code does same thing.
DeadTomGC
13
Years of Service
User Offline
Joined: 11th Aug 2010
Location: LU
Posted: 4th Apr 2011 02:24
??? are you sure that there is nothing else altering the sprite?
That is the same thing I do for all the blocks.

Oster200
13
Years of Service
User Offline
Joined: 21st Jan 2011
Location:
Posted: 4th Apr 2011 03:24 Edited at: 6th Apr 2011 02:54
Well i have the code you told me where it should be and i moved where i placed the

under the return key function just to see if it would work some where else and it works there but where would i place that dbSprite code if i didnt want to push return or anyother key?
if i confused you already just to clear things up i have this for my leftright function

and this is where i have the dbsprite image because it dosent work some where else



edit

I found it out i had to put it by all the other dbSprites i dint even think about that till now lol
DeadTomGC
13
Years of Service
User Offline
Joined: 11th Aug 2010
Location: LU
Posted: 6th Apr 2011 04:53
Sorry I took so long to get back to you. Calc exam.
Have you tried putting the dbSprite(1000,0,0,1000) before the loop in main.cpp?
Also, does it work the way it should with the current code is after the return key has been held for some time?

Oster200
13
Years of Service
User Offline
Joined: 21st Jan 2011
Location:
Posted: 6th Apr 2011 05:20
WOW big exam hope you did well on it. yeah everything works well on it now. i do have a question, how would i change the sprite example if the player collides with lets say a flame flower it turn red i could always use that hue thing or somthing like that but how would i change the sprite to a compltly diffrent sprite?
DeadTomGC
13
Years of Service
User Offline
Joined: 11th Aug 2010
Location: LU
Posted: 6th Apr 2011 23:38 Edited at: 7th Apr 2011 06:28
As long as every where you control the sprite you use dbSpriteImage(n), you could just use dbSprite(n,x,y,I);

Btw, I actually did do well on that exam. 95% top mark in the class which is really something for me.

Oster200
13
Years of Service
User Offline
Joined: 21st Jan 2011
Location:
Posted: 7th Apr 2011 02:34
WOW you did really good! congrats. math is my best subject but i rarly do that good

Login to post a reply

Server time is: 2024-04-23 13:54:04
Your offset time is: 2024-04-23 13:54:04