Hello, Bard's Tale fans - one and all! What's up? Write me and let me
know! I've been pretty busy lately - and unfortunately, I hate being busy.
I'm doing some programming on the side, making a new web page for a
well-known rap star, working on remixing some Monkees songs, and it's my son's 3rd birthday on April 3rd. I can't
believe it's been three years already - he makes me proud!
This month, I'd like to take a look under the hood at the Bard's Tale
engine, and talk about a technique used for drawing walls as you walk
through dungeons called "Ray-Casting". Not to be confused with another
video game technique "Ray-Tracing" which is used in 3D rendering, Ray
Casting is what you use to figure out which walls to draw, based on your
current location in a square maze-like dungeon.
The scene above is taken from none other than the first dungeon every Bard's
Tale party must conquer, the Wine Cellar, located in the Scarlet Bard.
As you walk foreword one block at a time, the computer redraws the view that
is presented to your party. There are billions of possible combinations of
wall locations, and variations therein.
With this in mind, you cannot take the easy way out and say, "Well,
when they're at position (1,1) facing north, there will be a wall 20 feet
away, with walls on each side coming at the player". If you did this for
every square in every dungeon, the game would have to be on CD-ROM, because
there would be so much data!
Luckily programmers don't have to do that. We can store the maps in the
computer's memory, and have the processor calculate what walls to draw when.
The scene below is seen facing north from square (4,8) in the Wine Cellars.
In math, we learned that a ray is a line with a beginning point and no
ending point. I guess it's like a ray gun, huh? In Star Trek, if they
shot their ray guns into open space, you could physically see the ray, it's
origin, and how it would travel on into infinity.
We use rays here as well. The computer loads the characters current
position into memory, and all the walls that are in front of the brave
party. This data is usually stored in a square array, one that could
easily be represented on graph paper. The program can mathematically
"cast rays" from the position of the party, perhaps starting with at a
straight-line foreword. If it hits a wall immediately, it knows to draw
a big wall right in front of the party. If no wall is hit, the ray will
continue foreword until it hits one. Then, it will change the angle of
the ray, perhaps by three degrees to the left, and it will continue to
cast rays in several directions, as shown below.
When a ray hits a wall, it simply turns that wall "on", which means that
the wall will be drawn. Once the program knows which walls to draw, it
begins to draw them, beginning with the farthest walls first and the
closest walls last. That way, closer walls will overlap walls that are
drawn in the distance.
Notice that the rays hit two walls towards the top of the map, but they don't
show up on the display. That's because my mages didn't know Cat's Eyes,
which let's you see further distances. I had to settle for Sabhar's Stonelight
Spell.
This technique is fairly simple, and works great for games that are based
on square movements, square walls, and ones that are made for square people.
It's not so simple when you go 3D, with games like Quake. I couldn't even
imagine the mathematics behind those calculations!
Speaking of 3D, be sure to stop by Rob Thomas'
"The Bard's Legacy Dark Ressurection".
You can contact me at WebMaster@BardsTale.com.
Until next month, farewell fellow Bard's Tale fans!
Go back to BardsTale.com
or see other BardsTale.com Editorials.