J
jap pagcaliwangan
Guest
So Ive gotten this shadow and light engine to work
.
The problem now is, I cant seem to draw the shadow and the light on one surface. Currently, Im drawing the shadows on the application surface.
Here is the project file: https://drive.google.com/open?id=0B2SZdyVcA3UVRmNCS0t0TkE5MVk
Here is the code:
obj_shadowandlightengine
Create Event
Step Event
Draw Event
The problem now is, I cant seem to draw the shadow and the light on one surface. Currently, Im drawing the shadows on the application surface.
Here is the project file: https://drive.google.com/open?id=0B2SZdyVcA3UVRmNCS0t0TkE5MVk
Here is the code:
obj_shadowandlightengine
Create Event
/// shadow variables
surf = surface_create(room_width,room_height);
shadow = surface_create(room_width,room_height);
surfscale = 1/8;
shON = true // this variable enables and disables the shadow system.
lightRad = 150
pl = obj_player
plX = pl.x
plY = pl.y
plXOld = 0
plYOld = 0
// First border Line
direct1Mod = 0
direct2Mod = 0
trace1 = true
trace2 = true
trace3 = true
trace4 = true
extender = 150 // extra shadow space for close lighting
point3X = 0
point3Y = 0
point4X = 0
point4Y = 0
point1X = 0
point1Y = 0
point2X = 0
point2Y = 0
mover1 = 0
mover2 = 0
surf = surface_create(room_width,room_height);
shadow = surface_create(room_width,room_height);
surfscale = 1/8;
shON = true // this variable enables and disables the shadow system.
lightRad = 150
pl = obj_player
plX = pl.x
plY = pl.y
plXOld = 0
plYOld = 0
// First border Line
direct1Mod = 0
direct2Mod = 0
trace1 = true
trace2 = true
trace3 = true
trace4 = true
extender = 150 // extra shadow space for close lighting
point3X = 0
point3Y = 0
point4X = 0
point4Y = 0
point1X = 0
point1Y = 0
point2X = 0
point2Y = 0
mover1 = 0
mover2 = 0
Step Event
/// draw_shadows
plX = pl.x
plY = pl.y
/*
if (place_meeting(x,y,obj_rayKey)) {
shON = true
}
else {shON = false}
*/
if (shON = true) {
if (point_distance(plX,plY,x,y) < lightRad) {inLight = true}
else {inLight = false}
if (inLight = true) {
while (trace1 = true ) {
direct1 = point_direction(plX,plY,x,y) + direct1Mod
point1X = plX + lengthdir_x(lightRad + extender,direct1)
point1Y = plY + lengthdir_y(lightRad + extender,direct1)
direct1Mod+=0.1
if (!collision_line(plX,plY,point1X,point1Y,id,true,false)) {trace1 = false}
}
while (trace1 = false && trace3 = true) {
point3X = plX + lengthdir_x(mover1,direct1-0.1)
point3Y = plY + lengthdir_y(mover1,direct1-0.1)
mover1 += 0.1
if (collision_circle(point3X,point3Y,1.1,id,true,false)) {trace3 = false}
}
while (trace2 = true ) {
direct2 = point_direction(plX,plY,x,y) + direct2Mod
point2X = plX + lengthdir_x(lightRad + extender,direct2)
point2Y = plY + lengthdir_y(lightRad + extender,direct2)
direct2Mod-=0.1
if (!collision_line(plX,plY,point2X,point2Y,id,true,false)) {trace2 = false}
}
while (trace2 = false && trace4 = true) {
point4X = plX + lengthdir_x(mover2,direct2+0.1)
point4Y = plY + lengthdir_y(mover2,direct2+0.1)
mover2 += 0.1
if (collision_circle(point4X,point4Y,1.1,id,true,false)) {trace4 = false}
}
}
if (plXOld != plX || plYOld != plY) {
trace1 = true
trace2 = true
trace3 = true
trace4 = true
mover1 = 0
mover2 = 0
direct1Mod = 0
direct2Mod = 0
plXOld = plX
plYOld = plY
}
}
plX = pl.x
plY = pl.y
/*
if (place_meeting(x,y,obj_rayKey)) {
shON = true
}
else {shON = false}
*/
if (shON = true) {
if (point_distance(plX,plY,x,y) < lightRad) {inLight = true}
else {inLight = false}
if (inLight = true) {
while (trace1 = true ) {
direct1 = point_direction(plX,plY,x,y) + direct1Mod
point1X = plX + lengthdir_x(lightRad + extender,direct1)
point1Y = plY + lengthdir_y(lightRad + extender,direct1)
direct1Mod+=0.1
if (!collision_line(plX,plY,point1X,point1Y,id,true,false)) {trace1 = false}
}
while (trace1 = false && trace3 = true) {
point3X = plX + lengthdir_x(mover1,direct1-0.1)
point3Y = plY + lengthdir_y(mover1,direct1-0.1)
mover1 += 0.1
if (collision_circle(point3X,point3Y,1.1,id,true,false)) {trace3 = false}
}
while (trace2 = true ) {
direct2 = point_direction(plX,plY,x,y) + direct2Mod
point2X = plX + lengthdir_x(lightRad + extender,direct2)
point2Y = plY + lengthdir_y(lightRad + extender,direct2)
direct2Mod-=0.1
if (!collision_line(plX,plY,point2X,point2Y,id,true,false)) {trace2 = false}
}
while (trace2 = false && trace4 = true) {
point4X = plX + lengthdir_x(mover2,direct2+0.1)
point4Y = plY + lengthdir_y(mover2,direct2+0.1)
mover2 += 0.1
if (collision_circle(point4X,point4Y,1.1,id,true,false)) {trace4 = false}
}
}
if (plXOld != plX || plYOld != plY) {
trace1 = true
trace2 = true
trace3 = true
trace4 = true
mover1 = 0
mover2 = 0
direct1Mod = 0
direct2Mod = 0
plXOld = plX
plYOld = plY
}
}
Draw Event
//meteor shadows
if (point_distance(plX,plY,x,y) < lightRad) {
draw_triangle_color(point1X,point1Y,point2X,point2Y,point3X,point3Y,c_black,c_black,c_black,false);
draw_triangle_color(point2X,point2Y,point3X,point3Y,point4X,point4Y,c_black,c_black,c_black,false);
}
draw_self()
//player light
surface_set_target(surf);
draw_clear(c_black);
with(pl){
draw_set_blend_mode(bm_src_color);
draw_sprite_ext(spr_light,0,x*other.surfscale,y*other.surfscale,1.5,1.5,0,c_white,lightstr);
draw_set_blend_mode(bm_normal);}
surface_reset_target();
draw_surface_ext(surf,0,0,1/surfscale,1/surfscale,0,c_white,1);
if (point_distance(plX,plY,x,y) < lightRad) {
draw_triangle_color(point1X,point1Y,point2X,point2Y,point3X,point3Y,c_black,c_black,c_black,false);
draw_triangle_color(point2X,point2Y,point3X,point3Y,point4X,point4Y,c_black,c_black,c_black,false);
}
draw_self()
//player light
surface_set_target(surf);
draw_clear(c_black);
with(pl){
draw_set_blend_mode(bm_src_color);
draw_sprite_ext(spr_light,0,x*other.surfscale,y*other.surfscale,1.5,1.5,0,c_white,lightstr);
draw_set_blend_mode(bm_normal);}
surface_reset_target();
draw_surface_ext(surf,0,0,1/surfscale,1/surfscale,0,c_white,1);