Første version af kode - RealMrMario/Tank_game GitHub Wiki
Mover m;
PVector g = new PVector(0, 0.1);
void setup() {
size(1920, 900);
}
void mouseReleased() {
m = new Mover(); PVector f = new PVector(mouseX,-(height - mouseY)); println(f); //float ma = log(f.mag()*100); //f.normalize(); f.mult(0.02);//ma); m.update(f);
}
void draw() {
clear(); stroke(255); line(0,900,mouseX,mouseY); if (m != null) { m.display(); m.update(g); }
}
class Mover {
PVector loc; PVector acc; PVector vel; float aVel = 0; float angle = 0; float aAcc = 0.5;
} Mover() {
loc = new PVector(0, 900); acc = new PVector(0, 0); vel = new PVector();
}
void update(PVector f) {
acc.add(f); vel.add(acc); loc.add(vel); acc.mult(0); aVel += aAcc; angle += aVel; aAcc = acc.x;
}
void display() {
rectMode(CENTER); translate(loc.x, loc.y); rotate(angle); ellipse(0, 0, 32, 16);}
}