LittleCoder Documentation

LittleCoder is fun. But beware, you're in serious danger of uncovering all its secret tricks.

Scene

The "Scene" object is always around, these are the things you can do with it.

Properties and Methods:

Scene.run_time
This property tells you how long LittleCoder has been running. It's a number, and it's counting seconds. A counter like this can be helpful when you're doing animations.
Scene.mouse_x and Scene.mouse_y
You can access these properties at any time to find out where the mouse is on the screen. The numbers that come back are in the same space as the Tiles in the scene. (Big shout out to my 18th century homeboy Carl Friedrich Gauß for help with the mathematics.)
#Examples of Scene properties

#Report runtime
myprint( "We've been running for #{Scene.run_time} seconds. This is fun!" )

#Report clicks
def left_mouse()
myprint( "You clicked at X: #{Scene.mouse_x} Y: #{Scene.mouse_y}" )
end

#Stick a tile to the mouse
def update()
$some_tile.x = Scene.mouse_x
$some_tile.y = Scene.mouse_y
end
the_tile = Scene.new_tile( in_file_path )

Adds a Tile (image) to the scene. You're going to want to hold on to what it returns, because it gives you back a Tile object to play with. Make sure you pass it a path to an image file. LittleCoder can load .jpg, .png, and other cool file formats.

#Examples of Scene.new_tile
the_blob = Scene.new_tile( 'demoblob.png' )

#Now the_blob is a tile, so you can call any of the tile methods on it!
the_blob.set_scale( 2, 2 ) #make the blob big!
the_blob.set_pos( -2, 0 ) #move the blob to the left. Shimmy, shimmy!
the_sound = Scene.new_sound( in_file_path )

Adds a Sound to the scene. Do store what it returns in a variable somewhere, so you can play the sound. Playing the sound is very simple. You just do the_sound.play ... whee! LittleCoder likes .ogg files.

#Examples of Scene.new_sound
the_sound = Scene.new_sound( 'beep.ogg' )
the_sound.play #BEEP!
Scene.set_camera_pos( in_x, in_y, in_z )

Even though LittleCoder looks 2d, its really 3d. You can set the cameras position in 3d space by calling this method on the scene. By default the camera is somewhere near 0, 0, -20 and looking at 0, 0, 0. By bringing the camera closer to 0, 0, 0 you can zoom in on the scene... Or maybe you want to dolly back to 0, 0, -50 to get a nice birds eye view on the scene.

Either way, the camera is always facing in the same direction, looking straight up the positive Z axis.

#Examples of Scene.set_camera_pos
Scene.set_camera_pos( 0, 0, -3 ) #Extreme closeup!!!
Scene.set_camera_pos( 0, 0, -50 ) #I can see my house from here!
Scene.set_camera_pos( 0, -20, -20) #Anyone down here?
Scene.set_posteffect_active( in_active )

LittleCoder is very simple on the surface, but Its built on some pretty heavy duty technology. There is a full shader based pipeline being used to draw everything, and this affords us some super powers. But, as we know, power comes with responsibility. This method turns on the special effects pixel shader (assuming you pass it a true value) ... The shader is stored in the file post.fx that sits next to LittleCoder.exe. Do have a look at that file, but if you're thinking about touching it, keep in mind that this file is very fragile, and can make LittleCoder blow up, so be careful!

#Examples of Scene.set_posteffect_active
Scene.set_posteffect_active( true ) #Special effects, ENGAGE! ... WOAH!
Scene.set_posteffect_active( false ) #Thats too much for me, please turn it off.... phew, thanx.

Tile

These are the things you can do with the "Tile" objects. (psst; you can get a Tile by calling Scene.new_tile)

Properties and Methods:

some_tile.x and some_tile.y
Get or set the position of the tile. Can be used to move a tile.
some_tile.r and some_tile.g and some_tile.b
Get or set the color of the tile. Can be used to make tiles pretty colors.
some_tile.active
Get or set the active state of the tile. Can be used to make tiles disappear.
some_tile.rot
Get or set rotation for the tile. Can be used to make tiles spin around.
some_tile.scale_x and some_tile.scale_y
Get or set scale for the tile. Can be used to make tiles bigger or smaller.
some_tile.blend_mode
Get or set the blend mode for the tile. Can be used to set different drawing styles for the tile. (see .set_blend_mode)
some_tile.layer
Get or set the layer of the tile. Layers can be used to control the drawing order to force some tiles to the back or front.
#Examples of Tile properties

#Move a tile a bit to the right
some_tile.x = some_tile.x + 2

#Make a tile blue. Blue is my favorite color.
some_tile.r = 0
some_tile.g = 0
some_tile.b = 1

#Spin a tile around
def update()
some_tile.rot = some_tile.rot + 3.141
end

#Is the tile active?
if( some_tile.active )
#Well, then make it big!
some_tile.scale_x = 4
some_tile.scale_y = 4
end

#Cause a tile to be drawn additively... oooh. pretty.
some_tile.blend_mode = 1

#Set this tile to the background
some_tile.layer = -50
the_tile.set_pos( in_x, in_y )

When you first make a new tile in the scene, it starts out at the center of the universe. 0 x and 0 y. If there was no way to move the tiles around, they would just stack up there in the center, and that would be boring. You can tell a tile to move by calling the_tile.set_pos on it. Just pass in an x and y value (numbers) and it will move to that location. Thank you Descartes!

#Examples of the_tile.set_pos

#Let's pretend we've got the blob tile from above.
the_blob.set_pos( 1, 6.2 ) #A little to the right, and waaay up.
the_blob.set_pos( -4, -4 ) #Down, and to the left... Down, and to the left.
the_blob.set_pos( -100, 0 ) #Woah, where did it go?
Scene.set_camera_pos( -100, 0, -10 ) #Oh, thank goodness. I found it!
the_tile.set_color( in_r, in_g, in_b, [in_a] )

You can set a tile's color in terms of red, green, and blue. You mix the colors like a modern day Rembrandt, but using realtime hardware accelerated graphics. So, its like faster. If Rembrandt saw it, he'd be all; "Dude! Thats fast!" ... I think. In any event, I think you'll get the idea from some examples.

Notice that passing the secret/optional in_a parameter allows you to set an alpha (opacity) value. This can be used to make see-through tiles. Neat!

#Examples of the_tile.set_color

#Again, we're playing with the blob.
the_blob.set_color( 1, 1, 1 ) #White blob. (This is the default)
the_blob.set_color( 0.6, 0.5, 0) #That's a kinda ugly orangeish color there.
the_blob.set_color( 0, 0, 0 ) #Black blob. Warning! may be tough to see on a black background.
the_blob.set_color( 1, 1, 1, 0.5 ) #See-through blob. (cool)
the_blob.set_color( 1, 1, 1, 0.1 ) #Nearly invisible blob.
the_tile.set_active( in_active )

You can set a Tile's active to make it disappear for a while. Does LittleCoder support spaceships with cloaking devices? Yes! Check out this example.

#Example of the_tile.set_active
spaceship_with_cloaking_device = Scene.new_tile( 'spaceship.png' )
spaceship_with_cloaking_device.set_active( false ) #Cloaking device activated!

#Then later, when its time to spring the trap
spaceship_with_cloaking_device.set_active( true ) #Ha! You didn't know I was hiding there, did you?
the_tile.set_rotation( in_rotation )

You can use this method to rotate the tile. And by rotate, we mean spin. The value you pass in is measured in degrees, so 360 is a full turn.

#Example of the_tile.set_rotation
#using update to change the rotation every frame:
$the_rotation = 0
function update
$the_rotation = $the_rotation + 1
some_sweet_tile.set_rotation( $the_rotation ) #Woah, getting dizzy here.
end
the_tile.set_scale( in_x, in_y )

Bigger tiles? Smaller tiles? Oblong tiles? Fullscreen tiles? Get 'em all here!

#Example of the_tile.set_scale
big_blob = Scene.new_tile( 'demoblob.png' )
big_blob.set_scale( 3.14, 3.14 )

tiny_blob = Scene.new_tile( 'demoblob.png' ).set_scale( 0.42, 0.42 ) #Tiny-tile-one-liner

oblong_tile.set_scale( 2, 1 ) #Stretch tiles this way. (can be used to handle non-square tiles)
the_tile.set_blend_mode( in_mode )

Each tile object has a blend mode that controls the way it is drawn each frame.
Currently there are two blend modes:

#Example of the_tile.set_blend_mode
some_normal_tile.set_blend_mode( 0 ) #Normal drawing. (This is the default)
some_hawttt_tile.set_blend_mode( 1 ) #Additive drawing... Pretty!
the_tile.set_layer( in_layer )

By default, each frame every tile you've created is drawn, and they are drawn in the order that they were created. If you want to override this default order to make certain tiles draw on top, or behind, this is the way to do it. Everyone is drawn in layer order, so lower numbers mean drawn earlier, and therefore behind.

#Example of the_tile.set_layer
#Waay back. Nobody draws behind me!
background_tile.set_layer( -100 )

#It's nice up here, I get drawn late, and on top of other things
cloudy_overlay_tile.set_layer( 20 )

Sound

These are the things you can do with a "Sound" object. You'll end up with a sound object if you accidentally catch the return value of Scene.new_sound

the_sound.play( )

Sounds are mad simple. Just call play... 

Note, as of LittleCoder-0.3 the limitation of monophony (one sound at a time) is gone. Adios, toodles, goodbye.

#Example of the_sound.play
the_sound.play #Can it be that easy?

#yup

Secret Functions

LittleCoder has a few secret functions you can define on your path to world domination. If you define these functions in your program, LittleCoder will call them, letting you know what's up.

def update
This function gets called every frame, allowing you to change the scene over time to make animations.
def keyboard( in_key, in_down_flag )
This function gets called when you mash on the keyboard. Which key they pressed will be in the in_key parameter, and the in_down_flag parameter will tell you if it was the key being pressed, or released.
def left_mouse_down
This function gets called when you presses down the left mouse button
def left_mouse_up
This function gets called when you let up on the mouse button
# Examples of secret functions

# Update
def update
$some_tile.set_pos( (10*rand)-5, (10*rand)-5 ) #DANCE!
end

# Keyboard
def keyboard( in_key, in_down_flag )
# ignore key up messages
if in_down_flag

if in_key == 'a'
$some_sound.play
elsif in_key == 'up'
$some_tile.y = $some_tile.y = + 1
elsif in_key == 'down'
$some_tile.y = $some_tile.y = - 1
elsif in_key == 'left'
$some_tile.x = $some_tile.x = - 1
elsif in_key == 'right'
$some_tile.x = $some_tile.x = + 1
else
myprint( "You pressed the #{in_key} key, we noticed." )
end
end
end

# Mouse
def left_mouse_down
# Start drag and drop procedure.
# (Left as an exercise for the reader)
end

def left_mouse_up
# Stop drag and drop procedure.
# (Also left as an exercise for the reader)
end

# ;)