Lua
Cada objeto pode ter um script Lua. O motor chama a função atualizar() (ou update()) em passo fixo, 60 vezes por segundo, na mesma velocidade em qualquer tela. Escreva o comportamento dentro dela.
Each object can have a Lua script. The engine calls the atualizar() (or update()) function at a fixed step, 60 times per second, at the same speed on any screen. Write the behavior inside it.
function atualizar()
-- roda 60x por segundo
end
Os dois idiomas valem ao mesmo tempo: toda função tem um nome em português e outro em inglês (
mover/move, tecla/key, tocar_som/play_sound…), e o motor aceita function atualizar() ou function update(). Escolher English no editor só troca os nomes exibidos.Both languages work at the same time: every function has a Portuguese and an English name (
mover/move, tecla/key, tocar_som/play_sound…), and the engine accepts function atualizar() or function update(). Picking English in the editor only changes the displayed names.O interpretador é Lua 5.4 (via Fengari). As bibliotecas
math, string, table, os e print estão disponíveis. Não há acesso a rede nem ao sistema de arquivos.The interpreter is Lua 5.4 (via Fengari). Libraries
math, string, table, os and print are available. There is no network or file system access.Movimento e posição
Movement and position
| Função | Function | Descrição | Description |
|---|---|---|---|
mover(dx, dy) | Soma dx/dy à posição. | Adds dx/dy to the position. | |
definir_posicao(x, y) | Coloca o objeto na posição. | Places the object at the position. | |
pos_x() / pos_y() | Leem a posição atual. | Read the current position. | |
largura() / altura() | Leem o tamanho. | Read the size. | |
definir_largura(w) / definir_altura(h) | Mudam o tamanho. | Change the size. |
Entrada
Input
| Função | Function | Descrição | Description |
|---|---|---|---|
tecla("direita") | Verdadeiro enquanto a tecla está pressionada. Teclas: esquerda, direita, cima, baixo. | True while the key is held. Keys: esquerda, direita, cima, baixo. |
Física e colisão
Physics and collision
| Função | Function | Descrição | Description |
|---|---|---|---|
pular(f) | Dá um impulso para cima se estiver no chão. | Jumps up if on the ground. | |
velocidade_y(v) | Define a velocidade vertical. | Sets the vertical velocity. | |
vel_y() | Lê a velocidade vertical. | Reads the vertical velocity. | |
colidindo("nome") | Verdadeiro se toca o objeto com aquele nome. | True if touching the object with that name. | |
colidindo_tilemap() | Verdadeiro se toca o chão/tilemap. | True if touching the ground/tilemap. |
Objetos sem Static sofrem gravidade. Objetos com Sólido e células de tilemap viram chão sólido.
Objects without Static fall under gravity. Objects with Solid and tilemap cells become solid ground.
Moeda que flutua e some: no objeto da moeda, marque Static e desmarque Sólido; no script, use
if colidindo("heroi") then remover() end.A coin that floats and vanishes: on the coin object, check Static and uncheck Solid; in the script use
if colidindo("hero") then remover() end.Imagem, cor e animação
Image, color and animation
| Função | Function | Descrição | Description |
|---|---|---|---|
definir_imagem("a.png") | Troca a imagem do objeto. | Changes the object's image. | |
definir_cor("#ffffff") | Cor mostrada quando não há imagem. | Color shown when there is no image. | |
espelhar(true) | Vira a imagem na horizontal. | Mirrors the image horizontally. | |
tocar("correr") | Toca uma animação criada no projeto. | Plays an animation created in the project. | |
parar() | Para a animação atual. | Stops the current animation. | |
remover() | Faz o objeto sumir durante o jogo (ex.: moeda recolhida). | Makes the object vanish during the game (e.g. a collected coin). |
Variáveis e texto
Variables and text
| Função | Function | Descrição | Description |
|---|---|---|---|
var("pontos") | Lê o valor de uma variável (0 se não existir). | Reads a variable's value (0 if missing). | |
definir_var("pontos", 0) | Define o valor de uma variável. | Sets a variable's value. | |
mostrar_texto("Pontos: {pontos}") | Escreve na tela; {nome} insere a variável. | Draws text; {name} inserts the variable. |
Áudio
Audio
| Função | Function | Descrição | Description |
|---|---|---|---|
tocar_som("moeda.wav") | Toca um efeito. Volume opcional de 0 a 1: tocar_som("tiro.wav", 0.5). | Plays an effect. Optional volume 0–1: tocar_som("shot.wav", 0.5). | |
tocar_musica("tema.ogg") | Toca música em loop. | Plays looping music. | |
parar_som() / parar_musica() | Param os efeitos / a música. | Stop effects / music. |
Câmera e mundo
Camera and world
| Função | Function | Descrição | Description |
|---|---|---|---|
seguir("heroi") | A câmera passa a acompanhar esse objeto. | The camera starts following that object. | |
camera(x, y) | Move a câmera para um ponto do mundo. | Moves the camera to a world point. | |
camera_x() / camera_y() | Leem a posição da câmera. | Read the camera position. | |
mundo_largura() / mundo_altura() | Leem o tamanho do mundo. | Read the world size. |
Progresso
Progress
| Função | Function | Descrição | Description |
|---|---|---|---|
salvar_jogo() | Grava variáveis e posições em save.json (na pasta do projeto). | Writes variables and positions to save.json (in the project folder). | |
carregar_jogo() | Restaura o que foi salvo. | Restores what was saved. |
Exemplo completo
Full example
-- scripts/heroi.lua
local velocidade = 3
function atualizar()
if tecla("direita") then mover(velocidade, 0) espelhar(false) end
if tecla("esquerda") then mover(-velocidade, 0) espelhar(true) end
if tecla("cima") then pular(12) end
if colidindo("moeda") then
definir_var("pontos", var("pontos") + 1)
tocar_som("moeda.wav")
end
seguir("heroi")
mostrar_texto("Pontos: {pontos}")
end