This is a blog about Rebol, it's a fantastic free programming language, it permits easily to create complete software with few lines of code. It's cross-platform, so if you write it on Windows, it will work on Linux and Mac, and vice-versa. You can produce also wonderful GUI with just 3 lines of code!
Wednesday, 27 November 2013
Nick Antonaccio made the following snake game:
Here is the source code:
Title: "Snake Game"
Author: Nick Antonaccio
A little graphic game.
Taken from the tutorial at http://musiclessonz.com/rebol.html
] snake:to-imagelayout/tight [button red 10x10] food:to-imagelayout/tight [button green 10x10] the-score:0direction:0x10newsection: false random/seednow rand-pair:func [s] [ to-pairrejoin [(round/torandom s 10) "x" (round/torandom s 10)]
] b:reduce [ 'image food ((rand-pair 190) +50x50) 'image snake ((rand-pair 190) +50x50)
] viewcenter-facelayout/tightgui: [ scrn: box white 300x300 effect [draw b] rate 15 feel [ engage:func [f a e] [ if a ='key [ if e/key ='up [direction:0x-10] if e/key ='down [direction:0x10] if e/key ='left [direction:-10x0] if e/key ='right [direction:10x0]
] if a ='time [ ifany [b/6/1 <0 b/6/2 <0 b/6/1 >290 b/6/2 >290] [alert"You hit the wall!"quit ] iffind (at b 7) b/6 [alert"You hit yourself!"quit] ifwithin? b/6 b/3 10x10 [ append b reduce ['image snake (last b)] newsection: true b/3: (rand-pair 290)
] newb:copy/parthead b 5append newb (b/6 + direction) for item 7 (length?head b) 1 [ either (type? (pick b item) =pair!) [ append newb pick b (item -3)
] [append newb pick b item ]
] if newsection = true [ clear (backtail newb) append newb (last b) newsection: false
] b:copy newb show scrn the-score: the-score +1 score/text:to-string the-score
origin across h2 "Score:" score: h2 bold "000000" do [focus scrn]