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 / GDK Limitations

Author
Message
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 21st Apr 2008 05:24
I'm no expert, but the GDK seems to have some limitations. Correct me if I'm wrong, but the GDK doesn't seem to easily support either of these features:

Loading a partial section of a large bitmap ( something like dbLoadImage ( "World Map.bmp", 32, 32, 64, 64, 1 ) to load, say, a small tile in the larger image.

Detecting collision with any foreground sprites with one command
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 21st Apr 2008 06:25
Quote: "Loading a partial section of a large bitmap ( something like dbLoadImage ( "World Map.bmp", 32, 32, 64, 64, 1 ) to load, say, a small tile in the larger image."


Copy a portion of the bitmap to another bitmap.

Quote: "Detecting collision with any foreground sprites with one command"


Seems easy enough to roll your own.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 21st Apr 2008 15:35
I don't get how to detect collision with any on screen sprites at once. The only collision command checks collision with one sprite. It would be in efficient and near impossible to make a loop that checked for collision with every single sprite.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 21st Apr 2008 17:14
Yes it would - that's why you specify a target sprite number of zero.

For example:


Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 21st Apr 2008 17:24
What he said. And if you need to check for all sprites..



Lilith, Night Butterfly
I'm not a programmer but I play one in the office
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 21st Apr 2008 18:09
Lilith - I don't like the if sprite exist thing in there. Perfect code snippet - just don't like that approach. I don't trust how fast it is, nor like the possibility of looping over "id's" that are just not in use.

I recommend for the poster that if he/she use this technique, he have an array/list of sprites that are guaranteed to exist, so no clock cycles are wasted on duds.

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 21st Apr 2008 18:19
Thank you for pointing out the zero target. I missed that usage in the documentation.

Also, how would I prevent it from detecting collision with the background I have set up? Would I hide the background sprite before I check for collision and show the background after the check?
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 21st Apr 2008 18:30
Your backdrop is a sprite? In that case you have a problem, unless you go back to individual checks that exclude the background sprites - Jasons idea of using a list of sprites that you can collide with is the best way to go here.

Alternatively, you could simply paste the image to your backdrop instead of using a sprite.

Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 21st Apr 2008 18:31
I agree, although some of the tutorials show this very approach. I was just showing that it is relatively easy to support such actions. Keeping an array of active sprites can have it's own hassles but just not as often as checking for collision every cycle. The OP wasn't clear as to whether he was wanted to check all items for collisions or one sprite against all the others.

On this score I'd like to point to an excellent series of articles, for those who haven't seen it, on GameDev.net called Enginuity. The first in the series is at

http://www.gamedev.net/reference/programming/features/enginuity1/

and the others can be found via links from the first. I followed the article through to a point but got a bit hung up when I got to the subject of functors. However, just the other day I stumbled on a Wiki article that gave me some insight. I'll probably go back and re-read the Enginuity article again. I've copied and pasted the article into Word and have a bound copy of it to read when away from my computer.

AAR, the reason for the mention is that the author uses vectors (which I always thought were ill-named) to track the items he's creating. With vectors you can selectively remove an element from the series without leaving gaps but it probably incurs some time at some point to check for dead objects.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 21st Apr 2008 18:43 Edited at: 21st Apr 2008 18:48
Quote: "I'll probably go back and re-read the Enginuity article again. I've copied and pasted the article into Word and have a bound copy of it to read when away from my computer."

[edited tags]

Good idea - I need more black ink

Again - your post was fine - and the code infallible.

I Agree VECTORS are the stupidest name for dynamic double linked lists! You know what I call my homemade brew of "Vectors"? Simply: DL

The ITERATOR is JFC_DL and the Items it manages have a base class named JFC_DLITEM (JFC = Jegas Foundation Class - My Licensed LLC company name) Which is "J" from Jason and my last name Backwards EGAS... but I digress....

I have to go read this article now thanx for that one.

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 21st Apr 2008 19:18
Quote: "VECTORS are the stupidest name for dynamic double linked lists"

That's because that is not what they are.

Vectors are dynamically allocated arrays - when you add extra data and that takes you beyond the reserved memory for that array, then new memory is allocated and all items copied across. Then the old memory is released. When you delete from the middle, all items past that point are moved back one, and when you insert, all items are moved up one - not fast.

Lists are the double linked lists and allocate on a node-by-node basis.

Deques are the cross between the two - basically a linked list of small dynamic arrays, providing random access (not as fast as vectors, but not possible for lists) and fast insert/delete (not as fast as list, but not as slow as vector).

For a list of integers though, which is what you need for sprite id's, I'd probably go with a vector - much less memory overhead than a list, and the insert/delete isn't too much of a problem - moving items around simply degenerates into the moral equivalent of memmove.

jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 21st Apr 2008 19:22
Same difference... vector is still a dumb name. Call it what it is.

I know - just got which is which screwed up. Still a dumb name.

Vector == Array == Dumb as calling mesh points "normals" IMHO

Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 21st Apr 2008 19:34 Edited at: 21st Apr 2008 19:34
My "irk" over the use of the term is that, having a degree in physics with a minor in math, vector has a totally different meaning. I'd allow that a std::vector can be used to represent a spacial vector along with a time dimension. But to use the term to represent a list of indeterminate length is counter intuitive.

I'm not claiming I have a better name for it, just that there's a bit of confusion on my part as to why it was used in this context. The first time I came across the term (I was away from programming when the std libraries came into official usage) I thought the programmer was actually using it to describe spacial dimensions. It also caused confusion when I created my own vector class for that very purpose and ended up with conflicts I didn't understand,

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 21st Apr 2008 19:55
I have found many sites with tutorials on collision systems for 2d sidescrollers, RPG's, etc. But they are all for other languages. I tried using some of the techniques in the DarkGDK and ran into problems. Thank you for clearing up the confusion I had over the collision command.

I am working on a side-scroller. I want to detect collision each frame between the character sprite and the world. The background is currently a sprite, so, any help with doing that differently would be appreciated.

Also, I was planning on following the method of using a few tiles to make everything in the world ( old school mario style ) where I can reference every copy of one tile at once. What would be the best method to do this?

Also, scrolling the world by detecting the position of the character ( once again, play the original mario to see what I mean ). Any suggestions for doing this in the DarkGDK ( no links, I got plenty. actual usage in the DarkGDK )? ( I'm very new to this. )
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 21st Apr 2008 20:07
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 21st Apr 2008 20:11
Da!!

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 21st Apr 2008 20:18
I'm still learning C++, so, what is the difference between an array and a dynamic array?
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 21st Apr 2008 20:19
My feeling is that you need to update the position of pretty much everything on the screen during each iteration of your loop. Each one of these objects potentially needs to check collision with your "mario." Why not check for the collision during their update phase?

If you're going with the standard Mario scenario then each of your objects are not only going to need to check for collision with your player, they'll also need to know when they bump into each other so they can reverse direction. You'll also have your breakable bricks that you'll need to check for, your eatable mushrooms, etc. Of course, all you really need to account for is what's either on the screen at the time or what's about to come up. If it were me I'd probably put my objects in an array that's arranged based on their horizontal position on the screen. That means that each iteration through the loop I'd only have to deal with the range within the array that's appearing on the screen at the time.

I don't know what I'd do about the background tiling, whether it would be an image reflected in one sprite or a series of sprites. Even then you only have to have enough to handle the visible screen and a bit to either side, not enough for the whole world. I'd strive to keep the player's character in the center of the screen, horizontally speaking, and calculate everything else to position itself around the player. I'd probably hedge to keep the player from moving to the left of center at the far left of the world and the same for the far right of the world.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 21st Apr 2008 20:22
Sorry, you were talking about renaming vectors. My bad.
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 21st Apr 2008 21:02
The background doesn't have to be tile-based. It can be static if easier. It may just be me not having enough experience, but I don't really get what exactly you are suggesting. I think what you're saying is that, basically, I need an array that is ( length of world in number of tiles ) x ( height of world in number of tiles ). Each value the type of tile. Each type of tile ( brick, breakable-brick, mushroom, etc. ) would have it's own descriptors ( passable, breakable, enemy, etc. ). I would keep "mario" in one centered position throughout with the world moving around him.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 21st Apr 2008 23:14
To be honest with you I wouldn't even begin to look at how I'd tile a background until I really got into it, which I'm not prepared to do at the moment. In large, I'd leave the background as just that, background. Using Mario by way of explanation the background would be nothing more than clouds, mountains or buildings that offer no interaction with the play. But it would need to scroll to some extent , a bit slower than the foreground to enhance the feeling of distance.

The foreground would be everything that interacts with Mario, including the Oopahs (or whatever,) turtles, etc. It would also include the pipes, bricks, flowers, mushrooms, etc. anything that's on the same plane as Mario. Each one of these objects (I'm assuming they're all sprites) would, IMO, have to be not only a sprite but class objects that encapsulate sprites. It can also be done by encapsulating the descriptive elements of the objects in structs. At this point my inclination to be instructive stops at going into explaining classes and structs. That's where you need to start studying. It's entirely possible to do this without class objects but you'd need to have a tracking system based on parallel data storage in a number of different arrays.

AAR, back to what I was saying before, assuming you have an array containing the objects, if you have the array sorted by the horizontal (X) position in the world you only need to determine which ones are on the screen at the moment. Since they're sorted they'd have to be between a certain minimum and a certain maximum index and that would be the range you need to check until the left most object moves off screen and any new ones move in from the right. At this point you move the index points for minimum and maximum checking up to encompass what's now on the screen.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 21st Apr 2008 23:55
I understand the usage of structs. I have learned that much, at least.

Thank you for your help. Hopefully, I can't figure this out. If I ever get anywhere with this, I be sure to post something with thanks to all of you.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 22nd Apr 2008 01:20
Quote: "I'm still learning C++, so, what is the difference between an array and a dynamic array?"


It's relevant to the discussion if a little off from original post. Poster seems happy.

answer:

In C++ when you declare an array - natively: int MyArray[100]; The comile allocates the memory for this 1 time and the Array size is fixed. (Not Dynamic, but Static!)

Dynamic "Array Classes" like "Vector" we discussed, and one I write that does the same thing - is... well, they have an array TYPE declared, then allocate the memory in a "Chunk". If you add more items than the chunk can hold, a BIGGER chunk is made, you data moved to that new chunk, the smaller chunk is released, and life goes on. This is what I refer to as a DYNAMIC ARRAY. (It is NOT Static.)

The logic gets tiny bit trickier with deleting elements.. say from the middle, and there are more ways than one to deal with that scenariio. Sometimes you might leave the "Hole" other times you might shift things to effectively remove the Hole.

Dynamic Linked Lists, as IanM pointed out are "Node" based. Just do a google on that - because I think that's a well used "phrase"... I personally love the "Double Linked List" because you can navigate it like a recordset... move first, move next, move last, etc.

Login to post a reply

Server time is: 2024-09-29 17:18:44
Your offset time is: 2024-09-29 17:18:44