New games every week!
JSE - New Collisions
4th June 2022  
Though I do still need to tweak a couple of elements, the new Collision methodology in JSE is now available to use.

-=-=-

// Crates // by Jayenkai // Created 2022/6/4 Symbol 0,"14_P_P_P_P?D_D/QQRRQQRRJRQRRJQ.RRQQRRJRQRRJQ.RRQQRRJRQRRJQ.RRQQRRJRQRRJQ.RRQQRRJRQRRJQ.RRQQRRJRQRRJQ.RRQQRRJRQRRJQ.RRQQRRJRQRRJQ.RRQQRRJRQRRJQ.RRQQRRJRQRRJQQD_D/P_P_P_P?"; Symbol 1,"14_0_0_0_0_0_0_0_0/RR0_0?RR0_0?RR0_0?RR0_0!RR0_0?RR0_0!RR0_0?R,0_0?RR"; #CONST $Boxes=25 Dim Box($Boxes,10) Graphics 512,512,2 Repeat CLS Collide_Pointer=Plot(MouseX(),MouseY()) h=MouseHit() for b=0 to $Boxes if Box(b,0)==0 and Rnd(0,100)<10 Box(b,1)=Rand(32,ScreenWidth()-32) Box(b,2)=0-Rand(64,128) Box(b,5)=Rand(0,360) Box(b,0)=1 endif if Box(b,0)==1 SetSize 2,2 if (b mod 5)==1 then SetSize 1,2 if (b mod 5)==3 then SetSize 2,1 SetRot Box(b,5) SetAlpha(0) Box(b,7)=DrawImg(box(b,1)-7,Box(b,2)+2) Box(b,8)=DrawImg(box(b,1),Box(b,2)+8) Box(b,9)=DrawImg(box(b,1)+7,Box(b,2)+2) SetAlpha(1) Box(b,6)=DrawImg(box(b,1),Box(b,2)) f=2 for m=0 to $Boxes if m<>b and Box(m,0)==1 if Collide(Box(b,8),Box(m,6))==1 and Box(b,2)<Box(m,2) then if Collide(Box(b,7),Box(m,6))==0 then f=1 if Collide(Box(b,9),Box(m,6))==0 then f=3 if f==2 then f=0 endif endif next if box(b,2)>jscrh-16 then f=0 if f==1 then Box(b,2)=Box(b,2)+2:Box(b,1)=Box(b,1)-4:Box(b,5)=Box(b,5)-jRnd(3,6) if f==2 then Box(b,2)=Box(b,2)+6 if f==3 then Box(b,2)=Box(b,2)+2:Box(b,1)=Box(b,1)+4:Box(b,5)=Box(b,5)+jRnd(3,6) if box(b,1)<-32 or box(b,1)>jscrw+32 then box(b,0)=0 if Collide(Collide_Pointer,box(b,6)) and h then h=0 For q=0 to 32 ThrowParticle box(b,1),box(b,2),2,Rand(0,360),Rnd(0.5,2),1 Next Box(b,0)=0 endif endif next SetParticleSize 32 Flip Forever


Disclaimer : It's not perfect.
And the above example doesn't really show it off, due to my rubbish Physics code. Anyone deft at making better physics code would end up with a better example, but .. there we go!!

The new collision functionality is now up and running.
The important drawing functions, Line, Plot, DrawImage, Rect, Oval and Triangle, now all have a return value, which links to its current position/rotation/size/collision type.
You can then use these collision values inside the Collide(object a, object b) function to test for collisions.

Collisions aren't perfect, and obviously using too many of them will slow things down a fair bit, but I'll do what I can to neaten it up.

Current obvious issues

1. Rects don't rotate. Not sure why they don't. Did I decide that a long time ago?! Can't remember. Perhaps it was a "It's just quicker that way" thing.

2. Ovals seem to have a little bit of a "margin/padding" when colliding against certain other things. Bit of wonky maths, there, I think.

3. Shapes (When you make an oval with 6 sides it becomes a hexagon) do not collide accurately, and instead behave as ovals.

4. .. And all the ovals only behave as circles, and rotation is all out the window for them!!

5. Line thickness is ignored.

6. DrawRect/DrawTriangle/DrawOval don't behave as hollow objects.

7. Symbols don't collide pixel-perfectly, so if all you have is a little dot in an image, the entire square will still be assumed as the collision area. I might see about chopping down obvious spaces, but I doubt I'll ever be able to get pixel-perfect collisions.

ToDo


First, I need to fix up the collisions that are there, and .. hopefully make them a little bit cleaner when colliding.

Next, I could do with adding Text/Print into the mix, though they're not going to be the easiest thing, I imagine! .. I might end up just wrapping all the text into rectangular boxes.

Views 6, Upvotes 0
Daily Blog , Jse
New games every week!
Site credits : If you can see it, Jayenkai did it.
(c) Jayenkai 2017 and onwards, site design Rychan. RSS feed
Blog - JSE - New Collisions - AGameAWeek