/** * TODO add a life system that checks color against a base value. being exposed to the same color * plasma will dull your color (make it closer to black), and when you are completely faded, you * die */ public void loop(float time) { this.red = (colorJet == 1) ? 255 : 0; this.green = (colorJet == 2) ? 255 : 0; this.blue = (colorJet == 0) ? 255 : 0; if (luminence > 0) { luminence--; } else if (luminence < -1 || luminence == 0) { this.killed = true; } int stepLen = D.field.stepLen; xLoc += xVel * time; yLoc += yVel * time; xVel += xAccel * time; yVel += yAccel * time; xAccel += ((D.field .xVel[ DisplayObjects.FluidSolver.IX( (int) (xLoc / stepLen), (int) (yLoc / stepLen))] + D.field .xVel[ DisplayObjects.FluidSolver.IX( (int) (xLoc / stepLen), (int) (yLoc / stepLen) + 1)]) * (stepLen - (xLoc - stepLen * (int) (xLoc / stepLen))) + (D.field .xVel[ DisplayObjects.FluidSolver.IX( (int) (xLoc / stepLen) + 1, (int) (yLoc / stepLen))] + D.field .xVel[ DisplayObjects.FluidSolver.IX( (int) (xLoc / stepLen) + 1, (int) (yLoc / stepLen) + 1)]) * (xLoc - stepLen * (int) (xLoc / stepLen))) / 6000; yAccel += ((D.field .yVel[ DisplayObjects.FluidSolver.IX( (int) (xLoc / stepLen), (int) (yLoc / stepLen))] + D.field .yVel[ DisplayObjects.FluidSolver.IX( (int) (xLoc / stepLen) + 1, (int) (yLoc / stepLen))]) * (stepLen - (yLoc - stepLen * (int) (yLoc / stepLen))) + (D.field .yVel[ DisplayObjects.FluidSolver.IX( (int) (xLoc / stepLen), (int) (yLoc / stepLen) + 1)] + D.field .yVel[ DisplayObjects.FluidSolver.IX( (int) (xLoc / stepLen) + 1, (int) (yLoc / stepLen) + 1)]) * (xLoc - stepLen * (int) (xLoc / stepLen))) / 6000; bounce(); xVel *= 0.99; yVel *= 0.99; for (int i = 0; i < this.projectiles.size(); i++) { projectiles.get(i).loop(time); } }
/** {@inheritdoc} */ public void emit(DisplayObjects.FluidField field) { int stepLen = this.D.field.stepLen; int left = (int) xLoc / stepLen; int right = left + 1; int up = (int) yLoc / stepLen; int down = up + 1; if (D.mouse.leftDown) { field.dXVel[DisplayObjects.FluidSolver.IX(left, up)] = (D.mouse.mx - xLoc) * 0.002f * (right * stepLen - xLoc) * (down * stepLen - yLoc); field.dYVel[DisplayObjects.FluidSolver.IX(left, up)] = (D.mouse.my - yLoc) * 0.002f * (right * stepLen - xLoc) * (down * stepLen - yLoc); field.dXVel[DisplayObjects.FluidSolver.IX(right, up)] = (D.mouse.mx - xLoc) * 0.002f * (xLoc - left * stepLen) * (down * stepLen - yLoc); field.dYVel[DisplayObjects.FluidSolver.IX(right, up)] = (D.mouse.my - yLoc) * 0.002f * (xLoc - left * stepLen) * (down * stepLen - yLoc); field.dXVel[DisplayObjects.FluidSolver.IX(left, down)] = (D.mouse.mx - xLoc) * 0.002f * (right * stepLen - xLoc) * (yLoc - up * stepLen); field.dYVel[DisplayObjects.FluidSolver.IX(left, down)] = (D.mouse.my - yLoc) * 0.002f * (right * stepLen - xLoc) * (yLoc - up * stepLen); field.dXVel[DisplayObjects.FluidSolver.IX(right, down)] = (D.mouse.mx - xLoc) * 0.002f * (xLoc - left * stepLen) * (yLoc - up * stepLen); field.dYVel[DisplayObjects.FluidSolver.IX(right, down)] = (D.mouse.my - yLoc) * 0.002f * (xLoc - left * stepLen) * (yLoc - up * stepLen); if (this.colorJet == 1) { field.rSource[DisplayObjects.FluidSolver.IX(left, up)] = 20.0f * (right * stepLen - xLoc) * (down * stepLen - yLoc); field.rSource[DisplayObjects.FluidSolver.IX(right, up)] = 20.0f * (xLoc - left * stepLen) * (down * stepLen - yLoc); field.rSource[DisplayObjects.FluidSolver.IX(left, down)] = 20.0f * (right * stepLen - xLoc) * (yLoc - up * stepLen); field.rSource[DisplayObjects.FluidSolver.IX(right, down)] = 20.0f * (xLoc - left * stepLen) * (yLoc - up * stepLen); } if (this.colorJet == 2) { field.gSource[DisplayObjects.FluidSolver.IX(left, up)] = 20.0f * (right * stepLen - xLoc) * (down * stepLen - yLoc); field.gSource[DisplayObjects.FluidSolver.IX(right, up)] = 20.0f * (xLoc - left * stepLen) * (down * stepLen - yLoc); field.gSource[DisplayObjects.FluidSolver.IX(left, down)] = 20.0f * (right * stepLen - xLoc) * (yLoc - up * stepLen); field.gSource[DisplayObjects.FluidSolver.IX(right, down)] = 20.0f * (xLoc - left * stepLen) * (yLoc - up * stepLen); } if (this.colorJet == 0) { field.bSource[DisplayObjects.FluidSolver.IX(left, up)] = 20.0f * (right * stepLen - xLoc) * (down * stepLen - yLoc); field.bSource[DisplayObjects.FluidSolver.IX(right, up)] = 20.0f * (xLoc - left * stepLen) * (down * stepLen - yLoc); field.bSource[DisplayObjects.FluidSolver.IX(left, down)] = 20.0f * (right * stepLen - xLoc) * (yLoc - up * stepLen); field.bSource[DisplayObjects.FluidSolver.IX(right, down)] = 20.0f * (xLoc - left * stepLen) * (yLoc - up * stepLen); } } if (D.mouse.rightDown) { this.firing = true; } if (!D.mouse.rightDown && this.firing) { PlasmaBomb p = new PlasmaBomb(); // p.Displacement(this.xLoc,this.yLoc); p.Displacement((float) xLoc, (float) yLoc); p.Velocity(this.xVel, this.yVel); p.Acceleration(this.xAccel, this.yAccel); p.Color(this.red, this.green, this.blue); p.D = D; p.owner = this; this.projectiles.add(p); this.firing = false; } for (int i = 0; i < this.projectiles.size(); i++) { projectiles.get(i).emit(field); } }