@Override public boolean update(double timeDelta) { Vector2f moveDelta = new Vector2f(getVelocity()); moveDelta.scale((float) timeDelta); Vector2f.add(getPosition(), moveDelta, getPosition()); if (Math.abs(getPosition().x) > halfRangeX || Math.abs(getPosition().y) > halfRangeY) return true; return false; }
@Override public void advance(float amount) { if (!missile.getSource().isAlive()) { IceUtils.destroy(missile); return; } super.advance(amount); weaponCooldown = Math.max(0, weaponCooldown - amount); if (target == null) return; Vector2f.add(destOffset, target.getLocation(), dest); accelerate(); turnToward(dest); if (ammo > 0 && weaponCooldown == 0) { CombatEntityAPI nearest = null; float record = Float.MAX_VALUE; for (int i = 0; i < potentialTargets.size(); ++i) { CombatEntityAPI m = (CombatEntityAPI) potentialTargets.get(i); float dist2 = MathUtils.getDistanceSquared(missile, m); if (dist2 < record && dist2 <= WEAPON_RANGE_SQUARED) { record = dist2; nearest = m; } } if (nearest != null) { Global.getCombatEngine() .spawnProjectile( missile.getSource(), null, WEAPON_ID, missile.getLocation(), VectorUtils.getAngle(missile.getLocation(), nearest.getLocation()), new Vector2f()); --ammo; weaponCooldown = WEAPON_COOLDOWN; } } }
public static Vector2f add(Vector2f v1, Vector2f v2) { return Vector2f.add(v1, v2, v1); }
private void update() { float posDelta = 0.1f; if (Keyboard.isKeyDown(Keyboard.KEY_W)) { Vector3f.add( cameraPos, new Vector3f( (float) (Math.cos(cameraAngle.getX() + Math.PI / 2) * posDelta), 0, (float) (Math.sin(cameraAngle.getX() + Math.PI / 2) * posDelta)), cameraPos); } if (Keyboard.isKeyDown(Keyboard.KEY_D)) { Vector3f.add( cameraPos, new Vector3f( (float) (Math.cos(cameraAngle.getX() + Math.PI) * posDelta), 0, (float) (Math.sin(cameraAngle.getX() + Math.PI) * posDelta)), cameraPos); } if (Keyboard.isKeyDown(Keyboard.KEY_S)) { Vector3f.add( cameraPos, new Vector3f( (float) (Math.cos(cameraAngle.getX() + Math.PI * 3 / 2) * posDelta), 0, (float) (Math.sin(cameraAngle.getX() + Math.PI * 3 / 2) * posDelta)), cameraPos); } if (Keyboard.isKeyDown(Keyboard.KEY_A)) { Vector3f.add( cameraPos, new Vector3f( (float) (Math.cos(cameraAngle.getX()) * posDelta), 0, (float) (Math.sin(cameraAngle.getX()) * posDelta)), cameraPos); } if (Keyboard.isKeyDown(Keyboard.KEY_Q)) { Vector3f.add(cameraPos, new Vector3f(0, -1, 0), cameraPos); } if (Keyboard.isKeyDown(Keyboard.KEY_E)) { Vector3f.add(cameraPos, new Vector3f(0, 1, 0), cameraPos); } if (Keyboard.isKeyDown(Keyboard.KEY_R)) { Vector3f.add(modelAngle, new Vector3f(0, 0.05f, 0), modelAngle); } if (Keyboard.isKeyDown(Keyboard.KEY_UP)) { Vector3f.add(modelPos, new Vector3f(0.1f, 0, 0), modelPos); } if (Keyboard.isKeyDown(Keyboard.KEY_DOWN)) { Vector3f.add(modelPos, new Vector3f(-0.1f, 0, 0), modelPos); } Vector2f.add(cameraAngle, new Vector2f(Mouse.getDX() * 0.004f, 0), cameraAngle); Vector2f.add(cameraAngle, new Vector2f(0, -Mouse.getDY() * 0.004f), cameraAngle); if (cameraAngle.getY() > Math.PI / 2) cameraAngle.setY((float) Math.PI / 2); if (cameraAngle.getY() < -Math.PI / 2) cameraAngle.setY((float) -Math.PI / 2); }