Hello all. I’m hoping you can all give me a hand with my game project again.
My game uses a grid of nodes to determine where everything is and for pathfinding. Each node is 20 by 20 pixels. I’m having an issue with lighting. As you can see in my screenshot, the wall in the upper left is visible to the player, even though it really shouldn’t be.
https://dl-web.dropbox.com/get/Public/screenshot.png?w=a8e9e862
I’ve been trying to figure out an efficient way to have the system check to see if the nodes are out of blocked but nothing has come up that works. I am currently using the following:
public void update(){
for(int i = 0; i<width; i++){
for(int j=0; j<height; j++){
Node n = nodeMap[i][j];
for(int k=0; k<player.getParty().size(); k++){
if(n.getDistance(player.getParty().get(k).getNode()) > 160){
n.setSight(false);
}
else{
ArrayList<Node> temp = n.getNeighbours();
int wallCheck = 0;
for(int l=0; l<temp.size(); l++){
if(!temp.get(l).getTraversible()){
wallCheck++;
}
}
if(wallCheck != temp.size()){
n.setSight(true);
break;
}
else{
n.setSight(false);
}
}
}
}
}
}
This code is called during every update cycle, which I accept may be too many times since it only really needs to be called whenever the player moves. If a node has it’s inSight value set to false, then it is not drawn. Any ideas for how I can check if there are walls between the player characters and the nodes? Note WallCheck checks to see if any node is completely surrounded by walls, because if it is then there’s no point to drawing it.
Additionally, I want to be able to create random objects. For example, lets say I have a treasure chest and I want it to be filled with a random assortment of weapons. How can I do this? Currently, I have Items like Longsword and Quarterstaff extending Weapon which extends Item, but I need to use new in order to create these objects. How can I do this?
Many thanks