**quadplay✜** Fantasy Console by [Casual Effects](https://casual-effects.com)
[*Quick Start*](#quickstart) ∙ [*API*](#standardlibrary) ([*Input*](#standardlibrary/input) ∙ [*Physics*](#standardlibrary/physics) ∙ [*Graphics*](#standardlibrary/graphics) ∙ [*Sound*](#standardlibrary/sound) ∙ [*AI*](#standardlibrary/pathfinding)) ∙ [*Assets*](#built-inassets) ([*Sprites*](#sprites) ∙ [*Fonts*](#fonts) ∙ [*Sounds*](#sounds))
[Controls](#controls) ∙ [Symbols](#symbols) ∙ [JSON Formats](#projectfile) ∙ [Language Spec](#pyxlscriptlanguage) ∙ [Network](#network) ∙ [Change Log](#changelog)
> "Imagine a fantasy timeline in which modern video game mechanics, > scripting languages, data structures, and AI all developed before > mainstream online gaming and 3D graphics. > The quadplay✜ console is a virtual predecessor of > Nintendo64 and PlayStation. It is so friendly that anyone can make their > own beautiful game in a few days, yet supports play as creative and deep as current > indie titles. It is the union of 2020 development power and 1989 output constraints." The [**quadplay✜**](../console/quadplay.html?IDE=1) is a web-based fantasy game console for sprite-based 2D and 2.5D games. It lets you create games with the power and consistency of a game console and the flexibility of modern tools and web deployment. Because it is free, is easy to use, and runs everywhere, quadplay✜ is perfect for hobby coding, a game programming course, teaching yourself programming and game development, and game jams. The integrated development environment (IDE) is packaged as an emulator with the tools that you need to make games: an editor, debugger, and profiler. **Virtual Hardware Features** - 384 x 224 pixel screen = 12:7 aspect ≈ 16:9.3 - 60 fps, with autoscaling on low-end machines - 4096 sRGB (4:4:4) colors - Native 2.5D graphics - A* pathfinding AI - 2D physics - 2D sound with pitch, volume, and unlimited voices - 10.5 MB of total sprite memory - Max 128 sprite and font sheets, max size 1024x1024 - Order-independent 16-level transparency - 4 players with SNES/PS1/Saturn-style controllers D-pad + 8-button gamepads - Touch screen/mouse input - Optional 320x180, 192 x 112, 128 x 128, and 64 x 64 screen modes, analog sticks, and dual D-pads **Software Features** - Export to your own website, itch.io, github pages, or download - Games run on web, mobile, desktop, tablet, Jetson Nano, and Raspberry Pi 4 - Free for commercial, personal, and educational use - Friendly and powerful PyxlScript Python-like scripting language - Run locally and offline using Python + web browser - Hundreds of built-in Creative Commons assets - Full commandline, external editor, and external art tool support for power users - Open source: use online, fork, or run locally - Import PNG, MP3, TMX, JSON, YAML, and CSV data **API** - Sprite, pixel, circle, line, triangle, rectangle, and polygon drawing with rotation and scaling - Font, tilemap, and UI window drawing - Optional entity parenting hierarchy - Ray casting and collision detection - Postprocessing effects - Persistence (saving and loading) - Nestable state-machine "modes" - Per-mode callback "hooks" Quick Start ==================================================================================== Welcome to the quadplay✜ public beta! To get started you only need: - [The quadplay✜ development kit](https://github.com/morgan3d/quadplay/archive/master.zip) - [Python 3.8](https://www.python.org/) - A modern web browser ([_Chrome_](https://www.google.com/chrome/), [_Firefox_](https://www.mozilla.org/en-US/firefox/new/), [_Edge_](https://www.microsoft.com/en-us/edge), or _Safari_) For the quadplay✜ development kit, just download, unzip, and then copy the files wherever you would like on your computer. There is no installer or configuration required. To make a game, run the `quadplay` script at the command line. When it opens your browser, select the "Tools" menu from inside the quadplay development environment and then the "New Game" option. Look at the Built-In Games section for more examples. If you've worked with other scripting languages, then you may want to read the PICO-8 section, Python section, or JavaScript section of this document for some starting tips. If you're new to programming, just look at the many sample games and examples that are included and try modifying your own copies of them. !!! Info Pro Developers Experienced programmers can use external editors with quadplay✜ for both programming and directly modifying game and asset `.json` files by: Launch your program in the emulator and debugger from the command line on Windows CMD, macOS Terminal, or a Linux terminal with the `quadplay` command in the root of the SDK. Here are some examples: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ bash # Run the emulator and IDE. You can use Open Game from the Tools # menu to load games quadplay # Load the games/quadpaddle/quadpaddle.game.json sample program quadplay quad://games/quadpaddle # Load the space.game.json game that you've made (on Mac and Linux) quadplay ~/my_quadplay/space # Load the space.game.json game that you've made (on Windows) quadplay C:\Users\MYNAME\my_quadplay\space # Load your game and allow mobile clients to connect by scanning # the QR code displayed in the IDE (Mac and Linux) quadplay --host ~/my_quadplay/space # ... Windows quadplay --host C:\Users\MYNAME\my_quadplay\space # Load a game from the web (their server must support CORS) quadplay https://morgan3d.github.io/somegame/foo.game.json ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ These examples assume that your directory structure is: ***************************************************************************** * 📂 HOME (~/ on Mac and Linux, %HOMEDRIVE%%HOMEPATH% on Windows) * | * +-- 📂 my_quadplay * | | * | '-- 📂 space * | | * | +-- 📄 space.game.json * | | * ⋮ ⋮ * * 📂 quadplay * | * +-- 📄 quadplay * | * +-- 📂 fonts * | | * | ⋮ * | * +-- 📂 games * | | * | +-- 📂 quadpaddle * | | | * | | +-- 📄 quadpaddle.game.json * | | | * | ⋮ ⋮ * | * +-- 📂 sprites * | | * ⋮ ⋮ ***************************************************************************** [Directory structure with the `quadplay` script in the root.] The directory and `.game.json` file do not have to have the same name. You can list the full path to the actual game file instead. Your games do not have to be stored in a subdirectory of the SDK. They can be anywhere on your system. Every time you push the Run button (F5) or Reload button (Ctrl+R) in the emulator within the web browser, it will reload your code and assets from disk. You can use the built-in assets from the developer kit, existing ones from sites like [OpenGameArt.org](http://opengameart.org) and [FreeSound](http://freesound.org), or create your own using: - PNG pixel art editor for sprites and fonts (_[Gimp](https://www.gimp.org/), [AseSprite](https://www.aseprite.org/), [Krita](https://krita.org/en/), Photoshop, GraphicsGale, etc._) - MP3 sound tools (_[BFXR](https://www.bfxr.net/), [Audacity](https://www.audacityteam.org/), etc._) - TMX map tool ([Tiled](https://www.mapeditor.org/), [TileKit](https://rxi.itch.io/tilekit)) _People playing your game don't need Python, just a web browser. See the Deploying Games section for more information._ Workflow ------------------------------------------------------------------------------------ You should create your programs however works best for you. Here's how I like to work in quadplay✜: 1. I start with a project file to load standard assets from `quad://` and a single *mode* called `Play.pyxl` that has no sections. I write a little code to draw the game. 2. Pretty soon, I need some state that persists between frames, so I separate `Play.pyxl` into top level initialization code and a `frame` *section*. I then declare variables in in the top level of the mode, and as my main loop grows too long, I start to define helper functions there as well. 3. At some point, I'm ready for *another mode*. This is usually for gameplay reasons, and not polish, because it is still early in the project. This might be a map or inventory screen, for example. As soon as there is a new mode, I need to have variables that can be seen by both modes. So, I also create a `common.pyxl` file or other *script* to store the global variables. I continue this process as more modes are required, periodically checking the mode system diagram in the IDE to ensure that the game flow is what I expected. 4. As code starts to become duplicated in the modes, I move generally useful helper functions out to scripts. When the scripts themselves get long, I start grouping them by functionality. For example, `particle.pyxl`, `animation.pyxl`, and `hud.pyxl`. This is a workflow that is good for prototyping, especially in game jam and hobby projects. I feel like keeping everything as simple as possible and then refactoring at growth points is best for productivity. Otherwise, it is hard to iterate in the beginning because you're stuck with big program abstractions in what is still a small program. Many prototypes don't go the distance to become big programs, anyway. There's no reason to overdesign early on. Built-In Games ------------------------------------------------------------------------------------ Five complete games and many examples are included to show how to use the API. If you are accessing this manual from a web site or your local machine running the quadplay✜ emulator, use the links here to launch the game in your browser, press the Run button (F5) to start the game. ### Playable
[Quadpaddle](../console/quadplay.html?game=quad://games/quadpaddle&IDE=1) is a four-player cooperative game inspired by [_Breakout_]("https://en.wikipedia.org/wiki/Breakout_(video_game)"): - Powerups - Level-end animations - Particle system - Screen shake - Frame hooks - Coordinates with +Y pointing down ----------------------------
[Doubles de Pon](../console/quadplay.html?game=quad://games/doublesdepon&IDE=1) is 1-4 player action puzzle matching game: - Custom music - High scores - Menus and character selection - Multiple play modes - Complex animation "juice" ----------------------------
[across the lake](../console/quadplay.html?game=quad://games/across_the_lake&IDE=1) is an endless runner created for Ludum Dare 46 based on skipping stones over a lake in the evening. - Crossfading - Simple custom physics - Custom camera - Coordinates with +Y pointing up - Procedural content - Fake reflections - Parallax and pseudo 3D ----------------------------
[Serpitron](../console/quadplay.html?game=quad://games/serpitron&IDE=1) is a four-player competive game derived from Snake-like games, including [TRON]("https://en.wikipedia.org/wiki/Tron_(video_game)"): - Level transitions using post effects - Drop shadows - Player selection - Sorting - Collisions ----------------------------
[Ice Time](../console/quadplay.html?game=quad://games/icetime&IDE=1) is a four-player competitive or cooperative 2 vs. 2 ice hockey game: - 192 x 112 graphics - AI players - Cut scenes - Persistent data - Reflection effects ----------------------------
[Beat the Gobblins](../console/quadplay.html?game=quad://games/beat_the_gobblins&IDE=1) is a single-player arcade battle arena: - High scores - Custom music - Animated title - Animated explosions - Character spawning ----------------------------
[Beyond Control](../console/quadplay.html?game=quad://games/beyond_control&IDE=1) is a game for 1-4 players controlling broken robots: - Hexgrid - Asynchronous animations - Turn based system - In-game user interface - Dynamic layout - Dynamic map - Animated map ----------------------------
[R. P. S.](../console/quadplay.html?game=quad://games/rps&IDE=1) is a rock-paper-scissors battle royale for up to four players: - Extensive animation - Use of modes for simplicity - Timed sound effects - Private choices in multiplayer - Combinatorial logic ### Examples
![](../examples/starter/label128.png) [Starter](../console/quadplay.html?game=quad://examples/starter&IDE=1) is a project with a basic setup from which you can build your own.
![](../examples/helloworld/label128.png) [Hello, World](../console/quadplay.html?game=quad://examples/helloworld&IDE=1) is a minimal example of a program with one mode, one asset, and no sections or optional elements, and that simply puts text on the screen.
![](../examples/rpg/label128.png) [RPG Demo](../console/quadplay.html?game=quad://examples/rpg&IDE=1) is a simple example of a single-player RPG game design: - Multiple [modes](#modes): Play, Inventory, and Shop - Multi-layer map - Player movement with obstructions - NPC interaction
![](../examples/dual-stick/label128.png) [Dual-Stick Example](../console/quadplay.html?game=quad://examples/dual-stick&IDE=1) shows how to use dual-stick controls. The body of the tank is controlled by player 1 and the turret is controlled by player 2. When using a dual-stick game controller or keyboard, a single player can also use the right stick or right side of the keyboard to control the turret. - Dual-stick controls - Working with angles - Entity parenting - 320x180 resolution
![](../examples/robot/label128.png) [Robot Example](../console/quadplay.html?game=quad://examples/robot&IDE=1) shows how to create and animate a deep entity hierarchy. - Entity parenting - Pivots that are not at the center of sprites - Using scale and rotation together - Graphics tricks for reflections
![](../examples/animation/label128.png) [Animation Example](../console/quadplay.html?game=quad://examples/animation&IDE=1) shows how to handle complicated sprite animations. - Sprite animations - Basic jumping physics - Changing direction - Modular items
![](../examples/vehicles/label128.png) [Vehicles Example](../console/quadplay.html?game=quad://examples/vehicles&IDE=1) contains examples of several vehicle controls from a free-direction top-down perspective. - 2.5D camera perspective - Using the ⓔ and ⓕ buttons - Simple vehicle simulation for control feel - Entities with moving child parts - 2.5D sprite stacking - Dynamic shadows - Minimap
![](../examples/fluid/label128.png) [Fluid Example](../console/quadplay.html?game=quad://examples/fluid&IDE=1) is a cellular automata fluid flow simulation with gravity and pressure.
![](../examples/roguelike/label128.png) [Roguelike Example](../console/quadplay.html?game=quad://examples/roguelike&IDE=1) uses the roguelike sprite set for tilemap rendering with a simple text-heavy UI section.
![](../examples/accel_demo/label128.png) [Acceleration Curve Example](../console/quadplay.html?game=quad://examples/accel_demo&IDE=1) is a simple demonstration of how various acceleration curves feel, changing only three constants: top speed, acceleration time and deceleration time. Up and down change the constants to fit different games.
![](../examples/boids/label128.png) [Boids Example](../console/quadplay.html?game=quad://examples/boids&IDE=1) implements the famous ["boids" flocking algorithm](https://en.wikipedia.org/wiki/Boids).
![](../examples/clouds/label128.png) [Clouds Example](../console/quadplay.html?game=quad://examples/clouds&IDE=1) demonstrates per-pixel graphics and multi-octave `noise()` functions. The virtual GPU is fast enough to process one point per pixel, but this technique is not recommended in general because the computations to produce the points tend to be too slow, even if this simple.
![](../examples/entity/label128.png) [Clouds Example](../console/quadplay.html?game=quad://examples/enity&IDE=1) Shows different ways of constructing entities with text and sprites.
![](../examples/physics/label128.png) [Physics Example](../console/quadplay.html?game=quad://examples/physics&IDE=1) shows all of the features of the physics engine, including the debugging visualization.
![](../examples/text/label128.png) [Text Example](../console/quadplay.html?game=quad://examples/text&IDE=1) shows how to use `replace()`, `draw_text()`, `join()`, `format_number()`, and `draw_sprite_corner_rect()` to build text-heavy interfaces.
![](../examples/fontpreview/label128.png) [Font Preview](../console/quadplay.html?game=quad://examples/fontpreview&IDE=1) shows how to render text in various styles and acts as a tool for previewing fonts when creating new ones. Use the arrow keys to scroll down and see more examples in the program, and edit the `game.json` file to see a different font.
![](../examples/highscore/label128.png) [High Score Example](../console/quadplay.html?game=quad://examples/highscore&IDE=1) demonstrates `load_local()` and `save_local()` to maintain a high score list, with `push_mode()` for creating a popup dialog.
![](../examples/vaporwave/label128.png) [Vaporwave Example](../console/quadplay.html?game=quad://examples/vaporwave&IDE=1) uses pseudo-3D techniques of pre-rendered sprites and polygon meshes.
![](../examples/sproing/label128.png) [Sproing Example](../console/quadplay.html?game=quad://examples/sproing&IDE=1) shows a squash and stretch effect for transforming sprites.
![](../examples/perceptual_color/label128.png) [Perceptual Color](../console/quadplay.html?game=quad://examples/perceptual_color&IDE=1) shows the difference between `perceptual_lerp_color()` and `lerp()`.
![](../examples/zcar/label128.png) [Z-Car Example](../console/quadplay.html?game=quad://examples/zcar&IDE=1) draws a 3D wireframe car using 2.5D graphics and CRT orange-screen retro phosophor effects.
![](../examples/lift_team/label128.png) [Lift Team](../console/quadplay.html?game=quad://examples/lift_team&IDE=1) combines physics and dynamic constraints for an asymmetric platformer setup, where one player flies a helicopter that can lift the other player's mech.
![](../examples/sequence_demo/label128.png) [Sequence Demo (transition effect)](../console/quadplay.html?game=quad://examples/sequence_demo&IDE=1) Shows how to use the sequence function to create a transition effect, which is factored out into an easy to drop in library. The sequence function lets choreograph series of frame hooks one after the other.
![](../examples/speedstreet/label128.png) [Speed Street](../console/quadplay.html?game=quad://examples/speedstreet&IDE=1) is the setup for a four-player competitive racing game inspired by [_Excitebike_](https://en.wikipedia.org/wiki/Excitebike) and Tony Hawk games, using: - Entity hierarchy - Simple custom physics - Orthographic 2.5D graphics - Coordinates with +Y pointing up - `sprite_override_color`
![](../examples/planetgen/label128.png) [Planet Generator](../console/quadplay.html?game=quad://examples/planetgen&IDE=1) uses built-in assets to create random 3D planets with moons, stars, atmosphere, and rings.
![](../examples/touch/label128.png) [Touch Example](../console/quadplay.html?game=quad://examples/touch&IDE=1) uses the mouse/touch API.
![](../examples/twin_analog/label128.png) [Twin Analog Example](../console/quadplay.html?game=quad://examples/twin_analog&IDE=1) shows how to use `device_control()` to access twin analog sticks and game controller triggers that are not standard on quadplay consoles.
### Inspiration Some games that were not made in quadplay✜, but which fit within the restrictions of quadplay and are sources of inspiration for their arcade graphics and gameplay:
- [Towerfall Ascension](http://www.towerfall-game.com/) - [Crawl](https://www.powerhoof.com/crawl/) - [Nuclear Throne](http://nuclearthrone.com/) - [Celeste](http://www.celestegame.com/) - [Undertale](https://undertale.com/) - [Monolith](https://store.steampowered.com/app/603960/Monolith/) - [Crypt of the Necrodancer](https://store.steampowered.com/app/247080/Crypt_of_the_NecroDancer/) - [Shovel Knight](https://yachtclubgames.com/shovel-knight/) - [Sonic Mania](https://www.sega.com/games/sonicmania) - [Spelunky Classic](https://spelunkyworld.com/original.html) - [Dwarf Fortress](http://www.bay12games.com/dwarves/) - [Contra]("https://en.wikipedia.org/wiki/Contra_(video_game)") - [Super Contra](https://en.wikipedia.org/wiki/Super_Contra) - [Kirby's Adventure](https://en.wikipedia.org/wiki/Kirby%27s_Adventure) - [Gradius](https://en.wikipedia.org/wiki/Gradius) - [Life Force](https://youtu.be/lgfTC3UVCVs) - [Gradius II](https://en.wikipedia.org/wiki/Gradius_II) - [Gradius III](https://en.wikipedia.org/wiki/Gradius_III) - [River City Ransom](https://en.wikipedia.org/wiki/River_City_Ransom) - [Double Dragon]("https://en.wikipedia.org/wiki/Double_Dragon_(video_game)") - [Super Double Dragon](https://en.wikipedia.org/wiki/Super_Double_Dragon) - [Castlevania II](https://en.wikipedia.org/wiki/Castlevania_II:_Simon%27s_Quest) - [Castlevania III](https://en.wikipedia.org/wiki/Castlevania_III:_Dracula%27s_Curse) - [Castlevania: Symphony of the Night](https://en.wikipedia.org/wiki/Castlevania:_Symphony_of_the_Night) - [Castlevania: Aria of Sorrow](https://en.wikipedia.org/wiki/Castlevania:_Aria_of_Sorrow) - [Castlevania: Dawn of Sorrow](https://en.wikipedia.org/wiki/Castlevania:_Dawn_of_Sorrow) - [Advance Wars](https://en.wikipedia.org/wiki/Advance_Wars) - [Advance Wars Dual Strike](https://en.wikipedia.org/wiki/Advance_Wars:_Dual_Strike) - [Out Run](https://en.wikipedia.org/wiki/Out_Run) - [Dig Dug](https://en.wikipedia.org/wiki/Dig_Dug) - [Batman](https://en.wikipedia.org/wiki/Batman:_The_Video_Game) - [Tetris](https://en.wikipedia.org/wiki/Tetris) - [Blades of Steel](https://en.wikipedia.org/wiki/Blades_of_Steel) - [Pac-Man](https://en.wikipedia.org/wiki/Pac-Man) - [PGA Tour Golf](https://en.wikipedia.org/wiki/PGA_Tour_Golf) - [Lode Runner](https://en.wikipedia.org/wiki/Lode_Runner) - [Star Fox](https://en.wikipedia.org/wiki/Star_Fox) - [Metroid](https://en.wikipedia.org/wiki/Metroid) - [The Legend of Zelda]("https://en.wikipedia.org/wiki/The_Legend_of_Zelda_(video_game)") - [Zelda II: The Adventure of Link](https://en.wikipedia.org/wiki/Zelda_II:_The_Adventure_of_Link) - [The Legend of Zelda: Link's Awakening](https://en.wikipedia.org/wiki/The_Legend_of_Zelda:_Link%27s_Awakening) - [The Legend of Zelda: A Link to the Past](https://en.wikipedia.org/wiki/The_Legend_of_Zelda:_A_Link_to_the_Past) - [Mega Man 2](https://en.wikipedia.org/wiki/Mega_Man_2) - [Super Mario Bros.](https://en.wikipedia.org/wiki/Super_Mario_Bros.) - [Super Mario Bros. 2](https://en.wikipedia.org/wiki/Super_Mario_Bros._2) - [Super Mario Bros. 3](https://en.wikipedia.org/wiki/Super_Mario_Bros._3) - [Rogue]("https://en.wikipedia.org/wiki/Rogue_(video_game)") - [NetHack](https://en.wikipedia.org/wiki/NetHack) - [Snake]("https://en.wikipedia.org/wiki/Snake_(video_game_genre)") - [Minit](https://store.steampowered.com/app/609490/Minit/) - [Chasm](https://bitkidinc.itch.io/chasm) - [Eliminator Boat Duel](https://www.youtube.com/watch?v=NM7ZNX0GUBI) - [The Eternal Castle](http://www.theeternalcastle.net/)
These are games that would fit the restrictions of quadplay✜ except they use native vector displays in their original implementations: - [Asteroids]("https://en.wikipedia.org/wiki/Asteroids_(video_game)") - [Battlezone]("https://en.wikipedia.org/wiki/Battlezone_(1980_video_game)") - [Space War](https://en.wikipedia.org/wiki/Spacewar!) - [Tempest]("https://en.wikipedia.org/wiki/Tempest_(video_game)") These are games whose style and gameplay would fit, but that would exceed the resolution limitations of quadplay✜: - [Axiom Verge](http://www.axiomverge.com/) - [Into the Breach](https://subsetgames.com/itb.html) Programming Model ------------------------------------------------------------------------------------ The **PyxlScript** programming language is designed to make compact, readable games. It blends Python, Lua, and JavaScript syntax. Indentation and newlines signify blocks and ends of statements. The syntax is based on math notation and looks like pseudocode. Variables are explicitly declared and dynamically typed. There's lexical scope, first class functions, and literal expressions for objects and (zero-based) arrays. It is decidedly function-based instead of object-oriented. Most of PyxlScript programming is typical of any imperative, high-level language. It is similar to Python, Lua, JavaScript, C#, and Java. There are three special parts of the PyxlScript programming model that are designed to simplify programming arcade games. These special features are [*modes*](#modes), [*2.5D graphics*](#2.5dgraphics), and [*frame hooks*](#framehooks). ### Modes Your program consists of one or more *modes* which are game states that the player will experience. Common modes are "Play", "Title", "Inventory", "CutScene", and "GameOver". Use `set_mode()` to change which mode the program is in. Clicking on the "Modes" label on the left side of the IDE draws a diagram showing the modes and transitions for your program. ![Mode diagram for the Quadpaddle sample game, as shown in the IDE.](modes.png width=50% style="image-rendering:auto") For each mode, you specify what code runs every *frame*. This is the body of the inner loop. Modes have capitalized names and are defined in a script file with the same name. The simplest implementation of a mode is just this per-frame code. The `mode_frames` variable tracks the number of frames since this mode started. `set_mode()` changes the mode and leaves a note in the debugging output explaining why the mode changed. It is also used by the IDE to visualize the state machine of your program and label the transitions, as in the diagram above. `get_mode()` returns the current mode, which acts like a special constant. You can also separate the mode file into different sections: - Top level: runs once when the game is first started. Usually just variable and function declarations. - `enter`: event that runs when this mode becomes active by another executing `push_mode()` or `set_mode()`. `enter` may be followed by an argument list that will be filled with the values passed to `set_mode()` or `push_mode()`. - `frame`: event that runs every frame while this mode is active. Put your drawing and simulation code here. - `leave`: event that runs when the game changes to another mode by executing `pop_mode()` or `set_mode()` itself. - `pop_mode`: event that runs when the game returns to this mode from another by `pop_mode()`. Note that `leave` and `pop_mode` do not run on `reset_game()` or `quit_game()`. You can think of these as callbacks, although they are not regular functions and can only be invoked directly by the console. You may be familiar with the concept of a [state machine](https://en.wikipedia.org/wiki/Finite-state_machine), also called a finite automata or flow chart. Your program is a state machine with the modes as the states. !!! Note: Transition Hints The IDE automatically constructs the mode diagram from your program. It is [impossible](https://en.wikipedia.org/wiki/Undecidable_problem) to do this for all programs, but it can usually do a good job. When the automatic algorithm misses a link, you can give it a hint using a commented out `set_mode()` call in your mode file. For example, // set_mode(GameOver) because "0 lives" will add a link from the current mode to the `GameOver` mode. The syntax of a mode with multiple sections is similar to [Markdown](https://en.wikipedia.org/wiki/Markdown) format: 1. The name of the mode on the first line 2. A line of `=`, `═`, or `⚌` characters to underline the mode name 3. The top-level code 4. The sections, each with a name underlined by `-`, `-`, `─`, `—`, `━`, or `⎯` characters ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PyxlScript Menu ═══════════════════════════════════════════════════════════ // A good place to declare state only used by this mode let selection const choices = ["Continue", "Show Map", "Abandon Mission"] enter(value) ─────────────────────────────────────────────────────────── // Can also be enter without any arguments or parentheses // Reset any state selection = 0 play_sound(menuOpen) frame ─────────────────────────────────────────────────────────── set_background(rgb(1, 1, 0)) // Up and down to change the choice selection = (selection + 3 + gamepad_array[0].y) mod 3 // Draw the menu let pos = screen_size / 2 - xy(0, 50) draw_text(menuFont, "→", pos + xy(-50, 16 selection), #00F) for c in choices: draw_text(menu_font, c, pos, #000) pos.y += 16 // Button press to choose if gamepad_array[0].aa: if selection == 0: set_mode(Play) because "Chose play" else if selection == 1: set_mode(Map) because "Chose map" else: push_mode(ConfirmDialog) because "Chose abandon" pop_mode(confirmed) from ConfirmDialog ─────────────────────────────────────────────────────────── if confirmed: set_mode(Title) because "Confirmed abandon" leave ─────────────────────────────────────────────────────────── play_sound(menuClose) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [A sample in-game menu mode using all of the optional mode sections.] If you're accustomed to object-oriented languages, then you might think of the whole program as: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Java public class Menu extends Mode { // These variables are the top-level code protected int selection; public void enter(int value) { selection = 0; play_sound(menuOpen); } public void frame() { selection = (selection + gamepad.y + 3) % 3; } drawChoices(selection); if (gamepad.a) { if (selection == 0) { set_mode(play); } ... } } public void pop_mode(boolean confirmed, Mode from) { if (from == confirmDialog) { ... } } public void leave() { play_sound(menuClose); } } Mode menu = new Menu(); ... menu.enter(); while (get_mode() == menu) { menu.frame(); } menu.leave(); ... ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [This is the rough equivalent of the menu mode PyxlScript code in an object-oriented language. You don't write all of this boilerplate in PyxlScript!] #### Unmatched Push and Pop Mode Push and pop on modes aren't always paired, because sometimes an exceptional change to state flow occurs. ********************************************************************* * .-----. push_mode(B) .-----. set_mode(C) .-----. * ( A )--------------->( B )-------------->( C ) * '-----' '-----' '-----' ********************************************************************* [Actual code executed with unmatched push/pop mode calls.] For example, if mode `A` executes `push_mode(B)`, and then `B` executes `set_mode(C)` (instead of popping), the order of events triggered will be: 1. `B: enter` 2. `B: leave` 3. `A: pop_mode from B` 4. `C: enter` This is as if `B` had run the `pop_mode` and then `A` directly transitioned to C. ********************************************************************* * push_mode(B) * .-----.----------------->.--+--. .-----. * ( A ) ( B ) ( C ) * '--+--'<-----------------'-----' '-----' * | pop_mode() ^ * | | * '----------------------------------------------' * set_mode(C) ********************************************************************* [Equivalent behavior triggered by the actual code, so that PyxlScript can ensure matched push/pop] ### 2.5D Graphics Graphics in PyxlScript are similar to other 2D rendering APIs. You can set the background color, draw basic shapes and text, and render sprites with some features such as flipping and rotation. There's special support for drawing whole tile maps as well. All drawing commands support an [_alpha_ channel](https://en.wikipedia.org/wiki/Alpha_compositing) for transparency. What is special about the 2.5D graphics in PyxlScript is that each drawing command has an associated _z-order_. If two commands are at the same z-order, then whichever comes second will draw on top of the other one. Commands that have explicit, different z-order values will render from low to high values. This means that you can issue drawing commands in whatever order is convenient and let the rendering system organize them as you wish. It also makes it easy to render orthographic games such as [_Double Dragon_]("https://en.wikipedia.org/wiki/Double_Dragon_(video_game)"), isometric games such as [_Populous_]("https://en.wikipedia.org/wiki/Populous_(video_game)"), and other games with semi-3D effects. The included [_Speed Street_](#playable) game demonstrates this. Although the screen is cleared to the background color every frame, all of the drawing commands are stored for one previous frame. This allows dialogue and inventory screens to re-render the previous mode's last frame using `draw_previous_mode()` so that they can render on top of them. This rendering retains z-order, so you can even inject new graphics in between objects from a previous mode's frozen image. ### Frame Hooks In addition to the mode's frame code, you can dynamically register hook functions to run at the beginning of every frame using `add_frame_hook()`. These are useful for timers and animations. For example, you can use this to draw an explosion every frame until it dissipates or to shake the screen for three frames. Frame hooks can be tied to only run in a specific mode or to run in all modes. You can also specify a separate hook to run each frame from the one to run when it expires. The closest relative to frame hooks is JavaScript's `setTimeout()` function, although it is much more limited. Coming from... ------------------------------------------------------------------------------------ Here are some tips to get you started quickly when you're coming to PyxlScript from other popular programming languages. ### PICO-8 If you're used to programming in PICO-8 Lua, make these changes for the PyxlScript: - Create a *mode* for your project. - Put your top-level and `_init` code into the top level - Put your `_update` and `_draw` combined into the `frame` section - Declare variables with `let` and `const` instead of `local` - Variable names can't begin with an underscore - Arrays start at 0 - Use `size(x)` instead of `#x` - Use `:` between the beginning of a block and its body - Blocks have no `end` statements and indentation is significant - Use `:` within object literals instead of `=` - It is safe to mutate containers inside iterator loops - You must specify a font for `draw_text()`. Several are provided; see the Fonts section. - Enjoy the overloaded operators, array functions, z-order, and alpha blend ### Python The PyxlScript language feels a lot like Python, with these changes: - Comments begin with `//` instead of `#` - Explicitly declare variables with `let` and `const` - Use `size(x)` instead of `len(x)` - Use `debug_print` instead of `print` - Use `for low <= i < high` instead of `for i in range(low, high)` - Variable names can't begin with an underscore - The `==` operator is pointer equality (Python `is`). Use `equivalent` for object structural equality tests. - Variables have block scope instead of function scope - Function variables have lexical scope (no `global` statement required) - No integer division (use `floor`) - No comparison operator chaining - Use `keys(obj)` and `values(obj)` instead of `obj.keys()` and `obj.values()` (although you almost never need either due to the `for` loop syntax) - Use `iterate()` instead of `map()`, `filter()`, or list comprehensions - Use `x = if t then a else b` for Python `x = a if t else b` - Use `true`, `false`, `nil` instead of `True`, `False`, `None` - Use `def foo(a, b, ...rest)` instead of `def foo(a, b, *rest)` - Use `foo(a, b, ...rest)` instead of `foo(a, b, *rest)` - Use `[...array1, ...array2]` or `extended(array1, array2)` instead of `array1 + array2` - Use `extend(a, b)` for Python `objA.update(objB)` and `listA.extend(listB)` - Use `extended(a, b)` for Python `listA + listB` or `{**objA, **objB}` - Use `extend(array1, array2)` instead of `array1 += array2` - Use `def foo(x default y)` instead of `def foo(x = y)` - Default function parameters are evaluated once per call instead of once per program, so they do not capture and share values ### JavaScript The PyxlScript language feels a lot like JavaScript strict mode, with these changes: - Use PyxlScript `==` in place of JavaScript `===` - Use `:` and indentation instead of `{}` for defining blocks - Use `def` instead of `function` - Variable names can't begin with an underscore - No `;` required, except for multiple statements on the same line - Use `size(x)` instead of `x.length` - Use `for v at k in object:` instead of `for (k in object)` - Use `for k in array:` instead of `for (k in array)` - Use `for v in array:` instead of `for (v of array)` - It is safe to mutate containers inside iterator loops - There are no anonymous functions - Function names are not lifted to the containing function's scope - Use `x = if t then a else b` for JavaScript `x = t ? a : b` - Use `debug_print` instead of `console.log` - Use `a default b` instead of `a ?? b` - Enjoy the overloaded operators for vectors Tools ==================================================================================== Development Environment ----------------------------------------------------------------------------- The browser development environment supports several alternative layouts, which are selected from the buttons on the upper right of the screen. I expect most experienced programmers to use external editors such as Visual Studio Code and Photoshop and put the development environment in Full Screen or Test layout. Most newer programmers will directly use the built-in integrated development environment within the browser in the Develop and Debug modes. ![](../console/ui-fullscreen.png width=32) Full Screen : Play your game full screen. Good for playtesting. ![](../console/ui-touchscreen.png width=32) Touch Screen : Play your game with single-player mobile touch controls. ![](../console/ui-test.png width=32) Test : Run with a large emulator and the debugger visible. This is good for using on the left or right half of the screen when running an external editor on the other half. ![](../console/ui-debug.png width=32) Debug : Pixel-doubled emulator and compressed text editor. Good for debugging graphics code and tuning constants. ![](../console/ui-develop.png width=32) Develop : 1:1 pixel emulator with text editor and debugger. Good for working on gameplay code. ![](../console/ui-edit.png width=32) Edit : Full-screen code editor. Good for writing lots of code. ![](../console/ui-ghost.png width=32) Ghost : Show-off mode for livestreaming, with the full screen code editor and the game running behind it full screen, like a ghost. Press the Play button to switch input to the game in the background. Game touch input is obviously not available in this layout. There's also a special "kiosk" mode that the `quadplay` script can run in for removing the top control bar when running on an arcade machine or other public display mode. Emulator ------------------------------------------------------------------------------------ The main tool is the console emulator, which you can launch with the `quadplay` command at the command line. The emulator accepts keyboard and game controller input, as well as directly pressing its buttons on screen for mobile. On a gamepad, you must press a button before directional input will register in a web browser. Pressing the "Play" button on the editor automatically transfers keyboard focus to the emulator. The emulator has special keyboard keys for: - F5: run - F6: screenshot - F8 or Ctrl+G: start/stop recording GIF [^safariGIF] - F10: step one frame - Ctrl+Break or Ctrl+C - Ctrl+R or Ctrl+F5: reload On macOS, either Control or Command can be used for "Ctrl". [^safariGIF]: On Safari, you have to explicitly allow popups for the website for this to work. Go to Preferences --> Websites --> Pop-up Windows and check "allow" for `localhost` (or whatever address you access quadplay✜ from). ### Controls quadplay✜ presents virtual controllers for four players. You can use the on-screen buttons on mobile and touch screens for a single player, a keyboard for up to two players, and connect most USB or Bluetooth game controllers for up to four players. Physical controllers work on all operating systems and mobile devices. For two-player keyboard input, you can use two USB or Bluetooth keyboards on the same computer, or have both players share a single keyboard. The order of physical controllers can be changed from the Controls panel in the quadplay debugger. This is needed when configuring an arcade kiosk with physical positions for the players, or to allow mixed keyboard and physical controller play.
![](../console/xbox_controller.png style="border:none; image-rendering:auto" width=50%) ![](../console/gamepad.png style="border:none; image-rendering:auto" width=50%) ![](../console/keyboard.png style="border:none; image-rendering:auto" width=75%)

Physical controllers give the best experience. We have successfully tested the following, and most are autodetected by quadplay:
![](sn30-pro.jpg style="image-rendering:auto")
[8BitDo SN30 Pro](https://amzn.to/35XGEl9) (SN or Classic)
![](sn30.jpg style="image-rendering:auto")
[8BitDo SN30](https://amzn.to/38ay83F)
![](zero2.jpg style="image-rendering:auto")
[8BitDo Zero 2](https://amzn.to/2Ny5nWN)

![](xboxone.jpg style="image-rendering:auto")
[Microsoft Xbox One Wired Controller](https://amzn.to/36Y7CdR)
![](xboxone.jpg style="image-rendering:auto")
[Microsoft Xbox One Wireless
Controller for Windows 10](https://amzn.to/35U36vz)
![](xbox360.jpg style="image-rendering:auto")
[Microsoft Xbox 360 Wired Controller](https://www.microsoft.com/accessories/en-ww/products/gaming/xbox-360-controller-for-windows/52a-00004)

![](joy-con.jpg style="image-rendering:auto")
[Nintendo Joy-Con](https://amzn.to/30recqP)
![](switch-pro.jpg style="image-rendering:auto")
[Nintendo Switch Pro Controller](https://www.amazon.com/Nintendo-Switch-Pro-Controller/dp/B01NAWKYZ0)
![](thrustmaster.jpg style="image-rendering:auto")
[Thrustmaster T-Flight HOTAS X Flight Stick](https://amzn.to/2Tvf8J4)

![](xarcade-dual.jpg style="image-rendering:auto")
[X-Arcade Dual](https://shop.xgaming.com/collections/arcade-joysticks/products/x-arcade-dual-joystick-usb-included)
![](genesis.jpg style="image-rendering:auto")
[retro bit Sega Genesis](http://retro-bit.com/sega-collaboration)
![](m30.jpg style="image-rendering:auto")
[8bitdo M30 2.4G](https://www.8bitdo.com/m30/)

![](dualshock4.jpg style="image-rendering:auto")
[PlayStation DualShock 4 Wireless Controller](https://www.playstation.com/en-us/explore/accessories/gaming-controllers/dualshock-4/)
When trying to get a new controller working, first use https://html5gamepad.com/ to verify that your OS and web browser can see it. Then use the controller with quadplay. 8BitDo controllers work in wired, wireless, and [XPad](https://support.8bitdo.com/xpad.html) mode. They seem most reliable on Windows and Linux. Be sure to install the latest firmware update from the 8BitDo website. Left and right Joy-Cons work individually in horizontal mode. They cannot be joined as on Switch. The Switch Pro controller and the SNES and NES controllers work normally. On macOS, Xbox wired controllers require a free, [open source driver](https://github.com/360Controller/360Controller/issues). Xbox wireless controllers do not work on Mac. Different controllers work with different browsers on macOS. For example, Xbox 360 controllers work well with Chrome and the Nintendo SNES controller works with Safari. On macOS PS4 controllers work in Bluetooth mode (Xbox wireless controllers may also work in Bluetooth mode). Press the PS and SHARE buttons simultaneously to pair. If you have any problems, delete `/Library/Preferences/com.apple.Bluetooth.plist`, shut down and then start (do not warm reboot) and then re-pair. Stadia and [Logitech](https://www.logitechg.com/en-ca/products/gamepads/f310-gamepad.html) controllers are intended to work but I have not tested them. Please let me know if you are using them successfully. All browsers have controller support, but Chrome seems to support the most different controllers reliably on all platforms. Input | Player 1 Key| Player 2 Key| Xbox | Playstation| SNES | Switch Pro :----------:|:-----------:|:-----------:|:----------:|:----------:|:------:|:-----------: | W or ↑ | I | ▲ | ▲ | ▲ | ▲ | A or ← | J | ◀ | ◀ | ◀ | ◀ | S or ↓ | K | ▼ | ▼ | ▼ | ▼ | D or → | L | ▶ | ▶ | ▶ | ▶ ⓐ | B or space | / | Ⓐ | ╳ | Ⓑ | Ⓑ ⓑ | H or enter | ' | Ⓑ | ◯ | Ⓐ | Ⓐ ⓒ | V | . | Ⓧ | ▢ | Ⓨ | Ⓨ ⓓ | G | ; | Ⓨ | △ | Ⓧ | Ⓧ ⓔ | L.shift | N | LB | L1 | L | L ⓕ | C or R.shift| alt/option | RB | R1 | R | R ⓠ | 1 or Q | 7 || Share | Select | ⓟ | 4 or P | 0 | ☰ | Options | Start | [Sample controller mappings. quadplay✜ supports many more, including JoyCons and flight sticks.] After launching a quadplay game, you must press a button on the controller for the web browser to allow access to it. quadplay will automatically detect the controller and change to appropriate button prompts for most standard devices, including Xbox, PlayStation, Switch, Stadia, and Thrustmaster controllers. If your device is not mapped correctly, just enter the pause menu on any game and select "Set Controls". I've found that the easiest Bluetooth controller to pair on macOS is a Switch JoyCon. Turn on Bluetooth on your Mac and open the Bluetooth preferences. Hold the controller horizontally and hold the tiny sync button [you have to take off the black wrist strap holder temporarily to access this button]. You'll see the controller appear on your Mac. Click on its name and select "connect". When you want to re-pair the controller with your Switch, just slide it back onto the Switch and it will sync. 8BitDo controllers seem to work very reliably on Windows and Linux but are inconsistent on macOS. The [X-Arcade](https://shop.xgaming.com/) controllers work with quadplay. If you have a recent (2020 or later, or with the Tri-Mode PCB upgrade) X-Arcade controller, set XInput Mode 4 with the switch on the back. [Install the latest firmware](https://support.xgaming.com/support/solutions/articles/12000051593-x-arcade-tri-mode-firmware-update-download-instructions), version 19.4 or later. On macOS, also install the open source [Xbox360 controller](https://github.com/360Controller/360Controller/releases) driver. The Chrome and Edge browsers provide the most reliable mapping. Safari and Firefox have inconsistent results. The X-arcade default mapping is below. For other operating systems, browsers, or older controllers, just use keyboard mode and program the buttons to match the quadplay keyboard controls. ![On Windows, put your X-Arcade in X-input mode 4 and it will automatically provide this mapping.](xarcade-mapping.png style="border:none; image-rendering:auto" width=50%) ![When using an X-Arcade controller in keyboard mode 2, program it like this.](xarcade-keyboard.png style="border:none; image-rendering:auto" width=50%) Other ten-button arcade fightsticks have two common button layouts. The symmetric ECDF layout used by inexpensive Honcam and PXN sticks puts the "shoulder" buttons that correspond to ⓔ and ⓕ on the left and right of the other "face" buttons. The CDEF layout used by more expensive Mayflash, Hori, eTokki, Qanba, and other sticks puts the "shoulder" buttons to the right of the "face" buttons. The appropriate button prompts will appear in quadplay for each one, but you'll have to change which fingers you use to play games depending on the physical layout. ![Symmetric ECDF fightstick layout.
(Example only; this controller has not been tested with quadplay)](symmetric-arcade.jpg width=80% style="image-rendering:auto") ![Asymmetric CDEF fightstick layout.
(Example only; this controller has not been tested with quadplay)](right-arcade.jpg width=80% style="image-rendering:auto") #### Dual D-Pad When `dual_dpad` is enabled (in the game.json file or via the project checkbox), player 1's _physical_ controller right stick can override the the player 2 (`gamepad_array[1]`) _virtual_ controller D-pad. This allows you to make digital twin-stick games that work with both default keyboard controls and a single modern dual-stick controller. ### Analog Sticks Quadplay exposes system features beyond the standard quadplay capabilities using the `device_control("get_analog_axes", ...)` function for low-level system access. You can read analog sticks, steering wheels, foot pedals, flight sticks, etc. directly using this API. Games that use these features will not work on all quadplay devices. But, it is a great way to program for a specific platform that you have in mind or have built. ### Resolution The emulator screen tries to maintain an integer multiple of the native pixel resolution to prevent distortion of pixel art. When running on a very high resolution screen (greater than 2.5x), it relaxes this constraint to use the full screen effectively. As a result, the emulator is pixel-perfect on small displays and fills the screen on large ones. Quadplay supports the following resolutions, all with 4:4:4:4 RGBA color and 60 Hz refresh: - 384x224 (default and recommended) - 320x180 (¼ 720p, ⅙ 1080p, ⅛ 1440p) - 192x112 - 128x128 - 64x64 For reference when importing assets or designing games inspired by previous work, here are the resolutions of classic and retro machines: - 800x480 Raspberry Pi official 7" touchscreen - 640x480 PiBoy DMG - 480x320 Odroid Go Advance - 480x272 PlayStation Portable - 480x270 Hyperlight Drifter - 400x240 Playdate, 2DS, 3DS - 384x224 quadplay✜ - 320x240 "240p", Towerfall - 320x180 Celeste and other Switch pixel art games - 320x200 VGA, including Amiga 500 and Commodore 64 - 280x192 Apple II - 256x240 NES and TurboGrafx-16 - 256x224 SNES - 256x192 Nintendo DS and Sega Master System - 240x160 Game Boy Advance - 240x136 TIC-80 - 160x192 Atari 2600 - 160x144 Game Boy Color and Sega Game Gear - 160x102 Atari Lynx - 128x128 Pico 8 quantize✜ --------------------------------------------------------------------------------------------- [quantize✜](../tools/quantize.html) is a standalone browser tool for converting any image format that your browser can load into a sRGB8 PNG for quadplay✜. While the console emulator can load any PNG file, if you convert them using quantize✜ you will have control over the color reduction process and be able to produce much smaller files for distribution. fontgen✜ --------------------------------------------------------------------------------------------- [fontgen✜](../tools/fontgen.html) is a standalone browser tool for producing rough quadplay✜ font images from fonts installed on your local computer. You can then screen capture these and edit them in your favorite pixel editor to clean them up. fontpack✜ --------------------------------------------------------------------------------------------- [fontpack✜](../tools/fontpack.html) is a standalone browser tool for taking a font PNG file with regular tiles (such as the one produced by fontgen✜) and packing it tightly. It will generate the output PNG and the `.font.json` file for you. scalepix✜ --------------------------------------------------------------------------------------------- [scalepix✜](../tools/scalepix.html) is a standalone browser tool for upscaling a font or sprit PNG file to twice the resolution in each dimension, for upscaling existing assets or importing NES, PICO8, and Game Boy assets. Standard Library ========================================================= Standard library functions are first-class values. They can be stored in data structures and variables. In PyxlScript syntax, a parameter shown with `default` after it, for example: `i default 0` indicates that this is an optional parameter and the value after `default` be used if none is supplied. Explicitly specifying `nil` for any parameter forces its default value. Input ----------------------------------------------------------- ### Gamepads The gamepad objects in the four-element `gamepad_array` each have the following properties: Property | Values | Meaning -------------------|----------|---------------------------------- `index` | 0,1,2,3 | Index of this gamepad in `pad` array `x` | -1,0,+1 | Current D-pad value on the _x_-axis (+1 = right) `xx` | -1,0,+1 | Direction that was just pressed this frame on the _x_-axis `dx` | -2 to +2 | Change in direction this frame on the _x_-axis `y` | -1,0,+1 | Current D-pad value on the _y_-axis (+1 = backward) `yy` | -1,0,+1 | Direction that was just pressed this frame on the _y_-axis `dy` | -2 to +2 | Change in direction this frame on the _y_-axis `xy` | xy | `xy(x, y)` for the gamepad `dxy` | xy | `xy(dx, dy)` for the gamepad `angle` | -π to +π | `rotation_sign() * atan(y, x)` if both are not zero, otherwise the last angle `dangle` | -π to +π | Change in `angle` this frame `a` | 0 or 1 | 1 if the ⓐ button is currently pressed `aa` or `pressed_a`| 0 or 1 | 1 if the ⓐ button was just pressed this frame `released_a` | 0 or 1 | 1 if the ⓐ button was just released this frame `b` | 0 or 1 | 1 if the ⓑ button is currently pressed `bb` or `pressed_b`| 0 or 1 | 1 if the ⓑ button was just pressed this frame `released_b` | 0 or 1 | 1 if the ⓑ button was just released this frame `c` | 0 or 1 | 1 if the ⓒ button is currently pressed `cc` or `pressed_c`| 0 or 1 | 1 if the ⓒ button was just pressed this frame `released_c` | 0 or 1 | 1 if the ⓒ button was just released this frame `d` | 0 or 1 | 1 if the ⓓ button is currently pressed `dd` or `pressed_d`| 0 or 1 | 1 if the ⓓ button was just pressed this frame `released_d` | 0 or 1 | 1 if the ⓓ button was just released this frame `e` | 0 or 1 | 1 if the ⓔ button is currently pressed `ee` or `pressed_e`| 0 or 1 | 1 if the ⓔ button was just pressed this frame `released_e` | 0 or 1 | 1 if the ⓔ button was just released this frame `f` | 0 or 1 | 1 if the ⓕ button is currently pressed `ff` or `pressed_e`| 0 or 1 | 1 if the ⓕ button was just pressed this frame `released_f` | 0 or 1 | 1 if the ⓕ button was just released this frame `q` | 0 or 1 | 1 if the ⓠ button is currently pressed `qq` or `pressed_q`| 0 or 1 | 1 if the ⓠ button was just pressed this frame `released_q` | 0 or 1 | 1 if the ⓠ button was just released this frame `prompt` | `{...}` | An object mapping button names to text prompts (see below) The axes are affected by the current transformation _at the time that they are read by your program_, as set by `set_transform()`. Reading the same property twice with a transform change in between can change the sign of the value. The angles are always clockwise in screen space. `any_button_press(gamepad_or_touch default ∅)` : Returns true if any button on `gamepad_or_touch` was just pressed. If `gamepad_or_touch` is `nil`, returns true if any button on any gamepad was pressed or there was any touch pressed. `any_button_release(gamepad_or_touch default ∅)` : Returns true if any button on `gamepad_or_touch` was just released. This is useful on main menus to ensure that the button is no longer held at the end of the mode. If `gamepad_or_touch` is `nil`, returns true if any button on any gamepad was released or there was any touch released. `joy` : A variable equal to `gamepad_array[0]` as shorthand for single-person games. `gamepad_array[]` : The array of all gamepads. Regardless of how many physical controllers are connected, there are always four elements. ### Button Prompts The `prompt` property of a `gamepad_array[]` value is to be used with `replace()` to create strings for showing controls and button prompts to players with `draw_text()`. It maps `"ⓐ"`, `"ⓑ"`, `"ⓒ"`, `"ⓓ"`, `"ⓔ"`,`"ⓕ"`, `"ⓟ"`, `"ⓠ"`, `"⍐"`, `"⍗"`, `"⍇"`, and `"⍈"` as well as ASCII aliases `"(a)"`, `"(b)"`, `"(c)"`, `"(d)"`, `"(e)"`, `"(f)"`,`"(p)"`, `"(q")`, `"[^]"`, `"[v]"`, `'[<]"`, and `"[>]"` to strings of text. It maps `"##"` to the 1-based player number. These can be used to describe controls to players in a way mapped to the physical controller they are currently using instead of the quadplay✜ native controls For example, `replace("Press (a) to jump", gamepad_array[0].prompt)` creates a string with the proper physical button label for the first player's primary button substituted for the string `"(a)"`. On a PlayStation controller, this string will be `"Press ⓧ to jump"`. On an Xbox controller, it will be `"Press ⓐ to jump"`. For a player using the keyboard, it will be `"Press ␣ to jump"`. The value of `gamepad_array[].prompt` can change during the game if the player uses the system menu to change the control scheme, so you should always generate the string right before drawing it instead of at program start. The `gamepad_array[i].type` property describes the control scheme used for prompts. ### Touch quadplay✜ provides single-touch and single-button mouse input via virtual touch screen. Not all quadplay✜ devices support touch input (although most do, through a touch screen, stylus, or mouse). If there is no mouse, then `touch.a` is always `false`. `touch` : There is a single `touch` global object with the following properties: Property | Type | Meaning -------------------------|----------|---------------------------------- `touch.x` | number | Camera-space x position `touch.y` | number | Camera-space y position `touch.dx` | number | Change in `x` since the previous frame `touch.dy` | number | Change in `y` since the previous frame `touch.xy` | xy | `xy(touch.x, touch.y)` `touch.dxy` | xy | `xy(touch.dx, touch.dy)` `touch.a` | boolean | True if the touch is currently active `touch.pressed_a` | boolean | Was the touch started this frame? `touch.aa` | boolean | Same as `pressed_a` `touch.released_a` | boolean | Was the touch ended this frame? `touch.screen_x` | number | Screen-space x position `touch.screen_y` | number | Screen-space y position `touch.screen_dx` | number | Change in `screen_x` since the previous frame `touch.screen_dy` | number | Change in `screen_y` since the previous frame `touch.screen_xy` | xy | `xy(touch.screen_x, touch.screen_y)` for the touch `touch.screen_dxy` | xy | `xy(touch.screen_dx, touch.screen_dy)` for the touch The `x` and `y` values are in camera-space coordinates using the current transform. Change or reset the transform to read them in a different coordinate system, or use the transformation routines. If there is no active touch, then the coordinates reflect the previous active touch location. There is no way to track a hovering mouse or detect a scroll wheel or second mouse button with `touch`, which would not be mapped to a mobile device anyway. `device_control()` allows low-level access to additional device-specific pointer properties. ### Main Menu The system pause menu is bound to the ⓟ button, which is not visible to games. Games can add up to three custom elements on the pause menu, and can change these at any point. `set_pause_menu(opt1 default ∅, opt2 default ∅, opt3 default ∅)` : Override the custom elements on the pause menu. Each argument is an object of the form `{text:string, callback:function, confirm:boolean}`. At 64x64 resolution, specifying `opt3` disables the automatic game credits option in the pause menu. - `text` is the menu item text. It will be clipped if too long. - `callback` is a function of no arguments to execute when this option is selected. - `confirm` (defaults to `false`) if true, is an additional confirmation dialog appears when this option is selected. If a non-empty string, displays that string as an additional message on the confirmation dialog. Modes ------------------------------------------------------------------------ `get_previous_mode()` : Return the previous mode, or `nil` if there was no previous mode. When returning to a mode via `pop_mode()`, the previous mode is the mode from which _that_ one was entered; they are on a stack. `get_mode()` : Return the current mode. This can be passed to hook functions or compared against mode names, but not to `set_mode`, which requires an explicit mode name. during mode initialization, `get_mode()` returns `nil`. `launch_game(url)` : Load a different game. This is primarily used by the built-in quadplay✜ launcher, but is available to all programs. This may be removed in version 1.0. `pop_mode()` : Go back to the previous mode that invoked `push_mode`, restoring the draw calls and `mode_frames` as of that point. It is a runtime error to invoke `pop_mode()` when the mode was not entered from `push_mode()`. Invokes the `leave` section of the current mode but not the `enter` section of the mode being returned to. `push_mode(Mode, ...)` : Enter a new mode but remember the current mode. Combines their draw calls for `draw_previous_mode()`. Useful for modal dialogs, such as pause screens, inventory screens, and dialogue. Does not invoke the `leave` section of the current mode. Does invoke the `enter` section of the mode being entered. Any arguments after the `Mode` are passed to the `enter` section. `quit_game()` : Quit the game and exit to the IDE or the launcher. Note that games do not form a stack. Quitting a game returns to the built-in quadplay✜ launcher or IDE, and not the game that launched it. `reset_game()` : Reset the game, restoring all assets and starting again from the initial mode. `set_mode(Mode, ...)` : Immediately switch to the new mode. The current mode stops executing and the new mode begins. The mode name must be the literal name of the mode, not a variable, a value from a data structure, or the return value of the function. If the note is present, it must likewise be a string literal and not an expression. The note is a comment that is used by the IDE for creating state machine diagrams and in the IDE for debugging. It has no effect on the executing program. Erases the `push_mode` stack but remembers its draw calls. Any arguments after the `Mode` are passed to the `enter` section. When changing modes via `set_mode()`, the order of operations is: 1. `get_previous_mode()` switches to the current mode, `get_mode()` switches to the _new_ mode. 2. The _previous_ mode's graphics commands are captured for future `draw_previous_mode()` calls. 3. Any `leave` code executes on the _previous_ mode. 4. `mode_frames = 0`, 5. Any `enter` code executes on the _new_ mode and arguments supplied. Types --------------------------------------------------------- `is_array(value)` : Returns true for arrays and false for all other types. `is_boolean(value)` : Returns true for booleans and false for all other types. `is_function(value)` : Returns true for functions and false for all other types. `is_nil(value)` : Returns true for `nil` and false for all other types. `is_NaN(value)` : Returns true for the floating point not-a-number value `NaN` and false for all other values. Note that you cannot test for `NaN` using `==` due to floating point NaN rules. `is_number(value)` : Returns true for numbers and false for all other types. `is_object(value)` : Returns true for objects and false for all other types. `is_string(value)` : Returns true for strings and false for all other types. `type(value)` : Returns the type of the value as a string: `array`, `boolean`, `function`, `nil`, `number`, `object`, or `string`. Array --------------------------------------------------------- `array_value(array, i, extrapolate default (array.extrapolate or "clamp"))` : Applies `floor()` to `i` and then applies the extrapolation mode, which defaults to the extrapolation mode of the array itself if specified. Intended primarily for animation of values, including the named arrays of spritesheets, for example, `sprite = array_value(spritesheet[animName], frame)`. See also `make_spline()` and the Sprite JSON section. The `extrapolate` values accepted are: - `"oscillate"` - `"loop"` - `"clamp"` (default, other unsupported values are silentely treated as clamp instead of failing) `clone(array)` : Return a shallow clone of `array`. Pointer structures are preserved and loops are OK. Built-in objects such as spritesheets and functions are not cloned. `deep_clone(array)` : Return a deep clone of `array`. Pointer structures are preserved and loops are OK. Built-in objects such as spritesheets and functions are not cloned. `extended(array1, array2)` : Create a new array that contains all elements of `array1` followed by all elements of `array2`. Identical to `[...array1, ...array2]`. See also `extend()`. `equivalent(a, b)` : Returns true if these arrays have the same length and the elements are `==` (does not recursively test if the elements are equivalent). `extend(array1, array2)` : Mutate `array1` by pushing all elements of `array2` onto it. Identical to `push(array1, ...array2)`. See also `extended()`. `fast_remove_key(array, i)` : Delete element `i` from the array, swapping it with the last element. O(1) expected amortized time. `fast_remove_value(array, v)` : Delete one element that is `== v`, or do nothing if there is no such element. May reorder the array and may choose any such element, not necessarily the first. See also `remove_values()`. `find(array, x, i default 0)` : Find the index of the element whose value is `x`, starting at optional index `i` (default 0). Returns `∅` if not found. Uses `==` to compare `x` to array values. Runs in linear time in the length of the list from `i`. `insert(array, i, x,...)` : Inserts the values into the array, starting at index `i` (as in, `array[i] = x` on return) and returns the first value inserted. Similar to Python insert and JavaScript splice functions. `iterate(array, callback)` : Iterates through array in order using a callback function, with optional O(1) order-preserving removal. This is an imperative version of map(), filter(), and list comprehension primitives from other languages. If `callback` is a string, iterate then calls `array[i][callback](array[i])` on each element. If `callback` is a function, it instead calls `callback(array[i])` on each element. Return values from the called function have the following effects: - `iterate.REMOVE`: remove the current value and continue iterating - `iterate.BREAK`: immediately stop iterating - `iterate.REMOVE_AND_BREAK`: remove the current element and then stop processing - `iterate.CONTINUE`: continue with iteration. This is not required; as long as the previous values are not returned by the callback, the iterator will still continue It is illegal for the callback to modify the array itself during iteration. `join(array, separator default "", lastSeparator default separator, pairSeparator default lastSeparator, empty default "")` : Joins the elements of the array into a string. Each element converted to a string with `unparse()` if it is not already a string. The optional `lastSeparator` allows the final join to use a special case. The optional `pairSeparator` is a special separator used for arrays of length two. For example `join(inventory, ", ", ", and ", " and ", "nothing")`. The optional `empty` value is used if the array has length 0. `last_key(array)` : Returns `size(array) - 1`, the last key (that is, index). `last_value(array)` : Returns `array[last_key(array)]`. `pop(array)` : Remove the last element from the array and return it, or `∅` if the array is empty. O(1) expected amortized time. `pop_front(array)` : Remove the first element from the array and return it, or `∅` if the array is empty. O(n) expected amortized time. `push(array, x, ...)` : Append `x` and any other arguments to the array and then return the last. O(1) expected amortized time for a single argument and O(n) for n arguments. `push_front(array, x, ...)` : Insert `x` and any other arguments onto the array, preserving the order that they appear in the arguments and then return the first. O(n) expected amortized time for a single argument and O(m) for m arguments and array of length n. `remove_key(array, i)` : Remove element `i` from the array, preserving order. O(n) expected time. `remove_values(array, x)` : Remove every instance of `x` in the array, maintaining order. O(n) time in the original length of the array. Does nothing if `x` is not in the array. See also `fast_remove_value()` `remove_all(array)` : Remove everything from the array. Same as `resize(array, 0)`. `resize(array, n)` : Change the length of the array. O(size(array) + n) time if growing, O(1) if shrinking. `reverse(array)` : Reverses the array in place, O(size(array)). Returns nothing to avoid confusion with `reversed()`. `reversed(array)` : Returns a shallow, reversed clone of the array, O(size(array)) `random_value(array, random default random)` : Return a random element of the array. `shuffle(array, random default random)` : Randomizes the array in place using using Knuth-Fisher-Yates in O(n) time. Returns nothing to avoid confusion with `shuffled()`. `shuffled(array, random default random)` : Returns a shallow, shuffled clone of the array, O(size(array)) `size(array)` : Get the length of the array. O(1) time. `slice(array, s, e default size(array))` : Return the subarray of `array` between `s` (inclusive) and optional `e` (exclusive, defaults to length). `sort(array, k, reverse default false)` : Sort the array from least to greatest. If `k` is a string, then elements of the array are assumed to be objects and are sorted by that key. If `k` is a number, then elements of the array are assumed to be other arrays or strings and are sorted by that index. If `k` is not specified and the array contains objects, then elements are sorted by their alphabetically-first key. If `k` is a function, then it must be a function of the form `compare(a, b)` that returns a positive number if `a` is greater than `b`, a negative number if `b` is greater than `a`, and zero if they are equal. If `k` is not specified and the array contains numbers or strings, then they are sorted by natural order. If `reverse` is true, then the array is sorted in reverse order from greatest to least. String --------------------------------------------------------- `array_value(string, i, extrapolate default (string.extrapolate or "clamp"))` : Applies `floor()` to `i` and then applies the extrapolation mode, which defaults to the extrapolation mode of the array itself if specified. The `extrapolate` values accepted are: - `"oscillate"` - `"loop"` - `"clamp"` (default, other unsupported values are silentely treated as clamp instead of failing) `ends_with(string, target)` : Returns true if `string` ends with the substring `target`. `extended(a, b)` : Returns a new string that is `a + b`. `find(string, x, i default 0)` : Find the index of the substring whose value is `x`, starting at optional index `i` (default 0). Returns `∅` if not found. O(n) time. `format_number(n, fmt)` : Produces a string from number `n` in one of the following formats. Input times are in seconds. Each is followed by an example output. - `"percent"`: 30% - `"commas"` (comma thousand separators): 1,000,000 - `"spaces"` (space thousand separators): 1 000 000 - `"binary"`: 0b10100001 - `"degrees"`: 57° - `"hex"`: 0xa1 - `"scientific"`: 6.022×10²³ - `"clock12"`: 5:35pm - `"clock24"`: 17:35 - `"stopwatch"`: 1:38.71 - `"oldstopwatch"`: 1"38'71 - `"ordinal"`: second - `"ordinalabbrev"`: 2ⁿᵈ - `".00"` (or any other trailing zero sequence): 4.91 - `"00"` (or any other leading zero sequence): 07 - `" 0"` (or any other leading space sequence followed by a zero sequence): " 7" `last_key(string)` : Returns `size(string) - 1`. `last_value(string)` : Returns `string[last_key(string)]`. `lowercase(s)` : Returns the lower case version of the string. `parse(s)` : Parse a string that was encoded using `unparse()` and convert it back into the original data structure. Functions, built-ins, and recursive arrays cannot be converted. `replace(string, src, dst)` : Replace all occurances of `src` in `string` with `dst`. `replace(string, object)` : Replace all occurances of each key of `object` with each `value` of object in `string` simultaneously. For example, `replace("Hey, PROPER_NOUN, use the ADJ NOUN!", {ADJ: "big", NOUN: "stick", PROPER_NOUN: "Runi"})`. `reversed(string)` : Returns a reversed version of the string in O(size) time. `shuffled(string)` : Returns a shuffled version of the string in O(size) time. `size(s)` : Get the length of the string. O(1) time. `slice(string, s, e default size(str))` : Return the substring of `string` between `s` (inclusive) and optional `e` (exclusive, defaults to length). `split(string, separator default "")` : Returns an array of strings separated by `separator`. If the separator is the empty string, then all characters are separated. `starts_with(string, target)` : Returns true if `string` begins with the substring `target`. See also `ends_with()`. `unparse(x)` : Returns code that is equivalent to producing data object `x`, if it is not a recursive object or array or a function. Note that strings will have quotes around them in the resulting string. `uppercase(s)` : Returns the upper case version of the string. Object --------------------------------------------------------- `clone(object)` : Return a shallow clone of `object`. Pointer structures are preserved and loops are OK. Built-in objects such as spritesheets and functions are not cloned. `deep_clone(object)` : Return a deep clone of `object`. Pointer structures are preserved and loops are OK. Built-in objects such as spritesheets and functions are not cloned. `extended(object1, object2)` : Create a new object that is the union of `object1` and `object2`, where `object2` keys override in the case of collisions. See also `extend()`. `extend(object1, object2)` : Mutate `object1` by assigning all elements of `object2` into it, overriding any existing keys in the case of collisions. See also `extended()`. `fast_remove_key(object, k)` : Same as `remove_key` for a object. `fast_remove_value(object, value)` : Delete one element that is `== v`, or do nothing if there is no such element. See also `remove_values()`. `find(object, x)` : Find a key for which the value is `x`. Returns `∅` if not found. Uses `==` to compare `x` to array values. O(n) time in the number of key-value pairs. `keys(object)` : An array of the keys in the object. You almost never need this because `for k in object` iterates over the keys directly. `remove_key(object, k)` : Remove a key-value pair by key. Does nothing if `k` is not in the object. Use `object[k] ≠ ∅` to test for containment explicitly. `remove_values(object, v)` : Remove every instance of `v` from the object. See also `fast_remove_value()`. `remove_all(object)` : Remove everything from the object. It is faster to assign to a new, empty object than to use this function. `remove_all()` is for when it is important to retain a pointer to the original object because it is shared. `size(object)` : The number of entries in the object. `values(object)` : An array of the values in the object. Random Values --------------------------------------------------------- ### 1D `make_random(seed default local_time().millisecond)` : Returns a new _function_ that acts like `random()` but has its own private seed and internal state. See also `set_random_seed()`. `random()` : `random(0, 1)`. Same as the `ξ` operator. `random(lo, hi)` : Random real number between `lo` and `hi`, excluding `hi`. See also the `ξ` operator, the no-argument version of `random()`. `random_gaussian()` : Same as `random_gaussian(0, 1, random)` `random_gaussian(mean, stddev, random default random)` : Returns a Gaussian distributed random number on the distribution with the given mean and standard deviation. See also `random_truncated_gaussian()`. `random_integer(hi)` : Uniformly distributed random integer between 0 and hi, inclusive. This version is deprecated. Use `random_integer(0, hi)` instead. `random_integer(lo, hi, random default random)` : Random integer between `lo` and `hi`, including both ends. The `random` argument defaults to common random number generator `random()`, but an alternative function previously created by `make_random()` can be passed instead. `random_sign(random default random)` : Returns +1 or -1 with equal probability. `random_truncated_gaussian(mean, stddev, radius default (2 * stddev), random default random)` : Returns a Gaussian distributed random number within `radius` of the mean. The default radius corresponds to about 96% of the total probability of the distribution and avoids very long tails. See also `random_gaussian()`. `set_random_seed(seed default local_time().millisecond)` : Reset the default random number generator, `random()`, using an optional seed. To match the default random number generator, use a seed of `0`. See also `make_random()`. ### 2D `random_direction2D(random default random)` : Same as `random_on_circle()` `random_gaussian2D()` : Same as `random_gaussian2D(xy(0, 0), xy(1, 1), random)`. `random_gaussian2D(mean, stddev, random default random)` : Returns a Gaussian distributed random point on the distribution with the given mean and standard deviation. The mean and standard deviation may each be scalar or `xy()` values. See also `random_gaussian()`, `random_truncated_gaussian2D()`. `random_on_circle(random default random)` : Returns a uniformly distributed `xy()` on the perimeter of the circle with center `(0, 0)` with radius 1. Useful for random directions. `random_on_square(random default random)` : Uniformly distributed `xy()` on the _perimeter_ of a square from `(-1, -1)` to `(1, 1)`. `random_within_circle(random default random)` : Returns a uniformly distributed `xy()` in the disk with center `(0, 0)` with radius 1. Useful for random offsets within a circle. See also `random_on_circle()` `random_within_square(random default random)` : Returns a uniformly distributed `xy()` in the square from `(-1, -1)` to `(1, 1)`, that is, the square that has a "radius" of 1 or sides of length two, and is centered at the origin `(0, 0)`. Analogous to `randomDisk()`. `random_truncated_gaussian2D(mean, stddev, radius, random default random)` : Returns a Gaussian distributed random point within `radius` of `mean`. The `mean` and `stddev` may be scalars or `xy()`s. If `radius` is a number, the truncation region is a disk. If `radius` is an `xy()`, then the truncation region is an ellipse that has those radii along each axis. See also `random_gaussian2D()`. ### 3D `random_direction3D(random default random)` : Same as `random_on_sphere()`. `random_gaussian3D()` : Same as `random_gaussian3D(xy(0, 0), xy(1, 1), random)`. `random_gaussian3D(mean, stddev, random = random)` : Returns a Gaussian distributed random point on the distribution with the given mean and standard deviation. The mean and standard deviation may each be scalar or `xyz()` values. See also `random_gaussian()`, `random_truncated_gaussian3D()`. `random_on_cube(random = random)` : A random point on the _surface_ of the cube from `(-1, -1, -1)` to `(1, 1, 1)`. `random_on_sphere(random = random)` : Returns a uniformly distributed `xyz()` on the [hollow] sphere with center `(0, 0, 0)` with radius 1. Useful for random directions in 3D. See also `random_within_sphere()` and `random_on_circle()`. `random_within_cube(random = random)` : A random point inside the cube from `(-1, -1, -1)` to `(1, 1, 1)`. `random_within_sphere(random = random)` : Returns a uniformly distributed `xyz()` within the unit sphere, that is, the ball with center `(0, 0, 0)` and radius 1. Useful for random offsets within a sphere. See also `random_on_sphere()`. `random_truncated_gaussian3D(mean, stddev, radius, random = random)` : Returns a Gaussian distributed random point within `radius` of `mean`. The `mean` and `stddev` may be scalars or `xyz()`s. If `radius` is a number, the truncation region is a disk. If `radius` is an `xyz()`, then the truncation region is an ellipsoid that has those radii along each axis. See also `random_gaussian3D()`. Vector --------------------------------------------------------- Most of the math functions and operators defined for numbers also operate component-wise on vectors represented as structures or arrays. For example, `clamp()`, `min()`, `loop()`, `+`, `/`, etc. The following vector operations can be applied to any array or object, including `xy()` and `rgb()` values, except where specific key names are mentioned: `atan(vec2)` : Returns `atan(vec2.y, vec2.x)`. `cross(a, b)` : Return the vector cross product of two arrays of length three each or two vectors with `x`, `y`, and `z` fields. For arguments of length two or without a `z` component, returns `a.x * b.y - a.y * b.x`, which is the 2D wedge product. `direction(v)` : `v / magnitude(v)` if the magnitude is greater than 10-10, otherwise returns the original (nearly zero) vector. That is, returns a normalized or unit vector unless the input is close to zero. `dot(a, b)` : Return the dot (inner) product of any two structures or arrays with parallel elements. `equivalent(a, b)` : Returns true if these vectors have the same size and the elements are `==` (does not recursively test if the elements are equivalent). `magnitude(v)` : The square root of the sum of the elements (L2 norm). `magnitude_squared(v)` : The sum of squares of the elements. `max_component(v)` : Largest element. `min_component(v)` : Smallest element. `perp(v)` : Returns a vector perpendicular to `v` by rotating it 90 degrees: `xy(-v.y, v.x)`, for `xy()` and 2-element array vectors only. `xy(x, y)` : Create the object with `x` and `y` properties. `xy(xy)` : Returns `{x:xy.x, y:xy.y}`. Useful for removing the `z` component or cloning. See also `xy_to_xz()`. `xy(array)` : Returns `{x:array[0], y:array[1]}`. Useful for converting from a matrix column. `xy_to_xz(xy)` : Returns `{x:xy.x, z:xy.y}`. See also `xz_to_xy()`. `xz_to_xyz(v, new_z default 0)` : Returns `{x:v.x, y:v.z, z:new_z}`. `xz(x, z)` : Create the object with `x` and `z` fields. `xz(xz)` : Returns `{x:xz.x, z:xz.z}`. Useful for removing the `y` property or cloning. `xz(array)` : Returns `{x:array[0], z:array[1]}`. Useful for converting from a matrix column. `xz_to_xy(xz)` : Returns `{x:xz.x, y:xz.z}`. See also `xy_to_xz()`. `xz_to_xyz(xz, new_z default 0)` : Returns `{x:xz.x, y:xz, z:new_z}`. See also `xz_to_xy()`. `xyz(x, y, z)` : Create the object with `x`, `y`, and `z` fields. `xyz(xy, z default 0)` : Creates `{x: xy.x, xy:y, z}` `xyz(xz, y default 0)` : Creates `{x: xz.x, y:y, z:xz.z}`. See also `xz_to_xyz()` `xyz(xyz)` : Clones the `xyz` value, stripping any other properties `xyz(array)` : Returns `{x:array[0], y:array[1], z:array[2]}`. Useful for converting from a matrix column. `xyz_to_rgb(v)` : Returns `{r: v.x, g: v.y, b: v.z}`. This does _not_ convert between the XYZ and sRGB color spaces. Function --------------------------------------------------------- `call(f, a, b, ...)` : Invoke function `f` with arguments `a`, `b`, etc. Math --------------------------------------------------------- `abs(x)` : Absolute value `acos(x)` : Inverse cosine in radians `atan(y, x)` : Arctangent of y/x, in radians. See also the version that operates on an `xy()`. `asin(x)` : Inverse sine in radians `cbrt(x)` : Cube root of `x`. Has the same sign as the argument. `ceil(x)` : Return the nearest integer value of `x` towards positive infinity. `ceil(x, u)` : Ceil to the nearest multiple of `u` using `ceil(x / u) * u`. `clamp(x, lo, hi)` : Clamp `x` to the range [`lo`, `hi`] inclusive. `clone(v)` : Return a shallow clone of `v`. For built-in objects and functions returns the original object, because they are immutable. For map assets, automatically deep clones the 3D layer array/2D XY array. `copy(s, d)` : Copy the properties of `s` onto `d`. Both must be arrays or objects. `cos(x)` : Cosine, `x` in radians `deep_clone(v)` : Return a deep clone of `v`. Pointer structures are preserved (two pointers to the same object will be cloned as identical pointers to a different object) and cycles are supported. Functions cannot be cloned. Assets and constants can be cloned. `floor(x)` : Return the nearest integer value of `x` towards negative infinity. `floor(x, u)` : Floor to the nearest multiple of `u` using `floor(x / u) * u`. `hash(x, y)` : A hash value of string or number `x`, returning a value on [0, 1]. If `y` is specified, the hash considers the union of the values. `lerp(a, b, t)` : Returns `a + (b - a) * t`. See also `smoothstep()` and `smootherstep()`. See also `perceptual_lerp_color()`. `lerp(a, b, t, t_min, t_max)` : Returns `a + (b - a) * ((t - t_min) / (t_max - t_min))`. `lerp_angle(a, b, t)` : Linear interpolation between angles `a` and `b` by `t`, taking wrapping into account and always going the short way. Returns a value between `-pi` and `+pi`. `log(x)` : Natural logarithm (base _e_) of `x`, _ln x_ in math notation. `log2(x)` : Logarithm base 2 `x`, _lg x_ in math notation. `log10(x)` : Logarithm base 10 `x`, _log x_ in math notation. `loop(x, lo, hi)` : Handy for making values wrap around. Real-number relative floored modulus. Wraps `x` to the range [`lo`, `hi`). See also `oscillate()` `loop(x, hi)` : Handy for making values wrap around. Real-number floored modulus. Wraps `x` to the range [0, `hi`). `hi` defaults to `1.0` if not specified. See also `oscillate()` `magnitude(x, y, ...)` : The square root of the sum of the arguments, which must all be numbers. Same as `magnitude([x, y, ...])`. `magnitude_squared(x, y, ...)` : The sum of the squares of the arguments, which must all be numbers. Same as `magnitude_squared([x, y, ...])`. `make_spline(time_array, value_array, order = 3, extrapolate = "stall")` : Returns a function mapping numbers to values by piecewise polynomial interpolation. The value array must have types for which `*` and `+` operate (which includes numbers, all objects, `xy()`, `xyz()`, `rgb()`, and `rgba()` values), and all elements of the `value_array` must have the same type. The spline is always interpolating. The `time_array` and `valueArray` must have the same length. `order`: - `0` = nearest-neighbor interpolation - `1` = linear (polyline) interpolation - `3` = cubic (Catmull-Rom) spline interpolation `extrapolate`: - `"loop"` = cyclic. The `time_array` must have one more element than the `value_array`. That final value is the looped time that matches the start time. Similar to OpenGL `GL_REPEAT` mode for textures. - `"clamp"` = hold the final value. Similar to OpenGL `GL_CLAMP` texture mode. - `"stall"` = interpolate to additional control points that match the final value. Unlike clamping, for a cubic curve this will ensure that the velocity smoothly ramps to zero rather than creating a sharp corner. - `"oscillate"` = treat like looping with twice the period, reversing direction. This is similar to OpenGL `GL_MIRROR` texture mode. - `"continue"` = continue the curve with the trend of the final control points `max(a, b, ...)` : Largest of the arguments `min(a, b, ...)` : Smallest of the arguments `mid(a, b, c)` : Middle argument once sorted. Can be used for clamping. `noise(octaves, v)` : Applies `noise()` to an `xy()`, `xyz()`, or array position. `noise(octaves, x, y default 0, z default 0)` : Value noise on the range [-1, 1], bicubically interpolated between integer locations at octave 0. Unused dimensions default to zero. `oscillate(x, m)` : Deprecated. `oscillate(x, 0, m)`. `oscillate(x)` : `oscillate(x, 0, 1)` `oscillate(x, lo, hi)` : Like `loop` but alternately counts up and down on the interval [`lo`, `hi`], including both ends. Works with negative and fractional values. Let `k = 2 m - 2; w = loop(x, k)`. `oscillate(x, m)` is `w` if `w < m`, otherwise it is `k - w`. `pow(a, b)` : Exponent. See also the `^` operator. `round(x)` : Return the nearest integer value of `x`. Half-integers round towards positive infinity. `round(x, u)` : Return the nearest value of `x` quantized to `u`: `round(x, u) == round(x * u) / u`. `sign(x)` : Sign of `x`. Returns -1 if `x` is less than zero, -0 if `x` is -0, +0 if `x` is +0, and +1 if `x` is greater than zero. `sign_nonzero(x)` : Returns -1 if `x` is less than zero, otherwise returns +1. `smoothstep(t_start, t_end, t)` : Transition from 0 at `t = t_start` to 1 at `t = t_end`. All arguments must be numbers. Typically used as `lerp(A, B, smoothstep(lo, hi, t))` where `A` and `B` are colors or points. This is a common graphics function for cubic Hermite interpolation. See also the [GLSL documentation](https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/smoothstep.xhtml). `smootherstep(t_start, t_end, t)` : Transition from 0 at `t = t_start` to 1 at `t = t_end` with more gradual acceleration than `smoothstep`. All arguments must be numbers. Typically used as `lerp(A, B, smootherstep(lo, hi, t))` where `A` and `B` are colors or points. This is a common graphics function for fifth-order interpolation. `sqrt(x)` : Square root. `sin(x)` : Sine of `x` radians. `tan(x)` : Tangent of `x` radians. `x` | -5 | -4 | -3 | -2 | -1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 ------------------|-----:|-----:|-----:|-----:|-----:|----:|----:|----:|----:|----:|----:|-----: `clamp(x, 0, 4-1)`| 0 | 0 | 0 | 0 | 0 | 0 | 1 | 2 | 3 | 3 | 3 | 3 `x mod 4` | -1 | 0 | -3 | -2 | -1 | 0 | 1 | 2 | 3 | 0 | 1 | 2 `loop(x, 4)` | 3 | 0 | 1 | 2 | 3 | 0 | 1 | 2 | 3 | 0 | 1 | 2 `oscillate(x, 4)` | 1 | 2 | 3 | 2 | 1 | 0 | 1 | 2 | 3 | 2 | 1 | 0 [Table [tblCompare]: Comparison of range restriction functions useful for animation.] Sound --------------------------------------------------------- `get_audio_status(audio)` : Returns an object describing the current properties of this audio object. The `state` property will have the value `"PLAYING"`, `"STOPPED"`, or `"ENDED"` `play_sound(args)` : Object version of `play_sound()`, allowing keyword argument style call. Values default according to the positional argument version. `play_sound(sound, loop default false, volume default 100%, pan default 0%, pitch default 100%, time default 0)` : Play `sound`, which must have been loaded as an asset. The time is in seconds. Full pan left is `-100%` and full pan right is `100%`. Returns an audio object that can be used with `stop_audio()`. If `pan` is an `xy()` value, it is interpreted as a world space point and the pan is computed based on the fraction of the screen under the current transformation and camera. `resume_audio(audio)` : Resume a sound previously stopped with `stop_audio()`. Sets the state to `"PLAYING"`. `set_pan(audio, pan)` : Set the pan of an audio object that is currently playing. 0% is centered. -100% is full left, 100% is full right. `set_pitch(audio, pitch)` : Set the pitch of an audio object that is currently playing. 100% is the default pitch from the file. 200% is one octave higher, 50% is one octave lower. `set_volume(audio, volume)` : Set the volume of an audio object that is currently playing. 100% is the default volume from the file. `stop_audio(audio)` : Stop playing `audio`, which was created with `play_sound`. Sets the state to `"STOPPED"`. `stop_audio(nil)` : Does nothing. This is provided because it is often convenient to stop background sound if there is one on entering a mode and do nothing if there is no background sound value in a variable, e.g., `stop_audio(background_audio)` Coordinates ----------------------------------------------------------- The quadplay default *screen space* coordinate system is: ************************************************************ * 2048 (out of the screen) * ^ * \ z * \ * \0 x * *----------------------->* SCREEN_SIZE.x * |\ | * | \ | * | \ | * y | v | * | -2047 | * v | * *------------------------* * SCREEN_SIZE.y *********************************************************** [Figure [coords]: Screen space coordinate system.] Almost all standard library functions take arguments in world space. This includes drawing routines, intersection routines, and the properties of entities without parents. The functions that don't use screen space are obvious, since what they do requires another space. If you use default values of the camera, transform, and `y_up`, and do not use child entities, then world space and camera space match the screen space coordinate system and you can ignore the rest of this section. Advanced users can leverage the full set of coordinate systems for the standard library, which are: - *screen* space (ss) - *world* space (ws) - *camera* space (cs) - *entity* space (es) - *sprite* space - pixels within in a sprite - *map* space - indices of sprites in a map Entities can also form hierarchies using the `entity.child_array`. The first four coordinate systems are related by:
Screen Space (ss) _Used by_: `set_clip()`, `reset_clip()`, `get_clip()`, `intersect_clip()`, `set_post_effects()`, `get_post_effects()`
`transform_cs_to_ss()`







`transform_ss_to_cs()` _Controlled by_: `y_up` in game.json, `set_transform()`, `reset_transform()`, `compose_transform()`, `get_transform()`
Camera Space (cs) _Used by_: `touch`, `joy`, `gamepad_array[]`, `text_width()`
`transform_ws_to_cs()`







`transform_cs_to_ws()` _Controlled by_: `set_camera()`, `reset_camera()`, `get_camera()`
World Space (ws) _Used by_: `draw_sprite()`, `draw_line()`, `draw_map()`, `draw_entity()`, `draw_text()`, `draw_point()`, `ray_intersect()`, `overlaps()`, etc.
`transform_es_to_ws()`







`transform_ws_to_es()` _Controlled by_: `entity.pos`, `entity.angle`, `entity.scale`
Entity Space (es)
`transform_to_parent()`







`transform_to_child()` `entity.pos_in_parent`, `entity.angle_in_parent`, `entity.scale_in_parent`
Child Entity Space



To simplify common game programming tasks and avoid certain kinds of mistakes, quadplay has some differences from traditional graphics systems under coordinate system transformations: - Angles are always measured counter-clockwise, and routines automatically change their angle direction to compensate. Use `rotation_sign()` to determine the current direction when using `sin()` and `cos()` to convert an angle to a vector. - Sprites automatically flip vertically to match when the y axis is inverted. - The anchor points for text will transform, but font characters are never rendered with scale or rotation because pixel fonts are generally unreadable if transformed and upside-down fonts are rarely what is intended when flipping an axis. Convert your text to a sprite if you want transformed text as an effect, or use a set of fonts available at different sizes (such as deja) if you want text at different sizes to correspond to zooming. - `touch`, `gamepad_array[]`, and `joy` `xy` values match the current screen-to-camera space transformation from `set_transform` at the time that they are read. This is mostly so that controls and event coordinates will match drawing coordinates when the axis is flipped or the screen origin changed. - Every `entity` contains both a transformation to its parent (`entity.pos_in_parent`, `entity.angle_in_parent`, `entity.scale_in_parent`, `entity.z_in_parent`) and a transformation directly to world space (`entity.pos`, `entity.angle`, `entity.scale`, `entity.z`). Storing the direct transformation improves performance and simplifies many common operations. `entity_update_children(root)` recursively updates the direct transformation for an entire hierarchy. In general, `set_transform()` is good for tasks such as, "I'm making the user interface and want Y=down and 0 at top left" or "I'm drawing the world and want Y=up and the origin in the center". It cannot rotate the viewpoint. `set_camera()` is for shifting the viewpoint in 2.5D within the world coordinate system. It cannot flip axes (it only allows positive, uniform zoom), but it can rotate, translate, and zoom. Use it to show different views of the same scene, follow a character, or render a minimap. Common situations are: - No camera or transform. Use `y_up` in the game.json file if you want the y axis to go up - Move (0, 0) to the center of the screen: `set_transform(SCREEN_SIZE / 2)` - Center on the player entity, without rotation: `set_transform(SCREEN_SIZE / 2); set_camera(pos:player_entity.pos})` - Center on the player and rotate the y-axis to match (good for sprites drawn facing up): `set_transform(SCREEN_SIZE / 2); set_camera(player_entity)` - Center on the player and rotate the x-axis to the y-axis (good if you want `player.angle=0` to be the x-axis) `set_transform(SCREEN_SIZE / 2); set_camera({pos:player_entity, angle:player.angle - 90deg})` The coordinate systems are defined by transformations _from_ a coordinate system to its parent always being applied in the order of scale, rotation (`angle`), translation (`pos`). That is, objects scale along their own axes and rotate about their own origin. The transformation routines are: `transform_cs_to_ss(cs_point, cs_z default 0)` : Transform `cs_point` at `cs_z` from camera space to screen space. The `cs_z` is needed only if a skew transformation is active. `transform_cs_z_to_ss_z(cs_z)` : Transform camera space `cs_z` to a screen space z value. `transform_ss_to_cs(ss_point, ss_z default 0)` : Transform `ss_point` from screen space to camera space. `transform_ss_z_to_cs_z(cs_z)` : Transform screen space `ss_z` to a camera space z value. If the current transform has a zero z-scale then the result will be positive infinity, negative infinity, or zero because the transformation is not invertible in that case. `transform_ss_to_ws(ss_point, ss_z default 0)` : Transform `ss_point` from screen space through camera space to world space. `transform_ws_to_ss(ws_point, ws_z default 0)` : Transform `ws_point` from world space through camera space to screen space. `transform_ws_to_cs(ws_point, ws_z default 0)` : Transform world space `ws_point` to camera space. There is no transformation function for `cs_z` value because you can transform it yourself `cs_z = ws_z - get_camera().z`. `transform_cs_to_ws(cs_point, cs_z default 0)` : Transform camera space `cs_point` to world space. There is no transformation function for `cs_z` because you can transform it yourself as `ws_z = cs_z + get_camera().z`. `transform_ws_to_es(entity, ws_point)` : Transform world space point `ws_point` into the entity space of `entity`, wherever it is in the hierarchy. There is no transformation function for `ws_z` because you can transform it yourself as `es_z = ws_z - entity.z`. `transform_es_to_ws(entity, es_point)` : Transform entity space point `es_point` into world space, wherever the entity is in the hierarchy. There is no transformation function for `es_z` because you can transform it yourself as `ws_z = es_z + entity.z`. `transform_to_parent(child, child_point)` : Takes a coordinate `child_point` in the `child` entity reference frame and transforms it to the `child.parent` entity reference frame. `transform_to_child(child, parent_point)` : Takes a coordinate `parent_point` in the `child.parent` entity reference frame and transforms it to the `child` entity reference frame. `transform_es_to_es(entity_from, entity_to, es_from_point)` : Transform the `es_from_point` in the reference frame of `entity_from` to the reference frame of `entity_to`. There is no transformation function for `z` values because you can transform it yourself as `z += entity_from.z - entity_to.z`. `transform_es_to_sprite_space(entity, es_point)` : Transform `es_point` in the reference frame of `entity` into the pixel coordinates of the current `entity.sprite`. `transform_sprite_space_to_es(entity, sprite_point)` : Transform `sprite_point` in the pixel coordinates of the current `entity.sprite` into the reference frame of the entity. `transform_to(pos, angle, scale, point)` : Transform `point` into the reference frame defined by `pos`, `angle`, and `scale`. `transform_from(pos, angle, scale, point)` : Transform `point` from the reference frame defined by `pos`, `angle`, and `scale`. ### Screen Space Note that `preserving_transform` also preserves the clipping rectangle. `compose_transform(args)` : Named argument version of `compose_transform()`. `compose_transform(pos default ∅, dir default ∅, z default ∅, zDir default ∅, skew default ∅)` : Apply this local transformation _before_ the current one. Used for entering a child coordinate system. Nil arguments or properties default to `(xy(0, 0), xy(1, 1), 0, 1, xy(0, 0))`. Use `preserving_transform` or `get_transform()` plus `set_transform()` to save and restore nested coordinate systems. `get_transform()` : Returns the current net transformation as an `args` object that could be passed to `set_transform(args)`. `preserving_transform:` : The special `preserving_transform:` block saves the current transform, camera, and clipping region, executes the code in the body, and then restores the previous transform and clipping region when the block is exited (including abruptly by `return`, `continue`, or `break`). It is useful for making modular functions for handling UI scrolling, minimaps, and screenshake. `rotation_sign()` : Returns -1 if `(t.dir.x * t.dir.y > 0)` for `t = get_transform()` and +1 if `(t.dir.x * t.dir.y < 0)`. Useful for computing the coordinate transform of an entity angle. Angles are always measured counter-clockwise on *screen*. In the *draw coordinate system*, they rotate counter-clockwise if `rotation_sign() = 1` and clockwise if `rotation_sign() = -1` (which is the default). This is used by `draw_sprite()` to determine the rotation direction. See also `up_y()`. `reset_transform()` : Reset to the default transformation, `set_transform(xy(0, 0), xy(1, 1), 0, 1, xy(0, 0))`. This overrides the `y_up` flag from the .game.json file. `set_transform(args)` : Named argument object version of `set_transform()`. `set_transform(pos default ∅, dir default ∅, z default ∅, z_dir default ∅, skew default ∅)` : Set the transformation applied to all camera coordinates to compute screen coordinates. Nil values or nil properties default to their previous value. The equation applied when mapping from camera space (cs) to screen space (ss) is: - `ss.x = (cs.x + skew.x * cs.z) * dir.x + pos.x`; - `ss.y = (cs.y + skew.y * cs.z) * dir.y + pos.y`; - `ss.z = cs.z * z_dir + z`. The `dir` parameters must be +1 or -1, for flipping axes. This affects the location of sprites and text but not their own axes; text will always render right side up and sprites must be independently flipped. By default, increasing z is towards the viewer, a negative direction can be used to make increasing values farther back. The skew transform applies after direction flipping and can be used for isometric 3D. up_y() : Returns `-sign(get_transform().dir.y)`, which is -1 if Y increases downwards (the default) and +1 if Y increases upwards (`"y_up": true` in the .game.json file). The clipping region is the only object interacted with in *screen space*, via `set_clip()`, `get_clip()`, and `intersect_clip()`. The screen space graphics coordinate system is: - x increasing from 0 at the left edge of the screen to `SCREEN_SIZE.x` at the right edge - y increasing from 0 at the top edge of the screen to `SCREEN_SIZE.y` at the bottom edge - z increasing from -2047 at the back to 2048 at the front Integer coordinates correspond to the top-left corner of a pixel. Pixel centers are at integers plus ½. The top-left pixel center is (½, ½). Drawing commands sample at pixel centers. The pixel ownership rules are bottom and right, so a primitive that has a top or left boundary exactly on a pixel center will not color that pixel. This is important for adjacent primitives to keep them from double-covering a pixel on the boundary. When thinking of the screen as a 2D array of discrete pixel elements, the snapping rule is essentially that a 1-pixel rectangle centered at `pos` colors pixel `⌊pos⌋`. For example, the rectangle from (0, 0) to (2, 1) covers two pixel centers: (0.5, 0.5) and (1.5, 0.5). Setting this as the clipping region makes two pixels visible. This coordinate system favors intuition for centered, even-sized objects such as sprites. It also gives the result that you might intuitively expect for odd-sized objects at integer or half-integer coordinates such as odd-width text, 1-pixel points at integers, and 1-pixel horizontal and vertical lines. Diagonal 1-pixel lines and points at non-integer, non-half locations will round in ways that are less intuitive. `draw_point(pos)` draws a one-pixel rectangle from `pos - ½` to `pos + ½`. So, when passed integer arguments, `pos` = (0, 0) will color the top-left pixel and `SCREEN_SIZE - 1` is the lower-right. Any value from 0 to (1 - `ε`) will write to the the first pixel. When seeking to draw individual pixels aligned with the grid, I recommend that you use integer plus 1/2 coordinates for `draw_point()` for robustness. However, if you use integer coordinates, it will "do what you expect". `draw_line()` draws a line centered on its endpoints that extends ½ pixel beyond its endpoints. When seeking to draw horizontal and vertical lines aligned with the grid, I recommend that you use integer plus ½ coordinates for `draw_point()` for robustness. However, if you use integer coordinates, it will "do what you expect". For other lines, you may be surprised by the result if they aren't at half-pixel offsets. A 4x4 sprite (or circle or text character) with its top and left edge aligned with the screen edges is centered on coordinate (2, 2), that is, half its width and height. A 3x3 object aligned as such is centered at (1.5, 1.5) but will draw in the same way if centered at (1, 1), which would be consistent with integer pixel centers. The center of the entire screen is `½ SCREEN_SIZE`. ### Camera Space Note that `preserving_transform` also preserves the camera. `get_camera()` : Returns the current camera as an `args` object that could be passed to `set_camera(args)`. `reset_camera()` : `set_camera({pos: xy(0, 0), angle: 0deg, zoom: 100%, z: 0})` `set_camera(args)` : Named argument object version of `set_camera()`. `set_camera(pos default xy(0, 0), angle default 0, zoom default 1, z default 0)` : Positions the camera used to transform other draw calls. Note that `zoom` is the inverse of a scale transformation on the camera itself. Use `set_transform()` to move the on-screen origin. `zoom` can be a number or a function, `zoom(cs_z)`. If it is a function, it computes the zoom factor for an object at `cs_z` in camera space. This is useful for creating pseudo-3D effects. If you do not want your map layers to zoom in perspective, set the `"z_scale"` value in the map.json file to a small number or zero. Enabling a zoom function with nonzero `z_scale` can make map rendering significantly slower in the case of multiple layers because it disables occlusion culling. To render sprites with parallax but 1:1 pixel scaling when using a zoom function, set the sprite or entity `scale` to `1 / camera.zoom(entity.pos.z - camera.pos.z)`. ### Entity Space Each entity has its own coordinate system defined by `entity.pos`, `entity.scale`, and `entity.angle`. The `entity.scale` is often used to flip sprites from left to right, which also flips the entity's local coordinate system. In most cases, you won't have to think about entity space beyond setting those fields. Entitys drawn with sprites and interacting with physics automatically handle the transformations. Only if you're doing detailed manipulation of children or drawing explicitly in entity space do you need to apply transformations. The direction of `entity.angle` is always counter-clockwise in screen coordinates. The direction in draw coordinates is given by `rotation_sign()`. ****************************************************************** * Default Entity Space With flipped y-axis * * ^ y * | * .---------. .----|----. * | ↶ | | |↶ | * | *-------> x | *--------> x * | | | | | * '----|----' '---------' * | * v y ****************************************************************** The axes of the entity space in draw space are given by: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PyxlScript const θ = rotation_sign() * entity.angle const X = xy( cos θ, sin θ) * entity.scale const Y = xy(-sin θ, cos θ) * entity.scale // or const X = transform_entity_to_draw(entity, xy(1, 0)) - entity.pos const Y = transform_entity_to_draw(entity, xy(0, 1)) - entity.pos ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Entity space is mostly used for moving a character relative to its own axes or resolving attachment points. Drawing commands always take world space arguments and physics, per-pixel hit detection, and sprite drawing automatically handle the world-to-entity transformation for you. In the rare case where you want to draw in entity space, you can transform the arguments to world space: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PyxlScript draw_disk(transform_es_to_ws(entity, es_pos), es_radius * entity.scale.x, color) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This works even if the entity is deep in an entity hierarchy. When drawing a shape with more parameters, the draw commands have additional arguments to help with this process. For example: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PyxlScript draw_rect(transform_es_to_ws(entity, es_pos), size * entity.scale, fill, border, entity.angle, entity.z) draw_poly(es_vertex_array, fill, border, entity.pos, entity.angle, entity.scale, entity.z)) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ### Sprite Pixel Coordinates Sprite coordinates are used by `get_sprite_pixel_color()`. These are integers with (0,0) on the top left of the sprite and (`sprite.size.x` - 1, `sprite.size.y` - 1) on the lower right. ### Spritesheet Indices *Sprite sheets* use integer coordinates with (0, 0) at the upper-left corner and (`size(sheet)` - 1, `size(sheet[0])` - 1) at the lower-right corner. Instead of functions for operating on these, sprite sheets are directly accessed as 2D arrays: `sheet[x][y]`. ### Map Cell Indices *Map space* integer coordinates used by maps have (0, 0) as upper-left tile and `map.size` - 1 at the lower-right tile. Maps are typically accessed as 2D arrays: `map.layer[L][x][y]`. For convenience, `map[x][y]` is a shorthand for `map.layer[0][x][y]`. The top-left corners of map cells are at integers when converting between map and draw coordinates. When rendered, a map therefore covers the same region as the drawing command `draw_corner_rect(xy(0,0), map.size * tileSize, #f)`. The map is aligned by default so that `draw_map()` renders the top-left corner of the map to the top-left corner of the screen. Use `offset` in the `.map.json` file or `set_transform()` to alter the location of the map when rendered. Animations ------------------------------------------------------------ Each named sprite animation `spritesheet["`animation_name`"]` or `spritesheet.`animation_name of a spritesheet is an array that has the following immutable properties: `animation.period` : Number of frames before the animation repeats, which is `0` for `clamp` animations. `animation.frames` : Number of frames before the animation ends, which is `infinity` for `loop` or `oscillate` animations. `animation.frame(t)` : Return the sprite to show for the animation at time `t` measured in frames, obeying the individual `sprite.frames` durations and wrapping or clamping appropriately. Because it is an array, the ith sprite is `animation[i]` and you can loop that using `array_value(animation, i)` or choose a random one with `random_value(animation)`. To create an animation, there must be a `start` field in the named entry of the .sprite.json file. Sprite ------------------------------------------------------------ Each sprite element `spritesheet[x][y]` of a spritesheet has the following immutable properties. Sprites can also be referenced by name `spritesheet["`name`"]` or `spritesheet.`name, if the named sprite has an `x` and `y` field instead of a `start` field in the .sprite.json file. `sprite.animation` : If the sprite is in an animation (a multi-frame named array from a `sprite.json` file), this is the array that contains it. `sprite.id` : Unique integer identifying this sprite by spritesheet and tile_index, but excluding orientation. This may change every time the program is run. `sprite.orientation_id` : Unique integer identifying this sprite, including orientation. This may change every time the program is run. The flipped versions of a sprite have _different_ IDs. To tell if two sprites are the same except for flipping, use `sprite.id`. `sprite.frames` : Number of 1/60-second (≈ 16.7 ms) game frames to hold this sprite during animation. Set by the spritesheet's `default_frames`, the animation's `default_frames`, or the animation's per-sprite `frames` array. `sprite.x_flipped` : The corresponding derived sprite that is this sprite flipped horizontally. Flipped sprites are created on spritesheet load but can only be accessed through the non-flipped sprites. Note that `s.x_flipped.x_flipped == s`. `sprite.y_flipped` : The corresponding derived sprite that is this sprite flipped vertically. Flipped sprites are created on spritesheet load but can only be accessed through the non-flipped sprites. Note that `s.y_flipped.y_flipped == s`. `sprite.rotated_90` : Counter-clockwise 90 degree rotated version of the sprite. The bounds may be different if the sprite is not square. `sprite.rotated_180` : Counter-clockwise 180 degree rotated version of the sprite. The bounds may be different if the sprite is not square. Note that `s.x_flipped.y_flipped == s.rotated_180 == s.y_flipped.x_flipped == s.rotated_90.rotated_90`. `sprite.rotated_270` : Counter-clockwise 270 degree/clockwise 90 degree rotated version of the sprite. The bounds may be different if the sprite is not square. Note that `s.x_flipped.y_flipped.rotated_90 == s.rotated_270`. `sprite.scale` : An `xy()` value that is `xy(1,1)` for sprites extracted directly from the spritesheet and may be +1 or -1 in each axis for flipped sprites. `sprite.size` : `xy()` dimensions of the sprite in pixels. Note that for a rotated sprite, `sprite.size` is not the same as `sprite.spritesheet.sprite_size`. `sprite.spritesheet` : From which this sprite is taken. `sprite.tile_index` : Integer `xy()` index of the sprite in its spritesheet. Any properties attached to a named sprite or animation in the `sprite.json` file also appear as properties of the sprite (and its flipped variations). Entity ------------------------------------------------------------ The entity system is optional. It is convenient for providing fast, reliable implementations of common game-like simulation operations for prototyping. There are three categories of entity abstraction: basic, physics, and hierarchy. Use whichever level of complexity is useful to you, or simply build your own system if you wish. Note that due to "duck typing", you can apply entity functions to any object that has the right subset of fields for that function. In addition to the built-in entity properties, you can add whatever properties you wish. Beware that the following properties are available as user properties today, but are likely to be added as built-in properties in the future: `density` and `friction`. ### Basic `draw_entity(e, recurse default true)` : Draw the entity, if its sprite is defined. If `recurse` is true, also draws all of the elements of `e.child_array` recursively (see the Hierarchy section). `make_entity(obj default {}, childTable default {})` : Returns a new entity object that is `obj` with defaults applied for any properties not specified. This is forward compatible to any extended properties that might be added in future versions, however, those properties might conflict with any that you add on your own. The built-in entity properties are all cloned if specified. All other properties of `obj` are copied over but not cloned. If the `childTable` second argument is provided (note that this is not a property of `obj`), then all of the keys become fields of the new entity and the values are added to the entity's `child_array`. This is a convenient way to build entity hierarchies. If a `child_array` property is specified on `obj`, then `entity_add_child()` is called for each element of this array and `entity_update_children()` is automatically invoked after the new entity is constructed. The basic entity properties and defaults are: `entity.angle` : The world space angle from the x-axis to y-axis in radians. See `draw_sprite()`. Defaults to 0. See also `entity.angle_in_parent` and `entity.orient_with_parent`. `entity.name` : A string useful for debugging and error messages. Defaults to `"entity"` + a unique number. `entity.offset` : A world space value added to `entity.pos` by `draw_entity()` for placing the sprite. Useful for causing the drawn position to temporarily drift from the simulated position for effects like shake or blowback after a hit. Defaults to `xy(0, 0)`. _Does not affect bounds for `overlaps()`, physics, or ray intersection._ See also `entity.pivot`. `entity.opacity` : Visibility on the interval 0 to 1. Defaults to 1. `entity.pivot` : Point on the sprite that is mapped to the center of the entity. Defaults to the pivot form the intial sprite, or `xy(0, 0)` if there was no sprite. If you change the `entity.sprite`, then you may want to also change the `entity.pivot` at the same time. See also `entity.offset` for transient effects. `entity.pos` : The world space `xy()` position of the center of the entity. Defaults to (0,0). See also `entity.pos_in_parent`, `entity.offset`, and `entity_update_children()`. `entity.scale` : The world space `xy()` scaling applied before translation and rotation. See `draw_sprite()`. Defaults to (1, 1). This can be used to grow, stretch, or flip the entity. If `entity.shape == "disk"`, then the scale must have the same magnitude in both x and y. `entity.shape` : A string that is `disk` or `rect`. Defaults to `rect`. A `disk` entity must have scale that is the same in x and y. `entity.size` : The draw-space `xy()` size of the width and height of the bounding box of the entire object in its own reference frame. If `entity.shape == "disk"`, then the `x` and `y` fields must have the same value. If not specified, defaults to the sprite's size. `entity.sprite` : A sprite from a sprite sheet. Can be `nil`. `entity.sprite_override_color` : Blends over the color of the sprite with this color (only works if there is a sprite). See `draw_sprite()` for details. Defaults to `nil`. `entity.z` : z-order position (a number). Defaults to zero. Examples of creating an entity with different shapes: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PyxlScript // Disk e = make_entity({pos:P, shape:"disk", size: xy(diameter, diameter)}) // Square e = make_entity({pos:P, shape:"rect", size: xy(edge, edge)}) // Rectangle e = make_entity({pos:P, shape:"rect", size: xy(w, h)}) // Line e = make_entity({pos:(A + B) / 2, shape:"rect", size: xy(magnitude(B - A), 0), angle:atan(B.y - A.y, B.x - A.x)}) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The entity system is designed to be extensible. You can add your own properties to it, and aren't required to use it at all...make direct `draw_sprite()` calls if you don't like this. You can also use the entity system but replace the rendering if you prefer. For example, if you'd like to register your own draw function callbacks instead of using the sprite rendering, you can do this: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PyxlScript def draw(e): if e.draw: e.draw(e) for c in e.child_array: draw(c) def drawInBox(e): draw_corner_rect(e.pos, e.size, #FFF) draw_sprite(e.sprite, e.pos) let e = make_entity({..., draw:drawInBox}) draw(e) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Example of replacing `draw_entity` with a version that uses arbitrary callbacks.] ### Label Properties A text label is drawn for the entity if `entity.text and entity.font` is not `nil`. This is useful for showing player names, map labels, RPG stats, scores, and character dialogue. The full set of label properties is: - `entity.text` - `entity.font` - `entity.text_x_align` - `entity.text_y_align` - `entity.text_offset` (this is not affected by entity rotation but is affected by scale) - `entity.text_color` - `entity.text_shadow` - `entity.text_outline` ### Physics Properties A key relating textbook symbols and definitions to the quadplay✜ entity property names is: Property | Symbol | Definition ----------------|----------------------------------|------------------ `pos` | _x_(_t_) | Position `vel` | _v_(_t_) = _dx_(_t_) / _dt_ | Linear velocity `force` | _F_(_t_) = _m_ • _a_(_t_) | Force `angle` | _θ_(_t_) | Angle `spin` | _ω_(_t_) = _dθ_(_t_) / _dt_ | Angular velocity `torque` | _τ_(_t_) = _I_ • _α_(_t_) | Torque `inertia` | _I_ | Inertia `density` | _ρ_ | Density `friction` | _μ_ₖ | Coefficient of kinetic friction `stiction_factor`| _μ_ₛ/_μ_ₖ | Static friction multiplier `restitution` | _e_ | Coefficient of restitution You can choose the units and coordinate system. Pixels (of distance), pixel mass, and game frames are the most common choice of units in order to simplify conversion factors. See also the Physics section for relevant functions. `entity.force` : `xy()` linear force. Defaults to (0, 0). Has units of mass * pixels / frame^2 by default. Typical forces are on the scale 1-10. `entity.density` : In mass units per square pixel. Defaults to 1. If density is `infinity`, then the object can move others but is not itself affected by collisions, and also ignores gravity. `entity.spin` : Scalar counter-clockwise rotational velocity. Defaults to 0. Has units of radians/frame by default. `entity.torque` : Scalar counter-clockwise rotational torque. Defaults to 0. Has units of mass * radians/frame^2 by default. Typical torques are on the scale 1-10. `entity.vel` : `xy()` linear velocity. Defaults to (0, 0). Has units of pixels/frame by default. `entity.physics_sleep_state` : Current sleeping state of the entity in a physics engine. Default is `"awake"`. Legal values are are `"sleeping"`, `"awake"`, and `"vigilant"` (awake and can never go to sleep). Because objects that are sleeping do not maintain contacts with other sleeping objects or parts of the environment, if you want to check for contacts (such as with the ground) on a player controlled entity then it should be `"vigilant"`. `entity.restitution` : Amount of energy preserved in a collision. Useful range is 0%-100%. The default is 10%. The net restitution applied between two entities is the geometric mean of their restitution values. `entity.contact_category_mask` : Contact (collision) categories for this object, as 32-bit flags. Two objects can only contact if `(A.contact_category_mask bitand B.contact_hit_mask) and (B.contact_category_mask bitand A.contact_hit_mask)`. Defaults to 1. Does not affect `overlaps()`. `entity.is_sensor` : If `true`, collisions will occur with this entity as usual but will not cause motion to change as a result, like a ghost. Default is `false`. This is useful for detecting triggers such as a character walking through a doorway or touching acid via the physics engine without causing that to affect the object. Note that a sensor must have infinite density or be attached to another object or it will fall out of the world by gravity. If you want to never register collisions, instead set `entity.contact_category_mask = 0` to prevent all collisions and preclude them being reported. Collision sensors have density, and it must be nonzero. Set their density to a small value, such as `epsilon`, to minimize the effect on the motion of other objects that they are attached to. `entity.contact_group` : An integer index of a group of other entities that this one should not collide with, regardless of the `contact_hit_mask` or `contact_category_mask`. Zero means no group at all. Defaults to 0. Does not affect `overlaps()`. `entity.contact_hit_mask` : See `entity.contact_category_mask`. Defaults to `0xffffffff`. Does not affect `overlaps()`. `entity.stiction_factor` : Multiplier applied to `entity.friction` in the static dry friction case when an object is at rest. Useful range is 0-10. Defaults to 1. The value 0 disables static friction (since it allows the object to immediately start moving, and thus have kinetic friction engage), so that only dynamic friction is applied. The net stiction_factor between two entities is the _maximum_ of each of their stiction_factor values. Set moving platforms and conveyor belts to have high stiction to help characters move with the surface that they are on. `entity.friction` : Kinetic dry friction applied when an object is in motion, damping the velocity. Useful range is 0%-100%. Defaults to 15%. The net friction applied between two entities is the geometric mean of their friction values. `entity.drag` : Drag friction applied when an object is moving freely. Useful range is 0-10. Defaults to 0.005. There is a single drag constant for the body independent of the orientation or direction of motion. This is not a drag _coefficient_ because it is independent of cross-sectional area. ### Hierarchy The hierarchy is not a traditional scene graph. Children can opt to either compose their properties with their ancestors recursively or have absolute properties in draw space. Hierarchy functions: `entity_add_child(parent, child)` : Adds the `child` entity to the `parent.child_array` and sets `child.parent = parent`. Removes the child from any previous parent's child array if there was one. Returns the `child`. `entity_remove_child(parent, child)` : Removes the `child` from `parent.child_array`, if it is a child. Does nothing if `child` is not in `parent`. Causes an error if `child` and `parent.child_array` are inconsistent. If the child was added by the `make_entity` `childTable` as a field on parent, that field is not modified. You can remove the field explicitly using `remove_key(parent, "childName")`. `entity_remove_all(parent)` : Removes all children. `entity_update_children(entity)` : Recursively update the `pos`, `scale`, `angle`, and `offset` fields of all children and descendants from their `pos_in_parent`, `scale_in_parent`, `angle_in_parent`, and `offset_in_parent` fields. Usually called after simulation or animation processing. The hierarchy properties are: `entity.child_array` : Array of other entities that position themselves relative to this one. Defaults to `[]`. `entity.parent` : Another entity that has this one as a child. Defaults to `nil`. `entity.angle_in_parent` : Scalar counter-clockwise angle in radians relative to the parent if `entity.orient_with_parent` is true, otherwise ignored. `entity.offset_in_parent` : `xy()` `offset` relative to the parent in entity space if `offset_with_parent` is true, otherwise ignored. `entity.offset_with_parent` : Boolean. If true, then `entity_update_children()` recomputes `entity.offset` from `entity.offset_in_parent` and `parent.offset`. `entity.pos_in_parent` : `xy()` position value relative to the parent, in parent space. There is no way to opt out of this property being applied recursively. Defaults to (0, 0). `entity.orient_with_parent` : If true, `entity_update_children()` will override this entity's angle and scale with `entity.angle = entity.angle_in_parent + parent.angle` and `entity.scale = entity.parent.scale * entity.scale_in_parent`. `entity.scale_in_parent` : `xy()` scale relative to the parent axes for flipping the child if `scaleWithParent` is true, otherwise ignored. `entity.z_in_parent` : Scalar z value relative to the parent. There is no way to opt out of this property being applied recursively. Defaults to 0. Physics --------------------------------------------------------- You can implement your own physics simulation, use entity and the entity helpers, enable the full entity physics engine, or mix these techniques. ### Entity Helpers Also see the Intersections section for computing your own collisions and intersections. `entity_apply_force(entity, world_force, world_pos default entity.pos)` : Apply world-space `world_force` to `entity` at world-space position `world_pos`, updating both `entity.force` and `entity.torque`. To apply a force at the center of mass, you can also directly add to `entity.force`. To apply a torque without a net force at the center of mass, directly add to `entity.torque`. Does not support entities with children or pivots. `entity_apply_impulse(entity, world_impulse, world_pos default entity.pos)` : Apply world-space `world_impulse` (mass * velocity) to `entity` at world-space position `world_pos`, updating both `entity.vel` and `entity.spin`. To apply a velocity change at the center of mass, you can also directly add to `entity.vel`. To apply angular velicty without a net linear velocity impulse at the center of mass, directly add to `entity.spin`. Does not support entities with children or pivots. `entity_area(e)` : Returns the world space area of `e`, which must have `shape` and `size` properties and may have a `scale` property. `entity_inertia(entity)` : Scalar inertia tensor about the center of mass. Equal to `entity_mass(entity) * magnitude(entity.scale * entity.size)² / 12` when `shape` is `"rect"` and `⅛ entity_mass(entity) * (entity.scale.x * entity.size.x)²` when `entity.shape == "disk"`. Has units of mass * pixels^2. `entity_mass(entity)` : Scalar mass equal to the bounds area in pixels specified by the `entity.shape` and `entity.size` times the `entity.density`. Returns generic mass units. `entity_move(entity, pos default entity.pos, angle default entity.angle)` : Instantaneously moves an entity to this position and angle _as if it had naturally reached that location in the previous frame_, setting the appropriate `entity.vel` and `entity.spin`. This is useful for moving entities with infinite density in a way that causes them to interact naturally with other entities that they come into contact with. For example, use this function for implementing moving platforms, scripted set-piece animations, and elevators. `entity_simulate(entity, t default 1)` : Computes `acc = force/mass; twist = torque/inertia` and `vel *= 1 - drag; spin *= 1 - drag`. Then, integrates `acc` into `vel` into `pos` and `twist` into `spin` into `angle`. Finally, resets `force` and `torque` to zero and invokes `entityUpdateChilren()`. Uses a forward Euler (1st order Runge-Kutta) integrator over duration `t` measured in frames. This tends to be a more stable method for small, discrete time steps than the analytic quadratic solution and avoids the need for additional data of higher-order integrators. Does not perform collision detection or response, or enforce attachment constraints. You do not need to call `entity_simulate()` if you are already using `physics_simulate()`. `make_contact_group()` : Creates a unique value for an `entity.contact_group`. ### Intersections These are methods for determining intersections and collisions explicitly, without using the full physics engine. `axis_aligned_draw_box(e)` : Returns a box specified by `{pos:xy(), size:xy(), shape:"rect"}` that encloses the object `e` (and all of its children if it is an entity) in draw space. `overlaps(A, B, recurse default true)` : Returns true if the bounds of `A` and `B` overlap each other, taking shape and orientation into account and incuding the borders. Ignores `offset` and `z` for entities. Each of `A` and `B` can be any of: - an entity from `make_entity()` - any object with `pos` and optional `shape`, `angle`, `pivot`, and `size` properties - an `xy()` point If `recurse` is true (the default), compares `A` and all of its children against `B` and all of its children. This is quadratic in the number of elements of each and can be slow for very deep entity hierarchies. See `entity.pivot`, `entity.shape`, etc. for discussion of how those properties affect the collision detection. `ray_intersect(ray, obj)` : The `ray` object must have `xy()` fields for `origin`, `direction`, and an optional number field for `length default infinity`. The `ray.direction` will automatically be normalized. The `obj` has `shape`, `pos`, `size`, and optional `angle` properties (an entity satisfies this, but it doesn't have to be a full entity). If there is a `obj.child_array`, then that is recursively processed and the first intersection encountered is returned. Returns the object hit or `nil` if there was no intersection. The `ray.length` is shortened to the hit distance. `ray_intersect(ray, array)` : Returns the first object intersected when calling `ray_intersect(ray, array[i])` on each element of the array. ### Engine The full physics engine provides collision detection, response, and constraints. Children of entities in the physics system have no effect on physics. In future releases they will affect the collision shape, moment of inertia, and mass. While an entity is in a physics context, the following properties may not be changed on that entity: - `shape` - `size` - `pivot`, which must always be `xy(0,0)` - `scale`, except for sign changes Attachments not moved for scale changes because it is ambiguous how the attached object should be changed. If you need attachments on entities that change scale signs, then detach the two entities, move them, and create a new attachment in the new position. For example, when a character flips direction and a rope tied to their hand should now be on the other side. Changing the `contact_group`, `contact_hit_mask`, or `contact_category_mask` on the bodies in an attachment with `collide = false` after the attachment been created may cause the attached bodies to start colliding with each other. `make_physics(options default {})` : Create and return a new physics context. There can be multiple, independent physics contexts in the game. Each entity may only be in one physics context at a time. The options are: - `gravity default xy(0, -up_y())`: Default gravitational acceleration on all objects. Set to `xy(0,0)` and explicitly apply gravity if your game is not set on a planetary surface or requires excluding most objects from gravity. - `allowSleeping default true`: Allow simple rigid bodies to fall "asleep" and stop simulating until touched. This dramatically increases simulation performance, however some entities will fail to properly waken when the object supporting them is removed and can remain floating in the air. `physics_add_contact_callback(physics, callback, min_depth default 0, max_depth default ∞, contact_mask default 0xffffffff, sensors default "exclude")` : Adds a callback that processes collisions (new contacts) at the end of `physics_simulate()`. If either entity in the collision has a `entity.contact_category_mask` that intersects the `contact_mask` and the collision has `depth >= min_depth`, then invoke `callback({entityA, entityB, depth, age, point0, point1, normal})`. `point1` may be `nil`. `normal` is in draw coordinates and always points out of `entityA`. `depth` is a coarse measure of how hard the objects hit each other. It has a useful scale from 0-4. This is good for triggering particle effects or sound on collisions, or causing damage to objects. When doing so, use the parameters to filter: for example, `min_depth` = 1 will only trigger on significant, new contacts. There is no way to remove a contact callback. `physics_entity_has_contacts(physics, entity, child_region default ∅, world_normal default ∅, mask default 0xffffffff, sensors default "exclude")` : Returns true if `physics_entity_contacts()` would produce any contacts with the same arguments. This is more efficient, for the case where the actual contacts are not needed. `physics_entity_contacts(physics, entity, child_region default ∅, world_normal default ∅, mask default 0xffffffff, sensors default "exclude")` : Returns an array of all current contacts, where each contact has the form `{entityA, entityB, depth, point0, point1, normal}`. The contact points are in draw coordinates. The region, mask, normal, and sensors setting are used to filter the contacts returned. A contact must have nonzero `contact_mask bitand otherEntity.contact_category_mask` for the _other_ entity involved. The average position of point0 and point1 must also lie within the `child_region`, which is in the entity's reference frame. `child_region` is either `nil` (all contacts) or an argument suitable for passing to `overlaps()`. If `normal` is specified, then the contact normal for the other entity must point within ±80° degrees of this vector. This is a draw-space vector. `sensors` may be `"include"`, `"exclude"`, or `"only"` (exclusively return contacts with sensors). In the returned contacts, the `entity` may be either `entityA` or `entityB`. This function is ueseful for determining if entities are currently in resting contact, such as whether a character is standing on the ground and can jump. In that case, make the `child_region` a box around the character's feet and set the `world_normal` to the up vector for the world. The `child_region` may have to be very wide (e.g., 2x as wide as the character) to encompass locations where contact was briefly made in a previous frame. Note that sleeping entities have no contacts. See also `physics_add_contact_callback()`. `physics_add_entity(physics, entity)` : Add `entity` to this physics context. An entity may only be in one physics context at a time. Returns the `entity`. Once an entity is added to the physics system, it will be retained in the physics system until `physics_remove_entity()` is called. Use the `draw_physics()` command or IDE button to debug physics objects that correspond to entities which are no longer being drawn. `physics_attach(physics, type, {entityA, entityB, pointA, pointB, collide default ∅, ...})` : Attaches two entities to each other or `entityB` to the world. `entityA` may be `nil` (the world) or have infinite density. `entityB` must be non-`nil` and have finite density. The points are optional attachment points in the reference frame of each entity. The attachment points do not have to be within the bounds of the entities. The entities are immediately moved to satisfy the constraint of the attachment. Two entities may not have multiple attachments directly between them. Doing so will cause unstable and undefined behavior. _There is no relationship to the entity parent/child hierarchy_. Entity children are used for explicit positioning. Attachments are for letting simulation position objects. Returns an attachment object, which can be passed to `physics_detach()`. All attachment types are massless, except for weld, which adds a slight amount of mass at the weld point and thus affects net mass and moment of inertia. If `collide` is false, then the entities cannot collide with each other while the attachment is maintained. The default for `collide` is `true` for spring and rod attachments and `false` for all other types. You can also disable collisions by putting the objects in the same `entity.contact_group`, which is more efficient. Attached entities cannot sleep. The supported values of `type` and the additional named parameters supported for each are: - `"pin"`: This kind of attachment is referred to in other APIs as a revolute joint. - `"spring"`: `length default ‖pointB - pointA‖`, `stiffness default 0.5%`, `damping default 0.2%` - `"rod"`: `length default ‖pointB - pointA‖` - `"weld"`: `angle default entityB.angle - entityA.angle`. Rigid attachment with the specified relative angle. Requires `entityA` to be non-`nil`. - `"gyro"`: `angle default 0` Free translation, but frozen rotation relative to each other. Useful for keeping characters upright. `entityA` must be `nil`. This kind of attachment is referred to in other APIs as a Cartesian joint or generalized 2D prismatic joint. `physics_detach(physics, attachment)` : Remove this attachment, which was previously created by `physics_attach()`. `physics_remove_all(physics)` : Remove all entities and attachments from this physics context. `physics_remove_entity(physics, entity)` : Remove `entity` and all attachments for it from the physics context. See also `physics_add_entity()`. `physics_simulate(physics, frames default 1)` : Simulate physics for this many frames, treating all forces and torques as constant over that period. Automatically calls `entity_update_children()` on all entities in the context. See also `entity_simulate()`. Graphics --------------------------------------------------------- ### Colors Colors in quadplay are interpreted in the [sRGB](https://en.wikipedia.org/wiki/SRGB) color space and are on the range 0 to 1 for each channel. Although the screen and GPU operate in 4-bit per channel mode, arbitrary colors (including negative and out of gamut ones) can be represented using these types. `gray(n)` : Returns `rgb(n, n, n)`, with `n` clamped to the range 0 to 1. `gray(color)` : Returns `rgb(n, n, n)`, with `n` equal to a perceptually-weighted average of the rgb values from color. The RGB --> gray conversion algorithm weights will likely change in a future release. `hsva(h, s, v, a default 1)` : Returns an object with field `h` _wrapped_ to [0, 1], and fields `s`, `v`, and `a` clamped to [0, 1]. `hsva(hsv, a default 1)` : Clone the `hsv` object, adding an `a` property. `hsva(rgb, a default 1)` : Convert the `rgb` value to hsv and add an `a` property. `hsva(rgba)` : Convert the `rgba` to hsva. `hsva(hsva)` : Clone the `hsva` object, stripping other properties. `hsv(hsv)` : Clone the `hsv` object, stripping other properties (such as an `a` channel). `hsv(h, s, v)` : Returns an object with field `h` _wrapped_ to [0, 1], and fields `s` and `v` clamped to [0, 1]. `h=0` and `h=1` are red, `h=1/3` is green, and `h=2/3` is blue, with values inbetween interpolated. `perceptual_lerp_color(c1, c2, t)` : Both `c1` and `c2` must have the same type: `hsv()`, `hsva()`, `rgb()`, or `rgba()`. Performs a linear interpolation in CIELAB perceptual space and returns a value in the original color space. See also `lerp()`, `smoothstep()`, and `smootherstep()`, which can be applied to colors. `rgb(hsv)` : Convert the `hsv` result to rgb, stripping other properties. `rgb(rgb)` : Clone the `rgb` value (stripping other properties, such as an `a` property). `rgb(r, g, b)` : Create a structure with properties `r`, `g`, and `b` clamped to [0, 1]. `rgb_to_xyz(c)` : Returns `{x: c.r, y: c.g, z: c.b}`. `rgba(rgb, a default 1)` : Clone the `rgb` value and add an alpha property. `rgba(rgba)` : Clone the `rgba` value, stripping other properties. `rgba(r, g, b, a default 1)` : Create a structure with properties `r`, `g`, `b`, and `a` clamped to [0, 1]. `rgba(hsva)` : Convert the `hsva` result to rgba. `rgba(hsv, a default 1)` : Convert the `hsv` result to rgb and add an `a` property. Colors can also be constructed using the syntax of HTML hexadecimal colors (which are also shown in Photoshop and other drawing programs) using the syntax: - #RRGGBBAA - #RRGGBB - #RGBA - #RGB - #LL (gray) - #L (gray) For example, `#F08` is equivalent to `rgb(1, 0, 0.5333)` and `#CC` is equivalent to `gray(0.8039)`. -------------------------------------------------- The quadplay✜ uses 4:4:4:4 RGBA color, for a total of 4096 different colors and 16 levels of transparency including fully-transparent. It can draw perfect 16-shade gradients of red, green, blue, yellow, magenta, cyan, and gray, where the darkest shade of each of those is black. Blending is based on z-order, not draw order, and is always the Porter-Duff over-compositing rule: `result.r = back.r * (1 - front.a) + front.r * front.a` and so on for `g` and `b`. The runtime is free to implement this blending exactly using sorted draw calls or an A-buffer, or to approximate it with alpha-to-coverage and multisampling or fixed-memory order-independent pixel shading techniques. Blending guarantees at least five bits per channel of intermediate precision and four bits per channel of framebuffer storage, but implementations may use more. Colors are specified as objects that have either `r`, `g`, and `b`; or `h`, `s`, and `v` fields, and an optional `a` field. All color channels are on the range 0-1 and snapped to discrete values. Additional fields in color objects are ignored. Many routines accept both a "fill" color for the interior and a "border" color for the perimeter. Set either to transparent (`nil`) to efficiently disable that portion of rendering. The `nil` value is transparent. Borders are drawn inside shape coordinate boundaries and on top of fills, so a transparent border is identical to a border that is the same color as the fill. Shapes include their endpoints and borders. ### Drawing `draw_poly(args)` : Named argument version of `draw_poly()`. `draw_poly(vertex_array, color, outline = (nil), pos default xy(0, 0), angle default 0, scale default xy(1, 1), z default 0)` : Draws the _convex_ polygon defined by the `vertex_array`, first scaling by `scale`, rotating by `angle`, and then translating by `pos`. The polygon may have any winding direction. The outcome of the drawn result is undefined and may change across platforms if the polygon is not convex (but there will never be an error). `draw_corner_rect(args)` : Named argument version of `draw_corner_rect()`. `draw_corner_rect(corner, size, color, outline default ∅, z default 0)` : Draw a rectangle covering all of the pixel centers between `corner` and `corner + size`. This is primarily for UI window drawing. `size` may be negative. If the top or right sides exactly touch a pixel center (at a half-integer), then they do not cover it. The direction in which the `size` applies is determined by the current transform. Note that if `up_y()` is positive, then the rectangle will extend _upward_ from the corner. See also `draw_rect()`. `draw_disk(args)` : Object version of `draw_disk()`. `draw_disk(pos, r, color, outline default ∅, z default 0)` : Draw a circle or filled disk centered at (`pos.x`, `pos.y`) with radius `r` and z-order `z`. Choose the radius to be a half-integer, such as 3.5, and place the position at a half-integer if you want it to be centered on a pixel. Guarantees: - zero self-overdraw within the circle (important when using alpha) - zero overdraw between the circle outline and filled interior disk - disk exactly inscribes the containing rectangle - the total number of pixels covered will not change size under subpixel translation if the circle radius is an integer or half-integer `draw_line(args)` : Named argument version of `draw_line()`. `draw_line(A, B, color, z default 0, width default 1)` : Draw a 1-pixel line from (`A.x`, `A.y`) to (`B.x`, `B.y`) using z-order `z`. When using the default transformation, put the endpoints at half-pixel positions for the best alignment with the pixel grid. `draw_point(args)` : Named argument version of `draw_point()`. `draw_point(pos, color, z default 0)` : Set the color of pixel (`pos.x`, `pos.y`) to color `color` with z-order `z`. A series of `draw_point` calls with the same `z` value are about twice as fast as ones with mixed `z` values or intermixed with other draw calls. For the best alignment under the default transformation, put the endpoints at half-pixel positions. `draw_previous_mode()` : Re-issue all of the drawing commands from the previous mode's frame that completed before the `set_mode()` call. These are not affected by the current `clip` or `transform`. The calls are in full 2.5D, so calls from this mode may insert graphics between them in the z-order. Useful for drawing the main game background during inventory, pause, menu, and dialogue modes. `draw_rect(args)` : Named argument version of `draw_rect()`. `draw_rect(pos, size, color, outline default ∅, angle default 0, z default 0)` : Draws the rectangle _centered_ at `pos` with the given `size` and `angle`. No `scale` argument is provided because it is easy for the caller to explicitly multiply `size` by `scale`. See also `draw_corner_rect()` and `draw_sprite_corner_rect()`. `draw_sprite(args)` : Keyword version of `draw_sprite()`. Pass an object that has properties whose names match the arguments of the positional version. For example, `draw_sprite({sprite: wizard, pos: xy(100, 100), z: 2})`. Values default according to the positional argument version. `draw_sprite(sprite, pos, angle default 0°, scale default xy(100%, 100%), opacity default 100%, z default 0, override_color default rgba(0,0,0,0), override_blend default "lerp", pivot default sprite.pivot)` : Draw sprite `sprite` with its center at `pos`. `pos` must have at least `x` and `y` fields. The sprite appears at `z` in the z-order (defaults to 0). The `scale` parameter must be nil (which is treated as `xy(1,1)`), a number that is not zero, or an `xy()` with nonzero fields. Scale is applied before the sprite is rotated. Sprites are not flipped or scaled by `set_transform` values, but the rotation and center are affected by the `set_transform` scaling. If it is not `nil`, the `override_color` blends with the red, green, and blue values read from each pixel of the sprite. The default blend mode is "lerp", which interpolates between the sprite color and the `override_color` based on `override_color.a`. The other blend operation supported is `"multiply"`, which multiplies the `r`, `g`, `b` values and ignores the `override_color.a`. The alpha value of the result is always the sprite's original alpha value. Useful for simulating lighting, turning a sprite into a shadow silhouette, or flashing a sprite a different color to indicate hits or invincibility. The `pivot` is in the sprite's coordinate system relative to its center, so it is affected by the `angle` and `scale`. `draw_sprite_corner_rect(sprite, corner, size, z default 0)` : Draw a rectangle enclosing points `corner` and `corner+size` filled with `sprite` tiled as needed (and aligned to the center), and surrounded by the neighbors of `sprite` in its spritesheet. The edges surround the specified coordinates. Used for drawing user interface elements (GUI) of dynamic size such as windows and health bars. Keep in mind that some artwork is designed to only be stretched in one dimension, or to tile only at integer multiples. See also `draw_corner_rect()` and `draw_rect()`. This routine ignores the global camera. That may change before SDK version 1.0. `draw_text(args)` : Keyword version of `draw_text()`. Pass an object that has properties whose names match the arguments of the positional version. For example, `draw_text({text: "Fire!", pos: xy(100, 100), x_align:"left", z: 2})`. Values default according to the positional argument version. `draw_text(font, text, pos, color default ∅, shadow default ∅, outline default ∅, x_align default "left", y_align default "baseline", z default 0, wrap_width default ∅, text_size default size(text), markup default false)` : Print string `text` relative to `pos`. Returns an `xy()` size of the bounding box, excluding shadows and outline. This bounding box is conservative in height and accounts for the highest ascender and accent and lowest descender. It is tight in width and tailored to the exact characters. The bounding box also does not include the spacing that should be added between consecutive lines. Use `font.line_height` to know how far to place separate lines vertically or simply use strings with `"\n"` characters in them to print multiple lines. _This return value will change in a future implementation._ The positioning of text will follow the transform and camera, but individual letters always draw upright and 1:1 pixel perfect, without flipping, rotation, or scaling, no matter what the transform or camera are. x-alignment of `-1` or `"left"` = left, `0` or `"center"` = center, `+1` or `"right"` = right, y-alignment of `-1` or `"top"` = top, `0` or `"center"` = center, `1` or `"baseline"` = baseline, `2` or `"bottom"` = bottom. `font` must be loaded from the assets. Color, shadow, and outline default to transparent. Any non-transparent outline causes the shadow to move below both the outline and main color. Returns the line height (including spacing) for the next line. If `wrap_width` is specified, breaks the text at the maximum width and renders multiple lines. Each line is offset by the font's vertical spacing and aligned as specified. See also `text_width()`. `text_size` restricts draw_text to only printing that many characters, *after* word-wrapping. This allows gradually revealing text in a stable way under word wrap. `markup = true` enables special syntax for changing the style within a single string and removes single linebreaks, in order to make it easier to import long text strings from constants or data files. The markup syntax is `"...{property:value text...}..."`. The valid property names are `color`, `font`, `shadow`, and `outline`. That property is valid from the beginning brace to the end one. Only one property can be changed per brace, and braces can be nested. For strings that word wrap, the vertical spacing of lines is based on the original font specified as an argument to `draw_text()`, so using very different fonts can result in poorly formatted output. The legal values are colors specified using `rgba()`, `rgb()`, `hsva()`, `hsv()`, or `gray()` with numbers, the `#` color syntax, or the names of constants specified in the `game.json` file. Variables and expressions are not permitted in the values. To insert a regular brace within markup, use a slash escape, which must be typed in a string using a double slash: `\\{` or `\\}`. To insert a single linebreak within markup, use `{br}`. `draw_tri(args)` : Named argument version of `draw_tri()`. `draw_tri(A, B, C, color, outline default ∅, pos default xy(0, 0), scale default xy(1, 1), angle default 0, z default 0)` : Scale `A`, `B`, and `C` by `scale`, rotate them around the origin by `angle`, translate by `pos`, and then draw the triangle. The `pos` argument is not first because in many cases this is called with draw-space vertices and no translation. The triangle may have any winding direction. `get_background()` : Returns the value previously set with `set_background()`. `get_clip()` : Returns the current net clipping region as an object that can be passed to `set_clip()`. `get_sprite_pixel_color(sprite, pos, result default ∅)` : Returns the color of pixel `pos` in the sprite as an `rgba` value. When `result` is not `nil`, it is used to store the result to avoid memory allocation. If the pixel is out of bounds for that sprite, returns `nil` if there is no `result` specified and `rgba(0,0,0,0)` in `result` otherwise. `intersect_clip(args)` : Object version of `intersect_clip()`. `intersect_clip(pos default ∅, size default ∅, z default ∅, z_size default ∅)` : Intersect the current clipping region with this new one. Ignores the current transformation. `reset_clip()` : Reset to the default clipping region, `set_clip(xy(0, 0), SCREEN_SIZE, -2047, 4096)`. `set_background(color default #000)` : Replace the background with this color. The background is automatically drawn each frame with the last value set. `set_background(sprite)` : Replace the background with this sprite, which must be the exact size of the screen and in a spritesheet that is the exact size of the screen. `set_clip(args)` : Object version of `set_clip()`. `set_clip(pos default ∅, size default ∅, z default ∅, z_size default ∅)` : Set the clipping region to this region. Unspecified and `nil` values retain their current value. `pos` is the upper-left corner. `pos` and `size` must be `nil` or `xy()` values. Coordinates are clamped to the physical screen and z to the range [-2047, 2048]. `size` and `z_size` may be negative. It is impossible to set a clipping region smaller than 1x1x1 pixels. `text_width(font, s, markup default false)` : Returns the pixel width of string `s` in this font, including border padding. Note that leading and trailing numbers may incur additional empty space for column alignment. If `markup` is true, then `s` is processed using the markup rules from `draw_text()`. `xy(x, y)` : Create a structure with values `x` and `y`, which can be used with most drawing routines. `xy(xy)` : Clone the `xy` value, stripping other properties (such as a `z` property). `xyz(x, y, z)` : Create an object `x`, `y`, and `z` properties, which can be used with most drawing routines. `xyz(xyz)` : Clone the `xyz` value, stripping other properties. `xyz(xy, z default 0)` : Clone the `xy` value, adding a `z` property. -------------------------------------------- ![Text styling options](text-style.png width=500%) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PyxlScript set_background(#FFF) // Make the text color clear to draw outlines. draw_text(goodNeighbors, "Transparent", xy(83, 155), rgba(0,0,0,0), nil, #0) // Make the bottom outline look thick by making the shadow and outline // the same color. draw_text(goodNeighbors, "Thick Bottom", xy(83, 170), #2AF, #0, #0) // Draw an explicit shadow wherever you want it draw_text(goodNeighbors, "Offset Shadow", xy(85, 184), rgba(0,0,0,25%)) draw_text(goodNeighbors, "Offset Shadow", xy(83, 182), #0A0) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Tricks with text styling] ![Tricks with text styling](text-tricks.png width=200%) ------------------------------------ Font assets have the following properties: `font.line_height` : Vertical spacing between baselines in multiline text. Advance the `y` coordinate of a position by this much if explicitly rendering multiline text (you can also just put newlines in the text or use the `wrap_width` argument for automatic multiline). The `line_height` is not the vertical bounds of all characters. Some characters may exceed the spacing because they have especially high accents or ascenders or low hooks and descenders. `font.spacing` : `xy()` spacing between characters vertically and horizontally. `font.glyph_size` : `xy()` width and height that will bound all characters in this font, not including border or shadow. The `font.char_size.y` is usually less than `font.line_height`, which only considers the typically highest and lowest characters in English. Good bounds for centered text are `xy(text_width(font, text), font.line_height)`. Some accents or descenders for exceptional cases may stick out of these bounds vertically. ### Post Effects The final image drawn can be transformed in limited ways during scan out to the display, as if it were a sprite being drawn to the screen. Setting any post effects may slow down rendering slightly. `get_post_effects()` : Return the current post effects in a form that can be passed to `set_post_effects()`. `set_post_effects(args)` : The arguments have the following fields, all optional. nil values default to their previous value. Invoke `reset_post_effects()` first for a clean set. - `background` is an `rgba()` to draw in the background behind the new frame. The `a` component controls how opaque the background is. Setting `background.a = 0` allows new frames to be blended on top of old ones for a motion blur effect. - `color` is an `rgba()` to combine with the the new frame before it is composited. Setting the `a` to 0 disables the color. - `blend_mode` is one of the following strings: `"source-over"`, `"difference"`, `"hue"`, `"multiply"` describing how the `color` affects the frame. - `scale` is an `xy` for how to stretch the new frame - `angle` is a counter-clockwise angle in radians to rotate the image about its center by - `pos` is an `xy` translation from the center, with +y = down - `opacity` is the amount of opacity to use for the new frame. If `background.a` and `opacity` are both less than 1 then the new and previous frames blend together `reset_post_effects()` : Restore the defaults, which directly composite each frame. Map --------------------------------------------------------------------------- A map asset has the following fields. The sprites in the map can be changed at runtime (maps are the only mutable assets). Use `deep_clone(map)` to make a copy of a map at runtime if you will want the original and plan to mutate the asset. `map[x][y]` : The sprite at `x, y` in integer map coordinates in layer 0, or `nil` if empty. `map.layer[L]` : A 2D array of the contents of layer `L`. `map.layer[L][x][y]` : The sprite at `x`, `y` in layer `L`, or `nil` if empty. The elements *can* be changed at runtime. `map.size` : `xy()` size in map coordinates (not pixels). `map.spritesheet_table` : A table mapping TMX tile set names to spritesheets for this map. `map.spritesheet` : For maps with a single spritesheet, this is the spritesheet. `map.sprite_size` : The `xy()` size of source sprites in pixels. `map.wrap_x` : If true, the map wraps horizontally. Array access does not automatically wrap, but function such as `draw_map()`, `find_map_path()`, and `get_map_pixel_color()` will implement wrapping. `map.wrap_y` : If true, the map wraps vertically. Array access does not automatically wrap, but function such as `draw_map()`, `find_map_path()`, and `get_map_pixel_color()` will implement wrapping. `map.z_offset` : Amount to add to each layer index when computing a z value for rendering. `layer = (z - map.z_offset) / map.z_scale`; `z = layer * map.z_scale + map.z_offset`. See also `transform_ws_to_map_space()` and `transform_map_space_to_ws()`. `map.z_scale` : Amount to multiply each layer index to compute a z value for rendering. `layer = (z - map.z_offset) / map.z_scale`; `z = layer * map.z_scale + map.z_offset`. See also `transform_ws_z_to_map_layer()` and `transform_map_layer_to_ws_z()`. Any other custom properties set on the map in the TMX file are added to this set of properties. The following functions relate maps, pixels, and sprites. In them, a "pixel coordinate" is in the _pre-transformed_ space in which graphics commands operate and a "map coordinate" is in the space of the map indices. The map's z-axis corresponds to layers. `draw_map(args)` : Draw the map using the named argument object. `draw_map(map, min_layer default 0, max_layer default length(map.layer), replacement_array default ∅, pos default xy(0, 0), angle default 0, scale default xy(1, 1), z default 0)` : Draws the map with the current transform. If there is no transform, the map is drawn with the first tile's center at (0, 0), which means that the tile will be half off the screen. If specified, `min_layer` and `max_layer` determine the inclusive range of layers to draw. Map rendering ignores skew transformations...typically the skew will be implicit in the map's layout and rendering. If `replacement_array` is specified, it must be an even length array of the form `[from0, to0, from1, to1, ...]`. Each `from` value is a sprite in the map. It will be replaced during drawing with the corresponding `to` value. The `to` values may also be `nil`. The if specified in the source `.json` file, the map will wrap appropriately horizontally or vertically when drawn, if it is large enough to covers at least 1/3 of the current clipping area. The `pos`, `angle`, and `scale` apply the position of the map as if it was a giant object, with the origin centered at the center of tile (0, 0). Using a non-default `angle` and `scale` will approximately double the cost of drawing the map. `find_map_path(map, startXY, goalXY, edgeCost, costLayer = 0)` : Specialized version of `find_path` for maps. The start and end positions are rounded down to the nearest integer map coordinates. The `edgeCost` is either a function or an array. The function returns an array of map coordinates to visit or `nil` if no traversable path exists. The function version is `def edgeCost(A, B, map)`. It returns the cost of traversing from `A` to `B` in the map, where each is an `xy()`. That cost should always be nonnegative. It should be 1 for a typical edge, `infinity` for an edge that is not traversable, and higher or lower than 1 for edges of varying difficulty such as walking through rough terrain or downhill. The array version of `edgeCost` is an array of pairs of the form `[sprite0, cost0, sprite1, cost1, ...]`. Each cost corresponds to entering that sprite on `map.layer[costLayer]`. These are the `B` values from `edgeCost`. Sprites that are not specified in the array cost 1 to traverse, and it costs `infinity` to leave the map bounds. `get_map_pixel_color(map, map_coord, min_layer default -infinity, max_layer_exclusive default +infinity,replacement_array default ∅, result default ∅, invert_sprite_y default false)` : Returns the color of the pixel in `map` at the corresponding `map_coord` and all layers between `min_layer` and `max_layer_exclusive`. If an `rgba()` value `result` is provided, then that object is mutated and returned to avoid memory allocation. Returns `nil` for out of bounds values and empty sprites if `result` is not specified, and sets `result.a = 0` in those cases if it is present. See also `get_map_pixel_color_by_ws_coord()`. If `invert_sprite_y` is true, then individual sprites pixels are read upside down. This is needed in rare cases where the transform's y direction was changed between when the map itself was drawn and when the pixel was read. `get_map_pixel_color_by_ws_coord(map, ws_coord, ws_z_min default -infinity, ws_z_max_exclusive default +infinity, replacement_array default ∅, result default nil)` : Returns the pixel color in `map` at the corresponding `ws_coord` by compositing all layers between `ws_z_min` and `ws_z_max_exclusive`. The result is guaranteed to match what was drawn by `draw_map()`. If `result` is specified, that `rgba()` value is mutated and returned instead of allocating a new color. Returns `nil` for out of bounds values and empty sprites, or a result with `result.a = 0` if `result` is specified. See also `get_map_pixel_color()`. `get_map_sprite(map, map_coord, layer default 0, replacement_array default ∅)` : Returns the sprite in `map` at the corresponding `map_coord` and `layer` using rounding. Returns `nil` for out of bounds values. See also `get_map_sprite_by_ws_coord()`. `get_map_sprite_by_ws_coord(map, ws_coord, ws_z default 0, replacement_array default ∅)` : Returns the sprite in `map` at the corresponding `draw_coord` and `ws_z` using `transform_ws_to_map_space()` and rounding to compute the coordinates. Returns `nil` for out of bounds values. See also `get_map_sprite()`. `set_map_sprite(map, map_coord, sprite, layer default 0)` : Sets the corresponding map sprite. Does nothing if `map_coord` is out of bounds. `set_map_sprite_by_ws_coord(map, ws_point, sprite, ws_z default 0)` : Sets the corresponding map sprite. Does nothing if `ws_point` is out of bounds. `transform_ws_to_map_space(map, ws_point)` : Returns the _fractional_ map coordinates of `ws_point`. See also `transform_map_space_to_ws()`. Note that integer map coordinates are at the corners of map tiles unless the map JSON has an `offset`. To account for a map that is rendered by `draw_map()` with its own `pos`, `angle`, and `scale`, use `transform_ws_to_map_space(map, transform_to(pos, angle, scale, ws_coord))`. `transform_ws_z_to_map_layer(map, ws_z)` : Using the current transformation, returns the _fractional_ map layer of `z`. `transform_map_layer_to_ws_z(map, L)` : Returns the `z` value that will be used for `map` under the current transformation. `transform_map_space_to_ws(map, map_coord)` : Returns the draw coordinates of `map_coord`. Integer map_coords correspond to the _centers_ of tiles if the offset on the map is zero (the default). (Centers will also be fractional _pixels_ for even map tile sizes). See also `transform_ws_to_map_space()` and `get_map_pixel_color()`. To account for a map that is rendered by `draw_map()` with its own `pos`, `angle`, and `scale`, use `transform_from(pos, angle, scale, transform_map_space_to_ws(map, map_coord))`. Frame Hooks ---------------------------------------------------------- Frame hooks are useful for registering animation callbacks that happen at the beginning of every frame or after a set number of frames. The order of execution between frame hooks is undefined and can change as hooks expire. The transform for a frame hook is whatever was set at the end of the previous frame. When drawing, use `z` arguments to ensure that drawn objects overlap in the desired order regardless of the order in which drawing executes. `add_frame_hook(callback, end_callback, frames, run_in_mode default get_mode(), data default nil)` : Register a `callback` function to run every frame for the given number of `frames`. The return value of `add_frame_hook()` is a hook that can be passed to `remove_frame_hook()`. - `callback`: `def callback(framesleft, total_frames, data)`, runs every frame. `framesleft` will be `total_frames - 1` on the first frame and `0` on the last one. This argument may be `nil`. If the callback returns `true`, the hook is removed without running the `end_callback`, otherwise it keeps running. - `end_callback`: `def end_callback(data)`, runs on the last frame. Can be `nil`. - `frames`: Number of frames to run for. May be `inf`. - `run_in_mode`: Only execute while the game is in this mode. Use `nil` to run in every mode. See also `sequence()` and `delay()` for common cases. `delay(callback, delay_frames default 0, data default nil)` : Same as `add_frame_hook(nil, callback, delay_frames, nil, data)`. `remove_frame_hook(hook)` : Remove this frame hook immediately, without executing its `end_callback`. If the hook has already ended or is not present, nothing happens. `remove_frame_hooks_by_mode(mode)` : Remove all frame hooks that are locked to the `mode`. Use `nil` to remove all hooks with no mode at all. Do not invoke the `endCallback`s on these hooks. `sequence(...)` : Add a series of frame hooks that run in the current mode. Returns a master hook that can be used with `remove_frame_hook()` to cancel the entire sequence. Each argument may be either a function, `nil`, a number of frames to skip, or `{callback: function, end_callback: function, frames: number, data: (any value)}`. If not `nil`, the callback signature is `def callback(frames_left, total_frames, data)`. If not `nil`, the end_callback signature is `def end_callback(data)` and it runs immediately after the last `callback` for that sequence entry. The callbacks run for the specified number of `frames`, rounded if fractional. If the `frames` is less than 1, then then they do not run at all. Example: `sequence(6, draw_explosion, {callback: draw_fire, frames: 20}, {callback: draw_smoke, frames: 4, end_callback: cleanup})`. Skips 6 frames, runs `draw_explosion` after the 7th, `draw_fire` after each of the next 20 frames after that, `draw_smoke` for the next 4 frames after _that_, and then `cleanup` immediately after the last `draw_smoke` in the same frame. If a callback returns the special value `sequence.NEXT`, then the sequence runs the `end_callback` for that entry and advances to the next step regardless of the frame count. If it returns `sequence.BREAK`, then the sequence immediately terminates and does not run the `end_callback`. All other return values are ignored. There is no `begin_callback`. Use an `end_callback` on the previous entry or immediately execute the code before `sequence()` if you need one. A `sequence` entry can itself trigger a new sequence or `delay()`, although be careful not to trigger uncontrolled recursive chains. Note that `sequence(...array)` allows passing an array of the individual callbacks instead of as separate parameters. Time ---------------------------------------------------------- Quadplay always runs your `frame` event code at 60 fps. You can hardcode this assumption into your program. For example, the built-in simulation routines all use "frame" as the unit of time (and "pixel" as the unit of distance). The _display_ may not refresh at 60 fps if your program is consuming too much computation, because the runtime will start dropping graphics calls to maintain the simulation rate. It will scale all the way down to 12 fps on refresh while still trying to execute your main loop at 60 fps so that simulation is unaffected. `game_frames` : Number of elapsed 1/60 frames since the program started. The program may mutate this global variable. `mode_frames` : Number of elapsed 1/60 frames since the current mode was most recently entered. The program may mutate this global variable. `now()` : Returns a time in seconds that is accurate to at least one millisecond. The origin for the time is arbitrary but constant per program run. Do not use this time for simulation because it will have inconsistent jumps between frames dues to frame rate scaling. `local_time()` : Returns an object with the following properties, set in the current time zone: - `year`, e.g., 2019 - `month` 0-11 - `day` 1-31 - `hours` 0-23 - `minute` 0-59 - `second` 0-59 - `millisecond` 0-999 - `weekday` 0-6, where 0 = Sunday - `day_second` seconds since midnight, including a fractional part - `timezone` minutes from UTC See `format_number()` for the various clock formatting options for numbers in seconds, and `now()` for a high-precision timer. Path Finding ---------------------------------------------------------- `find_path(start_node, goal_node, estimate_path_cost, edge_cost, get_neighbors, node_to_ID, graph_obj default ∅)` : `find_path()` is a general-purpose path-finding routine for any kind of world representation. It uses the "A*" (A-star) algorithm. _See also `find_map_path()` for a simpler, map-specific version._ The return value is an array of nodes to traverse to follow the shortest path discovered. The first node in the returned path will be the `start_node` and the last node will be the `goal_node`. `find_path()` will return `∅` if no path exists between the `start_node` and `goal_node`. To recover the cost of the path, use the idiom: ````````````` PyxlScript let cost = 0 for i < size(path) - 1: cost += edge_cost(path[i], path[i + 1]) ````````````` The arguments are below. See the example of using these on a map for a better understanding of how they are typically computed. `start_node` : The starting location, in your chosen node representation. `goal_node` : The ending location, in your chosen node representation. `estimate_path_cost(nodeA, nodeB, graph_obj)` : Returns a numerical estimate of the cost for the path between `nodeA` and `nodeB`. For example, the straight line distance. The more accurate this estimate is, the faster that the algorithm will run. If it returns 0 for all inputs, then the algorithm will run in the worst case quadratic time but is guaranteed to find the exact shortest path instead of an approximation. `edge_cost(nodeA, nodeB, graph_obj)` : The actual cost of going from A to B, which are guaranteed to be neighbors. `get_neighbors(node, graph_obj)` : Returns an array of all neighbor nodes reachable from node. It is not required that neighbors are bidirectional. For example, a ledge may create an edge traversable in only one direction `node_to_ID(node, graph_obj)` : Returns a compact integer or string representation of the node, which is required internally by the algorithm for maintaining a table of nodes. `graph_obj` : Any object that represents your world graph. This can be `nil` if the other function arguments use global state. ### Map Example ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PyxlScript const sprite = map.spritesheet_table["mapTiles"] const wall = sprite[0][0] const swamp = sprite[0][1] const dir = [xy(-1, 0), xy(0, -1), xy(0, 1), xy(1, 0)] // Assume all edges cost 1 def estimate_path_cost(A, B, map): return |B.x - A.x| + |B.y - A.y| // Moving through swamps is slow def edge_cost(A, B, map): return 1 + (get_map_sprite(map, A) == swamp) // Block traversal at map edges and walls def get_neighbors(A, map): const neighbors = [] for d in dir: const B = A + d; const s = get_map_sprite(map, B) if s and s != wall: push(neighbors, B) return neighbors // Map to integer indices def node_to_ID(A, map): return A.x + map.width * A.y // In map coordinates let start_node = xy(1, 1) let goal_node = xy(20, 20) let path = find_path(start_node, goal_node, estimate_path_cost, edge_cost, get_neighbors, node_to_ID, map) // Print the path for P in path: debug_print(P) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Debugging ------------------------------------------------------------------------------------ The following are provided for debugging and development support only. They may do nothing on some platforms and may crash on others. These APIs are subject to change. None of these are regular functions or variables. They are special syntax that cannot be bound as values. For enabling or disabling large sets of debugging statements at once in a program, they can be masked using standard boolean operators. For example: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PyxlScript // Error on unimplemented routine todo("Implement explosions") // To customize the startup mode per user when working on a team, // add a conditional set_mode() to your program's general startup mode (for example, Title) if IDE_USER == "forrester": set_mode(Inventory) because "Forrester is debugging inventory" // Make a global flag that jumps to gameplay in a debug build by putting // this in your Title or other startup mode if DEBUG: set_mode(Play) because "in DEBUG build" // Only error if your own debug_graphics constant is true. // You can change a constant from the IDE while the program // is running! debug_graphics and todo("Implement explosions") // Error if running in the IDE using a local quadplay server // and the current developer's local machine username is "stephan" (IDE_USER == "stephan") and todo("Implement explosions") // Only print if debug_graphics is true. debug_graphics and debug_print("Running iteration" + i) // Print when your own LOG_LEVEL constant is greater than 5 (LOG_LEVEL > 5) and debug_print("Simulating") // Print when the 2nd bit of your own LOG_MASK constant // is set (LOG_MASK bitand 0b010) and debug_print(format_number(x, "%")) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `assert(x, msg default "Assertion Failed")` : If `x` is true, does nothing. If `x` is false, creates the error `msg`. Assertions can be completely disabled from the Tools menu to make them have zero cost. In the current implementation, the `msg` is always evaluated when assertions are enabled even if the assertion test passes. `debug_pause()` : Pause program execution. `debug_print(x, ...)` : If `x` is a string, directly prints it to the Output window, otherwise prints `unparse(x)` to the Output window. When multiple arguments are provided they are processed individually with spaces between them. Debug print statements can be completely disabled from the Output window, which causes them to consume no processing time. In the output pane, click on the output to go to the line that produced it in the code editor. `debug_watch(expr)` : Make the expression appear along with its value at the time that `debug_watch` executs in the Watch pane of the debugger. If there are multiple expressions that are syntactically identical, they will be collapsed and only the last to execute each frame will be shown. This is *not* a function. It is a special syntax. You may not pass the `debug_watch` command as if it were a function. In the watch pane, click on the expression to go to the line that contains it in the code editor. `draw_bounds(e, color default gray(60%), recurse default true)` : Render a debugging view of the bounds of an entity or other object `e` with `pos` and optional `angle`, `size`, `scale`, and `shape` properties. If `recurse` is true, descend into any `e.child_array` field. `draw_physics(physics)` : Render a debugging view of the physics system `IDE_USER` : A string constant bound to the `USER` environment variable for the operating system. This is "anonymous" when not running the IDE or a quadplay local server. `todo` : Same as `todo()` `todo(message default "")` : If todo errors are enabled in the IDE, reports the error `"Unimplemented: " + message`, otherwise does nothing. The `message` must be a compile-time constant string, similar to `because`. Persistence ----------------------------------------------------------- The local persistence API stores values in the browser's local storage. It is tied to a specific web browser and the URL from which quadplay✜ is hosted, as well as the URL of the game. Some browsers will automatically synchronize local storage across computers, however. The storage API performs string manipulation and can be slow relative to other commands. Avoid using it every frame. This API is useful for save games, GUI state defaults, high scores, and persistent worlds. `load_local(key)` : The key is loaded and deserialized with `parse()` to return an object that was previously saved with `save_local()`. If the `key` is not found, then `∅` is returned. `save_local(key, value)` : The value will be serialized to a string with `unparse()` and then stored associated with `key` and the URL of the game. Save a value of `∅` to delete the key. There is a maximum size of 2048 characters for the unparsed value for each key and a maximum size of 128 keys per application. There is no way for two different games to read each other's values. Raw Device Access ----------------------------------------------------------- `device_control(command, ...)` : Reserved function for executing device-specific features such as the game launcher, GPIO, and alternative input devices. `command` is a string telling the host which control feature to execute, and the remaining arguments are passed to it. All `device_control()` commands may change in future releases and may fail silently on any given platform or when not using the IDE.
Parameters Effect
`"start_GIF_recording"` Begin GIF recording.
`"stop_GIF_recording"` End GIF recording. When the compression completes, the GIF will appear in a new tab.
`"start_preview_recording"` Begin preview video recording. There is no "stop" command because this terminates automatically after a set time.
`"take_screenshot"` Take a screenshot and download it to the local disk.
`"take_label_image"` Capture the center of the image and save it to disk, overwriting the label128 and label64 images (only works when running in the IDE on an editable project).
`"set_pad_type", index, "type"` Set `gamepad_array[index].type` and the corresponding prompts. There is no "get" version because you can read the property directly from the gamepad object.
`"get_analog_axes", player_index default 0, stick_index default 0` Return an `xy()` of the analog axis values for `gamepad_array[player_index]`, without D-pad snapping and unlocking reading of the values beyond the first stick. Needed for accessing Atari paddles, car pedals, steering wheels, and flight stick throttles in a meaningful way. There is currently no way to read the D-pad directly (it will be overriden by the analog axis if moved) or to read the analog triggers or other axes.
`"get_mouse_state"` Return `{x:number, y:number, dx:number, dy:number, xy:xy(...), dxy:xy(...), button_array:[...]}` for the current mouse position and buttons. Each element of `button_array` is 0 or 1. There are at least two buttons, but may be more.
`"set_debug_flag", flagname, bool` Set the enabled state of an IDE debugging flag. The flagnames are `"entity_bounds"`, `"assert"`, `"debug_print"`, `"debug_watch"`, `"physics"`.
`"get_debug_flag", flagname` Return the state of an IDE debugging flag.
`"console.dir", ...` Execute `console.dir(...)` if running in a web browser.
`"save", filename, value, callback` Serializes `value` to JSON using WorkJSON extensions and writes to `filename` on disk in the same directory as the game.json file. `filename` cannot contain slashes and must end in `.json`. This is intended for creating development tools within quadplay itself, for example, level editors, NPC ghost tracks, and demo sequences. The JSON files can be loaded as game constants with the `raw` type. If present, `callback` is invoked with `value, filename` when the asynchronous save is complete. This will only work with the IDE enabled and a quadplay server.
`"load", filename, callback`Loads `filename` and (asynchronously) runs the callback with the arguments `value, filename` when the load is complete. This will only work with the IDE enabled and a quadplay server.
Intrinsics ----------------------------------------------------------- quadplay✜ can execute about 10,000 vector operations per frame even on embedded platforms. This is sufficient to program most mathematical routines in a readable way and intrinsics are is not required. For some _very_ math intensive routines, such as those with thousands of particles, it is necessary to run slightly faster at the expense of code that is harder to maintain. In these cases, use the function calls below, which produce inline assembly instructions for the quadplay✜ platform. These calls have no argument checking. The vector functions execute about twice as fast as regular overloaded operator arithmetic. The scalar versions may be substantially faster than overloaded operators. Intrinsics are never needed on literal values. `5 + 6` compiles to the same code as `ADD(5, 6)`, for example. Intrinsics are not provided for exponents, square root, bit shifts, trigonometric, modulo (remainder) and other operations that naturally compile with maximum efficiency. `ADD(s1, s2)` : Returns the scalar sum. `DIV(s1, s2)` : Returns the scalar quotient. `MAD(s1, s2, s3)` : Returns `s1 * s2 + s3`. `MUL(s1, s2)` : Returns the scalar product. `SUB(s1, s2)` : Returns the scalar difference. `ABS(s1)` : Returns the absolute value of a scalar. `MAX(s1, s2)` : Returns the larger scalar. `MIN(s1, s2)` : Returns the smaller scalar. `LERP(s1, s2, s3)` : Returns `lerp(s1, s2, s3)`. `SIGN(s1)` : Returns +1, -1, or 0 as the sign of the scalar. `CLAMP(s, slo, shi)` : Clamps `s` to [`slo`, `shi`] where all are scalar and returns the result. `RGB_ADD_RGB(srcrgb, srcrgb, dstrgb)` : Element addition. `RGB_SUB_RGB(srcrgb1, srcrgb2, dstrgb)` : Element subtraction. `RGB_MUL_RGB(srcrgb1, srcrgb2, dstrgb)` : Element multiplication. `RGB_DIV_RGB(srcrgb1, srcrgb2, dstrgb)` : Element division. `RGB_MUL(srcrgb, srcs, dstrgb)` : Vector-scalar product. `RGB_DIV(srcrgb, srcs, dstrgb)` : Vector-scalar quotient. `RGB_DOT_RGB(srcrgb1, srcrgb2)` : Returns the scalar result. `RGB_LERP(srcrgb1, srcrgb2, s1, dstrgb)` : Interpolates between the two source values and returns the result in `dstrgb`. The destination may be the same as one of the sources. `RGBA_ADD_RGBA(srcrgba1, srcrgba2, dstrgba)` : Element addition. `RGBA_SUB_RGBA(srcrgba1, srcrgba2, dstrgba)` : Element subtraction. `RGBA_MUL_RGBA(srcrgba1, srcrgba2, dstrgba)` : Element multiplication. `RGBA_DIV_RGBA(srcrgba1, srcrgba2, dstrgba)` : Element division. `RGBA_MUL(srcrgba, srcs, dstrgba)` : Vector-scalar product. `RGBA_DIV(srcrgba, srcs, dstrgba)` : Vector-scalar quotient. `RGBA_DOT_RGBA(srcrgba1, srcrgba2)` : Returns the scalar result. `RGBA_LERP(srcrgba1, srcrgba2, s1, dstrgba)` : Interpolates between the two source values and returns the result in `dstrgba`. The destination may be the same as one of the sources. `XY_ADD_XY(srcxy1, srcxy2, dstxy)` : Element addition. `XY_SUB_XY(srcxy1, srcxy2, dstxy)` : Element subtraction. `XY_MUL_XY(srcxy1, srcxy2, dstxy)` : Element multiplication. `XY_DIV_XY(srcxy1, srcxy2, dstxy)` : Element division. `XY_MUL(srcxy1, srcs2, dstxy)` : Vector-scalar product. `XY_DIV(srcxy1, srcs2, dstxy)` : Vector-scalar quotient. `XY_DOT_XY(srcxy1, srcxy2)` : Returns the scalar result. `XY_CRS_XY(srcx1, srcx2)` : 2D cross product (z component of treating as a 3D cross product). Returns the scalar result. `XZ_ADD_XZ(srcxz1, srcxz2, dstxz)` : Element addition. `XZ_SUB_XZ(srcxy1, srcxz2, dstxz)` : Element subtraction. `XZ_MUL_XZ(srcxz1, srcxz2, dstxz)` : Element multiplication. `XZ_DIV_XZ(srcxz1, srcxy2, dstxz)` : Element division. `XZ_MUL(srcxz1, srcs2, dstxz)` : Vector-scalar product. `XZ_DIV(srcxz1, srcs2, dstxz)` : Vector-scalar quotient. `XZ_DOT_XZ(srcxz1, srcxz2)` : Returns the scalar result. `XYZ_ADD_XYZ(srcxyz1, srcxyz2, dstxyz)` : Element addition. `XYZ_SUB_XYZ(srcxyz1, srcxyz2, dstxyz)` : Element subtraction. `XYZ_MUL_XYZ(srcxyz1, srcxyz2, dstxyz)` : Element multiplication. `XYZ_DIV_XYZ(srcxyz1, srcxyz2, dstxyz)` : Element division. `XYZ_MUL(srcxyz1, srcs2, dstxyz)` : Vector-scalar product. `XYZ_DIV(srcxyz1, srcs2, dstxyz)` : Vector-scalar quotient. `XYZ_DOT_XYZ(srcxyz1, srcxyz2)` : Returns the scalar result. `XYZ_CRS_XYZ(srcxyz1, srcxyz2, dstxyz)` : Cross product. `dstxyz` can be the same object as one of the input arguments. `MAT2x2_MATMUL_XY(src2x2, srcxy, dstxy)` : Multiply matrix `src2x2` represented as `[[m11, m12], [m21, m22]]` by vector `(srcxy.x, srcxy.y)` and put the result in `dstxy`, which can be the same object as `srcxy`. `MAT2x2_MATMUL_XZ(src2x2, srcxz, dstxz)` : Multiply matrix `src2x2` represented as `[[m11, m12], [m21, m22]]` by vector `(srcxy.x, srcxy.z)` and put the result in `dstxz`, which can be the same object as `srcxz`. `MAT3x3_MATMUL_XYZ(src3x3, srcxyz, dstxyz)` : Multiply matrix `src3x3` represented as an array of length three row arrays, each of length three by vector `(srcxyz.x, srcxyz.y, srcxyz.z)` and put the result in `dstxyz`, which can be the same object as `srcxyz`. `MAT3x4_MATMUL_XYZ(src3x4, srcxyz, dstxyz)` : Multiply matrix `src3x4` represented as an array of length three row arrays of length four by vector `(srcxyz.x, srcxyz.y, srcxyz.z, 1)` and put the result in `dstxyz`, which can be the same object as `srcxyz`. You can use `MAT3x3_MATMUL_XYZ()` on the same `src3x4` to effectively multiply by `(srcxyz.x, srcxyz.y, srcxyz.z, 1)`. `MAT3x4_MATMUL_XYZW(src3x4, srcxyzw, dstxyzw)` : Multiply matrix `src3x4` represented as an array of length three row arrays of length four by vector `(srcxyzw.x, srcxyzw.y, srcxyzw.z, srcxyzw.w)` and put the result in `dstxyzw`, which can be the same object as `srcxyzw`. The `dstxyzw.w = srcxyzw.w`. Built-in Assets ==================================================================================== The quadplay✜ console provides thousands of built-in assets so that you can start creating games immediately and make games that have a small size. All assets are Creative Commons licensed and automatically include their license and copyright information in the `CREDITS` constant when loaded. Sprites ------------------------------------------------------------------------------------ ### Kenney ![`quad://sprites/kenney-blocks-16x16.sprite.json`](../sprites/kenney-blocks-16x16.png) ![`quad://sprites/kenney-ui-16x16.sprite.json`](../sprites/kenney-ui-16x16.png) ![`quad://sprites/kenney-alien-red-16x32.sprite.json`](../sprites/kenney-alien-red-16x32.png) ![`quad://sprites/kenney-alien-yellow-16x32.sprite.json`](../sprites/kenney-alien-yellow-16x32.png) ![`quad://sprites/kenney-alien-green-16x32.sprite.json`](../sprites/kenney-alien-green-16x32.png) ![`quad://sprites/kenney-alien-blue-16x32.sprite.json`](../sprites/kenney-alien-blue-16x32.png) ![`quad://sprites/kenney-alien-purple-16x32.sprite.json`](../sprites/kenney-alien-purple-16x32.png) ![`quad://sprites/kenney-cartography-64x64.sprite.json`] ### Ninja ![`quad://sprites/ninja-black-32x32.sprite.json`](../sprites/ninja-black-32x32.png) ![`quad://sprites/ninja-red-32x32.sprite.json`](../sprites/ninja-red-32x32.png) ![`quad://sprites/ninja-yellow-32x32.sprite.json`](../sprites/ninja-yellow-32x32.png) ![`quad://sprites/ninja-blue-32x32.sprite.json`](../sprites/ninja-blue-32x32.png) ![`quad://sprites/ninja-purple-32x32.sprite.json`](../sprites/ninja-purple-32x32.png) ![`quad://sprites/ninja-white-32x32.sprite.json`](../sprites/ninja-white-32x32.png) ![`quad://sprites/ninja-pink-32x32.sprite.json`](../sprites/ninja-pink-32x32.png) ![`quad://sprites/ninja-bow-32x32.sprite.json`](../sprites/ninja-bow-32x32.png) ![`quad://sprites/ninja-sword-32x32.sprite.json`](../sprites/ninja-sword-32x32.png) ![`quad://sprites/ninja-idle-64x64.sprite.json`](../sprites/ninja-idle-64x64.png) ### Dawnlike ![`quad://sprites/dawnlike-level-16x16.sprite.json`](../sprites/dawnlike-level-16x16.png) ![`quad://sprites/dawnlike-npcs-16x16.sprite.json`](../sprites/dawnlike-npcs-16x16.png) ![`quad://sprites/dawnlike-engineer-16x16.sprite.json`](../sprites/dawnlike-engineer-16x16.png) ![`quad://sprites/dawnlike-generic-16x16.sprite.json`](../sprites/dawnlike-generic-16x16.png) ![`quad://sprites/dawnlike-mage-16x16.sprite.json`](../sprites/dawnlike-mage-16x16.png) ![`quad://sprites/dawnlike-paladin-16x16.sprite.json`](../sprites/dawnlike-paladin-16x16.png) ![`quad://sprites/dawnlike-rogue-16x16.sprite.json`](../sprites/dawnlike-rogue-16x16.png) ![`quad://sprites/dawnlike-warrior-16x16.sprite.json`](../sprites/dawnlike-warrior-16x16.png) ![`quad://sprites/dawnlike-ui-16x16.sprite.json`](../sprites/dawnlike-ui-16x16.png) ### Space ![`quad://sprites/space-atmosphere.sprite.json`](../sprites/space-atmosphere.png) ![`quad://sprites/space-planet.sprite.json`](../sprites/space-planet.png) ![`quad://sprites/space-moon.sprite.json`](../sprites/space-moon.png) ![`quad://sprites/space-ring.sprite.json`](../sprites/space-ring.png) ### Action Hero ![`quad://sprites/sportscar-32x64.sprite.json`](../sprites/sportscar-32x64.png) ![`quad://sprites/road_tiles_64.sprite.json`](../sprites/road_tiles_64.png) ![`quad://sprites/chopper-body-44x99.sprite.json`](../sprites/chopper-44x99.png) ![`quad://sprites/tank-body-46x85.sprite.json`](../sprites/tank-46x85.png) ![`quad://sprites/top-runner-16x25.sprite.json`](../sprites/top-runner-16x25.png) ![`quad://sprites/top-runner-32x50.sprite.json`](../sprites/top-runner-32x50.png) ### Other ![`quad://sprites/miniroguelike-8x8.sprite.json`](../sprites/miniroguelike-8x8.png) ![`quad://sprites/ortho-city-32x16.sprite.json`](../sprites/ortho-city-32x16.png) ![`quad://sprites/controllers-64x44.sprite.json`](../sprites/controllers-64x44.png) ![`quad://sprites/controllers-32x22.sprite.json`](../sprites/controllers-32x22.png) ![`quad://sprites/explosion-realistic-128x128.sprite.json`](../sprites/explosion-realistic-128x128.png) ![`quad://sprites/beast-soldier-32x32.sprite.json`](../sprites/beast-soldier-32x32.png) ![`quad://sprites/shapes-32x32.sprite.json`](../sprites/shapes-32x32.png) Fonts ------------------------------------------------------------------------------------ ![`quad://fonts/robot-18.font.json`](../fonts/robot-18.png) ![`quad://fonts/octant-17.font.json`](../fonts/octant-17.png) ![`quad://fonts/deja-15.font.json`](../fonts/deja-15.png) ![`quad://fonts/blackletter-14.font.json`](../fonts/blackletter-14.png) ![`quad://fonts/broderick-14.font.json`](../fonts/broderick-14.png) ![`quad://fonts/cpc-14.font.json`](../fonts/cpc-14.png) ![`quad://fonts/ivanhoe-12.font.json`](../fonts/ivanhoe-12.png) ![`quad://fonts/suchet-12.font.json`](../fonts/suchet-12.png) ![`quad://fonts/hauer-12.font.json`](../fonts/hauer-12.png) ![`quad://fonts/federation-11.font.json`](../fonts/federation-11.png) ![`quad://fonts/good-neighbors-9.font.json`](../fonts/good-neighbors-9.png) ![`quad://fonts/stencil-9.font.json`](../fonts/stencil-9.png) ![`quad://fonts/robot-9.font.json`](../fonts/robot-9.png) ![`quad://fonts/deja-9.font.json`](../fonts/deja-9.png) ![`quad://fonts/fool-9.font.json`](../fonts/fool-9.png) ![`quad://fonts/bogart-9.font.json`](../fonts/bogart-9.png) ![`quad://fonts/runes-9.font.json`](../fonts/runes-9.png) ![`quad://fonts/suchet-9.font.json`](../fonts/suchet-9.png) ![`quad://fonts/thompson-8.font.json`](../fonts/thompson-8.png) ![`quad://fonts/roman-8.font.json`](../fonts/roman-8.png) ![`quad://fonts/wright-8.font.json`](../fonts/wright-8.png) ![`quad://fonts/deja-8.font.json`](../fonts/deja-8.png) ![`quad://fonts/pryce-7.font.json`](../fonts/pryce-7.png) ![`quad://fonts/broderick-7.font.json`](../fonts/broderick-7.png) ![`quad://fonts/cga-7.font.json`](../fonts/cga-7.png) ![`quad://fonts/cruise-7.font.json`](../fonts/cruise-7.png) ![`quad://fonts/connelly-7.font.json`](../fonts/connelly-7.png) ![`quad://fonts/deja-7.font.json`](../fonts/deja-7.png) ![`quad://fonts/scoreboard-7.font.json`](../fonts/scoreboard-7.png) ![`quad://fonts/hauer-6.font.json`](../fonts/hauer-6.png) ![`quad://fonts/deja-6.font.json`](../fonts/deja-6.png) ![`quad://fonts/scoreboard-6.font.json`](../fonts/scoreboard-6.png) ![`quad://fonts/scoreboard-5.font.json`](../fonts/scoreboard-5.png) ![`quad://fonts/deja-5.font.json`](../fonts/deja-5.png) ![`quad://fonts/nano-5.font.json`](../fonts/nano-5.png) ![`quad://fonts/deja-4.font.json`](../fonts/deja-4.png) ![`quad://fonts/nano-4.font.json`](../fonts/nano-4.png) ![`quad://fonts/nano-3.font.json`](../fonts/nano-3.png) ![`quad://fonts/deja-3.font.json`](../fonts/deja-3.png) ![`quad://fonts/nanob-3.font.json`](../fonts/nanob-3.png) Sounds ------------------------------------------------------------------------------------ ### Music ![`quad://sounds/music-opening.sound.json`](../sounds/music-opening.mp3) ![`quad://sounds/music-race.sound.json`](../sounds/music-race.mp3) ![`quad://sounds/music-moon.sound.json`](../sounds/music-moon.mp3) ![`quad://sounds/music-boss.sound.json`](../sounds/music-boss.mp3) ![`quad://sounds/music-vice.sound.json`](../sounds/music-vice.mp3) ![`quad://sounds/music-saturday.sound.json`](../sounds/music-saturday.mp3) ![`quad://sounds/music-brawl.sound.json`](../sounds/music-brawl.mp3) ![`quad://sounds/music-credits.sound.json`](../sounds/music-credits.mp3) ![`quad://sounds/music-days.sound.json`](../sounds/music-days.mp3) ![`quad://sounds/music-viper.sound.json`](../sounds/music-viper.mp3) ### Loops ![`quad://sounds/loop-arcade.sound.json`](../sounds/loop-arcade.mp3) ![`quad://sounds/loop-mega.sound.json`](../sounds/loop-mega.mp3) ![`quad://sounds/loop-edm.sound.json`](../sounds/loop-edm.mp3) ![`quad://sounds/loop-munster.sound.json`](../sounds/loop-munster.mp3) ![`quad://sounds/loop-tastic.sound.json`](../sounds/loop-tastic.mp3) ![`quad://sounds/loop-frantic.sound.json`](../sounds/loop-frantic.mp3) ![`quad://sounds/loop-soar.sound.json`](../sounds/loop-soar.mp3) ![`quad://sounds/loop-agent.sound.json`](../sounds/loop-agent.mp3) ![`quad://sounds/loop-castle.sound.json`](../sounds/loop-castle.mp3) ![`quad://sounds/loop-space.sound.json`](../sounds/loop-space.mp3) ![`quad://sounds/loop-splash.sound.json`](../sounds/loop-splash.mp3) ![`quad://sounds/loop-sanctuary.sound.json`](../sounds/loop-sanctuary.mp3) ![`quad://sounds/loop-town.sound.json`](../sounds/loop-town.mp3) ![`quad://sounds/loop-overworld.sound.json`](../sounds/loop-overworld.mp3) ![`quad://sounds/loop-victory.sound.json`](../sounds/loop-victory.mp3) ![`quad://sounds/loop-joy.sound.json`](../sounds/loop-joy.mp3) ![`quad://sounds/loop-built-this.sound.json`](../sounds/loop-built-this.mp3) ![`quad://sounds/loop-fight.sound.json`](../sounds/loop-fight.mp3) ![`quad://sounds/loop-select.sound.json`](../sounds/loop-select.mp3) ![`quad://sounds/loop-metal.sound.json`](../sounds/loop-metal.mp3) ![`quad://sounds/loop-puzzle.sound.json`](../sounds/loop-puzzle.mp3) ![`quad://sounds/loop-triumphant.sound.json`](../sounds/loop-triumphant.mp3) ![`quad://sounds/loop-dark-thriller.sound.json`](../sounds/loop-dark-thriller.mp3) ![`quad://sounds/loop-chilltech.sound.json`](../sounds/loop-chilltech.mp3) ![`quad://sounds/loop-prometheus.sound.json`](../sounds/loop-prometheus.mp3) ![`quad://sounds/loop-forest.sound.json`](../sounds/loop-forest.mp3) ![`quad://sounds/loop-escalator.sound.json`](../sounds/loop-escalator.mp3) ![`quad://sounds/loop-beat.sound.json`](../sounds/loop-beat.mp3) ![`quad://sounds/loop-wind.sound.json`](../sounds/loop-wind.mp3) ### Coin ![`quad://sounds/coin-00.sound.json`](../sounds/coin-00.mp3) ![`quad://sounds/coin-01.sound.json`](../sounds/coin-01.mp3) ![`quad://sounds/coin-02.sound.json`](../sounds/coin-02.mp3) ![`quad://sounds/coin-03.sound.json`](../sounds/coin-03.mp3) ![`quad://sounds/coin-04.sound.json`](../sounds/coin-04.mp3) ![`quad://sounds/coin-05.sound.json`](../sounds/coin-05.mp3) ![`quad://sounds/coin-06.sound.json`](../sounds/coin-06.mp3) ![`quad://sounds/coin-07.sound.json`](../sounds/coin-07.mp3) ![`quad://sounds/coin-08.sound.json`](../sounds/coin-08.mp3) ![`quad://sounds/coin-09.sound.json`](../sounds/coin-09.mp3) ### Engine Loops ![`quad://sounds/engine-00.sound.json`](../sounds/engine-00.mp3) ![`quad://sounds/engine-01.sound.json`](../sounds/engine-01.mp3) ### Shoot ![`quad://sounds/shoot-00.sound.json`](../sounds/shoot-00.mp3) ![`quad://sounds/shoot-01.sound.json`](../sounds/shoot-01.mp3) ![`quad://sounds/shoot-02.sound.json`](../sounds/shoot-02.mp3) ![`quad://sounds/shoot-03.sound.json`](../sounds/shoot-03.mp3) ![`quad://sounds/shoot-04.sound.json`](../sounds/shoot-04.mp3) ![`quad://sounds/shoot-05.sound.json`](../sounds/shoot-05.mp3) ![`quad://sounds/shoot-06.sound.json`](../sounds/shoot-06.mp3) ![`quad://sounds/shoot-07.sound.json`](../sounds/shoot-07.mp3) ![`quad://sounds/shoot-08.sound.json`](../sounds/shoot-08.mp3) ![`quad://sounds/shoot-09.sound.json`](../sounds/shoot-09.mp3) ![`quad://sounds/shoot-10.sound.json`](../sounds/shoot-10.mp3) ![`quad://sounds/shoot-11.sound.json`](../sounds/shoot-11.mp3) ![`quad://sounds/shoot-12.sound.json`](../sounds/shoot-12.mp3) ### Explode ![`quad://sounds/explode-00.sound.json`](../sounds/explode-00.mp3) ![`quad://sounds/explode-01.sound.json`](../sounds/explode-01.mp3) ![`quad://sounds/explode-02.sound.json`](../sounds/explode-02.mp3) ![`quad://sounds/explode-03.sound.json`](../sounds/explode-03.mp3) ![`quad://sounds/explode-04.sound.json`](../sounds/explode-04.mp3) ![`quad://sounds/explode-05.sound.json`](../sounds/explode-05.mp3) ![`quad://sounds/explode-06.sound.json`](../sounds/explode-06.mp3) ![`quad://sounds/explode-07.sound.json`](../sounds/explode-07.mp3) ![`quad://sounds/explode-08.sound.json`](../sounds/explode-08.mp3) ![`quad://sounds/explode-09.sound.json`](../sounds/explode-09.mp3) ![`quad://sounds/explode-11.sound.json`](../sounds/explode-11.mp3) ![`quad://sounds/explode-10.sound.json`](../sounds/explode-10.mp3) ![`quad://sounds/explode-12.sound.json`](../sounds/explode-12.mp3) ### Powerup ![`quad://sounds/powerup-00.sound.json`](../sounds/powerup-00.mp3) ![`quad://sounds/powerup-01.sound.json`](../sounds/powerup-01.mp3) ![`quad://sounds/powerup-02.sound.json`](../sounds/powerup-02.mp3) ![`quad://sounds/powerup-03.sound.json`](../sounds/powerup-03.mp3) ![`quad://sounds/powerup-04.sound.json`](../sounds/powerup-04.mp3) ![`quad://sounds/powerup-05.sound.json`](../sounds/powerup-05.mp3) ![`quad://sounds/powerup-06.sound.json`](../sounds/powerup-06.mp3) ![`quad://sounds/powerup-07.sound.json`](../sounds/powerup-07.mp3) ![`quad://sounds/powerup-08.sound.json`](../sounds/powerup-08.mp3) ![`quad://sounds/powerup-09.sound.json`](../sounds/powerup-09.mp3) ![`quad://sounds/powerup-10.sound.json`](../sounds/powerup-10.mp3) ![`quad://sounds/powerup-11.sound.json`](../sounds/powerup-11.mp3) ### Hit ![`quad://sounds/hit-00.sound.json`](../sounds/hit-00.mp3) ![`quad://sounds/hit-01.sound.json`](../sounds/hit-01.mp3) ![`quad://sounds/hit-02.sound.json`](../sounds/hit-02.mp3) ![`quad://sounds/hit-03.sound.json`](../sounds/hit-03.mp3) ![`quad://sounds/hit-04.sound.json`](../sounds/hit-04.mp3) ![`quad://sounds/hit-05.sound.json`](../sounds/hit-05.mp3) ![`quad://sounds/hit-06.sound.json`](../sounds/hit-06.mp3) ![`quad://sounds/hit-07.sound.json`](../sounds/hit-07.mp3) ![`quad://sounds/hit-08.sound.json`](../sounds/hit-08.mp3) ![`quad://sounds/hit-09.sound.json`](../sounds/hit-09.mp3) ### Jump ![`quad://sounds/jump-00.sound.json`](../sounds/jump-00.mp3) ![`quad://sounds/jump-01.sound.json`](../sounds/jump-01.mp3) ![`quad://sounds/jump-02.sound.json`](../sounds/jump-02.mp3) ![`quad://sounds/jump-03.sound.json`](../sounds/jump-03.mp3) ![`quad://sounds/jump-04.sound.json`](../sounds/jump-04.mp3) ![`quad://sounds/jump-05.sound.json`](../sounds/jump-05.mp3) ![`quad://sounds/jump-06.sound.json`](../sounds/jump-06.mp3) ![`quad://sounds/jump-07.sound.json`](../sounds/jump-07.mp3) ![`quad://sounds/jump-08.sound.json`](../sounds/jump-08.mp3) ![`quad://sounds/jump-09.sound.json`](../sounds/jump-09.mp3) ### Blip ![`quad://sounds/blip-00.sound.json`](../sounds/blip-00.mp3) ![`quad://sounds/blip-01.sound.json`](../sounds/blip-01.mp3) ![`quad://sounds/blip-02.sound.json`](../sounds/blip-02.mp3) ![`quad://sounds/blip-03.sound.json`](../sounds/blip-03.mp3) ![`quad://sounds/blip-04.sound.json`](../sounds/blip-04.mp3) ![`quad://sounds/blip-05.sound.json`](../sounds/blip-05.mp3) ![`quad://sounds/blip-06.sound.json`](../sounds/blip-06.mp3) ![`quad://sounds/blip-07.sound.json`](../sounds/blip-07.mp3) ![`quad://sounds/blip-08.sound.json`](../sounds/blip-08.mp3) ![`quad://sounds/blip-09.sound.json`](../sounds/blip-09.mp3) ![`quad://sounds/blip-10.sound.json`](../sounds/blip-10.mp3) ![`quad://sounds/blip-11.sound.json`](../sounds/blip-11.mp3) ![`quad://sounds/blip-12.sound.json`](../sounds/blip-12.mp3) ![`quad://sounds/blip-13.sound.json`](../sounds/blip-13.mp3) ![`quad://sounds/blip-14.sound.json`](../sounds/blip-14.mp3) ![`quad://sounds/blip-15.sound.json`](../sounds/blip-15.mp3) ![`quad://sounds/blip-16.sound.json`](../sounds/blip-16.mp3) ![`quad://sounds/blip-17.sound.json`](../sounds/blip-17.mp3) ### Wild ![`quad://sounds/wild-00.sound.json`](../sounds/wild-00.mp3) ![`quad://sounds/wild-01.sound.json`](../sounds/wild-01.mp3) ![`quad://sounds/wild-02.sound.json`](../sounds/wild-02.mp3) ![`quad://sounds/wild-03.sound.json`](../sounds/wild-03.mp3) ![`quad://sounds/wild-04.sound.json`](../sounds/wild-04.mp3) ![`quad://sounds/wild-05.sound.json`](../sounds/wild-05.mp3) ![`quad://sounds/wild-06.sound.json`](../sounds/wild-06.mp3) ![`quad://sounds/wild-07.sound.json`](../sounds/wild-07.mp3) ![`quad://sounds/wild-08.sound.json`](../sounds/wild-08.mp3) ![`quad://sounds/wild-09.sound.json`](../sounds/wild-09.mp3) ### Splash ![`quad://sounds/splash-00.sound.json`](../sounds/splash-00.mp3) ### Sparks ![`quad://sounds/sparks-00.sound.json`](../sounds/sparks-00.mp3) ![`quad://sounds/sparks-01.sound.json`](../sounds/sparks-01.mp3) ![`quad://sounds/sparks-02.sound.json`](../sounds/sparks-02.mp3) ![`quad://sounds/sparks-03.sound.json`](../sounds/sparks-03.mp3) ![`quad://sounds/sparks-04.sound.json`](../sounds/sparks-04.mp3) Project Files ============================================================================================= When importing assets using the IDE as JSON or raw PNG, MP3, or TMX files, the subdirectories `journal`, `screenshots`, `metadata`, `backlot` and `graveyard` are excluded. !!! quadplay✜ supports the extended [WorkJSON](https://github.com/morgan3d/workjson) format, which permits C++ style comments, hexadecimal numbers, IEEE 754 constants, raw decimals, leading plus signs, trailing commas, and multiline backquote JavaScript strings within JSON files for convenience when editing and debugging. This is not legal in strict JSON and may be incompatible with other tools. Game JSON --------------------------------------------------------------------------------------------- The project file is a JSON file describing all of the parts of the program. The project file and all of its dependencies are reloaded every time that you press play or reload in the IDE. All of the `.game.json` properties can be modified through the user interface in the IDE, except for the game constants. The only way to modify constants in the current release is through an external editor directly changing the `.game.json` file. Future releases will provide a user interface for simple constants. An example project is below, annotated with comments explaining the options. Project files should have the double extension `.game.json`. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ JavaScript { "title": "Your Game", "developer": "Your Name or Company", "copyright": "© Year Whomever", "license": "Distribution and source code license", // Not yet supported. These files will be loaded and inserted at the top // of your code, before the constant and asset definitions. "packages": ["https://someaccount.github.io/someproject/somefile.package.json", "somefileinyourproject.package.json"], // Documents for players or for yourself as a game developer, such // as a TODO list, game design doc, manual, or library specification. // These can be HTML, Markdeep (md.html), Markdown (.md), or text (.txt) format "docs": [ "gdd.md.html", "todo.md" ], // Files that form the global scope. Put most of your code in these. They are // loaded in order. "scripts": ["utils.pyxl", "juice.pyxl", "https://someaccount.github.io/someproject/inventory.pyxl"], // The name of the mode at which the program should begin. "start_mode": "Init", // These are the names of modes, which must start with a capital letter and // be legal identifiers in PyxlScript. These correspond to files that must // be stored in the same path as the project file. So, "Init" is in "Init.pyxl". // // Modes become global constants in your program. "modes": ["Init", "Play" "Credits"], // Assets are bound as global constants in your program. // They also properties of the global ASSETS object so that // they can be referenced by string names. "assets": { // Asset names must be legal PyxlScript identifiers "mysprite": "mysprite.sprite.json", "myfont": "arial.font.json", "boom": "boom.sound.json", "overworld": "overworld.map.json" }, "version": 1.0, // Properties affecting your game description in the launcher program: "min_players": 1, "max_players": 1, "cooperative": false, "competitive": false, "achievements": false, "highscores": false, "description": "Description of your game in about 22 words.", // False by default. If true, P1's right analog stick can override P2's // D-pad. This is useful for making single player dual D-pad games that // automatically work on both keyboard (WASD + IJKL) and physical game // controller. You can also make controller-only dual analog stick // games using device_control("get_analog_axes", ...) "dual_dpad": false, // Other global constants. You could define these in a global source code file // as well. The constants specified here have immutable *values*, not just immutable // bindings, and are available to editing tools. These are bound as global // variables and are also properties of the global CONSTANTS object so that // they can be referenced by string names. "constants": { // If the number value is in quotes it will be parsed. // This allows degrees, percents, infinity, and nan. // Raw numbers, strings, and booleans are permitted but // restricted to JSON limitations. "player_speed": {"type": "number", "value": "3"}, "background": {"type": "rgb", "value": {"r": {"type": "number", "value": 0.8}, "g": {"type": "number", "value": 0.8}, "b": {"type": "number", "value": 0.8}}, "data": {"type": "object", "value": { "height": {"type": "number", "value": 1}, "foo": {"type": "object", "value": {"a": {"type": "boolean", "value": true}}, "starmap": {"type": "raw", "url": "stars.yml"}, "name": "Destrier", "knight": {"type": "object", "value": { "upgrades": {"type": "array", "value": [10, 7, 3, 1]}, "hp": 50, "inventory": {"type": "object", "value": {"food": 4, "sword": "a sword"}}}}, "numbers": {"type": "array", "value": [ {"type": "number", "value": "10"}, {"type": "number", "value": "infinity"}]}, "level_table", {"type": "table", "url": "level_table.csv"} }, // The default Y axis increases down the screen, like old arcade games. // Set this to true for a modern vertical axis good for physics games. // You can also invoke set_transform() in code. "y_up": false, // Supported sizes: // // 384 x 224 (maximum, native, default) // 192 x 112 (half resolution), // 128 x 128 (PICO-8), // 64 x 64 (lowrezjam and nano JAMMER) // // The non-native screen sizes may render with substantial black // borders on some implementations to ensure integer pixel scaling. "SCREEN_SIZE": {"x": 384, "y": 224}, } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Each game must also contain: - 64x64 `label64.png` box art image in the same folder as the `.game.json` file. This is used for display in the launcher. - 128x128 `label128.png` box art image in the same folder as the `.game.json` file. This is used for the open dialog. - 1152x1120 `preview.png` image in the same folder as the `.game.json` file that contains 6x10 frames of 192x112 video at 20 fps (3 seconds total) used for the preview video in the launcher. You can create these images however you wish, including manually drawing them. The IDE has some tools to automate the process. You can create the `label128.png` and `label64.png` images by pressing *Shift+F6* while your game is playing. It will capture a 128x128 region from the center of the screen and resize it using bilinear interpolation to create the 64x64 image, and then save them with the appropriate filenames in the game's directory. Edit and compress these images as you would a sprite. You can create the `preview.png` image by pressing *Shift+F8* while your game is playing. It will record 3s of video, process it to the correct resolution, and save it to disk. Compress it as you would a sprite. Seek to keep the total size around 100 kB for the image by choosing content that compresses well and using a good compression tool. If the image is much larger, then there will be delay for players browsing your game in the discover tab. Assets and constants are both data used by your program. Assets include standalone JSON metadata files of their own to make them easy to reuse between projects and are usually relatively large media files. Constants have metadata embedded directly in the game to reduce files and maintenance and are usualy relatively small individual data. The `table` and `raw` constant types can use external files as constants, but still have metadata embedded in the game itself and use raw data instead of media formats. ### Constants Unlike constants declared in code, the constants in the `.game.json` file appear in the IDE in the project list and have GUI editors. They are immutable at runtime by the program, but can be changed by the GUI editors for debugging and tuning at runtime. Each constant has the format `"..name..": {"type": "..type..", "value": ..., "description": "..."}`. The `description` field is optional and the `raw` type permits a `url` instead of a `value`. Other types may have additional metadata used for the IDE. Explicit types allow support for the full PyxlScript literal syntax beyond that permitted natively in JSON, appropriate GUI editors, and annotations. The available constants types are: - `number` - Decimal number, with optional double quotes - Unicode fraction in double quotes - `"NaN"` - `"infinity"`, `"-infinity"`, `"∞"`, `"-∞"` - Number ending in `deg`, `°`, or `%`, all in double quotes - `"π"` - `string` - `boolean` - `nil` (no `value` needed) - vectors - `xy` - `xz` - `xyz` - Each of these may have a `"nudge"` field, which is another vector of the same type that specifies the amount that the IDE should shift by along each axis when nudging. The nudge vector expects strings of numbers or numbers directly, rather than recursive fields with type and value elements. - `rgb` - `rgba` - `hsv` - `hsva` - `raw` - Loaded from a json or yml file or inline as a json value. When in an external file, must be at top level and not nested inside an array or object. - `object` - `array` - `table` - `reference` - The value of a reference is the name of another constant or asset. These can be recursive, but obviously cannot form a cycle. References must be defined at top level and not nested inside an array or object. ### `table` Constants A `table` entry in the game constants has additional properties: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ json { "type": "table", "transpose": "false", // Optional, default false "column_type": "object", // Optional, default "object" "ignore_first_column": false, // Optional, default to false. Removes the source 1st column if true "row_type": "array", // Optional, default "object" "ignore_first_row": false, // Optional, default to false. Removes the source 1st row if true "url": "somefile.csv", // Must use a "url" property, not "value". Must be a csv file. "trim": true // If true, trim extra whitespace. Default is true } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ By default, tables are indexed in-game as `table[x][y]` a.k.a. `table[col][row]`. To use `table[y][x]` a.k.a. `table[row][col]` indexing, set `transpose == true`. The `column_type`, `ignore_first_column`, `row_type`, and `ignore_first_row` refer to the data in the original format, before any transpose has occured. This is consistent with named animation indexing in sprite sheets. If `column_type` is `"object"` (the default), then the first row of the data is treated as property names. If `column_type` is `"array"`, then the first row is considered element 0 of the column. If `row_type` is `"object"` (the default), then the first column of the data is treated as property names. If `row_type` is `"array"`, then the first column is considered element 0 of the row. If both `row_type` and `column_type` are `"object"` (the default), then the top-left element is not used. Quadplay parses values in [CSV](https://tools.ietf.org/html/rfc4180) files with these additional rules for data types: CSV Value | Quadplay Type -------------------------|----------------- number | number number ending in `%` | number date | string `TRUE` or `FALSE` | boolean `$`, `¥`, `€`, `£`, or `§` + number | number (ignores currency unit) double-quoted text | string (without quotes) other text | string empty | (empty) string `""` in text | `"` `infinity` | number (`infinity`) `-infinity` | number (`-infinity`) `nil`, `null` | `nil` `NaN` | `NaN` number ending in `deg` | number (in radians, same as native quadplay constants) Double-quoted text may contain newlines. #### Object Examples Consider the following CSV files, produced using a spreadsheet program or by hand: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ csv state, bird, flower Louisiana, Brown pelican, Magnolia Maine, Chickadee, White pine cone and tassel Wisconsin, American robin, Wood violet ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [`state.csv`] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ csv slot, fighter, rogue, wizard main, sword, dagger, fireball off, shield, blackjack, teleport aux, rope, lockpick, potion ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [`rpg.csv`] The following examples show how the data can be accessed in code, depending on the properties set on the constants ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PyxlScript // "state": {"type": "table", "url": "state.csv", "transpose": true} debug_print( state["Louisiana"]["bird"] ) // "Brown pelican" debug_print( state.Louisiana.bird ) // "Brown pelican" // "represent": {"type": "table", "url": "state.csv"} debug_print( represent.bird.Maine ) // "Chickadee" // "role": {"type": "table", "url": "rpg.csv"} debug_print( role.fighter.main ) // "slot": {"type": "table", "url": "rpg.csv", "transpose": true} debug_print( slot.main.fighter ) // "sword" debug_print( 'off-hand actions: ', slot.off) // {fighter:"shield", rogue:"blackjack", wizard:"teleport"} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #### Array Examples Consider the following CSV files, produced using a spreadsheet program or by hand: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ csv x,y 101,89 106,88 88,98 124,29 130,34 131,46 136,48 204,72 205,66 208,62 202,60 279,90 289,103 293,110 345,98 348,94 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [`positions.csv`] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ csv level, strength, hit_points, total_skills 0, 0, 0, 0 1, 16, 10, 1 2, 18, 15, 1 3, 18, 20, 2 4, 20, 25, 2 5, 21, 30, 2 6, 21, 35, 3 7, 22, 40, 3 8, 22, 45, 4 9, 22, 50, 5 10, 24, 55, 6 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [`level_table.csv`] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ csv 0, 10, 20, 30 1, 11, 21, 31 2, 12, 22, 32 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [`grid.csv`] The following examples show how the data can be accessed in code, depending on the properties set on the constants ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PyxlScript // "position_array": {"type": "table", "url": "positions.csv", "transpose": true, "column_type": "array"} for pos in position_array: draw_point(pos, #F00) // "level": {"type": "table", "url": "stats.csv", "transpose": true, "column_type": "array", "ignore_first_column": true} debug_print( level[1].strength ) // 16 // "grid": {"type": "table", "url": "grid.csv", "column_type": "array", "row_type": "array"} debug_print( grid[1][2] ) // 12 debug_print( grid[3][1] ) // 31 // "matrix": {"type": "table", "url": "grid.csv", "transpose": true, "column_type": "array", "row_type": "array"} debug_print( matrix[1][2] ) // 21 debug_print( matrix[3][1] ) // 13 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ### `raw` Format The `raw` format allows embedding a JSON-expressible value directly. `raw` format also supports the format {"type":"raw", "url": "your url"} instead of an inline value. The URL must be for a [JSON](https://www.json.org/) or [YAML](https://yaml.org/) file. Note that the `raw` format is restricted to values that are expressible in those interchange formats and does not support the full GUI editors and other format features. `raw` type constants with URLs must be top-level constants. They cannot be embedded within other constants. This is required in order to separate the asynchronous loading from constant evaluation in the implementation and to ensure that GUI editors can be built effectively for objects and arrays. Debug JSON --------------------------------------------------------------------------------------------- When working with multiple developers on a game, it is often useful to have slightly different settings for each developer. For example, one developer may want a `DEBUG_GRAPHICS` constant set to `true` while the usual value is false. Or the gameplay programmer may experiment with different player velocity than what is in the main game branch. One way to accomplish this is to explicitly use the built-in `IDE_USER` constant described in the Debugging section. Another solution is to use a `.debug.json` file. A debug JSON file must be in the same directory as the `.game.json` file and use the same basename. For example, if your game is `space.game.json`, then the debug file is `space.debug.json`. Typically you will _not_ add the debug file to version control, so that each developer may have their own. No `.debug.json` file is required, and if one is present it will be ignored unless running on a quadplay server using the IDE. The `.debug.json` format is: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ json { "start_mode": "Init", "start_mode_enabled": true, "constants" : { // Constants in the same format as in the .game.json. "player_speed": { "type": "number", "value": "3", // If false, then this debug value is // disabled in the IDE but remembered for later // enabling. "enabled": true } } } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The `start_mode` overrides the `.game.json` start mode, if it is present. The constants override the equivalent constants from the `.game.json` file (unless they are not enabled). Extra constants specified only in the `.debug.json` file are ignored; they are not mapped at runtime. Sprite JSON --------------------------------------------------------------------------------------------- The sprite sheet JSON descriptor looks like: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ JavaScript { "url": "hero.png", // Optional. Defaults to the size of the png. "sprite_size": {"x": 8, "y": 8}, // Optional blank pixels between sprites on the bottom and right. Default is zero. "gutter": 0, // Optional. Default is false. If true, indexing is transposed // in game. "transpose": false, // Optional name of the file to load with an external editor from the IDE // instead of the url one when editing. For example, if you export from // another tool such as Aseprite or Photoshop and would like to load *this* // instead from the IDE when editing the sprite. "source_url": "hero.psd", // Default value for sprite.frames, the number of 1/60-second frames // to play a sprite during animation. "default_frames": 1, // Optional. Applies to pre-transpose coordinates. Each becomes // an array on the spritesheet with the extrapolate field set. // A name cannot be 'sprite_size' or any other spritesheet field. // // If an xy() is specified, creates a single sprite. // // If an object is specified, creates an array of sprites. // // If `extrapolate` is unspecified, defaults to looping. // `extrapolate` options are "loop", "oscillate", and "clamp" // // Each object may have its own `defaultFrames` that overrides the // spritesheet's defaultFrames, as well as a `frames` array with // one element per sprite in the animation. // // `end` defaults to `start`, and each field of `end` defaults // to the corresponding part of `start`. "names": { "idle": {"start": {"x": 0, "y": 0}, "end": {"x": 0, "y": 3}, "extrapolate": "oscillate", "frames": [1, 2, 2, 1]}, "run": {"start": {"x": 1, "y": 0}, "end": {"y": 3}, "frames": 2}, "jumpUp": {"start": {"x": 2, "y": 0}}, "jumpDown": {"start": {"x": 2, "y": 1}}, "dead": {"x": 3, "y": 0}, "parachute":{"start": {"x": 3, "y": 1}, "pivot": {"x": 4, "y": 4}, "is_item": true // Arbitrary properties can be attached here, using the // same syntax as game constants }, }, // Optional offset and extent. Using this conserves memory if the sprites // do not fill the entire PNG. "region": { "corner": {"x": 0, "y": 0}, // Optional, defaults to (0, 0) "size": {"x": 128, "y": 32} // Optional, defaults to the remainder of the sheet }, // Optional location on the sprites that aligns with (0, 0) in an entity's reference // frame. Defaults to the sprite size / 2. "pivot": {"x": 4, "y": 7}, // Optional license and copyright information. "license": "GPL 3.0 (c) 2020 Morgan McGuire" } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This will appear as the global variable `heroSpriteSheet` in memory, which is a 2D array of individual sprites. !!! I recommend a two-step process for compressing sprites to minimize loading time and game size. First, use the quadplay✜ [Quantize✜](../tools/quantize.html) tool to reduce bit depth. Second, use [ImageOptim](https://imageoptim.com/mac) (macOS), [PNGGauntlet](https://pnggauntlet.com/) (Windows), [TriImage](https://trimage.org/) (Linux), or [PNG Crush online](https://richardassar.github.io/pngcrush.js/) to improve the PNG encoding. For a sprite sheet named `S`, individual sprites are accessed as `S[x][y]` in game. If the sprite sheet contains a single row, then `S[x]` is sufficient. If there's a single image, just use `S`. Setting `transpose` to true flips the indexing to `S[y][x]`, which is more convenient for some sprites. Animations appear to game code as arrays of sprites that have the following additional fields: `extrapolate` : Equal to `"clamp"`, `"loop"`, or `"oscillate"` as specified in the spritesheet. `frames` : Equal to `infinity` for `"loop"` and `"oscillate"` animations and the total number of 60 Hz game frames of animation for finite `"clamp"` animations. `period` : Equal to `nan` for `"clamp"` animations and the number of 60 Hz game frames for one repeat of a `"loop"` or `"oscillate"` animation. A game may use a total of **5,505,024 pixels** of sprite memory (10.5 MB) across **128 sprite sheets** (including fonts), each no larger than **1024x1024**. You can allocate this however you wish within those restrictions. That's equivalent to 5,376 sprites at 32x32, 21,504 sprites at 16x16, or 64 full-screen images. These are of course soft limits because you can modify the open source emulator to remove them. The intent of the limits is to guarantee that your programs will work on all future implementations of the runtime: web software, Raspberry Pi, WebGL, GLES, and desktop OpenGL and Vulkan. If the same sprite sheet is loaded by multiple `.sprite.json` files using the same URL then it only counts once towards the resource limits. This allows you to pack sprites with different sizes into the same physical sheet at no penalty and treat them as different logical sprite sheets. Multiple spritesheets loaded from the same sprite.json file will be pointers to the same object, which is immutable. There is no performance advantage or requirement for making sprites or spritesheets even sizes or power of two sizes, although many traditional sprites happen have sides of 8, 16, or 32 pixels. The quadplay✜ screen resolution is designed to allow an integer number of such tiles. You can use the Python script `tools/sprite_json_generator.py` to generate these json blobs for you. Use the `--help` argument for more details. Font JSON --------------------------------------------------------------------------------------------- Fonts have a JSON descriptor file that looks like: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ JavaScript { "url": "sundown-7x13.png", // Optional copyright and license information "license": "Public Domain 2018 by Danika Farheed", // Size of the glyph bounding boxes. Include gutter pixels in the // char_size. The loader repacks glyphs tightly, so extra padding // or horizontal alignment is irrelevant at runtime (but affects // distribution size and loading time). "char_size": {"x": 8, "y": 14}, // Spacing between letters and lines during rendering. If the // x spacing is zero (for script fonts), there will be no space between // letters or digits, but space will still be added around symbols. "letter_spacing": {"x": 2, "y": 3}, // Defaults to 1 pixel "shadow_size": 1, // Zero-based Y value of the baseline relative to char_size. // This is one less than the "height" of the baseline because // of the zero based value. "baseline": 11 } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can generate a default version of this JSON with the [Fontpack✜](../tools/fontpack.html) tool from a PNG image. You can generate a PNG template for the glyphs by taking a screenshot from the [Fontgen✜](../tools/fontgen.html) tool. By convention, the image filename contains the maximum size of the individual glyphs, which is usually smaller than the char_size due to gutters. The file can have any name, however. The image must be grayscale, where white is the font character and black will become transparent. The current implementation does not allow shades of gray for antialiasing. The image tiles must follow this exact character format: ![Figure [figFont]: The font character layout](../fonts/deja-15.png) The six dots on the final row are reserved for future characters. Because only the specified grid of tiles is read, you can include non-character information off the bounds of the tiles, for example, putting a copyright statement directly on the font itself. Fonts count 1/2 as much towards the spritesheet pixel limit because they are internally compressed to 8 bits per pixel. They still count fully towards the maximum spritesheet dimensions. Because a font is 32x26 glyphs, this means that the largest `char_size` can be is 24x29 pixels if the `shadow_size` is one pixel. Fonts enforce uniform width on all full-size digits 0..9 so that numbers print in aligned columns. Avoid drawing fonts with one digit that is larger than most of the others (usually the "4") because they result in extra padding around all digits. `font.line_height` : When loaded into memory, the font object exposes a `font.line_height` property that is the spacing used between consecutive baselines. This is chosen to make typical letters well spaced. It may leave some symbols overlapping on adjacent lines, especially for decorative fonts. This is the height of the actual characters plus the `char_size.y` value. Multiple fonts loaded from the same sound.json file will be pointers to the same object, which is immutable. Sound JSON --------------------------------------------------------------------------------------------- The sound JSON descriptor looks like: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ JavaScript { "url": "boom.mp3", // Optional license and copyright "license": "Released into the public domain by Edouard Gauthier" } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Sounds must be in MP3 format. Multiple sounds loaded from the same sound.json file will be pointers to the same object, which is immutable. Map JSON --------------------------------------------------------------------------------------------- Multiple maps loaded from the same map.json file will produce different map objects in memory because maps are mutable. The spritesheets that they load will be shared if they come from the same sprite.json files. The map JSON descriptor looks like: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ JavaScript { "url": "overworld.tmx", // Optional. Shift the map by this amount in pixels for all coordinate // transformations and rendering. Default = (0,0), which puts integer // map coordinates at the corners of tiles. "offset": {"x": 7.5, "y": 7.5}, // z value of the first layer. Optional, default = 0 "z_offset": 0, // Optional. Default = false. If true, flip the map // vertically during load so that (0,0) is the bottom // of the TMX map instead of the top. "y_up": false, // Optional. Default = false. "wrap_x": false, // Optional. Default = false. "wrap_y": false, // Optional. Default is 1.0. This is the z difference // between layers when rendering. Can be negative to // reverse layering direction. "z_scale": 2, // Optional license and copyright "license": "Released into the public domain by Edouard Gauthier", // Optional if the map only uses one spritesheet "sprite_url": "tiles.sprite.json" // If no sprite_url is specified, then an entire table // mapping each spritesheet referenced in the map to a sprite file "sprite_url_table": { "tiles": "tiles.sprite.json" } } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The url must reference a map file in [TMX format](https://doc.mapeditor.org/en/stable/reference/tmx-map-format/) and in files ending with `.tmx`. Only the following properties are currently supported: - `Orthogonal` or `Hexagonal (Staggered)` - `CSV` format - `Tile layers` (other layers are ignored) - `Embedded tileset` (a PNG reference in the TMX, _not_ a TSX file) - For an Orthogonal map, set the map tile size equal to the tileset tile size (e.g., 32x32) - For a Hexagonal map, set the map tile size to be 1.5x larger along the "pointy" direction (e.g., 32x48 for a 32x32 hex with points up and down) When accessing a Hexagonal map in memory, even rows should be rendered offset by 1/2 a tile width. ![Tiled program options for creating a new map.](tiled-new-map.png width=50% style="image-rendering:auto") The tile render order from the map is ignored. The easiest way to create these is using the open source [Tiled](https://www.mapeditor.org/) editor, which has pay-what-you-want precompiled binaries for Windows, macOS, and Linux. The sprite sheet from the map file will be used for visualization if it is available in the IDE, but map rendering is performed using a sprite sheet at runtime. For more sophisticated map drawing, [TileKit](https://rxi.itch.io/tilekit) is a US$20 Windows and Linux mapping program. When drawing, layer zero for `draw_map()` corresponds to the lowest layer in Tiled and the layer indices increase upwards. PyxlScript Language ========================================================================= Numbers ------------------------------------------------------------------------- Numbers are stored internally as double-precision (64-bit) IEEE floating point values. Integer operators truncate the decimal places of their arguments. The first 2^53=9007199254740992 contiguous positive integers are exactly representable. The largest finite representable number is about 1.7977x10^308. There are about seventeen decimal digits of precision on arbitrary numbers. `NaN` and positive and negative infinity are also exactly representable. Finite numeric literals contain an optional single plus or minus sign and one of: - a series of digits, followed by an optional decimal point and a series of digits - a decimal point followed by a series of digits - one of the following single-character fractions, representing one-half to one-tenth: `½ ⅓ ⅔ ¼ ¾ ⅕ ⅖ ⅗ ⅘ ⅙ ⅐ ⅛ ⅑ ⅒` Two optional suffixes are permitted: - Percent `%` divides the number by 100 - Degrees `deg` or `°` multiplies the number by `π/180` Examples of legal numeric literals: ~~~~~~~~~~~~~~ PyxlScript 1 -21.4 0 -0 .0 0.5 -½ +72.41 15% // 0.15 90° // ½π 45deg // ¼π ~~~~~~~~~~~~~~ No hexadecimal, octal, binary, or exponential notation are supported. Trailing decimal points are not allowed. For example, `0.` is illegal. Booleans -------------------------------------------------------------------- The boolean literals are `true` and `false`. Logical operators work with any values. For logical operators and flow control, `0`, `∅`, and empty string `""` act as `false`. Strings -------------------------------------------------------------------- String literals are enclosed in double quotes (`"..."`). They may not contain newlines or double quotes. To enter a double quotation mark or slash, escape it with a slash: `"\\"` is the `\` character and `"\""` is the `"` character. The `+` operator performs string concatenation, coercing the right-hand argument if it is not a string. String characters are read-only substrings accessed using zero-based array syntax. Arrays -------------------------------------------------------------------- Arrays are ordered sets of values. They are zero-based and have dynamically typed elements. Array literals are surrounded in square brackets and separated by commas. Square brackets are also used for l-value and r-value dereference. Array examples: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PyxlScript a = [8, 4, 1] a[0] = "hello" debug_print(a[0]) debug_print(size(a)) a₁ += 2 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Negative indices are permitted on arrays but will not be reported in the length. Reading an out-of-bounds value from an Array returns `∅`. Objects --------------------------------------------------------------------------- Objects are unordered sets of keys. Objects (also known as dictionaries and tables in other languages) map these keys to values. Literals are created using key-value pairs separated by a colon, surrounded by curly braces, and delimited by commas. Object elements can be accessed using the string name of a property in square brackets or by a period. This allows them to act as objects/structs. Object examples: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PyxlScript t = {x:3, y:10} t.x += 1 debug_print(t["x"]) debug_print(size(t)) debug_print(keyArray(t)) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Functions --------------------------------------------------------------------------- Functions are first-class values. They can be passed to and returned from other functions, stored in data structures, and bound to variables. Declare functions with `def` and return values from them with `return`. Separate the argument list from the body with `:`. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PyxlScript // Multi-line function block def solve(a, b, c): return ½(sqrt(b² - 4 a * c) - b) / a // Inline function def foo(x): x += 1; return 2 x // Call a user function text(foo(3)) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ There is no way to declare an anonymous function or use a function definition as an expression. If a function body takes too long to execute, then the interpreter may terminate the program to prevent the game from becoming unresponsive. To call a function returned from an expression that ends in parentheses, use the `call` function. To avoid having to indent the entire function body twice for the common case of preserving a transform, a joint `def-preserving_transform` statement is available: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PyxlScript def draw_stuff(a, b, c) preserving_transform: set_transform(...) ... // is the same as: def draw_stuff(a, b, c): preserving_transform: set_transform(...) ... ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Variables --------------------------------------------------------------------------- Variable name identifiers consist of an optional upper case delta plus a series of Roman letters, or the unambiguous-looking Greek letters `αβγδζηθιλμρσϕχτψωΩ` by themselves, and optionally trailing a series of digits. Greek letters may also be trailed by an underscore and a series of letters and digits. The identifier also must not be a reserved word. No underscores or other unicode characters are allowed in identifiers. Examples of legal identifiers: ~~~~~~~~~~~~~~~~~~~ none col screen long_variable longVariable L i damage Y2 Δx θ θ_in ~~~~~~~~~~~~~~~~~~~ Variables are declared to the scope of the containing block or mode. Scope blocks are denoted by a statement ending in a colon and zero or more indented lines. Use `let` to declare variable names that can later be re-bound. Use `const` to declare constants that cannot be rebound. Note that `const` marks the *binding* as constant, but the bound value itself may be mutated if it is an object or array. Note that only a single variable is permitted per `let` or `const` statement. Multiple statements may be chained using semi-colons on a single line, however. ~~~~~~~~~~~~~~~~~~~~~~~~~~~ PyxlScript const x = 7 // x may not be rebound let y // Declare y let z = 9 // Declare and initialize z // Declare and initialize two variables on the same line: let a = [1, 2]; let b = "hello" ~~~~~~~~~~~~~~~~~~~~~~~~~~~ The variables captured by `for` and `with` and the arguments to a `def` are bound to the scope of the body. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PyxlScript const scale = 2 let y = 100 for i < 3: y += 1 sprite(hero[anim][0], xy(scale * i, y)) def applyScale(x): return x * scale // i is out of scope here ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Variables declared within a mode are local to that mode and reinitialized every frame. Variables declared in a global file are global to the entire program. It is an error to assign to a variable before it is declared. ### Reserved Words These are reserved tokens that cannot be used as variable names. Some of them are keywords or built-in syntax, and some of them do nothing now but are reserved for future use. `ADD`, `and`, `arguments`, `args`, `as`, `async`, `at`, `auto`, `await`, `assert`, `because`, `begin`, `bitand`, `bitnot`, `bitor`, `bitashl`, `bitshl`, `bitshr`, `break`, `catch`, `class`, `const`, `cont`, `coroutine`, `continue`, `constructor`, `deg`, `do`, `delete`, `def`, `default`, `DIV`, `debug_watch`, `debug_print`, `elif`, `end`, `extern`, `enum`, `final`, `finally`, `for`, `from`, `freeze`, `function`, `get`, `global`, `go`, `goto`, `has`, `if`, `in`, `implements`, `inherits`, `include`, `import`, `interface`, `launch_game`, `let`, `local`, `NaN`, `new`, `nil`, `nonlocal`, `not`, `null`, `main`, `MAD`, `mod`, `module`, `mode`, `MUL`, `or`, `otherwise`, `public`, `private`, `protected`, `prototype`, `package`, `preserve`, `preserving_transform`, `quit_game`, `ret`, `return`, `reset_game`, `require`, `requires`, `seal`, `set`, `show`, `static`, `strict`, `SUB`, `swap`, `SOURCE_LOCATION`, `SCREEN_SIZE`, `to`, `todo`, `to_string`, `then`, `try`, `throw`, `template`, `touch`, `until`, `use`, `using`, `unless`, `var`, `while`, `with`, `when`, `xor`, `yield`. Built-in functions such as `draw_tri` that are legal identifiers can be rebound. They are not reserved. `cos`, `sin`, and `tan` by themselves are bound to first-class functions, but the special syntax that allows them to be invoked without parentheses on single variables is tied to their exact names. If you rebind them, then the new functions that you have bound will be invoked. ### `with` Statement The `with` statement creates a local scope in which explicitly named keys from an object are variables aliased to the properties on the object. This allows compact syntax for repeated use of those keys. It fills the role that methods and member variables do within object-oriented languages. The local variables shadow any global (or enclosing `with` statement) variables. Example: ~~~~~~~~~~~~~~~~~~~~~~ PyxlScript G = {x:1, y:2, z:0} with x,y in G: x = 100 y = 0 z = 4 // G.x is now 100, G.y is now 0, G.z is still 0, // and global z is now 4 ~~~~~~~~~~~~~~~~~~~~~~ Within the body, the local variables and the properties are true aliases. So, `G.x` and `x` may be used interchangably within the body in the above example. The single-line version of the `with` statement is comparable to other single-line flow control: ~~~~~~~~~~~~~~~~~~~~~~ PyxlScript G = {x:1, y:2, z:0} with x,y ∈ G: x = 100; y = 0; z = 4 ~~~~~~~~~~~~~~~~~~~~~~ `with` statements can make code clean but are expensive relative to the overhead of other statements, so avoid them for performance-sensitive inner loops. ### `local` Statement The `local` statement allows you to create a block without any other bindings or flow control. It is occasionally useful for creating variables with a tight scope inside a long function or mode. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PyxlScript let x = 4 local: // This is a local scope and variables // can shadow those in the outer scopes let x = 7 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Comments ------------------------------------------------------------------- Comments follow C/C++/Java/JavaScript syntax of `//` for single line comments and `/*`...`*/` for multi-line comments. `because "reason"` : The special `because` statement allows a compile-time string comment to follow a mode or game change control flow statement such as `set_mode()`. It acts as a machine-readable comment that the IDE will use to automatically annotate the program in the debug output and the mode diagram. Operators ------------------------------------------------------------------- Built-in arithmetic operators and functions are overloaded for numbers and objects. Some operators support a compact Unicode version and an ASCII version that is easier to type on a conventional keyboard. ASCII | Unicode | Meaning ---------|---------|-- `++` | | increment `--` | | decrement `=` | | assignment `==` |`≟` | equality test `!=` |`≠` | inequality test `+` | | addition and string concatenation `-` | | negation `+=` | | mutating addition, string concatenation `-=` | | mutating subtraction `<` | | less-than `<=` |`≤` | less-than or equal to `>` | | greater-than `>=` |`≥` | greater-than or equal to `in` |`∈` | `for` loop container element-of and `with` statement object `^` | | exponentiation (see also unicode exponents) `*` | | multiplication (see also implicit multiplication) `*=` | | mutating multiplication `/` | | floating-point division `/=` | | mutating division `mod` | | remainder (modulo) |`⌊⌋` | floor function |`⌈⌉` | ceiling function `||` | | absolute value |`‖‖` | magnitude (of a vector or array) `[]` | | object/array element reference, or array constructor `{}` | | object constructor (follows JavaScript syntax) `.` | | object property `()` | | grouping or function call `...` | `…` | spread operator for arrays `bitand` |`∩` | bitwise AND (bit set intersection) |`∩=` | mutating bitwise AND `bitor` |`∪` | bitwise OR (bit set union) |`∪=` | mutating bitwise OR `or` | | logical OR `not` | | logical NOT `and` | | logical AND `bitxor` |`⊕` | bitwise XOR |`⊕=` | mutating bitwise XOR `bitnot` |`~` | bitwise NOT `~=` | | mutating bitwise NOT `<<` or `bitshl` |`◀` | arithmetic bit shift left `<<=` |`◀=` | mutating arithmetic bit shift left `>>` or `bitshr` |`▶` | arithmetic bit shift right `>>=` |`▶=` | mutating arithmetic bit shift right `if`...`then`...`else`| | conditional `default`| | default value operator Assignment and mutating operators all return `nil`; they cannot be chained or used in expressions. There is no logical XOR or logical shift right. The `default` operator has the form: _expr1_ `default` _expr2_. If _expr1_ is not `nil`, then the value of the operation is the value of _expr1_. If it is `nil`, then _expr2_ is evaluated and the value of the expression is the value of _expr2_. Note that the second expression is not evaluated unless it is needed, as with `and`, `or`, and `if` operators. The `default` operator allows compact statements handling default arguments or out of bounds array accesses, for example: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PyxlScript // Returns a transparent gray. Opacity is optional // and defaults to 1 def transparent_gray(g, opacity): return rgba(g, g, g, opacity default 1) // Print the first element of array matching target, or // the first element of the entire array if not found. debug_print(array[find(array, target) default 0]) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The conditional operator (distinct from the `if` block statement) has the form: `if testexpr then truevalue else falsevalue`. Note that there are no colons (:), because it does not create blocks. The conditional operator is convenient when initializing constants, or data structures. For example: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PyxlScript const y = if x > 3 then "cat" else "dog" spawnMonster(if pos then pos else xy(0,0)) let data = {name: if i > 2 then "Peter" else "Amit", height: 7} setTarget(if ‖pos - P.pos‖ > 10 then ∅ else P) // Because "and" and "or" operate on non-booleans, the examples // above could have been written less clearly with alternative // logic: const y = (x > 3) and "cat" or "dog" spawnMonster(pos or xy(0,0)) let data = {name: (i > 2) and "Peter" or "Amit", height: 7} // Note that this one had to be restructured // because ∅ acts as false for "and" setTarget(‖pos - P.pos‖ ≤ 10 and P or ∅) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ To nest conditionals, you must put parentheses around at least the `falsevalue`, for example `y = if x > 3 then "cat" else (if x > 2 then "dog" else "llama")`. `a default b` is equal to `a` if `a` is not `nil` and `b` otherwise. It does not evaluate `b` if `a` was not `nil`. This is equivalent to the JavaScript and C# [nullish](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_operator) `??` operator. Some common uses are: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PyxlScript // Default value on load num_players = load_local("num_players") default 2 // Default value on missing object property height = character_height[name] default 170 // Default value on going out of array bounds vel = array[i + 2] default xy(2, 3) // Fallback value on find() failing debug_print(array[find(array, target) default 0]) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Spaces are not required around operators in most cases, so long as the text parses unambiguously. For example, `1or3` is equivalent to `1 or 3`. There is no ASCII operator for floor or ceiling; use the `floor` and `ceil` functions. There is no way to express mutating bitwise operators using ASCII. Behavior of these operators is consistent with the JavaScript definition of the operation (even though JavaScript uses different operators). For example, the logical-AND expression `4 and 1` evaluates to `1` because `4` is non-false and the result of non-false AND another value is the other value. The trigonometric functions `cos`, `sin`, and `tan` may be invoked as if they were operators when the order of operations is unambiguous. For example, `cos a` ==> `cos(a)`, `cosβ` ==> `cos(β)`, and `cosθ*sinφ` ==> `cos(θ) * sin(φ)`. To avoid confusion and reserve future syntax, they may not be invoked in this form when a high-precedence operator follows the argument. Those operators are `.`, `[`, and exponentiation. Because back-to-back parentheses are interpreted as implicit multiplication, functions that are returned from other functions, determined by parenthesized expressions, or stored in objects cannot be invoked using the `()` syntax. Instead, use the `call` function: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PyxlScript // Illegal: x = (a and abs or cos)(θ) y = tbl["myfunc"](3, 4) z = f(a)(b) // Legal: x = call(a and abs or cos, θ) y = call(tbl["myfunc"], 3, 4) z = call(f(a), b) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ### Assignment and Equality As in Python and JavaScript, all assignment operators perform pointer assignment and all equality operators check for pointer equality. All function call parameters are passed by pointer. Strings, `nil`, numbers, and booleans are immutable and unique. This means that variables will be aliased after assignment: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PyxlScript let v = xy(1, 2) let k = v k.x = 3 // v.x is 3 now ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Use `clone()`, `deep_clone()`, or one of the vector-specific helper functions for copying assignment: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PyxlScript let v = xy(4, 5) let k = xy(v) // copy k = clone(v) // generic version ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ A global game constant that is cloned becomes mutable. There is no way to declare immutable objects or arrays at runtime in code. `const` makes the _binding_ constant, but has no effect on the value (as in JavaScript). ### Exponents The characters `⁺⁻⁰¹²³⁴⁵⁶⁷⁸⁹ᵃᵝⁱʲᵏⁿᵘˣʸᶻ⁽⁾` can form exponent expressions that operate as if the `^` operator or `pow` function was invoked using those expressions as a second argument. The entire exponent expression is implicitly surrounded in parentheses. The variables `a`, `β`, `i`, `j`, `x`, `y`, `z`, `n`, `k`, and `u` may appear only as single-character variable names in exponents. Exponentiation, including via exponent characters, may not be performed on a negative number without parentheses. This follows the rules from JavaScript's `**` operator. For example, `x=y-1²` is legal, but `x=y+-1²` is illegal and must be rewritten as `x=y+(-1)²` or (the confusing and redundant expression, if that's really what was intended) `x=y+-(1²)`. ### Implicit Multiplication Multiplication is implicit wherever a number is immediately followed by a parenthesized expression or variable (including a function call). This also ocurrs when any exponent appears immediately preceeding a parenthesized expression or variable, and where two parenthesized expressions are back to back. For example, `2x`, `x²y`, `3(x+y)`, `(y+2)(x+1)`. Implicit multiplication can be used within exponents. ### Spread Operator The spread operator (`…` or `...`) allows defining and calling functions with a variable number of arguments. It is the same as `*rest` in Python and `...rest` in JavaScript. In a function declaration it designates the final argument as an array of all further arguments. For example, `def foo(a, b, …rest):` takes any number of arguments and maps them to `a`, `b`, and then an array `rest` of the remainder. For example, `def bar(…args):` takes any number of arguments and maps them all into array `args`. In a function call or array literal, the spread operator expands an array as if its elements had been entered inline. So, `bar(…a)` calls a function with all of the arguments from array `a`. `[1, 2, …a, 10]` creates an array that begins with 1 and 2, then has all of the elements of `a`, followed by the number 10. ### Built-in Objects The following are built-in constants and special zero-argument operators. They are not variable names and thus cannot be redefined. Several have both unicode and ASCII names. Symbol | ASCII | Value ---------------|-----------------|---------------------------------------- `ε` | `epsilon` | `0.000001` `π` | `pi` | `3.141592653589793115997963468544185161590576171875` `∞` | `infinity` | infinity | `nan` | floating-point "not-a-number" value | `CREDITS` | object of credit and license statements from assets and code `∅` | `nil` | ("undefined") | `pad` | array gamepad of objects | `joy` | shorthand for `pad₀` `ξ` | `random()` | random number on [0, 1), resampled every time the expression is used | `SCREEN_SIZE` | the size of the screen in pixels, defaults to `xy(384, 224)` | `CONSTANTS` | an object mapping all game-specific constants to their values | `ASSETS` | an object mapping all game-specific assets to their values | `SOURCE_LOCATION` | an object that has fields `{url:, filename:, line_number:}` from its location in the source code Loops and Flow Control -------------------------------------------------------------------------- The flow control statements are: - Blocks: - `if` conditional with optional `else` and `else if` clauses - `while` loop - `until` loop - `for` loop and `for...in` loop, both with optional `with` expansion. _See also the `iterate()` function_. - `break` and `continue` within loops - `preserving_transform` and `local`, which do not have branching flow but do create local scopes - `def`, which creates a local scope for a function but does not execute immediately - Modes: - `set_mode(ModeName)` to switch game modes. The note is optional. - `push_mode(ModeName)` and `pop_mode()` to temporarily enter a mode game mode. The notes are optional. - Game: - `reset_game()` to reset all state and restart the game. - `quit_game()` to end the current game and return to the launcher. - `launch_game(url)` to launch a different game. `set_mode()`, `push_mode()`, `pop_mode()`, `reset_game()`, `quit_game()`, and `launch_game()` may be followed by the keyword `because` and a reason that is a compile-time string. For example, `quit_game() because "lives = 0"`. The reason allows the IDE to label the transitions on the mode diagram for the game. There is no switch, do loop, goto, or try/catch. Whitespace is significant, as in Python. Indentation must be exactly a single space per nested block. For flow control purposes, the empty string, 0, and `∅` are false. All other objects (including empty data structures) are true. Within any loop, `continue` skips to the next iteration of the loop and `break` exits the loop. Multi-line `if` statements may be followed by `else:` and `else if ...:` clauses. These must always be multi-line. Numeric `for` loops increment by 1 each iteration and always count up. The loop variable must be on the left-side of a single comparison loop expression or the center of a multi-comparison expression. The iteration variable in any `for` loop is freshly bound for each iteration. This means that if it is captured by a function as in: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PyxlScript let array = [] for i < 3 def capture(): return i push(array, capture) for f in array: debug_print(f()) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ that the value will reflect the time of the capture. This avoids many common bugs when using first class functions with loops. Container iteration `for` loops iterate over the keys of a object, the characters of a string, or the elements of an array. `while` loops evaluate the condition at the top of the loop for every iteration. `for` loops evaluate the bounds once, before the first iteration. `for...in` loops evaluate the container expression once, before the first iteration. It is illegal (and will usually result in an error) to add or remove values from the container of a `for...in` loop. This semantic avoids confusing situations for the programmer and is necessary for performance optimizations in the iterator implementation. Changing the order of values is legal, but discouraged because the iterator will touch each slot in order and will skip or duplicate values if they change slots. Writing to the current value is legal and frequently useful. If you would like to add or remove from the container, transform your code from `for x in container:` to `for x in clone(container):`. Cloning is fairly fast in PyxlScript. Or, use the syntax `let i = 0; while i < size(container): let x = container[i] ... ++i` and account for the index and size changes in your own iteration. The main variations of a `for...in` loop are: - `for value in array:` - `for value in object:` - `for char in string:` - `for value at index in array:` - `for char at index in string:` - `for value at key in object:` The value variable is bound with `let`, so assignment to the value variable is legal but will not affect the underlying value in the array. In any loop, `break` immediately terminates the tightest enclosing loop and `continue` immediately begins the next iteration of the tightest enclosing loop. The Java/C++ equivalents of `for`-loop conditions are: quadplay✜ | Java/C++ ----------------------|------------------------ `for i ≤ k` | `for (i = 0; i <= k; ++i)` `for i < k` | `for (i = 0; i < k; ++i)` `for 4 ≤ i < k` | `for (i = 4; i < k; ++i)` `for 4 < i < k` | `for (i = 5; i < k; ++i)` `for x ∈ S` | `for (x : S)` You can pack a `for` and `with` statement together by chaining `∈` expressions, in what is called a `for`-`with` loop. The properties exposed by the `with` are references to the actual values and can be mutated directly. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PyxlScript for x,y ∈ point ∈ set: ... ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ is the same as: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PyxlScript for point ∈ set: with x,y ∈ point: ... ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The `for`-loop variable (in this case, `point`) cannot be the same as any of the `with` variables (in this case, `x` and `y`). The comparison operators in a `for` loop declaration are an overloaded syntax for comparison operators (just as many languages overload the `=` operator for `for` loops). They have the lowest precedence. For example, `for i<a||b` is equivalent to `for i<(a||b)`. To use regular comparison operators within `for` loop preamble, you *must* use parentheses to make the parsing unambiguous, for example, `for i < (a < b)`. Single-line `for`, `if`, `while`, and `until` are permitted. There can be multiple single-line expressions on the same line. No `else` is permitted with single-line `if`. The variable list in a `for`-`with` or `with` expression can be split across multiple lines by breaking after commas: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PyxlScript for health, power, stamina in character: health += stamina * power ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The `until` loop is a `while` loop with an inverted test: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PyxlScript until x == "end": x = find_next(x, data) // Is the same as: while x != "end": x = find_next(x, data) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ### Examples #### `for` loop variations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PyxlScript // Iterate over each current enemy once, destroying those // that overlap the missile for enemy in clone(enemy_array): if overlaps(enemy, missile): remove_value(enemy_array, enemy) // Regenerate hit points for every player for health, regen_rate in player in player_array: health += regen_rate // Position each equally-spaced satellite for satellite at i in satellite_array: const a = i * 360deg / size(planet_array) satellite.pos = xy(cos a, sin a) * ORBIT_RADIUS // Iterate over an object's keys for rating at stat in player.stats: draw_text(font, stat + ": " + format_number(rating, "%"), pos, #FFF) pos.y += font.line_height // Iterate over an object used as a set already_visited[current_room] = true for room_name in already_visited: draw_text(font, room_name, pos, #FFF) pos.y += font.line_height // Make a segmented-body centipede move if joy.x or joy.y: // Don't use += because the loop passes objects instead of copying them centipede[0] = centipede[0] + joy.xy for 0 < i < size(centipede): centipede[i] = centipede[i - 1] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [`for` loop examples] #### Array Iteration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PyxlScript let names = ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"] // Iterate over array elements let pos = xy(½ SCREEN_SIZE.x, 10) for planet in names: pos.y += draw_text(font, planet, pos, #f) // Iterate over values and modify (this is safe, no elements will be // skipped. You can even remove elements ahead of the iterator and // they will still be processed) for planet in names: // Remove any name with an "a" in it if find(planet, "a") ≠ ∅: remove_values(names, planet) // Add some random moons...the current loop will not // iterate over these, but they are immediately visible // in the array. if random() > 50%: push(names, planet + " moon") // Iterate over array keys pos = xy(½ SCREEN_SIZE.x, 10) for i < size(names): pos.y += draw_text(font, names[i], pos, #f) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #### Object Iteration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PyxlScript let poemBy = { Angelou: "Still I Rise", Frost: "Stopping by Woods on a Snowy Evening", Dickenson: "Because I could not stop for Death", Whitman: "Leaves of Grass", Hughes: "Montage of a Dream Deferred", Williams: "In the American Grain", Yeats: "Sailing to Byzantium", Browning: "How Do I Love Thee?" } // Iterate over array elements let pos = xy(½ SCREEN_SIZE.x, 10) for author in poemBy: pos.y += draw_text(font, poemBy[author] + " by " + author, pos, #f) // Iterate over values and modify (this is safe, no elements will be skipped) for author in poemBy: // Remove this entry if it contains an "a" in the value if find(poemBy[authpr], "a") ≠ ∅: remove_key(poemBy, author) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #### Array of Objects ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PyxlScript let spots = [xy(1, 1), xy(100, 2), xy(10, 20), xy(50, 20)] for x, y in S in spots: // Remove any element that is higher than 15 if y > 15: remove_values(spots, S) let i = 0 while i < size(spots): // More efficient O(1) removal without preserving order // if spots is *really* long if spots[i].x > 15: fast_remove_key(spots, i) else: ++i ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Debugging --------------------------------------------------------- There are two special forms for debugging that can be enabled or disabled at runtime for efficiency on the Output pane. These are not functions and cannot be passed as values like functions or stored in data structures. `debug_print(msg)` sends text output to the IDE Output pane. It runs `unparse()` on `msg` if it is not already a string. These statements are automatically removed from the program when debug printing is disabled. `assert(condition)` or `assert(condition, msg)` halts program execution if `condition` is false. The `msg` is evaluated regardless of the value of condition. These statements are automatically removed from the program when assertions are disabled. Multiline Expressions --------------------------------------------------------------- Newlines end PyxlScript expressions, unless there are unbalanced brackets (), [], {}. This allows you to spread function calls, array literals, and object literals over multiple lines. For example: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PyxlScript let player = { center: xy(100, 40), angle: 45deg, inventory: ["hat", "sword", "money", "watch", "apple"] } let x = (43 + 17) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ If an error occurs in a multiline expression, the line number reported will be that of the beginning of the expression. If a line contains the end of a multiline expression, it may not also contain multiple statements. Symbols --------------------------------------------------------------- The quadplay✜ IDE supports autocorrect for typing the optional special symbols such as `nil` --> `∅`, `1/2` --> `½`, and `>=` --> `≥`. To generate paired symbols, type the name of the corresponding function without arguments. For example: `floor()` --> `⌊⌋`, `ceil()` --> `⌈⌉`, `magnitude()` --> `‖‖`, and `abs()` --> `||`. For convenience when using an external editor or typing the full set of characters supported by fonts into strings on a US-EN keyboard, you can also copy and paste from here: ````````````````````````````````````````````````````` none big ∅ ° ½ ² ³ ξ ∞ ε ≠ ≤ ≥ π ∊ ⌊ ⌋ ⌈ ⌉ ‖ ≟ θ Mode ══════════════════════════════════════════ frame ────────────────────────────────────────── ````````````````````````````````````````````````````` [Most common symbols] ````````````````````````````````````````````````````` none big 1ˢᵗ 2ⁿᵈ 3ʳᵈ 4ᵗʰ 1ᵉʳ 1ʳᵉ 2ᵉ 2ᵈ 2ᵈᵉ 1ᵒ 1ᵃ ````````````````````````````````````````````````````` [Ordinals in different languages] ````````````````````````````````````````````````````` none big x⁰ ¹ ² ³ ⁴ ⁵ ⁶ ⁷ ⁸ ⁹ ⁺ ⁻ ⁽ ⁾ yᵃ ᵝ ⁱ ʲ ᵏ ⁿ ᵘ ˣ ʸ ᶻ ````````````````````````````````````````````````````` [Superscripts. These are legal math in code and can be used in strings.] ````````````````````````````````````````````````````` none big ₀ ₁ ₂ ₃ ₄ ₅ ₆ ₇ ₈ ₉ ₊ ₋ ₍ ₎ ₐ ᵦ ᵢ ⱼ ₓ ₖ ᵤ ₙ ````````````````````````````````````````````````````` [Subscript symbols, usable only in strings] ````````````````````````````````````````````````````` none big A B Γ Δ E Z H Θ I K Λ M N Ξ O Π P Σ T Φ X Ψ Ω α β γ δ ε ζ η θ ι κ λ μ ν ξ o π ρ σ τ ϕ χ ψ ω ````````````````````````````````````````````````````` [Greek alphabet] ````````````````````````````````````````````````````` none big ½ ⅓ ⅔ ¼ ¾ ⅕ ⅖ ⅗ ⅘ ⅙ ⅐ ⅛ ⅑ ⅒ ∩ ∪ ≟ ≠ ≤ ≥ ∊ ⌊ ⌋ ⌈ ⌉ ∅ ∞ ° ````````````````````````````````````````````````````` [Math symbols legal in code and strings.] ````````````````````````````````````````````````````` none big ς ş ğ İ Ş Ğ υ г ¡ м н к Ñ ñ б Б Œ œ ℵ Æ À Á Â Ã Ä Å Ç È É Ê Ë Ì Í Î Ï Ø Ò Ó Ô Õ Ö æ à á â ã ä å ç è é ê ë ì í î ï ø ò ó ô õ ö Д Ж З И Й Л П Ц Ч Ш Щ Э Ю Я Ъ Ы Ь ẞ Ù Ú Û Ü д ж з и й л п ц ч ш щ э ю я ъ ы ь ß ù ú û ü ````````````````````````````````````````````````````` [Accented and Cyrillic characters] ````````````````````````````````````````````````````` none big ¥ € £ § × ⊢ ¬ ≈ ⊗ ⊕ ⊖ ∫ ± « » ¿ ★ … ∙ ○ ● ◻ ◼ △ ▲ ▼ ◀ ▶ ✓ ♠ ♥ ♣ ♦ ↑ ↓ ← → ↖ ↗ ↙ ↘ ❖ ✜ ♆ © ````````````````````````````````````````````````````` [Others] ````````````````````````````````````````````````````` none big ⓐ ⓑ ⓒ ⓓ ⓔ ⓕ ⓟ ⓠ ⓥ ⓧ ⓨ ⓩ ⍐ ⍇ ⍗ ⍈ Ⓦ Ⓐ Ⓢ Ⓓ Ⓘ Ⓙ Ⓚ Ⓛ ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⓪ ⊖⊕ Ⓞ ⍍ ▣ ⧉ ☰ ````````````````````````````````````````````````````` [Button prompts. Device-aware and full button prompts are available via the `prompt` field of `gamepad_array[]` elements] Note that the superscripts `ᵈᵉʰᵐᵒʳˢᵗ` are legal in text strings but not as code. These are present specfically to support ordinals such as "1ˢᵗ, 2ⁿᵈ, 3ʳᵈ, 4ᵗʰ, 1ᵉʳ, 1ʳᵉ, 2ᵉ, 2ᵈ, 2ᵈᵉ, 1ᵒ, 1ᵃ, …" in various languages. The encircled characters and arrows are intended for use as button prompts. The characters `Ⓞ ⍍ ▣ ⧉ ☰` are drawn in quadplay✜ fonts to represent the buttons with approximately those symbols on PlayStation and Xbox controllers. The `ⓧ` character is drawn to ambiguously represent the "X"/cross buttons on PlayStation, Xbox, and Nintendo controllers. Note that the preferred way of generating button prompts is using the `gamepad.prompt` object with the string `replace()` function, rather than hardcoding. Advanced Tools ==================================================================================== In addition to the friendlier browser-based tools from the Tools section, the distribution includes command-line tools for experienced programmers. These support external editors, running the server locally, and performing some IDE tasks at the command line. Unlike the IDE, some of these have additional dependencies and assume that you know how to install those on your own. Local Emulator ----------------------------------------------------------------------------- You can launch the IDE on your local machine. This allows you to run without a network connection and to work with local files instead of Google Drive ones for the GitHub-hosted IDE. Launch your program in the emulator and debugger from the command line on Windows, macOS, or Linux with the `quadplay` command: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ bash # Load the games/quadpaddle/quadpaddle.game.json sample program quadplay quad://games/quadpaddle # Load a mygames/space/space.game.json game that you've made quadplay mygames/space # Load from the internet (server must support CORS) quadplay https://morgan3d.github.io/somegame/foo.game.json # Just run the emulator. You can modify the URL in your browser # to add "?game=" and the game's URL or relative path quadplay ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Run `quadplay --help` to see more options for the script. These examples assume that your directory structure is: ********************************************************** * * 📂 quadplay * | * +-- 📄 quadplay * | * +-- 📂 fonts * | | * | ⋮ * | * +-- 📂 games * | | * | +-- 📂 quadpaddle * | | | * | | +-- 📄 quadpaddle.game.json * | | | * | ⋮ ⋮ * | * +-- 📂 mygames * | | * | '-- 📂 space * | | * | +- 📄 space.game.json * | | * | ⋮ * | * +-- 📂 sprites * | | * ⋮ ⋮ ********************************************************** [Directory structure with the `quadplay` script in the root.] The directory and `.game.json` file do not have to have the same name. You can list the full path to the actual game file instead. Every time you push the play button (F5) or reload button (Ctrl+R) in the emulator, it will reload your code and assets from disk. By default, `quad://` assets are cached for fast reload peformance. To disable this behavior, force a reload of the entire page with shift+browser reload button, or remove `&fastReload=1` from the URL. Visual Studio Code ------------------------------------------------------------------------------------ Visual Studio Code natively supports the `.json` files. To configure it with PyxlScript file support as well: 1. Run Visual Studio Code 2. Press F1 and type `install code` and then press enter 3. Open a terminal and change directory to `quadplay/tools` 4. At the command line, run `code --install-extension vscode-pyxlscript.vsix` Vim ------------------------------------------------------------------------------------ To install the PyxlScript mode for Vim, you'll need to modify your .vimrc. If you're using a plugin manager like [dein](https://github.com/Shougo/dein.vim): ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ call dein#add("path/to/quadplay/tools/vim-pyxlscript-syntax", {'frozen':1}) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ If you want to directly copy the files into your ~/.vim directory, make sure you copy (or symlink) all the files into the corresponding directories like they structured in the plugin. [`pyxlscript.vim`](../tools/pyxlscript.vim) Emacs ------------------------------------------------------------------------------------ To install the PyxlScript mode for Emacs, add the following lines to your `~/.emacs` file: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Lisp ; Optional if you don't want to copy the files: (add-to-list 'load-path (expand-file-name "path/to/quadplay/tools")) (autoload 'rainbow-mode "rainbow-mode") (autoload 'pyxlscript-mode "pyxlscript-mode") (add-to-list 'auto-mode-alist '("\\.pyxl\\'" . pyxlscript-mode)) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Note that you have to put the real path in for the `"path/to/quadplay/tools"`, such as `~/quadplay/tools`, or wherever you installed quadplay to. Other Editors ------------------------------------------------------------------------------------ Fortunately, PyxlScript syntax is very close to Python syntax. If you tell your editor to treat `.pyxl` files as Python files, then it will probably handle indenting and most keywords correctly. Comments are the one element that will probably confuse your syntax highlighter. Command-Line Tools ------------------------------------------------------------------------------------ [`quadplay`](../quadplay) : Launches the emulator from the command line on any operating system. Requires Python. See the arguments above. [`quaddepend.py`](../tools/quaddepend.py) : Prints dependencies of a `.game.json` file, recursively. Run the script with `--help` to see the arguments. Run as `tools/quaddepend.py ...` or `python3 tools/quaddepend.py ...` from the main quadplay directory. [`export.py`](../tools/quaddepend.py) : Export a static HTML site for a single game, either lightweight by referencing `https://morgan3d.github.io/quadplay` or standalone by embedding a full copy of the emulator. Run the script with `--help` to see the arguments. Run as `tools/export.py ...` or `python3 tools/export.py ...` from the main quadplay directory. This script itself depends on `tools/quaddepend.py`. [`sprite_json_generator.py`](../tools/sprite_json_generator.py) : Generator for `.sprite.json` files. Requires Python and PIL. If you are exporting from aseprite, use the following settings with `sprite_json_generator.py`: - "horizontal strip" (quadplay doesn't support animations wrapping around image rows - "padding", "trim", and "extrude" should all be off - "Layers" should be visible layers (quadplay doesn't support layers") - "frames" should be "all frames" (unless you only want some frames) - "export json": yes and under "meta" for this: - "layers" should be off - "frame tags" should be checked - "slices" should be off - "open generated sprite sheet" is up to you, if you want it to show you the sprite sheet when its done. If you export with these settings, you can pass the generated json file to the sprite_json_generator program and it will convert the tags and sprite size automatically from the file. Note that while aseprite supports sprites of varying size, quadplay does not. `quadplay.html` ------------------------------------------------------------------------------------ The `quadplay.html` application launched by the `quadplay` script accepts the following HTML query arguments: `IDE` : If set, load in development mode with access to the full IDE and stop and pause buttons. Cannot be set with `kiosk` `fastReload` : If `1`, do not force reloading of `quad://` files from disk but instead allow browser caching. Those resources are unlikely to change (unless you are modifying quadplay itself!), so this speeds up game reloading, especially for music. `game` : URL of a game to load, which can be relative to the `quadplay` script. `mode` : Initial mode to display: `Maximal`, `Emulator`, `IDE`, or `Test` `kiosk` : If `1`, hide the entire menu bar. Cannot be set with `IDE` Physical Consoles --------------------------------------------------------------------------------------------- ### Build I expect most people will use quadplay✜ on phones, laptops, and desktops as a _virtual_ console. But, if you have some maker experience you can make a _real_ quadplay✜ console. When you're color coding a full four-player setup, the standard quadplay✜ arcade player colors and order is P3 Yellow, P1 Magenta ("pink"), P2 Cyan ("blue"), P3 Lime ("green"):
*P3* *P1* *P2* *P4*
`const COLOR_ARRAY = [#f5a, #0af, #fe5, #5f5]`
#### Nano or Pi 4 With a 3D-printed case and some Bluetooth or wired game controllers, you can build your own quadplay✜ retro mini console to connect to a TV or monitor. [Jetson Nano](https://developer.nvidia.com/embedded/jetson-nano-developer-kit) and [Raspberry Pi 4](https://www.raspberrypi.org/products/raspberry-pi-4-model-b/) cost less than $100 and can power such a box using Linux and Chromium. Both will hit 60 Hz for most games, and can easily run at 30 Hz for all games (quadplay✜ handles framerate scaling for you seamlessly, so you won't even notice most of the time). Jetson Nano is more expensive but has the advantage of a more powerful processor. Raspberry Pi 3B+ can run _some_ quadplay games, but will underperform on those with sophisticated graphics. ![Quadplay mini-console built by Morgan McGuire from a Jetson Nano with a 3D-printed case, USB Xbox 360 controller, and small external monitor.](nano-arcade.jpg width=50%) I've built Jetson Nano and Raspberry Pi consoles and the result is satisfyingly comparable to the Nintendo [NES Classic Edition](https://www.nintendo.com/nes-classic/), [Super NES Classic Edition](https://www.nintendo.com/super-nes-classic/), Sega [Genesis Mini](https://genesismini.sega.com/), and PlayStation [Classic](https://www.playstation.com/en-ca/explore/playstation-classic/) devices. The big difference from commercial mini retro consoles is that you can program your own quadplay console. The commercial consoles only play their own games. ![Self-contained quadplay console built by Morgan McGuire from a Raspberry Pi and standard screen case, with Bluetooth controllers.](rpi-arcade.jpg style="image-rendering:none" width=50%) My Raspberry Pi 4 software configuration from the default Raspbian install is simply: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ bash sudo apt install chromium sudo update-alternatives --config x-www-browser # + choose /usr/bin/chromium ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #### NUC An Intel NUC is a much more expensive device for powering a mini console, but has a lot more graphics power than an embedded processor and will comfortably run all games at 60 Hz. #### Cabinets You can also build a quadplay✜ arcade cabinet. This can be done with some carpentry and any low-cost PC and display, or by purchasing some (expensive!) pre-built arcade cabinets. There are a lot of physical [arcade controllers](https://shop.xgaming.com/products/x-arcade-dual-joystick-usb-included) available at reasonable prices for building out the controls without needing any custom electronics. Note that quadplay✜ supports (but does not require) a touch screen or mouse, which will not be available on a normal cabinet setup. One alternative is to use a small trackpad mounted on top of the joystick controller. ![Arcade station built by Morgan McGuire running quadplay on a 2012 MacBook with an X-Arcade Dual controller.](xarcade-arcade.jpg style="image-rendering:none" width=50%) ![Arcade station custom built by Nick Porcino running quadplay on Raspberry Pi](arcade.jpg style="image-rendering:none" width=50%) For arcade configurations, the order of the physical controllers in the `gamepad_array[]` matters because they are at fixed locations. The default order of controllers is set by the operating system. From the Controls tab of the IDE's debugger, you can bring up the quadplay dialog to change this order. When building your own controller, ensure that it maps correctly using the online tool at https://html5gamepad.com/. The specific mapping between HTML buttons and quadplay✜ is: quadplay✜ | HTML Gamepad :-------------------:|:-------------------------------: Analog x-axis | axis 0 (left is negative) Analog y-axis | axis 1 (forward is negative) ⓐ | button 0 ⓑ | button 1 ⓒ | button 2 ⓓ | button 3 ⓔ | button 4 ⓕ | button 5 ⓠ | button 8 ⓟ | button 9 D-pad | button 12 D-pad | button 13 D-pad | button 14 D-pad | button 15 The D-pad is not typically provided for an arcade setup. quadplay✜ automatically maps the analog stick into D-pad inputs as well as providing analog access under `device_control()`. The ⓔ button should be placed where it can be easily held while using the main buttons and stick, for example, as a hat button on the stick or under the right thumb or pinkie. The ⓕ button should be placed where it can be used similarly, but ⓔ should be the more convenient of the two. Note the positioning of the player 1 and 2 ⓔ and ⓕ on the keyboard compared to on a NES-style gamepad...the keyboard controls place these buttons _lower_ than on a gamepad, so that they are in reach of the pinkies for eas of holding down. They are not "shoulder" buttons, even though that is the best location for them on a physical controller. If building a physical cabinet or handheld _without_ on-screen mobile controls, I recommend using a 1280x720, 1600x900, or 1920x1200 display to efficiently fill the screen with integer pixel scaling. Some exact ratios when using quadplay's maximum 384x224 resolution are: Screen | Integer | Used | Efficiency | Autoscaler | Used | Efficiency ----------:|------------:|----------:|------------:|-----------:|----------:|---------: 480x320 | 1x | 384x224 | 56% | 1.00x | 384x224 | 56% 640x360 | 1x | 384x224 | 37% | 1.00x | 384x224 | 37% 640x480 | 1x | 384x224 | 28% | 1.00x | 384x224 | 28% 800x480 | 2x | 768x448 | 72% | 2.00x | 768x448 | 72% 1024x768 | 2x | 768x448 | 44% | 2.00x | 768x448 | 44% *1280x720* | *3x* |*1152x672* | *84%* | 3.21x | 1234x720 | 96% 1280x800 | *3x* | 1152x672 | 76% | 3.33x | 1280x747 | 93% 1366x768 | 3x | 1152x672 | 74% | 3.41x | 1316x768 | 96% 1440x900 | 3x | 1152x672 | 60% | 3.75x | 1440x840 | 93% *1600x900* | *4x* |*1536x896* | *96%* | 4.02x | 1544x900 | 97% 1680x1050 | 4x | 1536x896 | 78% | 4.38x | 1680x980 | 93% 1920x1080 | 4x | 1536x896 | 66% | 4.82x | 1852x1080 | 96% *1920x1200*| *5x* |*1920x1120*| *93%* | 5.00x | 1920x1120 | 93% ### Buy quadplay✜ works on all Mac, Windows, and Linux devices, so any computer you buy can be a dedicated device for playing or making games. For a _handheld_ form factor there are a few options. We've tested on the GPD Win 2 and it runs quadplay✜ well. Its successor is not yet available but should also work well, in a slightly larger form factor: - 1280x720 [GPD Win 2](http://gpd.hk/gdpwin2), Windows and Linux = full-res quadplay✜ 3x scaling - 1280x800 [GPD Win Max](http://gpd.hk/gpdwinmax), Windows and Linux = full-res quadplay✜ 3x scaling Some other physical handhelds that may be capable of running quadplay✜ games when/if released include: - 480x320 [Odroid-Go Advance Black](https://liliputing.com/2020/05/the-new-odroid-go-advance-adds-wifi-and-more-buttons-linux-handheld-game-console.html), Linux = full-res quadplay✜ 1x scaling; poor fit - 1280x720 [DragonBox Pyra](https://pyra-handheld.com/boards/pages/pyra/), Linux = full-res quadplay✜ 3x scaling - 1920x1080 The Smach Z - 1920x1200 Alienware UFO Network ==================================================================================== You can use quadplay over a local network or the internet in several ways: [Online Hosted](#network/onlinehosted) : Play single-player or local multiplayer quadplay games from the internet on any device with a modern web browser [Steam Streaming](#network/steamstreaming) : Play quadplay games on a SteamLink or any Steam client, streaming across your local network from a laptop or desktop [Network Multiplayer](#network/networkmultiplayer) : Play multiplayer quadplay games with friends across a local network or the internet, with some limitations. This is a work in progress and will improve before the final release. [Mobile Development](#network/mobiledevelopment) : Develop and test your quadplay game on a phone or tablet Online Hosted ------------------------------------------------------------------------------------ Quadplay games can be played on any device with a full modern web browser. This includes laptops, desktops, mobile devices, embedded processors, and some game consoles. Just enter the URL of the game's hosting page into your browser, such as: https://morgan3d.github.io/quadplay/console/quadplay.html or launch the `quadplay` script with the URL of the game. See the Deploying Games section to learn how to upload your own games onto an internet server. Steam Streaming ------------------------------------------------------------------------------------ Games for quadplay are usually best played through a browser. However, if you have a device that runs the [Steam Link](https://store.steampowered.com/steamlink/about/) app or the Steam client, but does not have a full web browser, then you can use Steam's streaming technology to play on that device. This allows you to have up to four players on a single machine that is not the machine which is running quadplay. For example, to stream to a living room set-top box. Steps that you only need to do once, on the hosting computer: 1. Create a free [Steam](https://store.steampowered.com/join) account if you do not already have one. 2. Install the free [Steam](https://store.steampowered.com/about/) client on the computer that you will stream from, if it does not already have Steam. The Steam client is available for macOS and Windows. There is a partly supported client for Linux as well. 3. Run the Steam client. From the Games menu, select "Add a Non-Steam Game to My Library...": ![](add-non-steam.png) 4. Select your web browser from the list. All browsers should appear under Windows. If it is not listed or you are on macOS, select "Browse..." and then identify the application. On macOS, you can find `/Applications/Google Chrome.app`, `/Applications/Safari.app`, or `/Applications/Firefox.app` in the list that appears. To Stream a game across a local network: 1. *On the hosting computer*, launch `quadplay --kiosk` with the name of your game. Press the icon in the center of the browser, so that it starts playing and goes fullscreen. 2. *On the remote computer* where you want to play, launch Steam and search your Steam library for your browser. Press the green "STREAM" button. After a moment, the game should start in fullscreen mode, showing the same view as the browser. Game controllers will work normally on the remote computer. ![](launch-chrome.png) Network Multiplayer ------------------------------------------------------------------------------------ This process uses the Steam Remote Play feature in an unusual way to connect up to four players on two different computers. It works best for two players on different computers using keyboard controls. The 1.0 release of quadplay will contain a more straightforward network multiplayer solution. This is a temporary workaround. One-time setup: 1. Install [Steam](https://store.steampowered.com/) on both computers. 2. Create/log in with an account that you do not mind sharing the password to. 3. On the "hosting" computer, in Steam: 1. Select from the menu Steam -> Settings -> Remote Play and then: 1. Check *Enable Remote Play* 2. *Pair* your "remote" computer 3. Press *Advanced Host Options* and check *Play audio on host* 2. Select from the menu Games -> Add a Non-Steam Game to My Library..., and then add your preferred web browser, as described in the Steam Streaming section To play: 1. Log in to the same Steam account on both computers 2. On the "remote" computer, in Steam, choose to run your browser via Streaming 3. On the "hosting" computer, run `quadplay` from the command line. If it does not launch in the browser that came up due to Steam, copy the url from the one that launched to the one that Steam launched. Make the browser full screen, and push play in the quadplay IDE. 4. Both players should now be sharing a view. The keyboard and controllers are shared as well, so one player must be sure to use use the Player 2 controls (IJKL). You may use game controllers as well, but if you have only one plugged in, it will be the player 1 game controller regardless of the machine that you use. So, one player must plug in _two_ game controllers and use the second one. Mobile Development ------------------------------------------------------------------------------------ The quadplay IDE allows you to easily test your game on a mobile device while developing from a laptop or desktop computer. First, launch the `quadplay` script on your computer with the `--host` flag. For example, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ bash quadplay --host games/quadpaddle/ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (Use your own game, not the `quadpaddle` sample, of course). Second, in the web browser that opens on your computer, select the Project or Test view at the upper right. Click on the Host tab of the debugging pane on the lower right: ![The QR code in the Host tab of the IDE](host-tab.png) Third, _on your mobile device_, either scan the QR code and then open the URL it shows in a browser, or manually type the URL into your mobile browser. Your mobile device will now play the game direct from your computer. You can edit the game or assets on your computer and reload the browser page on your mobile device to see the changes. You do not need to re-scan the QR code for each change. !!! note Mobile Controls On a mobile device, quadplay games be played with the on-screen touch controls or a physical game controller paired over BlueTooth or plugged in directly over USB. Deploying Games ==================================================================================== Your games can be played on any major web browser on desktop/laptop, phone, tablet, or embedded processor such as Jetson Nano or Raspberry Pi. You can also distribute them as phone or desktop apps. You may charge money for your games and may distribute them as closed source. It is your responsibility to satisfy copyright law and any licensing fees or royalties for content that you use when you distribute your game. The content provided with quadplay✜ is all royalty-free Creative Commons and contains its own licensing data. Content that you find elsewhere will have its own rules and restrictions. The code provided with quadplay✜ is all Open Source (even though it permits you to use it with your own closed-source came). See the Credits section for more information. GitHub ------------------------------------------------------------------------------------ ### From your development repo This is the easiest method to deploy your game. It also allows you to continuously update the game as well as gain the benefit of improvements to quadplay✜ itself continuously. Store your game in a git repository on [github.com](https://github.com), or in a subdirectory of a GitHub repository. Do not fork quadplay into the repo because that will make it large and disrupt the user's saved per-console state. Just keep your game there in the repo by itself as you create it. Assume that your GitHub account is named `USER` and your repo is named `REPO`. To deploy, go to the settings page for your repo on GitHub. For example, https://github.com/USER/REPO/settings. In the section titled "GitHub Pages" on the settings page, select "Master Branch" from the Source dropdown. The URL to play your game is then: `https://morgan3d.github.io/quadplay/console/quadplay.html?game=https://USER.github.io/REPO&mode=Maximal&kiosk=1`. If you'd like to make a friendlier URL, then you can also create an `index.html` file in the root of your repo with the contents: People visiting the URL https://USER.github.io/REPO will then be redirected to the correct page. ### From another repo To keep your development repository private or just separate from the deployment one, create a second repository on GitHub. Clone both to your local machine and at the command line, enter the _development_ repo and run ````````````````````````````````````````````````````````````` python3 tools/export.py -o ../PUBLIC_REPO path/to/game ````````````````````````````````````````````````````````````` You can then add and commit the public repo. If you want your game to be standalone and not depend on the quadplay repo at runtime, just add the `--standalone` argument. This will generate an `index.html` file as well as copying all dependencies. itch.io ------------------------------------------------------------------------------------ Deploying to [itch.io](https://itch.io/) as a Browser Game allows you to create a self contained online game that others can buy from you, or play for free if you choose. It is slightly more complicated to update than on GitHub because you must make a release file and upload it explicitly. The steps are: 1. Run `python3 path-to-quadplay/tools/export.py` inside the directory containing your `game.json` file, or `python3 tools/export.py -g path-to-your-game`. 2. Log into the itch.io website and create a new game entry with the following settings: - Classification: Games - Kind of project: HTML - Mobile friendly: Yes - Automatically start on page load: Yes - How should your project be run in your page?: Click to launch fullscreen - Orientation: Landscape - Visibility: Public 3. In the Uploads section on the itch.io game page, upload the zipfile generated in step 1. To update your game or upgrade the underlying quadplay✜ distribution, you must repeat the process of creating the zipfile and then upload it as a replacement for the original file. Web Server ------------------------------------------------------------------------------------ You can host your game using only your own files on any web server that supports [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS), or as a copy of all of quadplay✜ on _any_ web server, regardless of whether it supports CORS. To deploy your game on a web server with CORS named `myserver.com` in the `mygame` directory, run just upload your own game files to the server. The URL for your game is: https://morgan3d.github.io/quadplay/console/quadplay.html?game=https://myserver.com/mygame To deploy a complete package that is independent of the current version of quadplay✜, run `python3 tools/export.py -o path/to/output -g path/to/game` and then upload your files from the output directory. Your URL will be just https://myserver.com/mygame. Phones ------------------------------------------------------------------------------------ Any quadplay✜ game hosted on a web page using the methods from the previous sections can be played on a mobile phone. The emulator automatically creates on-screen buttons when it detects a phone, and it also supports gamepads connected to a phone. You can also deploy your game through a phone app store in order to sell it. This is an advanced process. You must wrap your game with a binary program. [Cordova](https://cordova.apache.org/) is a free tool that you can use to automate this process. It requires familiarity with [npm](https://www.npmjs.com/), web apps, the app store that you are deploying on, and the tools needed (such as Xcode for iOS) to compile on the platform. The basic idea is to use the method described in the itch.io section to create a standalone web app, and then use Cordova to create the phone app. Desktop ------------------------------------------------------------------------------------ [Electron](https://electronjs.org/) is a tool that turns web apps into desktop binary projects which can be distributed through the Windows or Mac App stores, Steam, the Epic Store, etc. It works by bundling an entire web browser with your application, wrapped so that it looks like a native app. The process is similar to that of using Cordova. Performance ==================================================================================== quadplay✜ is designed to make it easy to write small games that have very readable source code. I recommend designing your code primarily for readability instead of performance. However, at some point you'll probably hit the performance limits and want to optimize at least some of the program. Here's where to focus your efforts. To avoid input lag, process game pad input _before_ rendering and simulation each frame. This allows the players' input to affect the current frame instead of being delayed one frame. Game pads (and browsers) have 1-2 frames of input lag in them. To conceal this, allow critical input such as a jump, block, or dodge to happen up to one or two frames _after_ the period in which it should have. For example, do not damage the player character until one frame after they are attacked and allow a late dodge or block to save them retroactively. In the "Performance" tab of the IDE, you can see the amount of time spent per frame. If time spent is less than 16 ms, then your program is running at 60 fps. If time spent is higher than 16 ms, then you may need to optimize. `draw_map()` is substantially faster than making the same `draw_sprite()` calls by yourself. It culls all off-screen sprites. Drawing a map with `camera.zoom = 1` or `z_scale = 0` is faster than with perspective and zoom. Tiles without alpha will cull everything behind them when not using perspective, so you don't have to leave out the hidden map tiles for performance when drawing maps. Maps with opaque tiles that are not rotated or scaled draw extremely fast. Built-in math functions are faster than math functions that you write to do equivalent operations because they are designed to minimize memory allocation internally. The intrinsics are maximum speed but can make code hard to read. There is generally no need to cull objects that are off screen. The rendering code is very good at removing those for you. `draw_sprite()` and `draw_map()` are fastest for `opacity=1` sprites that are not rotated or scaled and do not have alpha. It can directly copy the memory in this case. It can be substantially faster (but use more memory) to use pre-drawn transitions between map terrain tiles instead of layering an alpha-masked tile on top of another one to blend them. If you can tell that an object is covered by another object in `z`, remove it (this is called occlusion culling). The renderer must process both otherwise even though the object that is behind is unseen. All of the drawing calls are much faster for opaque colors than ones with fractional alpha values. Perfectly horizontal lines are much faster to draw than vertical lines. Vertical lines are slightly faster than diagonal lines. Sequential `draw_point()` calls that have the same `z` value are significantly optimized in order to enable efficient per-pixel graphics. Sequential `draw_sprite()` calls that have the same `z` value and the same clipping region are slightly optimized to enable efficient custom map rendering and particle systems. Numeric for loops, such as `for i < N` are slightly faster than iterator for loops such as `for x in A`. `with` statements are relatively slow, as are `for`-`with` loops on large arrays. Use them for readability on individual or small sets of objects but not on large arrays or in loops that repeat many times. It is slightly faster to perform math on individual elements than vectors. For example, `pos.x += vel.x; pos.y += vel.y` is slightly faster than `pos += vel`. The tradeoff of expanding out math is generally not worth the readability cost unless processing hundreds of vectors. The performance advantage diminishes as the objects grow larger. For example, `rgba` vectors or adding whole arrays to each other have relatively less overhead than `xy` vectors. The IDE is designed to collapse gracefully so that you can use an external editor. Here's one useful layout: ![](external-editor.png width=50% style="image-rendering:auto") The editor on the left is emacs running in a terminal. On the right is the browser reduced to the quadplay✜ debugging output and emulator. Be careful to always end your *filenames* with _two_ extensions: `.game.json`, `.sprite.json`, `.map.json`, etc. This is how the IDE and compiler knows what type it is loading. Take note of the 4-bit sprite [quantizing tool](../tools/quantize.html). I find it better than the quality produced by Photoshop for color reduction. Road Map ==================================================================================== Quadplay is about 90% of the way to version 1.0. The API is stable, and many people are using it to make hobby games, participate in game jams, and to learn/teach programming. The soul of quadplay as a console is described by: - Four players with a shared screen - Minimal time from launch to main play - 1985 output limitations, 2020 development power The overarching design principles of the quadplay IDE and language are: - Keep small game development friendly and fun - Limitations that: - Allow games to run effectively on a wide range of displays, processors, and input devices without any per-platform work - Focus developers on gameplay and innovation - Help developers prevent scope creep - Allow expert users to bypass limitations to customize for a specific platform or game - Support working where developers choose: - Entirely in a browser - Primarily in external tools - Or any combination! 1.0 ------------------------------------------------------------- There's a long feature list and a short bug list that I'm working through for 1.0. The highlights of this are, in priority order: [x] Development on macOS, Windows, Ubuntu Linux, and Raspbian [x] Playing on phones, tablets, desktop, laptop, homebrew arcades, Raspberry Pi, Jetson Nano, PiBoy DMG [x] Gamepads [x] 8BitDo [x] Switch JoyCons [x] X-Arcade [x] Xbox and PlayStation [ ] PiBoy DMG [x] APIs [x] Graphics [x] Physics [x] AI [x] Six full sample games [x] Export to: [x] web page [x] github pages [x] itch.io (browser) [x] macOS/Windows/Linux download (browser) [ ] Built-in IDE [x] Code editor [x] Project editor [x] Constant editor [ ] Map editor [ ] Sprite editor [x] Vim, Emacs, and Visual Studio code external editor support [x] Aseprite, Photoshop, Krita, and Tiled external editor support [x] 50% virtual GPU graphics speedup over the alpha [x] Load tables of data from CSV files Post 1.0 -------------------------------------------------------------- [ ] Shared-screen network multiplayer [ ] Python not required [ ] Export to: [ ] macOS binary [ ] Windows binary [ ] Extended constant editor [ ] Font editor [ ] More AI routines [ ] Shadowing/line of sight [ ] Board game logic [ ] Maze and level generation [ ] Perfect outlined-disk and outlined-triangle blending [ ] Polyline rendering without double-blending endpoints [ ] Watertight rasterization of triangle meshes [ ] Watertight rasterization of polylines [ ] Edit your game in the IDE and save to Google Drive Credits ==================================================================================== quadplay✜ was created by Morgan McGuire. Stephan Steinbach provided extensive testing and design feedback, and Mauricio Vives proofread the manual. The quadplay✜ console's influences include Atari 2600, Commodore VIC-20, APL, Python, [PICO-8](https://www.lexaloffle.com/pico-8.php), [Shadertoy](https://www.shadertoy.com), [Arduboy](https://arduboy.com), and its predecessors, [codeheart.js](https://casual-effects.com/codeheart/) and [the nano JAMMER](https://morgan3d.github.io/nano). The quadplay✜ IDE and compiler are copyright 2019-2020 Morgan McGuire, including: - [`quadplay.html`](../console/quadplay.html) - [`quadplay.css`](../console/quadplay.css) - [`pyxlscript-compiler.js`](../console/pyxlscript-compiler.js) - [`quadplay-runtime-cpu.js`](../console/quadplay-runtime-cpu.js) - [`quadplay-runtime-gpu.js`](../console/quadplay-runtime-gpu.js) - [`quadplay-profiler.js`](../console/quadplay-profiler.js) - [`quadplay-host.js`](../console/quadplay-host.js) - [`quadplay-ide.js`](../console/quadplay-ide.js) - [`quadplay-edit-asset.js`](../console/quadplay-edit-asset.js) - [`quadplay-edit-code.js`](../console/quadplay-edit-code.js) - [`quadplay-edit-game.js`](../console/quadplay-edit-code.js) - [`quadplay-edit-constant.js`](../console/quadplay-edit-constant.js) - [`quadplay-font.js`](../console/quadplay-font.js) - [`quadplay-load.js`](../console/quadplay-load.js) and excluding the content described below. The IDE and compiler are licensed under the [LGPL 3.0](https://www.gnu.org/licenses/lgpl-3.0.en.html), but may be relicensed in the future. The Vim mode is by [Stephan Steinbach](https://twitter.com/stephan_gfx). The VS Code extension is by [Josef Spjut](http://josef.spjut.me/). GIF support via [gif.js](https://github.com/jnordberg/gif.js) (c) 2013 Johan Nordberg, used under the [MIT license](https://github.com/jnordberg/gif.js/blob/master/LICENSE). It includes code by Kevin Weiner, Thibault Imbert, and Anthony Dekker. QR code support via [qrcodejs](https://github.com/davidshimjs/qrcodejs) (c) 2012 [@davidshimjs](https://twitter.com/davidshimjs) used under the [MIT license](https://raw.githubusercontent.com/davidshimjs/qrcodejs/master/LICENSE). The random number generator is derived from [an implementation](https://github.com/AndreasMadsen/xorshift/blob/master/xorshift.js) of xorshift (c) 2014 Andreas Madsen and Emil Bay used under the [MIT license](https://github.com/AndreasMadsen/xorshift/blob/master/LICENSE.md). The code editor for the quadplay✜ IDE is [ace.js](https://ace.c9.io/) used under the [BSD license](https://github.com/ajaxorg/ace/blob/master/LICENSE). The physics engine is [matter.js](https://brm.io/matter-js/) and [poly-decomp.js](https://github.com/schteppe/poly-decomp.js), both used under the [MIT license](https://raw.githubusercontent.com/liabru/matter-js/master/LICENSE). The compiler uses [vectorify.js](https://github.com/morgan3d/misc/tree/master/jsvectorify) (c) 2018 Morgan McGuire under the MIT license, [recast](https://github.com/benjamn/recast) (c) 2012 Ben Newman under the [MIT license](https://github.com/benjamn/recast/blob/master/LICENSE), and [estraverse](https://github.com/estools/estraverse) (c) 2012-2016 Yusuke Suzuki under the [BSD 2-clause license](https://github.com/estools/estraverse/blob/master/LICENSE.BSD). [`LoadManager.js`](https://github.com/morgan3d/misc/tree/master/jsloadmanager) is (c) 2018 Morgan McGuire, [BSD-2-Clause](https://opensource.org/licenses/BSD-2-Clause) license. [`WorkJSON.js`](https://github.com/morgan3d/workjson) is (c) 2020 Morgan McGuire, [MIT](https://github.com/morgan3d/workjson/blob/master/LICENSE) license. [`js-yaml`](https://github.com/morgan3d/misc/tree/master/jsloadmanager) is (C) 2011-2015 by Vitaly Puzrin, [MIT](https://raw.githubusercontent.com/nodeca/js-yaml/master/LICENSE) license. [`dagre.js`](https://github.com/dagrejs/dagre) is (C) 2012-2014 Chris Pettitt, [MIT](https://github.com/dagrejs/dagre/blob/master/LICENSE) license. The boot screen font used in the emulator is [https://int10h.org/oldschool-pc-fonts](PxPlus_AmstradPC1512-2y) copyright 2016 [Int10h](https://int10h.org/), used under the [CC-BY 4.0](http://creativecommons.org/licenses/by-sa/4.0/) license. It is based on the Amstrad PC1512 BIOS font. All built-in assets are Creative Commons licensed have complete license and copyright information in the "license" property of the corresponding JSON file. Notes for Beta Testers ===================================================================================== IDE will receive major new features throughout and after the beta phase. This includes editors for sprites and maps. The API is mostly complete. I'm focusing on bug fixes and minor tweaks to improve convenience. Only some minor helpers, primarily for AI, will be added before the 1.0 release. Expect rasterization alignment rules for triangles to change slightly in order to better align for subpixel cases. The current sprite, map, disk, line, and rectangle rendering alignment is final. I will add separate functions for watertight triangle and line rasterization, which give different results than what is typically useful for individual primitives. The `make_spline()` function using `"continue"` mode will change to be a third-order curve outside of the bounds instead of a line. The package manager is not implemented and may actually be removed instead of being implemented, depending on the needs that arise in the beta. You can load relative URLs for scripts and assets right now. So, the need for packages isn't urgent as you can reuse across projects already. What packages will provide are namespaces as well as assets bundled together with a script. Change Log ===================================================================================== Changes for both the specification and implementation in each release. 2020 September 12: Beta update 48 - New game, _Doubles de Pon_ - Added `sprite.rotated_90`, `sprite.rotated_180`, and `sprite.rotated_270` - Added robot to `shapes-32x32x.sprite.json` - Added correct sprite size to `beast-soldier-32x32.sprite.json` - Added `invert_sprite_y` optional argument to `get_map_pixel_color()` - TMX maps now support rotation as well as flips - Disk, circle, text, and rectangle centering are now all aligned for subpixel offsets - IDE now shows the current filename at the top of the code editor - Context menu now keeps IDE rollout project view visible in debug layout - Optimized the performance of `rgba()` colors for `draw_point()` about 20% - Fixed `draw_text()` not returning a value in skipped frames - Fixed `noise()` for the 3D case - Fixed HSV color preview - `get_map_pixel_color()` now accepts an output value to avoid memory allocation - Fixed wrapping `draw_map()` under simultaneous transform scale and camera rotation transformations - Incompatible changes: - `get_map_pixel_color()` now accepts a range of layers and composites all values read across them - Known bugs: - HSV color preview not 100% accurate - `get_map_pixel_color()` uses wrong coordinates outside of primary bounds for wrapping maps - `draw_map()` not visible outside of central 3x3 repetitions for wrapping maps 2020 September 4: Beta update 47 - New built-in game "Beyond Control" - New example "Planet Generator" for 2.5D procedural content - New example "Clouds" of per-pixel graphics - New example "Entity" of different entity features - New `scoreboard-5` font - New `splash-00` sound - New `sparks-00` through `sparks-04` sounds - New `explode-10` sound - New `powerup-11` sound - New `shoot-11` sound - New `shoot-12` sound - New `loop-prometheus` sound - New `loop-forest` sound - New `loop-escalator` sound - New `loop-beat` sound - New `loop-wind` sound - New `beast-soldier-32x32` spritesheet - New `shapes-32x32` spritesheet - New dots, stripes, wood, and carbon console vinyl wraps - Added `gamepad.prompt["##"]` for a replacement string for the player number - Added `.debug.game` layer (see the Debug JSON section) - `debug_watch()` now allows multiple identical expressions at different locations - `debug_watch()` and `debug_print()` output are now hyperlinks to the source location that produced them - Added 320x180 support for targeting Switch, PiBoy, 720p, 1080p, and 1440p - Added support for TileKit - Added optional stick index argument to `device_control("get_analog_axes", ...)` - Added `font.spacing` and `font.glyph_size` - Packed `suchet-12` font characters more tightly to conserve memory - Optimized rendering of successive rectangles using the same `z` value - Optimized the 2D `noise()` function variant (now runs in 3/4 the time) - Incompatible changes: - Made the order of arguments for `draw_tri()` consistent with other drawing functions - `local_time().daySecond` --> `local_time().day_second` - `xz_to_xyz()` now swizzles `z` -> `y` - Games must now opt in with a game.json `dual_dpad` setting for the P1 right stick to override the P2 D-pad for dual digital stick input in single-player games - The `entity.pivot` now affects rendering as well as collision detection, overriding the sprite's pivot (it defaults to the sprite's pivot) - The start mode is now specified with `start_mode` in the game JSON file instead of an asterisk - `sequence()` now accepts bare numbers indicating frames to skip - `sequence()` now supports an `end_callback` - Made the default radius for `random_truncated_gaussian()` 2.5 standard deviations - Changed the `region` of a sprite JSON file to take `"corner"` instead of `"pos"` (the old version is accepted as a synonym for backwards compatibility at the moment) - The sprite viewer in the IDE now autoscales for tall sprites - `stop_audio()` now allows the argument to be `nil` - Added `SOURCE_LOCATION` zero-argument operator - `set_random_seed()` now defaults to a random seed based on the time - `random_value()`, `shuffle()`, and `shuffled()` now take an optional random number generator argument - IDE can now create new sound assets - IDE can now change the order of execution of scripts - IDE can now remove scripts (removed scripts are not deleted on disk) - IDE can now rename scripts - IDE project window now rolls out on hover in debug mode - `gamepad_array[]` elements now print as their name instead of properties - Increased the contrast of the text in ghost mode - Reordered quick links on the top of the manual - Rewrote the Project File section of the manual to clarify the asset vs. constant distinction - Increased the contrast on the sprite editor info data - The Import Asset dialog will now automatically default to a useful variable name - The Import Asset dialog can now import raw PNG, TMX, and MP3 files - Sprite JSON files now default to assuming a single sprite that is the size of the spritesheet if none is specified - Fonts now only count as 1/2 pixels towards the sprite pixel limit because they are compressed - Internally renamed variables and files for easier refactoring and future PyxlScript features - The fullscreen layout button now returns to full screen if tapped when already selected - IDE code editor now highlights compile-time error lines in red - Editor divider pane layout now persists over reload - Added Dualshock4 controller to the officially tested list - Added support for the [8bitdo M30](https://www.8bitdo.com/m30/) SEGA Genesis style controller - Added support for the Raphnet adapter and SEGA Genesis and Mega Drive retro bit controllers - Added `device_control()` `"load"` and `"save"` commands for JSON files - Added `touch.screen_x`, `touch.screen_y`, `touch.screen_xy`, `touch.screen_dx`, `touch.screen_dy`, and `touch.screen_dxy` accessors for screen-space (instead of camera-space) positions - Added `rgba(rgb, a)`, `rgba(hsv, a)`, `xyz(xy, z)`, `xyz(xz, y)`, `hsva(hsv, a)`, `hsva(rgb, a)` - Added `transform_ws_to_ss()` and `transform_ss_to_ws()` - Added `{br}` line break markup - Added `ABS()` intrinsic - Added `sprite.animation` property - Added Sega Genesis and Mega Drive controller support - Added `⑤ ⑥ ⓩ` characters to font mapping and all fonts - Added `design` document template for New Doc menu - Added named argument version of `draw_corner_rect()` - Added `table` constants that use external CSV files - Added `"multiply"` blend mode for `draw_sprite()`, useful for colored lighting - Added support for transposed spritesheets in the IDE sprite viewer - Added support for regions in the IDE sprite viewer - Added a global volume control on the Console menu - Added buttons to copy stats summaries from the Stats pane - Added `X_Arcade` controller icon and mapping for the [X-Arcade](https://shop.xgaming.com/) USB controller - Added `PiBoy` controller icon and mapping for the [PiBoy DMG](https://www.experimentalpi.com/PiBoy-DMG--Assembled_p_16.html) - Added `device_control("console.dir", ...)` for web browser console access - Fixed new game filename shortener to keep the beginning instead of the end of names - Fixed iterator container-mutation check when changing modes - Fixed `draw_sprite()` API links in the manual - Fixed `touch.xy` coordinates under translation transformations - Fixed recursive `push_mode()` and `pop_mode()` not preserving `draw_previous_mode()` state - Fixed `export.py` script to set read file permissions on the contents of the zipfile - Fixed constant editor vector vertical nudge value to default sign based on `y_up` setting - Fixed analog axis snapping when near 8-direction points - Fixed sprite editor not updating after JSON edits - Fixed gutters on sprites - Fixed initial `entity.size` to be based on scale for rectangular shaped entities that have initial sprites - Fixed broken images in Markdeep design documents after edits - Fixed incorrect image scaling when embedded in itch.io at 1080p - Fixed a bug that prevented `debug_watch()` on values containing string literals - Fixed IDE edits to asset JSON files not persisting after load - Fixed incorrect line numbers when using `default` expressions - Fixed 3-space indenting in .game.json files - Fixed internal assertion failure for `make_spline()` with negative time values - `clone()` and `deep_clone()` on _constants_ now clones the value and makes it mutable, while on _assets_ (other than maps) and built-in objects returns the original object. 2020 July 10: Beta update 46 - New font: `hauer-12` - New font: `robot-18` - IDE code editor now highlights run-time error lines in red - Color constant editor preview now shows the exact 16-bit color - Color constant editor preview now visualizes alpha channel - Made `local:` and `preserving_transform:` lines free versus total source statement limit - Added `gamepad_array[]` reordering dialog to support arcade configurations. Access this from the Controls tab of the debugger. - Added a breakdown of code size by file in the Stats window of the debugger. - Added a breakdown of sprite pixels by file in the Stats window of the debugger. - Fixed macOS quadplay script when quadplay and the home directory are on different volumes. - Fixed the bottom line not appearing on the editor on some browsers - Fixed binding on the animation example ninja duck key - Fixed `text_width()` being too small by one space between letters - Fixed a physics system crash on rare contact breaking situation - Fixed an API upgrade bug on object removal in Serpitron during showdowns - Fixed the mode graph clipping on the bottom - Made the mode graph scrollable 2020 July 3: Beta update 45 - Made function definition lines, `todo()`, and `assert()` free versus the total source statement limit - Optimized `debug_print()` to make it practical to print large amounts of data - The `confirm` argument to `set_pause_menu()` can now be a string that specifies additional message text - Made assets print in `debug_print()` and `debug_watch()` as their variable name - Assets with the same source URL are now guaranteed to produce live objects that are `==` to each other, except for maps, which are guaranteed to be `!=` because they are mutable - Made `clone()` and `deep_clone()` work properly on assets and constants - The `pan` argument to `play_sound()` can now be an `xy()` value for positional sound - Updated X-Arcade instructions to reflect the latest 9.14 firmware - Changed physical modern console controller mapping so that triggers are aliases for shoulders (previously P1's triggers were P2's A and B buttons) - Added `map.spritesheet` convenience helper - Added support for arbitrary properties on sprites in the `sprite.json` - Added `kenney-cartography-64x64.sprite.json` - Added `sprite.orientation_id` to distinguish unique orientations - Added `any_button_release()` - Added `explode-12.sound.json` - Added `spawn_particles_from_map_ws_coord()` to `scripts/particle.pyxl` - Optimized in-IDE game start time - The `export.py` script now ignores temporary and backup files - The `export.py` script now makes all output files world readable - Fixed a slight blue bias in alpha blending - Fixed alpha blending on sprites that are transposed at load - Fixed map coordinate documentation to match the practice, which is that map coordinates are at tile _corners_ if there is no `offset` on the map. - Fixed too-aggressive caching of map loading from IDE - Fixed `draw_map()` case using named arguments for `replacement_array` - Fixed `transform_map_space_to_ws()` and `transform_ws_to_map_space()` to map integer map coordinates to the centers of map tiles, as specified in the manual - Fixed constant references to assets - Fixed RPG demo crash - Fixed vehicle demo button prompts 2020 June 23: Beta update 44 - Incompatible change: `draw_text()` multiline `y_align = "center"` and `y_align = "bottom"` now adjust to the entire text block and not the first line - Incompatible change: Renamed `##-Coin.sound.json` to `coin-##.sound.json`, `##-Shoot.sound.json` to `shoot-##.sound.json`, `##-Jump.sound.json` to `jump-##.sound.json`, `##-Explode.sound.json` to `explode-##.sound.json`, `##-Powerup.sound.json` to `powerup-##.sound.json`, `##-Hit.sound.json` to `hit-##.sound.json`, `##-Wild.sound.json` to `wild-##.sound.json` - New font: `suchet-12` - Support for custom properties on TMX maps - Auto-generated TODO lists in the IDE from `todo()` statements in code - Errors will now open the appropriate file and line in the IDE - Changed document editor layout to show 50% preview and 50% source editor - Load a new script faster after creation - Active debugger tab persists over reloading - System pause menu now pauses game sound effects - Syntax highlighting in the IDE for `parse()` and `random_within_cube()` - Added Shift+F6 hotkey for label generation - Added a context menu for modes in the project view of the IDE - Added `sequence.BREAK` and `sequence.NEXT` options - Added five-argument version of `lerp()` - Added `LERP()` intrinsic - Added `starts_with()` and `ends_with()` functions for strings - Added "go to line" command (Ctrl-G/⌘-G) for the IDE - Added `engine-00.sound.json` and `engine-01.sound.json` - Fixed Windows paths in URLs - Fixed Add Existing Asset... on Windows - Fixed rectangle alpha blending - Fixed `random_within_sphere()` crashing - Fixed asset json editor changes being overwritten by caches - Fixed alpha channel of screenshots - Fixed emulator alignment on Safari - Fixed constant parsing for `pi` in game.json files - Fixed map preview rendering (was broken by the previous update) - Fixed scalepix tool (was broken by the previous update) - Fixed new game-level constants reverting to zero on Chrome - Fixed project asset/constant scrolling to allow full variable names to be seen - Fixed automath sometimes leaving the cursor off by one character 2020 June 14: Beta update 43 - Incompatible change: it is now illegal to mutate the container being iterated over by a `for...in` loop. Use `for x in clone(container):` as a workaround if you need mutation, which is still relatively fast. - Incompatible change: `+ - / * += -= /= *=` operators are now illegal to use on arrays (they are still overloaded for objects) - Incompatible change: `for` loops now evaluate the upper bound only once, before the loop body begins - Incompatible change: renamed `Blip*.sound.json` to `blip*.sound.json` - Temporary Network Multiplayer workaround solution (to be replaced with a more straightforward method at release) - Changed screenshot filename format to international date format to sort correctly - Added IDE option to restart a paused game automatically when focus switching back to the browser from an external editor or other tab - Optimized nonrotated opaque sprite drawing by up to 2x and halved memory usage by reducing GPU implementation to true 16 bit - Optimized Safari sprite drawing using forced integer coordinates for up to 4x performance increases in specific cases - Optimized rotated and scaled opaque sprite drawing by 10% by handling this case separate from tinting, alpha test, and opacity - Optimized thick line rendering by reducing virtual CPU Logic overhead - Optimized default `for` and `for...in` loops under the new semantics - Scripts loaded from `quad://scripts/` no longer count against the total program size - The game.json file is now directly editable in the IDE - Errors now report the filename with the URL truncated if it matches the game URL - The game.json structure for docs stores only raw URLs now, not metadata - Made the project pane wider to make it easier to see long variable names - Disabled browser navigation hotkeys to prevent accidentally leaving the IDE - Disabled Chrome browser two-finger back gesture to prevent accidentally leaving games or the IDE - Added syntax highlighting to inline code in the manual - Added `IDE_USER` constant - Added `iterate()` function - Added `lerp_angle()` - Added `perceptual_lerp_color()` - Added `examples/perceptual_color` - Added `explode-11.sound.json` - Added `xy`, `dx`, `dy`, and `dxy` values to `device_control("get_mouse_state")` - Added syntax highlighting for `touch` in the IDE - Added syntax highlighting for the type-testing functions `is_array()`, `is_object()`, etc. in the IDE - `for` loops now test for illegal containers - Added mouse support to the fluid simulation demo - Added more error checking to entity functions - Added `todo()` debugging statement - Added `"reference"` constant type - Added `scripts/particle.pyxl` reusable script - Added `sounds/shoot-10.sound.json` - Tooltips in the project listing of the IDE now show the full names of variables and scripts as well as URLs and descriptions - Improved error checking for `find_path()` - Made the Debug mode use a 1.5x scale emulator on displays of 1600 pixels wide or less (factoring in pixel doubling for retina displays) and 2.0x scaling at higher resolutions - Linked the game folder display in the IDE to opening the folder on disk - Fixed missing clamping of RGB colors outside the 0-1 range during rendering - Fixed HSV to and from RGB conversion - Fixed line number errors for programs with long lines - Fixed the bottom rows of the code editor being cropped - Fixed automath operating on non-pyxl files - Renamed `get_map_sprite_by_draw_coord()` --> `get_map_sprite_by_ws_coord()` - Renamed `get_map_pixel_color_by_draw_coord()` --> `get_map_pixel_color_by_ws_coord()` 2020 May 23: Beta update 42 - Incompatible change: Removed subscripts as array indices. They are still valid characters for strings. - Incompatible change: renamed "sound" --> "audio" and "audio clip" --> "sound" in the API - Made `Delta` autocorrect to `Δ` without requiring a following space in the IDE - Made rename and add asset/constant update faster - Search and Replace in the editor now triggers autosave - IDE open dialog now includes game descriptions and icons - P1's right stick and triggers no longer provide input to P2 unless P2 does not have a physical controller - New sound `loop-chilltech.sound.json` - New sound `music-vice.sound.json` - RPS game now times out after about 15 seconds when a player hasn't chosen - Serpitron game now has shorter showdown levels in 2-player games - Moved the code editor below the map/sprite/font view in the IDE - Added Vaporwave 3D example program - Added "New Asset..." dialog in the IDE for creating new sprites - Added `source_url` field for sprites to support export processesqu - Added autocorrect support for additional capital Greek letters `ΓΔΘΛΞΠΣΦΨΩ` - Added `transform_es_to_es()` - Added right-click menu for music assets - Added new Twin Analog stick example for dual stick shooters - Added `Arcade` (quadplay native), `Arcade_X` (Xbox labels), and `Arcade_PS` (PlayStation labels) controller options - Added X-Arcade controller information to the manual - Added buttons (as well as D-pad) choices for RPS game to better conceal player movements on an arcade controller - Renamed map transformation functions to `transform_ws_to_map_space()`, `transform_map_space_to_ws()`, `transform_ws_z_to_map_layer()`, and `transform_map_layer_to_ws_z()` - Changed default tab/indentation size to four spaces to reduce conflicts with Python editors - The quantize tool now allows toggling the "dither" option after dropping the image - Made quantize tool display using nearest neighbor interpolation - Improved Safari performance by warming the sprite blitter JIT during the quadplay logo screen - Improved Safari performance for Beat the Gobblins by eliminating large alpha-masked sprites - Improved Safari performance by removing explicit nearest-neighbor upscaling and using CSS zoom - Improved Safari load time on dual-core processors by spreading out asynchronous requests in time - Improved `lerp()` and `clamp()` performance - Fixed compilation of fractional degrees and percentages - Fixed map occlusion culling (was showing empty tiles) - Fixed loading quad:// games from the command line - Fixed blurring on Safari by using CSS zoom instead of CSS scale on that platform and adjusting layout to compensate - Fixed Safari mouse and touch event scaling - Fixed Debug UI layout not allowing full horizontal scrolling of the editor - Fixed button prompt alignment in Broderick-7 font 2020 May 8: Beta update 41 - Added named argument versions of all drawing routines - The new game's title now appears in the game and JSON when creating a new game in the IDE - IDE now automatically reloads externally changed files from disk when it regains focus - Faster saves on constant changes in the IDE - Added "Show in Finder/Explorer" for assets in the IDE - Added "Open with..." support for Photoshop, Krita, Aseprite, GIMP, Audacity, and Tiled in the IDE - Avoided IDE touching unchanged source files on disk to improve external editor interop - Added top runner sprites to complete the Action Spy set - Added support in the `quadplay` script for Windows systems with multiple drives - Added 'y' and 'z' superscript characters to fonts and the compiler (there are no subscripts for these because they do not appear in Unicode) - Documented backdoor mouse support via `device_control()` - Changed the mouse cursor to a crosshair over the emulator screen - Fixed relative paths when creating a new game from the IDE - Fixed `animation.frames`, which was completely broken in the previous release - Supported hierarchical directory structure under `~/my_quadplay/` - Implemented "automath" autocorrect-style typing of Unicode symbols in the text editor - Assets now appear in consistent alphabetical order in the project view of the IDE - New "Z-Car" wireframe 3D example 2020 May 1: Beta update 40 - Added `set_camera()` and `get_camera()` and global camera support to all drawing functions for camera rotation, translation, and zoom - Added occlusion culling optimizations to `draw_map()` for eliminating completely covered tiles - New sportscar sprites - New attack helicopter ("chopper") sprites - New tank sprites - New road tile sprites - New suchet-9 font - Removed browser context menu from most UI surfaces (it is still present on links and text boxes) - Constants can now be deleted from a project - Assets can now be renamed in a project - Added `pos`, `angle`, and `scale` arguments to `draw_map()` - Implemented z clipping for `draw_map()` - Added `examples/vehicles` sample - Renamed "draw" space to "world" space and introduced "camera" space - Removed screen-space touch events - Changed all `device_control()` arguments to snake case - map.json `z_scale` is now permitted to be 0 - Increased the built-in epsilon value by 10x and decreased the sprite draw call order-preserving offset by 1000x to ensure that epsilons can override sprite draw call order - Made Ctrl/Cmd-S do nothing, to avoid accidentally saving the browser page when using the IDE (since the game autosaves) - Fixed map preview rendering of flipped sprites - Fixed `set_clip()` with `pos = nil` - Added autocorrect for math symbols option to the Tools menu 2020 Apr 25: Beta update 39 - Added ⓔ and ⓕ buttons, which are mapped to shoulder buttons on physical controllers - Added a new playable game, "Across the Lake" - New games can now be created from the browser based IDE using "New Game..." - Games can now be loaded from the browser based IDE using "Open Game..." - Changed `lifetime` and `duration` arguments to various APIs to `frames` for consistency with the sprite and other settings, and to match the name "frame hook" - Fixed Ctrl/Command+C not copying in the IDE - Added an Animation section for sprites - Added `animation.frame()` for accessing animations by game frames instead of sprite index - Added button prompts to all fonts - *Incompatible change*: Renamed `"flip_y"` to `"y_up"` in .map.json and .game.json files - Fixed editor making relative URLs inside .sprite.json and other asset files absolute - The IDE now uses `$HOME/my_quadplay` as the root for new games - `any_button_press()` now responds to any `touch` as well - Increased the QR code size in the host tab to make it easier to scan - Changed the way that the width of the white space character is computed for fonts. It now uses the largest width of the `"il¹;["` characters - 2x performance optimization for alpha blending large sprites with no rotation or scale - Added `get_sound_status()` function - The IDE now puts badges on constants that are uneditable because the .game.json file is on a remote server or built-in - `quadplay` script no longer prints all internal messages - Changed default startup UI layout to `Emulator` for non-IDE mobile, `Maximal` for non-IDE desktop, and `IDE` if running in IDE mode 2020 Apr 17: Beta update 38 - Kiosk mode now completely fills the screen, removing all quadplay UI - Pressing play or reload now saves all documents immediately - Prevented frame rate changes during the first 1000 ms of a new mode to allow the JIT to catch up - Ghost mode for livestreaming the development environment - Pressing Play now restores keyboard focus to the game - Added touch example program - Added arrows for nudging vector constants in the IDE - Added sliders for color constants in the IDE - Fixed syntax highlighting for `with`, `entity_add_child`, and `entity_remove_child` - Improved frame rate scaling to avoid dropping to 30 Hz during transient browser hitches - Changed the player 1 keyboard mapping to B,H,V,G for the main buttons to make room for new virtual "shoulder" buttons - Changed mapping of game reload to Ctrl+R on Safari to prevent browser reload of the page, and clarified all hotkeys with improved tooltips. - Added PS5 controller mappings and graphics - Optimized sequential rendering of multiple sprites with the same `z` value and clipping region - Argument object version of `draw_map()` - `draw_map()` now accepts optional `pos`, `scale`, and `angle` arguments - Recorded GIFs now download in the same way as recorded PNGs - Added generalized `transform_to()` and `transform_from()` routines for points - Added support for Xbox Series X controller - Added a second row of 4x wide glyphs to the font format - Redrew all fonts with new glyphs for ⓔ, , ⓝ, ⓗ, alt, left shift, right shift, and tab 2020 Apr 11: Beta update 37 - New wide-screen "Debug" UI layout option with 2x scale emulator - Undo and redo hot keys and buttons in the code editor - Changed case color names - Added new orange and white case color options - Tuned gold case color - Improved case layout for small sizes - Can now edit string, number, `xy()`, `xz()`, `xyz()`, `hsv()`, `hsva()`, `rgb()`, `rgba()`, and boolean constant values in the IDE while the game is running - Added unique icons for different constant types in the IDE - Dialog for creating new constant values - Made `replace(string, object)` operate on all values simultaneously - Fixed IDE syntax higlighting for boolean operators - `draw_line()` now accepts a width argument - New wright-8 font - New deja-7 font - New deja-6 font - New deja-5 font - New deja-4 font - New deja-3 font - "Sproing" and "Camera Zoom" examples - Constants now have a `description` documentation field that appears in the IDE and as tooltips - Updated markdown and [Markdeep](https://casual-effects.com/markdeep) processing to version 1.10 - Created more room for the code editor in Debug view 2020 Mar 30: Beta update 36 - Syntax highlighting for intrinsics in Emacs and the IDE - Documented the autoscaler resolutions - Optimized IDE load time using `defer` - Optimized game load time using `async` and separate CPU and GPU scripts - Renamed `ASSET_CREDITS` --> `CREDITS` - Moved the console credits out of the `CREDITS.code` section and into their own `quadplay` section - Made four-way ball splits in Quadpaddle example game - When launching without the IDE, always go full screen - Document editor now preserves scroll position when updating - Document editor now forces cache override - Added paddle shield powerup in Quadpaddle example game - Added `entity_remove_all()` to syntax highlighting - Added `miniroguelike-8x8.sprite.json` - Added the Network section of the manual - Added the advanced Physical Consoles section - Added `examples/roguelike` - Added `--kiosk` mode for the `quadplay` script - Fixed recursive `overlaps()` on entitys with children - Fixed spritesheets for maps not showing in the project viewer 2020 Mar 25: Beta update 35 - Editing for sprite, font, map, and sound metadata directly in the IDE - Fix for the `quadplay` script when launched with an explicit `.game.json` file - Built-in assets cannot be modified and are shown with lock badges on their icons - Remote assets cannot be modified and are shown with cloud badges on their icons - Disabled reloading while the editor is saving - Can change the initial mode from the IDE - All four gamepads are now enabled in the launcher for navigating to a game - Patches for the sprite editor UI 2020 Mar 18: Beta update 34 - New wide editor UI IDE view mode - Maximal UI now enters full-screen mode even when the IDE is enabled - Editing is enabled for modes and scripts in the IDE - Code editor font size is now adjustable - Can now create new modes and scripts in the IDE - Can now edit screen resolution and flip y-axis in the IDE - Can now change the game license in the IDE - Can now change the game title, copyright, and developer in the IDE - Game description and metadata are now visible and editable in the IDE - Added SN30 Pro controller settings - Added more explicit dual-stick and shoulder/trigger control documentation - `draw_text()` shadows now apply after outlines, so they are on the outside - Per-tab editor state for undo/redo, selection, and cursor position 2020 Mar 7: Beta update 33 - Added `CONSTANTS` and `ASSETS` objects - Added `default`, a "nullish-coalescing" operator for creating default values - Added R. P. S. game - Syntax highlighting for `#RGB` colors in emacs 2020 Mar 5: Beta update 32 - Added long text button prompts for SPACE, ENTER, RETURN, SELECT, START, SHARE, and OPTIONS to fontgen - Converted the scalepix tool to dark mode - Optimized set controls OS dialog layout for all screen sizes - `font.lineHeight` -> `font.line_height`, `font.charSize` -> `font.char_size`, `font.letterSpacing` -> `font.letter_spacing` - Renamed `draw_text()` arguments `wrapWidth` -> `wrap_width` and `textSize` -> `text_size` - Added auto-generated asset credits screen on pause menu - Added .game.json constant types for `xz`, `hsv`, and `hsva` - Included time in screenshot filenames - Added joint `def-preserving_transform` block to reduce indentation - Added the Unmatched Push and Pop Mode section explaining complex mode transitions - Renamed `assetCredits` -> `ASSET_CREDITS` - Added serifs to Broderick font capital I variants - Made touching the screen in IDE mode not trigger button presses 2020 Feb 24: Beta update 31 - Removed context menu from emulator to make touch screens more responsive - Fixed virtual controller responsiveness on Android Chrome - Sharpened boot screen text on Safari - Fixed `gamepad_array[i].angle` to follow the current Y-axis scaling and match `draw_sprite()` angle - Changed the internal font image layout and added explicit keycaps characters to all fonts for all buttons used in controller and keyboard mappings to distinguish them from regular letters - Added `bitnot` text operator as a synonym for `~` - `collision_` --> `contact_` in the API to reduce unique terms - Switched all GUI tools to dark mode styling - quantize tool now allows dropping the image anywhere on the page - Improved fontgen button prompt draft characters 2020 Feb 17: Beta update 30 - Fixed Beat the Gobblins trying to write to read-only properites - Fixed confirmation dialog crash in OS reset menu - Reduced the number of rats in Serpitron - Reduced number of buildings on urban levels in Serpitron - quadplay internal server now does not return directory listings, to increase security - quadplay script now works from any directory for games in any directory - `quadplay --host` now launches faster on macOS - Optimized manual loading time by removing mathjax 2020 Feb 16: Beta update 29 - Changed the gamepads to define the direction of `x`, `y`, `dx`, `dy`, `xx`, and `yy` based on the current transformation at the time that they are accessed - Reduced number of rats in single-player Serpitron - Reduced the coffee speed in Serpitron - Changed `spriteUrlTable` --> `sprite_url_table` in map format - Fixed single-player snake hitting itself on the donut level in Serpitron - Fixed SpeedStreet loading crash introduced in the previous beta - Fixed `map.wrap_y` and `map.wrap_x`, which were broken by the camel case to snake case conversion in a previous beta - Fixed caching where multiple json files reference the same sound or image - Fixed several bugs in the RPG example - Optimized game launch time and memory utilization by eliminating in-memory backup copies of immutable assets 2020 Feb 15: Beta update 28 - Added optional `gamepad` argument to `any_button_press()` - Made controls menu option more visible in standalone game mode - Changed all fields of map to use snake case - Added `--zipfile` argument to `export.py` to streamline itch.io distribution of games - Made `export.py` runnable from any directory - Made `export.py` default to a standalone export - Added Beat the Gobblins game by Stephan Steinbach - Fixed IDE visualiztion of modes to support `push_mode` and `set_mode` with arguments - Added the `touch` API (no draw transform support in this implementation) - Added `xy` and `dxy` properties to `gamepad_array` elements - Improved the startup play icon for mobile using svg 2020 Feb 6: Beta update 27 - Added `xyz_to_rgb()` and `rgb_to_xyz()` - Added `xy_to_xz()` and `xz_to_xy()` - Added `xy_to_xyz()` and `xz_to_xyz()` - Added `MAT2x2_MATMUL_XY()` and `MAT2x2_MATMUL_XZ()` - Fixed outlines breaking up letters on script fonts - Removed the home button from the UI, as the in-game OS menu now handles this - Forced immediate interaction in autoplay mode to unlock fullscreen and audio context features in various browsers - Removed quadplay branding on the mobile welcome screen and removed escape to OS from standalone games to emphasize the game's own branding - Allowed keyboard and gamepad input to activate a standalone game from the welcome screen 2020 Feb 2: Beta update 26 - Added `examples/highscore` example - Added `xz()` for convenience when working with top down coordinate systems, and corresponding intrinsics - Browser tab label is now the game title - Significant copyediting of the manual by Mauricio Vives - Changed the definition of `override_color` alpha for `draw_sprite()` - Added `array_value()` support for strings - Fixed Emacs syntax highlighting matching keywords that appear within variable names - Fixed multiple bugs in `tools/export.py` and supported games not in the quadplay directory tree - Fixed `flip_y` for maps - Fixed `save_local` and `load_local` - Fixed `join()` default separators - Fixed `parse()` for nested objects within arrays 2020 Jan 29: Beta update 25 - Converted the entire API from camelCase to snake_case to improve readability and more closely resemble Python and Lua - Replaced all instances of `rnd` with `random` and `int` with `integer` in the API - `random_int()` -> `random_integer()` - `srand()` -> `set_random_seed()` - `pad[]` -> `gamepad_array[]` - Removed most scroll bars from the IDE on Windows - Clicking on gamepad icon now displays the name of the gamepads in the IDE - Added `hauer-6` font asset - Added `cruise-7` font asset - Added `connelly-7` font asset - Added `thompson-8` font asset - Increased vertical spacing on `cga-7`, `deja-8`, and `cpc-14` fonts - `draw_text()` now returns a tighter vertical bounding box - Added kerning for script fonts - Added `examples/fontpreview` example 2020 Jan 25: Beta update 24 - Added `physics_entity_has_contacts()` for optimized contact tests - Fixed `physics_remove_all()` crash - Increased physics broken contact forgiveness queue length to four frames to better maintain ground contact for sliding objects - Fixed sustained physics contacts for fast moving objects not updating position properly - Fixed `"Game start"` argument being passed to the start mode's `enter` event section - Added `tools/export.py` tool - Made `tools/quaddepend.py` able to launch directly as a script on macOS and Linux - Renamed internal BetterJSON library to WorkJSON - Centered ninja sprites - Added detection for 8BitDo SN30, SF30, and Zero 2 controllers - Redesigned the internals of the virtual sprite and font hardware memory system 2020 Jan 18: Beta update 23 - Redesigned profiler output in the "Stats" IDE tab to show game logic, physics, and graphics time separately - Rewrote framerate scaling to maintain the best possible motion appearance independent of framerate - Optimized memory management for physics attachments by reference counting and weak pointers - No longer count quadplay OS resources against the game's limit - Corrected the emulator screen position to remain centered during resizing - Added more information on physical controllers - Improved manual document layout on mobile phones in portrait mode - Added `ninja-pink-32x32.sprite.json` - Added `ninja-idle-64x64.sprite.json` - Adjusted ninja colors 2020 Jan 14: Beta update 22 - Implemented game frame rate throttling to 60 Hz on high refresh rate monitors - Fixed keyboard event handling when the game is not making framerate - Restored forum link in the IDE - Added `.nojekyll` and `_config.yml` files for proper hosting of quadplay system filenames that begin with underscores on github.io - Improved button prompt glyphs and vertical spacing in the nano-4, nano-5, scoreboard-6, scoreboard-7, and deja-8 fonts - Fixed controls menu for games with y = up 2020 Jan 13: Beta update 21 - Added support for Switch Pro, JoyCon, PlayStation 3, Xbox360, and Stadia controllers - Replaced with `◅ ▻` with `◀ ▶` in fonts - Added `▼` to fonts (all four cardinal solid arrows are now represented) - Added a system pause and configuration menu bound to the ⓟ/Start button - Added a startup message for standalone games notifying players of the system menu button - Added the symbol to all fonts - Removed the ⓟ gamepad button from game access space - Added an event section for `pop_mode`, which can be overloaded for the mode being returned from - Added `quaddepend.py` script for printing dependencies of a game file - Changed quadplay script default to rejecting external connections and made the argument to enable mobile support `--host`, replacing the previous `--secure` mode - Showed sprite pivots in the sprite viewer - Added `entity.is_sensor` property - Added 64x44 controller spritesheet - Separated emulator settings out of the Tools menu into a new Console menu - Added [scalepix✜](../tools/scalepix.html) tool for upscaling sprites and fonts - Changed the `gamepad_array[].prompt` to be a mapping for use with `replace()` instead of raw constants and updated example programs to use it - Documented the HOTAS `gamepad_array[].type` - Added more error checking for `xy()` to catch common typos - Added eight new blip UI sound effects - Fixed `reset_game()` running the game at double speed - Fixed `game_frames` and `mode_frames` starting at 60 - Redesigned boot and startup animations - Restored `examples/text` program that was broken by the previous update - Added `get_background()` 2020 Jan 3: Beta update 20 - Renamed `addEntityChild()` to `entity_add_child()` - Renamed `removeEntityChild()` to `entity_remove_child()` - Renamed `updateEntityChildren()` to `entity_update_children()` - Renamed `physicsStepEntity()` to `entity_simulate()` - Renamed `drawRect()` to `drawCornerRect()` - Renamed `draw_spriteRect()` to `draw_spriteCornerRect()` - Made `entity_simulate()` use `entity.drag` and invoke `entity_update_children()` - Added hardware physics support. See the Physics section for the API - Added physics debugging to the IDE - Added [physics example](../console/quadplay.html?game=quad://examples/physics&IDE=1) - Added `oscillate(x, lo, hi)` and deprecated `oscillate(x, m)` - Added `entity_remove_all()` - Allowed more flexible JSON syntax for data files - Added BetterJSON.js to credits - Added optional `pos`, `scale`, and `angle` arguments to `draw_tri()` - Added `drawRect()` that is centered and takes an optional `angle` argument - Added `drawPloy()` for drawing convex polygons - Documented that `draw_tri()` ignores winding order - Updated `tools/pyxlscript-mode.el` emacs syntax highlighting for new APIs - Fixed `tools/pyxlscript-mode.el` emacs syntax highlighting of color literals, negative numbers, and `size` properties - Optimized `overlaps(region, point)` test - Changed default entity name from `"Anonymous"` to `"entity"` + unique ID - [fontpack✜](../tools/fontpack.html) now allows dropping the source PNG anywhere on screen 2019 Dec 30: Beta update 19 - Added the Inspiration section - Added support for per-name (i.e., per-animation) pivots on spritesheets - Added `"setDebugFlag"` and `"getDebugFlag"` commands for controlling the IDE via `device_control()` - Added preview images in the Built-In Games section of the manual - Added [poly-decomp.js](https://github.com/schteppe/poly-decomp.js) to dependencies - Made `require`, `requires`, `default`, `otherwise`, and `swap` into reserved words - Restored the instruction manual tab title to "manual✜" to make it easier to see in the same browser hosting the IDE - Fixed audio on Safari desktop browser - Removed `entity.acc` and `entity.twist` properties - New properties for physics: `entity.friction`, `entity.stiction_factor`, `entity.restitution`, `entity.drag`, `entity.contact_category_mask`, `entity.contact_group`, and `entity.contact_hit_mask` - Added `entity_apply_force()` and `entity_apply_impulse()` - Added `magnitude_squared()` function 2019 Dec 25: Beta update 18 - Added Deploying Games section - Added [Serpitron](../console/quadplay.html?game=quad://games/serpitron&IDE=1) sample game - Removed `extendPostEffects()` and reverted definition of `set_post_effects()` to match beta 16 - Added `compose_transform()` - Renamed `addFrameSequence()` to `sequence()` - Added `entity.pivot` and spritesheet pivots - Fixed Chrome and Safari blank region on the bottom of the IDE - Made deja-9 font glyph widths more consistent - Raised mid-glyph bar for capitals 1px on deja-8 font 2019 Dec 14: Beta update 17 - Fixed `get_clip()` off-by-one error - Changed `intersect_clip()` to follow the argument conventions of `set_clip()` - Fixed `draw_text()` using the incorrect vertical clipping region - Added `last_value()` and `last_key()` for arrays and strings - Made `floor()` and `ceil()` variants that take a rounding precision - Added `fast_remove_value()` - Fixed misalignment of `-` character and enlarged the `+` character in the broderick-7 font - Added `delay()` and `addFrameSequence()` - Added options for open-ended line segments in `drawLine()` to support drawing polylines and curves with transparency - Fixed `set_post_effects()` background color crashing the emulator - Made Modes slightly wider in the visualization graph to accomodate longer mode names - Fixed a bug in the parsing of `because` statements that contained parentheses - Added support for type `"object"` in game JSON constants - Added `broderick-14` font - Made `loop()` work on vectors - Made `noise()` work on vectors - Added `extendPostEffects()` and `get_post_effects()` - Fixed `set_post_effects()` not resetting to defaults first - Added optional `reverse` argument to `sort()` - Increased analog stick dead zone to 40% to avoid accidental cross-axis input 2019 Dec 1: Beta update 16 - Added support for `"array"` constant types in `.game.json` files - Added `--secure` option to the quadplay script to prevent other machines from connecting to the local webserver - `draw_text()` markup is now implemented - `text_width()` now supports markup - Added `duration` and `period` to spritesheet animation arrays - Upgraded the `quadplay` script to use a multithreaded server when Python 3.7 or later is available - Fixed a 1-pixel overdraw in `drawSpriteRect()` - Made `push_front()` and `push()` return a pushed value - Overloaded `atan(xy)` - Added `insert()` - Fixed a parser error on `for` loops that have extra parentheses surrounding the test - Made documents appear at 80% scale when viewed in the IDE - Upgraded to Markdeep 1.07 for markdown processing - Changed the default markdown style sheet to have less vertical spacing and use a sans serif font - Fixed a bug in `push_mode()` when arguments are provided - Fixed handling newlines in JSON multiline strings across various OS conventions 2019 Nov 24: Beta update 15 - JSON files may now contain multiline strings using backquote: `...` - `sprite.json` files now support per-sprite animation frame timing - Updated the ninja sprites with animation durations and the `examples/animation` code demonstrating how to use it at runtime - Made the `quadplay` command line script shut down more gracefully on key press - Added per-sprite info viewer in the IDE - Added slow play button for debugging animations and interaction - Added the specification for `markup` on `draw_text()` (but not the implementation) - Improved the shape and line spacing for the `roman-8` font - Added `replace()` for strings - Added optional last, pair, and empty separators for `join()` - Added [Text](../console/quadplay.html?game=quad://examples/text&IDE=1) example 2019 Nov 17: Beta update 14 - Added `fool-9.font.json` - Added `make_random()` - Added `random_integer(lo, hi)` and deprecated `random_integer(n)` - Added `random(lo, hi)` overload - Added optional `random()` function argument to `randomBall()`, `randomSquare()`, etc. - Renamed `randomBall()` --> `random_within_sphere()`, `randomSquare()` --> `random_within_square()`, `randomDisk()` --> `random_within_circle()`, `randomSphere()` --> `random_on_sphere()` - Added `random_gaussian()`, `random_gaussian2D()`, `random_gaussian3D()`, `random_truncated_gaussian()`, `random_truncated_gaussian2D()`, random_truncated_gaussian3D()`, `random_on_cube()`, `random_within_cube()`, `random_intege(rlo, hi, random)`, `random_sign()`, `random_on_square()` 2019 Oct 4: Beta update 13 - Fixed RPG demo broken sprite paths - Fixed Boids demo broken sprite paths 2019 Oct 1: Beta update 12 - Added optional `region` to Sprite JSON files - Increased video RAM by 1 MB, for a total of 10.5 MB - Increased error checking for Sprite JSON files to detect typos - Increased robustness to load-time errors - Added `SIGN()` intrinsic - Made `sign()` work on vectors - Caught CORS errors on sprite loading and reported to GUI - Internal objects now `debug_print()` and `unparse()` as `«type objname»` instead of just `objname` - Fixed `forceReload=1` breaking map loading - Implemented pivots for sprites and entities (currently not exposed in the API) 2019 August 30: Beta update 11 - Added `ordinal` and `ordinalabbrev` to `format_number()` - Fixed implementation errors with `Runtime` naming clash on Firefox - Faster reload (no longer force reloading of `quad://` assets when locally hosting) - Documented `quadplay.html` arguments - Restored `get_transform()` to the API - Fixed `"oscillate"` extrapolate mode crash for `array_value()` 2019 August 25: Beta update 10 - Added support for `docs` in the `game.json` file using Markdeep, Markdown, HTML, and text format. Good for game design docs, TODO lists, and game manuals - Added support for Ctrl+G as an alternative GIF recording keystroke - Added `MIN()` and `MAX()` intrinsics - Fixed `opacity == 0` on `draw_sprite()` to draw nothing instead of full opacity - Added `randomBall()` and `randomSphere()` - Changed sprite.json name for a single `xy()` to be a sprite instead of an animation 2019 August 17: Beta update 9 - Added `nanob-3.font.json` (like nano-3, but with thinner L and I characters) - Patch for emulator view resizing for new dimensions on slower browsers - Added `device_control()` `"getAnalogAxes"` command - Renamed `index.html` to `quadplay.html` for improved itch.io compatibility 2019 August 16: Beta update 8 - Allowed `for` and `with` variable lists to be split across multiple lines - Added `nano-3.font.json` - Added `space-planet.sprite.json`, `space-atmosphere.sprite.json`, `space-moon.sprite.json`, and `space-ring.sprite.json` - Made the JSON parser report line numbers instead of character positions for errors - Added `get_clip()` for returning the current clipping region - Added `device_control()` support for setting the prompt characters for controllers 2019 August 12: Beta update 7 - Added two-argument version of `round()` - Added Linux button mapping for the 8bitdo SNES30 controller - Added the spread operator for variable number of arguments - Fixed arguments to `enter` - Added `…¿¡?` to the characters at which `draw_text()` can word wrap - Increased GIF recording pixel size for 64x64 games - Fixed compilation of repeated `if`...`then` on a single line - Added support for Thrustmaster Flight Hotas X - Added new intrinsics `MAT3x4_MATMUL_XYZW()`, `MAT3x4_MATMUL_XYZ()`, `MAT3x3_MATMUL_XYZ()` - Added `explosion-realistic-128x128.sprite.json` - Fixed `quadplay` script not launching the correct game on Windows - Added overloaded `xy()` and `xyz()` for arrays - Increased sprite sheet limit from 64 to 128 (no increase in total memory, however) 2019 August 8: Beta update 6 - Added `scoreboard-6.font.json` - Added `nano-4.font.json` - Fixed `XY_MUL()` intrinsic - Fixed `set_transform()` documentation to match current API - Added three argument version of `loop()` - Allowed `draw_text()` word-wrapping to search further back for a good break point - Reduced boot loader font size for smaller screens - Added `text_size` argument to `draw_text()` - Added units documentation to `entity` physics properties - Added space (`␣`) and return (`⏎`) button characters to fonts - Added alternative keyboard and 8Bitdo Zero controller to `controllers-32x22.png` - Added `gamepad_array[i].prompt.type` - Fixed compilation of `if...then...else` on lines with other control flow - Fixed asset credits leading "by" lacking a trailing space 2019 August 2: Beta update 5 - Required a space for `sin`, `cos`, `tan` automatic parenthesis insertion - Added Ice Time to the manual - Added label images for all example programs 2019 August 1: Beta update 4 - Fixed self-overdraw in disk and circle rendering - `direction()` now returns a non-unit vector if the input is less than 10-10 - Added [Fluid simulation](../console/quadplay.html?game=quad://examples/fluid&IDE=1) example program - Added `octant-17.font.json` - Added `CLAMP()`, `RGBA_LERP()` and `RGB_LERP()` - Fixed compilation bug with Greek letter identifiers - Made underscore-"subscripted" Greek letters legal identifiers. For example: θ_interior, μ_p 2019 July 17: Beta update 3 - Added syntax highlighting in emacs for `bitand`, `bitor`, and `bitxor` - Documented `log()`, `log2()`, and `log10()` - Added optional `result` argument for `get_sprite_pixel_color()` to reduce memory allocation - Made `at`, `because`, `reset_game`, `launch_game`, and `quit_game` into reserved words - *Incompatible change*: Changed how the note/reason works for `push_mode`, `pop_mode`, `set_mode`, `launch_game`, `quit_game`, and `reset_game`. The syntax now uses the `because` keyword after the complete expression instead of including the note as an argument. - `enter` can now take optional arguments, which are provided by `set_mode()` or `push_mode()` - Added `deep_clone()` - 10% performance optimization for adjacent `drawPoint()` calls - Added the Intrinsics section 2019 July 13: Beta update 2 - Added `loop-dark-thriller.mp3` audio clip - Fixed `mget` --> `get_map_sprite()` in manual - Fixed Unicode characters not appearing correctly on the ad blocker warning page - Added `remove_all()` - Made IDE mode not automatically full-screen the emulator - Added specifically-stylized versions of `ⓧ`, `ⓨ`, `Ⓞ`, `⍍`, `▣`,`⧉`, `☰`, `ⓕ` to fonts for use as button prompts for specific controllers - Fixed `override_color` in `draw_sprite()` - Added `controllers-32x22.sprite.json` - Added `prompt` field to `pad` instances/`joy` variable for button prompts - Fixed missing `tan()` function in implementation - Fixed screen alignment on resolution change when games are run from the launcher 2019 July 5: Beta update 1 - Vim editor plugin (Stephan) - Visual Studio Code plugin (Josef) - Linked API references in the manual to their detailed documentation - Fixed links in code font to still be colored blue - Corrected definition of `reversed(string)` 2019 July 4: Public Beta - Removed `extend_transform()`, `get_clip()`, and `get_transform()` from the beta release - Specified metadata for launcher - Moved programmatic GIF and screenshot recording to `device_control()`. - Allowed trailing commas and comments in JSON - Increased size of `deja-9` font button characters - Changed `pyx` to `pyxl` - Added graphics frame scaling for slower devices - Added QR codes for easily launching on mobile devices - Added `local_time()` - Added support for inserting padding with `fontpack.html` - Added named-argument versions of `set_transform()` and `set_clip()` - Changed the arguments of `set_transform()` to more closely match other graphics commands - Changed the arguments of `set_clip()` to more closely match `drawRect()` - Rerendered emulator case - Improved touch regions for mobile emulator - Added `games/icetime` complete sample game - Changed assignment and mutating operators to no longer return a value - Added `examples/animation` - Added `array_value()` animation support - Added mapping for 8bitdo SNES30 controller - Added animated ninja sprites - Mapped trigger and shoulder buttons from player 1's modern game controller to `gamepad_array[1]` ABCD buttons. It is now possible to create twin-stick games with all 10 buttons 2019 May 1: Public API Preview 2018 July 1: Private Alpha manual✜