
Programación |
|
| Votar por el foro |  | | Web amiga |  | | | Parte11-Fragmentos de código Lua (Snippet) | Dom Jul 27, 2008 1:56 pm por Anonymous | SI PULSAS DERECHA O IZQUIERDA (No creo que puedas pulsar los dos a la vez)
| Código: | if pad:right() or pad:analogX() > SA then
mensaje_enviado = mensaje_enviado .. "R"
mueve_sprite_derecha( 1 )
elseif pad:left() or pad:analogX() < -SA then
mensaje_enviado = mensaje_enviado .. "L"
mueve_sprite_izquierda( 1 )
else
mensaje_enviado = mensaje_enviado .. "F"
-- no hay movimiento --
end |
SI PULSAS CRUZ
| Código: | if pad:cross() and oldpad:cross() ~= pad:cross() then
mensaje_enviado = mensaje_enviado .. "C"
accion_sprite( 1 )
else
mensaje_enviado = mensaje_enviado .. "F"
-- no hay botón pulsado --
end |
Si te han matado pero durante algún tiempo sigue la partida
| Código: | mensaje_enviado = string.char(mensaje) .. "FFF" |
Trasmitimos el mensaje a prueba de fallos de transmisión
| Código: | fin_espera = false
repeat
Adhoc.send(mensaje_enviado)
System.sleep(10)
for espera = 1, 5 do
mensaje_recibido = Adhoc.recv()
if string.sub( mensaje_recibido, 1, 1) == string.char(mensaje) then
fin_espera = true
break
end
if mensaje_recibido == ultimo_mensaje_recibido then
Adhoc.send(ultimo_mensaje_enviado)
System.sleep(10)
end
System.sleep(10)
end
until fin_espera
ultimo_mensaje_recibido = mensaje_recibido
ultimo_mensaje_enviado = mensaje_enviado
mensaje = mensaje + 1
if mensaje > 122 then mensaje = 65 end |
| Código: | oldpad = pad -- (También se me ha olvidado)
if jugador[2].accion then -- Jugador contrario u remoto. -- |
SI EL CONTRARIO PULSA ARRIBA O ABAJO
| Código: | caracter = string.sub( mensaje_recibido, 2, 2 )
if caracter == "U" then
mueve_sprite_arriba( 2 )
elseif caracter == "D" then
mueve_sprite_abajo( 2 )
else
-- no hay movimiento --
end |
SI EL CONTRARIO PULSA DERECHA O IZQUIERDA
| Código: | caracter = string.sub( mensaje_recibido, 3, 3 )
if caracter == "R" then
mueve_sprite_derecha( 2 )
elseif caracter == "L" then
mueve_sprite_izquierda( 2 )
else
-- no hay movimiento --
end |
SI EL CONTRARIO PULSA CRUZ
| Código: | caracter = string.sub( mensaje_recibido, 4, 4 )
if caracter == "C" then
accion_sprite( 2 )
else
-- no hay botón pulsado --
end |
Si has matado al jugador remoto pero durante algún tiempo sigue la partida
| Código: | end
dibujar_sprites()
mostrar_marcadores()
muestra_pantalla()
determina_fin_partida_y_ganador()
until fin_partida |
Trasmitimos el último mensaje a prueba de fallos de transmisión pero esta vez para evitar que una consola se quede pillada en un bucle cerrado, solo hacemos cinco bucles de prueba y salimos.
| Código: | fin_espera = false
for esperando = 1, 5 do
Adhoc.send(mensaje_enviado)
System.sleep(10)
for espera = 1, 5 do
mensaje_recibido = Adhoc.recv()
if string.sub( mensaje_recibido, 1, 1) == string.char(mensaje) then
fin_espera = true
break
end
if mensaje_recibido == ultimo_mensaje_recibido then
Adhoc.send(ultimo_mensaje_enviado)
System.sleep(10)
end
System.sleep(10)
end
if fin_espera then break end
end
ultimo_mensaje_recibido = mensaje_recibido
ultimo_mensaje_enviado = mensaje_enviado
mensaje = mensaje + 1
if mensaje > 122 then mensaje = 65 end |
| Código: | until fin_juego
Adhoc.term() -- Cerramos el Adhoc -----
System.sleep(500)
System.memclean() -- Limpiamos la Memoria --
System.sleep(500)
System.Quit() -- Salida al XMB --------- |
Por pipagerardo
| | Comentarios: 0 |
| | Estadísticas | Tenemos 3 miembros registrados. El último usuario registrado es nicog_777.
Nuestros miembros han publicado un total de 43 mensajes. en 42 argumentos.
| | ¿Quién está en línea ? | En total hay 1 usuario en línea: 0 Registrados, 0 Ocultos y 1 Invitado Ninguno La mayor cantidad de usuarios en línea fue 4 el Miér Sep 03, 2008 10:53 am. |
|
| |
|