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.
 
 
 

59 lines
1.5 KiB

class Wormhole extends Item{
//Class for the wormhole objects appearing on the game board
//Inherits following properties from Item:
/*
id: string
pos: Vector
radius: number
color: Serialized.Color
settings: Settings.Item
time: TimeProcess
*/
power: number
constructor(settings: Settings.Wormhole){
super(settings)
this.power = settings.power
this.fadeTime = settings.fadeTime
this.radius = p.random(settings.minRadius, settings.maxRadius)
}
serialized(): Serialized.Wormhole{
let item = super.serialized() as Serialized.Wormhole
return item
}
destroy(): void{
let index = game.wormholes.indexOf(this)
game.wormholes.splice(index, 1)
}
attractBall(ball: Ball): void{
let distance = ball.dist(this.centerX, this.centerY)
let force = (this.power * ball.radius * this.currentRadius) / p.pow(distance, 2)
let forceVector = Vector.sub(this.pos, ball.pos).setMag(force) as Vector
ball.applyForce(forceVector)
}
show(): void{
let alpha = 0
p.push()
p.noFill()
p.strokeWeight(2)
for (let r = this.currentRadius; r > 0; --r){
let color = p.color(this.color.fill)
color.setAlpha(p.constrain(alpha, 0, 1) * 255)
p.stroke(color)
p.ellipse(this.centerX, this.centerY, r * 2, r * 2)
alpha += 1 / this.currentRadius;
}
p.pop()
}
}