|
From: | Marcos Oliveira |
Subject: | Re: [shell-script] Game em Shell |
Date: | Mon, 13 Jan 2014 21:37:23 -0200 |
Não está testado, mas deve andar com as teclas do vi H, J, K e L. Para sair Q. Pode ser com maiúsculas ou minúsculas.clear; tput civis # cursor invisivelLin=$(($(tput lines) / 2)) # linha do meioCol=$(($(tput cols) / 2)) # coluna do meiotput cup $Lin $Col; echo Xwhile truedoread -sn 1 Chavetput cup $Lin $((Col > 0 ? Col - 1 : 0)); echo -n " " # apagacase $Chave in[Hh]) ((Col > 0)) && let Col-- ;; # Esquerda[Ll]) ((Col < $(tput cols))) && let Col++ ;; # Direita[Jj]) ((Lin < $(tput lines))) && let Lin++ ;; # Desce[Kk]) ((Lin > 0)) && let Lin-- ;; # Sobe[Qq]) tput cnorm; echo; exitesactput ech 1tput cup $Lin $Colecho -n XdoneEm 13 de janeiro de 2014 19:30, <address@hidden> escreveu:
Galera fiz isso aqui, que é só um teste para o entendimento do movimento de um "boneco" em Shell, mas nada mais é o curso, e não um "boneco" em si. Se teclar 'd' vai pra direita; 's' pra esquerda; ... ; 'q' pra sair...n no entanto, está longe do que eu espero obter. Duas dúvidas: como manter o moviemnto contínuo a cada 'teclada' e com usar as SETAS do teclado em vez de letras. Se alguém tiver uma dica, ou um script, link... sei lá, só pra entender (e aprender) a fazer um game( bem básico) em shell, por enquanto, só de movimentar algo na tela, com o tempo, vou pesquisando e caso não encontro, verifico outras coisa. Desde já, agradeço!
#!/bin/bash
reset
tempo=2
while true ; do
read -s -n 1 -t $tempo chave
if [ "$chave" == "d" ]; then
tput cup 3 4
fi
if [ "$chave" == "s" ]; then
tput cup 3 1
fi
if [ "$chave" == "e" ]; then
tput cup 2 3
fi
if [ "$chave" == "x" ]; then
tput cup 4 3
fi
if [ "$chave" == "q" ]; then
echo
break
fi
done
[Prev in Thread] Current Thread [Next in Thread]
- Game em Shell, marcos.gnulinux, 2014/01/13
- Re: [shell-script] Game em Shell, Eduardo Júnior, 2014/01/13
- Re: [shell-script] Game em Shell, Julio C. Neves, 2014/01/13
- Re: [shell-script] Game em Shell, Marcos Oliveira <=
- Prev by Date: Re: [shell-script] Game em Shell
- Next by Date: Re: [shell-script] Condições com IF
- Previous by thread: Re: [shell-script] Game em Shell
- Next by thread: Inserindo comandos via echo
- Index(es):