make an image transparent? and better collision?

Started by MisterN, December 28, 2011, 04:48:34 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

MisterN

1. How can I make an image fully transparent? And then another thing id like to know is, is there a code where I can make a certain color transparent?

2 (THE MAIN QUESTION). I need some better collision detection, ive noticed (because ive colored in the transparencies to see) that collision isnt done fine. its always been kinda crappy, but at this point i need something more better. Here is an example using the player.

        //Player Movement 
        if (key (_left))
            flags = 1;
            dir = -1;           
            ii = 0;
            while (ii <4) 
                pixel = map_get_pixel(0, levelmask, playerx-11, playery);   
                get_rgb (pixel, & red, & green, & blue); 
                if (blue<220 or x==topx) 
                    ii = 0;
                    break; 
                else 
                    if (player_status!=2 and player_status!=3 and player_status!=6 and player_status!=7) player_status=1; end
                    walking=true;
                end               
                ii = ii + 1; 
            end 
            x = x-ii; 
        end 
        if (key (_right)) 
            flags = 0;
            dir = 1;
            ii = 0;
            while (ii <4)
                pixel = map_get_pixel(0, levelmask, playerx+11, playery); 
                get_rgb (pixel, & red, & green, & blue); 
                if (blue<220 or x==botx) 
                    ii = 0;
                    break; 
                else 
                    if (player_status!=2 and player_status!=3 and player_status!=6 and player_status!=7) player_status=1; end
                    walking=true;
                end   
                ii = ii + 1;
            end 
            x = x + ii;
        end


        // Jumping 
        if (key (__A))
            if(!key_jump_is_already_pressed)
                if(gun_ready)
                    player_status=6;
                else
                    player_status=2;
                end
            falling=true;
            pixel = map_get_pixel(0, levelmask, x, y +16);   
            get_rgb (pixel, & red, & green, & blue);   
            if (blue<220)
                play_wav(jump_sound,0);
                fall =- 20;   
            end
            pixel = map_get_pixel(0, levelmask, x+6, y +16);   
            get_rgb (pixel, & red, & green, & blue);   
            if (blue<220)
                play_wav(jump_sound,0);
                fall =- 20;   
            end
            pixel = map_get_pixel(0, levelmask, x-6, y +16);   
            get_rgb (pixel, & red, & green, & blue);   
            if (blue<220)
                play_wav(jump_sound,0);
                fall =- 20;   
            end
           
        end
            key_jump_is_already_pressed = true;//as long as x is held down, this is true
          else
            key_jump_is_already_pressed = false;//once space is released, this is false         
        end

        // Implementation of fall.   
        ii = fall;   
        if(ii > 0)
            while(ii != 0)
                pixel=map_get_pixel(0, levelmask, x+6, y + (fall-ii) +15); //falling onto the left side of the mask
                get_rgb (pixel, & red, & green, & blue);   
                if (blue<220) 
                    ii = ii + 1;
                    falling=false;
                        if(!walking);
                            player_status=0;
                        else
                            player_status=1;
                        end
                    break; 
                end
                pixel=map_get_pixel(0, levelmask, x-6, y + (fall-ii) +15); //falling onto the right side of the mask
                get_rgb (pixel, & red, & green, & blue);   
                if (blue<220) 
                    ii = ii + 1;
                    falling=false;
                        if(!walking);
                            player_status=0;
                        else
                            player_status=1;
                        end
                    break; 
                end
                pixel=map_get_pixel(0, levelmask, x, y + (fall-ii) +15); //falling onto the right side of the mask
                get_rgb (pixel, & red, & green, & blue);   
                if (blue<220) 
                    ii = ii + 1;
                    falling=false;
                        if(!walking);
                            player_status=0;
                        else
                            player_status=1;
                        end
                    break; 
                end
               
                ii = ii - 1; 
            end   
        else   
            ii = 0; 
        end
   
        // Move the fall until we can.   
        y = y + (fall-ii);


PROBLEMS:
*If you are right under a platform(a 32 height hallway), you jump right through.
*Sometimes you can sidewalk up the walls
*if the ceiling "stairs" you get caught on it
*sometime if you land at an angel, you will be partially in the platform and slowly rise up properly

I was hoping a collison box would work like you said but it didnt
collision_box(type player_collision_box); That is the code I am using.
the player is 32x32 and the collision box is 18x24 so I don't know whats wrong

do you know of any better collision systems I can use for this? thanks!
werg

gecko

the collision_box() (and collision() also) function is used to calculate collision between two processes.  For hardnesses maps and levels it's ok to use the map_get_pixel() functions.
Torres Baldi Studio
http://torresbaldi.com

MisterN

but can you give me an example of the first two? am i using the collision box right?
werg

josebita

Not sure if I understood you well, but the normal collision system should be more accurate than collision_box():
if ( collision(TYPE anything) )
    dosomething;
end

As a side note, when doing platformers, it's typical to implement this kind of things with hardness maps although it should be doable with collision_box().

Anyway, the problems you mention are quite typical when creating a platformer and usually come from not checking the hardness map well enough. Although your code looks nice (you seem to check the full movement line, which might be a bit overkill, but it's fine) if you share a working example of your code, we might be able to help better.

MisterN

I wont upload my code online however pm me your email and i will send it to you
werg