Update about stuff I guess.

Posted by Charlie Carlo on July 19, 2012, 5:23 p.m.

Okay, so after about two weeks of arduous trial-and-error, and the help of Poly and Spectre, I now have a sorta-good-maybe shadow engine for an untitled game that isn't Settle.

It looks like this.

If you tear off its skin, it looks like this.

{
    //Draw Background
    if surface_exists(global.sur_main)
                {
                surface_set_target(global.sur_main)
                    draw_background_tiled(par_croom.setback,0-view_xview[0],0-view_yview[0])
                surface_reset_target()
                }
    //Draw Shadows
    if surface_exists(global.sur_5)
                {
                surface_set_target(global.sur_5);
                    draw_set_color(make_color_rgb(237,239,199));
                    draw_rectangle(0,0,view_wview[0],view_hview[0],0);
                    draw_set_color(c_white);
                surface_reset_target()
                }               
    with par_light {
        var me;
        depth=19;
        me=id;
        if (instance_exists(par_hasshadow))
        {
            if surface_exists(global.sur_1)
                {
                surface_set_target(global.sur_1)
                    draw_set_color(c_white);
                    draw_rectangle(0,0,view_wview[0],view_hview[0],0);
                    with (par_hasshadow)
                    {
                    draw_sprite_ext(sprite_index,image_index,
                        (x-(me.x-x)/4)-view_xview[0],
                        (y-(me.y-y)/4)-view_yview[0],
                        image_xscale*1.25,
                        image_yscale*1.25,
                        image_angle,
                        c_black,
                        1);
                    }
                }
            surface_reset_target();
            if surface_exists(global.sur_2)
                {
                surface_set_target(global.sur_2);
                    draw_set_color(c_white);
                    draw_rectangle(0,0,view_wview[0],view_hview[0],0);
                    draw_sprite(spr_light,0,x-view_xview[0],y-view_yview[0])
                    draw_set_blend_mode(bm_add);
                    draw_surface(global.sur_1,0,0);
                    draw_set_blend_mode(bm_normal);
                }
            surface_reset_target();
            if surface_exists(global.sur_3)
                {
                surface_set_target(global.sur_3);
                    draw_set_color(c_white);
                    draw_rectangle(0,0,view_wview[0],view_hview[0],0);
                    draw_set_blend_mode(bm_subtract);
                    draw_surface(global.sur_2,0,0);
                    draw_set_blend_mode(bm_normal);
                }
            surface_reset_target();
            if surface_exists(global.sur_main)
                {
                surface_set_target(global.sur_main);         
                    draw_set_blend_mode(bm_subtract);
                    draw_surface(global.sur_3,0,0);
                    draw_set_blend_mode(bm_normal);
                }  
            surface_reset_target();
            if surface_exists(global.sur_5)
                {
                surface_set_target(global.sur_5);
                    draw_set_blend_mode(bm_subtract);
                    draw_sprite(spr_shadow,0,x-view_xview[0],y-view_yview[0]);
                    draw_set_blend_mode(bm_normal);
                }
            }      
    //Draw Objects with Shadows
        with par_hasshadow {
            surface_reset_target();
            if surface_exists(global.sur_main)
                {
                surface_set_target(global.sur_main);         
                    if instance_exists(par_light)
                    if point_distance(x,y,instance_nearest(x,y,par_light).x,instance_nearest(x,y,par_light).y) < 255
                    {
                        draw_sprite_ext(sprite_index,image_index,x-view_xview[0],y-view_yview[0],image_xscale,image_yscale,image_angle,
                        make_color_rgb(
                        255-point_distance(x,y,instance_nearest(x,y,par_light).x,instance_nearest(x,y,par_light).y),
                        255-point_distance(x,y,instance_nearest(x,y,par_light).x,instance_nearest(x,y,par_light).y),
                        255-point_distance(x,y,instance_nearest(x,y,par_light).x,instance_nearest(x,y,par_light).y)),
                        image_alpha)
                    }
                else
                    draw_sprite_ext(sprite_index,image_index,x-view_xview[0],y-view_yview[0],image_xscale,image_yscale,image_angle,c_black,image_alpha)
                    }               
                }
    //Draw Objects without Shadows
        with par_noshadow {
            surface_reset_target();
            if surface_exists(global.sur_main)
                {
                surface_set_target(global.sur_main);         
                    draw_sprite_ext(sprite_index,image_index,x-view_xview[0],y-view_yview[0],image_xscale,image_yscale,image_angle,c_white,image_alpha)               
                }
            }
    //Draw Foreground
    if surface_exists(global.sur_main)
                {
                surface_set_target(global.sur_main);
                    draw_background_tiled(par_croom.setfore,0-view_xview[0],0-view_yview[0]);
                surface_reset_target()
                }
    //Draw Shading
    if surface_exists(global.sur_4)
                {
                surface_set_target(global.sur_4);
                draw_set_color(c_black);
                draw_rectangle(0,0,view_wview[0],view_hview[0],0);
                draw_set_color(c_white);
                surface_reset_target();
                }
        with par_shading {
            surface_reset_target();
            if surface_exists(global.sur_4)
                {
                surface_set_target(global.sur_4);
                draw_sprite(sprite_index,image_index,x-view_xview[0],y-view_yview[0]);
                }
            }
    //Draw Lights
        with par_light{
            surface_reset_target();
                if surface_exists(global.sur_main)
                    {
                    surface_set_target(global.sur_main);
                    draw_set_blend_mode(bm_add);
                    draw_sprite_ext(spr_neglight,0,x-view_xview[0],y-view_yview[0],1,1,0,c_white,0.1);
                    draw_set_blend_mode(bm_normal);
                    }
                }
    //Draw EVERYTHING
        surface_reset_target();
        draw_surface_ext(global.sur_main,0,0,view_wport[0]/view_wview[0],view_hport[0]/view_hview[0],0,c_white,1);
        draw_set_blend_mode(bm_subtract);
        draw_surface_ext(global.sur_4,0,0,view_wport[0]/view_wview[0],view_hport[0]/view_hview[0],0,c_white,1);
        draw_surface_ext(global.sur_5,0,0,view_wport[0]/view_wview[0],view_hport[0]/view_hview[0],0,c_white,0.8);
        draw_set_blend_mode(bm_normal);

        }
}
Edit: I'll admit that I don't know the BB Code to put text into a collapsible singularity.

You guys have any thoughts/opinions/scrutiny/criticism/praise/hobbies to share, put them in boxes under this bigger one. I like feedback.

Edit: Dideo.

Comments

Polystyrene Man 12 years, 4 months ago

Looks great!

My recommendation, for your sanity, is to turn stuff that you use repeatedly like this

view_wport[0]/view_wview[0],view_hport[0]/view_hview[0]

into variables. Declare them at the start of your code. Call it something like xScale and yScale.

Charlie Carlo 12 years, 4 months ago

Dude, for my sanity, I plan on never altering this code again (despite the fact that I just altered it to draw the lights before drawing the foreground). It'll just sit there in the background like a forgotten peacekeeper. Reason is it's code; and I rock the D&D.

LAR Games 12 years, 4 months ago

Wow. That's awesome. Works really well with the style of the graphics too.

Praying Mantis 12 years, 4 months ago

Looking excellent! That character art is exceptional too; really good pixel art technique.

Taizen Chisou 12 years, 4 months ago

that's pretty damn sexy

quite a ways from the "smatter shadow blocks with opacity relative to distance to player on room" approach, isn't it :V

Charlie Carlo 12 years, 4 months ago

Quote:
quite a ways from the "smatter shadow blocks with opacity relative to distance to player on room" approach, isn't it :V
Yeah, but not quite as 'elegant'.

Cpsgames 12 years, 4 months ago

I love your art style. Real unique. Great stuff!