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 / Simple 2D Gravty

Author
Message
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 6th Aug 2010 06:19 Edited at: 6th Aug 2010 06:21
OK i am planning on making a remakes of Heli Attack 2 (off Miniclip as well as other sites). I am an experiences DBC Programmer and have a lil knowledge of C++.

Anyway when this is run it should create the "player" (currently just a filler image and basic physics data) in the top-left corner and let it fall until it hits an invisible floor (the floor is on bitmap 1), but its not working and i cant figure out why.

also whenever i put breakpoints in they say something about not working because the source code changed or something......idk)

any ideas? feel free to ask questions



bloodmage2
15
Years of Service
User Offline
Joined: 14th Jun 2009
Location:
Posted: 6th Aug 2010 19:00
well, for starters, you probably shouldn't use dbPoint for this. my best suggestion would be to create a 2x2 array (int arrayname[2][2]), where the first index determines the x/y, the second index determines start/end. you fill this with the points where the invisible floor (a rectangle) start and end. then, use this data to see if the player will either hit or pass through the block during the next move, if it will, place it on the floor, and set the jump speed to 0.

just a tip, with



you could change it to


and have the same effect, but neater and faster.

-to the optimist, the glass is half full. to the pessimist, it is half empty, to the engineer, it is twice as big as it needs to be.
http://www.lionsbloodstudios.justinman.net/index.htm
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 6th Aug 2010 19:17
i like your idea for changing the code in the snippets, im surprised i didnt think of that....

but about the array, there are 2 reasons why it wont work for me:

1. it wont just be flat floors on the BMP. there will also be hills and other terrain features, as well as different colors for other collision detections: enemies will be another color, players (I plan on making this multiplayer eventually) will have a designated color, bullets.....etc.

2.I plan on turning the BMP into a memblock each cycle and design a function similar to Point() that checks the memblock (this method was faster in DBC, so im assuming it will be in DarkGDK also)

Cuddle Bunniezzz 12
15
Years of Service
User Offline
Joined: 14th Jan 2009
Location: Buffalo, NY
Posted: 7th Aug 2010 17:34
Hmmm... Instead of using bitmaps, why don't you make a class that creates an imaginary box and uses it for collision detection.

Here is an example class:


I'd write the code for the friend function, but I kind of don't have the time to right now. When I do get home in a few hours I will. But if you feel like doing it yourself, what you will need to do is check if the boxes are overlapping inside that function.

And if you are debugging it, you can use the "dbLine()" function to draw four lines to visualize the box.

http://ref.darkgdk.us/ <- Online DarkGDK Refernece. More content coming soon.
bloodmage2
15
Years of Service
User Offline
Joined: 14th Jun 2009
Location:
Posted: 7th Aug 2010 19:53
that is quite literally, verbatim what i suggested.

anywho, what you can do if the terrain is uneven, you can have slots in the array for each. now what you do for slanted surfaces is check if the path of the character will intersect with the surface.

you have two lines: the line of the character from now to after this move, and the start and end of the slant. each has a slope, this is found by (y of end - y of start)/(x of end - x of start). once you have the slope, you can find y intercept, by "following" the slope to x=0. doing this, you can find both lines equations, and by doing so, you can calculate where they intersect. if the x of the point of intersection is between the start and end x of the player, the player would pass through, and you can the place the character where it would hit the ground.

in summary:
take 4 points, each with x and y: player and slant, now and after,
using m = (y2-y1)/(x2-x1), you can find the slope of both lines.
use slope to find the y intercept (this is called b)
y = mx+b
find the intersection point (player m * x + player b = slant m * x + slant b, find x)
if this value is inbetween the player now and after x, the player is going to hit the ground.

-to the optimist, the glass is half full. to the pessimist, it is half empty, to the engineer, it is twice as big as it needs to be.
http://www.lionsbloodstudios.justinman.net/index.htm
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 8th Aug 2010 02:13
ok...yes i am familiar with slope and line equations, i got an A in Alg. 2 last year....im not getting what ur meaning by slant line tho.....perhaps a small code example is in order?

and could someone please explain why my program isnt working as is? because this method worked in DBC.......my main issue here is that the program doesnt work, i can re-work things for efficiency after it gets working

thanks for the ideas tho!

Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 8th Aug 2010 17:07
I tested your original code and there are two problems with it. First, the JumpSpeed is not initialized to anything. Do not assume that it will be zero because it won't. It will be garbage. Therefore the first time when you try to compare it with something, the result is unpredictable. If you initialize the JumpSpeed to zero, then the player image will start falling.

But it will never stop falling because there is also a problem with the colour values. You might not have noticed but for three collision tests you used the RGB function, while for the fourth (bottom) collision you used the dbRGB function. These return different values. dbRGB appends the alpha value at the beginning, making the number hexa FF000000 larger. Therefore this equation test will never be true. If you exchange that function to RGB like all the rest, it will work and the player image will stop at the floor.

P.S. There was actually a third problem. What's that System("CLS") call? Exchange it for dbCLS(DWORD(0x000000)) or something similar because this does not even compile.
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 9th Aug 2010 01:15 Edited at: 9th Aug 2010 01:40
thanks bigtime.

and maybe i typoed that command, but there is some command similar to this that is basically a clear screen command, ill just use urs tho

edit:

and it works


Login to post a reply

Server time is: 2024-11-19 20:44:44
Your offset time is: 2024-11-19 20:44:44