coding for continually falling rocks

Need help with using DizzyAGE then look here
Grandad
Hard Boiled Egg
Posts: 1276
Joined: Sat Aug 08, 2009 10:47 am
Location: Balham - gateway to the south

coding for continually falling rocks

Postby Grandad » Thu Sep 26, 2013 9:22 am

Pogie, this is the 'proper' way to code continually falling rocks. The rate of fall can be altered for each rock by either changing the 'delay' property in each rock, or the 'speed of the fall' in the actual function. It also takes into account a rock going 'past' the lower activation axis point so you don't have to worry about ensuring the axis co-ordinates are precisely divisable. You can 'set' the rocks on the map at any point in the 'cycle' as the roomupdate will move the rock down and the 'abot' co-ordinate is where the rock gets moved back up to the top position. It's also best to have the 'ledges' between the rocks as a higher layer than the rocks, so that they only show as falling from the ceiling and disappearing into the floor. Don't forget to set the 'death' property and respawn Dizzy outside the rockfall. Hope this helps. Thank Jamie for the original coding.

Code: Select all

func Rock1 (id,atop,abot) //set the 'numbers' in the room update
{
idx = ObjFind(id);
if (!IsUpdate(ObjGet(idx, O_DELAY))) return; //don't move rock on delay update

y = (ObjGet(idx, O_Y); // y co-ordinate of rock at starting point on map
y+=2; // sets speed of falling rock
ObjSet(idx, O_Y, y); // sets new position of rock
ObjPresent(idx); // only needed if rocks falling over two or more rooms

if (y>=abot) // y co-ordinate of rock at lowest point
{
ObjSet(idx, O_Y, atop); // set rock back to highest position
}
}


then set the room update for each rock

Code: Select all

func UpdateRoom_12_12() //or whatever the room positon is
{
Rock1(248,1106,1197); // the id of the rock, the top and bottom y co-ordinates you're using
}

cron