New games every week!
JSE - Particles
31st May 2021  
I really did intend to work on the Music Editor, yesterday, but..
Oh boy, that just wasn't happening!!


The deeper I delved, the more issues to fix I found.
I eventually gave up trying to decide which bits to work on first, and instead found myself working on the Particle Engine for JSE.

Why not!?!


The most convoluted command in the language so far..
ThrowParticle( X, Y, Type, Direction, Speed, Symbol, Colour, Blend)

One simple command, a whole pile of behind the scenes work.

There are (currently) 8 types..
1. Straight line
2. Falls downwards
3. Falls downwards with a fake bounce
4. Slows down
5. Speeds up
6. Falls upwards(!)
7. Also falls upwards, but appears more smoke-like
8. Swirls around the spawn point

Note about Particles
For the final 8 or so frames, the particles will rotate back to 0 degrees. Browsers seem to struggle with both Alpha and Rotation at the same time. Really odd behaviour! (I expect this is more than likely something to do with how I'm drawing them, than the browsers themselves)

Hopefully it isn't too noticeable. It works best if you draw rotationally symmetrical sprites for them, to hide it!


There are now different blend modes, 1 to 11, with Lighten, Multiply, Dodge and more being accounted for.
The blend modes are also now available for general purpose drawing use. Text, images, shapes and the like should all behave as you set it.
SetBlend(Mode) (number or name!) has been implemented, functions like the scale/alpha/rotation commands, and will similarly reset with the ResetDraw command.

Note about blending. A lot of the blend modes don't show up on black backgrounds (my typical background style!!) Maybe make the background a bit brighter before you start experimenting!

Two code examples, today..

Particle Example

// Particle Test // by Jayenkai // Created 2021/5/30 Symbol 0,"0__0_0_0!P@"; Symbol 1,"0__4_40?440!440!440!440!440?4_4"; Symbol 2,"0__0,II0?I00I0.I00I0,I0.I00I0.I0I00II00II0I00I0I0I0.I"; Symbol 3,"2__0_0,y@0_0_0!y_0,y00y0_0/y?zyy0,z0,y0_0/y/:0!z0_y@0/:y.:yyz0@y@0z00yz00y.:yy:0@y@0,::0,zy/0y0!y.zy,0!:0y,:y.0_0,z.yzy,:yzzy!:00y0/y0yz,yzy_y?0!y0,:0zz:zy_y/:0_y0yz,y_y/0@y:,y.0.:zyz?yz,0?y0z:?yyz0y0zyz!yzzyz0y0!:.y,:z0,yz.yz,:zz0@:?y,0.z.yz?yz0.y,zy:yyz:zyz.y0y:z@0.y@zyz!yz00z_0,y,::y,zyz.yz0,z.yyzyz00:0y.zy::z?y:yz0,z@0.y?zyyz,y?:,z?0z0!yyzy?z,y,:zz:,z,y0@y.:zyz,yz?:z::z,y00z:0.yyzyy:y:z:zzy.:.z.0@y_0y0:yzzy:yz,:z0@y/z0.zyyz_0@y,zy.00y0z,yz@0@yyzy?00z0z_z,0z0_z0,z:.0_0_0/:00:.0z0_0_0!:0:.0z00z0_0_0,z0:.00z0!z"; Symbol 4,"0__0_0_;00;0?;;0!;;0?;00;"; Symbol 5,"0__00T.0,TTccTT0TTcVVcT,cV.cTTcV.cT,cVVcTT0TTccTT0,T."; Graphics 800,600,1 SetParticleSize 16 ScrollX=0;ScrollY Blend=0 SetFont "CPC" Repeat CLS 30,30,80 ResetDraw Print "Particle Test" SetSize(0.25); Starfield(0,3,4);ResetDraw(); Text ScreenWidth/2,ScreenHeight*0.2,Chr$(242)+" "+Blend+" "+BlendName(Blend)+" "+Chr$(243),1 if MouseHit() and MouseIn(ScreenWidth/2,ScreenHeight*0.2,256,32,1)>0 then Blend=Blend+1 if GamePad(ButtonLeft)<0.5 and GamePad(ButtonRight)<0.5 then kdis=0 if GamePad(ButtonLeft)>0.5 and kdis==0 then kdis=1:Blend=Blend-1 if GamePad(ButtonRight)>0.5 and kdis==0 then kdis=1:Blend=Blend+1 if Blend<0 then Blend=11 if Blend>11 then Blend=0 ScrollX=ScrollX+1 ParticleOffset(ScrollX,ScrollY) for t=0 to 7 tu=t+1 x=t mod 4;y=Floor(t/4) x=(x/4)+0.125 y=(y/3)+0.33 dx=ScreenWidth()*x;dy=ScreenHeight()*y SetSize(1) If MouseIn(dx,dy,32,32,1) and MouseDown()>0 Text(dx,dy,tu,1) SetSize(2) p=0;spd=1;ang=180;c=Rand(0,9);b=Blend if tu==2 or tu==3 or tu==6 then p=1 if tu==4 or tu==5 then p=2 if tu==7 then p=3 if tu==8 then p=5 if tu==5 or tu==7 then spd=0.25 if tu==2 or tu==3 then ang=45:spd=1.5 if tu==7 then ang=45 if tu==8 then spd=Rnd(0.5,1.5);p=5;c=0; ThrowParticle(MouseX(),MouseY(),tu,Rnd(0-ang,ang),spd,p,c,b) Endif DrawImg(dx,dy,1,t) Next Flip Forever

Blend Example

// Blending Modes // by Jayenkai // Created 2021/5/30 Symbol 0,"0__aaMMccOOaaMMccOO11FF33HH11FF33HHggSSeeQQggSSeeQQ77LL55JJ77LL55JJ"; Symbol 1,"0__;.v.;.v.;.v.;.v@;.v.;.v.;.v.;."; Blend=0 Graphics 512,512,1 AntiAlias Off Repeat Cls ResetDraw() // Blend Toggle If MouseHit() then Blend=Blend+1 If Blend>11 then Blend=0 Gosub Background dx=MouseX();dy=MouseY(); a=(dy-140)/200; SetCol(0,128,255); SetAlpha(a); SetBlend(Blend); SetSize(4); DrawImg(dx-128,dy,1);DrawImg(dx,dy,0);DrawImg(dx+128,dy,1) Flip Forever // Background @Background g=ScreenWidth()/8 n=0 sx=Sin(Mills()*0.05)*g sy=0-Cos(Mills()*0.03)*g // Grid for x=0-g to ScreenWidth()+g step g for y=0-g to ScreenHeight()+g step g n=(n+1) mod 2 if n==0 then SetCol 255,255,255 if n==1 then SetCol 0,0,0 Rect x+sx,y+sy,g+1,g+1 next next // Blue Box SetAlpha 0.9 SetCol(0,128,255); Rect(256,256,420,420,1) // Orange Box SetCol(255,128,0); Rect(256,256,256,256,1) SetAlpha 1 // Text at the Top SetFontSize(16) SetCol(0,0,0); Text ScreenWidth/2+2,18,"Blend Mode : "+BlendName(Blend),1 SetCol(150,128,90); Text ScreenWidth/2,16,"Blend Mode : "+BlendName(Blend),1 Return

Views 46, Upvotes 0
Jse , Particles
New games every week!
Site credits : Jayenkai, one crazy fool who has far too much time on his hands.
(c) Jayenkai 2017 and onwards, site design Rychan. RSS feed
Blog - JSE - Particles - AGameAWeek