powertron
Version:
An powerful library for making 2d games (BETA)
57 lines (47 loc) • 1.29 kB
Markdown
is an powerful library for making 2d games in BETA
/path/to/main.js
```
const pt = require("powertron")
pt.fullscreen = true
pt.title = "Writer"
pt.theme = "/path/to/theme.json"
pt.script = "/path/to/script.js"
pt.run()
```
--------------
/path/to/theme.json
```
{
"body": {
"background-color": "White",
"color": "Black",
"font-family": "Arial"
}
}
```
--------------
/path/to/script.js
```
let txt = ""
PowerTron.Game.setCursor("none")
PowerTron.Renderer2D.createScene(window.innerHeight - 100, window.innerHeight - 100)
function render() {
PowerTron.Renderer2D.writeText(PowerTron.Renderer2D.center().x, PowerTron.Renderer2D.center().y - 500, "Writer", "50", "Arial", "Black")
PowerTron.Renderer2D.writeText(PowerTron.Renderer2D.center().x, PowerTron.Renderer2D.center().y - 500, txt, "50", "Arial", "Black")
}
render()
PowerTron.Game.on("kdown", (e) => {
PowerTron.Renderer2D.clear()
if (PowerTron.Game.isCharacter(e.key)) {
txt += e.key
}else if (e.key == "Backspace") {
if (txt.length != 1) {
txt.slice(0, -1)
}
}
render()
})
```
Powered by [electron](https://npmjs.org/package/electron)
PowerTron