-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
03bcc93
commit c449ec9
Showing
4 changed files
with
93 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export class Bubble { | ||
constructor() {} | ||
update() { | ||
console.log('update'); | ||
} | ||
render(ctx) { | ||
console.log('render'); | ||
ctx.beginPath(); | ||
ctx.moveTo(this.x, this.y); | ||
ctx.arc(100, 75, 50, 0, 2 * Math.PI); | ||
ctx.stroke(); | ||
} | ||
init() {} | ||
isAlive() { | ||
return this.ttl >= 0; | ||
} | ||
} | ||
|
||
export function createBubble() { | ||
return new Bubble(...arguments); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { fgc2 } from './constants'; | ||
import { Pool, Sprite } from './kontra'; | ||
|
||
export class BubbleEffect { | ||
timeBetweenBubbles = 10; | ||
timeSinceLastBubble = 10; | ||
timeSinceLastBoostBubble = 10; | ||
constructor() { | ||
this.pool = Pool({ | ||
// TODO (johnedvard) Figure out how to use custom object instead | ||
create: Sprite, | ||
maxSize: 20, | ||
}); | ||
} | ||
render() { | ||
this.pool.render(); | ||
} | ||
update() { | ||
this.timeSinceLastBubble += 1; | ||
this.timeSinceLastBoostBubble += 5; | ||
this.pool.update(); | ||
} | ||
addBubbles({ x, y, isBoost }) { | ||
if (!isBoost && this.timeSinceLastBubble <= this.timeBetweenBubbles) return; | ||
if (isBoost && this.timeSinceLastBoostBubble <= this.timeBetweenBubbles) { | ||
return; | ||
} | ||
this.timeSinceLastBubble = 0; | ||
this.timeSinceLastBoostBubble = 0; | ||
this.pool.get({ | ||
// XXX (johnedvard) I don't know why, but we need to divide by 2. Must be some scaling issues | ||
x: x / 2, | ||
y: y / 2, | ||
width: 20, | ||
height: 40, | ||
color: fgc2, | ||
ttl: 50, | ||
render: function () { | ||
let size = 8; | ||
if (isBoost) size = 4; | ||
const ctx = this.context; | ||
ctx.lineWidth = 2; | ||
ctx.globalAlpha = this.ttl / 60; | ||
ctx.strokeStyle = this.color; | ||
ctx.beginPath(); | ||
ctx.arc(this.x, this.y, size, 0, 2 * Math.PI); | ||
ctx.stroke(); | ||
}, | ||
update: function (dt) { | ||
this.ttl -= 1; | ||
this.x += Math.random() > 0.5 ? 1 : -1; | ||
this.y -= 1; | ||
if (isBoost && this.ttl > 30) { | ||
this.y += 2; | ||
} else if (isBoost) { | ||
this.y += 1.5; | ||
} | ||
}, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters