 |
Castle Paradox
|
| View previous topic :: View next topic |
| Author |
Message |
Onlyoneinall Bug finder
Joined: 16 Jul 2005 Posts: 746
|
Posted: Fri Apr 06, 2007 5:13 pm Post subject: Requesting fairly simple (?) flashlight script |
|
|
I have little clue as to where I would start on making a flashlight script, but what I want to do I think is pretty simple next to just lighting up the whole screen.
ooo
oxo
ooo
I want the object that is being used to surround the player in a small circle of light. The x is where the character is, and the o are the surrounding tiles that are lit up. How would I be able to do a script that would only illuminate the tiles around him like that? Thanks. _________________ http://www.castleparadox.com/gamelist-display.php?game=750 Bloodlust Demo 1.00
 |
|
| Back to top |
|
 |
Newbie_Power

Joined: 04 Sep 2006 Posts: 1762
|
Posted: Fri Apr 06, 2007 6:18 pm Post subject: |
|
|
It's simple technically, but the actual positioning of the "dark" NPCs is tricky and would be relative to the hero.
I would do something like:
| Code: | // C-based pseudo code because I already forgot plotscripting syntax
for (x = 0; x < 16; x ++)
{
for (y = 0; y < 10; y ++)
{
if (x < (hero_x - 1) && x > (hero_x) + 1 && y < (hero_y - 1) && y > (hero_y + 1)
move npc(npc_reference[x + y], x * 20);
}
} |
...
...
...
...
Or something. I have a gut feeling that formula will suck even in plotscript form. _________________
TheGiz> Am I the only one who likes to imagine that Elijah Wood's character in Back to the Future 2, the kid at the Wild Gunman machine in the Cafe 80's, is some future descendant of the AVGN? |
|
| Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Fri Apr 06, 2007 9:39 pm Post subject: |
|
|
Hint: don't use npcs. Use tiles. This isn't going to get you a circle, instead a square. Project C solved this with plain awesomeness. You could use 4 npcs to round the square into a circle, but npcs complicate things. Of course, then you still need to have npcs appear lit or unlit depending on your position.
Try and look around for a flashlight script. Lots of games have used them. _________________ "It is so great it is insanely great." |
|
| Back to top |
|
 |
Mr B
Joined: 20 Mar 2003 Posts: 382
|
Posted: Tue Apr 10, 2007 3:39 pm Post subject: |
|
|
Ah-hah! I, Mr B, the instigator of lighting scripts (a process begun long ago in a game that never got beyond the pre-alpha release) have arrived!
They're...tricky beasts. I think they'll be easier now that scripts run faster -- lag was a probem for me.
Project C (which I didn't work on) was, as mentioned, awesome. It lagged, but it was so cool that I barely minded. I don't know how they did it, but I suspect that it used an LOS algorithm with a Time-To-Live die-off to make distant tiles darker.
My last real lighting script was PB2, which had three main components:
1.) When the light was turned on, a script simply turned on all of the tiles that were supposed to be illuminated.
2.) When the light was turned off, a script turned off all of the associated tiles.
3.) When moving in a direction, a script added a new, illuminated "fringe" of tiles in that direction while darkening the corresponding fringe on the opposite side. This cut down on overhead, even if there were more lines of script.
I made the tileset so that half of the tiles were illuminated, while the other half were the darkened equivalent. This severely limited how many tiles I could draw (which probably saved my sanity). One column was the illuminated version, the next the darkened version, illuminated, darkened, etc. Doing this meant that I could use "tile value, mod, 2" to determine whether a tile was illuminated, or change it to one or the other of the lit states without having to look it up in a table ("tile value -= tile value, mod, 2" forces it to be its illuminated stat w/o tedious "if...then" statements -- of course, we didn't have that exact syntax back then...).
For NPCs I did a similar thing -- even-numbered NPCs were illuminated, while odd-numbered ones were darkened. I remember that a snazzy new command had just come out that allowed you to change which NPC number a specific instance was. I used a simple formula that determined if an NPC was within a certain distance of the hero, and, if the light were on, it would switch it to its correspondingly lit version -- which could have a completely different sprite, palette, and AI. This allowed me to make rat NPCs that wandered randomly when in the dark, but fled the hero when they got caught in the light.
I don't think anyone ever saw the rats, but I loved them dearly.
Using four NPCs to make a circle of illumination is a great idea (b/c the circle can follow the hero in a smooth manner), but only if everything outside the lit zone is completely black -- it would look weird to have four black corners eclipsing the dim landscape.
Um, yeah. I have a few more ideas, but I've never tried 'em. Shadowiii wants to remake PB when he returns, so I think I'll keep them under wraps until that time.
*looks over post* I hope that was somehow informative! |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|