Snake: Difference between revisions

m
 
(2 intermediate revisions by 2 users not shown)
Line 2,293:
 
=={{header|EasyLang}}==
[https://easylang.dev/apps/_snakesnake.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,314:
text "SNAKE"
textsize 5
move 106 40
text "ArrowKeys keysor mouse for controlling"
move 106 30
text "PressSpace spaceor click to to start"
#
on key
if keybkeygame = "ArrowUp"0 and dirkeybkey <>= 3" "
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
elif keybkey = " " and game = 0
start
return
.
if dir mod 2 = 1
elif if keybkey = "ArrowRight" and dir <> 4
dir = 2
elif keybkey = "ArrowLeft" and dir <> 2
dir = 4
.
else
if keybkey = "ArrowUp"
dir = 1
elif keybkey = "ArrowDown" and 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 9695
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 "PressSpace spaceor forclick new game"
.
.
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="ecmascriptwren">/* snakeSnake.wren */
 
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 snakeSnake.c -o snakeSnake -lncurses -lwren -lm */
 
#include <stdio.h>
Line 5,379 ⟶ 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);
1,973

edits