Auto stash before merge of "master" and "origin/master"
@@ -897,6 +897,11 @@ Math.randomRange = function(min, max)
897
897
return min + (Math.random() * (max - min));
898
898
}
899
899
900
Math.lerp = function(a, b, t)
901
{
902
return a + (b - a) * t;
903
}
904
900
905
Array.prototype.random = function ()
901
906
{
902
907
return this[Math.floor((Math.random()*this.length))];
@@ -1663,7 +1668,195 @@ var GameInput =
1663
1668
1664
1669
/*
1665
1670
* Start File:
1666
* /c/Users/Nick/source/repos/frameworkv3/framework/util/ray.js
1671
* /e/Development/Repositories/frameworkv3/framework/util/particleEmitter.js
1672
*/
1673
class ParticleEmitter
1674
{
1675
static pool = [];
1676
mine = [];
1677
position = null;
1678
1679
emissionRate = 0;
1680
emissionTimer = 0;
1681
emissionAngle = 0;
1682
sprite = null;
1683
1684
constructor(position, sprite, r, a)
1685
{
1686
this.position = position;
1687
this.sprite = sprite;
1688
1689
this.emissionRate = r;
1690
this.animTimer = r;
1691
this.emissionAngle = a;
1692
}
1693
1694
update(deltaTime)
1695
{
1696
this.emissionTimer -= deltaTime;
1697
1698
if(this.emissionTimer <= 0)
1699
{
1700
this.emissionTimer = this.emissionRate;
1701
let newParticle = ParticleEmitter.unPool();
1702
this.mine.push(newParticle);
1703
1704
newParticle.emit(this, this.position.x, this.position.y, 0, 0, 0, 0, 0, 5, 0, this.sprite, 50, 50, 0, 0, 1, 2, 0.5, 1)
1705
}
1706
1707
for(let i = 0; i < this.mine.length; i++)
1708
{
1709
this.mine[i].update(deltaTime);
1710
}
1711
}
1712
1713
draw(scene)
1714
{
1715
for(let i = 0; i < this.mine.length; i++)
1716
{
1717
this.mine[i].draw(scene);
1718
}
1719
}
1720
1721
dispose(particle)
1722
{
1723
this.mine.remove(particle);
1724
ParticleEmitter.returnToPool(particle);
1725
}
1726
1727
static unPool() //get a particle from the static pool
1728
{
1729
if(ParticleEmitter.pool.length > 0)
1730
{
1731
return ParticleEmitter.pool.pop()
1732
}
1733
1734
return new Particle();
1735
}
1736
1737
static returnToPool(particle)
1738
{
1739
if(!ParticleEmitter.pool.contains(particle))
1740
{
1741
ParticleEmitter.pool.push(particle);
1742
}
1743
}
1744
}
1745
1746
class Particle
1747
{
1748
parent = null;
1749
position = null;
1750
rotation = 0;
1751
velocity = null;
1752
angularVelocity = 0;
1753
acceleration = null;
1754
angularAcceleration = 0;
1755
sprite = null;
1756
animTimer = 0;
1757
animationSpeed = 0;
1758
subImage = 0;
1759
startSize = null
1760
endSize = null;
1761
fadeInTime = 0;
1762
fadeInStart = 0;
1763
fadeOutTime = 0;
1764
lifeTime = 0;
1765
lifeTimeStart = 0;
1766
1767
constructor()
1768
{
1769
this.position = new vector(0,0);
1770
this.velocity = new vector(0,0);
1771
this.acceleration = new vector(0,0)
1772
this.startSize = new vector(0,0)
1773
this.endSize = new vector(0,0)
1774
}
1775
1776
emit(parent, x, y, r, vx, vy, va, ax, ay, ar, spr, ssx, ssy, esx, esy, lmin, lmax, fi = 0, fo = 0, as = 0)
1777
{
1778
this.parent = parent;
1779
this.position.x = x;
1780
this.position.y = y;
1781
this.rotation = r;
1782
this.velocity.x = vx;
1783
this.velocity.y = vy;
1784
this.angularVelocity = va;
1785
this.acceleration.x = ax;
1786
this.acceleration.y = ay;
1787
this.angularAcceleration = ar;
1788
this.sprite = spr;
1789
this.startSize.x = ssx;
1790
this.startSize.y = ssy;
1791
this.endSize.x = esx;
1792
this.endSize.y = esy;
1793
this.lifeTime = Math.randomRange(lmin, lmax);
1794
this.lifeTimeStart = this.lifeTime;
1795
this.fadeInTime = fi;
1796
this.fadeInStart = fi;
1797
this.fadeOutTime = fo;
1798
this.animationSpeed = as;
1799
this.animTimer = as;
1800
}
1801
1802
update(deltaTime)
1803
{
1804
this.position.x += this.velocity.x;
1805
this.position.y += this.velocity.y;
1806
this.velocity.x += this.acceleration.x;
1807
this.velocity.y += this.acceleration.y;
1808
1809
this.rotation += this.angularVelocity;
1810
this.angularVelocity += this.angularAcceleration;
1811
1812
this.lifeTime -= deltaTime;
1813
1814
if(this.fadeInTime > 0)
1815
this.fadeInTime -= deltaTime;
1816
1817
if(this.animationSpeed > 0)
1818
{
1819
this.animTimer -= deltaTime;
1820
1821
if(this.animTimer <= 0)
1822
{
1823
this.animTimer = this.animationSpeed;
1824
this.subImage = this.subImage % this.sprite.subImages;
1825
}
1826
}
1827
1828
if(this.lifeTime <= 0)
1829
this.parent.dispose(this);
1830
}
1831
1832
draw(scene)
1833
{
1834
let foAlpha = Math.min(1, this.lifeTime / this.fadeOutTime)
1835
1836
let fiAlpha = this.fadeInTime / this.fadeInStart;
1837
1838
this.sprite.draw(
1839
scene,
1840
Math.round(this.position.x),
1841
Math.round(this.position.y),
1842
Math.lerp(this.startSize.x, this.endSize.x, this.lifeTime / this.lifeTimeStart),
1843
Math.lerp(this.startSize.y, this.endSize.y, this.lifeTime / this.lifeTimeStart),
1844
this.rotation,
1845
false,
1846
false,
1847
Math.min(fiAlpha, foAlpha),
1848
this.subImage
1849
);
1850
}
1851
}
1852
/*
1853
* End File:
1854
* /e/Development/Repositories/frameworkv3/framework/util/particleEmitter.js
1855
*/
1856
1857
/*
1858
* Start File:
1859
* /e/Development/Repositories/frameworkv3/framework/util/ray.js
1667
1860
*/
1668
1861
class Ray
1669
1862
{
@@ -897,6 +897,11 @@ Math.randomRange = function(min, max)897
return min + (Math.random() * (max - min));897
return min + (Math.random() * (max - min));898
}898
}899
899
900
Math.lerp = function(a, b, t)901
{902
return a + (b - a) * t;903
}904
900
Array.prototype.random = function () 905
Array.prototype.random = function () 901
{906
{902
return this[Math.floor((Math.random()*this.length))];907
return this[Math.floor((Math.random()*this.length))];@@ -1663,7 +1668,195 @@ var GameInput =1663
1668
1664
/*1669
/*1665
* Start File:1670
* Start File:1666
* /c/Users/Nick/source/repos/frameworkv3/framework/util/ray.js1671
* /e/Development/Repositories/frameworkv3/framework/util/particleEmitter.js1672
*/ 1673
class ParticleEmitter1674
{1675
static pool = [];1676
mine = [];1677
position = null;1678
1679
emissionRate = 0;1680
emissionTimer = 0;1681
emissionAngle = 0;1682
sprite = null;1683
1684
constructor(position, sprite, r, a)1685
{1686
this.position = position;1687
this.sprite = sprite;1688
1689
this.emissionRate = r;1690
this.animTimer = r;1691
this.emissionAngle = a;1692
}1693
1694
update(deltaTime)1695
{1696
this.emissionTimer -= deltaTime;1697
1698
if(this.emissionTimer <= 0)1699
{1700
this.emissionTimer = this.emissionRate;1701
let newParticle = ParticleEmitter.unPool();1702
this.mine.push(newParticle);1703
1704
newParticle.emit(this, this.position.x, this.position.y, 0, 0, 0, 0, 0, 5, 0, this.sprite, 50, 50, 0, 0, 1, 2, 0.5, 1)1705
}1706
1707
for(let i = 0; i < this.mine.length; i++)1708
{1709
this.mine[i].update(deltaTime);1710
}1711
}1712
1713
draw(scene)1714
{1715
for(let i = 0; i < this.mine.length; i++)1716
{1717
this.mine[i].draw(scene);1718
}1719
}1720
1721
dispose(particle)1722
{1723
this.mine.remove(particle);1724
ParticleEmitter.returnToPool(particle);1725
}1726
1727
static unPool() //get a particle from the static pool1728
{1729
if(ParticleEmitter.pool.length > 0)1730
{1731
return ParticleEmitter.pool.pop()1732
}1733
1734
return new Particle();1735
}1736
1737
static returnToPool(particle)1738
{1739
if(!ParticleEmitter.pool.contains(particle))1740
{1741
ParticleEmitter.pool.push(particle);1742
}1743
}1744
}1745
1746
class Particle1747
{1748
parent = null;1749
position = null;1750
rotation = 0;1751
velocity = null;1752
angularVelocity = 0;1753
acceleration = null;1754
angularAcceleration = 0;1755
sprite = null;1756
animTimer = 0;1757
animationSpeed = 0;1758
subImage = 0;1759
startSize = null1760
endSize = null;1761
fadeInTime = 0;1762
fadeInStart = 0;1763
fadeOutTime = 0;1764
lifeTime = 0;1765
lifeTimeStart = 0;1766
1767
constructor()1768
{1769
this.position = new vector(0,0);1770
this.velocity = new vector(0,0);1771
this.acceleration = new vector(0,0)1772
this.startSize = new vector(0,0)1773
this.endSize = new vector(0,0)1774
}1775
1776
emit(parent, x, y, r, vx, vy, va, ax, ay, ar, spr, ssx, ssy, esx, esy, lmin, lmax, fi = 0, fo = 0, as = 0)1777
{1778
this.parent = parent;1779
this.position.x = x;1780
this.position.y = y;1781
this.rotation = r;1782
this.velocity.x = vx;1783
this.velocity.y = vy;1784
this.angularVelocity = va;1785
this.acceleration.x = ax;1786
this.acceleration.y = ay;1787
this.angularAcceleration = ar;1788
this.sprite = spr;1789
this.startSize.x = ssx;1790
this.startSize.y = ssy;1791
this.endSize.x = esx;1792
this.endSize.y = esy;1793
this.lifeTime = Math.randomRange(lmin, lmax);1794
this.lifeTimeStart = this.lifeTime;1795
this.fadeInTime = fi;1796
this.fadeInStart = fi;1797
this.fadeOutTime = fo;1798
this.animationSpeed = as;1799
this.animTimer = as;1800
}1801
1802
update(deltaTime)1803
{1804
this.position.x += this.velocity.x;1805
this.position.y += this.velocity.y;1806
this.velocity.x += this.acceleration.x;1807
this.velocity.y += this.acceleration.y;1808
1809
this.rotation += this.angularVelocity;1810
this.angularVelocity += this.angularAcceleration;1811
1812
this.lifeTime -= deltaTime;1813
1814
if(this.fadeInTime > 0)1815
this.fadeInTime -= deltaTime;1816
1817
if(this.animationSpeed > 0)1818
{1819
this.animTimer -= deltaTime;1820
1821
if(this.animTimer <= 0)1822
{1823
this.animTimer = this.animationSpeed;1824
this.subImage = this.subImage % this.sprite.subImages;1825
}1826
}1827
1828
if(this.lifeTime <= 0)1829
this.parent.dispose(this);1830
}1831
1832
draw(scene)1833
{1834
let foAlpha = Math.min(1, this.lifeTime / this.fadeOutTime)1835
1836
let fiAlpha = this.fadeInTime / this.fadeInStart;1837
1838
this.sprite.draw(1839
scene,1840
Math.round(this.position.x), 1841
Math.round(this.position.y), 1842
Math.lerp(this.startSize.x, this.endSize.x, this.lifeTime / this.lifeTimeStart), 1843
Math.lerp(this.startSize.y, this.endSize.y, this.lifeTime / this.lifeTimeStart), 1844
this.rotation, 1845
false,1846
false,1847
Math.min(fiAlpha, foAlpha),1848
this.subImage1849
);1850
}1851
}1852
/*1853
* End File:1854
* /e/Development/Repositories/frameworkv3/framework/util/particleEmitter.js1855
*/ 1856
1857
/*1858
* Start File:1859
* /e/Development/Repositories/frameworkv3/framework/util/ray.js1667
*/ 1860
*/ 1668
class Ray1861
class Ray1669
{1862
{@@ -11,6 +11,8 @@ class Chao extends GameObject
11
11
behaviourList = [];
12
12
currentBehaviour = null;
13
13
14
particler = null;
15
14
16
static Instance;
15
17
16
18
get busyWithBehaviour()
@@ -43,6 +45,8 @@ class Chao extends GameObject
43
45
44
46
this.renderer.defaultAnimationSpeed = 0.2;
45
47
this.registerBehaviour(new BehaviourSneeze());
48
49
this.particler = new ParticleEmitter(new vector(100, 100), this.scene.game.gem, 0.1, 0)
46
50
}
47
51
48
52
onClick(btn)
@@ -58,6 +62,7 @@ class Chao extends GameObject
58
62
update(deltaTime)
59
63
{
60
64
super.update(deltaTime);
65
this.particler.update(deltaTime)
61
66
62
67
if(this.busyWithBehaviour)
63
68
this.currentBehaviour.update(deltaTime);
@@ -72,4 +77,10 @@ class Chao extends GameObject
72
77
}
73
78
}
74
79
}
80
81
draw(context)
82
{
83
super.draw(context);
84
this.particler.draw(this.scene)
85
}
75
86
}
@@ -11,6 +11,8 @@ class Chao extends GameObject11
behaviourList = [];11
behaviourList = [];12
currentBehaviour = null;12
currentBehaviour = null;13
13
14
particler = null;15
14
static Instance;16
static Instance;15
17
16
get busyWithBehaviour()18
get busyWithBehaviour()@@ -43,6 +45,8 @@ class Chao extends GameObject43
45
44
this.renderer.defaultAnimationSpeed = 0.2;46
this.renderer.defaultAnimationSpeed = 0.2;45
this.registerBehaviour(new BehaviourSneeze());47
this.registerBehaviour(new BehaviourSneeze());48
49
this.particler = new ParticleEmitter(new vector(100, 100), this.scene.game.gem, 0.1, 0)46
}50
}47
51
48
onClick(btn)52
onClick(btn)@@ -58,6 +62,7 @@ class Chao extends GameObject58
update(deltaTime)62
update(deltaTime)59
{63
{60
super.update(deltaTime);64
super.update(deltaTime);65
this.particler.update(deltaTime)61
66
62
if(this.busyWithBehaviour)67
if(this.busyWithBehaviour)63
this.currentBehaviour.update(deltaTime);68
this.currentBehaviour.update(deltaTime);@@ -72,4 +77,10 @@ class Chao extends GameObject72
}77
}73
}78
}74
}79
}80
81
draw(context)82
{83
super.draw(context);84
this.particler.draw(this.scene)85
}75
}86
}