Adding pick-ups to iMarble

Alright, so one thing you need in any game is pick-up items, whether that be gold, health, magic, bananas, or in my case gems.  If you’ve played AdventureBall then you’ve seen the gems in that, and you can see them in pictures on my blog here.  This isn’t the exact same gem, this one is four instead of three sided, but it needs to act the same.  I was hoping to create the desired actions with LUA, and indeed did, but I had the problem of the LUA script not being copied with the sio2ObjectHardCopy or sio2ObjectSoftCopy.  I also couldn’t access the hard or soft copied objects from a LUA script.  Rom seemed to be saying on the forum that the HardCopy should copy the LUA script as well (I think, he is a man of few words), but I am a self taught programmer and don’t know what I am doing wrong.  So I didn’t use LUA.  I did it all in my gameLoading and gameRendering, and it works like a charm.

Pick-Ups Files

Creating the Gem

This is real easy.  Open Blender, select the default cube and tab into Edit Mode.  In Face Select Mode (ctrl+tab – 3 in Edit Mode) select the top face and press E to extrude it.  Press 1 to extrude it one unit.  Your object should now be half again as tall as it originally was.  In Vertices Select Mode (ctrl+tab – 1 in Edit Mode) select the top four vertices and press S, then 0 (zero) then Enter.  This will scale (S) the four vertices to zero, moving them all to the same spot, creating a point.  Now your box should look like a cube with a pyramid on top, or a simple house or something.  Do the same to the bottom four vertices, and you will have a simple gem shape.  I’m sure I adjusted the height of the top and bottom a little, but the only other thing to so is remove the double vertices.  Press A until all the vertices are yellow (selected), then press W to bring up the Specials Menu (in Edit Mode) and press Remove Doubles.  A pop up should tell you that 6 vertices have been removed.  Hopefully I haven’t forgotten anything, I’ve written this from memory.  The file is available at the top of the page.  The object really isn’t important though, it could be whatever you want to duplicate.

Xcode

I have separated the gem in it’s own .sio2 file for reasons that should hopefully become obvious as I continue my documentation of this game.  After loading the gem, I duplicate it using the code from the wiki.

Then in gemRendering I use a similar process to iterate through the copied gems rotating them, then checking to see if the player is within one unit of the current gem.  If it is this gem is moved vertically by 100 units, out of camera range.  I should probably make it invisible too using the same command from the last line of the previous code snippet, but I haven’t yet so it isn’t in the code here.  The line with all the sqrt functions is basically two a2 + b2 = c2 equations used to calculate the 3D distance between the player and the current gem.

Currently this just creates ten gems in a row, but soon it will load them from a vec3 array where I will specify the locations I want the gems to live.  For a lot of levels this could turn into a lot of manual data entry, but a clever person could easily make a python script that would let you place them all in Blender, then export only the xyz locations into a text file that is of the exact format you need.  I am too busy/lazy to go and learn enough python to do that right now so I will settle for a little manual entry.

I have also not textured the gems yet.  I was hoping to change the texture colour as I iterate through them in duplication, but the forum seems to say I can’t do this (until SIO2 1.5) without using some sort of modified HardCopy.  I tried using the code here but couldn’t get it to work due to my own inexperience coding I am sure.  I am not too worried about it though.  I hope 1.5 will be out before this version of my game is released and I don’t have to worry about modifying things.  That is all for today.

~KeithK

Advertisements

About keithkarnage

KeithK is an artist living in Halifax, Nova Scotia. He mostly works in programming and video games.
This entry was posted in iMarble. Bookmark the permalink.

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