Page 6 – Adding Some Environment

Step Thirteen: Adding Some Environment

So the next step I have taken is to add fences and trees to my levels in the same way I have been adding other things, by putting them in their own .sio2 files and then loading and duplicating them if necessary for the level. It is important to note however that due to the game mechanic (you can only control the ball if it is touching the ground), if you end up on top of a fence, you wont be able to control your ball up there. I tried using a for statement like in the loading process but in the collision callback instead, but haven’t succeeded in getting it to work. Not that it matters for the fence. When I add rocks in (like those in AdventureBall already) they will be part of the level’s .sio2 file, and not in their own. It will add about 200kb to each level (before compressing). Even so the levels will probably still be less than 500kb each, compared to the 3 – 4 MB a piece that are currently in AdventureBall. That is the whole point of the separate .sio2 files, and all the empty mesh locations, saving tons of space. What really does it is the images used for textures. On top of reducing them from 5122 to 2562 pixels (from about 700kb to 200kb) I will now only have three of them repeated in every level instead of all of them.

Step Thirteen Files

gameLoading


/////FENCE LOADING
obj_loc = NULL;
obj_loc = ( SIO2object * ) sio2ResourceGet(sio2->_SIO2resource, SIO2_OBJECT, "object/postLoc_0" );
if( obj_loc )
{
unsigned int num_posts = Lua->_SIO2transform->rot->y;
unsigned int num_planks = Lua->_SIO2transform->rot->z;
i = 0;
sio2ResourceOpen( sio2->_SIO2resource, "fence.sio2", 1 );
while ( i != sio2->_SIO2resource->gi.number_entry )
{ sio2ResourceExtract( sio2->_SIO2resource, NULL );
++i; }
sio2ResourceClose( sio2->_SIO2resource );
/////POST DUPLICATION
for( int i = 0; i _SIO2resource, SIO2_OBJECT, "object/fencePost" );
char name[ SIO2_MAX_CHAR ];
sprintf( name, "%s_%i", obj->name, i );
char name2[ SIO2_MAX_CHAR ];
sprintf( name2, "object/postLoc_%i", i );
obj_loc = ( SIO2object * ) sio2ResourceGet( sio2->_SIO2resource, SIO2_OBJECT, name2 );
obj->_SIO2transform->loc->x = obj_loc->_SIO2transform->loc->x;
obj->_SIO2transform->loc->y = obj_loc->_SIO2transform->loc->y;
obj->_SIO2transform->loc->z = obj_loc->_SIO2transform->loc->z;
obj->_SIO2transform->rot->x = obj_loc->_SIO2transform->rot->x;
obj->_SIO2transform->rot->y = obj_loc->_SIO2transform->rot->y;
obj->_SIO2transform->rot->z = obj_loc->_SIO2transform->rot->z;
obj_duplicate = sio2ObjectSoftCopy( obj, name );
sio2TransformCopy( obj_duplicate->_SIO2transform, obj->_SIO2transform );
sio2TransformBindMatrix( obj_duplicate->_SIO2transform );
}
sio2EnableState( &obj->flags, SIO2_OBJECT_INVISIBLE );
/////PLANK DUPLICATION
for( int i = 0; i _SIO2resource, SIO2_OBJECT, "object/fencePlank" );
char name[ SIO2_MAX_CHAR ];
sprintf( name, "%s_%i", obj->name, i );
char name2[ SIO2_MAX_CHAR ];
sprintf( name2, "object/plankLoc_%i", i );
obj_loc = ( SIO2object * ) sio2ResourceGet( sio2->_SIO2resource, SIO2_OBJECT, name2 );
obj->_SIO2transform->loc->x = obj_loc->_SIO2transform->loc->x;
obj->_SIO2transform->loc->y = obj_loc->_SIO2transform->loc->y;
obj->_SIO2transform->loc->z = obj_loc->_SIO2transform->loc->z;
obj->_SIO2transform->rot->x = obj_loc->_SIO2transform->rot->x;
obj->_SIO2transform->rot->y = obj_loc->_SIO2transform->rot->y;
obj->_SIO2transform->rot->z = obj_loc->_SIO2transform->rot->z;
obj_duplicate = sio2ObjectSoftCopy( obj, name );
sio2TransformCopy( obj_duplicate->_SIO2transform, obj->_SIO2transform );
sio2TransformBindMatrix( obj_duplicate->_SIO2transform );
}
sio2EnableState( &obj->flags, SIO2_OBJECT_INVISIBLE );
}

/////TREE LOADING / DUPLICATION
obj_loc = NULL;
obj_loc = ( SIO2object * ) sio2ResourceGet(sio2->_SIO2resource, SIO2_OBJECT, "object/treeLoc_0" );
if( obj_loc )
{
unsigned int num_trees = Lua->_SIO2transform->loc->x;
i = 0;
sio2ResourceOpen( sio2->_SIO2resource, "tree.sio2", 1 );
while ( i != sio2->_SIO2resource->gi.number_entry )
{ sio2ResourceExtract( sio2->_SIO2resource, NULL );
++i; }
sio2ResourceClose( sio2->_SIO2resource );
/////TREE TRUNK
for( int i = 0; i _SIO2resource, SIO2_OBJECT, "object/treeTrunk" );
char name[ SIO2_MAX_CHAR ];
sprintf( name, "%s_%i", obj->name, i );
char name2[ SIO2_MAX_CHAR ];
sprintf( name2, "object/treeLoc_%i", i );
obj_loc = ( SIO2object * ) sio2ResourceGet( sio2->_SIO2resource, SIO2_OBJECT, name2 );
obj->_SIO2transform->loc->x = obj_loc->_SIO2transform->loc->x;
obj->_SIO2transform->loc->y = obj_loc->_SIO2transform->loc->y;
obj->_SIO2transform->loc->z = obj_loc->_SIO2transform->loc->z;
obj->_SIO2transform->rot->x = obj_loc->_SIO2transform->rot->x;
obj->_SIO2transform->rot->y = obj_loc->_SIO2transform->rot->y;
obj->_SIO2transform->rot->z = obj_loc->_SIO2transform->rot->z;
obj_duplicate = sio2ObjectSoftCopy( obj, name );
sio2TransformCopy( obj_duplicate->_SIO2transform, obj->_SIO2transform );
sio2TransformBindMatrix( obj_duplicate->_SIO2transform );

}
sio2EnableState( &obj->flags, SIO2_OBJECT_INVISIBLE );
/////TREE LEAVES
for( int i = 0; i _SIO2resource, SIO2_OBJECT, "object/treeLeaves" );
char name[ SIO2_MAX_CHAR ];
sprintf( name, "%s_%i", obj->name, i );
char name2[ SIO2_MAX_CHAR ];
sprintf( name2, "object/treeLoc_%i", i );
obj_loc = ( SIO2object * ) sio2ResourceGet( sio2->_SIO2resource, SIO2_OBJECT, name2 );
obj->_SIO2transform->loc->x = obj_loc->_SIO2transform->loc->x;
obj->_SIO2transform->loc->y = obj_loc->_SIO2transform->loc->y;
obj->_SIO2transform->loc->z = obj_loc->_SIO2transform->loc->z + 3.067f;
obj->_SIO2transform->rot->x = obj_loc->_SIO2transform->rot->x;
obj->_SIO2transform->rot->y = obj_loc->_SIO2transform->rot->y;
obj->_SIO2transform->rot->z = obj_loc->_SIO2transform->rot->z;
obj_duplicate = sio2ObjectSoftCopy( obj, name );
sio2TransformCopy( obj_duplicate->_SIO2transform, obj->_SIO2transform );
sio2TransformBindMatrix( obj_duplicate->_SIO2transform );
}
sio2EnableState( &obj->flags, SIO2_OBJECT_INVISIBLE );
}

This is really simple, pretty much the same as the other load and copy portions. Where the rotation didn’t matter with the gems as they are symmetrical, always have the same side up, and spin, the trees and fences need the rotation copied as well. To do this in Blender I just duplicated and placed all my fence and tree parts and put them where I wanted them. Then you move the cursor to the location of each one in turn (Shift – S, Cursor -> Selection) and add an empty mesh (spacebar, Add, Mesh, Empty Mesh), naming it treeLoc_0 (must start at 0 not 1) or whatever naming convention you choose. Then you copy rotation data from the object to the empty mesh in the Transform Properties box (N). You do this for all your objects, then update the total number of that object in the Lua script.

Lua


Level = {};
Level.Lua = SIO2.sio2ResourceGetObject( SIO2.sio2._SIO2resource, "object/Lua" );
Level.Cube = SIO2.sio2ResourceGetObject( SIO2.sio2._SIO2resource, "object/Cube" );

function Level.data()
--NUMBER OF GEMS
Level.Lua._SIO2transform.rot.x = 9;
--NUMBER OF FENCE POSTS AND PLANKS
Level.Lua._SIO2transform.rot.y = 19;
Level.Lua._SIO2transform.rot.z = 19;
--NUMBER OF TREES
Level.Lua._SIO2transform.loc.x = 1;
end

function Level.ready()
SIO2.sio2IpoPlay( Level.Goal._SIO2ipo );
end

function Level.button()
SIO2.sio2IpoPlay(Level.Cube._SIO2ipo);
end

Background

I have also added a background which at the moment I think is just a stand in. It is just a plane about 50 units below the level with a water texture on it. I added a separate .sio2 file for it as it will be used in every level (for now), and added separate loading code for it. I am not sure how I will make the backgrounds look in the end. I am considering making an animated texture that looks similar to how it currently does, or making much more complex backgrounds that will add more theme to the levels (more like Super Monkey Ball). I think I will also have to change my fall off mechanic as well. Currently if your vertical velocity gets higher than a certain point you die. If I make some levels I am thinking of making though that will start to get in the way. What I am thinking is making a catch basin of sorts. It will be different in every level, but be invisible so it wont need a texture and wont eat up much memory. If you collide with it (by falling off the edge) you die. Soon…

gameLoading


/////BACKGROUND LOADING
i = 0;
sio2ResourceOpen( sio2->_SIO2resource, "background.sio2", 1 );
while( i != sio2->_SIO2resource->gi.number_entry )
{ sio2ResourceExtract( sio2->_SIO2resource, NULL );
++i; }
sio2ResourceClose( sio2->_SIO2resource );

I think that is all for now. I will be adding more environment shortly.
~KeithK

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s