Script Library: 1238 scripts
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Archive version of: snake-gui.r ... version: 1 ... notchent 8-Jan-2017

Amendment note: new script || Publicly available? Yes

REBOL [
    title: "Snake (tiny GUI version)"
    date: 6-Jan-2016
    file: %snake-gui.r
    author:  Nick Antonaccio
    purpose: {
        The draw dialect is not used in this example, only VID GUI,
        so it's short and full featured for a tiny example.  A video
        explaining the code is at https://youtu.be/rnKvmwe2F6w
        Taken from http://re-bol.com/short_rebol_examples.r
    } 
]

]  ; see also http://re-bol.com/snake.r
random/seed now  f: random 400  p: .3  d: 20  s:[1]  g:[
  across key #"w"[d: -20]key #"s"[d: 20]key #"a"[d: -1]key #"d"[d: 1]origin
] repeat i 400 [
  append g reduce [to-set-word join "p"i 'box 'snow 20x20]
  if i // 20 = 0 [append g 'return]
] e: does [alert "Oops" q]  w: view/new layout g  forever [
  if any [all[d = -1 s/1 // 20 = 1] all[d = 1 s/1 // 20 = 0]] [e]
  if find s h: s/1 + d[e]insert head s h do rejoin["p"last s"/color: snow"]
  either f = s/1 [f: random 400  p: p - .01][remove at s length? s]
  repeat i length? s[if error? try[do rejoin["p"s/:i"/color: red"]][e]]
  do rejoin ["p"f"/color: blue"]  show w  if not viewed? w [q]  wait p
]; KEY:  f food  p speed  d direction  s snake-block  g gui  e end  i count