SDL Collide & Euphoria, eh, colliding...
- Posted by Steve <bleak_outlook at hotmail.com> Jun 10, 2006
- 654 views
A couple weeks back I entertained the idea of trying to learn C again. The torpid tale that lies ahead is the exact reason I am going to put it off until next year... Ok, my current game project demands collision detection. This leaves me a couple options; 1. Try to write a wrapper for an SDL lib or 2. Write one in euphoria. I played around with option one thinking it would be trivial to build a dll and then write the simple wrapper for it. After about 3 hours of wandering the source code and drooling on myself I decided that compiling a dll is not a newb thing. My next idea (and here is where I get real bright), was to just rewrite the entire library into euphoria code. I thought, "yeah, maybe I'll learn something." Needless to say here I am. The good news is that I managed to rewrite everything but one function. The actual "hunt for a pixel perfect collision" function. This is just to 'C' omplicated for my sad little brain. The difficult part is that I have no idea what it is doing in some places. Can someone with some SDL + C experience give me an Eu-ish description of this function? Your help would be extremely appreciated. The offensive code: int SDL_CollideTransparentPixelTest(SDL_Surface *surface,int u,int v) { int bpp = surface->format->BytesPerPixel; /*here p is the address to the pixel we want to retrieve*/ Uint8 *p = (Uint8 *)surface->pixels + v * surface->pitch + u * bpp; Uint32 pixelcolor; switch(bpp) { case(1): pixelcolor = *p; break; case(2): pixelcolor = *(Uint16 *)p; break; case(3): -- How can I test for endian-ness in Eu? if(SDL_BYTEORDER == SDL_BIG_ENDIAN) pixelcolor = p[0] << 16 | p[1] << 8 | p[2]; else pixelcolor = p[0] | p[1] << 8 | p[2] << 16; break; case(4): pixelcolor = *(Uint32 *)p; break; } /*test whether pixels color == color of transparent pixels for that surface*/ return (pixelcolor == surface->format->colorkey); } What the heck is with all this recasting and carrying on ?!? How do I *recast* a dataobject in Eu? Does this require auditioning? ;) I really wanted to do this on my own to learn it, a small step towards learning how to wrap libraries, etc, etc. I just don't think I am going to get anywhere without a kick in the right direction. Thanks again!