angry-pixel 1.2.1 → 1.2.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.
@@ -0,0 +1,25 @@
1
+ name: Reusable Workflow Analyze Code
2
+
3
+ on:
4
+ workflow_call:
5
+
6
+ jobs:
7
+ analyze:
8
+ name: "[Analyze Code]"
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v2
12
+
13
+ - name: "[Restore node modules]"
14
+ id: cache-node-modules
15
+ uses: actions/cache@v2
16
+ with:
17
+ path: node_modules
18
+ key: ${{ runner.os }}-nodemodules-${{ hashFiles('**/yarn.lock') }}
19
+ restore-keys: |
20
+ ${{ runner.os }}-nodemodules-
21
+ - name: "[Run lint]"
22
+ run: yarn run lint
23
+
24
+ - name: "[Run prettier-check]"
25
+ run: yarn run prettier-check
@@ -0,0 +1,23 @@
1
+ name: Reusable Workflow Build Code
2
+
3
+ on:
4
+ workflow_call:
5
+
6
+ jobs:
7
+ build:
8
+ name: "[Build Core]"
9
+ runs-on: ubuntu-latest
10
+ if: contains('refs/heads/main', github.ref)
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+
14
+ - name: "[Restore node modules]"
15
+ id: cache-node-modules
16
+ uses: actions/cache@v2
17
+ with:
18
+ path: node_modules
19
+ key: ${{ runner.os }}-nodemodules-${{ hashFiles('**/yarn.lock') }}
20
+ restore-keys: |
21
+ ${{ runner.os }}-nodemodules-
22
+ - name: "[Run build]"
23
+ run: yarn run build
@@ -1,13 +1,15 @@
1
- name: CI
2
- on: push
3
- jobs:
4
- build:
5
- runs-on: ubuntu-latest
6
- steps:
7
- - uses: actions/setup-node@v1
8
- with:
9
- node-version: 12.x
10
- - uses: actions/checkout@v2
11
- - run: npm install
12
- - run: npm run lint
13
- - run: npm run prettier-check
1
+ name: Continuous Integration App
2
+
3
+ on: push
4
+
5
+ jobs:
6
+ Setup:
7
+ uses: ./.github/workflows/setupNode.yml
8
+
9
+ Analyze:
10
+ needs: Setup
11
+ uses: ./.github/workflows/analyzeCode.yml
12
+
13
+ Build:
14
+ needs: [Setup, Analyze]
15
+ uses: ./.github/workflows/buildCode.yml
@@ -0,0 +1,40 @@
1
+ name: Reusable Workflow Node Setup
2
+
3
+ on:
4
+ workflow_call:
5
+
6
+ jobs:
7
+ setup:
8
+ name: "[Setup]"
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v2
12
+ - name: "[Use node 16.x]"
13
+ uses: actions/setup-node@v2
14
+ with:
15
+ node-version: 16.x
16
+ cache: "yarn"
17
+
18
+ - name: "[Get yarn cache directory path]"
19
+ id: yarn-cache-dir-path
20
+ run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
21
+
22
+ - name: "[Cache yarn directory]"
23
+ id: cache-yarn-cache
24
+ uses: actions/cache@v2
25
+ with:
26
+ path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
27
+ key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
28
+ restore-keys: |
29
+ ${{ runner.os }}-yarn-
30
+ - name: "[Cache node modules]"
31
+ id: cache-node-modules
32
+ uses: actions/cache@v2
33
+ with:
34
+ path: node_modules
35
+ key: ${{ runner.os }}-nodemodules-${{ hashFiles('**/yarn.lock') }}
36
+ restore-keys: |
37
+ ${{ runner.os }}-nodemodules-
38
+ - name: "[Install dependencies]"
39
+ if: steps.cache-yarn-cache.outputs.cache-hit != 'true' || steps.cache-node-modules.outputs.cache-hit != 'true'
40
+ run: yarn install
package/README.md CHANGED
@@ -1,3 +1,168 @@
1
- # Angry Pixel Engine
1
+ # Introduction
2
2
 
3
- A lightweight 2D game engine made with TypeScript
3
+ ## What is Angry Pixel?
4
+
5
+ Angry Pixel is a 2D engine for browsers games written in Typescript.
6
+
7
+ Main features:
8
+
9
+ - Sprites and animations
10
+ - Tilemaps (csv and Tiled)
11
+ - WebGL rendering
12
+ - Polygonal collisions and static physics resolution
13
+ - Input (keyboard, mouse, gamepad, touch)
14
+ - Scene-Object-Component based architecture
15
+
16
+ ## Getting Started
17
+
18
+ ### Installation
19
+
20
+ ```bash
21
+ npm i angry-pixel
22
+ ```
23
+
24
+ ### Initialize
25
+
26
+ Create and configure a new Game instance.
27
+
28
+ ```typescript
29
+ import { Game, GameConfig } from "angry-pixel";
30
+
31
+ const config: GameConfig = {
32
+ containerNode: document.getElementById("app"),
33
+ gameWidth: 1920,
34
+ gameHeight: 1080,
35
+ canvasColor: "#00D9D9",
36
+ };
37
+
38
+ // create the game
39
+ const game = new Game(config);
40
+ ```
41
+
42
+ ### Create a Scene
43
+
44
+ Crear la clase MainScene que extiende Scene and load an image that will be used as a Sprite.
45
+
46
+ ```typescript
47
+ import { Scene } from "angry-pixel";
48
+
49
+ class MainScene extends Scene {
50
+ protected init(): void {
51
+ this.assetManager.loadImage("logo.png");
52
+ }
53
+ }
54
+ ```
55
+
56
+ Add the scene to the game.
57
+
58
+ ```typescript
59
+ const config: GameConfig = {
60
+ containerNode: document.getElementById("app"),
61
+ gameWidth: 1920,
62
+ gameHeight: 1080,
63
+ canvasColor: "#00D9D9",
64
+ };
65
+
66
+ // create the game
67
+ const game = new Game(config);
68
+ // add scene
69
+ game.addScene(MainScene, "MainScene");
70
+ ```
71
+
72
+ ### Create a Game Object
73
+
74
+ Create the Logo class extending GameObject and add the image using the native SpriteRenderer component.
75
+
76
+ ```typescript
77
+ import { GameObject, Sprite, SpriteRenderer } from "angry-pixel";
78
+
79
+ class Logo extends GameObject {
80
+ protected init(): void {
81
+ this.addComponent(SpriteRenderer, {
82
+ sprite: new Sprite({
83
+ image: this.assetManager.getImage("logo.png"),
84
+ }),
85
+ });
86
+ }
87
+ }
88
+ ```
89
+
90
+ Add the object to the scene.
91
+
92
+ ```typescript
93
+ class MainScene extends Scene {
94
+ protected init(): void {
95
+ this.assetManager.loadImage("logo.png");
96
+ this.addGameObject(Logo);
97
+ }
98
+ }
99
+ ```
100
+
101
+ ### Create a Component
102
+
103
+ Create the MoveAndBounce class that extends Component and contains the logic for object movement, using the native Transform component (natively included in the GameObject), vectors and delta time.
104
+
105
+ ```typescript
106
+ import { Component, Transform, Vector2 } from "angry-pixel";
107
+
108
+ class MoveAndBounce extends Component {
109
+ private transform: Transform;
110
+ private direction: Vector2;
111
+ private speed: number;
112
+
113
+ protected init(): void {
114
+ this.transform = this.gameObject.transform;
115
+ this.direction = new Vector2(1, 1);
116
+ this.speed = 200; // pixels per second
117
+ }
118
+
119
+ // this method is called once per frame
120
+ protected update(): void {
121
+ if (this.transform.position.y >= 476 || this.transform.position.y <= -476) {
122
+ this.direction.y *= -1;
123
+ }
124
+ if (this.transform.position.x >= 896 || this.transform.position.x <= -896) {
125
+ this.direction.x *= -1;
126
+ }
127
+
128
+ this.transform.position.x += this.direction.x * this.speed * this.timeManager.deltaTime;
129
+ this.transform.position.y += this.direction.y * this.speed * this.timeManager.deltaTime;
130
+ }
131
+ }
132
+ ```
133
+
134
+ Add the component to the object.
135
+
136
+ ```typescript
137
+ class Logo extends GameObject {
138
+ protected init(): void {
139
+ this.addComponent(SpriteRenderer, {
140
+ sprite: new Sprite({
141
+ image: this.assetManager.getImage("logo.png"),
142
+ }),
143
+ });
144
+
145
+ this.addComponent(MoveAndBounce);
146
+ }
147
+ }
148
+ ```
149
+
150
+ ### Run the game
151
+
152
+ ```typescript
153
+ const config: GameConfig = {
154
+ containerNode: document.getElementById("app"),
155
+ gameWidth: 1920,
156
+ gameHeight: 1080,
157
+ canvasColor: "#00D9D9",
158
+ };
159
+
160
+ // create the game
161
+ const game = new Game(config);
162
+ // add scene
163
+ game.addScene(MainScene, "MainScene");
164
+ // run the game
165
+ game.run();
166
+ ```
167
+
168
+ #### Check this example live [here](https://angrypixel.gg/angry-pixel-logo-bounce)
@@ -5,7 +5,6 @@ import { GameActor } from "./GameActor";
5
5
  import { Container } from "../utils/Container";
6
6
  export type ComponentClass<T extends Component = Component> = new (container: Container, gameObject: GameObject, name?: string) => T;
7
7
  export declare abstract class Component extends GameActor {
8
- readonly id: string;
9
8
  readonly name: string;
10
9
  readonly gameObject: GameObject;
11
10
  readonly allowMultiple: boolean;
@@ -5,9 +5,9 @@ import { Scene } from "./Scene";
5
5
  import { GameActor, InitOptions } from "./GameActor";
6
6
  import { Container } from "../utils/Container";
7
7
  export declare const LAYER_DEFAULT = "Default";
8
- export type GameObjectClass<T extends GameObject = GameObject> = new (container: Container, name?: string, parent?: GameObject) => T;
8
+ export type GameObjectClass<T extends GameObject = GameObject> = new (container: Container, id: number, name?: string, parent?: GameObject) => T;
9
9
  export declare class GameObject extends GameActor {
10
- readonly id: string;
10
+ readonly id: number;
11
11
  readonly name: string;
12
12
  tag: string;
13
13
  layer: string;
@@ -18,7 +18,7 @@ export declare class GameObject extends GameActor {
18
18
  private components;
19
19
  private activeComponentsCache;
20
20
  private activeChildrenCache;
21
- constructor(container: Container, name?: string, parent?: GameObject);
21
+ constructor(container: Container, id: number, name?: string, parent?: GameObject);
22
22
  get active(): boolean;
23
23
  set active(active: boolean);
24
24
  get parent(): GameObject | null;
@@ -4,7 +4,7 @@ import { Container } from "../../utils/Container";
4
4
  export interface IGameObjectManager {
5
5
  addGameObject<T extends GameObject>(gameObjectClass: GameObjectClass<T>, options?: InitOptions, parent?: GameObject, name?: string): T;
6
6
  findGameObjects<T extends GameObject>(gameObjectClass?: GameObjectClass<T>): T[];
7
- findGameObjectById<T extends GameObject>(id: string): T;
7
+ findGameObjectById<T extends GameObject>(id: number): T;
8
8
  findGameObject<T extends GameObject>(gameObjectClass: GameObjectClass<T>): T;
9
9
  findGameObject<T extends GameObject>(name: string): T;
10
10
  findGameObject<T extends GameObject>(filter: GameObjectClass<T> | string): T;
@@ -22,7 +22,7 @@ export declare class GameObjectManager implements IGameObjectManager {
22
22
  constructor(container: Container);
23
23
  addGameObject<T extends GameObject>(gameObjectClass: GameObjectClass<T>, options?: InitOptions, parent?: GameObject, name?: string): T;
24
24
  findGameObjects<T extends GameObject>(gameObjectClass?: GameObjectClass<T>): T[];
25
- findGameObjectById<T extends GameObject>(id: string): T;
25
+ findGameObjectById<T extends GameObject>(id: number): T;
26
26
  findGameObject<T extends GameObject>(gameObjectClass: GameObjectClass<T>): T;
27
27
  findGameObject<T extends GameObject>(name: string): T;
28
28
  findGameObjectsByParent<T extends GameObject>(parent: GameObject): T[];