Jump to content

Snake: Difference between revisions

42 bytes removed ,  1 year ago
Line 1,672:
 
=={{header|Craft 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 upkey = 0, rightkey = 0, downkey = 0, leftkey = 0, esckey = 0
define speed = 0, delay = 0, score = 0, game = 1
define maxsize = 1000, size = 9, direction = int: (rnd) * 4) + 1
define rx = ( int: (rnd) * ( gfxx - 24 ) ) + 12
define ry = ( int: (rnd) * ( gfxy - 40 ) ) + 25
 
dim sx[maxsize]
dim sy[maxsize]
 
define fn (bounds) as sx[0] <= -10 or sx[0] >= gfxx or sy[0] <= -10 or sy[0] >= gfxy
define fn (collision) as sx[0] + 15 >= rx and sx[0] <= rx + 15 and sy[0] + 15 >= ry and sy[0] <= ry + 15
define fn (eatself) as sx[0] = sx[i] and sy[0] = sy[i]
 
let sx[0] = gfxx / 2
Line 1,743 ⟶ 1,740:
 
fgcolor 0, 80, 0
oval sx[size], sy[size], 15, 15
 
let i = size + 1
Line 1,752 ⟶ 1,749:
let c = i - 1
 
if (eatself)sx[0] = sx[i] and sy[0] = sy[i] = 1 then
 
let game = 0
Line 1,794 ⟶ 1,791:
endif
 
define fn (bounds) as if sx[0] <= -10 or sx[0] >= gfxx or sy[0] <= -10 or sy[0] >= gfxy = 1 then
if (bounds) = 1 then
 
let game = 0
Line 1,800 ⟶ 1,797:
endif
 
define fn (collision) as if sx[0] + 15 >= rx and sx[0] <= rx + 15 and sy[0] + 15 >= ry and sy[0] <= ry + 15 = 1 then
if (collision) = 1 then
 
playwave "examples\tada.wav"
 
fgcolor 0, 80, 0
rect 0, 0, gfxx, gfxy
 
let rx = ( int: (rnd) * ( gfxx - 24 ) ) + 12
let ry = ( int: (rnd) * ( gfxy - 40 ) ) + 25
 
let size = size + 3
Line 1,820 ⟶ 1,819:
oval rx + 9, ry + 5, 3, 3
 
fgcolor 255, 255, 0
cursor 1, 1
print "Score: ", score
 
let delay = (clock)
 
do
Line 1,830 ⟶ 1,829:
wait
 
loop (clock) < delay + speed
 
loop esckey <> 1 and game = 1
 
playwave "examples\boom.wav"
 
alert "Game over! Score: ", score
305

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.