This commit is contained in:
choelzl 2022-02-21 00:15:03 +01:00
parent a5c4be914b
commit 4161844c4c
Signed by: sora
GPG Key ID: A362EA0491E2EEA0
2 changed files with 511 additions and 79 deletions

410
web/chatguessr/bus.js Normal file

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,7 @@ $(function () {
const webSocket = window.socket;
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 lastframe = 0;
@ -48,27 +48,38 @@ $(function () {
const part_speed = 50;
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 {
constructor(emote,data){
this.size = 64;
this.data = data;
this.x = Math.random() * canvas.width - this.size;
this.y = Math.random() * canvas.height - this.size;
this.vx = this.vy = 0;
this.ax = this.ay = 0;
this.setPhysics(randRange(0,canvas.width),
randRange(0,canvas.height),
0,0,0,0);
this.emote = emote;
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(){
ctx.globalAlpha = tWave(this.time);
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){
@ -84,12 +95,11 @@ $(function () {
class RainP extends Particle {
constructor(emote,data) {
super(emote,data)
this.x = Math.random() * canvas.width;
this.y = - this.size;
this.vx = 0;
this.vy = 15;
this.ax = 0, this.ay = 0;
this.time = 2;
this.setPhysics(randRange(0, canvas.width),
randRange(0, canvas.height-this.size),
0,15,
0,0)
this.time = 5.5+this.y/canvas.height*2;
}
update(tick){
super.update(tick)
@ -99,11 +109,13 @@ $(function () {
class BounceP extends Particle {
constructor(emote,data) {
super(emote,data)
this.x = Math.random() * canvas.width;
this.y = Math.random() * canvas.height;
this.vx = (Math.random() * 2 - 1) *15;
this.vy = (Math.random() * 2 - 1) * 15;
this.ax = 0, this.ay = 0;
let speed = randRange(5,10);
let ang = randRange(0, 2*Math.PI);
this.setPhysics(randRange(0, canvas.width),
randRange(0, canvas.height),
Math.cos(ang)*speed,
Math.sin(ang)*speed,
0,0)
}
update(tick){
@ -128,76 +140,92 @@ $(function () {
class BounceGP extends BounceP {
constructor(emote,data) {
super(emote,data)
this.x = Math.random() * canvas.width;
this.y = Math.random() * canvas.height;
this.vx = Math.random() * 20 - 10;
this.vy = Math.random() * 20 - 10;
this.ax = 0, this.ay = 10;
let speed = randRange(5,10);
let ang = randRange(0,2*Math.PI);
this.setPhysics(randRange(0,canvas.width),
randRange(0,canvas.height),
Math.cos(ang)*speed,
Math.sin(ang)*speed,
0,10);
}
}
update(tick){
super.update(tick);
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;
}
}
class FireworkP extends Particle {
constructor(emote,data) {
super(emote,data)
this.x = canvas.width/2;
this.y = canvas.height;
this.vx = 0;
this.vy = -15;
this.ax = 0;
this.ay = 0;
this.time=4;
this.boom = false;
this.setPhysics(canvas.width/2,canvas.height,
0,-15,
0,0);
this.time=fdt;
}
update(tick){
super.update(tick);
if(this.y <= canvas.height/4 && !this.boom){
let angle = Math.random() *2 * Math.PI;
this.vx = Math.sin(angle) * (Math.random()*4 + 10);
this.vy = Math.cos(angle) * (Math.random()*4 + 10);
this.ay = 10;
this.boom = true;
if(this.y <= canvas.height/4 && this.time < drt){
this.time = drt;
genExplosion(this.x,this.y,360)
}
}
}
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() {
new RainP('peepo', {});
new RainP('peepo', {});
new RainP('peepo', {});
new RainP('peepo', {});
new RainP('peepo', {});
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', {});
createParticule(BounceGP, "nod", {}, {})
createParticule(BounceP, "nod", {}, {})
createParticule(BounceP, "nod", {}, {})
createParticule(BombP, "nod", {}, {})
createParticule(FireworkP, "nod", {}, {})
//genRain();
main(0);
}
@ -209,16 +237,10 @@ $(function () {
ctx.clearRect(0, 0, canvas.width, canvas.height);
if (!initialized) {
if (preloaded) {
setTimeout(function(){initialized = true;}, 1000);
}
if (preloaded) setTimeout(function(){initialized = true;}, 1000);
} else {
particles.forEach((particle) => {
particle.update(dt);
});
particles.forEach((particle) => {
particle.draw();
});
particles.forEach(p => p.update(dt));
particles.forEach(p => p.draw());
}
}