Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Allegro collision detection

Name: Anonymous 2010-05-11 12:59

bool Player::collide(int x, int y, BITMAP* object)
{
    for (int px = 0; px < 20; px++)
    {
        for (int py = 0; py < 20; px++)
        {
            if (getpixel(image,px+x,py=y)!=bitmap_mask_color(image))
            {
                if (getpixel(object,xPos+px+x,yPos+py+y)!=bitmap_mask_color(object))
                {
                    return true;
                    break;
                }
            }
        }
    }
    return false;
}

xPos and yPos speak for themselves
x and y are the potential changes to the xPos and yPos, if this method returns false, they will be made.
image is a 20x20px player image.
object is my arena made from a tileset, pieced together by a vector of strings, each character in the vector representing a tile.

However, my player resolutely refuses to fall when gravity tells him to, or the program crashes. Either he's colliding with something (He shouldn't be, he's surrounded by masked squares) or some crazy voodoo is eating my datas.

any ideas?

Name: Anonymous 2010-05-11 21:14

>>8
most compilers output cleaner code for ++var
Sigh. Why must this ridiculous myth be perpetuated? Any competent compiler will produce exactly the same output for either expression if the result is unused.

$ echo 'int f(int x) { ++x; return x; }' > pre.c
$ echo 'int f(int x) { x++; return x; }' > post.c
$ gcc -S *.c
$ diff *.s
1c1
<       .file   "post.c"
---
>
       .file   "pre.c"
$ rm *.s
$ clang -S *.c
$ diff *.s
1c1
<       .file   "post.c"
---
>
       .file   "pre.c"
$ rm *.s
$ pcc -S pre.c
$ pcc -S post.c

$ diff *.s
$ rm *.s
$ cp pre.c pre.d
$ cp post.c post.d
$ dmd -s *.d
$ objdump -d pre.o > pre.dump
$ objdump -d post.o > post.dump
$ diff pre.dump post.dump
2c2
< pre.o:     file format elf32-i386
---
>
post.o:     file format elf32-i386
18c18
< Disassembly of section .text._D3pre1fFiZi:
---
>
Disassembly of section .text._D4post1fFiZi:
20c20
< 00000000 <_D3pre1fFiZi>:
---
>
00000000 <_D4post1fFiZi>:
$ rm *.o *.d *.dump


Do go on about how the code produced by ++var is in any way cleaner.

(I don't have icc or msvc on hand at the moment, but I have no expectation that their output would be at all different from the above.)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List