Catalog · How the catalog works
quickjs-demo
Demo of QuickJS-Pascal in Castle Game Engine
- ★ 9 on GitHub
Anyone may press Interesting, signed in or not. It helps others find this project.
README
Control a snake using JavaScript (demo of QuickJS-Pascal and Castle Game Engine)
Overview
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 withxandyfields (like{x:3,y:5}) that contains the position of the "goal" on the map.player_position()- returns a structure withxandyfields 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)
Supported platforms
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
QuickJS-Pascal
https://github.com/Coldzer0/QuickJS-Pascal
Game Credit
Demo by Coldzer0, who also created QuickJS-Pascal.

