Original Post
Hi there, just joined :) Hope someone can help me out. I've a tile based game, basic stuff with just trees and grass. The player can walk on the grass but can't walk on a tree :) It's basic stuff where when you click right, it moves the unit to the tile to the right (just sets him on it, no animation), all done using a simple 2 dimensional array. ie: int Map[5][5] = {0,0,0,0,1} {0,2,0,0,1} {0,1,1,0,1} {0,0,0,0,1} {0,0,1,0,1} Where 0=grass, 1=tree and 2=playerPosition. In the actual game the grid is say 100x100. Now the player has a "view range", a square grid around his position of 4 grid slots, in all directions. so if he can see 4 grid slots in front and 4 behind, plus the slot he is standing on thats 9 slots across, both vertically and horizontally is a 9x9 view range in a square shape (keeping it basic). Any enemies outside this range won't show up. Now the problem. If there is a tree within this view range, I want to 'shadow' behind it any slots that would normally be visible (because they are within the view range) but aren't now because they are behind the tree. Now I was thinking of an algorithm that 'shoots' a line from the center of the player slot around him in 10 degree increments (1 degree would be more accurate but I don't want 360 calculations each move), an if the line reaches the outside edge of the view range square then any slots it has passed through are visible. If it sets to a degree (say 130) and the line hits a tree slot, then any slot it passed through before the tree is visible, and because the line couldn't reach behind the tree, these slots are marked outside the view range. Hope you know what I mean. Would anyone here know a good way of doing this? Or a better way? Assuming this method, I presume I'd need the equation for a line and move along this line in 1pixel increments checking if I'm in the slot ? Thanks for your help, I'm totally new to game design. Cheers