Quote: "I've been contemplating this 'using one object as all the blocks' thing, and haven't been able to figure out how it could work... "
This code shows how to make one object that seems to be comprised of many separate boxes. Using this method should speed up your game, as there will only be one draw call for the scene.
No media is required. All you’ll need to do is to change the display mode settings in line 1.
set display mode 1920, 1080, 32
sync on : sync rate 0 : sync
set ambient light 100
hide light 0
autocam off
color backdrop 0, 0
hide mouse
` Make the colour textures.
ink rgb(255, 0, 0), 0
box 0, 0, 3, 3
get image 1, 0, 0, 3, 3
ink rgb(0, 255, 0), 0
box 0, 0, 3, 3
get image 2, 0, 0, 3, 3
ink rgb(0, 0, 255), 0
box 0, 0, 3, 3
get image 3, 0, 0, 3, 3
ink rgb(255, 255, 0), 0
box 0, 0, 3, 3
get image 4, 0, 0, 3, 3
` Set the print colour.
ink rgb(255, 130, 206), 0
Blocks = 1000
` Make the "base" object. When I use multi-limb objects, I usually use a base object that's only used for positioning the object. It isn't actually necessary but especially in this case makes handling
` the limbs much easier.
make object triangle 1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
` Make an object then make a mesh from the object that can be used to add the limbs.
make object cube 2, 2.0
make mesh from object 1, 2
for LimbNumber = 1 to Blocks
` Add the limb.
add limb 1, LimbNumber, 1
` Randomly choose a colour and apply it to the limb.
ColorNumber = 1 + rnd(3)
texture limb 1, LimbNumber, 0, ColorNumber
next LimbNumber
` All of the limbs have been added so delete the mesh and the object the mesh was made from.
delete mesh 1
delete object 2
` Convert the vertex format so that it only includes the required data.
` Note: If you're going to use a texture other than solid colours, you'll have to use another vertex format; 258 would work.
convert object fvf 1, 2
` See below.
gosub PositionBlocks
` Position and orient the camera.
position camera 0, 50.0, 50.0, -50.0
point camera 0, 50.0, 50.0, 50.0
` Program loop.
do
` If the space key is pressed, re-arrange the limbs.
if spacekey() and KeyIsPressed = 0
gosub PositionBlocks
KeyIsPressed = 1
endif
text 10, 10, "FPS: " + str$(screen fps())
text 10, 30, "Press SPACE to re-arrange the blocks."
sync
if scancode() = 0 then KeyIsPressed = 0
loop
end
PositionBlocks:
for LimbNumber = 1 to Blocks
` Randomly decide whether this limb will be used or not. The EXCLUDE LIMB ON/OFF command is used to include the limbs in the scene or not.
Exclusion = rnd(1)
if Exclusion
exclude limb on 1, LimbNumber
else
exclude limb off 1, LimbNumber
` If the limb is going to be used, randomly position it in the scene. The OFFSET LIMB command is used to do this. The position specified is in relation to the "base" object. Since the base
` object is at 0.0, 0.0, 0.0, the offset equals the 3D space coordinates making it easier to manage.
PositionX# = rnd(100)
PositionY# = rnd(100)
PositionZ# = rnd(100)
offset limb 1, LimbNumber, PositionX#, PositionY#, PositionZ#
endif
next LimbNumber
return
Jane -