dandymcgee wrote:Amazing how fast this is progressing, looking awesome Ryan.
RyanPridgeon wrote:
Very true, a lot of the time when showing this game I can't really display what I've been working on because a lot of it is in the engine / back end.
Keep in mind, this
is a programming forum. Just because we like pictures doesn't mean we don't like code too. If you ever come up with a new way to solve a problem in code, and you're dying to share it with someone, feel free to post it here so we can all revel in your greatness.
![Cool 8-)](./images/smilies/icon_cool.gif)
Good point, and I doubt anyone will be revelling in greatness, but I've just updated the minimap to only draw walls that you can see, on the side that you see them. This will be cool since anything not explored will be completely hidden in the map with no bleed into the next room.
I basically did it by first iterating through the grid of collidable tiles in the map in a window around the player's position, and checking if they are in sight of the player by checking n points between that tile and the player's position and checking if there's another wall in the way. If a collidable tile is in sight, it's flagged as "uncovered" in the minimap.
Code: Select all
// calculate N points to check along line of sight
var iterations:int = Math.sqrt(Math.pow(c - playerC, 2) + Math.pow(r - playerR, 2)) * 1.5;
// the current iteration's point position, start at the current checked tile
var ix:Number = c;
var iy:Number = r;
// start at the right or bottom of the tile if the player is on that side
if (playerC > c) ix += 1;
if (playerR > r) iy += 1;
// Calculate the step vector to iterate with
var stepX:Number = (pos.x / 32 - ix) / iterations;
var stepY:Number = (pos.y / 32 - iy) / iterations;
// if set to true, there was a collision
var collide:Boolean = false;
// Start away from the wall
ix += stepX;
iy += stepY;
// While haven't reached the player tile yet
while (!(Math.floor(ix) == playerC && Math.floor(iy) == playerR))
{
// If this isn't the start tile, and there's a wall in the way
if (!(Math.floor(ix) == c && Math.floor(iy) == r) && _map.getCol(ix, iy) == 1)
{
// Collision in line of sight
collide = true;
break;
}
// Move the current point to the next point along the line of sight
ix += stepX;
iy += stepY;
}
if (collide == false)
{
// If no collisions, this tile has been uncovered
setUncovered(c, r);
}
Then I iterate over them again, and for each uncovered tile, it draws the appropriate walls coming out of it onto the graphic, in a + shape. So if theres an uncovered tile with another uncovered tile above and another uncovered tile to the right, it draws a └ onto the tile's position in the map, and then flags the "UP" and "RIGHT" components as being drawn. This is cool because it means I can draw nice thin lines for the walls instead of big tile blocks, and if there's a wall stemming out on the other side of a wall from the player, it doesn't draw that line until you reach the other side.
Code: Select all
for (c = topleftC; c < topleftC + WINDOW_SIZE; c++)
{
for (r = topleftR; r < topleftR + WINDOW_SIZE; r++)
{
if (isUncovered(c, r))
{
// left
if ((getDrawn(c, r) & 1) == 0 && isUncovered(c - 1, r))
{
addDrawn(c, r, 1);
_lines.graphics.moveTo(c * UNIT_SIZE, r * UNIT_SIZE);
_lines.graphics.lineTo(c * UNIT_SIZE - HALF_UNIT_SIZE, r * UNIT_SIZE);
}
// right
if ((getDrawn(c, r) & 2) == 0 && isUncovered(c + 1, r))
{
addDrawn(c, r, 2);
_lines.graphics.moveTo(c * UNIT_SIZE, r * UNIT_SIZE);
_lines.graphics.lineTo(c * UNIT_SIZE + HALF_UNIT_SIZE, r * UNIT_SIZE);
}
// up
if ((getDrawn(c, r) & 4) == 0 && isUncovered(c, r - 1))
{
addDrawn(c, r, 4);
_lines.graphics.moveTo(c * UNIT_SIZE, r * UNIT_SIZE);
_lines.graphics.lineTo(c * UNIT_SIZE, r * UNIT_SIZE - HALF_UNIT_SIZE);
}
// down
if ((getDrawn(c, r) & 8) == 0 && isUncovered(c, r + 1))
{
addDrawn(c, r, 8);
_lines.graphics.moveTo(c * UNIT_SIZE, r * UNIT_SIZE);
_lines.graphics.lineTo(c * UNIT_SIZE, r * UNIT_SIZE + HALF_UNIT_SIZE);
}
}
}
}
Dunno if that's the best way to do it, but it runs lightning fast and seems to work perfectly
![Happy :)](./images/smilies/icon_smile.gif)
If anyone can suggest any improvements, please do!
YourNerdyJoe wrote:This looks like one of the few flash games I would actually be willing to pay for if it came to that.
Wow, thanks! That means a lot. Luckily for your wallet it'll be released as free to play
![Happy :)](./images/smilies/icon_smile.gif)