angry-pixel 2.1.5 → 2.1.7
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/LICENSE +7 -7
- package/README.md +194 -194
- package/lib/index.cjs.js +1 -1
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +73 -2
- package/lib/index.esm.js +1 -1
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/package.json +28 -28
- package/lib/broadPhaseWorker.cjs.js +0 -2
- package/lib/broadPhaseWorker.cjs.js.map +0 -1
- package/lib/broadPhaseWorker.esm.js +0 -2
- package/lib/broadPhaseWorker.esm.js.map +0 -1
- package/lib/broadPhaseWorker.js +0 -2
- package/lib/broadPhaseWorker.js.map +0 -1
package/LICENSE
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Copyright 2024 Mauro Manuel Cristy
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
-
|
|
5
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
-
|
|
7
|
-
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
1
|
+
Copyright 2024 Mauro Manuel Cristy
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,194 +1,194 @@
|
|
|
1
|
-

|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/angry-pixel)
|
|
4
|
-
[](https://github.com/angry-pixel-studio/angry-pixel-engine/blob/master/LICENSE)
|
|
5
|
-
[](https://docs.angrypixel.gg)
|
|
6
|
-
[](https://github.com/angry-pixel-studio/angry-pixel-engine/actions?query=workflow%3AContinuous)
|
|
7
|
-
|
|
8
|
-
## What is Angry Pixel Engine?
|
|
9
|
-
|
|
10
|
-
Angry Pixel Engine is a 2D game engine for browser written in Typescript.
|
|
11
|
-
|
|
12
|
-
Main features:
|
|
13
|
-
|
|
14
|
-
- [Entity-Component-System](https://github.com/SanderMertens/ecs-faq) based architecture
|
|
15
|
-
- WebGL rendering
|
|
16
|
-
- Sprite-based graphics and frame-by-frame animations
|
|
17
|
-
- Text rendering with support for web-safe and imported fonts
|
|
18
|
-
- Basic 2D lightning system
|
|
19
|
-
- Polygonal collision detection and physical response based on speed and acceleration.
|
|
20
|
-
- Keyboard, mouse, gamepad, and touchscreen input support
|
|
21
|
-
- Ability to create desktop or mobile games using frameworks like [Electron.js](https://www.electronjs.org/) or [React Native](https://reactnative.dev/)
|
|
22
|
-
- Built-in tilemap and tileset components, with support for orthogonal maps exported from [Tiled](https://www.mapeditor.org/)
|
|
23
|
-
- Dependency Injection
|
|
24
|
-
|
|
25
|
-
## Getting Started
|
|
26
|
-
|
|
27
|
-
Let's create a scene where the Angry Pixel logo bounces off the edges of the screen in a DVD screensaver fashion.
|
|
28
|
-
|
|
29
|
-
### Installation
|
|
30
|
-
|
|
31
|
-
```bash
|
|
32
|
-
npm i angry-pixel
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
or
|
|
36
|
-
|
|
37
|
-
```bash
|
|
38
|
-
yarn add angry-pixel
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
### Initialize
|
|
42
|
-
|
|
43
|
-
First we create an instance of the `Game` class:
|
|
44
|
-
|
|
45
|
-
```typescript
|
|
46
|
-
import { Game, GameConfig } from "angry-pixel";
|
|
47
|
-
|
|
48
|
-
const config: GameConfig = {
|
|
49
|
-
containerNode: document.querySelector("#app"),
|
|
50
|
-
width: 1920,
|
|
51
|
-
height: 1080,
|
|
52
|
-
canvasColor: "#00D9D9",
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const game = new Game(config);
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
### Create a Scene
|
|
59
|
-
|
|
60
|
-
Then we will create the `MainScene` class, which extends the `Scene` base class. This class represents a scene in our game, and has three main functions:
|
|
61
|
-
|
|
62
|
-
- To load assets.
|
|
63
|
-
- To create the initial entities.
|
|
64
|
-
- To know which are the necessary systems.
|
|
65
|
-
|
|
66
|
-
For the moment we only implement the function loadAssets to load an image that we will use later:
|
|
67
|
-
|
|
68
|
-
```typescript
|
|
69
|
-
import { Scene } from "angry-pixel";
|
|
70
|
-
|
|
71
|
-
class MainScene extends Scene {
|
|
72
|
-
// within this method we load the assets
|
|
73
|
-
loadAssets(): void {
|
|
74
|
-
this.assetManager.loadImage("logo.png");
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
And we add this scene to our game:
|
|
80
|
-
|
|
81
|
-
```typescript
|
|
82
|
-
// arguments: the scene class, the scene name, opening scene = true
|
|
83
|
-
game.addScene(MainScene, "MainScene", true);
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
### Create a Component
|
|
87
|
-
|
|
88
|
-
Then we will create the `MoveAndBounce` component which has the necessary attributes to define the movement of our entity.
|
|
89
|
-
|
|
90
|
-
```typescript
|
|
91
|
-
import { Vector2 } from "angry-pixel";
|
|
92
|
-
|
|
93
|
-
class MoveAndBounce {
|
|
94
|
-
boundaries: number[] = [476, -476, 896, -896]; // top, bottom, left, right
|
|
95
|
-
direction: Vector2 = new Vector2(1, 1); // the direction in wich the entity will move
|
|
96
|
-
speed: number = 200; // pixels per second
|
|
97
|
-
}
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
### Create a System
|
|
101
|
-
|
|
102
|
-
Once we have created our component, we will need a system that executes the business logic. Extending the base class `GameSystem`, we will create our `MoveAndBounceSystem`, which, using the `EntityManager`, obtains all the entities that have the `MoveAndBounce` component, and executes the business logic necessary for the entity to move by bouncing on the edges of the screen:
|
|
103
|
-
|
|
104
|
-
```typescript
|
|
105
|
-
import { GameSystem, Transform } from "angry-pixel";
|
|
106
|
-
|
|
107
|
-
class MoveAndBounceSystem extends GameSystem {
|
|
108
|
-
onUpdate(): void {
|
|
109
|
-
this.entityManager.search(MoveAndBounce).forEach(({ component, entity }) => {
|
|
110
|
-
const transform = this.entityManager.getComponent(entity, Transform);
|
|
111
|
-
const { boundaries, direction, speed } = component;
|
|
112
|
-
|
|
113
|
-
if (transform.position.y >= boundaries[0] || transform.position.y <= boundaries[1]) {
|
|
114
|
-
direction.y *= -1;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (transform.position.x >= boundaries[2] || transform.position.x <= boundaries[3]) {
|
|
118
|
-
direction.x *= -1;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
transform.position.x += direction.x * speed * this.timeManager.deltaTime;
|
|
122
|
-
transform.position.y += direction.y * speed * this.timeManager.deltaTime;
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
Once the system is created, we can add it to the scene
|
|
129
|
-
|
|
130
|
-
```typescript
|
|
131
|
-
import { Scene } from "angry-pixel";
|
|
132
|
-
|
|
133
|
-
class MainScene extends Scene {
|
|
134
|
-
loadAssets(): void {
|
|
135
|
-
this.assetManager.loadImage("logo.png");
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// within this method we register the systems of the scene
|
|
139
|
-
registerSystems(): void {
|
|
140
|
-
this.addSystem(MoveAndBounceSystem);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
### Create the entities
|
|
146
|
-
|
|
147
|
-
Finally, we need to create two entities, one that represents our logo, to which we want to apply the behavior of moving and bouncing, and another one that represents the camera of our game. For this we will use the `EntityManager`, specifically the `createEntity` method. This method accepts an array of components, the components can be concrete instances (this is useful when it is necessary to pass parameters by constructor) or classes (if it is not necessary to pass parameters by constructor, we can pass only the class).
|
|
148
|
-
|
|
149
|
-
```typescript
|
|
150
|
-
import { Camera, Scene, SpriteRenderer, Transform } from "angry-pixel";
|
|
151
|
-
|
|
152
|
-
class MainScene extends Scene {
|
|
153
|
-
loadAssets(): void {
|
|
154
|
-
this.assetManager.loadImage("logo.png");
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
registerSystems(): void {
|
|
158
|
-
this.addSystem(MoveAndBounceSystem);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// within this method we create the entities
|
|
162
|
-
createEntities(): void {
|
|
163
|
-
// camera
|
|
164
|
-
this.entityManager.createEntity([new Transform(), new Camera({ layers: ["Logo"] })]);
|
|
165
|
-
|
|
166
|
-
// logo
|
|
167
|
-
this.entityManager.createEntity([
|
|
168
|
-
new Transform(),
|
|
169
|
-
new MoveAndBounce(),
|
|
170
|
-
new SpriteRenderer({
|
|
171
|
-
layer: "Logo",
|
|
172
|
-
image: this.assetManager.getImage("logo.png"),
|
|
173
|
-
}),
|
|
174
|
-
]);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
### Run the game
|
|
180
|
-
|
|
181
|
-
Now we can start the game:
|
|
182
|
-
|
|
183
|
-
```typescript
|
|
184
|
-
game.run();
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
### Check this example live
|
|
188
|
-
|
|
189
|
-
🎮 [https://angrypixel.gg/angry-pixel-logo-bounce](https://angrypixel.gg/angry-pixel-logo-bounce)
|
|
190
|
-
|
|
191
|
-
## DOCS
|
|
192
|
-
|
|
193
|
-
🔎 [Documentation](https://docs.angrypixel.gg)\
|
|
194
|
-
⚙️ [Api Docs](https://api-docs.angrypixel.gg)
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/angry-pixel)
|
|
4
|
+
[](https://github.com/angry-pixel-studio/angry-pixel-engine/blob/master/LICENSE)
|
|
5
|
+
[](https://docs.angrypixel.gg)
|
|
6
|
+
[](https://github.com/angry-pixel-studio/angry-pixel-engine/actions?query=workflow%3AContinuous)
|
|
7
|
+
|
|
8
|
+
## What is Angry Pixel Engine?
|
|
9
|
+
|
|
10
|
+
Angry Pixel Engine is a 2D game engine for browser written in Typescript.
|
|
11
|
+
|
|
12
|
+
Main features:
|
|
13
|
+
|
|
14
|
+
- [Entity-Component-System](https://github.com/SanderMertens/ecs-faq) based architecture
|
|
15
|
+
- WebGL rendering
|
|
16
|
+
- Sprite-based graphics and frame-by-frame animations
|
|
17
|
+
- Text rendering with support for web-safe and imported fonts
|
|
18
|
+
- Basic 2D lightning system
|
|
19
|
+
- Polygonal collision detection and physical response based on speed and acceleration.
|
|
20
|
+
- Keyboard, mouse, gamepad, and touchscreen input support
|
|
21
|
+
- Ability to create desktop or mobile games using frameworks like [Electron.js](https://www.electronjs.org/) or [React Native](https://reactnative.dev/)
|
|
22
|
+
- Built-in tilemap and tileset components, with support for orthogonal maps exported from [Tiled](https://www.mapeditor.org/)
|
|
23
|
+
- Dependency Injection
|
|
24
|
+
|
|
25
|
+
## Getting Started
|
|
26
|
+
|
|
27
|
+
Let's create a scene where the Angry Pixel logo bounces off the edges of the screen in a DVD screensaver fashion.
|
|
28
|
+
|
|
29
|
+
### Installation
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm i angry-pixel
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
or
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
yarn add angry-pixel
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Initialize
|
|
42
|
+
|
|
43
|
+
First we create an instance of the `Game` class:
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import { Game, GameConfig } from "angry-pixel";
|
|
47
|
+
|
|
48
|
+
const config: GameConfig = {
|
|
49
|
+
containerNode: document.querySelector("#app"),
|
|
50
|
+
width: 1920,
|
|
51
|
+
height: 1080,
|
|
52
|
+
canvasColor: "#00D9D9",
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const game = new Game(config);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Create a Scene
|
|
59
|
+
|
|
60
|
+
Then we will create the `MainScene` class, which extends the `Scene` base class. This class represents a scene in our game, and has three main functions:
|
|
61
|
+
|
|
62
|
+
- To load assets.
|
|
63
|
+
- To create the initial entities.
|
|
64
|
+
- To know which are the necessary systems.
|
|
65
|
+
|
|
66
|
+
For the moment we only implement the function loadAssets to load an image that we will use later:
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { Scene } from "angry-pixel";
|
|
70
|
+
|
|
71
|
+
class MainScene extends Scene {
|
|
72
|
+
// within this method we load the assets
|
|
73
|
+
loadAssets(): void {
|
|
74
|
+
this.assetManager.loadImage("logo.png");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
And we add this scene to our game:
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
// arguments: the scene class, the scene name, opening scene = true
|
|
83
|
+
game.addScene(MainScene, "MainScene", true);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Create a Component
|
|
87
|
+
|
|
88
|
+
Then we will create the `MoveAndBounce` component which has the necessary attributes to define the movement of our entity.
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
import { Vector2 } from "angry-pixel";
|
|
92
|
+
|
|
93
|
+
class MoveAndBounce {
|
|
94
|
+
boundaries: number[] = [476, -476, 896, -896]; // top, bottom, left, right
|
|
95
|
+
direction: Vector2 = new Vector2(1, 1); // the direction in wich the entity will move
|
|
96
|
+
speed: number = 200; // pixels per second
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Create a System
|
|
101
|
+
|
|
102
|
+
Once we have created our component, we will need a system that executes the business logic. Extending the base class `GameSystem`, we will create our `MoveAndBounceSystem`, which, using the `EntityManager`, obtains all the entities that have the `MoveAndBounce` component, and executes the business logic necessary for the entity to move by bouncing on the edges of the screen:
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
import { GameSystem, Transform } from "angry-pixel";
|
|
106
|
+
|
|
107
|
+
class MoveAndBounceSystem extends GameSystem {
|
|
108
|
+
onUpdate(): void {
|
|
109
|
+
this.entityManager.search(MoveAndBounce).forEach(({ component, entity }) => {
|
|
110
|
+
const transform = this.entityManager.getComponent(entity, Transform);
|
|
111
|
+
const { boundaries, direction, speed } = component;
|
|
112
|
+
|
|
113
|
+
if (transform.position.y >= boundaries[0] || transform.position.y <= boundaries[1]) {
|
|
114
|
+
direction.y *= -1;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (transform.position.x >= boundaries[2] || transform.position.x <= boundaries[3]) {
|
|
118
|
+
direction.x *= -1;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
transform.position.x += direction.x * speed * this.timeManager.deltaTime;
|
|
122
|
+
transform.position.y += direction.y * speed * this.timeManager.deltaTime;
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Once the system is created, we can add it to the scene
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
import { Scene } from "angry-pixel";
|
|
132
|
+
|
|
133
|
+
class MainScene extends Scene {
|
|
134
|
+
loadAssets(): void {
|
|
135
|
+
this.assetManager.loadImage("logo.png");
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// within this method we register the systems of the scene
|
|
139
|
+
registerSystems(): void {
|
|
140
|
+
this.addSystem(MoveAndBounceSystem);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Create the entities
|
|
146
|
+
|
|
147
|
+
Finally, we need to create two entities, one that represents our logo, to which we want to apply the behavior of moving and bouncing, and another one that represents the camera of our game. For this we will use the `EntityManager`, specifically the `createEntity` method. This method accepts an array of components, the components can be concrete instances (this is useful when it is necessary to pass parameters by constructor) or classes (if it is not necessary to pass parameters by constructor, we can pass only the class).
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
import { Camera, Scene, SpriteRenderer, Transform } from "angry-pixel";
|
|
151
|
+
|
|
152
|
+
class MainScene extends Scene {
|
|
153
|
+
loadAssets(): void {
|
|
154
|
+
this.assetManager.loadImage("logo.png");
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
registerSystems(): void {
|
|
158
|
+
this.addSystem(MoveAndBounceSystem);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// within this method we create the entities
|
|
162
|
+
createEntities(): void {
|
|
163
|
+
// camera
|
|
164
|
+
this.entityManager.createEntity([new Transform(), new Camera({ layers: ["Logo"] })]);
|
|
165
|
+
|
|
166
|
+
// logo
|
|
167
|
+
this.entityManager.createEntity([
|
|
168
|
+
new Transform(),
|
|
169
|
+
new MoveAndBounce(),
|
|
170
|
+
new SpriteRenderer({
|
|
171
|
+
layer: "Logo",
|
|
172
|
+
image: this.assetManager.getImage("logo.png"),
|
|
173
|
+
}),
|
|
174
|
+
]);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### Run the game
|
|
180
|
+
|
|
181
|
+
Now we can start the game:
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
game.run();
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Check this example live
|
|
188
|
+
|
|
189
|
+
🎮 [https://angrypixel.gg/angry-pixel-logo-bounce](https://angrypixel.gg/angry-pixel-logo-bounce)
|
|
190
|
+
|
|
191
|
+
## DOCS
|
|
192
|
+
|
|
193
|
+
🔎 [Documentation](https://docs.angrypixel.gg)\
|
|
194
|
+
⚙️ [Api Docs](https://api-docs.angrypixel.gg)
|