Sign in to follow this  
EclipseNightshade

Gamemaker Studio: Dynamic Shadow Issues

Recommended Posts

So, I gave it a few rounds, but in the 3rd I lost miserably.

 

I'm attempting to add a dynamic lighting system into my game, but the shadows portion (which is the only portion left) is kicking my furry end to the curb.

 

My algorithms, which are in utterly proper syntax, look as though they'd work quite well at finding the four points I need to draw the shadow on. First I find an edge, then create two point off it, and have the system circle around until it finds the other edge of whatever object it's near to create the other points. But for some reason, mostly randomized points re found instead.

 

The following shows the result of my system. The green and purple dots are supposed to be the furthest extreme of the shadows, while the blue and red dots are supposed to be where the shadows start. As is plainly visible, the only one that seems to be working at even 80% is the blue.

 

If the dots are only supposed to be appearing at the corners of the blocks and quite a bit past them, then not even 20% of the visible dots should even exist.

 

I'll have a download to my system available upon request.

 

{EDIT}

Never mind, I'll just post the code here.

 

 

/*~F***ing THING WON'T WORK~*/
/*~NOT PROPERLY ANYWAY~*/
intensity = 200;
test = 0;
fin = -359;
tri1x = 0;
tri1y = 0;
tri2y = 0;
tri2x = 0;
tri3y = 0;
tri3x = 0;
tri4y = 0;
tri4x = 0;
findr=0;
find1 = false;
//make sure there isn't a collision straight into testing so as to be sure all edges are found
while(collision_line(x,y,x+(intensity*cos(test)),y+(intensity*sin(test)),obj_block,true,false)){
    test--;
    fin++;
}
while(test > fin){//test all 360 degrees
    if(find1 == false){
        //keep circling until a collision is found
        if(collision_line(x,y,x+((intensity/2)*cos(test)),y+((intensity/2)*sin(test)),obj_block,true,false)){
            //set green dot location
            tri1x = x+((intensity*0.75)*cos(test));
            tri1y = y+((intensity*0.75)*sin(test));
            //find radius to blue location
            findr=0;
            while(!collision_line(x,y,x+((findr)*cos(test)),y+((findr)*sin(test)),obj_block,true,false)){
                findr++;
            }
            //set blue location
            tri2x = x+((findr)*cos(test));
            tri2y = y+((findr)*sin(test));
            find1 = true;
        }
    }
    if(find1==true){
        //continuously circle until the end of the object's image is found
        while(collision_line(x,y,x+((intensity)*cos(test)),y+((intensity)*sin(test)),obj_block,true,false)){
            test--;
            //set purple location
            tri3x = x+((intensity*0.75)*cos(test));
            tri3y = y+((intensity*0.75)*sin(test));
        }
        //find the radius for the red location
        if(!collision_line(x,y,x+((intensity/2)*cos(test)),y+((intensity/2)*sin(test)),obj_block,true,false)){
            findr=0;
            while(!collision_line(x,y,x+((findr)*cos(test)),y+((findr)*sin(test)),obj_block,true,false) && findr < intensity*0.75){
                findr++;
            }
            //set red location
            tri4x = x+((findr)*cos(test));
            tri4y = y+((findr)*sin(test));
            find1 = false;
        }
    }
    //draw_dots
    draw_set_color(c_green);
    draw_ellipse(tri1x+5,tri1y+5,tri1x-5,tri1y-5,0);
    draw_set_color(c_blue);
    draw_ellipse(tri2x+5,tri2y+5,tri2x-5,tri2y-5,0);
    draw_set_color(c_purple);
    draw_ellipse(tri3x+5,tri3y+5,tri3x-5,tri3y-5,0);
    draw_set_color(c_red);
    draw_ellipse(tri4x+5,tri4y+5,tri4x-5,tri4y-5,0);
    //draw shadows
    /*draw_set_color(c_black);
    draw_triangle(tri1x,tri1y,tri2x,tri2y,tri3x,tri3y,0);
    draw_triangle(tri2x,tri2y,tri3x,tri3y,tri4x,tri4y,0);*/
    
    test--;//decrement the test angle
}

 

 

Edited by EclipseNightshade

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Join the herd!

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.