I'm making an overhead shooter, but I'm having trouble with the 'cone of sight' of the enemy. What I want is for the enemy to only detect the player if he is in front of him (ie in his cone of sight). Here is a screenshot
and here is the code I'm having trouble with:
boolean PointInViewAngle(float objX, float objY, float coneX, float coneY, float coneDir, float coneAngle) { boolean seeMe = false; //this WILL BE returned as TRUE at the END of the funciton if the enemy can see the player float minAngle = coneDir - coneAngle / 2; //the minimum angle of the code (ie 1 of the red lines) float maxAngle = coneDir + coneAngle / 2; //the max angle of the code (ie 1 the other red line)
float thisAngle = atan2(objY - coneY, objX - coneX); // objX,objY = player, coneY = of the enemy) //Test if the angle is inside the 'cone' (between the min angle and max angle) if (minAngle > maxAngle) { if ((thisAngle <= maxAngle) ||(thisAngle >= minAngle)) { seeMe = true; } } return seeMe; }
void enemiesDraw() {
//Draw a visual representation of the cone of sight (+16 to center it on the enemy image) stroke(255,0,0); line(x*+16,y+16,x + (cos(angle+radians(45)/2)*400)*tileSize,y + (sin(angle+radians(45) / 2)*400*tileSize)); line(x*+16,y+16,x + (cos(angle-radians(45)/2)*400)*tileSize,y + (sin(angle-radians(45) / 2)*400*tileSize));
//if the enemy can see the player, print a message. if (PointInViewAngle(player1.x+offsetX,player1.y+offsetY,x*tileSize+offsetX,y*tileSize+offsetY,angle,radians(45)) == true) { print("I can see you"); }
I'm making an overhead shooter, and although I can control the character (he moves to wherever the mouse clicks) and draw the tile map I've loaded in. I can't figure out how to move the screen with the character.
I've used the variables offsetX and offsetY to show the amount the screen has 'moved', but I can't figure out how to make this work for the tiles and following the shooter.
I've got the following structure in my sketches libraries folder:
LeadboltController
libraries
LeadboltController.jar
and it shows no problems when I use:
import com.Leadbolt.*;
the leadbolt documentation says this, but is there anyway to use this in the processing ide, I've never used eclipse.
/* Other imports here */ import com.Leadbolt.AdController; public class HelloWorld extends Activity { private AdController myController; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // create a new layout LinearLayout layout = new LinearLayout(this); /* Add any elements to your view */ // make the view visible this.setContentView(layout); } final Activity act = this; // now add the banner or overlay to the app layout.post(new Runnable() { public void run() { myController = new AdController(act, MY_LB_SECTION_ID); myController.loadAd(); } }); } public void onDestroy() { myController.destroyAd(); super.onDestroy(); }