// Jogo de Lógica em LSL: Primitiva principal // vagnercsousa@yahoo.com.br, 20-jan-2008 SP // (1) variáveis integer iBtsPorLado = 4; // botões por lado integer iBotoes; // total de botões integer iPartes; // divisões do form // (2) variáveis vector vBtnScale; // tamanho dos botões integer i; // contador auxiliar default { state_entry() { iBotoes = iBtsPorLado * iBtsPorLado; iPartes = (2 * iBtsPorLado) + 1; // (3) ajustes iniciais do form llSetPos(llGetPos() + <0, 0, 2>); llSetScale(<0.2, 3, 3>); llSetObjectName("Jogo de Logica"); } touch_start(integer total_number) { // (4) permissões key dono = llGetOwner(); if (llDetectedKey(0) == dono) { // solicita permissão para agrupar objetos llRequestPermissions(dono, PERMISSION_CHANGE_LINKS); } else llSay(0, "Desculpe, " + llDetectedName(0) + ", este objeto pertence a " + llKey2Name(dono)); } run_time_permissions(integer perm) { // (5) permissão concedida if (perm & PERMISSION_CHANGE_LINKS) { // (6) dimensão dos botões vector scale = llGetScale(); vBtnScale = scale / (float)iPartes; vBtnScale.x = 0.25; // (7) artifício técnico vector pos = llGetPos(); // centro geométrico do objeto pos.y += (scale.y - vBtnScale.y) / 2.; // desloca para canto pos.z += (scale.z - vBtnScale.z) / 2.; // superior esquerdo for (i = 0; i < iBotoes; i++) { // (8) posição do novo botão (sentido regra mão direita) float left = pos.y - (vBtnScale.y + 2 * (i % iBtsPorLado) * vBtnScale.y); float top = pos.z - (vBtnScale.z + 2 * (i / iBtsPorLado) * vBtnScale.z); // (9) replica o botão (deve estar no inventário da root) llRezObject("Botao", , ZERO_VECTOR, ZERO_ROTATION, i); } } } object_rez(key id) { // (10) agrupa botão llCreateLink(id, TRUE); if (--i == 0) // passa tamanho dos botões por mensagem { llMessageLinked(LINK_ALL_CHILDREN, 0, "Tamanho:" + (string)vBtnScale, ""); state Jogando; // muda para outro estado } } } state Jogando { state_entry() { llSetText("Todos os botões devem ficar vermelhos", <1,1,1>, 1); } link_message(integer sender_number, integer number, string message, key id) { // (11) auxiliar para determinar fim do jogo if (message == "Botao Clicado") { llSetTimerEvent(2); // define prazo para respostas llMessageLinked(LINK_ALL_CHILDREN, 0, "Ha alguem verde?", ""); } // (12) ainda há botões verdes if (message == "Sim, estou verde") { // desliga timer llSetTimerEvent(0); } } timer() { // (13) sem resposta, não há mais botões verdes llSay(0, "Parabens, " + llKey2Name(llGetOwner()) + ". Jogo finalizado!"); // envia mensagem para botões resetarem llMessageLinked(LINK_ALL_CHILDREN, 0, "Resetar Jogo", ""); // pára timer llSetTimerEvent(0); } touch_start(integer total_number) { llMessageLinked(LINK_ALL_CHILDREN, 0, "Resetar Jogo", ""); } }