This demo shows QuickJS-Pascal (Pascal bindings to QuickJS) integrated with Castle Game Engine.
The demo is based on a snake game. In the original snake game, you control snake by the keyboard. In this version, you control snake by implementing an A.I. using JavaScript :)
The core file to play with is the data/movement.js. There you have to define a global update
function, which is called once per second, and can move the snake using these JS functions:
-
goal_position()
- returns a structure withx
andy
fields (like{x:3,y:5}
) that contains the position of the "goal" on the map. -
player_position()
- returns a structure withx
andy
fields that contains the current player position on the map. -
move(x, y)
. Moves the player. Can be called at most once perupdate()
. The only allowed arguments' combinations are:move(+1, 0)
(move right)move(-1, 0)
(move left)move(0, +1)
(move up)move(0, -1)
(move down)
The demo is cross-platform and should support every platform supported by Castle Game Engine. Build it using Castle Game Engine build tool or Lazarus.
-
Tested
- Mac OS Catalina
- IOS 13.3.1
-
TODO
- Test on Linux, Windows, Android
- Add more JS examples
- Add Start function to be called on game init
- Implement full UIFont interface to JS
You can download QuickJS library files from here: Download
https://github.com/Coldzer0/QuickJS-Pascal
Demo by Coldzer0, who also created QuickJS-Pascal.