AGK2 Limbs by Jack30th Oct 2016 2:12
|
---|
Summary This lib can add several objects to another one and keep track of the added limbs. Description Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com rem Project: Simulated Limbs - Alex Schmidt - online-arts.de rem Created: 2016-05-06 // This functions can simulate limbs in AGK. Every limb will be registered and can be // found and then manipulated with the standard object commands. // set window properties SetWindowTitle( "Simulated Limbs - Alex Schmidt - online-arts.de" ) SetWindowSize( 1024, 768, 0 ) // set display properties SetVirtualResolution( 1024, 768 ) SetOrientationAllowed( 1, 1, 1, 1 ) // create demo media: // create the main object, the root for the other limbs main = CreateObjectBox(1,1,1) setobjectposition(main,-5,0,0) // create a 2nd main object main2 = CreateObjectBox(1,1,1) setobjectposition(main2,5,0,0) // add 20 planes to the object main for i=0 to 19 limb = CreateObjectPlane(1,1) addLimb(limb,main) // rotate, position limb object randomly SetObjectPosition(limb,random(0,4)-2,random(0,4),random(0,4)-2) SetObjectRotation(limb,random(-180,180),random(-180,180),random(-180,180)) next i // add 10 planes to the object main2 for i=0 to 9 limb = CreateObjectPlane(1,1) addLimb(limb,main2) // rotate, position limb object randomly SetObjectPosition(limb,random(0,4)-2,random(0,4),random(0,4)-2) SetObjectRotation(limb,random(-180,180),random(-180,180),random(-180,180)) next i do print("Limbs Simuation in AGK") print("======================") print("") print("") print("") print("") print("") print("") print("") print("") print("") print("") print("") print("") print("") print("") print("") print("Object main limb count: "+ str(getObjectLimbCount(main))) print("Object main2 limb count: "+ str(getObjectLimbCount(main2))) print("Object(s) with limbs: "+str(ObjectLimb.length)) // point all limbs of main to the camera for i=1 to getObjectLimbCount(main) limb=getObjectLimb(main,i) SetObjectLookAt( limb,getcamerax(1),getcameray(1),getcameraz(1),1 ) next i // rotate main objects SetObjectRotation(main,0,sin(timer())*3600,0) SetObjectRotation(main2,0,sin(timer())*3600,0) Print( ScreenFPS() ) Sync() loop // LIMB Functions by Jack // ====================== // yet small and simple but powerful (if you need it), use this functions to add objects to objects. // Each attached object is saved as a virtual limb, it still remains an object but is saved inside // the list attached to the main object. // you can get the total limb list, and find the Object for each defined limb // ================================================================== // adds a limb to the object and saves that information for later use function addLimb(limb,main) list as integer if ObjectLimb.length=-1 // if no array to count the limb objects exists, add a new one dim ObjectLimb[0,0] as integer endif // first, search if the main object is already in the limb object list (already limbs added) for i=0 to ObjectLimb.length if ObjectLimb[i,0] = main // if so, then the list is the list number of the limb object list = i exit endif next i FixObjectToObject(limb,main) if list = 0 // if there is nothing found, increase the array count ObjectLimb.length=ObjectLimb.length+1 ObjectLimb[ObjectLimb.length].length=ObjectLimb[ObjectLimb.length].length+1 ObjectLimb[ObjectLimb.length,0] = main // define main object in array count [x,0] ObjectLimb[ObjectLimb.length].length=ObjectLimb[ObjectLimb.length].length+1 ObjectLimb[ObjectLimb.length,ObjectLimb[ObjectLimb.length].length] = limb else // if something was found, just add the limb to the limb list ObjectLimb[list].length=ObjectLimb[list].length+1 ObjectLimb[list,ObjectLimb[list].length] = limb endif endfunction // gets the total limb count of the object function getObjectLimbCount(main) limbcount as integer // first, search if the main object is already in the limb object list (already limbs added) for i=0 to ObjectLimb.length if ObjectLimb[i,0] = main // if so, then the list is the list number of the limb object limbcount = ObjectLimb[i].length exit endif next i endfunction limbcount // returns the limb object for the given limb number inside the given main object function getObjectLimb(main,limbnum) limb as integer // first, search if the main object is already in the limb object list (already limbs added) for i=0 to ObjectLimb.length if ObjectLimb[i,0] = main limb = ObjectLimb[i,limbnum] exit endif next i endfunction limb // ================================================================== |