plainscript-lang 1.0.35 → 1.0.361
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1052 -201
- package/compiler/bundler.js +4 -4
- package/compiler/cli.js +82 -18
- package/compiler/dependency-detector.js +34 -22
- package/compiler/generator.js +587 -172
- package/compiler/lexer.js +61 -39
- package/compiler/parser.js +685 -182
- package/compiler/sourcemap.js +1 -1
- package/compiler/version.js +1 -1
- package/docs/CAPABILITY_GAP_AUDIT.md +25 -4
- package/docs/FB-PROMPT.md +524 -0
- package/docs/GAME-PROMPT.md +916 -0
- package/docs/PLAINSCRIPT-SPEC.md +135 -5
- package/docs/index.html +28 -14
- package/docs/website/script.js +1 -1
- package/docs/website/style.css +162 -195
- package/examples/ai-providers.pln +1 -1
- package/examples/arrays.pln +1 -1
- package/examples/async-errors.pln +2 -1
- package/examples/auth-api.pln +1 -1
- package/examples/auth-sessions.pln +1 -1
- package/examples/basics.pln +1 -1
- package/examples/bots.pln +1 -1
- package/examples/browser-interactive/README.md +29 -0
- package/examples/browser-interactive/public/index.html +83 -0
- package/examples/browser-interactive/public/interactive.js +27 -0
- package/examples/browser-interactive/src/interactive.pln +34 -0
- package/examples/cache-and-jobs.pln +1 -1
- package/examples/cache-schedule.pln +1 -1
- package/examples/canvas-game/README.md +34 -0
- package/examples/canvas-game/public/game.js +131 -0
- package/examples/canvas-game/public/index.html +48 -0
- package/examples/canvas-game/src/game.pln +139 -0
- package/examples/collections.pln +1 -1
- package/examples/concurrency.pln +1 -1
- package/examples/conditions.pln +1 -1
- package/examples/database.pln +1 -1
- package/examples/day2.pln +1 -1
- package/examples/day3.pln +1 -1
- package/examples/deployment.pln +1 -1
- package/examples/email-send.pln +1 -1
- package/examples/error-handling.pln +3 -2
- package/examples/expressions.pln +1 -1
- package/examples/file-uploads.pln +1 -1
- package/examples/files-and-config.pln +1 -1
- package/examples/files.pln +1 -1
- package/examples/football-backend/app.pln +1 -1
- package/examples/functions.pln +1 -1
- package/examples/hello.pln +1 -1
- package/examples/http-client.pln +1 -1
- package/examples/http.pln +1 -1
- package/examples/id-verification/app.pln +1 -1
- package/examples/javascript-library/README.md +54 -0
- package/examples/javascript-library/package-lock.json +21 -0
- package/examples/javascript-library/package.json +8 -0
- package/examples/javascript-library/public/config.json +4 -0
- package/examples/javascript-library/public/index.html +40 -0
- package/examples/javascript-library/src/interop.pln +53 -0
- package/examples/json.pln +1 -1
- package/examples/loops.pln +1 -1
- package/examples/modules/app.pln +1 -1
- package/examples/modules/main.pln +1 -1
- package/examples/modules/math.pln +1 -1
- package/examples/mongo.pln +1 -1
- package/examples/objects.pln +1 -1
- package/examples/ocr.pln +1 -1
- package/examples/packages.pln +1 -1
- package/examples/record-kinds.pln +1 -1
- package/examples/records.pln +1 -1
- package/examples/rest-api-fetch.pln +1 -1
- package/examples/rest-api.pln +1 -1
- package/examples/scheduled-tasks.pln +1 -1
- package/examples/search-and-filter.pln +1 -1
- package/examples/server.pln +1 -1
- package/examples/sessions-and-cookies.pln +1 -1
- package/examples/sqlite.pln +1 -1
- package/examples/start.pln +1 -1
- package/examples/stdlib.pln +1 -1
- package/examples/string-verbs.pln +1 -1
- package/examples/telegram-ai-bot.pln +1 -1
- package/examples/telegram-bot.pln +1 -1
- package/examples/testing.pln +1 -1
- package/examples/three-dimensional/README.md +51 -0
- package/examples/three-dimensional/public/index.html +33 -0
- package/examples/three-dimensional/src/scene.pln +34 -0
- package/examples/web-api.pln +1 -1
- package/examples/web-app.pln +1 -1
- package/examples/websocket-server.pln +1 -1
- package/examples/websocket.pln +1 -1
- package/examples/whatsapp-bot/pairing.pln +2 -2
- package/examples/whatsapp-bot/qr.pln +2 -2
- package/package.json +9 -10
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>PlainScript Clicker</title>
|
|
7
|
+
<style>
|
|
8
|
+
body {
|
|
9
|
+
margin: 0;
|
|
10
|
+
min-height: 100vh;
|
|
11
|
+
display: flex;
|
|
12
|
+
flex-direction: column;
|
|
13
|
+
align-items: center;
|
|
14
|
+
justify-content: center;
|
|
15
|
+
gap: 16px;
|
|
16
|
+
background: #0d1117;
|
|
17
|
+
color: #e6edf3;
|
|
18
|
+
font-family: system-ui, "Segoe UI", sans-serif;
|
|
19
|
+
}
|
|
20
|
+
.card {
|
|
21
|
+
width: 360px;
|
|
22
|
+
padding: 20px;
|
|
23
|
+
border: 1px solid #30363d;
|
|
24
|
+
border-radius: 10px;
|
|
25
|
+
background: #161b22;
|
|
26
|
+
text-align: center;
|
|
27
|
+
}
|
|
28
|
+
#score { font-size: 34px; font-weight: 700; color: #40c463; }
|
|
29
|
+
.row { display: flex; gap: 10px; justify-content: center; }
|
|
30
|
+
button {
|
|
31
|
+
padding: 10px 16px;
|
|
32
|
+
font-size: 14px;
|
|
33
|
+
font-weight: 600;
|
|
34
|
+
border: none;
|
|
35
|
+
border-radius: 8px;
|
|
36
|
+
cursor: pointer;
|
|
37
|
+
background: #40c463;
|
|
38
|
+
color: #0d1117;
|
|
39
|
+
}
|
|
40
|
+
button.secondary { background: #30363d; color: #e6edf3; }
|
|
41
|
+
button.level-up { animation: pulse 0.6s ease-in-out; }
|
|
42
|
+
@keyframes pulse {
|
|
43
|
+
0% { transform: scale(1); }
|
|
44
|
+
50% { transform: scale(1.12); }
|
|
45
|
+
100% { transform: scale(1); }
|
|
46
|
+
}
|
|
47
|
+
ul#history {
|
|
48
|
+
list-style: none;
|
|
49
|
+
padding: 0;
|
|
50
|
+
margin: 0;
|
|
51
|
+
max-height: 140px;
|
|
52
|
+
overflow: auto;
|
|
53
|
+
font-size: 13px;
|
|
54
|
+
color: #8b949e;
|
|
55
|
+
text-align: left;
|
|
56
|
+
}
|
|
57
|
+
ul#history li { padding: 2px 0; }
|
|
58
|
+
kbd {
|
|
59
|
+
padding: 1px 5px;
|
|
60
|
+
border: 1px solid #30363d;
|
|
61
|
+
border-radius: 4px;
|
|
62
|
+
background: #21262d;
|
|
63
|
+
font-size: 12px;
|
|
64
|
+
}
|
|
65
|
+
</style>
|
|
66
|
+
</head>
|
|
67
|
+
<body>
|
|
68
|
+
<div class="card">
|
|
69
|
+
<h1>PlainScript Clicker</h1>
|
|
70
|
+
<p><span id="score">0</span></p>
|
|
71
|
+
<div class="row">
|
|
72
|
+
<button id="click-button" type="button">+10 points</button>
|
|
73
|
+
<button id="log-button" type="button" class="secondary">Log entry</button>
|
|
74
|
+
</div>
|
|
75
|
+
<p><kbd>R</kbd> resets the score and history</p>
|
|
76
|
+
</div>
|
|
77
|
+
<div class="card">
|
|
78
|
+
<h2>Run log</h2>
|
|
79
|
+
<ul id="history"></ul>
|
|
80
|
+
</div>
|
|
81
|
+
<script src="interactive.js"></script>
|
|
82
|
+
</body>
|
|
83
|
+
</html>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
let scoreEl = document.querySelector("#score");
|
|
2
|
+
let historyEl = document.querySelector("#history");
|
|
3
|
+
let clickButton = document.querySelector("#click-button");
|
|
4
|
+
let logButton = document.querySelector("#log-button");
|
|
5
|
+
let entryCount = 0;
|
|
6
|
+
console.log("PlainScript clicker dashboard ready");
|
|
7
|
+
clickButton.addEventListener("click", function (event) {
|
|
8
|
+
let current = parseInt(scoreEl.textContent);
|
|
9
|
+
let updated = current + 10;
|
|
10
|
+
scoreEl.innerHTML = String(updated);
|
|
11
|
+
if (updated >= 50) {
|
|
12
|
+
clickButton.classList.add("level-up");
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
logButton.addEventListener("click", function (event) {
|
|
16
|
+
entryCount = entryCount + 1;
|
|
17
|
+
let item = document.createElement("li");
|
|
18
|
+
item.textContent = ((("Entry " + entryCount) + " (score ") + scoreEl.textContent) + ")";
|
|
19
|
+
historyEl.appendChild(item);
|
|
20
|
+
});
|
|
21
|
+
document.addEventListener("keydown", function (e) {
|
|
22
|
+
if (e.key === "r" || e.key === "R") {
|
|
23
|
+
scoreEl.textContent = "0";
|
|
24
|
+
clickButton.classList.remove("level-up");
|
|
25
|
+
historyEl.innerHTML = "";
|
|
26
|
+
}
|
|
27
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// PlainScript 1.0.361: a DOM-first clicker with a run log.
|
|
2
|
+
|
|
3
|
+
remember scoreEl as document.querySelector("#score")
|
|
4
|
+
remember historyEl as document.querySelector("#history")
|
|
5
|
+
remember clickButton as document.querySelector("#click-button")
|
|
6
|
+
remember logButton as document.querySelector("#log-button")
|
|
7
|
+
|
|
8
|
+
remember entryCount as 0
|
|
9
|
+
|
|
10
|
+
show "PlainScript clicker dashboard ready"
|
|
11
|
+
|
|
12
|
+
when clickButton "click" happens
|
|
13
|
+
remember current as parseInt(scoreEl.textContent)
|
|
14
|
+
remember updated as current + 10
|
|
15
|
+
scoreEl.innerHTML becomes String(updated)
|
|
16
|
+
if updated is at least 50
|
|
17
|
+
clickButton.classList.add("level-up")
|
|
18
|
+
done
|
|
19
|
+
done
|
|
20
|
+
|
|
21
|
+
when logButton "click" happens
|
|
22
|
+
entryCount becomes entryCount + 1
|
|
23
|
+
remember item as document.createElement("li")
|
|
24
|
+
item.textContent becomes "Entry " + entryCount + " (score " + scoreEl.textContent + ")"
|
|
25
|
+
historyEl.appendChild(item)
|
|
26
|
+
done
|
|
27
|
+
|
|
28
|
+
when document "keydown" happens as e
|
|
29
|
+
if e.key is "r" or e.key is "R"
|
|
30
|
+
scoreEl.textContent becomes "0"
|
|
31
|
+
clickButton.classList.remove("level-up")
|
|
32
|
+
historyEl.innerHTML becomes ""
|
|
33
|
+
done
|
|
34
|
+
done
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Canvas 2D dodge mini-game
|
|
2
|
+
|
|
3
|
+
A self-contained PlainScript game: a green square you steer with WASD or the
|
|
4
|
+
arrow keys while red blocks fall from the top. Score a point for every block
|
|
5
|
+
that drifts past you; lose a life when one collides with you. Run out of lives
|
|
6
|
+
and the game freezes until you press Restart.
|
|
7
|
+
|
|
8
|
+
It demonstrates the v1.0.361 browser API:
|
|
9
|
+
|
|
10
|
+
- `when document "keydown"/"keyup" happens` handlers that set flags on a
|
|
11
|
+
`keys{}` map - the game loop reads the map, the event handlers never move the
|
|
12
|
+
player directly.
|
|
13
|
+
- `every frame ... done`, a `requestAnimationFrame` loop with delta time from
|
|
14
|
+
`performance.now()` so movement speed is frame-rate independent.
|
|
15
|
+
- `define a kind called "Enemy"` records, `new Enemy`, and `Math.random()`
|
|
16
|
+
spawning.
|
|
17
|
+
- Direct canvas interop: `canvas.getContext("2d")`, `clearRect`, `fillRect`,
|
|
18
|
+
`fillStyle`, `fillText`, and `strokeStyle` via `becomes`.
|
|
19
|
+
- A Restart button wired up with `when restartButton "click" happens`.
|
|
20
|
+
|
|
21
|
+
## Run
|
|
22
|
+
|
|
23
|
+
Build the compiled script, then open the page (any static file server works -
|
|
24
|
+
`npx serve public` is one option):
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npx plainscript build src/game.pln -o public/game.js
|
|
28
|
+
npx serve public
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Then open http://localhost:3000.
|
|
32
|
+
|
|
33
|
+
The page needs a server only for the HTML script tag, not for the game logic -
|
|
34
|
+
opening `public/index.html` directly from disk works in most browsers too.
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
function __makeKind_Enemy(EnemyFields) {
|
|
2
|
+
const __rec = { "x": 0, "y": 0, "size": 18, "speed": 0 };
|
|
3
|
+
if (EnemyFields != null) {
|
|
4
|
+
for (const __k in EnemyFields) {
|
|
5
|
+
if (!(Object.prototype.hasOwnProperty.call(__rec, __k))) throw new Error("\"Enemy\" has no field named \"" + __k + "\".");
|
|
6
|
+
__rec[__k] = EnemyFields[__k];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return __rec;
|
|
10
|
+
}
|
|
11
|
+
const Enemy = __makeKind_Enemy;
|
|
12
|
+
let canvas = document.getElementById("game");
|
|
13
|
+
let ctx = canvas.getContext("2d");
|
|
14
|
+
let restartButton = document.getElementById("restart");
|
|
15
|
+
let keys = { };
|
|
16
|
+
let enemies = [];
|
|
17
|
+
let widthValue = 640;
|
|
18
|
+
let heightValue = 480;
|
|
19
|
+
let playerSize = 24;
|
|
20
|
+
let playerX = 308;
|
|
21
|
+
let playerY = 420;
|
|
22
|
+
let playerSpeed = 240;
|
|
23
|
+
let scoreValue = 0;
|
|
24
|
+
let lives = 3;
|
|
25
|
+
let gameOver = false;
|
|
26
|
+
let previousMs = -1;
|
|
27
|
+
let spawnTimer = 0.5;
|
|
28
|
+
function resetEnemy(e) {
|
|
29
|
+
e.x = 20 + (Math.random() * 600);
|
|
30
|
+
e.y = -30;
|
|
31
|
+
e.speed = 60 + (Math.random() * 120);
|
|
32
|
+
}
|
|
33
|
+
function spawnEnemy() {
|
|
34
|
+
let e = new Enemy();
|
|
35
|
+
resetEnemy(e);
|
|
36
|
+
enemies.push(e);
|
|
37
|
+
}
|
|
38
|
+
for (let startCount = 0; (0 <= 4 ? startCount <= 4 : startCount >= 4); startCount += (0 <= 4 ? 1 : -1)) {
|
|
39
|
+
spawnEnemy();
|
|
40
|
+
}
|
|
41
|
+
document.addEventListener("keydown", function (e) {
|
|
42
|
+
keys[e.key] = true;
|
|
43
|
+
});
|
|
44
|
+
document.addEventListener("keyup", function (e) {
|
|
45
|
+
keys[e.key] = false;
|
|
46
|
+
});
|
|
47
|
+
restartButton.addEventListener("click", function (event) {
|
|
48
|
+
scoreValue = 0;
|
|
49
|
+
lives = 3;
|
|
50
|
+
gameOver = false;
|
|
51
|
+
playerX = 308;
|
|
52
|
+
playerY = 420;
|
|
53
|
+
previousMs = -1;
|
|
54
|
+
});
|
|
55
|
+
requestAnimationFrame(function __frame(__frameTime) {
|
|
56
|
+
let nowMs = performance.now();
|
|
57
|
+
let delta = 0;
|
|
58
|
+
if (previousMs > 0) {
|
|
59
|
+
delta = (nowMs - previousMs) / 1000;
|
|
60
|
+
}
|
|
61
|
+
previousMs = nowMs;
|
|
62
|
+
if (gameOver === false) {
|
|
63
|
+
if (keys["ArrowLeft"] === true || keys["a"] === true) {
|
|
64
|
+
playerX = playerX - (playerSpeed * delta);
|
|
65
|
+
}
|
|
66
|
+
if (keys["ArrowRight"] === true || keys["d"] === true) {
|
|
67
|
+
playerX = playerX + (playerSpeed * delta);
|
|
68
|
+
}
|
|
69
|
+
if (keys["ArrowUp"] === true || keys["w"] === true) {
|
|
70
|
+
playerY = playerY - (playerSpeed * delta);
|
|
71
|
+
}
|
|
72
|
+
if (keys["ArrowDown"] === true || keys["s"] === true) {
|
|
73
|
+
playerY = playerY + (playerSpeed * delta);
|
|
74
|
+
}
|
|
75
|
+
if (playerX < 0) {
|
|
76
|
+
playerX = 0;
|
|
77
|
+
}
|
|
78
|
+
if (playerX > widthValue - playerSize) {
|
|
79
|
+
playerX = widthValue - playerSize;
|
|
80
|
+
}
|
|
81
|
+
if (playerY < 0) {
|
|
82
|
+
playerY = 0;
|
|
83
|
+
}
|
|
84
|
+
if (playerY > heightValue - playerSize) {
|
|
85
|
+
playerY = heightValue - playerSize;
|
|
86
|
+
}
|
|
87
|
+
spawnTimer = spawnTimer - delta;
|
|
88
|
+
if (spawnTimer < 0) {
|
|
89
|
+
spawnEnemy();
|
|
90
|
+
spawnTimer = 1.1;
|
|
91
|
+
}
|
|
92
|
+
for (const e of enemies) {
|
|
93
|
+
e.y = e.y + (e.speed * delta);
|
|
94
|
+
if (e.y > heightValue) {
|
|
95
|
+
scoreValue = scoreValue + 1;
|
|
96
|
+
resetEnemy(e);
|
|
97
|
+
}
|
|
98
|
+
if (e.x < playerX + playerSize && e.x + e.size > playerX && e.y < playerY + playerSize && e.y + e.size > playerY) {
|
|
99
|
+
lives = lives - 1;
|
|
100
|
+
resetEnemy(e);
|
|
101
|
+
if (lives === 0) {
|
|
102
|
+
gameOver = true;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
ctx.clearRect(0, 0, widthValue, heightValue);
|
|
108
|
+
ctx.fillStyle = "#0d1117";
|
|
109
|
+
ctx.fillRect(0, 0, widthValue, heightValue);
|
|
110
|
+
ctx.fillStyle = "#40c463";
|
|
111
|
+
ctx.fillRect(playerX, playerY, playerSize, playerSize);
|
|
112
|
+
ctx.strokeStyle = "#2ea043";
|
|
113
|
+
ctx.strokeRect(playerX, playerY, playerSize, playerSize);
|
|
114
|
+
ctx.fillStyle = "#ef4444";
|
|
115
|
+
for (const e of enemies) {
|
|
116
|
+
ctx.fillRect(e.x, e.y, e.size, e.size);
|
|
117
|
+
}
|
|
118
|
+
ctx.fillStyle = "#e6edf3";
|
|
119
|
+
ctx.font = "18px sans-serif";
|
|
120
|
+
ctx.fillText("Score: " + scoreValue, 12, 28);
|
|
121
|
+
ctx.fillText("Lives: " + lives, 12, 52);
|
|
122
|
+
if (gameOver === true) {
|
|
123
|
+
ctx.fillStyle = "#f6f8fa";
|
|
124
|
+
ctx.font = "34px sans-serif";
|
|
125
|
+
ctx.fillText("Game Over", 230, 208);
|
|
126
|
+
ctx.font = "18px sans-serif";
|
|
127
|
+
ctx.fillText("Press Restart to play again", 196, 244);
|
|
128
|
+
}
|
|
129
|
+
requestAnimationFrame(__frame);
|
|
130
|
+
});
|
|
131
|
+
if (typeof module !== 'undefined') { module.exports = { resetEnemy, spawnEnemy }; }
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>PlainScript Dodge</title>
|
|
7
|
+
<style>
|
|
8
|
+
body {
|
|
9
|
+
margin: 0;
|
|
10
|
+
min-height: 100vh;
|
|
11
|
+
display: flex;
|
|
12
|
+
flex-direction: column;
|
|
13
|
+
align-items: center;
|
|
14
|
+
justify-content: center;
|
|
15
|
+
gap: 14px;
|
|
16
|
+
background: #0d1117;
|
|
17
|
+
color: #e6edf3;
|
|
18
|
+
font-family: system-ui, "Segoe UI", sans-serif;
|
|
19
|
+
}
|
|
20
|
+
h1 { font-size: 22px; margin: 0; }
|
|
21
|
+
p { margin: 0; font-size: 14px; color: #8b949e; }
|
|
22
|
+
canvas {
|
|
23
|
+
border: 2px solid #30363d;
|
|
24
|
+
border-radius: 8px;
|
|
25
|
+
background: #0d1117;
|
|
26
|
+
display: block;
|
|
27
|
+
}
|
|
28
|
+
button {
|
|
29
|
+
padding: 10px 22px;
|
|
30
|
+
font-size: 15px;
|
|
31
|
+
font-weight: 600;
|
|
32
|
+
color: #0d1117;
|
|
33
|
+
background: #40c463;
|
|
34
|
+
border: none;
|
|
35
|
+
border-radius: 8px;
|
|
36
|
+
cursor: pointer;
|
|
37
|
+
}
|
|
38
|
+
button:hover { filter: brightness(1.1); }
|
|
39
|
+
</style>
|
|
40
|
+
</head>
|
|
41
|
+
<body>
|
|
42
|
+
<h1>PlainScript Dodge</h1>
|
|
43
|
+
<p>Use WASD or arrow keys to dodge the falling blocks.</p>
|
|
44
|
+
<canvas id="game" width="640" height="480"></canvas>
|
|
45
|
+
<button id="restart" type="button">Restart</button>
|
|
46
|
+
<script src="game.js"></script>
|
|
47
|
+
</body>
|
|
48
|
+
</html>
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// PlainScript 1.0.361: a self-contained canvas 2D dodge mini-game.
|
|
2
|
+
|
|
3
|
+
define a kind called "Enemy" with
|
|
4
|
+
x is 0
|
|
5
|
+
y is 0
|
|
6
|
+
size is 18
|
|
7
|
+
speed is 0
|
|
8
|
+
done
|
|
9
|
+
|
|
10
|
+
remember canvas as document.getElementById("game")
|
|
11
|
+
remember ctx as canvas.getContext("2d")
|
|
12
|
+
remember restartButton as document.getElementById("restart")
|
|
13
|
+
|
|
14
|
+
remember keys as {}
|
|
15
|
+
remember enemies as []
|
|
16
|
+
remember widthValue as 640
|
|
17
|
+
remember heightValue as 480
|
|
18
|
+
remember playerSize as 24
|
|
19
|
+
remember playerX as 308
|
|
20
|
+
remember playerY as 420
|
|
21
|
+
remember playerSpeed as 240
|
|
22
|
+
remember scoreValue as 0
|
|
23
|
+
remember lives as 3
|
|
24
|
+
remember gameOver as false
|
|
25
|
+
remember previousMs as -1
|
|
26
|
+
remember spawnTimer as 0.5
|
|
27
|
+
|
|
28
|
+
make resetEnemy(e)
|
|
29
|
+
e.x becomes 20 + Math.random() * 600
|
|
30
|
+
e.y becomes -30
|
|
31
|
+
e.speed becomes 60 + Math.random() * 120
|
|
32
|
+
done
|
|
33
|
+
|
|
34
|
+
make spawnEnemy()
|
|
35
|
+
remember e as new Enemy
|
|
36
|
+
resetEnemy(e)
|
|
37
|
+
enemies.push(e)
|
|
38
|
+
done
|
|
39
|
+
|
|
40
|
+
for index startCount from 0 to 4
|
|
41
|
+
spawnEnemy()
|
|
42
|
+
done
|
|
43
|
+
|
|
44
|
+
when document "keydown" happens as e
|
|
45
|
+
keys[e.key] becomes true
|
|
46
|
+
done
|
|
47
|
+
|
|
48
|
+
when document "keyup" happens as e
|
|
49
|
+
keys[e.key] becomes false
|
|
50
|
+
done
|
|
51
|
+
|
|
52
|
+
when restartButton "click" happens
|
|
53
|
+
scoreValue becomes 0
|
|
54
|
+
lives becomes 3
|
|
55
|
+
gameOver becomes false
|
|
56
|
+
playerX becomes 308
|
|
57
|
+
playerY becomes 420
|
|
58
|
+
previousMs becomes -1
|
|
59
|
+
done
|
|
60
|
+
|
|
61
|
+
every frame
|
|
62
|
+
remember nowMs as performance.now()
|
|
63
|
+
remember delta as 0
|
|
64
|
+
if previousMs is above 0
|
|
65
|
+
delta becomes (nowMs - previousMs) / 1000
|
|
66
|
+
done
|
|
67
|
+
previousMs becomes nowMs
|
|
68
|
+
|
|
69
|
+
if gameOver is false
|
|
70
|
+
if keys["ArrowLeft"] is true or keys["a"] is true
|
|
71
|
+
playerX becomes playerX - playerSpeed * delta
|
|
72
|
+
done
|
|
73
|
+
if keys["ArrowRight"] is true or keys["d"] is true
|
|
74
|
+
playerX becomes playerX + playerSpeed * delta
|
|
75
|
+
done
|
|
76
|
+
if keys["ArrowUp"] is true or keys["w"] is true
|
|
77
|
+
playerY becomes playerY - playerSpeed * delta
|
|
78
|
+
done
|
|
79
|
+
if keys["ArrowDown"] is true or keys["s"] is true
|
|
80
|
+
playerY becomes playerY + playerSpeed * delta
|
|
81
|
+
done
|
|
82
|
+
if playerX is less than 0
|
|
83
|
+
playerX becomes 0
|
|
84
|
+
done
|
|
85
|
+
if playerX is greater than widthValue - playerSize
|
|
86
|
+
playerX becomes widthValue - playerSize
|
|
87
|
+
done
|
|
88
|
+
if playerY is less than 0
|
|
89
|
+
playerY becomes 0
|
|
90
|
+
done
|
|
91
|
+
if playerY is greater than heightValue - playerSize
|
|
92
|
+
playerY becomes heightValue - playerSize
|
|
93
|
+
done
|
|
94
|
+
|
|
95
|
+
spawnTimer becomes spawnTimer - delta
|
|
96
|
+
if spawnTimer is less than 0
|
|
97
|
+
spawnEnemy()
|
|
98
|
+
spawnTimer becomes 1.1
|
|
99
|
+
done
|
|
100
|
+
|
|
101
|
+
for each e in enemies
|
|
102
|
+
e.y becomes e.y + e.speed * delta
|
|
103
|
+
if e.y is above heightValue
|
|
104
|
+
scoreValue becomes scoreValue + 1
|
|
105
|
+
resetEnemy(e)
|
|
106
|
+
done
|
|
107
|
+
if e.x is less than playerX + playerSize and e.x + e.size is greater than playerX and e.y is less than playerY + playerSize and e.y + e.size is greater than playerY
|
|
108
|
+
lives becomes lives - 1
|
|
109
|
+
resetEnemy(e)
|
|
110
|
+
if lives is 0
|
|
111
|
+
gameOver becomes true
|
|
112
|
+
done
|
|
113
|
+
done
|
|
114
|
+
done
|
|
115
|
+
done
|
|
116
|
+
|
|
117
|
+
ctx.clearRect(0, 0, widthValue, heightValue)
|
|
118
|
+
ctx.fillStyle becomes "#0d1117"
|
|
119
|
+
ctx.fillRect(0, 0, widthValue, heightValue)
|
|
120
|
+
ctx.fillStyle becomes "#40c463"
|
|
121
|
+
ctx.fillRect(playerX, playerY, playerSize, playerSize)
|
|
122
|
+
ctx.strokeStyle becomes "#2ea043"
|
|
123
|
+
ctx.strokeRect(playerX, playerY, playerSize, playerSize)
|
|
124
|
+
ctx.fillStyle becomes "#ef4444"
|
|
125
|
+
for each e in enemies
|
|
126
|
+
ctx.fillRect(e.x, e.y, e.size, e.size)
|
|
127
|
+
done
|
|
128
|
+
ctx.fillStyle becomes "#e6edf3"
|
|
129
|
+
ctx.font becomes "18px sans-serif"
|
|
130
|
+
ctx.fillText("Score: " + scoreValue, 12, 28)
|
|
131
|
+
ctx.fillText("Lives: " + lives, 12, 52)
|
|
132
|
+
if gameOver is true
|
|
133
|
+
ctx.fillStyle becomes "#f6f8fa"
|
|
134
|
+
ctx.font becomes "34px sans-serif"
|
|
135
|
+
ctx.fillText("Game Over", 230, 208)
|
|
136
|
+
ctx.font becomes "18px sans-serif"
|
|
137
|
+
ctx.fillText("Press Restart to play again", 196, 244)
|
|
138
|
+
done
|
|
139
|
+
done
|
package/examples/collections.pln
CHANGED
package/examples/concurrency.pln
CHANGED
package/examples/conditions.pln
CHANGED
package/examples/database.pln
CHANGED
package/examples/day2.pln
CHANGED
package/examples/day3.pln
CHANGED
package/examples/deployment.pln
CHANGED
package/examples/email-send.pln
CHANGED
package/examples/expressions.pln
CHANGED
package/examples/files.pln
CHANGED
package/examples/functions.pln
CHANGED
package/examples/hello.pln
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
// PlainScript 1.0.
|
|
1
|
+
// PlainScript 1.0.361: hello world.
|
|
2
2
|
show "Hello, PlainScript!"
|
package/examples/http-client.pln
CHANGED
package/examples/http.pln
CHANGED