public SteeringA getSteering() { /* // METODO DEL PRIMER LIBRO // The steering variable holds the output SteeringA steering = new SteeringA(); // Loop through each target for(Kinematic target : targets){ // Check if the target is close Vector direction = target.getPosicion().clone(); //System.out.println("target direction module:"+direction.getModulo()); direction.restar(character.getPosicion()); Double distance = direction.getModulo(); if (distance < threshold){ // Calculate the strength of repulsion //System.out.println("distance:"+distance+", threshold:"+threshold); double strength = Math.min(decayCofficient / (distance * distance), maxAcceleration); // Add the acceleration direction.normalizar(); direction.multiEscalar(strength); steering.getLin().sumar(direction); //System.out.println("steering.lin:"+steering.getLin().getModulo()+", steering.ang:"+steering.getAng()+", strength:"+strength); } // We have gone through all targets, return the result } return steering; }*/ /* METODO DEL SEGUNDO LIBRO public SteeringA getSteering(){ // The steering variable holds the output SteeringA steering = new SteeringA(); // Loop through each target for(Kinematic target : targets){ Vector toAgent = target.getPosicion().clone(); toAgent.restar(character.getPosicion()); double distance = toAgent.getModulo(); toAgent.normalizar(); toAgent.divEscalar(distance); steering.getLin().sumar(toAgent); } // We have gone through all targets, return the result return steering; }*/ // METODO DE AIMCORE int count = flock.prepareNeighourhood(character); if (count <= 0) return new SteeringA(); Vector cofm = flock.getNeighbourhoodCenter(); try { super.setObjetivo(new Kinematic(cofm.getX(), cofm.getY())); } catch (SlickException ex) { Logger.getLogger(KinematicSeparation.class.getName()).log(Level.SEVERE, null, ex); } return super.getSteering(); }
@Override public void update(GameContainer container, int delta) throws SlickException { // throw new UnsupportedOperationException("Not supported yet."); Input input = container.getInput(); // rotate quad double x1 = jugador1.getPosicion().getX(); double y1 = jugador1.getPosicion().getY(); if (Keyboard.isKeyDown(Keyboard.KEY_LEFT)) { plane1.rotate(-0.2f * delta); } if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) { plane1.rotate(0.2f * delta); } if (Keyboard.isKeyDown(Keyboard.KEY_DOWN)) { float hip = 0.4f * delta; float rotation = plane1.getRotation(); x1 -= hip * Math.sin(Math.toRadians(rotation)); y1 += hip * Math.cos(Math.toRadians(rotation)); } if (Keyboard.isKeyDown(Keyboard.KEY_UP)) { float hip = 0.4f * delta; float rotation = plane1.getRotation(); x1 += hip * Math.sin(Math.toRadians(rotation)); y1 -= hip * Math.cos(Math.toRadians(rotation)); } // keep quad on the screen if (x1 < 10) { x1 = 10; } if (x1 > 790) { x1 = 790; } if (y1 < 10) { y1 = 10; } if (y1 > 590) { y1 = 590; } Vector posicion = jugador1.getPosicion(); posicion.setX(x1); posicion.setY(y1); jugador1.setPosicion(posicion); // jugador 2 if (Keyboard.isKeyDown(Keyboard.KEY_W)) lastSteering = 1; if (Keyboard.isKeyDown(Keyboard.KEY_A)) lastSteering = 2; if (Keyboard.isKeyDown(Keyboard.KEY_F)) lastSteering = 3; if (Keyboard.isKeyDown(Keyboard.KEY_S)) lastSteering = 4; /* switch(lastSteering) { case 1: jugador2.update(steeringW.getSteering(), delta); break; case 2: jugador2.update(steeringA.getSteering(), delta); break; case 3: jugador2.update(steeringF.getSteering(), delta); break; case 4: jugador2.update(steeringS.getSteering(), delta); break; default: }*/ // plane2.rotate((float) jugador2.getOrientacion()); if (input.isKeyPressed(Input.KEY_F1)) { Image target = new Image(container.getWidth(), container.getHeight()); container.getGraphics().copyArea(target, 0, 0); ImageOut.write(target.getFlippedCopy(false, true), "screenshot.png", false); target.destroy(); } }