Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Despite the possibility you'll win the "worst ever mismatch between programming language and program" award for 2013, going up against contenders like an accounting package written in x86, or a COBOL-based operating system, or <em>anything</em> written in Pascal :-), you'll probably find it's just easier to code that shape directly in your bash script.</p> <p>There appears to be no pressing need to separate the shape from the code itself.</p> <hr> <p>For a starter, here's a little script that uses <code>tput</code> (curses and the terminfo database) to animate your ship along the bottom of the window.</p> <p>It's not exactly <code>World of Warcraft</code> but it should be a good starting point. First we'll set up the stuff that never changes, ship and bullet strings, and various screen coordinate stuff:</p> <pre><code>#!/bin/bash bull1=' * * ' bull2=' ' ship1=' ^ /\ ^ ' ship2=' !__/()\__! ' ship3=' /==: :==\ ' ship4=' (/\/\) ' tput clear ((line1 = $(tput lines) - 6)) ((line2 = line1 + 1)) ((line3 = line2 + 1)) ((line4 = line3 + 1)) ((maxcol = $(tput cols) - 15)) </code></pre> <p>Then we'll initialise the relevant variable and enter an infinite loop:</p> <pre><code>((bullline = 1)) ((bullcol = 1)) ((curcol = 1)) ((coldir = 1)) while true ; do </code></pre> <p>Inside the loop, we simply move the sprites by blanking the previous values and writing new ones. The bullet positions are updated in this section as well. Note that we don't need to explicitly blank the ship since it's surrounded by spaces which blanks the edge characters anyway:</p> <pre><code> tput cup $bullline $bullcol ; echo "$bull2" if [[ $bullline -le 2 ]] ; then ((bullline = line1 - 1)) ((bullcol = curcol)) else ((bullline = bullline - 2)) fi tput cup $bullline $bullcol ; echo "$bull1" tput cup $line1 $curcol ; echo "$ship1" tput cup $line2 $curcol ; echo "$ship2" tput cup $line3 $curcol ; echo "$ship3" tput cup $line4 $curcol ; echo "$ship4" </code></pre> <p>Then we simply update variables for the ship to have it move left and right, finally delaying for a little bit so the animation is smooth:</p> <pre><code> ((curcol = curcol + coldir)) if [[ $curcol -eq $maxcol ]] ; then ((coldir = -coldir)) else if [[ $curcol -eq 1 ]] ; then ((coldir = -coldir)) fi fi sleep 0.1 done </code></pre> <p>What you end up with is an animation that looks bearable, given the limitations of the platform:</p> <pre> * * ^ /\ ^ !__/()\__! /==: :==\ (/\/\) </pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload