// Collision groups
//
// The red and green balls will collide with all other objects
// but not with each other
//
SetWindowSize(1024, 768, 0)
setVirtualResolution(GetWindowWidth() * .5, GetWindowHeight() * .5)
SetVSync(1)
#constant VW GetVirtualWidth()
#constant VH GetVirtualHeight()
//
// Set physics world up
setPhysicsScale(0.1)
setPhysicsGravity(0,0)
setPhysicsDebugOn()
type dir
x as float
y as float
endtype
b1 as integer
b2 as integer
for i=0 to 10
createBall(VW, VH, 0)
next
b1 = createBall(VW, VH, 20)
b2 = createBall(VW, VH, 20)
SetSpriteColor(b1, 0xff, 0, 0, 0xff)
SetSpriteColor(b2, 0, 0xff, 0, 0xff)
SetSpriteVisible(b1, 1)
SetSpriteVisible(b2, 1)
SetSpriteGroup(b1, -100, 0)
SetSpriteGroup(b2, -100, 0)
SetSpritePhysicsVelocity( b1, random(100, 200), -random(100, 200) )
SetSpritePhysicsVelocity( b2, -random(100, 200), random(100, 200) )
do
SetSpritePhysicsImpulse(b1, GetSpriteXByOffset(b1), GetSpriteYByOffset(b1), GetSpritePhysicsVelocityX(b1) * .02, GetSpritePhysicsVelocityY(b1) * .02)
SetSpritePhysicsImpulse(b2, GetSpriteXByOffset(b2), GetSpriteYByOffset(b2), GetSpritePhysicsVelocityX(b2) * .02, GetSpritePhysicsVelocityY(b2) * .02)
sync()
loop
function createBall(w as float, h as float, r as integer)
x as float
y as float
s as integer
d as float
x = random(10, w - 10)
y = random(10, h - 10)
s = createsprite(0)
if r = 0
d = random(10, 20)
else
d = r
endif
SetSpritePositionByOffset(s, x, y)
SetSpriteSize(s, d, d)
SetSpriteShape( s, 1)
setSpritePhysicsOn(s,2)
setSpriteVisible(s, 0)
SetSpritePhysicsRestitution(s, 01)
SetSpriteGroup(s, 100, 0)
endfunction s
Help make AGK better by submitting an example for this command! (All examples are subject to approval)