PDA

View Full Version : Let there be light!

DustyPorViva
03-05-2008, 11:12 PM
A little lighting effect I made for single levels. You simply put the code in an NPC in the level or place it in a class and join it, the choice is yours really. You can have more than one light source in a level, but it's not gonna do anything advanced, just merely overlaps(and when played with, you can get some nice looking effects out of it). I use it for just aesthetic reasons, not logical. Like in my screenshot I'm not using it to show light coming from a window, but just to create some nice looking effects.
I should note that even though it does a lot of looping, it only does so when you enter the level and it is not noticeable at all(at least in my experience, and I run on a pretty damn terrible computer, and in my level I'm using two).
Anyways, here's the code, and an image attachment of it in effect:

//#CLIENTSIDE
function onPlayerenters() {
// These are tiles that light will 'pass through'... add stuff like vases(that can change
// blocking) here. I also have the window tiles in there... so you can have a light source
// coming from the windows, you might want to remove that
temp.opacity=.5; // how opaque the shadow will be
temp.checks=300; // how many checks to perform, careful not to exceed limit loop

// NOTHING TO EDIT BELOW THIS
temp.seg=(pi*2)/checks;
temp.poly={0,0,0,64,64,64,64,0,0,0};

for (i=0;i<checks+1;i++) {
for (j=0;j<64;j+=.5) {
if (onwall(x-sin((i*seg))*j,y-cos((i*seg))*j)) {
if (!(tiles[x-sin((i*seg))*j,y-cos((i*seg))*j] in nonblocking)) {
this.newpoly={int((x-sin((i*seg))*j)+.5),int((y-cos((i*seg))*j)+.5)};
break;
}
}
}
}

showpoly(200,poly);
changeimgcolors(200,0,0,0,opacity);
changeimgvis(200,0);
}

Sorry for the bad screenshot... I don't know how to do a full level screenshot in Graalv5.

cbk1994
03-05-2008, 11:24 PM
Very nice, though I was never a huge fan of these kinds of systems. They don't seem to fit into Graal style.

Chompy
03-05-2008, 11:40 PM
Very nice Dusty ^^ :D

Clockwork
03-06-2008, 12:46 AM
I like it, its just too bad that it doesn't have a z axis to affect how long the shadow should be for things like the table. :(

DustyPorViva
03-06-2008, 12:49 AM
I thought about it, but that would be impossible because even though I can assign a z-axis to the light source, I wouldn't have a z-axis to compare it to when it comes to the tiles.

Rapidwolve24
03-06-2008, 03:39 AM
Very nice, I think I remember you (or someone else) working on something like this.

Chompy
03-06-2008, 09:19 PM
Very nice, I think I remember you (or someone else) working on something like this.

Yeah, Knight did :o

Inverness
03-07-2008, 01:34 AM
*Eyes are vaporized by the intensity of the light*