A
Alek214
Guest
I've been trying (on and off for probably a few months now) to create an extremely simple "light casting" function in my game in order to tell the player what enemies can and can't see. The game is essentially a top-down zelda dungeon puzzle games with "stealth" elements using a C64-esque graphics style.
Right now it's almost working, but there are a few major issues that i cant really get past. The light casting system is supossed to be literally black and white, so a long of tutorials are giving me a lot of information that i dont really need. This tutorial helped a lot, but the main problem is that it's drawing the dark parts instead of the light parts, so i cant have more than one enemy on screen without either the last enemy that loads prioritizing it's "light" or it just showing a black screen altogether
The other major problem is that i have no idea what i'm doing code wise and i'm pretty sure having a for statment calling a script in the draw event is probably a terrible idea.
This is what my code looks like right now
Draw event of ob_ShowSight:
The global.eye array is what i use to link specific eyes-type-enemy instances (which are the focal point of the game) to specific trap instances. it is also used to save and load the life/death status of an eye instance after exiting the game. there are multiple different types of "eye" enemies, so this also makes it so i dont have to type scr_ShowSight(obj_SmallEye) and scr_ShowSight(obj_PanicEye) and so on.
scr_ShowSight code:
this code draws a black and white representation of each eye's FOV, in the full game the player will have to find and use an item to get this effect. right now i can just press 0 on the number pad. one obvious thing that im noticing now is that drawing the white rectangle will overshadow previously drawn FoV's, but changing this just bring back the initial problem of the screen just going completely black.
Here are a few gifs of the game and examples of this problem.
Another problem is that light will seep between tiles, if anyone knows a quick fix for that then that would be great, but it's not the main problem.
I've been trying to figure out how to change the light system to draw the "light" instead of drawing "dark" but it's a lot harder than i thought, plus i only barely understand what's going on in my script right now.
does anyone know 1: a better way to run this code that's not overexerting the draw event and 2: a way to easily change the scr_ShowSight code to draw triangles where the eye can see, rather than where they cant?
Thank you!
Right now it's almost working, but there are a few major issues that i cant really get past. The light casting system is supossed to be literally black and white, so a long of tutorials are giving me a lot of information that i dont really need. This tutorial helped a lot, but the main problem is that it's drawing the dark parts instead of the light parts, so i cant have more than one enemy on screen without either the last enemy that loads prioritizing it's "light" or it just showing a black screen altogether
The other major problem is that i have no idea what i'm doing code wise and i'm pretty sure having a for statment calling a script in the draw event is probably a terrible idea.
This is what my code looks like right now
Draw event of ob_ShowSight:
Code:
if room!=rm_TitleScreen
{
var n=0;
for(n=0; n != array_length_1d(global.eye) ; n+=1)
{
var status=global.eye[n].is_alive;
scr_ShowSight(global.eye[n])
}
}
scr_ShowSight code:
Code:
with(argument0)
{
if scr_InRoomWith(obj_Player) and is_alive and keyboard_check(vk_numpad0)
{
draw_set_colour(c_white)
draw_rectangle(r_x1,r_y1,r_x2,r_y2,false) //draw white recangle the size of current room
with(obj_BlockSight)
{
depth=-100000
var shadowsize=1000
draw_set_colour(c_black)
draw_rectangle(bbox_left,bbox_top,bbox_right,bbox_bottom,false) //draw black squares over the walls
draw_primitive_begin(pr_trianglestrip)
draw_vertex(bbox_left, bbox_top);
var dir = point_direction(argument0.x,argument0.y,bbox_left,bbox_top)
draw_vertex(x+lengthdir_x(shadowsize,dir), y+lengthdir_y(shadowsize,dir));
draw_vertex(bbox_left, bbox_bottom);
var dir = point_direction(argument0.x,argument0.y,bbox_left,bbox_bottom)
draw_vertex(x+lengthdir_x(shadowsize,dir), y+lengthdir_y(shadowsize,dir));
draw_vertex(bbox_right, bbox_top);
var dir = point_direction(argument0.x,argument0.y,bbox_right,bbox_top)
draw_vertex(x+lengthdir_x(shadowsize,dir), y+lengthdir_y(shadowsize,dir));
draw_vertex(bbox_right, bbox_bottom);
var dir = point_direction(argument0.x,argument0.y,bbox_right,bbox_bottom)
draw_vertex(x+lengthdir_x(shadowsize,dir), y+lengthdir_y(shadowsize,dir));
draw_primitive_end()
}
draw_set_colour(c_gray)
with (obj_Player) draw_rectangle(bbox_left,bbox_top,bbox_right,bbox_bottom,false) //draw a grey rectangle over the player
}
}
Here are a few gifs of the game and examples of this problem.
Another problem is that light will seep between tiles, if anyone knows a quick fix for that then that would be great, but it's not the main problem.
I've been trying to figure out how to change the light system to draw the "light" instead of drawing "dark" but it's a lot harder than i thought, plus i only barely understand what's going on in my script right now.
does anyone know 1: a better way to run this code that's not overexerting the draw event and 2: a way to easily change the scr_ShowSight code to draw triangles where the eye can see, rather than where they cant?
Thank you!