@jiant/canvable 0.0.5 → 0.0.6
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 +34 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,35 +24,55 @@ yarn add @jiant/canvable
|
|
|
24
24
|
|
|
25
25
|
### Criando uma Cena
|
|
26
26
|
|
|
27
|
+
### Criando uma Cena
|
|
28
|
+
|
|
27
29
|
A seguir está um exemplo básico de como criar uma cena e adicionar um objeto nela:
|
|
28
30
|
|
|
29
31
|
```typescript
|
|
30
|
-
import {
|
|
31
|
-
import "./style.css";
|
|
32
|
+
import { Scene, Square, Vector2D, getCanvas, KinematicBody } from "@jiant/canvable";
|
|
32
33
|
|
|
33
34
|
// Obtendo o canvas
|
|
34
|
-
const canvas = getCanvas("app")
|
|
35
|
+
const canvas = getCanvas("app");
|
|
35
36
|
const ctx = canvas.getContext("2d")!;
|
|
36
37
|
|
|
37
38
|
// Criando a cena
|
|
38
39
|
const scene = new Scene(ctx);
|
|
39
40
|
|
|
40
|
-
// Criando um
|
|
41
|
-
const
|
|
41
|
+
// Criando um objeto (Quadrado)
|
|
42
|
+
const player = new Square(scene, {
|
|
43
|
+
size: new Vector2D(50, 50),
|
|
44
|
+
startsWithBoundingBox: true, // Adicionar colisão automaticamente
|
|
45
|
+
});
|
|
46
|
+
player.pos = new Vector2D(100, 100);
|
|
47
|
+
player.style.fillStyle = "#00FF00"; // Cor customizada
|
|
42
48
|
|
|
43
|
-
// Adicionando
|
|
44
|
-
scene
|
|
49
|
+
// Adicionando física (Corpo Kinemático)
|
|
50
|
+
const body = new KinematicBody(scene, player, {
|
|
51
|
+
speed: 1000,
|
|
52
|
+
friction: 0.9,
|
|
53
|
+
});
|
|
54
|
+
scene.addObject(body);
|
|
55
|
+
|
|
56
|
+
// Iniciando o loop
|
|
57
|
+
scene.run((deltaTime) => {
|
|
58
|
+
// Movimento simples
|
|
59
|
+
if (scene.inputManager.isPressed("ArrowRight")) {
|
|
60
|
+
body.applyForce(1000 * deltaTime, 0, deltaTime);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
45
63
|
```
|
|
46
64
|
|
|
47
|
-
###
|
|
65
|
+
### Playground Interativo
|
|
48
66
|
|
|
49
|
-
|
|
67
|
+
O pacote inclui um exemplo completo de "Playground de Física" com:
|
|
50
68
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
69
|
+
- Controle de personagem (WASD + Setas)
|
|
70
|
+
- Sprint (Shift)
|
|
71
|
+
- Colisões e Física
|
|
72
|
+
- Câmera que segue o jogador
|
|
73
|
+
- Geração procedural de nível
|
|
74
|
+
|
|
75
|
+
Você pode conferir o código fonte em `example/index.ts` ou rodar localmente com `npm run dev`.
|
|
56
76
|
|
|
57
77
|
---
|
|
58
78
|
|