Snake: Difference between revisions
m
→{{header|EasyLang}}
(2 intermediate revisions by 2 users not shown) | |||
Line 2,293:
=={{header|EasyLang}}==
[https://easylang.dev/apps/
{{Trans|Craft Basic}}
<syntaxhighlight
subr fruit
rx = (
ry = (
.
subr start
Line 2,305:
sx[] = [ 52.5 0 0 0 0 ]
sy[] = [ 52.5 0 0 0 0 ]
dir =
timer 0
.
Line 2,314:
text "SNAKE"
textsize 5
move
text "
move
text "
#
on key
if
dir = 1▼
elif keybkey = "ArrowRight" and dir <> 4▼
dir = 2▼
elif keybkey = "ArrowDown" and dir <> 1▼
dir = 3▼
elif keybkey = "ArrowLeft" and dir <> 2▼
dir = 4▼
start
return
.
if dir mod 2 = 1
▲ dir = 2
▲ dir = 4
.
else
if keybkey = "ArrowUp"
▲ dir = 1
▲ dir = 3
.
.
.
on mouse_down
if game = 0
start
return
.
if dir mod 2 = 1
if mouse_x < sx
dir = 4
else
dir = 2
.
else
if mouse_y < sy
dir = 3
else
dir = 1
.
.
.
Line 2,335 ⟶ 2,360:
clear
color 997
move 2
text "Score: " & 10 * len sx[] - 50
color 966
move rx ry
circle 1.5
#
sx = sx[1] ; sy = sy[1]
if dir = 1
Line 2,391 ⟶ 2,416:
color 997
move 10 10
text "
.
.
Line 5,095 ⟶ 5,120:
{{libheader|Wren-dynamic}}
An embedded program so we can ask the C host to call ncurses and another library function for us.
<syntaxhighlight lang="
import "random" for Random
Line 5,233 ⟶ 5,258:
<br>
Now embed this script in the following C program, compile and run it.
<syntaxhighlight lang="c">/* gcc
#include <stdio.h>
Line 5,379 ⟶ 5,404:
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
|