litecanvas 0.98.1 → 0.98.2

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 CHANGED
@@ -28,74 +28,205 @@ Litecanvas is a lightweight HTML5 canvas 2D engine suitable for small web games,
28
28
  - **Extensible**: Use or create [plugins](https://www.npmjs.com/search?q=keywords:litecanvas) to add functionalities or change the engine.
29
29
  - **Playground**: Access or install the [playground](https://litecanvas.js.org/) webapp to code and share games (even offline).
30
30
 
31
- [Learn more in the cheatsheet...](https://litecanvas.js.org/about.html)
32
-
33
31
  ## Getting Started
34
32
 
35
- You can try our [online playground](https://litecanvas.github.io) or install the NPM package:
33
+ ### Installation
34
+
35
+ You can get started using our [online playground](https://litecanvas.github.io).
36
+
37
+ Or installing our package via NPM:
36
38
 
37
39
  ```sh
38
40
  npm i litecanvas
39
41
  ```
40
42
 
41
- or just use add a `<script>` tag with our CDN link:
43
+ Or just create a HTML file and add a `<script>` tag with our CDN link:
42
44
 
43
45
  ```html
44
46
  <script src="https://unpkg.com/litecanvas"></script>
45
47
  ```
46
48
 
47
- ### Show me the code!
49
+ ### Basic game structure
48
50
 
49
51
  ```js
50
- // import the package if you installed via NPM
51
- import litecanvas from 'litecanvas'
52
+ litecanvas()
53
+
54
+ function init() {
55
+ // this functions is called one time only
56
+ // before the game starts
57
+ }
58
+
59
+ function update(dt) {
60
+ // this functions is called 60 times per second
61
+ // your game logic goes here
62
+ }
52
63
 
53
- // Start and setup the engine
54
- // learn more: https://litecanvas.js.org/about.html#settings
64
+ function draw() {
65
+ // this functions is called 60 times per second
66
+ // your game rendering goes here
67
+ }
68
+ ```
69
+
70
+ > **Note**: if you installed via NPM you need to import the package first: <br/>
71
+ > `import litecanvas from "litecanvas"`
72
+
73
+ ### Set the width and height of the game screen
74
+
75
+ ```js
76
+ // example: a game screen size equal to 480x360
55
77
  litecanvas({
56
- loop: { init, update, draw, tapped },
78
+ width: 480,
79
+ height: 360,
57
80
  })
81
+ ```
58
82
 
59
- // this function runs once at the beginning
60
- function init() {
61
- bg = 0 // the color #0 (black)
62
- color = 3 // the color #3 (white)
63
- radius = W / 10 // the canvas Width/10
64
- posx = W / 2 // center X (or canvas Width/2)
65
- posy = H / 2 // center Y (or canvas Height/2)
83
+ ### Colors
84
+
85
+ Litecanvas has a default palette with 12 colors:
86
+
87
+ | # | Color | # | Color |
88
+ | --- | ---------- | --- | ----------- |
89
+ | 0 | Black | 6 | Dark blue |
90
+ | 1 | Dark grey | 7 | Light blue |
91
+ | 2 | Light grey | 8 | Dark green |
92
+ | 3 | White | 9 | Light green |
93
+ | 4 | Red | 10 | Brown |
94
+ | 5 | Yellow | 11 | Beige |
95
+
96
+ ![The litecanvas color palette](.github/_assets/palette.png)
97
+
98
+ Each time a Litecanvas' function ask for a color, you should use an of theses colors by its index.
99
+
100
+ ```js
101
+ // example: draw a white rectangle
102
+ color = 3
103
+ rectfill(0, 0, 32, 32, color)
104
+ ```
105
+
106
+ ### Printing messages
107
+
108
+ ```js
109
+ litecanvas()
110
+
111
+ function draw() {
112
+ // clear and fill the game screen with color #0 (black)
113
+ cls(0)
114
+
115
+ // print a red "Hello" text at x=0, y=0
116
+ text(0, 0, 'Hello', 4)
117
+ }
118
+ ```
119
+
120
+ ### Drawing shapes
121
+
122
+ You can use the following functions to draw shapes:
123
+
124
+ - `rect(x, y, width, height, color)` draw a rectangle outline
125
+ - `rectfill(x, y, width, height, color)` draw a color-filled rectangle
126
+ - `circ(x, y, radius, color)` draw a circle outline
127
+ - `circfill(x, y, radius, color)` draw a color-filled circle
128
+ - `oval(x, y, rx, ry, color)` draw a ellipse outline
129
+ - `ovalfill(x, y, rx, ry, color)` draw a color-filled ellipse
130
+
131
+ ```js
132
+ litecanvas()
133
+
134
+ function draw() {
135
+ cls(0)
136
+
137
+ // draw a color filled rectangle at x=0 and y=0
138
+ // with width=32 and height=32
139
+ // and color=3 (white)
140
+ rectfill(0, 0, 32, 32, 3)
141
+
142
+ // draw a circle outline at x=64 and y=32
143
+ // with radius=40
144
+ // and color=5 (yellow)
145
+ circ(64, 32, 40, 5)
66
146
  }
147
+ ```
148
+
149
+ ### Keyboard
150
+
151
+ ```js
152
+ litecanvas()
153
+
154
+ function update() {
155
+ if (iskeydown('space')) {
156
+ // checks if the spacebar key is down
157
+ }
158
+
159
+ if (iskeypressed('a')) {
160
+ // checks if the "a" key was pressed
161
+ }
67
162
 
68
- // this function detect clicks/touches
69
- function tapped(x, y) {
70
- // changes the circle position
71
- // based on the position of the tap
72
- posx = x
73
- posy = y
163
+ // Returns the last key pressed in your keyboard.
164
+ const key = lastkey()
165
+
166
+ console.log(key)
74
167
  }
168
+ ```
75
169
 
76
- // put the game logic in this function
77
- function update(dt) {
78
- // make the circle falls 200 pixels per second
79
- posy += 200 * dt
170
+ > Note: you can call `iskeydown()` or `iskeypressed()` (without arguments) to check for any key.
171
+
172
+ ### Clicks and Touches
173
+
174
+ ```js
175
+ litecanvas()
176
+
177
+ let x, y
178
+
179
+ function tapped(tapX, tapY) {
180
+ // this function is called when a click or a touch happens
181
+ // tapX and tapY is where the tap happened
182
+ x = tapX
183
+ y = tapY
80
184
  }
81
185
 
82
- // put the game rendering in this function
83
186
  function draw() {
84
- cls(bg) // clear the screen
85
- circfill(posx, posy, radius, color) // draw a circle
86
- text(10, 10, 'Tap anywhere') // draw a text
187
+ cls(0)
188
+
189
+ if (x != null) {
190
+ // Draw a red circle wherever you tap
191
+ circfill(x, y, 32, 4)
192
+ }
193
+ }
194
+ ```
195
+
196
+ ### Mouse cursor
197
+
198
+ Use `MX` and `MY` variables (automatically declared by Litecanvas) to track the position of the mouse cursor.
199
+
200
+ ```js
201
+ litecanvas()
202
+
203
+ function draw() {
204
+ cls(0)
205
+
206
+ // draw a red circle in the mouse cursor's position
207
+ circfill(MX, MY, 32, 4)
87
208
  }
88
209
  ```
89
210
 
90
- [Play with this code in the playground](https://litecanvas.js.org?c=eJx9U8tu2zAQvOsrBsghcitYtnMz4HvvLdD2SJFriTVNEuSqthH430tSduQEQQUI0GNmdnZ22bb4ziIwhFWIxKMHDwSyvbZUtS0MiWBxdIG2GJh93Lat0UxS2L8iLv%2FEpQt9Kzo38nLgo3lKIqxtH6sZVb9WSJdxzm%2FxCm01Nxi9EkwNVBCnBiy8J4VrU10XVa7Lg47Yj1aydhZhtBHOSoLgYrCjZNCmOtUbJsvWC0y1uh47rFCECNIZF%2FC0Qt0ZIQ%2BLApk%2B7vDyAfWC%2BjQk7xMqCKXHmGA%2F0WI9K5bGcNKKh3a9KlDv4vkG3GScJMsU8At1kn1H2CzuhEsifPtA%2BP0p4fpJLIpSxAxptDzElt0oB4pzIlOo9bnB5Z5LrjII21Oc2tBBGspGdGbcIZ2IaRhZYZh%2Fwu3Le1J9bPf82MrlZtOP05h6caQ0917LNJ735meb0ybUih9MHsWBHh3uhTEx5b%2BC12dKjz4FFUk6q%2Bb6X3fYJMQXKP7MRyCrKKSd%2BY%2BXvI1vSyRNrLt%2BUULL56BIRRmIpqSyt702ps5RNMVDc1uYZtqmws2aELdOCpHpzPV61SDfzz%2BET8fvchoo0PMjI8Oq6z8yIyTy)
211
+ ### Litecanvas' variables
212
+
213
+ Like `MX` and `MY`, Litecanvas also declares these other variables:
214
+
215
+ - `W`: the width of the game canvas
216
+ - `H`: the height of the game canvas
217
+ - `T`: the amount of seconds since the game started
218
+ - `PI`: approximately 3.14 radians (or 180 degrees)
219
+ - `TWO_PI`: approximately 6.28 radians (or 360 degrees)
220
+ - `HALF_PI`: approximately 1.57 radians (or 90 degrees)
91
221
 
92
- https://github.com/user-attachments/assets/854ac6bd-724f-4da8-bb3c-bc04dba5d8c8
222
+ ### And much more!
223
+
224
+ You can find a complete list of everything litecanvas has to offer on our [cheatsheet](https://litecanvas.js.org/about.html).
93
225
 
94
226
  ## Demos
95
227
 
96
228
  Try some demos in the playground:
97
229
 
98
- - [Pong](https://litecanvas.js.org?c=eJy1VV1y00gQftcpmidJWJYl2U5IIKFMyiEPgKk4YMLW1paQxvY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%2FRZ7Yd3jz0zArI%2FVumsCySax762zvUM4%2FyWbnMYP1yoqEcMn2dh4wvExsTEAYpluhXQJGuZeNORx4bHjZjfIKaUIDvTAH4AEIGEgw%3D%3D)
101
232
  - [3D projection](https://litecanvas.js.org?c=eJyNVcuS2jAQvPsrJofUykE8wykJySlVyRckuy4fZGwWgZEpWQSWFP%2BeGUlgizVLqgyyprul1mgkl9IUc6H%2BiJrFUbTYqbmRlQKppGEx%2FI0AanksYAa%2F4Cv8gG%2F4G8IUPmEfW4S3uloVTjSDBAMAyZjDCJ%2BUuy6%2Bj8MuRWw3pREqqUzdqPs0I4d2k3IYDiE5cHjhcEwdr4vWRjqA%2Fj2kRQgHuwm8jvc7gbTJVZHTYikg1HNJyR1Fp1byd9tcmILlxm2AI%2FWQNRiNIwwsKg2sLAxIkn7G5otP4qAs1LNZYqjXc2KAeaVqgzhl2LImG2G0PLDBYOBUiUxjS6UxdWWEc4i0za5kNoC2fjNrJOY0luPf5D5euJ5yh%2F%2FUzb%2FkCx02oqbiAvopyGGuxd4X8Lys2SimxG139ZIRt5Sq2MvcLNmEukYLVZeUc6rqCbdFbpGuVE%2Bv06vQDZMcmIQejGN4D1PeeI9DGlIQZS1u7EK3BBxkB%2BFkD84WV9Ne9VkkOGTc14QzSitmfrtFmozoOTMoMA4C2TUjuzA%2BhjP6PaEJfbZtuYl5VVLBCdT4omwwXe0tdg1kXpR1iDIvys4AInIBzE30bjZzjBjMElvA7YXvWleaPfzEy62UObiqL%2BoHWwpuVF3U56PYtdPWabDbKHC1mLhL6KJaOdUKVXYZ%2BNqo3Mmqdxt71F3kolw75Zrmc8p1WwlW16NUyjRZp%2FAB87NOk1XqCSffOmsYx%2FFQEp2xEy1XF2anFXGC3WvOtha5xEPg5vXsm7f5vKovAns1qla3TQyRUDby12KXn8e3%2FFwNE85y45tz7TE084aTp%2F93cisP95Pw6qPYdhLc2f4LGJpJDngukxf6O6Yk%2FgdWEko3)
@@ -103,6 +234,19 @@ Try some demos in the playground:
103
234
 
104
235
  > _See other demos in [samples](/samples) folder_
105
236
 
237
+ ## Contributing
238
+
239
+ 1. Fork this repository and clone it.
240
+ 1. Install the dependencies: `npm i`
241
+ 1. Create a new branch and make your changes.
242
+ 1. Format the code: `npm run format`
243
+ 1. Create new tests in `tests` directory, if necessary.
244
+ 1. Test with `npm run test`
245
+ 1. Create your pull request.
246
+ 1. Done!
247
+
248
+ > Note: You'll need Node.JS installed in your machine.
249
+
106
250
  ## Inspirations
107
251
 
108
252
  - [floppy](https://github.com/lpagg/floppy): a micro game engine for beginners.
package/dist/dist.dev.js CHANGED
@@ -32,7 +32,7 @@
32
32
  };
33
33
 
34
34
  // src/version.js
35
- var version = "0.98.1";
35
+ var version = "0.98.2";
36
36
 
37
37
  // src/index.js
38
38
  function litecanvas(settings = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "litecanvas",
3
- "version": "0.98.1",
3
+ "version": "0.98.2",
4
4
  "description": "Lightweight HTML5 canvas 2D game engine suitable for small projects and creative coding. Inspired by PICO-8 and p5.js/Processing.",
5
5
  "license": "MIT",
6
6
  "author": "Luiz Bills <luizbills@pm.me>",
package/src/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '0.98.1'
2
+ export const version = '0.98.2'