here's my 2 cents worth of fun beginning with all static boxes and replacing them with dynamic ones based on impact while the static boxes help maintain stability until it's time to topple things; LMB to shoot:
// Project: topple1
// Created: 2020-02-25
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "topple1" )
SetWindowSize( 1080, 720, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1080, 720 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 60, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
SetVSync(1)
SetPhysicsThreading(0)
SetPhysicsScale(0.10)
for x = 1 to 6
for y = 1 to 20
this = createsprite(0) : SetSpriteSize(this,20,20)
SetSpritePosition(this,400+x*20,200+y*20)
SetSpritePhysicsOn(this,1) `static
next y
next x
global ground
ground = CreateSprite(0)
SetSpriteSize(ground,3000,20)
SetSpritePosition(ground,-1000,y*20 + 200)
SetSpritePhysicsOn(ground,1)
SetPhysicsWallLeft(0)
SetPhysicsWallRight(0)
SetPhysicsDebugOn()
ToReplace as Integer []
threshold# = 1.5
shotforce# = 500.0
shotsize# = 30.0
do
If GetPointerPressed() = 1 and lastshot# + 1 < timer()
if GetSpriteExists(shot) then DeleteSprite(shot)
shot = CreateSprite(0)
SetSpriteSize(shot,shotsize#,shotsize#)
SetSpritePositionByOffset(shot,GetPointerX(),GetPointerY())
SetSpritePhysicsOn(shot,2)
if GetPointerX() < 540 then direction = 1 else direction = -1
SetSpritePhysicsVelocity(shot,shotforce#*direction,0)
SetSpritePhysicsAngularVelocity(shot,20)
lastshot# = timer()
Endif
If GetFirstContact() > 0
repeat
Asprite = GetContactSpriteID1()
Bsprite = GetContactSpriteID2()
if ABS(GetSpritePhysicsVelocityX(BSprite)) > threshold# or ABS(GetSpritePhysicsVelocityY(BSprite)) > threshold#
if GetSpritePhysicsVelocityX(Asprite) = 0.0 then ToReplace.Insert (Asprite)
Endif
if ABS(GetSpritePhysicsVelocityX(ASprite)) > threshold# or ABS(GetSpritePhysicsVelocityY(ASprite)) > threshold#
if GetSpritePhysicsVelocityX(Bsprite) = 0.0 then ToReplace.Insert (BSprite)
Endif
SetSpriteColor(Asprite,255,0,0,255)
SetSpriteColor(Bsprite,255,0,0,255)
until GetNextContact() = 0
Endif
if ToReplace.Length > -1
for x = ToReplace.Length to 0 step -1
ReplaceSprite(ToReplace[x])
ToReplace.Remove(x)
next x
endif
Print( ScreenFPS() )
Sync()
loop
Function ReplaceSprite(sprite)
if sprite <> ground and GetSpriteExists(sprite) = 1
x# = GetSpriteXByOffset(sprite)
y# = GetSpriteYByOffset(sprite)
a# = GetSpriteAngle(sprite)
DeleteSprite(sprite)
new = CreateSprite(0)
SetSpriteSize(new,20,20)
SetSpritePositionByOffset(new,x#,y#)
SetSpriteAngle(new,a#)
SetSpritePhysicsOn(new,2)
SetSpritePhysicsFriction(new,0.3)
endif
Endfunction
play with:
threshold# = 1.5
shotforce# = 500.0
shotsize# = 30.0
&
SetSpritePhysicsFriction(new,0.3)
otherwise, i only skimmed through the above and don't know your real goal but i wouldn't mess with dampening, mass, etc, too much on the blocks. i've only played with friction and the physics scale (to get more velocity/effect for the shot) and i think the idea could provide a different base for you to tweak.
the joints could be doing the same/similar, for that matter. i haven't tried anything but this method (and i've had enough fun with the idea so probably won't be), though my first inclination was to break a single box into smaller quads/tris using chain shapes which shouldn't be too terrible since you can keep track of the verts easy enough (i see similar notion mentioned above re: slice-wise).
meanwhile, the code can optimized. ie, u could keep track of which static boxes were already replaced with dynamic ones (and see if checking is more efficient than just replacing them, over and over), etc.
bonus fun: try to flip boxes
into gaps to
reinforce the structure vs bringing it down. was a good 2 minutes of additional entertainment
extra bonus fun: start shots from
within the structure
OUCH:
i just read the initial post...
Quote: "At the moment what I'm doing is dividing a sprite into small parts in static mode and when an object comes into contact, that static part changes to dynamic mode"
i was watching this thread on my TV's browser and was really just looking at the GIFs. sorry for re-inventing your wheel (and probably not helping much)