Hello everyone!
In my absence from this site I have been experimenting with swing and graphics. My problem is this, I have two cows on the screen that move along a grid(each square is 16x16) and I have them print an arrow in the direction of the other cow AS LONG AS IT IS 3 OR LESS SQUARES away. When they print their arrows it's usually facing the opposite direction of the cow they are detecting. The object that is the cow is Testai. If you need more of my code posted in order to help I will! (After all it is just cows moving)
This code is the Testai "detection" code
This is where the arrows are printed.for(Testai c : testArray) { //looking right if ((int)(c.x - super.x)/16 <= 3 && (c.x - super.x)/16 > 0) { if ((int)c.y - super.y == 0) { //shoots right PrintScreen.right = true; } else if((int)c.y - super.y > 0) { //shoots south east PrintScreen.southeast = true; } else if((int)c.y - super.y < 0) { //shoots north east PrintScreen.northeast = true; } } //looking left else if ((int)(c.x - super.x)/16 >= -3 && (c.x - super.x)/16 < 0) { if ((int)c.y - super.y == 0) { //shoots left PrintScreen.left = true; } else if((int)c.y - super.y > 0) { //shoots south west PrintScreen.southwest = true; } else if((int)c.y - super.y < 0) { //shoots north west PrintScreen.northwest = true; } } else if ((int)(c.x - super.x)/16 == 0) { if ((int)c.y - super.y < 0) { //shoots down PrintScreen.down = true; } else if ((int)c.y - super.y > 0) { //shoots up PrintScreen.up = true; } } }
Thanks to all who reply! I don't know if I put this in the right section though.for(int s = 0; s < testArray.size(); s++) { t = testArray.get(s); if(up) { arrow = new ImageIcon("up.png"); arrowprint = arrow.getImage(); g2.drawImage(arrowprint,(int)t.getX(),(int)t.getY()-16,this); up = false; } else if(down) { arrow = new ImageIcon("down.png"); arrowprint = arrow.getImage(); g2.drawImage(arrowprint,(int)t.getX(),(int)t.getY()+16,this); down = false; } else if(left) { arrow = new ImageIcon("left.png"); arrowprint = arrow.getImage(); g2.drawImage(arrowprint,(int)t.getX()-16,(int)t.getY(),this); left = false; } else if (right) { arrow = new ImageIcon("right.png"); arrowprint = arrow.getImage(); g2.drawImage(arrowprint,(int)t.getX()+16,(int)t.getY(),this); right = false; } else if(southwest) { arrow = new ImageIcon("sw.png"); arrowprint = arrow.getImage(); g2.drawImage(arrowprint,(int)t.getX()-16,(int)t.getY()+16,this); southwest = false; } else if(southeast) { arrow = new ImageIcon("se.png"); arrowprint = arrow.getImage(); g2.drawImage(arrowprint,(int)t.getX()+16,(int)t.getY()+16,this); southeast = false; } else if(northwest) { arrow = new ImageIcon("nw.png"); arrowprint = arrow.getImage(); g2.drawImage(arrowprint,(int)t.getX()-16,(int)t.getY()-16,this); northwest = false; } else if(northeast) { arrow = new ImageIcon("ne.png"); arrowprint = arrow.getImage(); g2.drawImage(arrowprint,(int)t.getX()+16,(int)t.getY()-16,this); northeast = false; } g2.drawImage(cow,(int)t.getX(),(int)t.getY(),this); }
lil_misfit