-
Notifications
You must be signed in to change notification settings - Fork 3
Eppabasic
Eppabasic is a new, simple web based basic language inspired by Coolbasic. The idea of the language is to be as simple as possible to start programming.
The official web site of the language (under construction) contains a web based IDE (also available as downloadable zip) with syntax highlighting, spell checking and documentation with sample programs for every command.
The IDE contains compiler which compiles the Eppabasic code into native JavaScript which is then ran in a separate window. The programs can be shared with other users via the web site of the language, but programs can also be downloaded as single .html files for offline usage.
The program uses html5 canvas elements for drawing, possibly with WebGl. It is yet to be desided how this is exactly to be implemented.
Drawing commands
- LINE x1, y1, x2, y2
- RECT x, y, w, h
- ELLIPSE x, y, w, h (x and y being the center of the ellipse)
- TRIANGLE x1, y1, x2, y2, x3, y3
Eppabasic supports loading audio from files and playing it back via JavaScript Audio object, with html audio element as a backup implementation.
- Simple to start programming with
- Easy to make graphics
- Works everywhere (cross-platform)
- Copied code works without any other tweeking (no compiler settings)
This is a simple code to show off a syntax proposal. It is yet to be decided whether keywords and function names should be with capitals (ie. IF, ADDTEXT) or with CamelCase(ie. If, AddText).
DIM a AS INTEGER = 10
DIM b AS INTEGER = 20
DIM c AS INTEGER = (a + b) * a
' Create one dimensional array
DIM array(10) AS INTEGER
' Set value to index 0
array(0) = 15
' Change array to contain indices from 17 to 20
REDIM array(17 TO 20)
' Multidimensional arrays
DIM array2(10, 20) AS INTEGER
array2(10, 20) = 17
' Arrays can also be sorted
SORT(array)
SORT(array2)
##If-statements
IF a > b AND b < c THEN
' Do something
ELSE IF b > c THEN
' Or now
ELSE
' Or now
END IF
FOR i = b TO a STEP -2
LINE 10, 30, TEXTWIDTH(STR(c)), 30 + i*20
NEXT i
SELECT a
CASE 0 TO 10
' Values 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
CASE 11, 13
' Values 11, 13
CASE ELSE
' All other values, ie. negative values, 12, and values over 13
END SELECT
REPEAT
' Do something
FOREVER
REPEAT
' Do something
UNTIL a < b
REPEAT
' Do something
WHILE a != b
' Calling functions
PRINT "Text" ' Calls user defined function (though PRINT may later also be native)
ADD 10, 20 ' Call function as a sub
PRINT STR(10) ' If function return value is used parameters must be in parenthesis
DRAWSCREEN ' Without parameters
' Defining function
FUNCTION ADD(a AS INTEGER, b AS INTEGER) AS INTEGER
RETURN a + b
END FUNCTION
' And a subprogram
SUB PRINT(s AS STRING)
STATIC y AS INTEGER = 0
ADDTEXT 0, y, s
y = y + 10
END SUB
The language can be extended by extension libraries (possibly only for developers of Eppabasic). Extensions consist of JavaScript file containing the program code of the extension and a map file mapping Eppabasic code to Javascript. For example:
Javascript:
function somefuncInJs(x1, y1, x2, y2) {
// Do something
}
Map file:
FUNCTION SOME(x1 AS INTEGER, y1 AS INTEGER, x2 AS INTEGER, y2 AS INTEGER) AS INTEGER
RETURN NATIVE(somefuncInJs(x1, y1, x2, y2))
END FUNCTION
FUNCTION SOME(x1 AS INTEGER, y1 AS INTEGER, x2 AS INTEGER, y2 AS INTEGER) AS INTEGER: somefuncInJs
DECLARE FUNCTION SOME ALIAS somefunctInJs(x1 AS INTEGER, y1 AS INTEGER, x2 AS INTEGER, y2 AS INTEGER) AS INTEGER
There is one big difference between desktop and web programs, namely the main loop. In desktop programs one can write a main loop quite easily:
while (1) {
input();
update();
render();
}
This is not the case with the Javascript. In Javascript one has to write a game loop asynchronously:
function mainloop() {
input();
update();
render();
window.requestAnimationFrame(mainloop);
}
// Start the game
mainloop();
We want games to be programmed as desktop programs, so we have to find some trick to get around the problem. Here are listed some suggested solutions for the problem:
- Creating a mandatory sub to the language
SUB UPDATE()
' Update and rerender the screen
END SUB
- Adding a new type of loop
DO
' Update and rerender the screen
RENDER