LittleCoder is fun. But beware, you're in serious danger of uncovering all its secret tricks.
The "Scene" object is always around, these are the things you can do with it.
#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
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!
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!
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?
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.
These are the things you can do with the "Tile" objects. (psst; you can get a Tile by calling Scene.new_tile)
#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
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!
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.
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?
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
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)
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!
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 )
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
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
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.
# 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
# ;)