Snake: Difference between revisions

21 bytes removed ,  4 months ago
m
 
(One intermediate revision by one other user not shown)
Line 2,295:
[https://easylang.dev/apps/snake.html Run it]
{{Trans|Craft Basic}}
<syntaxhighlight lang="easylang">
subr fruit
rx = (randomrandint 20 - 1) * 5 + 2.5
ry = (randomrandint 20 - 1) * 5 + 2.5
.
subr start
Line 2,305:
sx[] = [ 52.5 0 0 0 0 ]
sy[] = [ 52.5 0 0 0 0 ]
dir = randomrandint 4
timer 0
.
Line 2,318:
move 6 30
text "Space or click to to start"
#
on key
if game = 0 and keybkey = " "
Line 2,365:
move rx ry
circle 1.5
#
sx = sx[1] ; sy = sy[1]
if dir = 1
Line 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="ecmascriptwren">/* snakeSnake.wren */
 
import "random" for Random
Line 5,258:
<br>
Now embed this script in the following C program, compile and run it.
<syntaxhighlight lang="c">/* gcc snakeSnake.c -o snakeSnake -lncurses -lwren -lm */
 
#include <stdio.h>
Line 5,404:
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "snakeSnake.wren";
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
2,063

edits