tinycoffee

sumary

tico module

tico.getVersion()

audio module

tico.audio.setVolume(volume)

Set the master volume

tico.audio.newSound(filename)

Create a new Sound

The current supported formats are: mp3, ogg, wav and flac

Sound functions:

:play()

Play the current sound

:pause()

Pause the current sound (don’t rewind)

:stop()

Stop the current sound (rewind sound)

:volume(volume)

Set and get the volume of the sound

:isPlaying()

Get if sound is playing

:isPaused()

Get if sound is paused

function tico.load()
	sound = tico.audio.newSound("sound.mp3")
end


function tico.update(dt)
	if tico.input.isDown("mouse1") then sound:play() end
end

input module

tico.input.isDown(name)

Return true if the key/mouse button with the given name is pressed

tico.input.isPressed(name)

Return true if the key/mouse button with the given name was pressed

tico.input.isUp(name)

Return true if the key/mouse button with the given name is not pressed

tico.input.isReleased(name)

Return true if the key/mouse button with the given name was released

tico.input.isKeyDown(key)

Return true if the given key is pressed

tico.input.isKeyPressed(key)

Return true if the given key was pressed

tico.input.isKeyUp(key)

Return true if the given key is not pressed

tico.input.isKeyReleased(key)

Return true if the given key was released

tico.input.isMouseDown(button)

Return true if the given mouse button is pressed

tico.input.isMousePressed(button)

Return true if the given mouse button was pressed

tico.input.isMouseUp(button)

Return true if the given mouse button is not pressed

tico.input.isReleased(button)

Return true if the given mouse button was released

tico.input.isJoyDown(jid, name)

Return true if the joystick/gamepad button is pressed, jid is the number of the joystick

tico.input.isJoyPressed(name)

Return true if the joystick/gamepad button was pressed, jid is the number of the joystick

tico.input.isJoyUp(name)

Return true if the joystick/gamepad button is not pressed, jid is the number of the joystick

tico.input.isJoyReleased(name)

Return true if the joystick/gamepad button was released, jid is the number of the joystick

math module

tico.math.lerp(init, end, t)

Return the linear interpolation between init and end for the given t

tico.math.clamp(v, min, max)

Bounds v between min and max.

if x < min returns min if x > max returns max

tico.math.round(value)

Round value

tico.math.sign(value)

Sign value if x < 0 return -1 if x > 0 return 1 if x == 0 return 0

tico.math.distance(val1, val2)

Returns the distance between val1 and val2

tico.math.angle(x0, y0, x1, y1)

Return the angle between the two points

filesystem module

tico.filesystem.read(filename)

Read content from file

tico.filesystem.write(filename, text, mode)

Write content to file, if file don’t exists, create one.

tico.filesystem.fileExists(filename)

Check if the file exists

tico.filesystem.setPath(path)

tico.filesystem.getPath()

Get the current project path

tico.filesystem.exePath()

Get the exe path

tico.filesystem.resolvePath(filename)

Resolve the filename using the current project_path

tico.filesystem.mkdir(name)

Create a directory

tico.filesystem.rmdir(name)

Remove a directory

json module

tico.json.encode(table)

Encodes a Lua table in a JSON string

tico.json.decode(str)

Decodes a JSON string to a Lua table

tico.json.load(filename)

Load a JSON file to a Lua table

tico.json.save(filename, table)

Save a Lua table to a JSON file

window module

tico.window.getTitle()

Get window title

tico.window.setTitle(title)

Set window title

tico.window.getWidth()

Get window width

tico.window.setWidth(width)

Set window width

tico.window.getHeight()

Get window height

tico.window.setHeight(height)

Set window height

tico.window.getSize()

Get window size

timer module

tico.timer.delta()

Return the current delta time

tico.timer.fps()

Return the current FPS

graphics module

tico.graphics.getSize()

Returns the current window size

local w, h = tico.graphics.getSize()

tico.graphics.clear(r, g, b, a)

tico.graphics.clear(color)

Clear the current framebuffer

If none argument is passed, clear to black

function tico.draw()
	tico.graphics.clear(255, 0, 0)
end
Color = require "tico.color"

function tico.draw()
	tico.graphics.clear(Color.Red)
end
function tico.draw()
	tico.graphics.clear({255, 0, 0})
end

tico.graphics.newCanvas(width, height)

Create a new canvas (OpenGL framebuffer)

Canvas functions:

:draw(x, y, angle, scaleX, scaleY, centerX, centerY, color)

:draw(x, y, color)

Draw the canvas

All arguments are optional

:auto()

Draw canvas and auto scale to fit window size but maintain the ratio

:getWidth()

Get the canvas texture width

:getHeight()

Get the canvas texture height

:getSize()

Get the canvas texture size

:attach()

Attach the Canvas

:detach()

Detach the Canvas, backing to the default framebuffer

function tico.load()
	canvas = tico.graphics.newCanvas(320, 240)
end

function tico.draw()
	canvas:attach()
	tico.graphics.clear()
	tico.graphics.drawRectangle(0, 0, 32, 32)
	canvas:detach()

	canvas:auto()
end

tico.graphics.newImage(filename)

Creates a new image

Image functions

:draw(x, y, angle, scaleX, scaleY, centerX, centerY, color)

Draw the image

All arguments are optional

:getWidth()

Get the image’s width

:getHeight()

Get the image’s height

:getSize()

Get the image’s size

function tico.load()
	image = tico.graphics.newImage("image.png")
end

function tico.draw()
	image:draw(32, 32)
end

tico.graphics.newRectangle(x, y, w, h)

Creates a new Rectangle

Rectangle functions

:width()

Get the rectangle width

:height()

Get the rectangle height

:x()

Get the rectangle x

:y()

Get the rectangle y

tico.graphics.drawRectangle(x, y, w, h, color)

Draw a lined rectangle

tico.graphics.fillRectangle(x, y, w, h, color)

Draw a filled rectangle

tico.graphics.drawCircle(x, y, radius, color)

Draw a lined circle

tico.graphics.fillCircle(x, y, radius, color)

Draw a filled circle

tico.graphics.drawTriangle(x0, y0, x1, y1, x2, y2, color)

Draw a lined triangle

tico.graphics.fillTriangle(x0, y0, x1, y1, x2, y2, color)

Draw a lined triangle

tico.graphics.line(x0, y0, x1, y1, color)

Draw a line

-args: - x0, x1: number - y0, y1: number - color: table ({255, 255, 255})

tico.graphics.scissor(x, y, w, h)

Set a scissor

tico.graphics.print(text, x, y, color)

tico.graphics.print(Font, text, x, y, color)

Draw text on the screen

tico.graphics.printf(text, x, y, sx, sy, color)

tico.graphics.printf(Font, text, x, y, sx, sy, color)

extended tico.graphics.print

sx and sy are the scale factor