Hey,
ich glaube ich verlier gerade meinen Verstand.
Ich habe eine Mutterklasse GameOBject in der die Variable speed lokalisiert ist.
[code=Java]package suchtytv.complexservice.game.objects;
import java.awt.Graphics;
import suchtytv.complexservice.game.maths.Vector;
public abstract class GameObject {
Vector speed = Vector.Zero;
Vector pos; //Jeder GameObejct hat eine Position
public GameObject(Vector pos) {
this.pos = pos;
}
//gibt Position zurück
public Vector getPosition() {
return pos;
}
//setzt Position
public void setPosition(Vector v) {
this.pos = v;
}
public abstract void display(Graphics g, Vector scale) throws Exception;
public Vector getSpeed() {
return speed;
}
public void setSpeed(Vector speed) {
this.speed = speed;
}
}
[/code]
Von dieser Klasse erbt Obstacle...:
[code=Java]package suchtytv.complexservice.game.objects;
import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.Random;
import suchtytv.complexservice.game.components.Simulation;
import suchtytv.complexservice.game.maths.Vector;
public class Obstacle extends GameObject implements IUpdateable{
private Color c;
private ArrayList<ArrayList<Double>> functions;
private Vector startPos;
private double radiusMAX;
private double radiusUpMAX;
private double radiusLeftMAX;
private double radius;
private double radiusUp;
private double radiusLeft;
private double growthSpeed;
private boolean bursted;
private Shape shape;
private int functioncounter = 0;
public Obstacle(Vector pos,Shape s, double radius, double growthspeed,ArrayList<ArrayList<Double>> functions) {
super(pos);
Random r = new Random();
c = new Color(r.nextInt(255), r.nextInt(255), r.nextInt(255));
shape = s;
if(shape == Shape.CIRCLE) {
this.radiusMAX = radius;
radiusUpMAX = radius;
radiusLeftMAX = radius;
}
if(shape == Shape.RECTANGLE) {
radiusUpMAX = radius;
radiusLeftMAX = radius;
radiusMAX = 1000000000;
}
setRadiusZero();
this.growthSpeed = growthspeed;
this.functions = functions;
startPos = pos;
speed.setX(0.01 * Math.random());
}
public Obstacle(Vector pos, Shape s, double radius, Color c, double growthspeed,ArrayList<ArrayList<Double>> functions) {
super(pos);
this.radiusMAX = radius;
this.c = c;
shape = s;
radiusUpMAX = radius;
radiusLeftMAX = radius;
setRadiusZero();
this.growthSpeed = growthspeed;
this.functions = functions;
startPos = pos;
speed.setX(0.01 * Math.random());
}
public Obstacle(Vector pos, double radiusUP, double radiusLeft, Color c, double growthspeed,ArrayList<ArrayList<Double>> functions) {
super(pos);
this.c = c;
shape = Shape.RECTANGLE;
this.radiusUpMAX = radiusUP;
this.radiusLeftMAX = radiusLeft;
radiusMAX = 1000000000;
setRadiusZero();
this.growthSpeed = growthspeed;
this.functions = functions;
startPos = pos;
speed.setX(0.01 * Math.random());
}
public Obstacle(Vector pos, double radiusUP, double radiusLeft, double growthspeed,ArrayList<ArrayList<Double>> functions) {
super(pos);
Random r = new Random();
c = new Color(r.nextInt(255), r.nextInt(255), r.nextInt(255));
shape = Shape.RECTANGLE;
this.radiusUpMAX = radiusUP;
this.radiusLeftMAX = radiusLeft;
radiusMAX = 1000000000;
setRadiusZero();
this.growthSpeed = growthspeed;
this.functions = functions;
startPos = pos;
speed.setX(0.01 * Math.random());
}
//Andere Methoden hier
public void move(double t) {
pos.setX(pos.getX()+speed.getX()*(-t));
if(functions.get(functioncounter).get(5) < Simulation.ObstacleStartPosX-pos.getX()) {
functioncounter ++;
// System.out.println(functions.get(0).get(5));
}
if(pos.getX() <= 0) {
bursted = true;
return;
}
double x = Simulation.ObstacleStartPosX - pos.getX();
pos.setY(functions.get(functioncounter).get(0)*x*x*x+functions.get(functioncounter).get(1)*x*x+functions.get(functioncounter).get(2)*x+functions.get(functioncounter).get(3));
}
}
[/code]
Mit der Methode move(zeiit) soll je nach spezifichen Speed eine unterschiedliche Position angenommen werden.
Die spezifische Geschwindigkeit einer jeden Instanz wird im Konstruktor festgelegt.
NUN DER BUG:
Wird ein Objekt zerstört und/oder neu erstellt, verändert dies die geschwindigkeit global...
Versteh ich nicht...