Snake: Difference between revisions
Content deleted Content added
Basicgames (talk | contribs) |
Basicgames (talk | contribs) |
||
Line 1,672: | Line 1,672: | ||
=={{header|Craft Basic}}== |
=={{header|Craft Basic}}== |
||
<syntaxhighlight lang="basic"> |
<syntaxhighlight lang="basic">rem Snake example game for Craft Basic |
||
rem by Gemino Smothers 2022 |
|||
rem www.lucidapogee.com |
|||
define gfxx = 330, gfxy = 296 |
define gfxx = 330, gfxy = 296 |
||
define upkey = 0, rightkey = 0, downkey = 0, leftkey = 0, esckey = 0 |
define upkey = 0, rightkey = 0, downkey = 0, leftkey = 0, esckey = 0 |
||
define speed = 0, delay = 0, score = 0, game = 1 |
define speed = 0, delay = 0, score = 0, game = 1 |
||
define maxsize = 1000, size = 9, direction = int |
define maxsize = 1000, size = 9, direction = int(rnd * 4) + 1 |
||
define rx = |
define rx = int(rnd * (gfxx - 24)) + 12 |
||
define ry = |
define ry = int(rnd * (gfxy - 40)) + 25 |
||
dim sx[maxsize] |
dim sx[maxsize] |
||
dim sy[maxsize] |
dim sy[maxsize] |
||
⚫ | |||
⚫ | |||
define fn (eatself) as sx[0] = sx[i] and sy[0] = sy[i] |
|||
let sx[0] = gfxx / 2 |
let sx[0] = gfxx / 2 |
||
Line 1,743: | Line 1,740: | ||
fgcolor 0, 80, 0 |
fgcolor 0, 80, 0 |
||
oval sx[size],sy[size],15,15 |
oval sx[size], sy[size], 15, 15 |
||
let i = size + 1 |
let i = size + 1 |
||
Line 1,752: | Line 1,749: | ||
let c = i - 1 |
let c = i - 1 |
||
if |
if sx[0] = sx[i] and sy[0] = sy[i] = 1 then |
||
let game = 0 |
let game = 0 |
||
Line 1,794: | Line 1,791: | ||
endif |
endif |
||
⚫ | |||
if (bounds) = 1 then |
|||
let game = 0 |
let game = 0 |
||
Line 1,800: | Line 1,797: | ||
endif |
endif |
||
⚫ | |||
if (collision) = 1 then |
|||
playwave "examples\tada.wav" |
|||
fgcolor 0, 80, 0 |
fgcolor 0, 80, 0 |
||
rect 0, 0, gfxx, gfxy |
rect 0, 0, gfxx, gfxy |
||
let rx = |
let rx = int(rnd * (gfxx - 24)) + 12 |
||
let ry = |
let ry = int(rnd * (gfxy - 40)) + 25 |
||
let size = size + 3 |
let size = size + 3 |
||
Line 1,820: | Line 1,819: | ||
oval rx + 9, ry + 5, 3, 3 |
oval rx + 9, ry + 5, 3, 3 |
||
fgcolor 255,255,0 |
fgcolor 255, 255, 0 |
||
cursor 1,1 |
cursor 1, 1 |
||
print "Score: ", score |
print "Score: ", score |
||
let delay = |
let delay = clock |
||
do |
do |
||
Line 1,830: | Line 1,829: | ||
wait |
wait |
||
loop |
loop clock < delay + speed |
||
loop esckey <> 1 and game = 1 |
loop esckey <> 1 and game = 1 |
||
playwave "examples\boom.wav" |
|||
alert "Game over! Score: ", score |
alert "Game over! Score: ", score |