tscratch 0.4.2 → 0.4.3

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
@@ -1,281 +1,13 @@
1
1
  # TScratch
2
2
 
3
- ## About
4
-
5
- A **Scratch-inspired 2D game engine** for **TypeScript**.
6
- Type-safe, lightweight, and fun — bring the simplicity of Scratch into real code.
7
-
8
- This is a new open source project. It is maintained by me, a 14 year old student.
9
- If anyone has suggestions, feedback, or improvement ideas, feel free to contact me
10
- at `sebastianrucabado0@gmail.com`, or open a pull request here on Github.
11
-
12
- It's main purpose is to introduce real programming for kids. In most schools,
13
- children code on the [Scratch](https://scratch.mit.edu) platform, where they drag
14
- blocks, such as `move (10) steps`, `point in direction (80°)` etc. TScratch provides
15
- a high abstraction on top of the HTML canvas with a Scratch-like API, so that the
16
- children can smoothly transition from dragging blocks, into coding in real
17
- programming languages.
18
-
19
- ---
20
-
21
- ## Live showcases
22
-
23
- 1. [Interactive Inverse Kinematics Simulation](https://tscratch-project-ik.vercel.app)
24
- 2. [Recursive Snowflake Generator](https://tscratch-project-snowflake.vercel.app)
25
- 3. [Pythagoras Tree Fractal](https://tscratch-project-fractal.vercel.app)
26
- 4. [Ball Physics Simulation](https://tscratch-project-ball.vercel.app)
27
- 5. [Abstract Art Generator (2D trig functions)](https://tscratch-project-func2d.vercel.app)
28
-
29
- ## Features
30
-
31
- - **Scratch-style API** — `goTo`, `setX`, `move`, etc.
32
- - **TypeScript first** — full type safety & IntelliSense.
33
- - **Canvas rendering** — built on the HTML5 canvas.
34
- - **Sprites system** — extend `Sprite` to create your own shapes.
35
- - **Lightweight** — no heavy dependencies, works in any TypeScript project.
36
-
37
- ---
38
-
39
- ## Installation
40
-
41
- ```sh
42
- npx create-tscratch-app@latest project-name
43
- cd project-name
44
- npm install
45
- ```
46
-
47
- ## Quick Start
48
-
49
- ```ts
50
- import { Engine, Rectangle } from 'tscratch';
51
-
52
- // Initialize engine
53
- const engine = Engine.init();
54
-
55
- // Create a rectangle sprite
56
- const rect = new Rectangle({ color: 'red' });
57
- // Move it to x: 100, y: 50
58
- rect.goTo(100, 50);
59
-
60
- // Animate in the game loop
61
- engine.setLoop('main', () => {
62
- rect.move(1);
63
- rect.turn(-2);
64
- });
65
- ```
66
- ### Example: Multiple Sprites
67
-
68
- ```ts
69
- import { Engine, Rectangle } from 'tscratch';
70
-
71
- // Setup
72
- const engine = Engine.init();
73
-
74
- const redBox = new Rectangle({ scene: 'primary' });
75
-
76
- redBox.setColor('red');
77
- redBox.goTo(-100, 0);
78
-
79
- const blueBox = new Rectangle({ scene: 'secondary' });
80
-
81
- blueBox.setColor('blue');
82
- blueBox.goTo(100, 0);
83
-
84
- // Scenes & loops
85
- engine.changeScene('primary');
86
-
87
- engine.setLoop('primary', () => redBox.changeX(1));
88
- engine.setLoop('secondary', () => blueBox.changeX(-1));
89
- ```
90
-
91
- The recommended way of managing multiple scenes is to seperate your code into
92
- 1 file per scene, export the loop function and set the loops inside index.ts
93
- (your entry file).
94
-
95
- ```ts
96
- // scenes/main.ts
97
-
98
- const rect = new Rectangle();
99
-
100
- // Export the loop
101
- export default () => rect.move(1);
102
- ```
103
-
104
- ```ts
105
- // index.ts
106
-
107
- import { Engine } from 'tscratch';
108
- import main from './scenes/main.ts';
109
-
110
- const engine = Engine.init();
111
-
112
- // No need for changeScene() here, since we're in the 'main' scene
113
- engine.setLoop('main', main);
114
- ```
115
-
116
- ### Collisions
117
-
118
- Sadly, TScratch doesn't have a built in method for collision checking.
119
- However, there might be some 3rd party libraries that extend TScratch
120
- with collision checks.
121
-
122
- But TScratch does have methods for mouse interactions! You can use the
123
- `engine.isHovering(sprite)` method to check, if the user is hovering a
124
- specific sprite. By combining this with `engine.mouseDown`, you can
125
- create click events. You can also make your own custom events using
126
- `engine.mouseX` and `engine.mouseY`.
127
-
128
- ### Custom sprites
129
-
130
- You can extend the `Sprite` class, or any sprite that inherits from it.
131
- This way, the new sprite gets access to all the sprite properties and
132
- methods, like `x`, `dir`, `move(steps)` and so on. You want to call the
133
- parents constructor using super with the sprite options, that inherit
134
- from `SpriteOptions`, or any sub-interface.
135
-
136
- ```ts
137
- import { Rectangle, RectangleOptions } from 'tscratch';
138
-
139
- export interface PlayerOptions extends RectangleOptions {
140
- speed: number;
141
- }
142
-
143
- export default class Player extends Rectangle {
144
-
145
- public speed: number;
146
-
147
- constructor(options?: PlayerOptions) {
148
- super(options);
149
- this.speed = options?.speed ?? 5;
150
- }
151
- }
152
- ```
153
-
154
- For sprites that directly inherit from `Sprite`, you'll need to implement the
155
- following methods:
156
-
157
- ```ts
158
- import { Sprite, ctx, penCtx } from 'tscratch';
159
-
160
- export default class MySprite extends Sprite {
161
-
162
- public getPath(): Path2D {
163
- const path = new Path2D();
164
-
165
- // Example path
166
- path.rect(
167
- -this.width / 2, -this.height / 2,
168
- this.width, this.height
169
- );
170
- path.closePath();
171
-
172
- return path;
173
- }
174
-
175
- public draw(stamping?: boolean): void {
176
- // For pen stamping (optional, you can just use ctx)
177
- const c = stamping ? penCtx : ctx;
178
- c.save();
179
- c.translate(
180
- this.x + canvas.width / 2,
181
- -this.y + canvas.height / 2
182
- );
183
- c.rotate(this.toRadians(this.dir));
184
- c.fill(this.getPath());
185
- c.restore();
186
- }
187
- }
188
- ```
189
-
190
- ## Scenes
191
-
192
- TScratch supports scenes with the `scene` property. In every sprite you create,
193
- you can specify, in which scene you want it to render. TScratch will default it
194
- to 'main' if not specified.
195
-
196
- After that, you can switch between scenes by using `engine.changeScene(scene)`.
197
- TScratch will then render only the sprites, that belong in that specific scene.
198
-
199
- You can also specify 1 loop per scene using `engine.setLoop(scene, callback)`.
200
- Keep in mind that there is only 1 loop running at a time, which is the one
201
- in the current scene.
202
-
203
- ## Sound
204
-
205
- You can use the `engine.playSound(src)` method to play sounds. You just provide
206
- the source. Keep in mind that a lot of modern browsers block sound without user
207
- interaction.
208
-
209
- To stop sounds, you can use the `engine.stopAllSounds()` method.
210
-
211
- ## API Overview
212
-
213
- ### Engine
214
-
215
- - `Engine.init()` → get the singleton instance
216
- - `engine.setMaxFramesPerSecond(FPS)`→ sets the maximum FPS
217
- - `engine.setLoop(scene, callback)` → game loop logic
218
- - `engine.changeScene(scene)` → changes the scene, renders only the targeted sprites
219
- - `await engine.wait(ms)` → Wait some time in milliseconds
220
- - `engine.isHovering(sprite)` → Checks if the user is hovering a sprite with the mouse pointer
221
- - `engine.toRadians(rad)` → converts degrees to radians
222
- - `engine.toDegrees(deg)` → converts radians to degrees
223
-
224
- ### Sprite (abstract)
225
-
226
- #### Movement
227
-
228
- - `goTo(x, y)` → move to coordinates
229
- - `setX(x)` / `setY(y)` → set position
230
- - `changeX(x)` / `changeY(y)` → change position
231
- - `turn(deg)` / `point(deg)` → change / set direction
232
- - `changeX(dX)` / `changeY(dY)` → relative movement
233
-
234
- #### Looks
235
-
236
- - `show()` → shows the sprite
237
- - `hide()` → hides the sprite (prevents rendering => better preformance)
238
- - `goToLayer(layer)` → swithes the current layer (z-indexing)
239
- - `changeLayer(dL)` → moves forwards/backwards in layers (z-indexing)
240
-
241
- ### Rectangle
242
-
243
- - Has `width`, `height`, and `color` properties.
244
- - Draws a rectangle centered on `(x, y)`.
245
-
246
- ### RegularPolygon
247
-
248
- - Has `radius`, `sides`, and `color` properties.
249
- - Draws a polygon centered on `(x, y)`.
250
-
251
- ### Oval
252
-
253
- - Has `radA`, `radB`, and `color` properties.
254
- - Draws an oval centered on `(x, y)`.
255
-
256
- ### Text
257
-
258
- - Has `content`, `color`, and other properties specifying the style.
259
- - Draws a label aligned to your preference.
260
-
261
- ### ImageSprite
262
-
263
- - Has `src`, `width`, and `height` properties.
264
- - Draws an image centered on `(x, y)`.
265
-
266
- ### Pen
267
-
268
- - Has `color`, `size`, and `drawing` properties.
269
- - `down()` → starts drawing
270
- - `up()` → stops drawing
271
- - `dot()` → draws a single dot
272
- - Movement methods, such as `move()`, can draw a line based on if `drawing` is true.
273
-
274
- ### Canvas
275
-
276
- - `setScale` → sets the scale of the stage
277
- - `setAspectRatio` → sets the aspect ratio of the stage
278
-
279
- ## License
280
-
281
- MIT © 2025 sebastian-goat, see [LICENSE](./LICENSE)
3
+ ## Contents
4
+
5
+ - [About](https://github.com/Sebastian-GOAT/tscratch/blob/main/docs/about.md)
6
+ - [Installation](https://github.com/Sebastian-GOAT/tscratch/blob/main/docs/installation.md)
7
+ - [Getting Started](https://github.com/Sebastian-GOAT/tscratch/blob/main/docs/getting-started.md)
8
+ - [API](https://github.com/Sebastian-GOAT/tscratch/blob/main/docs/api.md)
9
+ - [Collisions](https://github.com/Sebastian-GOAT/tscratch/blob/main/docs/collisions.md)
10
+ - [Scenes](https://github.com/Sebastian-GOAT/tscratch/blob/main/docs/scenes.md)
11
+ - [Sounds](https://github.com/Sebastian-GOAT/tscratch/blob/main/docs/sounds.md)
12
+ - [Showcases](https://github.com/Sebastian-GOAT/tscratch/blob/main/docs/showcases.md)
13
+ - [License](https://github.com/Sebastian-GOAT/tscratch/blob/main/docs/license.md)
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var P=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var A=(n,t)=>{for(var e in t)P(n,e,{get:t[e],enumerable:!0})},D=(n,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of W(t))!L.call(n,r)&&r!==e&&P(n,r,{get:()=>t[r],enumerable:!(s=T(t,r))||s.enumerable});return n};var X=n=>D(P({},"__esModule",{value:!0}),n);var k={};A(k,{Engine:()=>u,ImageSprite:()=>y,Oval:()=>m,Pen:()=>f,Rectangle:()=>b,RegularPolygon:()=>g,Sprite:()=>a,Text:()=>x,canvas:()=>i,ctx:()=>h,default:()=>B,setAspectRatio:()=>C,setScale:()=>M});module.exports=X(k);var i=document.getElementById("game-window"),h=i.getContext("2d"),d=document.createElement("canvas"),o=d.getContext("2d");d.id="pen-canvas";var v=16/9,c;function M(n){c=n,i.width=v*c,i.height=c,d.width=v*c,d.height=c}function C(n){v=n,i.width=v*c,i.height=c,d.width=v*c,d.height=c}i.parentElement?.insertBefore(d,i);M(500);var a=class{x;y;dir;scene;hidden;layer;refresh(){u.init().refresh()}constructor(t){this.x=t?.x??0,this.y=t?.y??0,this.dir=t?.dir??0,this.scene=t?.scene??"main",this.hidden=t?.hidden??!1,this.layer=t?.layer??0,u.init().addSprite(this)}toRadians(t){return t*Math.PI/180}toDegrees(t){return t*180/Math.PI}move(t){this.x+=t*Math.sin(this.toRadians(this.dir)),this.y+=t*Math.cos(this.toRadians(this.dir)),this.refresh()}turn(t){this.dir+=t,this.refresh()}point(t){this.dir=t,this.refresh()}setX(t){this.x=t,this.refresh()}setY(t){this.y=t,this.refresh()}goTo(t,e){this.x=t,this.y=e,this.refresh()}changeX(t){this.x+=t,this.refresh()}changeY(t){this.y+=t,this.refresh()}show(){this.hidden=!1,this.refresh()}hide(){this.hidden=!0,this.refresh()}goToLayer(t){this.layer=t,this.refresh()}changeLayer(t){this.layer+=t,this.refresh()}};var u=class n{static instance;loopRunning=!1;gameLoop=null;maxFPS=24;sounds=[];mouseX=0;mouseY=0;mouseDown=!1;currentScene="main";sceneMap={};static init(){return this.instance||(this.instance=new n),this.instance}changeScene(t){this.sceneMap[t]||(this.sceneMap[t]={sprites:[],loop:null}),this.loopRunning=!1,this.currentScene=t,this.gameLoop=this.sceneMap[t].loop,this.setMaxFramesPerSecond(this.maxFPS)}setLoop(t,e){if(!this.sceneMap[t]){this.sceneMap[t]={sprites:[],loop:e},t===this.currentScene&&this.changeScene(t);return}this.sceneMap[t].loop=e,t===this.currentScene&&this.changeScene(t)}addSprite(t){let{scene:e,layer:s}=t;if(!this.sceneMap[e]){this.sceneMap[e]={sprites:[t],loop:null};return}let r=this.sceneMap[e].sprites.findIndex(l=>l.layer>s);if(r===-1){this.sceneMap[e].sprites.push(t);return}this.sceneMap[e].sprites.splice(r,0,t)}async setMaxFramesPerSecond(t){this.maxFPS=t;let e=this.gameLoop;if(e)for(this.loopRunning=!0;this.loopRunning;)await e(),await this.wait(1e3/t)}refresh(){h.clearRect(0,0,i.width,i.height),this.sceneMap[this.currentScene]?.sprites.forEach(t=>{t.hidden||t.draw()})}async wait(t){return new Promise(e=>setTimeout(e,t))}isHovered(t){let{mouseX:e,mouseY:s}=this,r=e+i.width/2,l=i.height/2-s,w=r-(t.x+i.width/2),S=l-(i.height/2-t.y),p=-this.toRadians(t.dir),O=w*Math.cos(p)-S*Math.sin(p),R=w*Math.sin(p)+S*Math.cos(p);return h.isPointInPath(t.getPath(),O,R)}playSound(t){let e=new Audio(t);return this.sounds.push(e),e.play(),e}stopSound(t){t.pause(),t.currentTime=0,this.sounds=this.sounds.filter(e=>e!==t)}stopAllSounds(){this.sounds.forEach(t=>{t.pause(),t.currentTime=0}),this.sounds=[]}pickRandom(t,e){return t>e&&([t,e]=[e,t]),Math.floor(Math.random()*(e-t+1)+t)}sin(t){return Math.sin(this.toRadians(t))}cos(t){return Math.cos(this.toRadians(t))}tan(t){return Math.tan(this.toRadians(t))}csc(t){return 1/Math.sin(this.toRadians(t))}sec(t){return 1/Math.cos(this.toRadians(t))}cot(t){return 1/Math.tan(this.toRadians(t))}asin(t){return this.toDegrees(Math.asin(t))}acos(t){return this.toDegrees(Math.acos(t))}acsc(t){return this.toDegrees(Math.asin(1/t))}asec(t){return this.toDegrees(Math.acos(1/t))}toRadians(t){return t*Math.PI/180}toDegrees(t){return t*180/Math.PI}constructor(){this.setMaxFramesPerSecond(24),i.addEventListener("mousemove",t=>{this.mouseX=t.clientX-i.offsetLeft-i.width/2,this.mouseY=-(t.clientY-i.offsetTop-i.height/2)}),i.addEventListener("mousedown",t=>{this.mouseDown=!0}),i.addEventListener("mouseup",t=>{this.mouseDown=!1})}};var b=class extends a{width;height;color;outlineColor;outlineWidth;getPath(){let t=new Path2D;return t.rect(-this.width/2,-this.height/2,this.width,this.height),t}draw(t){let e=t?o:h;e.save();let s=this.x+i.width/2,r=-this.y+i.height/2;e.translate(s,r),e.rotate(this.toRadians(this.dir));let l=this.getPath();e.fillStyle=this.color,e.strokeStyle=this.outlineColor,e.lineWidth=this.outlineWidth,e.fill(l),e.stroke(l),e.restore()}setWidth(t){this.width=t,this.refresh()}setHeight(t){this.height=t,this.refresh()}setColor(t){this.color=t,this.refresh()}constructor(t){super(t),this.width=t?.width??50,this.height=t?.height??50,this.color=t?.color??"black",this.outlineColor=t?.outlineColor??"black",this.outlineWidth=t?.outlineWidth??0,this.draw()}};var m=class extends a{radA;radB;color;outlineColor;outlineWidth;getPath(){let t=new Path2D;return t.ellipse(0,0,this.radA,this.radB,0,0,Math.PI*2),t}draw(t){let e=t?o:h;e.save();let s=this.x+i.width/2,r=-this.y+i.height/2;e.translate(s,r),e.rotate(this.toRadians(this.dir));let l=this.getPath();e.fillStyle=this.color,e.strokeStyle=this.outlineColor,e.lineWidth=this.outlineWidth,e.fill(l),e.stroke(l),e.restore()}setRadA(t){this.radA=t,this.refresh()}setRadB(t){this.radB=t,this.refresh()}setColor(t){this.color=t,this.refresh()}constructor(t){super(t),this.radA=t?.radA??25,this.radB=t?.radB??25,this.color=t?.color??"black",this.outlineColor=t?.outlineColor??"black",this.outlineWidth=t?.outlineWidth??0,this.draw()}};var g=class extends a{sides;radius;color;outlineColor;outlineWidth;getPath(){let t=new Path2D,e=Math.PI*2/this.sides,s=this.toRadians(this.dir),r=this.radius;for(let l=0;l<this.sides;l++){let w=l*e-Math.PI/2+s,S=r*Math.cos(w),p=-r*Math.sin(w);l===0?t.moveTo(S,p):t.lineTo(S,p)}return t.closePath(),t}draw(t){let e=t?o:h;e.save();let s=this.x+i.width/2,r=-this.y+i.height/2;e.translate(s,r);let l=this.getPath();e.fillStyle=this.color,e.strokeStyle=this.outlineColor,e.lineWidth=this.outlineWidth,e.fill(l),e.stroke(l),e.restore()}setSides(t){this.sides=t,this.refresh()}setRadius(t){this.radius=t,this.refresh()}setColor(t){this.color=t,this.refresh()}constructor(t){super(t),this.sides=t?.sides??5,this.radius=t?.radius??50,this.color=t?.color??"black",this.outlineColor=t?.outlineColor??"black",this.outlineWidth=t?.outlineWidth??0,this.draw()}};var f=class extends a{drawing;size;color;getPath(){return new Path2D}draw(){}up(){this.drawing=!1}down(){this.drawing=!0}stamp(t){t.draw(!0)}ereaseAll(){o.clearRect(0,0,i.width,i.height)}dot(){o.fillStyle=this.color,o.fillRect(this.x-this.size/2+i.width/2,-this.y-this.size/2+i.height/2,this.size,this.size)}drawLine(t,e){o.beginPath(),o.moveTo(t+i.width/2,-e+i.height/2),o.lineTo(this.x+i.width/2,-this.y+i.height/2),o.lineWidth=this.size,o.strokeStyle=this.color,o.stroke()}move(t){let e=this.x,s=this.y;this.x+=t*Math.sin(this.toRadians(this.dir)),this.y+=t*Math.cos(this.toRadians(this.dir)),this.drawing&&this.drawLine(e,s),this.refresh()}setX(t){let e=this.x,s=this.y;this.x=t,this.drawing&&this.drawLine(e,s),this.refresh()}setY(t){let e=this.x,s=this.y;this.y=t,this.drawing&&this.drawLine(e,s),this.refresh()}goTo(t,e){let s=this.x,r=this.y;this.x=t,this.y=e,this.drawing&&this.drawLine(s,r),this.refresh()}changeX(t){let e=this.x,s=this.y;this.x+=t,this.drawing&&this.drawLine(e,s),this.refresh()}changeY(t){let e=this.x,s=this.y;this.y+=t,this.drawing&&this.drawLine(e,s),this.refresh()}constructor(t){super(t),this.drawing=t?.drawing??!1,this.size=t?.size??5,this.color=t?.color??"black"}};var x=class extends a{content;color;fontFamily;fontSize;align;baseline;font;getPath(){let t=new Path2D;h.save(),h.font=this.font;let e=h.measureText(this.content),s=e.width,r=e.actualBoundingBoxAscent+e.actualBoundingBoxDescent;return h.restore(),t.rect(-s/2,-r/2,s,r),t}draw(t){let e=t?o:h;e.save();let s=this.x+i.width/2,r=-this.y+i.height/2;e.translate(s,r),e.rotate(this.toRadians(this.dir)),e.font=this.font,e.fillStyle=this.color,e.textAlign=this.align,e.textBaseline=this.baseline,e.fillText(this.content,0,0),e.restore()}setContent(t){this.content=t,this.refresh()}setColor(t){this.color=t,this.refresh()}setFontSize(t){this.fontSize=t,this.font=`${this.fontSize}px ${this.fontFamily}`,this.refresh()}setFontFamily(t){this.fontFamily=t,this.font=`${this.fontSize}px ${this.fontFamily}`,this.refresh()}setAlign(t){this.align=t,this.refresh()}setBaseline(t){this.baseline=t,this.refresh()}constructor(t){super(t),this.content=t?.content??"",this.color=t?.color??"black",this.fontFamily=t?.fontFamily??"Arial",this.fontSize=t?.fontSize??16,this.align=t?.align??"center",this.baseline=t?.baseline??"middle",this.font=`${this.fontSize}px ${this.fontFamily}`}};var y=class extends a{src;width;height;outlineColor;outlineWidth;img;getPath(){let t=new Path2D;return t.rect(-this.width/2,-this.height/2,this.width,this.height),t}draw(t){let e=t?o:h;e.save();let s=this.x+i.width/2,r=-this.y+i.height/2;e.translate(s,r),e.rotate(this.toRadians(this.dir)),e.strokeStyle=this.outlineColor,e.lineWidth=this.outlineWidth,e.drawImage(this.img,0,0,this.img.width,this.img.height,-this.width/2,-this.height/2,this.width,this.height),e.stroke(this.getPath()),e.restore()}setSrc(t){this.src=t,this.refresh()}setWidth(t){this.width=t,this.refresh()}setHeight(t){this.height=t,this.refresh()}constructor(t){super(t),this.src=t?.src??"",this.img=new Image,this.img.src=this.src,this.width=t?.width??this.img.width,this.height=t?.height??this.img.height,this.outlineColor=t?.outlineColor??"black",this.outlineWidth=t?.outlineWidth??0}};var Y={Engine:u,Sprite:a,Rectangle:b,Oval:m,RegularPolygon:g,Pen:f,Text:x,ImageSprite:y,setScale:M,setAspectRatio:C,canvas:i,ctx:h},B=Y;0&&(module.exports={Engine,ImageSprite,Oval,Pen,Rectangle,RegularPolygon,Sprite,Text,canvas,ctx,setAspectRatio,setScale});
1
+ "use strict";var P=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var A=(n,t)=>{for(var e in t)P(n,e,{get:t[e],enumerable:!0})},D=(n,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of W(t))!L.call(n,r)&&r!==e&&P(n,r,{get:()=>t[r],enumerable:!(s=T(t,r))||s.enumerable});return n};var X=n=>D(P({},"__esModule",{value:!0}),n);var k={};A(k,{Engine:()=>p,ImageSprite:()=>y,Oval:()=>m,Pen:()=>f,Rectangle:()=>b,RegularPolygon:()=>g,Sprite:()=>a,Text:()=>x,canvas:()=>i,ctx:()=>h,default:()=>B,setAspectRatio:()=>C,setScale:()=>M});module.exports=X(k);var i=document.getElementById("game-window"),h=i.getContext("2d"),c=document.createElement("canvas"),o=c.getContext("2d");c.id="pen-canvas";var v=16/9,u;function M(n){u=n,i.width=v*u,i.height=u,c.width=v*u,c.height=u}function C(n){v=n,i.width=v*u,i.height=u,c.width=v*u,c.height=u}i.parentElement?.insertBefore(c,i);M(500);var a=class{x;y;dir;scene;hidden;layer;refresh(){p.init().refresh()}constructor(t){this.x=t?.x??0,this.y=t?.y??0,this.dir=t?.dir??0,this.scene=t?.scene??"main",this.hidden=t?.hidden??!1,this.layer=t?.layer??0,p.init().addSprite(this)}toRadians(t){return t*Math.PI/180}toDegrees(t){return t*180/Math.PI}move(t){this.x+=t*Math.sin(this.toRadians(this.dir)),this.y+=t*Math.cos(this.toRadians(this.dir)),this.refresh()}turn(t){this.dir+=t,this.refresh()}point(t){this.dir=t,this.refresh()}setX(t){this.x=t,this.refresh()}setY(t){this.y=t,this.refresh()}goTo(t,e){this.x=t,this.y=e,this.refresh()}changeX(t){this.x+=t,this.refresh()}changeY(t){this.y+=t,this.refresh()}show(){this.hidden=!1,this.refresh()}hide(){this.hidden=!0,this.refresh()}goToLayer(t){this.layer=t,this.refresh()}changeLayer(t){this.layer+=t,this.refresh()}};var p=class n{static instance;loopRunning=!1;gameLoop=null;maxFPS=24;sounds=[];mouseX=0;mouseY=0;mouseDown=!1;currentScene="main";sceneMap={};static init(){return this.instance||(this.instance=new n),this.instance}changeScene(t){this.sceneMap[t]||(this.sceneMap[t]={sprites:[],loop:null}),this.loopRunning=!1,this.currentScene=t,this.gameLoop=this.sceneMap[t].loop,this.setMaxFramesPerSecond(this.maxFPS)}setLoop(t,e){if(!this.sceneMap[t]){this.sceneMap[t]={sprites:[],loop:e},t===this.currentScene&&this.changeScene(t);return}this.sceneMap[t].loop=e,t===this.currentScene&&this.changeScene(t)}addSprite(t){let{scene:e,layer:s}=t;if(!this.sceneMap[e]){this.sceneMap[e]={sprites:[t],loop:null};return}let r=this.sceneMap[e].sprites.findIndex(l=>l.layer>s);if(r===-1){this.sceneMap[e].sprites.push(t);return}this.sceneMap[e].sprites.splice(r,0,t)}removeSprite(t){let{scene:e}=t;this.sceneMap[e]&&(this.sceneMap[e].sprites=this.sceneMap[e].sprites.filter(s=>s!==t))}async setMaxFramesPerSecond(t){this.maxFPS=t;let e=this.gameLoop;if(e)for(this.loopRunning=!0;this.loopRunning;)await e(),await this.wait(1e3/t)}refresh(){h.clearRect(0,0,i.width,i.height),this.sceneMap[this.currentScene]?.sprites.forEach(t=>{t.hidden||t.draw()})}async wait(t){return new Promise(e=>setTimeout(e,t))}isHovered(t){let{mouseX:e,mouseY:s}=this,r=e+i.width/2,l=i.height/2-s,w=r-(t.x+i.width/2),S=l-(i.height/2-t.y),d=-this.toRadians(t.dir),O=w*Math.cos(d)-S*Math.sin(d),R=w*Math.sin(d)+S*Math.cos(d);return h.isPointInPath(t.getPath(),O,R)}playSound(t){let e=new Audio(t);return this.sounds.push(e),e.play(),e}stopSound(t){t.pause(),t.currentTime=0,this.sounds=this.sounds.filter(e=>e!==t)}stopAllSounds(){this.sounds.forEach(t=>{t.pause(),t.currentTime=0}),this.sounds=[]}pickRandom(t,e){return t>e&&([t,e]=[e,t]),Math.floor(Math.random()*(e-t+1)+t)}sin(t){return Math.sin(this.toRadians(t))}cos(t){return Math.cos(this.toRadians(t))}tan(t){return Math.tan(this.toRadians(t))}csc(t){return 1/Math.sin(this.toRadians(t))}sec(t){return 1/Math.cos(this.toRadians(t))}cot(t){return 1/Math.tan(this.toRadians(t))}asin(t){return this.toDegrees(Math.asin(t))}acos(t){return this.toDegrees(Math.acos(t))}acsc(t){return this.toDegrees(Math.asin(1/t))}asec(t){return this.toDegrees(Math.acos(1/t))}toRadians(t){return t*Math.PI/180}toDegrees(t){return t*180/Math.PI}constructor(){this.setMaxFramesPerSecond(24),c.addEventListener("mousemove",t=>{this.mouseX=t.clientX-c.offsetLeft-c.width/2,this.mouseY=-(t.clientY-c.offsetTop-c.height/2)}),c.addEventListener("mousedown",t=>{this.mouseDown=!0}),c.addEventListener("mouseup",t=>{this.mouseDown=!1})}};var b=class extends a{width;height;color;outlineColor;outlineWidth;getPath(){let t=new Path2D;return t.rect(-this.width/2,-this.height/2,this.width,this.height),t}draw(t){let e=t?o:h;e.save();let s=this.x+i.width/2,r=-this.y+i.height/2;e.translate(s,r),e.rotate(this.toRadians(this.dir));let l=this.getPath();e.fillStyle=this.color,e.strokeStyle=this.outlineColor,e.lineWidth=this.outlineWidth,e.fill(l),e.stroke(l),e.restore()}setWidth(t){this.width=t,this.refresh()}setHeight(t){this.height=t,this.refresh()}setColor(t){this.color=t,this.refresh()}constructor(t){super(t),this.width=t?.width??50,this.height=t?.height??50,this.color=t?.color??"black",this.outlineColor=t?.outlineColor??"black",this.outlineWidth=t?.outlineWidth??0,this.draw()}};var m=class extends a{radA;radB;color;outlineColor;outlineWidth;getPath(){let t=new Path2D;return t.ellipse(0,0,this.radA,this.radB,0,0,Math.PI*2),t}draw(t){let e=t?o:h;e.save();let s=this.x+i.width/2,r=-this.y+i.height/2;e.translate(s,r),e.rotate(this.toRadians(this.dir));let l=this.getPath();e.fillStyle=this.color,e.strokeStyle=this.outlineColor,e.lineWidth=this.outlineWidth,e.fill(l),e.stroke(l),e.restore()}setRadA(t){this.radA=t,this.refresh()}setRadB(t){this.radB=t,this.refresh()}setColor(t){this.color=t,this.refresh()}constructor(t){super(t),this.radA=t?.radA??25,this.radB=t?.radB??25,this.color=t?.color??"black",this.outlineColor=t?.outlineColor??"black",this.outlineWidth=t?.outlineWidth??0,this.draw()}};var g=class extends a{sides;radius;color;outlineColor;outlineWidth;getPath(){let t=new Path2D,e=Math.PI*2/this.sides,s=this.toRadians(this.dir),r=this.radius;for(let l=0;l<this.sides;l++){let w=l*e-Math.PI/2+s,S=r*Math.cos(w),d=-r*Math.sin(w);l===0?t.moveTo(S,d):t.lineTo(S,d)}return t.closePath(),t}draw(t){let e=t?o:h;e.save();let s=this.x+i.width/2,r=-this.y+i.height/2;e.translate(s,r);let l=this.getPath();e.fillStyle=this.color,e.strokeStyle=this.outlineColor,e.lineWidth=this.outlineWidth,e.fill(l),e.stroke(l),e.restore()}setSides(t){this.sides=t,this.refresh()}setRadius(t){this.radius=t,this.refresh()}setColor(t){this.color=t,this.refresh()}constructor(t){super(t),this.sides=t?.sides??5,this.radius=t?.radius??50,this.color=t?.color??"black",this.outlineColor=t?.outlineColor??"black",this.outlineWidth=t?.outlineWidth??0,this.draw()}};var f=class extends a{drawing;size;color;getPath(){return new Path2D}draw(){}up(){this.drawing=!1}down(){this.drawing=!0}stamp(t){t.draw(!0)}ereaseAll(){o.clearRect(0,0,i.width,i.height)}dot(){o.fillStyle=this.color,o.fillRect(this.x-this.size/2+i.width/2,-this.y-this.size/2+i.height/2,this.size,this.size)}drawLine(t,e){o.beginPath(),o.moveTo(t+i.width/2,-e+i.height/2),o.lineTo(this.x+i.width/2,-this.y+i.height/2),o.lineWidth=this.size,o.strokeStyle=this.color,o.stroke()}move(t){let e=this.x,s=this.y;this.x+=t*Math.sin(this.toRadians(this.dir)),this.y+=t*Math.cos(this.toRadians(this.dir)),this.drawing&&this.drawLine(e,s),this.refresh()}setX(t){let e=this.x,s=this.y;this.x=t,this.drawing&&this.drawLine(e,s),this.refresh()}setY(t){let e=this.x,s=this.y;this.y=t,this.drawing&&this.drawLine(e,s),this.refresh()}goTo(t,e){let s=this.x,r=this.y;this.x=t,this.y=e,this.drawing&&this.drawLine(s,r),this.refresh()}changeX(t){let e=this.x,s=this.y;this.x+=t,this.drawing&&this.drawLine(e,s),this.refresh()}changeY(t){let e=this.x,s=this.y;this.y+=t,this.drawing&&this.drawLine(e,s),this.refresh()}constructor(t){super(t),this.drawing=t?.drawing??!1,this.size=t?.size??5,this.color=t?.color??"black"}};var x=class extends a{content;color;fontFamily;fontSize;align;baseline;font;getPath(){let t=new Path2D;h.save(),h.font=this.font;let e=h.measureText(this.content),s=e.width,r=e.actualBoundingBoxAscent+e.actualBoundingBoxDescent;return h.restore(),t.rect(-s/2,-r/2,s,r),t}draw(t){let e=t?o:h;e.save();let s=this.x+i.width/2,r=-this.y+i.height/2;e.translate(s,r),e.rotate(this.toRadians(this.dir)),e.font=this.font,e.fillStyle=this.color,e.textAlign=this.align,e.textBaseline=this.baseline,e.fillText(this.content,0,0),e.restore()}setContent(t){this.content=t,this.refresh()}setColor(t){this.color=t,this.refresh()}setFontSize(t){this.fontSize=t,this.font=`${this.fontSize}px ${this.fontFamily}`,this.refresh()}setFontFamily(t){this.fontFamily=t,this.font=`${this.fontSize}px ${this.fontFamily}`,this.refresh()}setAlign(t){this.align=t,this.refresh()}setBaseline(t){this.baseline=t,this.refresh()}constructor(t){super(t),this.content=t?.content??"",this.color=t?.color??"black",this.fontFamily=t?.fontFamily??"Arial",this.fontSize=t?.fontSize??16,this.align=t?.align??"center",this.baseline=t?.baseline??"middle",this.font=`${this.fontSize}px ${this.fontFamily}`}};var y=class extends a{src;width;height;outlineColor;outlineWidth;img;getPath(){let t=new Path2D;return t.rect(-this.width/2,-this.height/2,this.width,this.height),t}draw(t){let e=t?o:h;e.save();let s=this.x+i.width/2,r=-this.y+i.height/2;e.translate(s,r),e.rotate(this.toRadians(this.dir)),e.strokeStyle=this.outlineColor,e.lineWidth=this.outlineWidth,e.drawImage(this.img,0,0,this.img.width,this.img.height,-this.width/2,-this.height/2,this.width,this.height),e.stroke(this.getPath()),e.restore()}setSrc(t){this.src=t,this.refresh()}setWidth(t){this.width=t,this.refresh()}setHeight(t){this.height=t,this.refresh()}constructor(t){super(t),this.src=t?.src??"",this.img=new Image,this.img.src=this.src,this.width=t?.width??this.img.width,this.height=t?.height??this.img.height,this.outlineColor=t?.outlineColor??"black",this.outlineWidth=t?.outlineWidth??0}};var Y={Engine:p,Sprite:a,Rectangle:b,Oval:m,RegularPolygon:g,Pen:f,Text:x,ImageSprite:y,setScale:M,setAspectRatio:C,canvas:i,ctx:h},B=Y;0&&(module.exports={Engine,ImageSprite,Oval,Pen,Rectangle,RegularPolygon,Sprite,Text,canvas,ctx,setAspectRatio,setScale});
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/canvas.ts","../src/Sprite.ts","../src/Engine.ts","../src/sprites/Rectangle.ts","../src/sprites/Oval.ts","../src/sprites/RegularPolygon.ts","../src/sprites/Pen.ts","../src/sprites/Text.ts","../src/sprites/ImageSprite.ts"],"sourcesContent":["import Engine from './Engine.ts';\r\n\r\nimport Sprite, { type SpriteOptions } from './Sprite.ts';\r\nimport Rectangle, { type RectangleOptions } from './sprites/Rectangle.ts';\r\nimport Oval, { type OvalOptions } from './sprites/Oval.ts';\r\nimport RegularPolygon, { type RegularPolygonOptions } from './sprites/RegularPolygon.ts';\r\nimport Pen, { type PenOptions } from './sprites/Pen.ts';\r\nimport Text, { type TextOptions, type CanvasTextAlign, type CanvasTextBaseline } from './sprites/Text.ts';\r\nimport ImageSprite, { type ImageSpriteOptions } from './sprites/ImageSprite.ts';\r\n\r\nimport { setScale, setAspectRatio, canvas, ctx } from './canvas.ts';\r\n\r\nconst TScratch = {\r\n // Main\r\n Engine,\r\n Sprite,\r\n\r\n // Sprites\r\n Rectangle,\r\n Oval,\r\n RegularPolygon,\r\n Pen,\r\n Text,\r\n ImageSprite,\r\n\r\n // Canvas\r\n setScale,\r\n setAspectRatio,\r\n canvas,\r\n ctx\r\n};\r\n\r\nexport default TScratch;\r\nexport {\r\n // Main\r\n Engine,\r\n Sprite,\r\n\r\n // Sprites\r\n Rectangle,\r\n Oval,\r\n RegularPolygon,\r\n Pen,\r\n Text,\r\n ImageSprite,\r\n\r\n // Options\r\n type SpriteOptions,\r\n type RectangleOptions,\r\n type OvalOptions,\r\n type RegularPolygonOptions,\r\n type PenOptions,\r\n type TextOptions,\r\n type ImageSpriteOptions,\r\n\r\n // Other types\r\n type CanvasTextAlign,\r\n type CanvasTextBaseline,\r\n \r\n // Canvas\r\n setScale,\r\n setAspectRatio,\r\n canvas,\r\n ctx\r\n};","export const canvas = document.getElementById('game-window') as HTMLCanvasElement;\r\nexport const ctx = canvas.getContext('2d')!;\r\n\r\nexport const penCanvas = document.createElement('canvas');\r\nexport const penCtx = penCanvas.getContext('2d')!;\r\npenCanvas.id = 'pen-canvas';\r\n\r\nlet ratio: number = 16 / 9;\r\nlet scale: number;\r\n\r\nexport function setScale(newScale: number) {\r\n scale = newScale;\r\n\r\n canvas.width = ratio * scale;\r\n canvas.height = scale;\r\n\r\n penCanvas.width = ratio * scale;\r\n penCanvas.height = scale;\r\n}\r\n\r\nexport function setAspectRatio(newAspectRatio: number) {\r\n ratio = newAspectRatio;\r\n\r\n canvas.width = ratio * scale;\r\n canvas.height = scale;\r\n\r\n penCanvas.width = ratio * scale;\r\n penCanvas.height = scale;\r\n}\r\n\r\ncanvas.parentElement?.insertBefore(penCanvas, canvas);\r\n\r\nsetScale(500);","import Engine from './Engine.ts';\r\n\r\nexport interface SpriteOptions {\r\n x?: number;\r\n y?: number;\r\n dir?: number;\r\n scene?: string;\r\n hidden?: boolean;\r\n layer?: number;\r\n};\r\n\r\nexport default abstract class Sprite {\r\n\r\n public x: number;\r\n public y: number;\r\n public dir: number;\r\n public scene: string;\r\n public hidden: boolean;\r\n public layer: number;\r\n\r\n // Rendering\r\n\r\n public abstract getPath(): Path2D;\r\n public abstract draw(stamping?: boolean): void;\r\n\r\n protected refresh() {\r\n Engine.init().refresh();\r\n }\r\n\r\n constructor(options?: SpriteOptions) {\r\n this.x = options?.x ?? 0;\r\n this.y = options?.y ?? 0;\r\n this.dir = options?.dir ?? 0;\r\n this.scene = options?.scene ?? 'main';\r\n this.hidden = options?.hidden ?? false;\r\n this.layer = options?.layer ?? 0;\r\n Engine.init().addSprite(this);\r\n }\r\n\r\n // Helpers\r\n\r\n protected toRadians(deg: number) {\r\n return deg * Math.PI / 180;\r\n }\r\n\r\n protected toDegrees(rad: number) {\r\n return rad * 180 / Math.PI;\r\n }\r\n\r\n // Methods\r\n\r\n // Motion\r\n public move(steps: number) {\r\n this.x += steps * Math.sin(this.toRadians(this.dir));\r\n this.y += steps * Math.cos(this.toRadians(this.dir));\r\n this.refresh();\r\n }\r\n\r\n public turn(deg: number) {\r\n this.dir += deg;\r\n this.refresh();\r\n }\r\n\r\n public point(dir: number) {\r\n this.dir = dir;\r\n this.refresh();\r\n }\r\n\r\n public setX(x: number) {\r\n this.x = x;\r\n this.refresh();\r\n }\r\n\r\n public setY(y: number) {\r\n this.y = y;\r\n this.refresh();\r\n }\r\n\r\n public goTo(x: number, y: number) {\r\n this.x = x;\r\n this.y = y;\r\n this.refresh();\r\n }\r\n\r\n public changeX(dX: number) {\r\n this.x += dX;\r\n this.refresh();\r\n }\r\n\r\n public changeY(dY: number) {\r\n this.y += dY;\r\n this.refresh();\r\n }\r\n\r\n // Looks\r\n\r\n public show() {\r\n this.hidden = false;\r\n this.refresh();\r\n }\r\n\r\n public hide() {\r\n this.hidden = true;\r\n this.refresh();\r\n }\r\n\r\n public goToLayer(layer: number) {\r\n this.layer = layer;\r\n this.refresh();\r\n }\r\n\r\n public changeLayer(dL: number) {\r\n this.layer += dL;\r\n this.refresh();\r\n }\r\n}","import { canvas, ctx } from './canvas.ts';\r\nimport Sprite from './Sprite.ts';\r\n\r\ntype GameLoop = (() => any) | (() => Promise<any>);\r\n\r\ntype SceneMap = {\r\n [scene: string]: {\r\n sprites: Sprite[];\r\n loop: GameLoop | null;\r\n };\r\n};\r\n\r\nexport default class Engine {\r\n\r\n private static instance: Engine;\r\n\r\n private loopRunning: boolean = false;\r\n public gameLoop: GameLoop | null = null;\r\n public maxFPS: number = 24;\r\n\r\n public sounds: HTMLAudioElement[] = [];\r\n\r\n public mouseX: number = 0;\r\n public mouseY: number = 0;\r\n\r\n public mouseDown: boolean = false;\r\n\r\n public currentScene: string = 'main';\r\n public sceneMap: SceneMap = {};\r\n\r\n // Singleton initialization\r\n\r\n public static init() {\r\n if (!this.instance)\r\n this.instance = new Engine();\r\n\r\n return this.instance;\r\n }\r\n\r\n // Change the scene\r\n\r\n public changeScene(scene: string) {\r\n if (!this.sceneMap[scene])\r\n this.sceneMap[scene] = { sprites: [], loop: null };\r\n\r\n this.loopRunning = false;\r\n this.currentScene = scene;\r\n this.gameLoop = this.sceneMap[scene].loop;\r\n this.setMaxFramesPerSecond(this.maxFPS); // Update the interval function\r\n }\r\n\r\n // Set a loop\r\n\r\n public setLoop(scene: string, loop: GameLoop) {\r\n if (!this.sceneMap[scene]) {\r\n this.sceneMap[scene] = { sprites: [], loop };\r\n if (scene === this.currentScene)\r\n this.changeScene(scene);\r\n return;\r\n }\r\n\r\n this.sceneMap[scene].loop = loop;\r\n if (scene === this.currentScene)\r\n this.changeScene(scene);\r\n }\r\n\r\n // Internal\r\n\r\n public addSprite(sprite: Sprite) {\r\n const { scene, layer } = sprite;\r\n\r\n if (!this.sceneMap[scene]) {\r\n this.sceneMap[scene] = { sprites: [sprite], loop: null };\r\n return;\r\n }\r\n\r\n let targetIndex = this.sceneMap[scene].sprites.findIndex(s => s.layer > layer);\r\n if (targetIndex === -1) {\r\n this.sceneMap[scene].sprites.push(sprite);\r\n return;\r\n }\r\n\r\n this.sceneMap[scene].sprites.splice(targetIndex, 0, sprite);\r\n }\r\n\r\n public async setMaxFramesPerSecond(maxFPS: number) {\r\n this.maxFPS = maxFPS;\r\n \r\n let loop = this.gameLoop;\r\n if (!loop) return;\r\n\r\n this.loopRunning = true;\r\n\r\n while (this.loopRunning) {\r\n await loop();\r\n await this.wait(1000 / maxFPS);\r\n }\r\n }\r\n\r\n public refresh() {\r\n ctx.clearRect(0, 0, canvas.width, canvas.height);\r\n this.sceneMap[this.currentScene]?.sprites.forEach(sprite => {\r\n if (!sprite.hidden)\r\n sprite.draw();\r\n });\r\n }\r\n\r\n // Wait function\r\n\r\n public async wait(ms: number): Promise<void> {\r\n return new Promise(resolve => setTimeout(resolve, ms));\r\n }\r\n\r\n // Mouse events\r\n\r\n public isHovered(sprite: Sprite) {\r\n const { mouseX, mouseY } = this;\r\n\r\n const canvasMouseX = mouseX + canvas.width / 2;\r\n const canvasMouseY = canvas.height / 2 - mouseY;\r\n\r\n // Mouse relative to sprite center\r\n const localX = canvasMouseX - (sprite.x + canvas.width / 2);\r\n const localY = canvasMouseY - (canvas.height / 2 - sprite.y);\r\n\r\n // Rotate mouse point by -dir to align with the path's local coordinates\r\n const angle = -this.toRadians(sprite.dir);\r\n const rotatedX = localX * Math.cos(angle) - localY * Math.sin(angle);\r\n const rotatedY = localX * Math.sin(angle) + localY * Math.cos(angle);\r\n\r\n return ctx.isPointInPath(sprite.getPath(), rotatedX, rotatedY);\r\n }\r\n\r\n // Sound\r\n\r\n public playSound(src: string) {\r\n const audio = new Audio(src);\r\n this.sounds.push(audio);\r\n\r\n audio.play();\r\n\r\n return audio;\r\n }\r\n\r\n public stopSound(sound: HTMLAudioElement) {\r\n sound.pause();\r\n sound.currentTime = 0;\r\n this.sounds = this.sounds.filter(s => s !== sound);\r\n }\r\n\r\n public stopAllSounds() {\r\n this.sounds.forEach(sound => {\r\n sound.pause();\r\n sound.currentTime = 0;\r\n });\r\n this.sounds = [];\r\n }\r\n\r\n // Math\r\n\r\n public pickRandom(min: number, max: number) {\r\n if (min > max)\r\n [min, max] = [max, min];\r\n return Math.floor(Math.random() * (max - min + 1) + min);\r\n }\r\n\r\n // Trigonometric functions\r\n public sin(deg: number) {\r\n return Math.sin(this.toRadians(deg));\r\n }\r\n\r\n public cos(deg: number) {\r\n return Math.cos(this.toRadians(deg));\r\n }\r\n\r\n public tan(deg: number) {\r\n return Math.tan(this.toRadians(deg));\r\n }\r\n\r\n public csc(deg: number) {\r\n return 1 / Math.sin(this.toRadians(deg));\r\n }\r\n\r\n public sec(deg: number) {\r\n return 1 / Math.cos(this.toRadians(deg));\r\n }\r\n\r\n public cot(deg: number) {\r\n return 1 / Math.tan(this.toRadians(deg));\r\n }\r\n\r\n // Inverse Trigonometric functions\r\n public asin(val: number) {\r\n return this.toDegrees(Math.asin(val));\r\n }\r\n\r\n public acos(val: number) {\r\n return this.toDegrees(Math.acos(val));\r\n }\r\n\r\n public acsc(val: number) {\r\n return this.toDegrees(Math.asin(1 / val));\r\n }\r\n\r\n public asec(val: number) {\r\n return this.toDegrees(Math.acos(1 / val));\r\n }\r\n\r\n // Helpers\r\n\r\n public toRadians(deg: number) {\r\n return deg * Math.PI / 180;\r\n }\r\n\r\n public toDegrees(rad: number) {\r\n return rad * 180 / Math.PI;\r\n }\r\n\r\n // Private constructor\r\n\r\n private constructor() {\r\n void this.setMaxFramesPerSecond(24);\r\n\r\n canvas.addEventListener('mousemove', e => {\r\n this.mouseX = e.clientX - canvas.offsetLeft - canvas.width / 2;\r\n this.mouseY = -(e.clientY - canvas.offsetTop - canvas.height / 2);\r\n });\r\n canvas.addEventListener('mousedown', e => {\r\n this.mouseDown = true;\r\n });\r\n canvas.addEventListener('mouseup', e => {\r\n this.mouseDown = false;\r\n });\r\n }\r\n}","import Sprite, { type SpriteOptions } from '../Sprite.ts';\r\nimport { ctx, canvas, penCtx } from '../canvas.ts';\r\n\r\nexport interface RectangleOptions extends SpriteOptions {\r\n width?: number;\r\n height?: number;\r\n color?: string;\r\n outlineColor?: string;\r\n outlineWidth?: number;\r\n};\r\n\r\nexport default class Rectangle extends Sprite {\r\n\r\n public width: number;\r\n public height: number;\r\n public color: string;\r\n public outlineColor: string;\r\n public outlineWidth: number;\r\n\r\n public getPath(): Path2D {\r\n const path = new Path2D();\r\n\r\n path.rect(\r\n -this.width / 2,\r\n -this.height / 2,\r\n this.width,\r\n this.height\r\n );\r\n\r\n return path;\r\n }\r\n\r\n public draw(stamping?: boolean): void {\r\n const c = stamping ? penCtx : ctx;\r\n\r\n c.save();\r\n\r\n const cX = this.x + canvas.width / 2;\r\n const cY = -this.y + canvas.height / 2;\r\n c.translate(cX, cY);\r\n\r\n c.rotate(this.toRadians(this.dir));\r\n\r\n const path = this.getPath();\r\n\r\n c.fillStyle = this.color;\r\n c.strokeStyle = this.outlineColor;\r\n c.lineWidth = this.outlineWidth;\r\n c.fill(path)\r\n c.stroke(path);\r\n\r\n c.restore();\r\n }\r\n\r\n public setWidth(width: number) {\r\n this.width = width;\r\n this.refresh();\r\n }\r\n\r\n public setHeight(height: number) {\r\n this.height = height;\r\n this.refresh();\r\n }\r\n\r\n public setColor(color: string) {\r\n this.color = color;\r\n this.refresh();\r\n }\r\n\r\n constructor(options?: RectangleOptions) {\r\n super(options);\r\n this.width = options?.width ?? 50;\r\n this.height = options?.height ?? 50;\r\n this.color = options?.color ?? 'black';\r\n this.outlineColor = options?.outlineColor ?? 'black';\r\n this.outlineWidth = options?.outlineWidth ?? 0;\r\n this.draw();\r\n }\r\n\r\n}","import Sprite, { type SpriteOptions } from '../Sprite.ts';\r\nimport { canvas, ctx, penCtx } from '../canvas.ts';\r\n\r\nexport interface OvalOptions extends SpriteOptions {\r\n radA?: number;\r\n radB?: number;\r\n color?: string;\r\n outlineColor?: string;\r\n outlineWidth?: number;\r\n};\r\n\r\nexport default class Oval extends Sprite {\r\n\r\n public radA: number;\r\n public radB: number;\r\n public color: string;\r\n public outlineColor: string;\r\n public outlineWidth: number;\r\n\r\n public getPath(): Path2D {\r\n const path = new Path2D();\r\n\r\n path.ellipse(\r\n 0, 0,\r\n this.radA,\r\n this.radB,\r\n 0, 0,\r\n Math.PI * 2\r\n );\r\n\r\n return path;\r\n }\r\n\r\n public draw(stamping?: boolean): void {\r\n const c = stamping ? penCtx : ctx;\r\n \r\n c.save();\r\n\r\n const cX = this.x + canvas.width / 2;\r\n const cY = -this.y + canvas.height / 2;\r\n c.translate(cX, cY);\r\n\r\n c.rotate(this.toRadians(this.dir));\r\n\r\n const path = this.getPath();\r\n\r\n c.fillStyle = this.color;\r\n c.strokeStyle = this.outlineColor;\r\n c.lineWidth = this.outlineWidth;\r\n c.fill(path)\r\n c.stroke(path);\r\n\r\n c.restore();\r\n }\r\n\r\n public setRadA(radA: number) {\r\n this.radA = radA;\r\n this.refresh();\r\n }\r\n\r\n public setRadB(radB: number) {\r\n this.radB = radB;\r\n this.refresh();\r\n }\r\n\r\n public setColor(color: string) {\r\n this.color = color;\r\n this.refresh();\r\n }\r\n\r\n constructor(options?: OvalOptions) {\r\n super(options);\r\n this.radA = options?.radA ?? 25;\r\n this.radB = options?.radB ?? 25;\r\n this.color = options?.color ?? 'black';\r\n this.outlineColor = options?.outlineColor ?? 'black';\r\n this.outlineWidth = options?.outlineWidth ?? 0;\r\n this.draw();\r\n }\r\n\r\n}","import { canvas, ctx, penCtx } from '../canvas.ts';\r\nimport Sprite, { type SpriteOptions } from '../Sprite.ts';\r\n\r\nexport interface RegularPolygonOptions extends SpriteOptions {\r\n sides?: number;\r\n radius?: number;\r\n color?: string;\r\n outlineColor?: string;\r\n outlineWidth?: number;\r\n}\r\n\r\nexport default class RegularPolygon extends Sprite {\r\n\r\n public sides: number;\r\n public radius: number;\r\n public color: string;\r\n public outlineColor: string;\r\n public outlineWidth: number;\r\n\r\n public getPath(): Path2D {\r\n const path = new Path2D();\r\n\r\n const step = (Math.PI * 2) / this.sides;\r\n const rotation = this.toRadians(this.dir);\r\n const r = this.radius;\r\n\r\n for (let i = 0; i < this.sides; i++) {\r\n const theta = i * step - Math.PI / 2 + rotation;\r\n const px = r * Math.cos(theta);\r\n const py = -r * Math.sin(theta);\r\n\r\n if (i === 0) path.moveTo(px, py);\r\n else path.lineTo(px, py);\r\n }\r\n\r\n path.closePath();\r\n\r\n return path;\r\n }\r\n\r\n public draw(stamping?: boolean) {\r\n const c = stamping ? penCtx : ctx;\r\n\r\n c.save();\r\n\r\n const cX = this.x + canvas.width / 2;\r\n const cY = -this.y + canvas.height / 2;\r\n\r\n c.translate(cX, cY);\r\n\r\n const path = this.getPath();\r\n\r\n c.fillStyle = this.color;\r\n c.strokeStyle = this.outlineColor;\r\n c.lineWidth = this.outlineWidth;\r\n c.fill(path)\r\n c.stroke(path);\r\n\r\n c.restore();\r\n }\r\n\r\n public setSides(sides: number) {\r\n this.sides = sides;\r\n this.refresh();\r\n }\r\n\r\n public setRadius(radius: number) {\r\n this.radius = radius;\r\n this.refresh();\r\n }\r\n\r\n public setColor(color: string) {\r\n this.color = color;\r\n this.refresh();\r\n }\r\n\r\n constructor(options?: RegularPolygonOptions) {\r\n super(options);\r\n this.sides = options?.sides ?? 5;\r\n this.radius = options?.radius ?? 50;\r\n this.color = options?.color ?? 'black';\r\n this.outlineColor = options?.outlineColor ?? 'black';\r\n this.outlineWidth = options?.outlineWidth ?? 0;\r\n this.draw();\r\n }\r\n\r\n}","import { canvas, penCtx } from '../canvas.ts';\r\nimport Sprite, { type SpriteOptions } from '../Sprite.ts';\r\n\r\nexport interface PenOptions extends SpriteOptions {\r\n drawing?: boolean;\r\n size?: number;\r\n color?: string;\r\n}\r\n\r\nexport default class Pen extends Sprite {\r\n\r\n public drawing: boolean;\r\n public size: number;\r\n public color: string;\r\n\r\n public getPath(): Path2D {\r\n return new Path2D();\r\n }\r\n public draw() {}\r\n\r\n public up() {\r\n this.drawing = false;\r\n }\r\n\r\n public down() {\r\n this.drawing = true;\r\n }\r\n\r\n public stamp(sprite: Sprite) {\r\n sprite.draw(true);\r\n }\r\n\r\n public ereaseAll() {\r\n penCtx.clearRect(0, 0, canvas.width, canvas.height);\r\n }\r\n\r\n public dot() {\r\n penCtx.fillStyle = this.color;\r\n penCtx.fillRect(\r\n this.x - this.size / 2 + canvas.width / 2,\r\n -this.y - this.size / 2 + canvas.height / 2,\r\n this.size,\r\n this.size\r\n );\r\n }\r\n\r\n private drawLine(lastX: number, lastY: number) {\r\n penCtx.beginPath();\r\n\r\n penCtx.moveTo(lastX + canvas.width / 2, -lastY + canvas.height / 2);\r\n penCtx.lineTo(this.x + canvas.width / 2, -this.y + canvas.height / 2);\r\n\r\n penCtx.lineWidth = this.size;\r\n penCtx.strokeStyle = this.color;\r\n penCtx.stroke();\r\n }\r\n\r\n // Overriding methods to include drawing\r\n\r\n public override move(steps: number) {\r\n const lastX = this.x;\r\n const lastY = this.y;\r\n\r\n this.x += steps * Math.sin(this.toRadians(this.dir));\r\n this.y += steps * Math.cos(this.toRadians(this.dir));\r\n if (this.drawing)\r\n this.drawLine(lastX, lastY);\r\n this.refresh();\r\n }\r\n\r\n public override setX(x: number) {\r\n const lastX = this.x;\r\n const lastY = this.y;\r\n\r\n this.x = x;\r\n if (this.drawing)\r\n this.drawLine(lastX, lastY);\r\n this.refresh();\r\n }\r\n\r\n public override setY(y: number) {\r\n const lastX = this.x;\r\n const lastY = this.y;\r\n\r\n this.y = y;\r\n if (this.drawing)\r\n this.drawLine(lastX, lastY);\r\n this.refresh();\r\n }\r\n\r\n public override goTo(x: number, y: number) {\r\n const lastX = this.x;\r\n const lastY = this.y;\r\n\r\n this.x = x;\r\n this.y = y;\r\n if (this.drawing)\r\n this.drawLine(lastX, lastY);\r\n this.refresh();\r\n }\r\n\r\n public override changeX(dX: number) {\r\n const lastX = this.x;\r\n const lastY = this.y;\r\n\r\n this.x += dX;\r\n if (this.drawing)\r\n this.drawLine(lastX, lastY);\r\n this.refresh();\r\n }\r\n\r\n public override changeY(dY: number) {\r\n const lastX = this.x;\r\n const lastY = this.y;\r\n\r\n this.y += dY;\r\n if (this.drawing)\r\n this.drawLine(lastX, lastY);\r\n this.refresh();\r\n }\r\n\r\n // Constructor\r\n\r\n constructor(options?: PenOptions) {\r\n super(options);\r\n this.drawing = options?.drawing ?? false;\r\n this.size = options?.size ?? 5;\r\n this.color = options?.color ?? 'black';\r\n }\r\n\r\n}","import { canvas, ctx, penCtx } from '../canvas.ts';\r\nimport Sprite, { type SpriteOptions } from '../Sprite.ts';\r\n\r\nexport type CanvasTextAlign =\r\n | 'left'\r\n | 'right'\r\n | 'center'\r\n | 'start'\r\n | 'end';\r\n\r\nexport type CanvasTextBaseline =\r\n | 'top'\r\n | 'hanging'\r\n | 'middle'\r\n | 'alphabetic'\r\n | 'ideographic'\r\n | 'bottom';\r\n\r\nexport interface TextOptions extends SpriteOptions {\r\n content?: string;\r\n color?: string;\r\n fontFamily?: string;\r\n fontSize?: number;\r\n align?: CanvasTextAlign;\r\n baseline?: CanvasTextBaseline;\r\n}\r\n\r\nexport default class Text extends Sprite {\r\n\r\n public content: string;\r\n public color: string;\r\n public fontFamily: string;\r\n public fontSize: number;\r\n public align: CanvasTextAlign;\r\n public baseline: CanvasTextBaseline;\r\n\r\n private font: string;\r\n\r\n public getPath(): Path2D {\r\n const path = new Path2D();\r\n\r\n ctx.save();\r\n \r\n ctx.font = this.font;\r\n\r\n const metrics = ctx.measureText(this.content);\r\n const width = metrics.width;\r\n const height = metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent;\r\n\r\n ctx.restore();\r\n\r\n path.rect(-width / 2, -height / 2, width, height);\r\n\r\n return path\r\n }\r\n\r\n public draw(stamping?: boolean) {\r\n const c = stamping ? penCtx : ctx;\r\n\r\n c.save();\r\n\r\n const cX = this.x + canvas.width / 2;\r\n const cY = -this.y + canvas.height / 2;\r\n c.translate(cX, cY);\r\n\r\n c.rotate(this.toRadians(this.dir));\r\n\r\n c.font = this.font;\r\n c.fillStyle = this.color;\r\n c.textAlign = this.align;\r\n c.textBaseline = this.baseline;\r\n\r\n c.fillText(this.content, 0, 0);\r\n\r\n c.restore();\r\n }\r\n\r\n // Methods\r\n\r\n public setContent(content: string) {\r\n this.content = content;\r\n this.refresh();\r\n }\r\n\r\n public setColor(color: string) {\r\n this.color = color;\r\n this.refresh();\r\n }\r\n\r\n public setFontSize(fontSize: number) {\r\n this.fontSize = fontSize;\r\n this.font = `${this.fontSize}px ${this.fontFamily}`;\r\n this.refresh();\r\n }\r\n\r\n public setFontFamily(fontFamily: string) {\r\n this.fontFamily = fontFamily;\r\n this.font = `${this.fontSize}px ${this.fontFamily}`;\r\n this.refresh();\r\n }\r\n\r\n public setAlign(align: CanvasTextAlign) {\r\n this.align = align;\r\n this.refresh();\r\n }\r\n\r\n public setBaseline(baseline: CanvasTextBaseline) {\r\n this.baseline = baseline;\r\n this.refresh();\r\n }\r\n\r\n // Constructor\r\n\r\n constructor(options?: TextOptions) {\r\n super(options);\r\n\r\n this.content = options?.content ?? '';\r\n this.color = options?.color ?? 'black';\r\n this.fontFamily = options?.fontFamily ?? 'Arial';\r\n this.fontSize = options?.fontSize ?? 16;\r\n this.align = options?.align ?? 'center';\r\n this.baseline = options?.baseline ?? 'middle';\r\n\r\n this.font = `${this.fontSize}px ${this.fontFamily}`;\r\n }\r\n}","import { canvas, ctx, penCtx } from '../canvas.ts';\r\nimport Sprite, { type SpriteOptions } from '../Sprite.ts';\r\n\r\nexport interface ImageSpriteOptions extends SpriteOptions {\r\n src?: string;\r\n width: number;\r\n height: number;\r\n outlineColor?: string;\r\n outlineWidth?: number;\r\n};\r\n\r\nexport default class ImageSprite extends Sprite {\r\n\r\n public src: string;\r\n public width: number;\r\n public height: number;\r\n public outlineColor: string;\r\n public outlineWidth: number;\r\n\r\n protected img: HTMLImageElement;\r\n\r\n public getPath(): Path2D {\r\n const path = new Path2D();\r\n\r\n path.rect(\r\n -this.width / 2,\r\n -this.height / 2,\r\n this.width,\r\n this.height\r\n );\r\n\r\n return path;\r\n }\r\n\r\n public draw(stamping?: boolean) {\r\n const c = stamping ? penCtx : ctx;\r\n\r\n c.save();\r\n\r\n const cX = this.x + canvas.width / 2;\r\n const cY = -this.y + canvas.height / 2;\r\n c.translate(cX, cY);\r\n\r\n c.rotate(this.toRadians(this.dir));\r\n\r\n c.strokeStyle = this.outlineColor;\r\n c.lineWidth = this.outlineWidth;\r\n c.drawImage(\r\n this.img,\r\n 0, 0,\r\n this.img.width,\r\n this.img.height,\r\n -this.width / 2,\r\n -this.height / 2,\r\n this.width, this.height\r\n );\r\n c.stroke(this.getPath());\r\n\r\n c.restore();\r\n }\r\n\r\n // Methods\r\n\r\n public setSrc(src: string) {\r\n this.src = src;\r\n this.refresh();\r\n }\r\n\r\n public setWidth(width: number) {\r\n this.width = width;\r\n this.refresh();\r\n }\r\n\r\n public setHeight(height: number) {\r\n this.height = height;\r\n this.refresh();\r\n }\r\n\r\n // Constructor\r\n\r\n constructor(options?: ImageSpriteOptions) {\r\n super(options);\r\n\r\n this.src = options?.src ?? '';\r\n this.img = new Image();\r\n this.img.src = this.src;\r\n\r\n this.width = options?.width ?? this.img.width;\r\n this.height = options?.height ?? this.img.height;\r\n\r\n this.outlineColor = options?.outlineColor ?? 'black';\r\n this.outlineWidth = options?.outlineWidth ?? 0;\r\n }\r\n}"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,YAAAE,EAAA,gBAAAC,EAAA,SAAAC,EAAA,QAAAC,EAAA,cAAAC,EAAA,mBAAAC,EAAA,WAAAC,EAAA,SAAAC,EAAA,WAAAC,EAAA,QAAAC,EAAA,YAAAC,EAAA,mBAAAC,EAAA,aAAAC,IAAA,eAAAC,EAAAf,GCAO,IAAMgB,EAAS,SAAS,eAAe,aAAa,EAC9CC,EAAMD,EAAO,WAAW,IAAI,EAE5BE,EAAY,SAAS,cAAc,QAAQ,EAC3CC,EAASD,EAAU,WAAW,IAAI,EAC/CA,EAAU,GAAK,aAEf,IAAIE,EAAgB,GAAK,EACrBC,EAEG,SAASC,EAASC,EAAkB,CACvCF,EAAQE,EAERP,EAAO,MAAQI,EAAQC,EACvBL,EAAO,OAASK,EAEhBH,EAAU,MAAQE,EAAQC,EAC1BH,EAAU,OAASG,CACvB,CAEO,SAASG,EAAeC,EAAwB,CACnDL,EAAQK,EAERT,EAAO,MAAQI,EAAQC,EACvBL,EAAO,OAASK,EAEhBH,EAAU,MAAQE,EAAQC,EAC1BH,EAAU,OAAS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IAAI,OAE1C,KAAK,aAAeA,GAAS,cAAgB,QAC7C,KAAK,aAAeA,GAAS,cAAgB,CACjD,CACJ,ETjFA,IAAMC,EAAW,CAEb,OAAAC,EACA,OAAAC,EAGA,UAAAC,EACA,KAAAC,EACA,eAAAC,EACA,IAAAC,EACA,KAAAC,EACA,YAAAC,EAGA,SAAAC,EACA,eAAAC,EACA,OAAAC,EACA,IAAAC,CACJ,EAEOC,EAAQb","names":["index_exports","__export","Engine","ImageSprite","Oval","Pen","Rectangle","RegularPolygon","Sprite","Text","canvas","ctx","index_default","setAspectRatio","setScale","__toCommonJS","canvas","ctx","penCanvas","penCtx","ratio","scale","setScale","newScale","setAspectRatio","newAspectRatio","Sprite","Engine","options","deg","rad","steps","dir","x","y","dX","dY","layer","dL","Engine","_Engine","scene","loop","sprite","layer","targetIndex","s","maxFPS","ctx","canvas","ms","resolve","mouseX","mouseY","canvasMouseX","canvasMouseY","localX","localY","angle","rotatedX","rotatedY","src","audio","sound","min","max","deg","val","rad","e","Rectangle","Sprite","path","stamping","c","penCtx","ctx","cX","canvas","cY","width","height","color","options","Oval","Sprite","path","stamping","c","penCtx","ctx","cX","canvas","cY","radA","radB","color","options","RegularPolygon","Sprite","path","step","rotation","i","theta","px","py","stamping","c","penCtx","ctx","cX","canvas","cY","sides","radius","color","options","Pen","Sprite","sprite","penCtx","canvas","lastX","lastY","steps","x","y","dX","dY","options","Text","Sprite","path","ctx","metrics","width","height","stamping","c","penCtx","cX","canvas","cY","content","color","fontSize","fontFamily","align","baseline","options","ImageSprite","Sprite","path","stamping","c","penCtx","ctx","cX","canvas","cY","src","width","height","options","TScratch","Engine","Sprite","Rectangle","Oval","RegularPolygon","Pen","Text","ImageSprite","setScale","setAspectRatio","canvas","ctx","index_default"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/canvas.ts","../src/Sprite.ts","../src/Engine.ts","../src/sprites/Rectangle.ts","../src/sprites/Oval.ts","../src/sprites/RegularPolygon.ts","../src/sprites/Pen.ts","../src/sprites/Text.ts","../src/sprites/ImageSprite.ts"],"sourcesContent":["import Engine from './Engine.ts';\r\n\r\nimport Sprite, { type SpriteOptions } from './Sprite.ts';\r\nimport Rectangle, { type RectangleOptions } from './sprites/Rectangle.ts';\r\nimport Oval, { type OvalOptions } from './sprites/Oval.ts';\r\nimport RegularPolygon, { type RegularPolygonOptions } from './sprites/RegularPolygon.ts';\r\nimport Pen, { type PenOptions } from './sprites/Pen.ts';\r\nimport Text, { type TextOptions, type CanvasTextAlign, type CanvasTextBaseline } from './sprites/Text.ts';\r\nimport ImageSprite, { type ImageSpriteOptions } from './sprites/ImageSprite.ts';\r\n\r\nimport { setScale, setAspectRatio, canvas, ctx } from './canvas.ts';\r\n\r\nconst TScratch = {\r\n // Main\r\n Engine,\r\n Sprite,\r\n\r\n // Sprites\r\n Rectangle,\r\n Oval,\r\n RegularPolygon,\r\n Pen,\r\n Text,\r\n ImageSprite,\r\n\r\n // Canvas\r\n setScale,\r\n setAspectRatio,\r\n canvas,\r\n ctx\r\n};\r\n\r\nexport default TScratch;\r\nexport {\r\n // Main\r\n Engine,\r\n Sprite,\r\n\r\n // Sprites\r\n Rectangle,\r\n Oval,\r\n RegularPolygon,\r\n Pen,\r\n Text,\r\n ImageSprite,\r\n\r\n // Options\r\n type SpriteOptions,\r\n type RectangleOptions,\r\n type OvalOptions,\r\n type RegularPolygonOptions,\r\n type PenOptions,\r\n type TextOptions,\r\n type ImageSpriteOptions,\r\n\r\n // Other types\r\n type CanvasTextAlign,\r\n type CanvasTextBaseline,\r\n \r\n // Canvas\r\n setScale,\r\n setAspectRatio,\r\n canvas,\r\n ctx\r\n};","export const canvas = document.getElementById('game-window') as HTMLCanvasElement;\r\nexport const ctx = canvas.getContext('2d')!;\r\n\r\nexport const penCanvas = document.createElement('canvas');\r\nexport const penCtx = penCanvas.getContext('2d')!;\r\npenCanvas.id = 'pen-canvas';\r\n\r\nlet ratio: number = 16 / 9;\r\nlet scale: number;\r\n\r\nexport function setScale(newScale: number) {\r\n scale = newScale;\r\n\r\n canvas.width = ratio * scale;\r\n canvas.height = scale;\r\n\r\n penCanvas.width = ratio * scale;\r\n penCanvas.height = scale;\r\n}\r\n\r\nexport function setAspectRatio(newAspectRatio: number) {\r\n ratio = newAspectRatio;\r\n\r\n canvas.width = ratio * scale;\r\n canvas.height = scale;\r\n\r\n penCanvas.width = ratio * scale;\r\n penCanvas.height = scale;\r\n}\r\n\r\ncanvas.parentElement?.insertBefore(penCanvas, canvas);\r\n\r\nsetScale(500);","import Engine from './Engine.ts';\r\n\r\nexport interface SpriteOptions {\r\n x?: number;\r\n y?: number;\r\n dir?: number;\r\n scene?: string;\r\n hidden?: boolean;\r\n layer?: number;\r\n};\r\n\r\nexport default abstract class Sprite {\r\n\r\n public x: number;\r\n public y: number;\r\n public dir: number;\r\n public scene: string;\r\n public hidden: boolean;\r\n public layer: number;\r\n\r\n // Rendering\r\n\r\n public abstract getPath(): Path2D;\r\n public abstract draw(stamping?: boolean): void;\r\n\r\n protected refresh() {\r\n Engine.init().refresh();\r\n }\r\n\r\n constructor(options?: SpriteOptions) {\r\n this.x = options?.x ?? 0;\r\n this.y = options?.y ?? 0;\r\n this.dir = options?.dir ?? 0;\r\n this.scene = options?.scene ?? 'main';\r\n this.hidden = options?.hidden ?? false;\r\n this.layer = options?.layer ?? 0;\r\n Engine.init().addSprite(this);\r\n }\r\n\r\n // Helpers\r\n\r\n protected toRadians(deg: number) {\r\n return deg * Math.PI / 180;\r\n }\r\n\r\n protected toDegrees(rad: number) {\r\n return rad * 180 / Math.PI;\r\n }\r\n\r\n // Methods\r\n\r\n // Motion\r\n public move(steps: number) {\r\n this.x += steps * Math.sin(this.toRadians(this.dir));\r\n this.y += steps * Math.cos(this.toRadians(this.dir));\r\n this.refresh();\r\n }\r\n\r\n public turn(deg: number) {\r\n this.dir += deg;\r\n this.refresh();\r\n }\r\n\r\n public point(dir: number) {\r\n this.dir = dir;\r\n this.refresh();\r\n }\r\n\r\n public setX(x: number) {\r\n this.x = x;\r\n this.refresh();\r\n }\r\n\r\n public setY(y: number) {\r\n this.y = y;\r\n this.refresh();\r\n }\r\n\r\n public goTo(x: number, y: number) {\r\n this.x = x;\r\n this.y = y;\r\n this.refresh();\r\n }\r\n\r\n public changeX(dX: number) {\r\n this.x += dX;\r\n this.refresh();\r\n }\r\n\r\n public changeY(dY: number) {\r\n this.y += dY;\r\n this.refresh();\r\n }\r\n\r\n // Looks\r\n\r\n public show() {\r\n this.hidden = false;\r\n this.refresh();\r\n }\r\n\r\n public hide() {\r\n this.hidden = true;\r\n this.refresh();\r\n }\r\n\r\n public goToLayer(layer: number) {\r\n this.layer = layer;\r\n this.refresh();\r\n }\r\n\r\n public changeLayer(dL: number) {\r\n this.layer += dL;\r\n this.refresh();\r\n }\r\n}","import { canvas, ctx, penCanvas } from './canvas.ts';\r\nimport Sprite from './Sprite.ts';\r\n\r\ntype GameLoop = (() => any) | (() => Promise<any>);\r\n\r\ntype SceneMap = {\r\n [scene: string]: {\r\n sprites: Sprite[];\r\n loop: GameLoop | null;\r\n };\r\n};\r\n\r\nexport default class Engine {\r\n\r\n private static instance: Engine;\r\n\r\n private loopRunning: boolean = false;\r\n public gameLoop: GameLoop | null = null;\r\n public maxFPS: number = 24;\r\n\r\n public sounds: HTMLAudioElement[] = [];\r\n\r\n public mouseX: number = 0;\r\n public mouseY: number = 0;\r\n\r\n public mouseDown: boolean = false;\r\n\r\n public currentScene: string = 'main';\r\n public sceneMap: SceneMap = {};\r\n\r\n // Singleton initialization\r\n\r\n public static init() {\r\n if (!this.instance)\r\n this.instance = new Engine();\r\n\r\n return this.instance;\r\n }\r\n\r\n // Change the scene\r\n\r\n public changeScene(scene: string) {\r\n if (!this.sceneMap[scene])\r\n this.sceneMap[scene] = { sprites: [], loop: null };\r\n\r\n this.loopRunning = false;\r\n this.currentScene = scene;\r\n this.gameLoop = this.sceneMap[scene].loop;\r\n this.setMaxFramesPerSecond(this.maxFPS); // Update the interval function\r\n }\r\n\r\n // Set a loop\r\n\r\n public setLoop(scene: string, loop: GameLoop) {\r\n if (!this.sceneMap[scene]) {\r\n this.sceneMap[scene] = { sprites: [], loop };\r\n if (scene === this.currentScene)\r\n this.changeScene(scene);\r\n return;\r\n }\r\n\r\n this.sceneMap[scene].loop = loop;\r\n if (scene === this.currentScene)\r\n this.changeScene(scene);\r\n }\r\n\r\n // Internal\r\n\r\n public addSprite(sprite: Sprite) {\r\n const { scene, layer } = sprite;\r\n\r\n if (!this.sceneMap[scene]) {\r\n this.sceneMap[scene] = { sprites: [sprite], loop: null };\r\n return;\r\n }\r\n\r\n let targetIndex = this.sceneMap[scene].sprites.findIndex(s => s.layer > layer);\r\n if (targetIndex === -1) {\r\n this.sceneMap[scene].sprites.push(sprite);\r\n return;\r\n }\r\n\r\n this.sceneMap[scene].sprites.splice(targetIndex, 0, sprite);\r\n }\r\n\r\n public removeSprite(sprite: Sprite) {\r\n const { scene } = sprite;\r\n\r\n if (!this.sceneMap[scene]) return;\r\n\r\n this.sceneMap[scene].sprites = this.sceneMap[scene].sprites.filter(s => s !== sprite);\r\n }\r\n\r\n public async setMaxFramesPerSecond(maxFPS: number) {\r\n this.maxFPS = maxFPS;\r\n \r\n let loop = this.gameLoop;\r\n if (!loop) return;\r\n\r\n this.loopRunning = true;\r\n\r\n while (this.loopRunning) {\r\n await loop();\r\n await this.wait(1000 / maxFPS);\r\n }\r\n }\r\n\r\n public refresh() {\r\n ctx.clearRect(0, 0, canvas.width, canvas.height);\r\n this.sceneMap[this.currentScene]?.sprites.forEach(sprite => {\r\n if (!sprite.hidden)\r\n sprite.draw();\r\n });\r\n }\r\n\r\n // Wait function\r\n\r\n public async wait(ms: number): Promise<void> {\r\n return new Promise(resolve => setTimeout(resolve, ms));\r\n }\r\n\r\n // Mouse events\r\n\r\n public isHovered(sprite: Sprite) {\r\n const { mouseX, mouseY } = this;\r\n\r\n const canvasMouseX = mouseX + canvas.width / 2;\r\n const canvasMouseY = canvas.height / 2 - mouseY;\r\n\r\n // Mouse relative to sprite center\r\n const localX = canvasMouseX - (sprite.x + canvas.width / 2);\r\n const localY = canvasMouseY - (canvas.height / 2 - sprite.y);\r\n\r\n // Rotate mouse point by -dir to align with the path's local coordinates\r\n const angle = -this.toRadians(sprite.dir);\r\n const rotatedX = localX * Math.cos(angle) - localY * Math.sin(angle);\r\n const rotatedY = localX * Math.sin(angle) + localY * Math.cos(angle);\r\n\r\n return ctx.isPointInPath(sprite.getPath(), rotatedX, rotatedY);\r\n }\r\n\r\n // Sound\r\n\r\n public playSound(src: string) {\r\n const audio = new Audio(src);\r\n this.sounds.push(audio);\r\n\r\n audio.play();\r\n\r\n return audio;\r\n }\r\n\r\n public stopSound(sound: HTMLAudioElement) {\r\n sound.pause();\r\n sound.currentTime = 0;\r\n this.sounds = this.sounds.filter(s => s !== sound);\r\n }\r\n\r\n public stopAllSounds() {\r\n this.sounds.forEach(sound => {\r\n sound.pause();\r\n sound.currentTime = 0;\r\n });\r\n this.sounds = [];\r\n }\r\n\r\n // Math\r\n\r\n public pickRandom(min: number, max: number) {\r\n if (min > max)\r\n [min, max] = [max, min];\r\n return Math.floor(Math.random() * (max - min + 1) + min);\r\n }\r\n\r\n // Trigonometric functions\r\n public sin(deg: number) {\r\n return Math.sin(this.toRadians(deg));\r\n }\r\n\r\n public cos(deg: number) {\r\n return Math.cos(this.toRadians(deg));\r\n }\r\n\r\n public tan(deg: number) {\r\n return Math.tan(this.toRadians(deg));\r\n }\r\n\r\n public csc(deg: number) {\r\n return 1 / Math.sin(this.toRadians(deg));\r\n }\r\n\r\n public sec(deg: number) {\r\n return 1 / Math.cos(this.toRadians(deg));\r\n }\r\n\r\n public cot(deg: number) {\r\n return 1 / Math.tan(this.toRadians(deg));\r\n }\r\n\r\n // Inverse Trigonometric functions\r\n public asin(val: number) {\r\n return this.toDegrees(Math.asin(val));\r\n }\r\n\r\n public acos(val: number) {\r\n return this.toDegrees(Math.acos(val));\r\n }\r\n\r\n public acsc(val: number) {\r\n return this.toDegrees(Math.asin(1 / val));\r\n }\r\n\r\n public asec(val: number) {\r\n return this.toDegrees(Math.acos(1 / val));\r\n }\r\n\r\n // Helpers\r\n\r\n public toRadians(deg: number) {\r\n return deg * Math.PI / 180;\r\n }\r\n\r\n public toDegrees(rad: number) {\r\n return rad * 180 / Math.PI;\r\n }\r\n\r\n // Private constructor\r\n\r\n private constructor() {\r\n void this.setMaxFramesPerSecond(24);\r\n\r\n penCanvas.addEventListener('mousemove', e => {\r\n this.mouseX = e.clientX - penCanvas.offsetLeft - penCanvas.width / 2;\r\n this.mouseY = -(e.clientY - penCanvas.offsetTop - penCanvas.height / 2);\r\n });\r\n penCanvas.addEventListener('mousedown', e => {\r\n this.mouseDown = true;\r\n });\r\n penCanvas.addEventListener('mouseup', e => {\r\n this.mouseDown = false;\r\n });\r\n }\r\n}","import Sprite, { type SpriteOptions } from '../Sprite.ts';\r\nimport { ctx, canvas, penCtx } from '../canvas.ts';\r\n\r\nexport interface RectangleOptions extends SpriteOptions {\r\n width?: number;\r\n height?: number;\r\n color?: string;\r\n outlineColor?: string;\r\n outlineWidth?: number;\r\n};\r\n\r\nexport default class Rectangle extends Sprite {\r\n\r\n public width: number;\r\n public height: number;\r\n public color: string;\r\n public outlineColor: string;\r\n public outlineWidth: number;\r\n\r\n public getPath(): Path2D {\r\n const path = new Path2D();\r\n\r\n path.rect(\r\n -this.width / 2,\r\n -this.height / 2,\r\n this.width,\r\n this.height\r\n );\r\n\r\n return path;\r\n }\r\n\r\n public draw(stamping?: boolean): void {\r\n const c = stamping ? penCtx : ctx;\r\n\r\n c.save();\r\n\r\n const cX = this.x + canvas.width / 2;\r\n const cY = -this.y + canvas.height / 2;\r\n c.translate(cX, cY);\r\n\r\n c.rotate(this.toRadians(this.dir));\r\n\r\n const path = this.getPath();\r\n\r\n c.fillStyle = this.color;\r\n c.strokeStyle = this.outlineColor;\r\n c.lineWidth = this.outlineWidth;\r\n c.fill(path)\r\n c.stroke(path);\r\n\r\n c.restore();\r\n }\r\n\r\n public setWidth(width: number) {\r\n this.width = width;\r\n this.refresh();\r\n }\r\n\r\n public setHeight(height: number) {\r\n this.height = height;\r\n this.refresh();\r\n }\r\n\r\n public setColor(color: string) {\r\n this.color = color;\r\n this.refresh();\r\n }\r\n\r\n constructor(options?: RectangleOptions) {\r\n super(options);\r\n this.width = options?.width ?? 50;\r\n this.height = options?.height ?? 50;\r\n this.color = options?.color ?? 'black';\r\n this.outlineColor = options?.outlineColor ?? 'black';\r\n this.outlineWidth = options?.outlineWidth ?? 0;\r\n this.draw();\r\n }\r\n\r\n}","import Sprite, { type SpriteOptions } from '../Sprite.ts';\r\nimport { canvas, ctx, penCtx } from '../canvas.ts';\r\n\r\nexport interface OvalOptions extends SpriteOptions {\r\n radA?: number;\r\n radB?: number;\r\n color?: string;\r\n outlineColor?: string;\r\n outlineWidth?: number;\r\n};\r\n\r\nexport default class Oval extends Sprite {\r\n\r\n public radA: number;\r\n public radB: number;\r\n public color: string;\r\n public outlineColor: string;\r\n public outlineWidth: number;\r\n\r\n public getPath(): Path2D {\r\n const path = new Path2D();\r\n\r\n path.ellipse(\r\n 0, 0,\r\n this.radA,\r\n this.radB,\r\n 0, 0,\r\n Math.PI * 2\r\n );\r\n\r\n return path;\r\n }\r\n\r\n public draw(stamping?: boolean): void {\r\n const c = stamping ? penCtx : ctx;\r\n \r\n c.save();\r\n\r\n const cX = this.x + canvas.width / 2;\r\n const cY = -this.y + canvas.height / 2;\r\n c.translate(cX, cY);\r\n\r\n c.rotate(this.toRadians(this.dir));\r\n\r\n const path = this.getPath();\r\n\r\n c.fillStyle = this.color;\r\n c.strokeStyle = this.outlineColor;\r\n c.lineWidth = this.outlineWidth;\r\n c.fill(path)\r\n c.stroke(path);\r\n\r\n c.restore();\r\n }\r\n\r\n public setRadA(radA: number) {\r\n this.radA = radA;\r\n this.refresh();\r\n }\r\n\r\n public setRadB(radB: number) {\r\n this.radB = radB;\r\n this.refresh();\r\n }\r\n\r\n public setColor(color: string) {\r\n this.color = color;\r\n this.refresh();\r\n }\r\n\r\n constructor(options?: OvalOptions) {\r\n super(options);\r\n this.radA = options?.radA ?? 25;\r\n this.radB = options?.radB ?? 25;\r\n this.color = options?.color ?? 'black';\r\n this.outlineColor = options?.outlineColor ?? 'black';\r\n this.outlineWidth = options?.outlineWidth ?? 0;\r\n this.draw();\r\n }\r\n\r\n}","import { canvas, ctx, penCtx } from '../canvas.ts';\r\nimport Sprite, { type SpriteOptions } from '../Sprite.ts';\r\n\r\nexport interface RegularPolygonOptions extends SpriteOptions {\r\n sides?: number;\r\n radius?: number;\r\n color?: string;\r\n outlineColor?: string;\r\n outlineWidth?: number;\r\n}\r\n\r\nexport default class RegularPolygon extends Sprite {\r\n\r\n public sides: number;\r\n public radius: number;\r\n public color: string;\r\n public outlineColor: string;\r\n public outlineWidth: number;\r\n\r\n public getPath(): Path2D {\r\n const path = new Path2D();\r\n\r\n const step = (Math.PI * 2) / this.sides;\r\n const rotation = this.toRadians(this.dir);\r\n const r = this.radius;\r\n\r\n for (let i = 0; i < this.sides; i++) {\r\n const theta = i * step - Math.PI / 2 + rotation;\r\n const px = r * Math.cos(theta);\r\n const py = -r * Math.sin(theta);\r\n\r\n if (i === 0) path.moveTo(px, py);\r\n else path.lineTo(px, py);\r\n }\r\n\r\n path.closePath();\r\n\r\n return path;\r\n }\r\n\r\n public draw(stamping?: boolean) {\r\n const c = stamping ? penCtx : ctx;\r\n\r\n c.save();\r\n\r\n const cX = this.x + canvas.width / 2;\r\n const cY = -this.y + canvas.height / 2;\r\n\r\n c.translate(cX, cY);\r\n\r\n const path = this.getPath();\r\n\r\n c.fillStyle = this.color;\r\n c.strokeStyle = this.outlineColor;\r\n c.lineWidth = this.outlineWidth;\r\n c.fill(path)\r\n c.stroke(path);\r\n\r\n c.restore();\r\n }\r\n\r\n public setSides(sides: number) {\r\n this.sides = sides;\r\n this.refresh();\r\n }\r\n\r\n public setRadius(radius: number) {\r\n this.radius = radius;\r\n this.refresh();\r\n }\r\n\r\n public setColor(color: string) {\r\n this.color = color;\r\n this.refresh();\r\n }\r\n\r\n constructor(options?: RegularPolygonOptions) {\r\n super(options);\r\n this.sides = options?.sides ?? 5;\r\n this.radius = options?.radius ?? 50;\r\n this.color = options?.color ?? 'black';\r\n this.outlineColor = options?.outlineColor ?? 'black';\r\n this.outlineWidth = options?.outlineWidth ?? 0;\r\n this.draw();\r\n }\r\n\r\n}","import { canvas, penCtx } from '../canvas.ts';\r\nimport Sprite, { type SpriteOptions } from '../Sprite.ts';\r\n\r\nexport interface PenOptions extends SpriteOptions {\r\n drawing?: boolean;\r\n size?: number;\r\n color?: string;\r\n}\r\n\r\nexport default class Pen extends Sprite {\r\n\r\n public drawing: boolean;\r\n public size: number;\r\n public color: string;\r\n\r\n public getPath(): Path2D {\r\n return new Path2D();\r\n }\r\n public draw() {}\r\n\r\n public up() {\r\n this.drawing = false;\r\n }\r\n\r\n public down() {\r\n this.drawing = true;\r\n }\r\n\r\n public stamp(sprite: Sprite) {\r\n sprite.draw(true);\r\n }\r\n\r\n public ereaseAll() {\r\n penCtx.clearRect(0, 0, canvas.width, canvas.height);\r\n }\r\n\r\n public dot() {\r\n penCtx.fillStyle = this.color;\r\n penCtx.fillRect(\r\n this.x - this.size / 2 + canvas.width / 2,\r\n -this.y - this.size / 2 + canvas.height / 2,\r\n this.size,\r\n this.size\r\n );\r\n }\r\n\r\n private drawLine(lastX: number, lastY: number) {\r\n penCtx.beginPath();\r\n\r\n penCtx.moveTo(lastX + canvas.width / 2, -lastY + canvas.height / 2);\r\n penCtx.lineTo(this.x + canvas.width / 2, -this.y + canvas.height / 2);\r\n\r\n penCtx.lineWidth = this.size;\r\n penCtx.strokeStyle = this.color;\r\n penCtx.stroke();\r\n }\r\n\r\n // Overriding methods to include drawing\r\n\r\n public override move(steps: number) {\r\n const lastX = this.x;\r\n const lastY = this.y;\r\n\r\n this.x += steps * Math.sin(this.toRadians(this.dir));\r\n this.y += steps * Math.cos(this.toRadians(this.dir));\r\n if (this.drawing)\r\n this.drawLine(lastX, lastY);\r\n this.refresh();\r\n }\r\n\r\n public override setX(x: number) {\r\n const lastX = this.x;\r\n const lastY = this.y;\r\n\r\n this.x = x;\r\n if (this.drawing)\r\n this.drawLine(lastX, lastY);\r\n this.refresh();\r\n }\r\n\r\n public override setY(y: number) {\r\n const lastX = this.x;\r\n const lastY = this.y;\r\n\r\n this.y = y;\r\n if (this.drawing)\r\n this.drawLine(lastX, lastY);\r\n this.refresh();\r\n }\r\n\r\n public override goTo(x: number, y: number) {\r\n const lastX = this.x;\r\n const lastY = this.y;\r\n\r\n this.x = x;\r\n this.y = y;\r\n if (this.drawing)\r\n this.drawLine(lastX, lastY);\r\n this.refresh();\r\n }\r\n\r\n public override changeX(dX: number) {\r\n const lastX = this.x;\r\n const lastY = this.y;\r\n\r\n this.x += dX;\r\n if (this.drawing)\r\n this.drawLine(lastX, lastY);\r\n this.refresh();\r\n }\r\n\r\n public override changeY(dY: number) {\r\n const lastX = this.x;\r\n const lastY = this.y;\r\n\r\n this.y += dY;\r\n if (this.drawing)\r\n this.drawLine(lastX, lastY);\r\n this.refresh();\r\n }\r\n\r\n // Constructor\r\n\r\n constructor(options?: PenOptions) {\r\n super(options);\r\n this.drawing = options?.drawing ?? false;\r\n this.size = options?.size ?? 5;\r\n this.color = options?.color ?? 'black';\r\n }\r\n\r\n}","import { canvas, ctx, penCtx } from '../canvas.ts';\r\nimport Sprite, { type SpriteOptions } from '../Sprite.ts';\r\n\r\nexport type CanvasTextAlign =\r\n | 'left'\r\n | 'right'\r\n | 'center'\r\n | 'start'\r\n | 'end';\r\n\r\nexport type CanvasTextBaseline =\r\n | 'top'\r\n | 'hanging'\r\n | 'middle'\r\n | 'alphabetic'\r\n | 'ideographic'\r\n | 'bottom';\r\n\r\nexport interface TextOptions extends SpriteOptions {\r\n content?: string;\r\n color?: string;\r\n fontFamily?: string;\r\n fontSize?: number;\r\n align?: CanvasTextAlign;\r\n baseline?: CanvasTextBaseline;\r\n}\r\n\r\nexport default class Text extends Sprite {\r\n\r\n public content: string;\r\n public color: string;\r\n public fontFamily: string;\r\n public fontSize: number;\r\n public align: CanvasTextAlign;\r\n public baseline: CanvasTextBaseline;\r\n\r\n private font: string;\r\n\r\n public getPath(): Path2D {\r\n const path = new Path2D();\r\n\r\n ctx.save();\r\n \r\n ctx.font = this.font;\r\n\r\n const metrics = ctx.measureText(this.content);\r\n const width = metrics.width;\r\n const height = metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent;\r\n\r\n ctx.restore();\r\n\r\n path.rect(-width / 2, -height / 2, width, height);\r\n\r\n return path\r\n }\r\n\r\n public draw(stamping?: boolean) {\r\n const c = stamping ? penCtx : ctx;\r\n\r\n c.save();\r\n\r\n const cX = this.x + canvas.width / 2;\r\n const cY = -this.y + canvas.height / 2;\r\n c.translate(cX, cY);\r\n\r\n c.rotate(this.toRadians(this.dir));\r\n\r\n c.font = this.font;\r\n c.fillStyle = this.color;\r\n c.textAlign = this.align;\r\n c.textBaseline = this.baseline;\r\n\r\n c.fillText(this.content, 0, 0);\r\n\r\n c.restore();\r\n }\r\n\r\n // Methods\r\n\r\n public setContent(content: string) {\r\n this.content = content;\r\n this.refresh();\r\n }\r\n\r\n public setColor(color: string) {\r\n this.color = color;\r\n this.refresh();\r\n }\r\n\r\n public setFontSize(fontSize: number) {\r\n this.fontSize = fontSize;\r\n this.font = `${this.fontSize}px ${this.fontFamily}`;\r\n this.refresh();\r\n }\r\n\r\n public setFontFamily(fontFamily: string) {\r\n this.fontFamily = fontFamily;\r\n this.font = `${this.fontSize}px ${this.fontFamily}`;\r\n this.refresh();\r\n }\r\n\r\n public setAlign(align: CanvasTextAlign) {\r\n this.align = align;\r\n this.refresh();\r\n }\r\n\r\n public setBaseline(baseline: CanvasTextBaseline) {\r\n this.baseline = baseline;\r\n this.refresh();\r\n }\r\n\r\n // Constructor\r\n\r\n constructor(options?: TextOptions) {\r\n super(options);\r\n\r\n this.content = options?.content ?? '';\r\n this.color = options?.color ?? 'black';\r\n this.fontFamily = options?.fontFamily ?? 'Arial';\r\n this.fontSize = options?.fontSize ?? 16;\r\n this.align = options?.align ?? 'center';\r\n this.baseline = options?.baseline ?? 'middle';\r\n\r\n this.font = `${this.fontSize}px ${this.fontFamily}`;\r\n }\r\n}","import { canvas, ctx, penCtx } from '../canvas.ts';\r\nimport Sprite, { type SpriteOptions } from '../Sprite.ts';\r\n\r\nexport interface ImageSpriteOptions extends SpriteOptions {\r\n src?: string;\r\n width: number;\r\n height: number;\r\n outlineColor?: string;\r\n outlineWidth?: number;\r\n};\r\n\r\nexport default class ImageSprite extends Sprite {\r\n\r\n public src: string;\r\n public width: number;\r\n public height: number;\r\n public outlineColor: string;\r\n public outlineWidth: number;\r\n\r\n protected img: HTMLImageElement;\r\n\r\n public getPath(): Path2D {\r\n const path = new Path2D();\r\n\r\n path.rect(\r\n -this.width / 2,\r\n -this.height / 2,\r\n this.width,\r\n this.height\r\n );\r\n\r\n return path;\r\n }\r\n\r\n public draw(stamping?: boolean) {\r\n const c = stamping ? penCtx : ctx;\r\n\r\n c.save();\r\n\r\n const cX = this.x + canvas.width / 2;\r\n const cY = -this.y + canvas.height / 2;\r\n c.translate(cX, cY);\r\n\r\n c.rotate(this.toRadians(this.dir));\r\n\r\n c.strokeStyle = this.outlineColor;\r\n c.lineWidth = this.outlineWidth;\r\n c.drawImage(\r\n this.img,\r\n 0, 0,\r\n this.img.width,\r\n this.img.height,\r\n -this.width / 2,\r\n -this.height / 2,\r\n this.width, this.height\r\n );\r\n c.stroke(this.getPath());\r\n\r\n c.restore();\r\n }\r\n\r\n // Methods\r\n\r\n public setSrc(src: string) {\r\n this.src = src;\r\n this.refresh();\r\n }\r\n\r\n public setWidth(width: number) {\r\n this.width = width;\r\n this.refresh();\r\n }\r\n\r\n public setHeight(height: number) {\r\n this.height = height;\r\n this.refresh();\r\n }\r\n\r\n // Constructor\r\n\r\n constructor(options?: ImageSpriteOptions) {\r\n super(options);\r\n\r\n this.src = options?.src ?? '';\r\n this.img = new Image();\r\n this.img.src = this.src;\r\n\r\n this.width = options?.width ?? this.img.width;\r\n this.height = options?.height ?? this.img.height;\r\n\r\n this.outlineColor = options?.outlineColor ?? 'black';\r\n this.outlineWidth = options?.outlineWidth ?? 0;\r\n }\r\n}"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,YAAAE,EAAA,gBAAAC,EAAA,SAAAC,EAAA,QAAAC,EAAA,cAAAC,EAAA,mBAAAC,EAAA,WAAAC,EAAA,SAAAC,EAAA,WAAAC,EAAA,QAAAC,EAAA,YAAAC,EAAA,mBAAAC,EAAA,aAAAC,IAAA,eAAAC,EAAAf,GCAO,IAAMgB,EAAS,SAAS,eAAe,aAAa,EAC9CC,EAAMD,EAAO,WAAW,IAAI,EAE5BE,EAAY,SAAS,cAAc,QAAQ,EAC3CC,EAASD,EAAU,WAAW,IAAI,EAC/CA,EAAU,GAAK,aAEf,IAAIE,EAAgB,GAAK,EACrBC,EAEG,SAASC,EAASC,EAAkB,CACvCF,EAAQE,EAERP,EAAO,MAAQI,EAAQC,EACvBL,EAAO,OAASK,EAEhBH,EAAU,MAAQE,EAAQC,EAC1BH,EAAU,OAASG,CACvB,CAEO,SAASG,EAAeC,EAAwB,CACnDL,EAAQK,EAERT,EAAO,MAAQI,EAAQC,EACvBL,EAAO,OAASK,EAEhBH,EAAU,MAAQE,EAAQC,EAC1BH,EAAU,OAASG,CACvB,CAEAL,EAAO,eAAe,aAAaE,EAAWF,CAAM,EAEpDM,EAAS,GAAG,ECrBZ,IAA8BI,EAA9B,KAAqC,CAE1B,EACA,EACA,IACA,MACA,OACA,MAOG,SAAU,CAChBC,EAAO,KAAK,EAAE,QAAQ,CAC1B,CAEA,YAAYC,EAAyB,CACjC,KAAK,EAAIA,GAAS,GAAK,EACvB,KAAK,EAAIA,GAAS,GAAK,EACvB,KAAK,IAAMA,GAAS,KAAO,EAC3B,KAAK,MAAQA,GAAS,OAAS,OAC/B,KAAK,OAASA,GAAS,QA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AAC,EACA,YAAAC,EAGA,SAAAC,EACA,eAAAC,EACA,OAAAC,EACA,IAAAC,CACJ,EAEOC,EAAQb","names":["index_exports","__export","Engine","ImageSprite","Oval","Pen","Rectangle","RegularPolygon","Sprite","Text","canvas","ctx","index_default","setAspectRatio","setScale","__toCommonJS","canvas","ctx","penCanvas","penCtx","ratio","scale","setScale","newScale","setAspectRatio","newAspectRatio","Sprite","Engine","options","deg","rad","steps","dir","x","y","dX","dY","layer","dL","Engine","_Engine","scene","loop","sprite","layer","targetIndex","s","maxFPS","ctx","canvas","ms","resolve","mouseX","mouseY","canvasMouseX","canvasMouseY","localX","localY","angle","rotatedX","rotatedY","src","audio","sound","min","max","deg","val","rad","penCanvas","e","Rectangle","Sprite","path","stamping","c","penCtx","ctx","cX","canvas","cY","width","height","color","options","Oval","Sprite","path","stamping","c","penCtx","ctx","cX","canvas","cY","radA","radB","color","options","RegularPolygon","Sprite","path","step","rotation","i","theta","px","py","stamping","c","penCtx","ctx","cX","canvas","cY","sides","radius","color","options","Pen","Sprite","sprite","penCtx","canvas","lastX","lastY","steps","x","y","dX","dY","options","Text","Sprite","path","ctx","metrics","width","height","stamping","c","penCtx","cX","canvas","cY","content","color","fontSize","fontFamily","align","baseline","options","ImageSprite","Sprite","path","stamping","c","penCtx","ctx","cX","canvas","cY","src","width","height","options","TScratch","Engine","Sprite","Rectangle","Oval","RegularPolygon","Pen","Text","ImageSprite","setScale","setAspectRatio","canvas","ctx","index_default"]}
package/dist/index.d.cts CHANGED
@@ -55,6 +55,7 @@ declare class Engine {
55
55
  changeScene(scene: string): void;
56
56
  setLoop(scene: string, loop: GameLoop): void;
57
57
  addSprite(sprite: Sprite): void;
58
+ removeSprite(sprite: Sprite): void;
58
59
  setMaxFramesPerSecond(maxFPS: number): Promise<void>;
59
60
  refresh(): void;
60
61
  wait(ms: number): Promise<void>;
package/dist/index.d.ts CHANGED
@@ -55,6 +55,7 @@ declare class Engine {
55
55
  changeScene(scene: string): void;
56
56
  setLoop(scene: string, loop: GameLoop): void;
57
57
  addSprite(sprite: Sprite): void;
58
+ removeSprite(sprite: Sprite): void;
58
59
  setMaxFramesPerSecond(maxFPS: number): Promise<void>;
59
60
  refresh(): void;
60
61
  wait(ms: number): Promise<void>;
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- var i=document.getElementById("game-window"),h=i.getContext("2d"),d=document.createElement("canvas"),n=d.getContext("2d");d.id="pen-canvas";var g=16/9,c;function M(l){c=l,i.width=g*c,i.height=c,d.width=g*c,d.height=c}function P(l){g=l,i.width=g*c,i.height=c,d.width=g*c,d.height=c}i.parentElement?.insertBefore(d,i);M(500);var a=class{x;y;dir;scene;hidden;layer;refresh(){u.init().refresh()}constructor(t){this.x=t?.x??0,this.y=t?.y??0,this.dir=t?.dir??0,this.scene=t?.scene??"main",this.hidden=t?.hidden??!1,this.layer=t?.layer??0,u.init().addSprite(this)}toRadians(t){return t*Math.PI/180}toDegrees(t){return t*180/Math.PI}move(t){this.x+=t*Math.sin(this.toRadians(this.dir)),this.y+=t*Math.cos(this.toRadians(this.dir)),this.refresh()}turn(t){this.dir+=t,this.refresh()}point(t){this.dir=t,this.refresh()}setX(t){this.x=t,this.refresh()}setY(t){this.y=t,this.refresh()}goTo(t,e){this.x=t,this.y=e,this.refresh()}changeX(t){this.x+=t,this.refresh()}changeY(t){this.y+=t,this.refresh()}show(){this.hidden=!1,this.refresh()}hide(){this.hidden=!0,this.refresh()}goToLayer(t){this.layer=t,this.refresh()}changeLayer(t){this.layer+=t,this.refresh()}};var u=class l{static instance;loopRunning=!1;gameLoop=null;maxFPS=24;sounds=[];mouseX=0;mouseY=0;mouseDown=!1;currentScene="main";sceneMap={};static init(){return this.instance||(this.instance=new l),this.instance}changeScene(t){this.sceneMap[t]||(this.sceneMap[t]={sprites:[],loop:null}),this.loopRunning=!1,this.currentScene=t,this.gameLoop=this.sceneMap[t].loop,this.setMaxFramesPerSecond(this.maxFPS)}setLoop(t,e){if(!this.sceneMap[t]){this.sceneMap[t]={sprites:[],loop:e},t===this.currentScene&&this.changeScene(t);return}this.sceneMap[t].loop=e,t===this.currentScene&&this.changeScene(t)}addSprite(t){let{scene:e,layer:s}=t;if(!this.sceneMap[e]){this.sceneMap[e]={sprites:[t],loop:null};return}let r=this.sceneMap[e].sprites.findIndex(o=>o.layer>s);if(r===-1){this.sceneMap[e].sprites.push(t);return}this.sceneMap[e].sprites.splice(r,0,t)}async setMaxFramesPerSecond(t){this.maxFPS=t;let e=this.gameLoop;if(e)for(this.loopRunning=!0;this.loopRunning;)await e(),await this.wait(1e3/t)}refresh(){h.clearRect(0,0,i.width,i.height),this.sceneMap[this.currentScene]?.sprites.forEach(t=>{t.hidden||t.draw()})}async wait(t){return new Promise(e=>setTimeout(e,t))}isHovered(t){let{mouseX:e,mouseY:s}=this,r=e+i.width/2,o=i.height/2-s,b=r-(t.x+i.width/2),m=o-(i.height/2-t.y),p=-this.toRadians(t.dir),C=b*Math.cos(p)-m*Math.sin(p),O=b*Math.sin(p)+m*Math.cos(p);return h.isPointInPath(t.getPath(),C,O)}playSound(t){let e=new Audio(t);return this.sounds.push(e),e.play(),e}stopSound(t){t.pause(),t.currentTime=0,this.sounds=this.sounds.filter(e=>e!==t)}stopAllSounds(){this.sounds.forEach(t=>{t.pause(),t.currentTime=0}),this.sounds=[]}pickRandom(t,e){return t>e&&([t,e]=[e,t]),Math.floor(Math.random()*(e-t+1)+t)}sin(t){return Math.sin(this.toRadians(t))}cos(t){return Math.cos(this.toRadians(t))}tan(t){return Math.tan(this.toRadians(t))}csc(t){return 1/Math.sin(this.toRadians(t))}sec(t){return 1/Math.cos(this.toRadians(t))}cot(t){return 1/Math.tan(this.toRadians(t))}asin(t){return this.toDegrees(Math.asin(t))}acos(t){return this.toDegrees(Math.acos(t))}acsc(t){return this.toDegrees(Math.asin(1/t))}asec(t){return this.toDegrees(Math.acos(1/t))}toRadians(t){return t*Math.PI/180}toDegrees(t){return t*180/Math.PI}constructor(){this.setMaxFramesPerSecond(24),i.addEventListener("mousemove",t=>{this.mouseX=t.clientX-i.offsetLeft-i.width/2,this.mouseY=-(t.clientY-i.offsetTop-i.height/2)}),i.addEventListener("mousedown",t=>{this.mouseDown=!0}),i.addEventListener("mouseup",t=>{this.mouseDown=!1})}};var f=class extends a{width;height;color;outlineColor;outlineWidth;getPath(){let t=new Path2D;return t.rect(-this.width/2,-this.height/2,this.width,this.height),t}draw(t){let e=t?n:h;e.save();let s=this.x+i.width/2,r=-this.y+i.height/2;e.translate(s,r),e.rotate(this.toRadians(this.dir));let o=this.getPath();e.fillStyle=this.color,e.strokeStyle=this.outlineColor,e.lineWidth=this.outlineWidth,e.fill(o),e.stroke(o),e.restore()}setWidth(t){this.width=t,this.refresh()}setHeight(t){this.height=t,this.refresh()}setColor(t){this.color=t,this.refresh()}constructor(t){super(t),this.width=t?.width??50,this.height=t?.height??50,this.color=t?.color??"black",this.outlineColor=t?.outlineColor??"black",this.outlineWidth=t?.outlineWidth??0,this.draw()}};var x=class extends a{radA;radB;color;outlineColor;outlineWidth;getPath(){let t=new Path2D;return t.ellipse(0,0,this.radA,this.radB,0,0,Math.PI*2),t}draw(t){let e=t?n:h;e.save();let s=this.x+i.width/2,r=-this.y+i.height/2;e.translate(s,r),e.rotate(this.toRadians(this.dir));let o=this.getPath();e.fillStyle=this.color,e.strokeStyle=this.outlineColor,e.lineWidth=this.outlineWidth,e.fill(o),e.stroke(o),e.restore()}setRadA(t){this.radA=t,this.refresh()}setRadB(t){this.radB=t,this.refresh()}setColor(t){this.color=t,this.refresh()}constructor(t){super(t),this.radA=t?.radA??25,this.radB=t?.radB??25,this.color=t?.color??"black",this.outlineColor=t?.outlineColor??"black",this.outlineWidth=t?.outlineWidth??0,this.draw()}};var y=class extends a{sides;radius;color;outlineColor;outlineWidth;getPath(){let t=new Path2D,e=Math.PI*2/this.sides,s=this.toRadians(this.dir),r=this.radius;for(let o=0;o<this.sides;o++){let b=o*e-Math.PI/2+s,m=r*Math.cos(b),p=-r*Math.sin(b);o===0?t.moveTo(m,p):t.lineTo(m,p)}return t.closePath(),t}draw(t){let e=t?n:h;e.save();let s=this.x+i.width/2,r=-this.y+i.height/2;e.translate(s,r);let o=this.getPath();e.fillStyle=this.color,e.strokeStyle=this.outlineColor,e.lineWidth=this.outlineWidth,e.fill(o),e.stroke(o),e.restore()}setSides(t){this.sides=t,this.refresh()}setRadius(t){this.radius=t,this.refresh()}setColor(t){this.color=t,this.refresh()}constructor(t){super(t),this.sides=t?.sides??5,this.radius=t?.radius??50,this.color=t?.color??"black",this.outlineColor=t?.outlineColor??"black",this.outlineWidth=t?.outlineWidth??0,this.draw()}};var w=class extends a{drawing;size;color;getPath(){return new Path2D}draw(){}up(){this.drawing=!1}down(){this.drawing=!0}stamp(t){t.draw(!0)}ereaseAll(){n.clearRect(0,0,i.width,i.height)}dot(){n.fillStyle=this.color,n.fillRect(this.x-this.size/2+i.width/2,-this.y-this.size/2+i.height/2,this.size,this.size)}drawLine(t,e){n.beginPath(),n.moveTo(t+i.width/2,-e+i.height/2),n.lineTo(this.x+i.width/2,-this.y+i.height/2),n.lineWidth=this.size,n.strokeStyle=this.color,n.stroke()}move(t){let e=this.x,s=this.y;this.x+=t*Math.sin(this.toRadians(this.dir)),this.y+=t*Math.cos(this.toRadians(this.dir)),this.drawing&&this.drawLine(e,s),this.refresh()}setX(t){let e=this.x,s=this.y;this.x=t,this.drawing&&this.drawLine(e,s),this.refresh()}setY(t){let e=this.x,s=this.y;this.y=t,this.drawing&&this.drawLine(e,s),this.refresh()}goTo(t,e){let s=this.x,r=this.y;this.x=t,this.y=e,this.drawing&&this.drawLine(s,r),this.refresh()}changeX(t){let e=this.x,s=this.y;this.x+=t,this.drawing&&this.drawLine(e,s),this.refresh()}changeY(t){let e=this.x,s=this.y;this.y+=t,this.drawing&&this.drawLine(e,s),this.refresh()}constructor(t){super(t),this.drawing=t?.drawing??!1,this.size=t?.size??5,this.color=t?.color??"black"}};var S=class extends a{content;color;fontFamily;fontSize;align;baseline;font;getPath(){let t=new Path2D;h.save(),h.font=this.font;let e=h.measureText(this.content),s=e.width,r=e.actualBoundingBoxAscent+e.actualBoundingBoxDescent;return h.restore(),t.rect(-s/2,-r/2,s,r),t}draw(t){let e=t?n:h;e.save();let s=this.x+i.width/2,r=-this.y+i.height/2;e.translate(s,r),e.rotate(this.toRadians(this.dir)),e.font=this.font,e.fillStyle=this.color,e.textAlign=this.align,e.textBaseline=this.baseline,e.fillText(this.content,0,0),e.restore()}setContent(t){this.content=t,this.refresh()}setColor(t){this.color=t,this.refresh()}setFontSize(t){this.fontSize=t,this.font=`${this.fontSize}px ${this.fontFamily}`,this.refresh()}setFontFamily(t){this.fontFamily=t,this.font=`${this.fontSize}px ${this.fontFamily}`,this.refresh()}setAlign(t){this.align=t,this.refresh()}setBaseline(t){this.baseline=t,this.refresh()}constructor(t){super(t),this.content=t?.content??"",this.color=t?.color??"black",this.fontFamily=t?.fontFamily??"Arial",this.fontSize=t?.fontSize??16,this.align=t?.align??"center",this.baseline=t?.baseline??"middle",this.font=`${this.fontSize}px ${this.fontFamily}`}};var v=class extends a{src;width;height;outlineColor;outlineWidth;img;getPath(){let t=new Path2D;return t.rect(-this.width/2,-this.height/2,this.width,this.height),t}draw(t){let e=t?n:h;e.save();let s=this.x+i.width/2,r=-this.y+i.height/2;e.translate(s,r),e.rotate(this.toRadians(this.dir)),e.strokeStyle=this.outlineColor,e.lineWidth=this.outlineWidth,e.drawImage(this.img,0,0,this.img.width,this.img.height,-this.width/2,-this.height/2,this.width,this.height),e.stroke(this.getPath()),e.restore()}setSrc(t){this.src=t,this.refresh()}setWidth(t){this.width=t,this.refresh()}setHeight(t){this.height=t,this.refresh()}constructor(t){super(t),this.src=t?.src??"",this.img=new Image,this.img.src=this.src,this.width=t?.width??this.img.width,this.height=t?.height??this.img.height,this.outlineColor=t?.outlineColor??"black",this.outlineWidth=t?.outlineWidth??0}};var R={Engine:u,Sprite:a,Rectangle:f,Oval:x,RegularPolygon:y,Pen:w,Text:S,ImageSprite:v,setScale:M,setAspectRatio:P,canvas:i,ctx:h},at=R;export{u as Engine,v as ImageSprite,x as Oval,w as Pen,f as Rectangle,y as RegularPolygon,a as Sprite,S as Text,i as canvas,h as ctx,at as default,P as setAspectRatio,M as setScale};
1
+ var i=document.getElementById("game-window"),h=i.getContext("2d"),l=document.createElement("canvas"),n=l.getContext("2d");l.id="pen-canvas";var g=16/9,u;function M(c){u=c,i.width=g*u,i.height=u,l.width=g*u,l.height=u}function P(c){g=c,i.width=g*u,i.height=u,l.width=g*u,l.height=u}i.parentElement?.insertBefore(l,i);M(500);var a=class{x;y;dir;scene;hidden;layer;refresh(){p.init().refresh()}constructor(t){this.x=t?.x??0,this.y=t?.y??0,this.dir=t?.dir??0,this.scene=t?.scene??"main",this.hidden=t?.hidden??!1,this.layer=t?.layer??0,p.init().addSprite(this)}toRadians(t){return t*Math.PI/180}toDegrees(t){return t*180/Math.PI}move(t){this.x+=t*Math.sin(this.toRadians(this.dir)),this.y+=t*Math.cos(this.toRadians(this.dir)),this.refresh()}turn(t){this.dir+=t,this.refresh()}point(t){this.dir=t,this.refresh()}setX(t){this.x=t,this.refresh()}setY(t){this.y=t,this.refresh()}goTo(t,e){this.x=t,this.y=e,this.refresh()}changeX(t){this.x+=t,this.refresh()}changeY(t){this.y+=t,this.refresh()}show(){this.hidden=!1,this.refresh()}hide(){this.hidden=!0,this.refresh()}goToLayer(t){this.layer=t,this.refresh()}changeLayer(t){this.layer+=t,this.refresh()}};var p=class c{static instance;loopRunning=!1;gameLoop=null;maxFPS=24;sounds=[];mouseX=0;mouseY=0;mouseDown=!1;currentScene="main";sceneMap={};static init(){return this.instance||(this.instance=new c),this.instance}changeScene(t){this.sceneMap[t]||(this.sceneMap[t]={sprites:[],loop:null}),this.loopRunning=!1,this.currentScene=t,this.gameLoop=this.sceneMap[t].loop,this.setMaxFramesPerSecond(this.maxFPS)}setLoop(t,e){if(!this.sceneMap[t]){this.sceneMap[t]={sprites:[],loop:e},t===this.currentScene&&this.changeScene(t);return}this.sceneMap[t].loop=e,t===this.currentScene&&this.changeScene(t)}addSprite(t){let{scene:e,layer:s}=t;if(!this.sceneMap[e]){this.sceneMap[e]={sprites:[t],loop:null};return}let r=this.sceneMap[e].sprites.findIndex(o=>o.layer>s);if(r===-1){this.sceneMap[e].sprites.push(t);return}this.sceneMap[e].sprites.splice(r,0,t)}removeSprite(t){let{scene:e}=t;this.sceneMap[e]&&(this.sceneMap[e].sprites=this.sceneMap[e].sprites.filter(s=>s!==t))}async setMaxFramesPerSecond(t){this.maxFPS=t;let e=this.gameLoop;if(e)for(this.loopRunning=!0;this.loopRunning;)await e(),await this.wait(1e3/t)}refresh(){h.clearRect(0,0,i.width,i.height),this.sceneMap[this.currentScene]?.sprites.forEach(t=>{t.hidden||t.draw()})}async wait(t){return new Promise(e=>setTimeout(e,t))}isHovered(t){let{mouseX:e,mouseY:s}=this,r=e+i.width/2,o=i.height/2-s,b=r-(t.x+i.width/2),m=o-(i.height/2-t.y),d=-this.toRadians(t.dir),C=b*Math.cos(d)-m*Math.sin(d),O=b*Math.sin(d)+m*Math.cos(d);return h.isPointInPath(t.getPath(),C,O)}playSound(t){let e=new Audio(t);return this.sounds.push(e),e.play(),e}stopSound(t){t.pause(),t.currentTime=0,this.sounds=this.sounds.filter(e=>e!==t)}stopAllSounds(){this.sounds.forEach(t=>{t.pause(),t.currentTime=0}),this.sounds=[]}pickRandom(t,e){return t>e&&([t,e]=[e,t]),Math.floor(Math.random()*(e-t+1)+t)}sin(t){return Math.sin(this.toRadians(t))}cos(t){return Math.cos(this.toRadians(t))}tan(t){return Math.tan(this.toRadians(t))}csc(t){return 1/Math.sin(this.toRadians(t))}sec(t){return 1/Math.cos(this.toRadians(t))}cot(t){return 1/Math.tan(this.toRadians(t))}asin(t){return this.toDegrees(Math.asin(t))}acos(t){return this.toDegrees(Math.acos(t))}acsc(t){return this.toDegrees(Math.asin(1/t))}asec(t){return this.toDegrees(Math.acos(1/t))}toRadians(t){return t*Math.PI/180}toDegrees(t){return t*180/Math.PI}constructor(){this.setMaxFramesPerSecond(24),l.addEventListener("mousemove",t=>{this.mouseX=t.clientX-l.offsetLeft-l.width/2,this.mouseY=-(t.clientY-l.offsetTop-l.height/2)}),l.addEventListener("mousedown",t=>{this.mouseDown=!0}),l.addEventListener("mouseup",t=>{this.mouseDown=!1})}};var f=class extends a{width;height;color;outlineColor;outlineWidth;getPath(){let t=new Path2D;return t.rect(-this.width/2,-this.height/2,this.width,this.height),t}draw(t){let e=t?n:h;e.save();let s=this.x+i.width/2,r=-this.y+i.height/2;e.translate(s,r),e.rotate(this.toRadians(this.dir));let o=this.getPath();e.fillStyle=this.color,e.strokeStyle=this.outlineColor,e.lineWidth=this.outlineWidth,e.fill(o),e.stroke(o),e.restore()}setWidth(t){this.width=t,this.refresh()}setHeight(t){this.height=t,this.refresh()}setColor(t){this.color=t,this.refresh()}constructor(t){super(t),this.width=t?.width??50,this.height=t?.height??50,this.color=t?.color??"black",this.outlineColor=t?.outlineColor??"black",this.outlineWidth=t?.outlineWidth??0,this.draw()}};var x=class extends a{radA;radB;color;outlineColor;outlineWidth;getPath(){let t=new Path2D;return t.ellipse(0,0,this.radA,this.radB,0,0,Math.PI*2),t}draw(t){let e=t?n:h;e.save();let s=this.x+i.width/2,r=-this.y+i.height/2;e.translate(s,r),e.rotate(this.toRadians(this.dir));let o=this.getPath();e.fillStyle=this.color,e.strokeStyle=this.outlineColor,e.lineWidth=this.outlineWidth,e.fill(o),e.stroke(o),e.restore()}setRadA(t){this.radA=t,this.refresh()}setRadB(t){this.radB=t,this.refresh()}setColor(t){this.color=t,this.refresh()}constructor(t){super(t),this.radA=t?.radA??25,this.radB=t?.radB??25,this.color=t?.color??"black",this.outlineColor=t?.outlineColor??"black",this.outlineWidth=t?.outlineWidth??0,this.draw()}};var y=class extends a{sides;radius;color;outlineColor;outlineWidth;getPath(){let t=new Path2D,e=Math.PI*2/this.sides,s=this.toRadians(this.dir),r=this.radius;for(let o=0;o<this.sides;o++){let b=o*e-Math.PI/2+s,m=r*Math.cos(b),d=-r*Math.sin(b);o===0?t.moveTo(m,d):t.lineTo(m,d)}return t.closePath(),t}draw(t){let e=t?n:h;e.save();let s=this.x+i.width/2,r=-this.y+i.height/2;e.translate(s,r);let o=this.getPath();e.fillStyle=this.color,e.strokeStyle=this.outlineColor,e.lineWidth=this.outlineWidth,e.fill(o),e.stroke(o),e.restore()}setSides(t){this.sides=t,this.refresh()}setRadius(t){this.radius=t,this.refresh()}setColor(t){this.color=t,this.refresh()}constructor(t){super(t),this.sides=t?.sides??5,this.radius=t?.radius??50,this.color=t?.color??"black",this.outlineColor=t?.outlineColor??"black",this.outlineWidth=t?.outlineWidth??0,this.draw()}};var w=class extends a{drawing;size;color;getPath(){return new Path2D}draw(){}up(){this.drawing=!1}down(){this.drawing=!0}stamp(t){t.draw(!0)}ereaseAll(){n.clearRect(0,0,i.width,i.height)}dot(){n.fillStyle=this.color,n.fillRect(this.x-this.size/2+i.width/2,-this.y-this.size/2+i.height/2,this.size,this.size)}drawLine(t,e){n.beginPath(),n.moveTo(t+i.width/2,-e+i.height/2),n.lineTo(this.x+i.width/2,-this.y+i.height/2),n.lineWidth=this.size,n.strokeStyle=this.color,n.stroke()}move(t){let e=this.x,s=this.y;this.x+=t*Math.sin(this.toRadians(this.dir)),this.y+=t*Math.cos(this.toRadians(this.dir)),this.drawing&&this.drawLine(e,s),this.refresh()}setX(t){let e=this.x,s=this.y;this.x=t,this.drawing&&this.drawLine(e,s),this.refresh()}setY(t){let e=this.x,s=this.y;this.y=t,this.drawing&&this.drawLine(e,s),this.refresh()}goTo(t,e){let s=this.x,r=this.y;this.x=t,this.y=e,this.drawing&&this.drawLine(s,r),this.refresh()}changeX(t){let e=this.x,s=this.y;this.x+=t,this.drawing&&this.drawLine(e,s),this.refresh()}changeY(t){let e=this.x,s=this.y;this.y+=t,this.drawing&&this.drawLine(e,s),this.refresh()}constructor(t){super(t),this.drawing=t?.drawing??!1,this.size=t?.size??5,this.color=t?.color??"black"}};var S=class extends a{content;color;fontFamily;fontSize;align;baseline;font;getPath(){let t=new Path2D;h.save(),h.font=this.font;let e=h.measureText(this.content),s=e.width,r=e.actualBoundingBoxAscent+e.actualBoundingBoxDescent;return h.restore(),t.rect(-s/2,-r/2,s,r),t}draw(t){let e=t?n:h;e.save();let s=this.x+i.width/2,r=-this.y+i.height/2;e.translate(s,r),e.rotate(this.toRadians(this.dir)),e.font=this.font,e.fillStyle=this.color,e.textAlign=this.align,e.textBaseline=this.baseline,e.fillText(this.content,0,0),e.restore()}setContent(t){this.content=t,this.refresh()}setColor(t){this.color=t,this.refresh()}setFontSize(t){this.fontSize=t,this.font=`${this.fontSize}px ${this.fontFamily}`,this.refresh()}setFontFamily(t){this.fontFamily=t,this.font=`${this.fontSize}px ${this.fontFamily}`,this.refresh()}setAlign(t){this.align=t,this.refresh()}setBaseline(t){this.baseline=t,this.refresh()}constructor(t){super(t),this.content=t?.content??"",this.color=t?.color??"black",this.fontFamily=t?.fontFamily??"Arial",this.fontSize=t?.fontSize??16,this.align=t?.align??"center",this.baseline=t?.baseline??"middle",this.font=`${this.fontSize}px ${this.fontFamily}`}};var v=class extends a{src;width;height;outlineColor;outlineWidth;img;getPath(){let t=new Path2D;return t.rect(-this.width/2,-this.height/2,this.width,this.height),t}draw(t){let e=t?n:h;e.save();let s=this.x+i.width/2,r=-this.y+i.height/2;e.translate(s,r),e.rotate(this.toRadians(this.dir)),e.strokeStyle=this.outlineColor,e.lineWidth=this.outlineWidth,e.drawImage(this.img,0,0,this.img.width,this.img.height,-this.width/2,-this.height/2,this.width,this.height),e.stroke(this.getPath()),e.restore()}setSrc(t){this.src=t,this.refresh()}setWidth(t){this.width=t,this.refresh()}setHeight(t){this.height=t,this.refresh()}constructor(t){super(t),this.src=t?.src??"",this.img=new Image,this.img.src=this.src,this.width=t?.width??this.img.width,this.height=t?.height??this.img.height,this.outlineColor=t?.outlineColor??"black",this.outlineWidth=t?.outlineWidth??0}};var R={Engine:p,Sprite:a,Rectangle:f,Oval:x,RegularPolygon:y,Pen:w,Text:S,ImageSprite:v,setScale:M,setAspectRatio:P,canvas:i,ctx:h},at=R;export{p as Engine,v as ImageSprite,x as Oval,w as Pen,f as Rectangle,y as RegularPolygon,a as Sprite,S as Text,i as canvas,h as ctx,at as default,P as setAspectRatio,M as setScale};
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/canvas.ts","../src/Sprite.ts","../src/Engine.ts","../src/sprites/Rectangle.ts","../src/sprites/Oval.ts","../src/sprites/RegularPolygon.ts","../src/sprites/Pen.ts","../src/sprites/Text.ts","../src/sprites/ImageSprite.ts","../src/index.ts"],"sourcesContent":["export const canvas = document.getElementById('game-window') as HTMLCanvasElement;\r\nexport const ctx = canvas.getContext('2d')!;\r\n\r\nexport const penCanvas = document.createElement('canvas');\r\nexport const penCtx = penCanvas.getContext('2d')!;\r\npenCanvas.id = 'pen-canvas';\r\n\r\nlet ratio: number = 16 / 9;\r\nlet scale: number;\r\n\r\nexport function setScale(newScale: number) {\r\n scale = newScale;\r\n\r\n canvas.width = ratio * scale;\r\n canvas.height = scale;\r\n\r\n penCanvas.width = ratio * scale;\r\n penCanvas.height = scale;\r\n}\r\n\r\nexport function setAspectRatio(newAspectRatio: number) {\r\n ratio = newAspectRatio;\r\n\r\n canvas.width = ratio * scale;\r\n canvas.height = scale;\r\n\r\n penCanvas.width = ratio * scale;\r\n penCanvas.height = scale;\r\n}\r\n\r\ncanvas.parentElement?.insertBefore(penCanvas, canvas);\r\n\r\nsetScale(500);","import Engine from './Engine.ts';\r\n\r\nexport interface SpriteOptions {\r\n x?: number;\r\n y?: number;\r\n dir?: number;\r\n scene?: string;\r\n hidden?: boolean;\r\n layer?: number;\r\n};\r\n\r\nexport default abstract class Sprite {\r\n\r\n public x: number;\r\n public y: number;\r\n public dir: number;\r\n public scene: string;\r\n public hidden: boolean;\r\n public layer: number;\r\n\r\n // Rendering\r\n\r\n public abstract getPath(): Path2D;\r\n public abstract draw(stamping?: boolean): void;\r\n\r\n protected refresh() {\r\n Engine.init().refresh();\r\n }\r\n\r\n constructor(options?: SpriteOptions) {\r\n this.x = options?.x ?? 0;\r\n this.y = options?.y ?? 0;\r\n this.dir = options?.dir ?? 0;\r\n this.scene = options?.scene ?? 'main';\r\n this.hidden = options?.hidden ?? false;\r\n this.layer = options?.layer ?? 0;\r\n Engine.init().addSprite(this);\r\n }\r\n\r\n // Helpers\r\n\r\n protected toRadians(deg: number) {\r\n return deg * Math.PI / 180;\r\n }\r\n\r\n protected toDegrees(rad: number) {\r\n return rad * 180 / Math.PI;\r\n }\r\n\r\n // Methods\r\n\r\n // Motion\r\n public move(steps: number) {\r\n this.x += steps * Math.sin(this.toRadians(this.dir));\r\n this.y += steps * Math.cos(this.toRadians(this.dir));\r\n this.refresh();\r\n }\r\n\r\n public turn(deg: number) {\r\n this.dir += deg;\r\n this.refresh();\r\n }\r\n\r\n public point(dir: number) {\r\n this.dir = dir;\r\n this.refresh();\r\n }\r\n\r\n public setX(x: number) {\r\n this.x = x;\r\n this.refresh();\r\n }\r\n\r\n public setY(y: number) {\r\n this.y = y;\r\n this.refresh();\r\n }\r\n\r\n public goTo(x: number, y: number) {\r\n this.x = x;\r\n this.y = y;\r\n this.refresh();\r\n }\r\n\r\n public changeX(dX: number) {\r\n this.x += dX;\r\n this.refresh();\r\n }\r\n\r\n public changeY(dY: number) {\r\n this.y += dY;\r\n this.refresh();\r\n }\r\n\r\n // Looks\r\n\r\n public show() {\r\n this.hidden = false;\r\n this.refresh();\r\n }\r\n\r\n public hide() {\r\n this.hidden = true;\r\n this.refresh();\r\n }\r\n\r\n public goToLayer(layer: number) {\r\n this.layer = layer;\r\n this.refresh();\r\n }\r\n\r\n public changeLayer(dL: number) {\r\n this.layer += dL;\r\n this.refresh();\r\n }\r\n}","import { canvas, ctx } from './canvas.ts';\r\nimport Sprite from './Sprite.ts';\r\n\r\ntype GameLoop = (() => any) | (() => Promise<any>);\r\n\r\ntype SceneMap = {\r\n [scene: string]: {\r\n sprites: Sprite[];\r\n loop: GameLoop | null;\r\n };\r\n};\r\n\r\nexport default class Engine {\r\n\r\n private static instance: Engine;\r\n\r\n private loopRunning: boolean = false;\r\n public gameLoop: GameLoop | null = null;\r\n public maxFPS: number = 24;\r\n\r\n public sounds: HTMLAudioElement[] = [];\r\n\r\n public mouseX: number = 0;\r\n public mouseY: number = 0;\r\n\r\n public mouseDown: boolean = false;\r\n\r\n public currentScene: string = 'main';\r\n public sceneMap: SceneMap = {};\r\n\r\n // Singleton initialization\r\n\r\n public static init() {\r\n if (!this.instance)\r\n this.instance = new Engine();\r\n\r\n return this.instance;\r\n }\r\n\r\n // Change the scene\r\n\r\n public changeScene(scene: string) {\r\n if (!this.sceneMap[scene])\r\n this.sceneMap[scene] = { sprites: [], loop: null };\r\n\r\n this.loopRunning = false;\r\n this.currentScene = scene;\r\n this.gameLoop = this.sceneMap[scene].loop;\r\n this.setMaxFramesPerSecond(this.maxFPS); // Update the interval function\r\n }\r\n\r\n // Set a loop\r\n\r\n public setLoop(scene: string, loop: GameLoop) {\r\n if (!this.sceneMap[scene]) {\r\n this.sceneMap[scene] = { sprites: [], loop };\r\n if (scene === this.currentScene)\r\n this.changeScene(scene);\r\n return;\r\n }\r\n\r\n this.sceneMap[scene].loop = loop;\r\n if (scene === this.currentScene)\r\n this.changeScene(scene);\r\n }\r\n\r\n // Internal\r\n\r\n public addSprite(sprite: Sprite) {\r\n const { scene, layer } = sprite;\r\n\r\n if (!this.sceneMap[scene]) {\r\n this.sceneMap[scene] = { sprites: [sprite], loop: null };\r\n return;\r\n }\r\n\r\n let targetIndex = this.sceneMap[scene].sprites.findIndex(s => s.layer > layer);\r\n if (targetIndex === -1) {\r\n this.sceneMap[scene].sprites.push(sprite);\r\n return;\r\n }\r\n\r\n this.sceneMap[scene].sprites.splice(targetIndex, 0, sprite);\r\n }\r\n\r\n public async setMaxFramesPerSecond(maxFPS: number) {\r\n this.maxFPS = maxFPS;\r\n \r\n let loop = this.gameLoop;\r\n if (!loop) return;\r\n\r\n this.loopRunning = true;\r\n\r\n while (this.loopRunning) {\r\n await loop();\r\n await this.wait(1000 / maxFPS);\r\n }\r\n }\r\n\r\n public refresh() {\r\n ctx.clearRect(0, 0, canvas.width, canvas.height);\r\n this.sceneMap[this.currentScene]?.sprites.forEach(sprite => {\r\n if (!sprite.hidden)\r\n sprite.draw();\r\n });\r\n }\r\n\r\n // Wait function\r\n\r\n public async wait(ms: number): Promise<void> {\r\n return new Promise(resolve => setTimeout(resolve, ms));\r\n }\r\n\r\n // Mouse events\r\n\r\n public isHovered(sprite: Sprite) {\r\n const { mouseX, mouseY } = this;\r\n\r\n const canvasMouseX = mouseX + canvas.width / 2;\r\n const canvasMouseY = canvas.height / 2 - mouseY;\r\n\r\n // Mouse relative to sprite center\r\n const localX = canvasMouseX - (sprite.x + canvas.width / 2);\r\n const localY = canvasMouseY - (canvas.height / 2 - sprite.y);\r\n\r\n // Rotate mouse point by -dir to align with the path's local coordinates\r\n const angle = -this.toRadians(sprite.dir);\r\n const rotatedX = localX * Math.cos(angle) - localY * Math.sin(angle);\r\n const rotatedY = localX * Math.sin(angle) + localY * Math.cos(angle);\r\n\r\n return ctx.isPointInPath(sprite.getPath(), rotatedX, rotatedY);\r\n }\r\n\r\n // Sound\r\n\r\n public playSound(src: string) {\r\n const audio = new Audio(src);\r\n this.sounds.push(audio);\r\n\r\n audio.play();\r\n\r\n return audio;\r\n }\r\n\r\n public stopSound(sound: HTMLAudioElement) {\r\n sound.pause();\r\n sound.currentTime = 0;\r\n this.sounds = this.sounds.filter(s => s !== sound);\r\n }\r\n\r\n public stopAllSounds() {\r\n this.sounds.forEach(sound => {\r\n sound.pause();\r\n sound.currentTime = 0;\r\n });\r\n this.sounds = [];\r\n }\r\n\r\n // Math\r\n\r\n public pickRandom(min: number, max: number) {\r\n if (min > max)\r\n [min, max] = [max, min];\r\n return Math.floor(Math.random() * (max - min + 1) + min);\r\n }\r\n\r\n // Trigonometric functions\r\n public sin(deg: number) {\r\n return Math.sin(this.toRadians(deg));\r\n }\r\n\r\n public cos(deg: number) {\r\n return Math.cos(this.toRadians(deg));\r\n }\r\n\r\n public tan(deg: number) {\r\n return Math.tan(this.toRadians(deg));\r\n }\r\n\r\n public csc(deg: number) {\r\n return 1 / Math.sin(this.toRadians(deg));\r\n }\r\n\r\n public sec(deg: number) {\r\n return 1 / Math.cos(this.toRadians(deg));\r\n }\r\n\r\n public cot(deg: number) {\r\n return 1 / Math.tan(this.toRadians(deg));\r\n }\r\n\r\n // Inverse Trigonometric functions\r\n public asin(val: number) {\r\n return this.toDegrees(Math.asin(val));\r\n }\r\n\r\n public acos(val: number) {\r\n return this.toDegrees(Math.acos(val));\r\n }\r\n\r\n public acsc(val: number) {\r\n return this.toDegrees(Math.asin(1 / val));\r\n }\r\n\r\n public asec(val: number) {\r\n return this.toDegrees(Math.acos(1 / val));\r\n }\r\n\r\n // Helpers\r\n\r\n public toRadians(deg: number) {\r\n return deg * Math.PI / 180;\r\n }\r\n\r\n public toDegrees(rad: number) {\r\n return rad * 180 / Math.PI;\r\n }\r\n\r\n // Private constructor\r\n\r\n private constructor() {\r\n void this.setMaxFramesPerSecond(24);\r\n\r\n canvas.addEventListener('mousemove', e => {\r\n this.mouseX = e.clientX - canvas.offsetLeft - canvas.width / 2;\r\n this.mouseY = -(e.clientY - canvas.offsetTop - canvas.height / 2);\r\n });\r\n canvas.addEventListener('mousedown', e => {\r\n this.mouseDown = true;\r\n });\r\n canvas.addEventListener('mouseup', e => {\r\n this.mouseDown = false;\r\n });\r\n }\r\n}","import Sprite, { type SpriteOptions } from '../Sprite.ts';\r\nimport { ctx, canvas, penCtx } from '../canvas.ts';\r\n\r\nexport interface RectangleOptions extends SpriteOptions {\r\n width?: number;\r\n height?: number;\r\n color?: string;\r\n outlineColor?: string;\r\n outlineWidth?: number;\r\n};\r\n\r\nexport default class Rectangle extends Sprite {\r\n\r\n public width: number;\r\n public height: number;\r\n public color: string;\r\n public outlineColor: string;\r\n public outlineWidth: number;\r\n\r\n public getPath(): Path2D {\r\n const path = new Path2D();\r\n\r\n path.rect(\r\n -this.width / 2,\r\n -this.height / 2,\r\n this.width,\r\n this.height\r\n );\r\n\r\n return path;\r\n }\r\n\r\n public draw(stamping?: boolean): void {\r\n const c = stamping ? penCtx : ctx;\r\n\r\n c.save();\r\n\r\n const cX = this.x + canvas.width / 2;\r\n const cY = -this.y + canvas.height / 2;\r\n c.translate(cX, cY);\r\n\r\n c.rotate(this.toRadians(this.dir));\r\n\r\n const path = this.getPath();\r\n\r\n c.fillStyle = this.color;\r\n c.strokeStyle = this.outlineColor;\r\n c.lineWidth = this.outlineWidth;\r\n c.fill(path)\r\n c.stroke(path);\r\n\r\n c.restore();\r\n }\r\n\r\n public setWidth(width: number) {\r\n this.width = width;\r\n this.refresh();\r\n }\r\n\r\n public setHeight(height: number) {\r\n this.height = height;\r\n this.refresh();\r\n }\r\n\r\n public setColor(color: string) {\r\n this.color = color;\r\n this.refresh();\r\n }\r\n\r\n constructor(options?: RectangleOptions) {\r\n super(options);\r\n this.width = options?.width ?? 50;\r\n this.height = options?.height ?? 50;\r\n this.color = options?.color ?? 'black';\r\n this.outlineColor = options?.outlineColor ?? 'black';\r\n this.outlineWidth = options?.outlineWidth ?? 0;\r\n this.draw();\r\n }\r\n\r\n}","import Sprite, { type SpriteOptions } from '../Sprite.ts';\r\nimport { canvas, ctx, penCtx } from '../canvas.ts';\r\n\r\nexport interface OvalOptions extends SpriteOptions {\r\n radA?: number;\r\n radB?: number;\r\n color?: string;\r\n outlineColor?: string;\r\n outlineWidth?: number;\r\n};\r\n\r\nexport default class Oval extends Sprite {\r\n\r\n public radA: number;\r\n public radB: number;\r\n public color: string;\r\n public outlineColor: string;\r\n public outlineWidth: number;\r\n\r\n public getPath(): Path2D {\r\n const path = new Path2D();\r\n\r\n path.ellipse(\r\n 0, 0,\r\n this.radA,\r\n this.radB,\r\n 0, 0,\r\n Math.PI * 2\r\n );\r\n\r\n return path;\r\n }\r\n\r\n public draw(stamping?: boolean): void {\r\n const c = stamping ? penCtx : ctx;\r\n \r\n c.save();\r\n\r\n const cX = this.x + canvas.width / 2;\r\n const cY = -this.y + canvas.height / 2;\r\n c.translate(cX, cY);\r\n\r\n c.rotate(this.toRadians(this.dir));\r\n\r\n const path = this.getPath();\r\n\r\n c.fillStyle = this.color;\r\n c.strokeStyle = this.outlineColor;\r\n c.lineWidth = this.outlineWidth;\r\n c.fill(path)\r\n c.stroke(path);\r\n\r\n c.restore();\r\n }\r\n\r\n public setRadA(radA: number) {\r\n this.radA = radA;\r\n this.refresh();\r\n }\r\n\r\n public setRadB(radB: number) {\r\n this.radB = radB;\r\n this.refresh();\r\n }\r\n\r\n public setColor(color: string) {\r\n this.color = color;\r\n this.refresh();\r\n }\r\n\r\n constructor(options?: OvalOptions) {\r\n super(options);\r\n this.radA = options?.radA ?? 25;\r\n this.radB = options?.radB ?? 25;\r\n this.color = options?.color ?? 'black';\r\n this.outlineColor = options?.outlineColor ?? 'black';\r\n this.outlineWidth = options?.outlineWidth ?? 0;\r\n this.draw();\r\n }\r\n\r\n}","import { canvas, ctx, penCtx } from '../canvas.ts';\r\nimport Sprite, { type SpriteOptions } from '../Sprite.ts';\r\n\r\nexport interface RegularPolygonOptions extends SpriteOptions {\r\n sides?: number;\r\n radius?: number;\r\n color?: string;\r\n outlineColor?: string;\r\n outlineWidth?: number;\r\n}\r\n\r\nexport default class RegularPolygon extends Sprite {\r\n\r\n public sides: number;\r\n public radius: number;\r\n public color: string;\r\n public outlineColor: string;\r\n public outlineWidth: number;\r\n\r\n public getPath(): Path2D {\r\n const path = new Path2D();\r\n\r\n const step = (Math.PI * 2) / this.sides;\r\n const rotation = this.toRadians(this.dir);\r\n const r = this.radius;\r\n\r\n for (let i = 0; i < this.sides; i++) {\r\n const theta = i * step - Math.PI / 2 + rotation;\r\n const px = r * Math.cos(theta);\r\n const py = -r * Math.sin(theta);\r\n\r\n if (i === 0) path.moveTo(px, py);\r\n else path.lineTo(px, py);\r\n }\r\n\r\n path.closePath();\r\n\r\n return path;\r\n }\r\n\r\n public draw(stamping?: boolean) {\r\n const c = stamping ? penCtx : ctx;\r\n\r\n c.save();\r\n\r\n const cX = this.x + canvas.width / 2;\r\n const cY = -this.y + canvas.height / 2;\r\n\r\n c.translate(cX, cY);\r\n\r\n const path = this.getPath();\r\n\r\n c.fillStyle = this.color;\r\n c.strokeStyle = this.outlineColor;\r\n c.lineWidth = this.outlineWidth;\r\n c.fill(path)\r\n c.stroke(path);\r\n\r\n c.restore();\r\n }\r\n\r\n public setSides(sides: number) {\r\n this.sides = sides;\r\n this.refresh();\r\n }\r\n\r\n public setRadius(radius: number) {\r\n this.radius = radius;\r\n this.refresh();\r\n }\r\n\r\n public setColor(color: string) {\r\n this.color = color;\r\n this.refresh();\r\n }\r\n\r\n constructor(options?: RegularPolygonOptions) {\r\n super(options);\r\n this.sides = options?.sides ?? 5;\r\n this.radius = options?.radius ?? 50;\r\n this.color = options?.color ?? 'black';\r\n this.outlineColor = options?.outlineColor ?? 'black';\r\n this.outlineWidth = options?.outlineWidth ?? 0;\r\n this.draw();\r\n }\r\n\r\n}","import { canvas, penCtx } from '../canvas.ts';\r\nimport Sprite, { type SpriteOptions } from '../Sprite.ts';\r\n\r\nexport interface PenOptions extends SpriteOptions {\r\n drawing?: boolean;\r\n size?: number;\r\n color?: string;\r\n}\r\n\r\nexport default class Pen extends Sprite {\r\n\r\n public drawing: boolean;\r\n public size: number;\r\n public color: string;\r\n\r\n public getPath(): Path2D {\r\n return new Path2D();\r\n }\r\n public draw() {}\r\n\r\n public up() {\r\n this.drawing = false;\r\n }\r\n\r\n public down() {\r\n this.drawing = true;\r\n }\r\n\r\n public stamp(sprite: Sprite) {\r\n sprite.draw(true);\r\n }\r\n\r\n public ereaseAll() {\r\n penCtx.clearRect(0, 0, canvas.width, canvas.height);\r\n }\r\n\r\n public dot() {\r\n penCtx.fillStyle = this.color;\r\n penCtx.fillRect(\r\n this.x - this.size / 2 + canvas.width / 2,\r\n -this.y - this.size / 2 + canvas.height / 2,\r\n this.size,\r\n this.size\r\n );\r\n }\r\n\r\n private drawLine(lastX: number, lastY: number) {\r\n penCtx.beginPath();\r\n\r\n penCtx.moveTo(lastX + canvas.width / 2, -lastY + canvas.height / 2);\r\n penCtx.lineTo(this.x + canvas.width / 2, -this.y + canvas.height / 2);\r\n\r\n penCtx.lineWidth = this.size;\r\n penCtx.strokeStyle = this.color;\r\n penCtx.stroke();\r\n }\r\n\r\n // Overriding methods to include drawing\r\n\r\n public override move(steps: number) {\r\n const lastX = this.x;\r\n const lastY = this.y;\r\n\r\n this.x += steps * Math.sin(this.toRadians(this.dir));\r\n this.y += steps * Math.cos(this.toRadians(this.dir));\r\n if (this.drawing)\r\n this.drawLine(lastX, lastY);\r\n this.refresh();\r\n }\r\n\r\n public override setX(x: number) {\r\n const lastX = this.x;\r\n const lastY = this.y;\r\n\r\n this.x = x;\r\n if (this.drawing)\r\n this.drawLine(lastX, lastY);\r\n this.refresh();\r\n }\r\n\r\n public override setY(y: number) {\r\n const lastX = this.x;\r\n const lastY = this.y;\r\n\r\n this.y = y;\r\n if (this.drawing)\r\n this.drawLine(lastX, lastY);\r\n this.refresh();\r\n }\r\n\r\n public override goTo(x: number, y: number) {\r\n const lastX = this.x;\r\n const lastY = this.y;\r\n\r\n this.x = x;\r\n this.y = y;\r\n if (this.drawing)\r\n this.drawLine(lastX, lastY);\r\n this.refresh();\r\n }\r\n\r\n public override changeX(dX: number) {\r\n const lastX = this.x;\r\n const lastY = this.y;\r\n\r\n this.x += dX;\r\n if (this.drawing)\r\n this.drawLine(lastX, lastY);\r\n this.refresh();\r\n }\r\n\r\n public override changeY(dY: number) {\r\n const lastX = this.x;\r\n const lastY = this.y;\r\n\r\n this.y += dY;\r\n if (this.drawing)\r\n this.drawLine(lastX, lastY);\r\n this.refresh();\r\n }\r\n\r\n // Constructor\r\n\r\n constructor(options?: PenOptions) {\r\n super(options);\r\n this.drawing = options?.drawing ?? false;\r\n this.size = options?.size ?? 5;\r\n this.color = options?.color ?? 'black';\r\n }\r\n\r\n}","import { canvas, ctx, penCtx } from '../canvas.ts';\r\nimport Sprite, { type SpriteOptions } from '../Sprite.ts';\r\n\r\nexport type CanvasTextAlign =\r\n | 'left'\r\n | 'right'\r\n | 'center'\r\n | 'start'\r\n | 'end';\r\n\r\nexport type CanvasTextBaseline =\r\n | 'top'\r\n | 'hanging'\r\n | 'middle'\r\n | 'alphabetic'\r\n | 'ideographic'\r\n | 'bottom';\r\n\r\nexport interface TextOptions extends SpriteOptions {\r\n content?: string;\r\n color?: string;\r\n fontFamily?: string;\r\n fontSize?: number;\r\n align?: CanvasTextAlign;\r\n baseline?: CanvasTextBaseline;\r\n}\r\n\r\nexport default class Text extends Sprite {\r\n\r\n public content: string;\r\n public color: string;\r\n public fontFamily: string;\r\n public fontSize: number;\r\n public align: CanvasTextAlign;\r\n public baseline: CanvasTextBaseline;\r\n\r\n private font: string;\r\n\r\n public getPath(): Path2D {\r\n const path = new Path2D();\r\n\r\n ctx.save();\r\n \r\n ctx.font = this.font;\r\n\r\n const metrics = ctx.measureText(this.content);\r\n const width = metrics.width;\r\n const height = metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent;\r\n\r\n ctx.restore();\r\n\r\n path.rect(-width / 2, -height / 2, width, height);\r\n\r\n return path\r\n }\r\n\r\n public draw(stamping?: boolean) {\r\n const c = stamping ? penCtx : ctx;\r\n\r\n c.save();\r\n\r\n const cX = this.x + canvas.width / 2;\r\n const cY = -this.y + canvas.height / 2;\r\n c.translate(cX, cY);\r\n\r\n c.rotate(this.toRadians(this.dir));\r\n\r\n c.font = this.font;\r\n c.fillStyle = this.color;\r\n c.textAlign = this.align;\r\n c.textBaseline = this.baseline;\r\n\r\n c.fillText(this.content, 0, 0);\r\n\r\n c.restore();\r\n }\r\n\r\n // Methods\r\n\r\n public setContent(content: string) {\r\n this.content = content;\r\n this.refresh();\r\n }\r\n\r\n public setColor(color: string) {\r\n this.color = color;\r\n this.refresh();\r\n }\r\n\r\n public setFontSize(fontSize: number) {\r\n this.fontSize = fontSize;\r\n this.font = `${this.fontSize}px ${this.fontFamily}`;\r\n this.refresh();\r\n }\r\n\r\n public setFontFamily(fontFamily: string) {\r\n this.fontFamily = fontFamily;\r\n this.font = `${this.fontSize}px ${this.fontFamily}`;\r\n this.refresh();\r\n }\r\n\r\n public setAlign(align: CanvasTextAlign) {\r\n this.align = align;\r\n this.refresh();\r\n }\r\n\r\n public setBaseline(baseline: CanvasTextBaseline) {\r\n this.baseline = baseline;\r\n this.refresh();\r\n }\r\n\r\n // Constructor\r\n\r\n constructor(options?: TextOptions) {\r\n super(options);\r\n\r\n this.content = options?.content ?? '';\r\n this.color = options?.color ?? 'black';\r\n this.fontFamily = options?.fontFamily ?? 'Arial';\r\n this.fontSize = options?.fontSize ?? 16;\r\n this.align = options?.align ?? 'center';\r\n this.baseline = options?.baseline ?? 'middle';\r\n\r\n this.font = `${this.fontSize}px ${this.fontFamily}`;\r\n }\r\n}","import { canvas, ctx, penCtx } from '../canvas.ts';\r\nimport Sprite, { type SpriteOptions } from '../Sprite.ts';\r\n\r\nexport interface ImageSpriteOptions extends SpriteOptions {\r\n src?: string;\r\n width: number;\r\n height: number;\r\n outlineColor?: string;\r\n outlineWidth?: number;\r\n};\r\n\r\nexport default class ImageSprite extends Sprite {\r\n\r\n public src: string;\r\n public width: number;\r\n public height: number;\r\n public outlineColor: string;\r\n public outlineWidth: number;\r\n\r\n protected img: HTMLImageElement;\r\n\r\n public getPath(): Path2D {\r\n const path = new Path2D();\r\n\r\n path.rect(\r\n -this.width / 2,\r\n -this.height / 2,\r\n this.width,\r\n this.height\r\n );\r\n\r\n return path;\r\n }\r\n\r\n public draw(stamping?: boolean) {\r\n const c = stamping ? penCtx : ctx;\r\n\r\n c.save();\r\n\r\n const cX = this.x + canvas.width / 2;\r\n const cY = -this.y + canvas.height / 2;\r\n c.translate(cX, cY);\r\n\r\n c.rotate(this.toRadians(this.dir));\r\n\r\n c.strokeStyle = this.outlineColor;\r\n c.lineWidth = this.outlineWidth;\r\n c.drawImage(\r\n this.img,\r\n 0, 0,\r\n this.img.width,\r\n this.img.height,\r\n -this.width / 2,\r\n -this.height / 2,\r\n this.width, this.height\r\n );\r\n c.stroke(this.getPath());\r\n\r\n c.restore();\r\n }\r\n\r\n // Methods\r\n\r\n public setSrc(src: string) {\r\n this.src = src;\r\n this.refresh();\r\n }\r\n\r\n public setWidth(width: number) {\r\n this.width = width;\r\n this.refresh();\r\n }\r\n\r\n public setHeight(height: number) {\r\n this.height = height;\r\n this.refresh();\r\n }\r\n\r\n // Constructor\r\n\r\n constructor(options?: ImageSpriteOptions) {\r\n super(options);\r\n\r\n this.src = options?.src ?? '';\r\n this.img = new Image();\r\n this.img.src = this.src;\r\n\r\n this.width = options?.width ?? this.img.width;\r\n this.height = options?.height ?? this.img.height;\r\n\r\n this.outlineColor = options?.outlineColor ?? 'black';\r\n this.outlineWidth = options?.outlineWidth ?? 0;\r\n }\r\n}","import Engine from './Engine.ts';\r\n\r\nimport Sprite, { type SpriteOptions } from './Sprite.ts';\r\nimport Rectangle, { type RectangleOptions } from './sprites/Rectangle.ts';\r\nimport Oval, { type OvalOptions } from './sprites/Oval.ts';\r\nimport RegularPolygon, { type RegularPolygonOptions } from './sprites/RegularPolygon.ts';\r\nimport Pen, { type PenOptions } from './sprites/Pen.ts';\r\nimport Text, { type TextOptions, type CanvasTextAlign, type CanvasTextBaseline } from './sprites/Text.ts';\r\nimport ImageSprite, { type ImageSpriteOptions } from './sprites/ImageSprite.ts';\r\n\r\nimport { setScale, setAspectRatio, canvas, ctx } from './canvas.ts';\r\n\r\nconst TScratch = {\r\n // Main\r\n Engine,\r\n Sprite,\r\n\r\n // Sprites\r\n Rectangle,\r\n Oval,\r\n RegularPolygon,\r\n Pen,\r\n Text,\r\n ImageSprite,\r\n\r\n // Canvas\r\n setScale,\r\n setAspectRatio,\r\n canvas,\r\n ctx\r\n};\r\n\r\nexport default TScratch;\r\nexport {\r\n // Main\r\n Engine,\r\n Sprite,\r\n\r\n // Sprites\r\n Rectangle,\r\n Oval,\r\n RegularPolygon,\r\n Pen,\r\n Text,\r\n ImageSprite,\r\n\r\n // Options\r\n type SpriteOptions,\r\n type RectangleOptions,\r\n type OvalOptions,\r\n type RegularPolygonOptions,\r\n type PenOptions,\r\n type TextOptions,\r\n type ImageSpriteOptions,\r\n\r\n // Other types\r\n type CanvasTextAlign,\r\n type CanvasTextBaseline,\r\n \r\n // Canvas\r\n setScale,\r\n setAspectRatio,\r\n canvas,\r\n ctx\r\n};"],"mappings":"AAAO,IAAMA,EAAS,SAAS,eAAe,aAAa,EAC9CC,EAAMD,EAAO,WAAW,IAAI,EAE5BE,EAAY,SAAS,cAAc,QAAQ,EAC3CC,EAASD,EAAU,WAAW,IAAI,EAC/CA,EAAU,GAAK,aAEf,IAAIE,EAAgB,GAAK,EACrBC,EAEG,SAASC,EAASC,EAAkB,CACvCF,EAAQE,EAERP,EAAO,MAAQI,EAAQC,EACvBL,EAAO,OAASK,EAEhBH,EAAU,MAAQE,EAAQC,EAC1BH,EAAU,OAASG,CACvB,CAEO,SAASG,EAAeC,EAAwB,CACnDL,EAAQK,EAERT,EAAO,MAAQI,EAAQC,EACvBL,EAAO,OAASK,EAEhBH,EAAU,MAAQE,EAAQC,EAC1BH,EAAU,OAASG,CACvB,CAEAL,EAAO,eAAe,aAAaE,EAAWF,CAAM,EAEpDM,EAAS,GAAG,ECrBZ,IAA8BI,EAA9B,KAAqC,CAE1B,EACA,EACA,IACA,MACA,OACA,MAOG,SAAU,CAChBC,EAAO,KAAK,EAAE,QAAQ,CAC1B,CAEA,YAAYC,EAAyB,CACjC,KAAK,EAAIA,GAAS,GAAK,EACvB,KAAK,EAAIA,GAAS,GAAK,EACvB,KAAK,IAAMA,GAAS,KAAO,EAC3B,KAAK,MAAQA,GAAS,OAAS,OAC/B,KAAK,OAAS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B,CAC5B,IAAMC,EAAID,EAAWE,EAASC,EAE9BF,EAAE,KAAK,EAEP,IAAMG,EAAK,KAAK,EAAIC,EAAO,MAAQ,EAC7BC,EAAK,CAAC,KAAK,EAAID,EAAO,OAAS,EACrCJ,EAAE,UAAUG,EAAIE,CAAE,EAElBL,EAAE,OAAO,KAAK,UAAU,KAAK,GAAG,CAAC,EAEjCA,EAAE,YAAc,KAAK,aACrBA,EAAE,UAAY,KAAK,aACnBA,EAAE,UACE,KAAK,IACL,EAAG,EACH,KAAK,IAAI,MACT,KAAK,IAAI,OACT,CAAC,KAAK,MAAQ,EACd,CAAC,KAAK,OAAS,EACf,KAAK,MAAO,KAAK,MACrB,EACAA,EAAE,OAAO,KAAK,QAAQ,CAAC,EAEvBA,EAAE,QAAQ,CACd,CAIO,OAAOM,EAAa,CACvB,KAAK,IAAMA,EACX,KAAK,QAAQ,CACjB,CAEO,SAASC,EAAe,CAC3B,KAAK,MAAQA,EACb,KAAK,QAAQ,CACjB,CAEO,UAAUC,EAAgB,CAC7B,KAAK,OAASA,EACd,KAAK,QAAQ,CACjB,CAIA,YAAYC,EAA8B,CACtC,MAAMA,CAAO,EAEb,KAAK,IAAMA,GAAS,KAAO,GAC3B,KAAK,IAAM,IAAI,MACf,KAAK,IAAI,IAAM,KAAK,IAEpB,KAAK,MAAQA,GAAS,OAAS,KAAK,IAAI,MACxC,KAAK,OAASA,GAAS,QAAU,KAAK,IAAI,OAE1C,KAAK,aAAeA,GAAS,cAAgB,QAC7C,KAAK,aAAeA,GAAS,cAAgB,CACjD,CACJ,ECjFA,IAAMC,EAAW,CAEb,OAAAC,EACA,OAAAC,EAGA,UAAAC,EACA,KAAAC,EACA,eAAAC,EACA,IAAAC,EACA,KAAAC,EACA,YAAAC,EAGA,SAAAC,EACA,eAAAC,EACA,OAAAC,EACA,IAAAC,CACJ,EAEOC,GAAQb","names":["canvas","ctx","penCanvas","penCtx","ratio","scale","setScale","newScale","setAspectRatio","newAspectRatio","Sprite","Engine","options","deg","rad","steps","dir","x","y","dX","dY","layer","dL","Engine","_Engine","scene","loop","sprite","layer","targetIndex","s","maxFPS","ctx","canvas","ms","resolve","mouseX","mouseY","canvasMouseX","canvasMouseY","localX","localY","angle","rotatedX","rotatedY","src","audio","sound","min","max","deg","val","rad","e","Rectangle","Sprite","path","stamping","c","penCtx","ctx","cX","canvas","cY","width","height","color","options","Oval","Sprite","path","stamping","c","penCtx","ctx","cX","canvas","cY","radA","radB","color","options","RegularPolygon","Sprite","path","step","rotation","i","theta","px","py","stamping","c","penCtx","ctx","cX","canvas","cY","sides","radius","color","options","Pen","Sprite","sprite","penCtx","canvas","lastX","lastY","steps","x","y","dX","dY","options","Text","Sprite","path","ctx","metrics","width","height","stamping","c","penCtx","cX","canvas","cY","content","color","fontSize","fontFamily","align","baseline","options","ImageSprite","Sprite","path","stamping","c","penCtx","ctx","cX","canvas","cY","src","width","height","options","TScratch","Engine","Sprite","Rectangle","Oval","RegularPolygon","Pen","Text","ImageSprite","setScale","setAspectRatio","canvas","ctx","index_default"]}
1
+ {"version":3,"sources":["../src/canvas.ts","../src/Sprite.ts","../src/Engine.ts","../src/sprites/Rectangle.ts","../src/sprites/Oval.ts","../src/sprites/RegularPolygon.ts","../src/sprites/Pen.ts","../src/sprites/Text.ts","../src/sprites/ImageSprite.ts","../src/index.ts"],"sourcesContent":["export const canvas = document.getElementById('game-window') as HTMLCanvasElement;\r\nexport const ctx = canvas.getContext('2d')!;\r\n\r\nexport const penCanvas = document.createElement('canvas');\r\nexport const penCtx = penCanvas.getContext('2d')!;\r\npenCanvas.id = 'pen-canvas';\r\n\r\nlet ratio: number = 16 / 9;\r\nlet scale: number;\r\n\r\nexport function setScale(newScale: number) {\r\n scale = newScale;\r\n\r\n canvas.width = ratio * scale;\r\n canvas.height = scale;\r\n\r\n penCanvas.width = ratio * scale;\r\n penCanvas.height = scale;\r\n}\r\n\r\nexport function setAspectRatio(newAspectRatio: number) {\r\n ratio = newAspectRatio;\r\n\r\n canvas.width = ratio * scale;\r\n canvas.height = scale;\r\n\r\n penCanvas.width = ratio * scale;\r\n penCanvas.height = scale;\r\n}\r\n\r\ncanvas.parentElement?.insertBefore(penCanvas, canvas);\r\n\r\nsetScale(500);","import Engine from './Engine.ts';\r\n\r\nexport interface SpriteOptions {\r\n x?: number;\r\n y?: number;\r\n dir?: number;\r\n scene?: string;\r\n hidden?: boolean;\r\n layer?: number;\r\n};\r\n\r\nexport default abstract class Sprite {\r\n\r\n public x: number;\r\n public y: number;\r\n public dir: number;\r\n public scene: string;\r\n public hidden: boolean;\r\n public layer: number;\r\n\r\n // Rendering\r\n\r\n public abstract getPath(): Path2D;\r\n public abstract draw(stamping?: boolean): void;\r\n\r\n protected refresh() {\r\n Engine.init().refresh();\r\n }\r\n\r\n constructor(options?: SpriteOptions) {\r\n this.x = options?.x ?? 0;\r\n this.y = options?.y ?? 0;\r\n this.dir = options?.dir ?? 0;\r\n this.scene = options?.scene ?? 'main';\r\n this.hidden = options?.hidden ?? false;\r\n this.layer = options?.layer ?? 0;\r\n Engine.init().addSprite(this);\r\n }\r\n\r\n // Helpers\r\n\r\n protected toRadians(deg: number) {\r\n return deg * Math.PI / 180;\r\n }\r\n\r\n protected toDegrees(rad: number) {\r\n return rad * 180 / Math.PI;\r\n }\r\n\r\n // Methods\r\n\r\n // Motion\r\n public move(steps: number) {\r\n this.x += steps * Math.sin(this.toRadians(this.dir));\r\n this.y += steps * Math.cos(this.toRadians(this.dir));\r\n this.refresh();\r\n }\r\n\r\n public turn(deg: number) {\r\n this.dir += deg;\r\n this.refresh();\r\n }\r\n\r\n public point(dir: number) {\r\n this.dir = dir;\r\n this.refresh();\r\n }\r\n\r\n public setX(x: number) {\r\n this.x = x;\r\n this.refresh();\r\n }\r\n\r\n public setY(y: number) {\r\n this.y = y;\r\n this.refresh();\r\n }\r\n\r\n public goTo(x: number, y: number) {\r\n this.x = x;\r\n this.y = y;\r\n this.refresh();\r\n }\r\n\r\n public changeX(dX: number) {\r\n this.x += dX;\r\n this.refresh();\r\n }\r\n\r\n public changeY(dY: number) {\r\n this.y += dY;\r\n this.refresh();\r\n }\r\n\r\n // Looks\r\n\r\n public show() {\r\n this.hidden = false;\r\n this.refresh();\r\n }\r\n\r\n public hide() {\r\n this.hidden = true;\r\n this.refresh();\r\n }\r\n\r\n public goToLayer(layer: number) {\r\n this.layer = layer;\r\n this.refresh();\r\n }\r\n\r\n public changeLayer(dL: number) {\r\n this.layer += dL;\r\n this.refresh();\r\n }\r\n}","import { canvas, ctx, penCanvas } from './canvas.ts';\r\nimport Sprite from './Sprite.ts';\r\n\r\ntype GameLoop = (() => any) | (() => Promise<any>);\r\n\r\ntype SceneMap = {\r\n [scene: string]: {\r\n sprites: Sprite[];\r\n loop: GameLoop | null;\r\n };\r\n};\r\n\r\nexport default class Engine {\r\n\r\n private static instance: Engine;\r\n\r\n private loopRunning: boolean = false;\r\n public gameLoop: GameLoop | null = null;\r\n public maxFPS: number = 24;\r\n\r\n public sounds: HTMLAudioElement[] = [];\r\n\r\n public mouseX: number = 0;\r\n public mouseY: number = 0;\r\n\r\n public mouseDown: boolean = false;\r\n\r\n public currentScene: string = 'main';\r\n public sceneMap: SceneMap = {};\r\n\r\n // Singleton initialization\r\n\r\n public static init() {\r\n if (!this.instance)\r\n this.instance = new Engine();\r\n\r\n return this.instance;\r\n }\r\n\r\n // Change the scene\r\n\r\n public changeScene(scene: string) {\r\n if (!this.sceneMap[scene])\r\n this.sceneMap[scene] = { sprites: [], loop: null };\r\n\r\n this.loopRunning = false;\r\n this.currentScene = scene;\r\n this.gameLoop = this.sceneMap[scene].loop;\r\n this.setMaxFramesPerSecond(this.maxFPS); // Update the interval function\r\n }\r\n\r\n // Set a loop\r\n\r\n public setLoop(scene: string, loop: GameLoop) {\r\n if (!this.sceneMap[scene]) {\r\n this.sceneMap[scene] = { sprites: [], loop };\r\n if (scene === this.currentScene)\r\n this.changeScene(scene);\r\n return;\r\n }\r\n\r\n this.sceneMap[scene].loop = loop;\r\n if (scene === this.currentScene)\r\n this.changeScene(scene);\r\n }\r\n\r\n // Internal\r\n\r\n public addSprite(sprite: Sprite) {\r\n const { scene, layer } = sprite;\r\n\r\n if (!this.sceneMap[scene]) {\r\n this.sceneMap[scene] = { sprites: [sprite], loop: null };\r\n return;\r\n }\r\n\r\n let targetIndex = this.sceneMap[scene].sprites.findIndex(s => s.layer > layer);\r\n if (targetIndex === -1) {\r\n this.sceneMap[scene].sprites.push(sprite);\r\n return;\r\n }\r\n\r\n this.sceneMap[scene].sprites.splice(targetIndex, 0, sprite);\r\n }\r\n\r\n public removeSprite(sprite: Sprite) {\r\n const { scene } = sprite;\r\n\r\n if (!this.sceneMap[scene]) return;\r\n\r\n this.sceneMap[scene].sprites = this.sceneMap[scene].sprites.filter(s => s !== sprite);\r\n }\r\n\r\n public async setMaxFramesPerSecond(maxFPS: number) {\r\n this.maxFPS = maxFPS;\r\n \r\n let loop = this.gameLoop;\r\n if (!loop) return;\r\n\r\n this.loopRunning = true;\r\n\r\n while (this.loopRunning) {\r\n await loop();\r\n await this.wait(1000 / maxFPS);\r\n }\r\n }\r\n\r\n public refresh() {\r\n ctx.clearRect(0, 0, canvas.width, canvas.height);\r\n this.sceneMap[this.currentScene]?.sprites.forEach(sprite => {\r\n if (!sprite.hidden)\r\n sprite.draw();\r\n });\r\n }\r\n\r\n // Wait function\r\n\r\n public async wait(ms: number): Promise<void> {\r\n return new Promise(resolve => setTimeout(resolve, ms));\r\n }\r\n\r\n // Mouse events\r\n\r\n public isHovered(sprite: Sprite) {\r\n const { mouseX, mouseY } = this;\r\n\r\n const canvasMouseX = mouseX + canvas.width / 2;\r\n const canvasMouseY = canvas.height / 2 - mouseY;\r\n\r\n // Mouse relative to sprite center\r\n const localX = canvasMouseX - (sprite.x + canvas.width / 2);\r\n const localY = canvasMouseY - (canvas.height / 2 - sprite.y);\r\n\r\n // Rotate mouse point by -dir to align with the path's local coordinates\r\n const angle = -this.toRadians(sprite.dir);\r\n const rotatedX = localX * Math.cos(angle) - localY * Math.sin(angle);\r\n const rotatedY = localX * Math.sin(angle) + localY * Math.cos(angle);\r\n\r\n return ctx.isPointInPath(sprite.getPath(), rotatedX, rotatedY);\r\n }\r\n\r\n // Sound\r\n\r\n public playSound(src: string) {\r\n const audio = new Audio(src);\r\n this.sounds.push(audio);\r\n\r\n audio.play();\r\n\r\n return audio;\r\n }\r\n\r\n public stopSound(sound: HTMLAudioElement) {\r\n sound.pause();\r\n sound.currentTime = 0;\r\n this.sounds = this.sounds.filter(s => s !== sound);\r\n }\r\n\r\n public stopAllSounds() {\r\n this.sounds.forEach(sound => {\r\n sound.pause();\r\n sound.currentTime = 0;\r\n });\r\n this.sounds = [];\r\n }\r\n\r\n // Math\r\n\r\n public pickRandom(min: number, max: number) {\r\n if (min > max)\r\n [min, max] = [max, min];\r\n return Math.floor(Math.random() * (max - min + 1) + min);\r\n }\r\n\r\n // Trigonometric functions\r\n public sin(deg: number) {\r\n return Math.sin(this.toRadians(deg));\r\n }\r\n\r\n public cos(deg: number) {\r\n return Math.cos(this.toRadians(deg));\r\n }\r\n\r\n public tan(deg: number) {\r\n return Math.tan(this.toRadians(deg));\r\n }\r\n\r\n public csc(deg: number) {\r\n return 1 / Math.sin(this.toRadians(deg));\r\n }\r\n\r\n public sec(deg: number) {\r\n return 1 / Math.cos(this.toRadians(deg));\r\n }\r\n\r\n public cot(deg: number) {\r\n return 1 / Math.tan(this.toRadians(deg));\r\n }\r\n\r\n // Inverse Trigonometric functions\r\n public asin(val: number) {\r\n return this.toDegrees(Math.asin(val));\r\n }\r\n\r\n public acos(val: number) {\r\n return this.toDegrees(Math.acos(val));\r\n }\r\n\r\n public acsc(val: number) {\r\n return this.toDegrees(Math.asin(1 / val));\r\n }\r\n\r\n public asec(val: number) {\r\n return this.toDegrees(Math.acos(1 / val));\r\n }\r\n\r\n // Helpers\r\n\r\n public toRadians(deg: number) {\r\n return deg * Math.PI / 180;\r\n }\r\n\r\n public toDegrees(rad: number) {\r\n return rad * 180 / Math.PI;\r\n }\r\n\r\n // Private constructor\r\n\r\n private constructor() {\r\n void this.setMaxFramesPerSecond(24);\r\n\r\n penCanvas.addEventListener('mousemove', e => {\r\n this.mouseX = e.clientX - penCanvas.offsetLeft - penCanvas.width / 2;\r\n this.mouseY = -(e.clientY - penCanvas.offsetTop - penCanvas.height / 2);\r\n });\r\n penCanvas.addEventListener('mousedown', e => {\r\n this.mouseDown = true;\r\n });\r\n penCanvas.addEventListener('mouseup', e => {\r\n this.mouseDown = false;\r\n });\r\n }\r\n}","import Sprite, { type SpriteOptions } from '../Sprite.ts';\r\nimport { ctx, canvas, penCtx } from '../canvas.ts';\r\n\r\nexport interface RectangleOptions extends SpriteOptions {\r\n width?: number;\r\n height?: number;\r\n color?: string;\r\n outlineColor?: string;\r\n outlineWidth?: number;\r\n};\r\n\r\nexport default class Rectangle extends Sprite {\r\n\r\n public width: number;\r\n public height: number;\r\n public color: string;\r\n public outlineColor: string;\r\n public outlineWidth: number;\r\n\r\n public getPath(): Path2D {\r\n const path = new Path2D();\r\n\r\n path.rect(\r\n -this.width / 2,\r\n -this.height / 2,\r\n this.width,\r\n this.height\r\n );\r\n\r\n return path;\r\n }\r\n\r\n public draw(stamping?: boolean): void {\r\n const c = stamping ? penCtx : ctx;\r\n\r\n c.save();\r\n\r\n const cX = this.x + canvas.width / 2;\r\n const cY = -this.y + canvas.height / 2;\r\n c.translate(cX, cY);\r\n\r\n c.rotate(this.toRadians(this.dir));\r\n\r\n const path = this.getPath();\r\n\r\n c.fillStyle = this.color;\r\n c.strokeStyle = this.outlineColor;\r\n c.lineWidth = this.outlineWidth;\r\n c.fill(path)\r\n c.stroke(path);\r\n\r\n c.restore();\r\n }\r\n\r\n public setWidth(width: number) {\r\n this.width = width;\r\n this.refresh();\r\n }\r\n\r\n public setHeight(height: number) {\r\n this.height = height;\r\n this.refresh();\r\n }\r\n\r\n public setColor(color: string) {\r\n this.color = color;\r\n this.refresh();\r\n }\r\n\r\n constructor(options?: RectangleOptions) {\r\n super(options);\r\n this.width = options?.width ?? 50;\r\n this.height = options?.height ?? 50;\r\n this.color = options?.color ?? 'black';\r\n this.outlineColor = options?.outlineColor ?? 'black';\r\n this.outlineWidth = options?.outlineWidth ?? 0;\r\n this.draw();\r\n }\r\n\r\n}","import Sprite, { type SpriteOptions } from '../Sprite.ts';\r\nimport { canvas, ctx, penCtx } from '../canvas.ts';\r\n\r\nexport interface OvalOptions extends SpriteOptions {\r\n radA?: number;\r\n radB?: number;\r\n color?: string;\r\n outlineColor?: string;\r\n outlineWidth?: number;\r\n};\r\n\r\nexport default class Oval extends Sprite {\r\n\r\n public radA: number;\r\n public radB: number;\r\n public color: string;\r\n public outlineColor: string;\r\n public outlineWidth: number;\r\n\r\n public getPath(): Path2D {\r\n const path = new Path2D();\r\n\r\n path.ellipse(\r\n 0, 0,\r\n this.radA,\r\n this.radB,\r\n 0, 0,\r\n Math.PI * 2\r\n );\r\n\r\n return path;\r\n }\r\n\r\n public draw(stamping?: boolean): void {\r\n const c = stamping ? penCtx : ctx;\r\n \r\n c.save();\r\n\r\n const cX = this.x + canvas.width / 2;\r\n const cY = -this.y + canvas.height / 2;\r\n c.translate(cX, cY);\r\n\r\n c.rotate(this.toRadians(this.dir));\r\n\r\n const path = this.getPath();\r\n\r\n c.fillStyle = this.color;\r\n c.strokeStyle = this.outlineColor;\r\n c.lineWidth = this.outlineWidth;\r\n c.fill(path)\r\n c.stroke(path);\r\n\r\n c.restore();\r\n }\r\n\r\n public setRadA(radA: number) {\r\n this.radA = radA;\r\n this.refresh();\r\n }\r\n\r\n public setRadB(radB: number) {\r\n this.radB = radB;\r\n this.refresh();\r\n }\r\n\r\n public setColor(color: string) {\r\n this.color = color;\r\n this.refresh();\r\n }\r\n\r\n constructor(options?: OvalOptions) {\r\n super(options);\r\n this.radA = options?.radA ?? 25;\r\n this.radB = options?.radB ?? 25;\r\n this.color = options?.color ?? 'black';\r\n this.outlineColor = options?.outlineColor ?? 'black';\r\n this.outlineWidth = options?.outlineWidth ?? 0;\r\n this.draw();\r\n }\r\n\r\n}","import { canvas, ctx, penCtx } from '../canvas.ts';\r\nimport Sprite, { type SpriteOptions } from '../Sprite.ts';\r\n\r\nexport interface RegularPolygonOptions extends SpriteOptions {\r\n sides?: number;\r\n radius?: number;\r\n color?: string;\r\n outlineColor?: string;\r\n outlineWidth?: number;\r\n}\r\n\r\nexport default class RegularPolygon extends Sprite {\r\n\r\n public sides: number;\r\n public radius: number;\r\n public color: string;\r\n public outlineColor: string;\r\n public outlineWidth: number;\r\n\r\n public getPath(): Path2D {\r\n const path = new Path2D();\r\n\r\n const step = (Math.PI * 2) / this.sides;\r\n const rotation = this.toRadians(this.dir);\r\n const r = this.radius;\r\n\r\n for (let i = 0; i < this.sides; i++) {\r\n const theta = i * step - Math.PI / 2 + rotation;\r\n const px = r * Math.cos(theta);\r\n const py = -r * Math.sin(theta);\r\n\r\n if (i === 0) path.moveTo(px, py);\r\n else path.lineTo(px, py);\r\n }\r\n\r\n path.closePath();\r\n\r\n return path;\r\n }\r\n\r\n public draw(stamping?: boolean) {\r\n const c = stamping ? penCtx : ctx;\r\n\r\n c.save();\r\n\r\n const cX = this.x + canvas.width / 2;\r\n const cY = -this.y + canvas.height / 2;\r\n\r\n c.translate(cX, cY);\r\n\r\n const path = this.getPath();\r\n\r\n c.fillStyle = this.color;\r\n c.strokeStyle = this.outlineColor;\r\n c.lineWidth = this.outlineWidth;\r\n c.fill(path)\r\n c.stroke(path);\r\n\r\n c.restore();\r\n }\r\n\r\n public setSides(sides: number) {\r\n this.sides = sides;\r\n this.refresh();\r\n }\r\n\r\n public setRadius(radius: number) {\r\n this.radius = radius;\r\n this.refresh();\r\n }\r\n\r\n public setColor(color: string) {\r\n this.color = color;\r\n this.refresh();\r\n }\r\n\r\n constructor(options?: RegularPolygonOptions) {\r\n super(options);\r\n this.sides = options?.sides ?? 5;\r\n this.radius = options?.radius ?? 50;\r\n this.color = options?.color ?? 'black';\r\n this.outlineColor = options?.outlineColor ?? 'black';\r\n this.outlineWidth = options?.outlineWidth ?? 0;\r\n this.draw();\r\n }\r\n\r\n}","import { canvas, penCtx } from '../canvas.ts';\r\nimport Sprite, { type SpriteOptions } from '../Sprite.ts';\r\n\r\nexport interface PenOptions extends SpriteOptions {\r\n drawing?: boolean;\r\n size?: number;\r\n color?: string;\r\n}\r\n\r\nexport default class Pen extends Sprite {\r\n\r\n public drawing: boolean;\r\n public size: number;\r\n public color: string;\r\n\r\n public getPath(): Path2D {\r\n return new Path2D();\r\n }\r\n public draw() {}\r\n\r\n public up() {\r\n this.drawing = false;\r\n }\r\n\r\n public down() {\r\n this.drawing = true;\r\n }\r\n\r\n public stamp(sprite: Sprite) {\r\n sprite.draw(true);\r\n }\r\n\r\n public ereaseAll() {\r\n penCtx.clearRect(0, 0, canvas.width, canvas.height);\r\n }\r\n\r\n public dot() {\r\n penCtx.fillStyle = this.color;\r\n penCtx.fillRect(\r\n this.x - this.size / 2 + canvas.width / 2,\r\n -this.y - this.size / 2 + canvas.height / 2,\r\n this.size,\r\n this.size\r\n );\r\n }\r\n\r\n private drawLine(lastX: number, lastY: number) {\r\n penCtx.beginPath();\r\n\r\n penCtx.moveTo(lastX + canvas.width / 2, -lastY + canvas.height / 2);\r\n penCtx.lineTo(this.x + canvas.width / 2, -this.y + canvas.height / 2);\r\n\r\n penCtx.lineWidth = this.size;\r\n penCtx.strokeStyle = this.color;\r\n penCtx.stroke();\r\n }\r\n\r\n // Overriding methods to include drawing\r\n\r\n public override move(steps: number) {\r\n const lastX = this.x;\r\n const lastY = this.y;\r\n\r\n this.x += steps * Math.sin(this.toRadians(this.dir));\r\n this.y += steps * Math.cos(this.toRadians(this.dir));\r\n if (this.drawing)\r\n this.drawLine(lastX, lastY);\r\n this.refresh();\r\n }\r\n\r\n public override setX(x: number) {\r\n const lastX = this.x;\r\n const lastY = this.y;\r\n\r\n this.x = x;\r\n if (this.drawing)\r\n this.drawLine(lastX, lastY);\r\n this.refresh();\r\n }\r\n\r\n public override setY(y: number) {\r\n const lastX = this.x;\r\n const lastY = this.y;\r\n\r\n this.y = y;\r\n if (this.drawing)\r\n this.drawLine(lastX, lastY);\r\n this.refresh();\r\n }\r\n\r\n public override goTo(x: number, y: number) {\r\n const lastX = this.x;\r\n const lastY = this.y;\r\n\r\n this.x = x;\r\n this.y = y;\r\n if (this.drawing)\r\n this.drawLine(lastX, lastY);\r\n this.refresh();\r\n }\r\n\r\n public override changeX(dX: number) {\r\n const lastX = this.x;\r\n const lastY = this.y;\r\n\r\n this.x += dX;\r\n if (this.drawing)\r\n this.drawLine(lastX, lastY);\r\n this.refresh();\r\n }\r\n\r\n public override changeY(dY: number) {\r\n const lastX = this.x;\r\n const lastY = this.y;\r\n\r\n this.y += dY;\r\n if (this.drawing)\r\n this.drawLine(lastX, lastY);\r\n this.refresh();\r\n }\r\n\r\n // Constructor\r\n\r\n constructor(options?: PenOptions) {\r\n super(options);\r\n this.drawing = options?.drawing ?? false;\r\n this.size = options?.size ?? 5;\r\n this.color = options?.color ?? 'black';\r\n }\r\n\r\n}","import { canvas, ctx, penCtx } from '../canvas.ts';\r\nimport Sprite, { type SpriteOptions } from '../Sprite.ts';\r\n\r\nexport type CanvasTextAlign =\r\n | 'left'\r\n | 'right'\r\n | 'center'\r\n | 'start'\r\n | 'end';\r\n\r\nexport type CanvasTextBaseline =\r\n | 'top'\r\n | 'hanging'\r\n | 'middle'\r\n | 'alphabetic'\r\n | 'ideographic'\r\n | 'bottom';\r\n\r\nexport interface TextOptions extends SpriteOptions {\r\n content?: string;\r\n color?: string;\r\n fontFamily?: string;\r\n fontSize?: number;\r\n align?: CanvasTextAlign;\r\n baseline?: CanvasTextBaseline;\r\n}\r\n\r\nexport default class Text extends Sprite {\r\n\r\n public content: string;\r\n public color: string;\r\n public fontFamily: string;\r\n public fontSize: number;\r\n public align: CanvasTextAlign;\r\n public baseline: CanvasTextBaseline;\r\n\r\n private font: string;\r\n\r\n public getPath(): Path2D {\r\n const path = new Path2D();\r\n\r\n ctx.save();\r\n \r\n ctx.font = this.font;\r\n\r\n const metrics = ctx.measureText(this.content);\r\n const width = metrics.width;\r\n const height = metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent;\r\n\r\n ctx.restore();\r\n\r\n path.rect(-width / 2, -height / 2, width, height);\r\n\r\n return path\r\n }\r\n\r\n public draw(stamping?: boolean) {\r\n const c = stamping ? penCtx : ctx;\r\n\r\n c.save();\r\n\r\n const cX = this.x + canvas.width / 2;\r\n const cY = -this.y + canvas.height / 2;\r\n c.translate(cX, cY);\r\n\r\n c.rotate(this.toRadians(this.dir));\r\n\r\n c.font = this.font;\r\n c.fillStyle = this.color;\r\n c.textAlign = this.align;\r\n c.textBaseline = this.baseline;\r\n\r\n c.fillText(this.content, 0, 0);\r\n\r\n c.restore();\r\n }\r\n\r\n // Methods\r\n\r\n public setContent(content: string) {\r\n this.content = content;\r\n this.refresh();\r\n }\r\n\r\n public setColor(color: string) {\r\n this.color = color;\r\n this.refresh();\r\n }\r\n\r\n public setFontSize(fontSize: number) {\r\n this.fontSize = fontSize;\r\n this.font = `${this.fontSize}px ${this.fontFamily}`;\r\n this.refresh();\r\n }\r\n\r\n public setFontFamily(fontFamily: string) {\r\n this.fontFamily = fontFamily;\r\n this.font = `${this.fontSize}px ${this.fontFamily}`;\r\n this.refresh();\r\n }\r\n\r\n public setAlign(align: CanvasTextAlign) {\r\n this.align = align;\r\n this.refresh();\r\n }\r\n\r\n public setBaseline(baseline: CanvasTextBaseline) {\r\n this.baseline = baseline;\r\n this.refresh();\r\n }\r\n\r\n // Constructor\r\n\r\n constructor(options?: TextOptions) {\r\n super(options);\r\n\r\n this.content = options?.content ?? '';\r\n this.color = options?.color ?? 'black';\r\n this.fontFamily = options?.fontFamily ?? 'Arial';\r\n this.fontSize = options?.fontSize ?? 16;\r\n this.align = options?.align ?? 'center';\r\n this.baseline = options?.baseline ?? 'middle';\r\n\r\n this.font = `${this.fontSize}px ${this.fontFamily}`;\r\n }\r\n}","import { canvas, ctx, penCtx } from '../canvas.ts';\r\nimport Sprite, { type SpriteOptions } from '../Sprite.ts';\r\n\r\nexport interface ImageSpriteOptions extends SpriteOptions {\r\n src?: string;\r\n width: number;\r\n height: number;\r\n outlineColor?: string;\r\n outlineWidth?: number;\r\n};\r\n\r\nexport default class ImageSprite extends Sprite {\r\n\r\n public src: string;\r\n public width: number;\r\n public height: number;\r\n public outlineColor: string;\r\n public outlineWidth: number;\r\n\r\n protected img: HTMLImageElement;\r\n\r\n public getPath(): Path2D {\r\n const path = new Path2D();\r\n\r\n path.rect(\r\n -this.width / 2,\r\n -this.height / 2,\r\n this.width,\r\n this.height\r\n );\r\n\r\n return path;\r\n }\r\n\r\n public draw(stamping?: boolean) {\r\n const c = stamping ? penCtx : ctx;\r\n\r\n c.save();\r\n\r\n const cX = this.x + canvas.width / 2;\r\n const cY = -this.y + canvas.height / 2;\r\n c.translate(cX, cY);\r\n\r\n c.rotate(this.toRadians(this.dir));\r\n\r\n c.strokeStyle = this.outlineColor;\r\n c.lineWidth = this.outlineWidth;\r\n c.drawImage(\r\n this.img,\r\n 0, 0,\r\n this.img.width,\r\n this.img.height,\r\n -this.width / 2,\r\n -this.height / 2,\r\n this.width, this.height\r\n );\r\n c.stroke(this.getPath());\r\n\r\n c.restore();\r\n }\r\n\r\n // Methods\r\n\r\n public setSrc(src: string) {\r\n this.src = src;\r\n this.refresh();\r\n }\r\n\r\n public setWidth(width: number) {\r\n this.width = width;\r\n this.refresh();\r\n }\r\n\r\n public setHeight(height: number) {\r\n this.height = height;\r\n this.refresh();\r\n }\r\n\r\n // Constructor\r\n\r\n constructor(options?: ImageSpriteOptions) {\r\n super(options);\r\n\r\n this.src = options?.src ?? '';\r\n this.img = new Image();\r\n this.img.src = this.src;\r\n\r\n this.width = options?.width ?? this.img.width;\r\n this.height = options?.height ?? this.img.height;\r\n\r\n this.outlineColor = options?.outlineColor ?? 'black';\r\n this.outlineWidth = options?.outlineWidth ?? 0;\r\n }\r\n}","import Engine from './Engine.ts';\r\n\r\nimport Sprite, { type SpriteOptions } from './Sprite.ts';\r\nimport Rectangle, { type RectangleOptions } from './sprites/Rectangle.ts';\r\nimport Oval, { type OvalOptions } from './sprites/Oval.ts';\r\nimport RegularPolygon, { type RegularPolygonOptions } from './sprites/RegularPolygon.ts';\r\nimport Pen, { type PenOptions } from './sprites/Pen.ts';\r\nimport Text, { type TextOptions, type CanvasTextAlign, type CanvasTextBaseline } from './sprites/Text.ts';\r\nimport ImageSprite, { type ImageSpriteOptions } from './sprites/ImageSprite.ts';\r\n\r\nimport { setScale, setAspectRatio, canvas, ctx } from './canvas.ts';\r\n\r\nconst TScratch = {\r\n // Main\r\n Engine,\r\n Sprite,\r\n\r\n // Sprites\r\n Rectangle,\r\n Oval,\r\n RegularPolygon,\r\n Pen,\r\n Text,\r\n ImageSprite,\r\n\r\n // Canvas\r\n setScale,\r\n setAspectRatio,\r\n canvas,\r\n ctx\r\n};\r\n\r\nexport default TScratch;\r\nexport {\r\n // Main\r\n Engine,\r\n Sprite,\r\n\r\n // Sprites\r\n Rectangle,\r\n Oval,\r\n RegularPolygon,\r\n Pen,\r\n Text,\r\n ImageSprite,\r\n\r\n // Options\r\n type SpriteOptions,\r\n type RectangleOptions,\r\n type OvalOptions,\r\n type RegularPolygonOptions,\r\n type PenOptions,\r\n type TextOptions,\r\n type ImageSpriteOptions,\r\n\r\n // Other types\r\n type CanvasTextAlign,\r\n type CanvasTextBaseline,\r\n \r\n // Canvas\r\n setScale,\r\n setAspectRatio,\r\n canvas,\r\n ctx\r\n};"],"mappings":"AAAO,IAAMA,EAAS,SAAS,eAAe,aAAa,EAC9CC,EAAMD,EAAO,WAAW,IAAI,EAE5BE,EAAY,SAAS,cAAc,QAAQ,EAC3CC,EAASD,EAAU,WAAW,IAAI,EAC/CA,EAAU,GAAK,aAEf,IAAIE,EAAgB,GAAK,EACrBC,EAEG,SAASC,EAASC,EAAkB,CACvCF,EAAQE,EAERP,EAAO,MAAQI,EAAQC,EACvBL,EA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AAK,IAAMA,EACX,KAAK,QAAQ,CACjB,CAEO,SAASC,EAAe,CAC3B,KAAK,MAAQA,EACb,KAAK,QAAQ,CACjB,CAEO,UAAUC,EAAgB,CAC7B,KAAK,OAASA,EACd,KAAK,QAAQ,CACjB,CAIA,YAAYC,EAA8B,CACtC,MAAMA,CAAO,EAEb,KAAK,IAAMA,GAAS,KAAO,GAC3B,KAAK,IAAM,IAAI,MACf,KAAK,IAAI,IAAM,KAAK,IAEpB,KAAK,MAAQA,GAAS,OAAS,KAAK,IAAI,MACxC,KAAK,OAASA,GAAS,QAAU,KAAK,IAAI,OAE1C,KAAK,aAAeA,GAAS,cAAgB,QAC7C,KAAK,aAAeA,GAAS,cAAgB,CACjD,CACJ,ECjFA,IAAMC,EAAW,CAEb,OAAAC,EACA,OAAAC,EAGA,UAAAC,EACA,KAAAC,EACA,eAAAC,EACA,IAAAC,EACA,KAAAC,EACA,YAAAC,EAGA,SAAAC,EACA,eAAAC,EACA,OAAAC,EACA,IAAAC,CACJ,EAEOC,GAAQb","names":["canvas","ctx","penCanvas","penCtx","ratio","scale","setScale","newScale","setAspectRatio","newAspectRatio","Sprite","Engine","options","deg","rad","steps","dir","x","y","dX","dY","layer","dL","Engine","_Engine","scene","loop","sprite","layer","targetIndex","s","maxFPS","ctx","canvas","ms","resolve","mouseX","mouseY","canvasMouseX","canvasMouseY","localX","localY","angle","rotatedX","rotatedY","src","audio","sound","min","max","deg","val","rad","penCanvas","e","Rectangle","Sprite","path","stamping","c","penCtx","ctx","cX","canvas","cY","width","height","color","options","Oval","Sprite","path","stamping","c","penCtx","ctx","cX","canvas","cY","radA","radB","color","options","RegularPolygon","Sprite","path","step","rotation","i","theta","px","py","stamping","c","penCtx","ctx","cX","canvas","cY","sides","radius","color","options","Pen","Sprite","sprite","penCtx","canvas","lastX","lastY","steps","x","y","dX","dY","options","Text","Sprite","path","ctx","metrics","width","height","stamping","c","penCtx","cX","canvas","cY","content","color","fontSize","fontFamily","align","baseline","options","ImageSprite","Sprite","path","stamping","c","penCtx","ctx","cX","canvas","cY","src","width","height","options","TScratch","Engine","Sprite","Rectangle","Oval","RegularPolygon","Pen","Text","ImageSprite","setScale","setAspectRatio","canvas","ctx","index_default"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tscratch",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "A Scratch-style game engine for TypeScript.",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",