sources, input bug fix and pre-projectiles
This commit is contained in:
parent
33a9f46bb9
commit
402fe7e3bc
|
@ -10,7 +10,10 @@ void userMovement(char k, float hfo) {
|
|||
break;
|
||||
case 's':
|
||||
finalAngle += PI;
|
||||
break;
|
||||
}
|
||||
if (finalAngle == hfo && k != 'w')
|
||||
return;
|
||||
PVector t = PVector.fromAngle(finalAngle);
|
||||
t.setMag(USER_ACCELERATION_MAGNITUDE);
|
||||
userVelocity.add(t);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection#Given_two_points_on_each_line_segment
|
||||
PVector intersect(PVector A, PVector B, PVector C, PVector D) {
|
||||
final float d = ((A.x-B.x)*(C.y-D.y)-(A.y-B.y)*(C.x-D.x));
|
||||
final float t = ((A.x-C.x)*(C.y-D.y)-(A.y-C.y)*(C.x-D.x))/d;
|
||||
|
@ -8,6 +9,7 @@ PVector intersect(PVector A, PVector B, PVector C, PVector D) {
|
|||
return output;
|
||||
}
|
||||
|
||||
// https://math.stackexchange.com/questions/65503/point-reflection-over-a-line
|
||||
boolean reflect(Projectile p, Wall w) {
|
||||
// Position -> Next : A -> B
|
||||
// Wall.start -> Wall.end : C -> D
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
final int SHOOTING_COOLDOWN = 2;
|
||||
final int SHOOTING_COOLDOWN = 1;
|
||||
final float PROJECTILE_RADIUS = 10;
|
||||
final float VELOCITY_MAGNITUDE = 2;
|
||||
final float HEADING_LINE_LENGTH = 50;
|
||||
|
@ -56,6 +56,18 @@ void setup() {
|
|||
new PVector(100, height-100),
|
||||
new PVector(100, 100)
|
||||
));
|
||||
|
||||
final PVector center = new PVector(width/2, height/2);
|
||||
for (float a = 0; a < TWO_PI; a+=0.01) {
|
||||
PVector v = new PVector(
|
||||
cos(a) * HEADING_LINE_LENGTH,
|
||||
sin(a) * HEADING_LINE_LENGTH
|
||||
);
|
||||
projectiles.add(new Projectile(
|
||||
PVector.add(center, v),
|
||||
PVector.mult(PVector.div(v, v.mag()), VELOCITY_MAGNITUDE)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
void draw() {
|
||||
|
@ -70,7 +82,7 @@ void draw() {
|
|||
p.move();
|
||||
}
|
||||
|
||||
mouse = new PVector(mouseX, mouseY);
|
||||
mouse = new PVector(width, height / 2);
|
||||
stroke(255,0,0);
|
||||
fill(255,0,0);
|
||||
ellipse(userPosition.x, userPosition.y, PROJECTILE_RADIUS*2, PROJECTILE_RADIUS*2);
|
||||
|
@ -132,7 +144,8 @@ void draw() {
|
|||
}
|
||||
userPosition = nPos.copy();
|
||||
|
||||
if (keyPressed) {
|
||||
if (keyPressed)
|
||||
userMovement(key, headingFromOrigin);
|
||||
}
|
||||
|
||||
// saveFrame("Y:\\Stash\\ProcessingAnimations\\Reflections\\frame-#####.png");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user