You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

90 lines
2.3 KiB

"use strict"
class Goal{
constructor(){
this.dim = createVector(200, 375);
}
setBrick(b){
this.pos = createVector(b.pos.x + b.dim.x / 2, b.pos.y);
this.vel = b.vel;
this.brick = b;
}
update(){
let b = this.brick;
this.pos = createVector(b.pos.x + b.dim.x / 2, b.pos.y);
}
display(){
this.show();
}
show(){
fill(colors.goal.main);
noStroke();
rect(this.pos.x - this.dim.x / 2, this.pos.y - this.dim.y * 0.76, this.dim.x, this.dim.y * 0.76);
triangle(this.pos.x - this.dim.x / 2, this.pos.y - this.dim.y * 0.75, this.pos.x, this.pos.y - this.dim.y, this.pos.x + this.dim.x / 2, this.pos.y - this.dim.y * 0.75);
stroke(colors.goal.roof);
strokeWeight(20);
line(this.pos.x - this.dim.x / 2 - this.dim.x * 0.1, this.pos.y - this.dim.y * 0.75 + this.dim.x * 0.1, this.pos.x, this.pos.y - this.dim.y);
line(this.pos.x + this.dim.x / 2 + this.dim.x * 0.1, this.pos.y - this.dim.y * 0.75 + this.dim.x * 0.1, this.pos.x, this.pos.y - this.dim.y);
fill(colors.goal.hole);
noStroke();
rect(this.pos.x - this.dim.x / 3, this.pos.y - this.dim.y * 0.41, this.dim.x * 2 / 3, this.dim.y * 0.41);
arc(this.pos.x, this.pos.y - this.dim.y * 0.4, this.dim.x * 2 / 3, this.dim.x * 2 / 3, PI, TWO_PI);
}
contains(p){
if (p.pos.x + p.radius < this.pos.x + this.dim.x / 2 && p.pos.x - p.radius > this.pos.x - this.dim.x / 2
&& p.pos.y - p.radius > this.pos.y - this.dim.y && p.pos.y + p.radius <= this.pos.y){
return true;
}
return false;
}
hint(player, world){
let pl = player.pos.copy();
let gl = this.pos.copy();
let v = p5.Vector.sub(gl, pl).normalize();
let d = dist(pl.x, pl.y, gl.x, gl.y);
while (true){
v.setMag(v.mag() + 1);
if (pl.x + v.x > viewPort.x + width - 20
|| pl.x + v.x < viewPort.x + 20
|| pl.y + v.y > viewPort.y + height - 20
|| pl.y + v.y < viewPort.y + 20){
break;
}
}
if (v.mag() > d) return;
let pos = p5.Vector.add(pl, v);
//green starts at a distance of worldWidth / 3
let r = d / (world.dim.x / 3) * 255;
//Arrow
push();
translate(pos.x, pos.y);
rotate(v.heading());
strokeWeight(3);
stroke(0);
fill(r, 255 - r, 0);
//Arrow
beginShape();
vertex(0, 0);
vertex(-10, 10);
vertex(-10, 5);
vertex(-30, 5);
vertex(-30, -5);
vertex(-10, -5);
vertex(-10, -10);
vertex(0, 0);
endShape();
pop();
}
}