WIP
This commit is contained in:
parent
a5c4be914b
commit
4161844c4c
410
web/chatguessr/bus.js
Normal file
410
web/chatguessr/bus.js
Normal file
File diff suppressed because one or more lines are too long
@ -9,7 +9,7 @@ $(function () {
|
|||||||
|
|
||||||
const webSocket = window.socket;
|
const webSocket = window.socket;
|
||||||
const emote_str = ["peepo", 'nod']
|
const emote_str = ["peepo", 'nod']
|
||||||
const emote_url = ['https://cdn.7tv.app/emote/603cac391cd55c0014d989be/2x', 'https://cdn.7tv.app/emote/60ae4bb30e35477634610fda/1x']
|
const emote_url = ['https://cdn.7tv.app/emote/603cac391cd55c0014d989be/4x', 'https://cdn.7tv.app/emote/60ae4bb30e35477634610fda/4x']
|
||||||
var img_map = {};
|
var img_map = {};
|
||||||
|
|
||||||
var lastframe = 0;
|
var lastframe = 0;
|
||||||
@ -48,27 +48,38 @@ $(function () {
|
|||||||
|
|
||||||
const part_speed = 50;
|
const part_speed = 50;
|
||||||
const part_bounce_el = 0.9
|
const part_bounce_el = 0.9
|
||||||
|
const fdt = 1;
|
||||||
|
const drt = 8;
|
||||||
|
const tWave = (t) => (t<0 || t>drt )? 0 : (t<fdt ? t/fdt : (t>(drt-fdt) ? (drt-t)/fdt : 1))
|
||||||
|
const sWave = (t, s) => (t<0 || t>drt) ? 1 : (t<fdt ? t*s/fdt : (t>(drt-fdt) ? (drt-t)*s/fdt : s))
|
||||||
|
|
||||||
const tWave = (t) => (t<0 || t>8 )? 0 : (t<2 ? t/2 : (t>6 ? (8-t)/2 : 1))
|
const randRange = (min,max) => (Math.random()* (max-min) + min)
|
||||||
|
|
||||||
class Particle {
|
class Particle {
|
||||||
constructor(emote,data){
|
constructor(emote,data){
|
||||||
this.size = 64;
|
this.size = 64;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.x = Math.random() * canvas.width - this.size;
|
this.setPhysics(randRange(0,canvas.width),
|
||||||
this.y = Math.random() * canvas.height - this.size;
|
randRange(0,canvas.height),
|
||||||
this.vx = this.vy = 0;
|
0,0,0,0);
|
||||||
this.ax = this.ay = 0;
|
|
||||||
this.emote = emote;
|
this.emote = emote;
|
||||||
this.time = 0;
|
this.time = 0;
|
||||||
particles.push(this);
|
}
|
||||||
setTimeout(()=>{particles.pop()}, 10000);
|
|
||||||
|
setPhysics(x,y,vx,vy,ax,ay){
|
||||||
|
this.x = x || this.x || 0;
|
||||||
|
this.y = y || this.y || 0;
|
||||||
|
this.vx = vx || this.vx || 0;
|
||||||
|
this.vy = vy || this.vy || 0;
|
||||||
|
this.ax = ax || this.ax || 0;
|
||||||
|
this.ay = ay || this.ay || 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
draw(){
|
draw(){
|
||||||
ctx.globalAlpha = tWave(this.time);
|
ctx.globalAlpha = tWave(this.time);
|
||||||
if(img_map[this.emote])
|
if(img_map[this.emote])
|
||||||
ctx.drawImage(img_map[this.emote], this.x, this.y, this.size, this.size);
|
ctx.drawImage(img_map[this.emote], this.x, this.y,
|
||||||
|
sWave(this.time,this.size), sWave(this.time,this.size));
|
||||||
}
|
}
|
||||||
|
|
||||||
update(tick){
|
update(tick){
|
||||||
@ -84,12 +95,11 @@ $(function () {
|
|||||||
class RainP extends Particle {
|
class RainP extends Particle {
|
||||||
constructor(emote,data) {
|
constructor(emote,data) {
|
||||||
super(emote,data)
|
super(emote,data)
|
||||||
this.x = Math.random() * canvas.width;
|
this.setPhysics(randRange(0, canvas.width),
|
||||||
this.y = - this.size;
|
randRange(0, canvas.height-this.size),
|
||||||
this.vx = 0;
|
0,15,
|
||||||
this.vy = 15;
|
0,0)
|
||||||
this.ax = 0, this.ay = 0;
|
this.time = 5.5+this.y/canvas.height*2;
|
||||||
this.time = 2;
|
|
||||||
}
|
}
|
||||||
update(tick){
|
update(tick){
|
||||||
super.update(tick)
|
super.update(tick)
|
||||||
@ -99,11 +109,13 @@ $(function () {
|
|||||||
class BounceP extends Particle {
|
class BounceP extends Particle {
|
||||||
constructor(emote,data) {
|
constructor(emote,data) {
|
||||||
super(emote,data)
|
super(emote,data)
|
||||||
this.x = Math.random() * canvas.width;
|
let speed = randRange(5,10);
|
||||||
this.y = Math.random() * canvas.height;
|
let ang = randRange(0, 2*Math.PI);
|
||||||
this.vx = (Math.random() * 2 - 1) *15;
|
this.setPhysics(randRange(0, canvas.width),
|
||||||
this.vy = (Math.random() * 2 - 1) * 15;
|
randRange(0, canvas.height),
|
||||||
this.ax = 0, this.ay = 0;
|
Math.cos(ang)*speed,
|
||||||
|
Math.sin(ang)*speed,
|
||||||
|
0,0)
|
||||||
}
|
}
|
||||||
|
|
||||||
update(tick){
|
update(tick){
|
||||||
@ -128,76 +140,92 @@ $(function () {
|
|||||||
class BounceGP extends BounceP {
|
class BounceGP extends BounceP {
|
||||||
constructor(emote,data) {
|
constructor(emote,data) {
|
||||||
super(emote,data)
|
super(emote,data)
|
||||||
this.x = Math.random() * canvas.width;
|
let speed = randRange(5,10);
|
||||||
this.y = Math.random() * canvas.height;
|
let ang = randRange(0,2*Math.PI);
|
||||||
this.vx = Math.random() * 20 - 10;
|
this.setPhysics(randRange(0,canvas.width),
|
||||||
this.vy = Math.random() * 20 - 10;
|
randRange(0,canvas.height),
|
||||||
this.ax = 0, this.ay = 10;
|
Math.cos(ang)*speed,
|
||||||
|
Math.sin(ang)*speed,
|
||||||
|
0,10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ExplosionP extends Particle {
|
||||||
|
constructor(emote,data,args){
|
||||||
|
super(emote,data)
|
||||||
|
let speed = randRange(0,6) + 7;
|
||||||
|
let fang = 2*Math.PI* (args.angle/360)
|
||||||
|
let ang = randRange(-fang/2, +fang/2)+Math.PI/2 ;//+ 2*(angle/360)*Math.PI;
|
||||||
|
this.setPhysics(args.x,args.y,
|
||||||
|
Math.cos(ang)*speed,
|
||||||
|
-Math.sin(ang)*speed,
|
||||||
|
0,10);
|
||||||
|
this.time = drt - fdt*1.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
update(tick){
|
|
||||||
super.update(tick);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class FireworkP extends Particle {
|
class FireworkP extends Particle {
|
||||||
constructor(emote,data) {
|
constructor(emote,data) {
|
||||||
super(emote,data)
|
super(emote,data)
|
||||||
this.x = canvas.width/2;
|
this.setPhysics(canvas.width/2,canvas.height,
|
||||||
this.y = canvas.height;
|
0,-15,
|
||||||
this.vx = 0;
|
0,0);
|
||||||
this.vy = -15;
|
this.time=fdt;
|
||||||
this.ax = 0;
|
|
||||||
this.ay = 0;
|
|
||||||
this.time=4;
|
|
||||||
this.boom = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
update(tick){
|
update(tick){
|
||||||
super.update(tick);
|
super.update(tick);
|
||||||
if(this.y <= canvas.height/4 && !this.boom){
|
if(this.y <= canvas.height/4 && this.time < drt){
|
||||||
let angle = Math.random() *2 * Math.PI;
|
this.time = drt;
|
||||||
this.vx = Math.sin(angle) * (Math.random()*4 + 10);
|
genExplosion(this.x,this.y,360)
|
||||||
this.vy = Math.cos(angle) * (Math.random()*4 + 10);
|
}
|
||||||
this.ay = 10;
|
}
|
||||||
this.boom = true;
|
}
|
||||||
|
|
||||||
|
class BombP extends Particle {
|
||||||
|
constructor(emote,data) {
|
||||||
|
super(emote,data)
|
||||||
|
this.setPhysics(randRange(0, canvas.width-this.size),
|
||||||
|
-this.size,
|
||||||
|
0,15,
|
||||||
|
0,0)
|
||||||
|
this.time=fdt;
|
||||||
|
}
|
||||||
|
|
||||||
|
update(tick){
|
||||||
|
super.update(tick);
|
||||||
|
if(this.y >= canvas.height - this.size && this.time < drt){
|
||||||
|
this.time = drt;
|
||||||
|
genExplosion(this.x,this.y,60)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const createParticule = (partP, emote, data, args) => {
|
||||||
|
let a = new partP(emote,data,args)
|
||||||
|
particles.push(a);
|
||||||
|
setTimeout(()=>{particles.pop()}, drt*1000+2000);
|
||||||
|
}
|
||||||
|
|
||||||
|
const genExplosion = (x,y,ang) =>{
|
||||||
|
for(let i=0; i<50; ++i) new ExplosionP('nod', {},x,y,ang);
|
||||||
|
}
|
||||||
|
|
||||||
|
const genRain = () => {
|
||||||
|
for(let i = 0; i<50; ++i) new RainP('nod', {});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
|
createParticule(BounceGP, "nod", {}, {})
|
||||||
new RainP('peepo', {});
|
createParticule(BounceP, "nod", {}, {})
|
||||||
new RainP('peepo', {});
|
createParticule(BounceP, "nod", {}, {})
|
||||||
new RainP('peepo', {});
|
createParticule(BombP, "nod", {}, {})
|
||||||
new RainP('peepo', {});
|
createParticule(FireworkP, "nod", {}, {})
|
||||||
new RainP('peepo', {});
|
//genRain();
|
||||||
new BounceGP('nod', {});
|
|
||||||
new BounceP('nod', {});
|
|
||||||
new FireworkP('nod', {});
|
|
||||||
new FireworkP('nod', {});
|
|
||||||
new FireworkP('nod', {});
|
|
||||||
new FireworkP('nod', {});
|
|
||||||
new FireworkP('nod', {});
|
|
||||||
new FireworkP('nod', {});
|
|
||||||
new FireworkP('nod', {});
|
|
||||||
new FireworkP('nod', {});
|
|
||||||
new FireworkP('nod', {});
|
|
||||||
new FireworkP('nod', {});
|
|
||||||
new FireworkP('nod', {});
|
|
||||||
new FireworkP('nod', {});
|
|
||||||
new FireworkP('nod', {});
|
|
||||||
new FireworkP('nod', {});
|
|
||||||
new FireworkP('nod', {});
|
|
||||||
new FireworkP('nod', {});
|
|
||||||
new FireworkP('nod', {});
|
|
||||||
new FireworkP('nod', {});
|
|
||||||
new FireworkP('nod', {});
|
|
||||||
new FireworkP('nod', {});
|
|
||||||
new FireworkP('nod', {});
|
|
||||||
main(0);
|
main(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,16 +237,10 @@ $(function () {
|
|||||||
|
|
||||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
if (preloaded) {
|
if (preloaded) setTimeout(function(){initialized = true;}, 1000);
|
||||||
setTimeout(function(){initialized = true;}, 1000);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
particles.forEach((particle) => {
|
particles.forEach(p => p.update(dt));
|
||||||
particle.update(dt);
|
particles.forEach(p => p.draw());
|
||||||
});
|
|
||||||
particles.forEach((particle) => {
|
|
||||||
particle.draw();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user