i was doing this in c++ in tier 2 but i converted to BASIC
in case someone in the future looks for this subject.
I did 2 methods with several ideas from this thread
Static Method
SetErrorMode(2)
SetWindowTitle("Test")
SetWindowSize(1280, 720, 0)
SetWindowAllowResize(1)
SetVirtualResolution(1280, 720 )
SetSyncRate(60, 0)
SetScissor(0,0,0,0)
UseNewDefaultFonts(1)
SetClearColor(0, 149, 255)
SetPhysicsGravity(0, 100)
SetPhysicsScale(0.01)
SetPhysicsDebugOn()
Height as integer = 12
Width as integer = 5
active as integer = 0
idn as integer = 1000
for y = 0 to Height-1
for x = 0 to Width-1
CreateSprite(idn, 0)
SetSpriteSize(idn, 20, 20)
SetSpritePosition(idn, 500 + (GetSpriteWidth(idn) * x), 700 - (GetSpriteHeight(idn) * y))
SetSpritePhysicsOn(idn, 1)
SetSpritePhysicsCanRotate(idn, 0)
SetSpritePhysicsFriction(idn, 1)
SetSpriteColor(idn, 220, 220, 220, 255)
SetSpriteOffset(idn, GetSpriteWidth(idn)/2, GetSpriteHeight(idn)/2)
inc idn
next x
next y
CreateSprite(2, 0)
SetSpriteSize(2, 50, 80)
SetSpritePosition(2, 50, 600)
setspritephysicsOn(2, 2)
SetSpriteGroup(2, -100)
SetSpritePhysicsCanRotate(2, 0)
do
if GetRawKeyState(68)
vx = 250
vy = GetSpritePhysicsVelocityY(2)
active = 1
endif
if GetRawKeyState(65)
vx = -250
vy = GetSpritePhysicsVelocityY(2)
active = 1
endif
if GetRawKeyPressed(87)
noAr = 1
vy = -650
vx = GetSpritePhysicsVelocityX(2)
active = 1
endif
if active = 1
SetSpritePhysicsVelocity(2, vx, vy)
active = 0
endif
for i = 1000 to 2000
if GetSpriteExists(i)
if GetPhysicsCollision(2, i)
SetSpritePhysicsDelete(i)
SetSpritePhysicsOn(i, 2)
SetSpriteShapebox(i, -(GetSpriteWidth(i)/2) + 1, -(GetSpriteHeight(i)/2) + 1, GetSpriteWidth(i)/2 - 1, GetSpriteHeight(i)/2 - 1, 0)
SetSpriteGroup(i, -100)
SetSpriteColorAlpha(i, 150)
endif
endif
next i
for i = 1000 to 2000
if GetSpriteExists(i)
if (GetSpritePhysicsVelocityY(i) = 0)
if GetSpriteYByOffset(i) + GetSpriteHeight(i) > 720 then continue
obj = GetSpriteHit(GetSpriteXByOffset(i), GetSpriteYByOffset(i) + GetSpriteHeight(i))
if obj = 0 and not obj = 2
SetSpritePhysicsDelete(i)
SetSpritePhysicsOn(i, 2)
SetSpriteShapebox(i, -(GetSpriteWidth(i)/2) + 1, -(GetSpriteHeight(i)/2) + 1, GetSpriteWidth(i)/2 - 1, GetSpriteHeight(i)/2 - 1, 0)
SetSpriteGroup(i, -100)
obj = GetSpriteHit(GetSpriteXByOffset(i) + GetSpriteWidth(i), GetSpriteYByOffset(i))
if obj > 0 and not obj = 2
SetSpritePhysicsDelete(obj)
SetSpritePhysicsOn(obj, 2)
SetSpriteShapebox(obj, -(GetSpriteWidth(obj)/2) + 1, -(GetSpriteHeight(obj)/2) + 1, GetSpriteWidth(obj)/2 - 1, GetSpriteHeight(obj)/2 - 1, 0)
SetSpriteGroup(obj, -100)
endif
obj = GetSpriteHit(GetSpriteXByOffset(i) - GetSpriteWidth(i), GetSpriteYByOffset(i))
if obj > 0 and not obj = 2
SetSpritePhysicsDelete(obj)
SetSpritePhysicsOn(obj, 2)
SetSpriteShapebox(obj, -(GetSpriteWidth(obj)/2) + 1, -(GetSpriteHeight(obj)/2) + 1, GetSpriteWidth(obj)/2 - 1, GetSpriteHeight(obj)/2 - 1, 0)
SetSpriteGroup(obj, -100)
endif
endif
endif
endif
next i
Print( ScreenFPS() )
Sync()
loop
Dynamic method with connections
SetErrorMode(2)
SetWindowTitle("Test")
SetWindowSize(1280, 720, 0)
SetWindowAllowResize(1)
SetVirtualResolution(1280, 720 )
SetSyncRate(60, 0)
SetScissor(0,0,0,0)
UseNewDefaultFonts(1)
SetClearColor(0, 149, 255)
SetPhysicsGravity(0, 100)
SetPhysicsScale(0.01)
SetPhysicsDebugOn()
//Player
CreateSprite(2, 0)
SetSpriteSize(2, 50, 80)
SetSpritePosition(2, 50, 600)
setspritephysicsOn(2, 2)
SetSpriteGroup(2, -100)
SetSpritePhysicsCanRotate(2, 0)
//Building
Height as integer = 12
Width as integer = 5
active as integer = 0
idn as integer = 1000
for y = 0 to Height-1
for x = 0 to Width-1
CreateSprite(idn, 0)
SetSpriteSize(idn, 20, 20)
SetSpritePosition(idn, 500 + (GetSpriteWidth(idn) * x), 700 - (GetSpriteHeight(idn) * y))
SetSpritePhysicsOn(idn, 2)
SetSpritePhysicsCanRotate(idn, 0)
SetSpritePhysicsFriction(idn, 1)
SetSpriteColor(idn, 220, 220, 220, 255)
SetSpriteOffset(idn, GetSpriteWidth(idn)/2, GetSpriteHeight(idn)/2)
inc idn
next x
next y
//Joints
idn = 1000
for n = 0 to Height
for i = 0 to Width
if GetSpriteExists(idn + 1)
if GetSpriteY(idn + 1) = GetSpriteY(idn)
id = CreateDistanceJoint(idn, idn + 1, GetSpriteXByOffset(idn), GetSpriteYByOffset(idn), GetSpriteXByOffset(idn + 1), GetSpriteYByOffset(idn + 1), 1)
SetJointDamping(id, 0, 30)
if not GetSpriteExists(idn + Width)
inc idn
continue
endif
id2 = CreateDistanceJoint(idn, idn + Width, GetSpriteXByOffset(idn), GetSpriteYByOffset(idn), GetSpriteXByOffset(idn + Width), GetSpriteYByOffset(idn + Width), 1)
SetJointDamping(id2, 0, 30)
else
id3 = CreateDistanceJoint(idn, idn + Width, GetSpriteXByOffset(idn), GetSpriteYByOffset(idn), GetSpriteXByOffset(idn + Width), GetSpriteYByOffset(idn + Width), 1)
SetJointDamping(id3, 0, 30)
endif
inc idn
endif
next i
next n
do
//Collision
for i = 1000 to 2000
if (GetSpriteExists(i))
if (GetPhysicsCollision(2, i))
SetSpritePhysicsDelete(i)
SetSpritePhysicsOn(i, 2)
SetSpriteColorAlpha(i, Random2(150, 255))
SetSpriteGroup(i, -100)
endif
endif
next i
if GetRawKeyState(68)
vx = 250
vy = GetSpritePhysicsVelocityY(2)
active = 1
endif
if GetRawKeyState(65)
vx = -250
vy = GetSpritePhysicsVelocityY(2)
active = 1
endif
if GetRawKeyPressed(87)
noAr = 1
vy = -650
vx = GetSpritePhysicsVelocityX(2)
active = 1
endif
if active = 1
SetSpritePhysicsVelocity(2, vx, vy)
active = 0
endif
Print( ScreenFPS() )
Sync()
loop
the Virtual Nomad method is also great
https://forum.thegamecreators.com/thread/225827?page=1#msg2653100