For one of my sketches, I have some tanks that fire at the opposing side. To do this I wrote an AI for the tank that controls firing and wheel movement. The issue is that the first shot by a tank aiming left sometimes goes too far down. Can anyone figure it out?
the AI:
void AI(ArrayList<Tank> targets,boolean side){
Vec2 target = new Vec2();
boolean hasTarget = true; //changed to false if there is no enemy
float targetIDr = 0; //stores the distance from a tank
float targetIDl = 0;
Vec2 targetIDrv = new Vec2(); //stores the actual position of a target
Vec2 targetIDlv = new Vec2();
Vec2 b = this.getCenter(); //its own postion;
if(side){
for (int i = targets.size()-1; i >= 0; i--) { //runs through targets to find closest
Tank e = targets.get(i);
Vec2 a = e.getCenter(); //get the center of the current tank
if(a.x > b.x){ //sets different values based on the side it is
if(getDistance(a.x,a.y,b.x,b.y) < targetIDr || targetIDr == 0){ //sets values if it is closer that the previouse closest
particles.add(new Particle(this.getCenter().x,this.getCenter().y-35,cos(radians(temp_deg))*20,sin(radians(temp_deg))*20,3,10)); //spawn partical with velocity , Args: (posX,posY,velocityX,velocityY,partical size, damage it will cause)
if(sPlayers.size() < 30){ //is there less than 30 audio players?
sPlayers.add(minim.loadFile("shot.mp3", 2048)); //play the shot noise
AudioPlayer a = sPlayers.get(sPlayers.size()-1);
a.play();
}
}
}
firetimer++; //increase fire timer;
if(firetimer >= 80){ //reset it after a while
firetimer = 0;
}
}
}
if you want an easy way to test it, here is the entire sketch:
for one of my sketches, I have some vehicles which need to be on the same terrain but not collide with each-other. What I need to do is to make my circle class not collide with another circle and any rectangles and likewise with my rectangle class which are the shapes I used to define the collision points of my vehicles. Does anyone know how to do this?
So I have been working on getting a server - client jbox2D based sketch going and I got it mostly working. However, I have been having some strange bugs that I can't work out. Right now, I have projectile syncing working but for some reason, gravity seems to stop working after a while. Anyone know how to fix this?
Due to the amount of code and how I wrote it, I feel it would be unreasonable to put the entire thing in here so what I did was I uploaded my sketch to mediafire. Here is the link:
http://www.mediafire.com/?6yy9votk4q7ivpd
However, I do have the main page of the server and the client here in-case there is any obvious bugs that are easy to spot:
For one of my sketches, I intend to use some 2D physics. So what I did was I looked up 2D physics engines and I found a physics engine called Jbox2D which is a port of box2D for java and I have been trying to figure out how to use it in processing but I can't figure out how to install it. Anyone used this or know how to get processing to use the code?
Now I am not that good at dealing with keyboard inputs or text-cursors so I just made it render with an extra "|" half the time to show where the end of the text is. Does anyone know how I could improve on this?
Note: I also know about the
controlP5 library but I am trying to avoid libraries as I intend to port my code to android (libraries + androids != good experiance for me) later and
controlP5 doesn't support exactly what I am looking to do anyways
Im trying to find the length of a array of strings but cince the variable string already contains the length function, it gives me an error. Does anyone know how to find the length of a array of strings?