Skip to content

Commit b2ca0ce

Browse files
committed
chore: readme
1 parent bcffd9d commit b2ca0ce

File tree

1 file changed

+106
-98
lines changed

1 file changed

+106
-98
lines changed

README.md

Lines changed: 106 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,47 @@
1-
# KAPLAY.js, a JavaScript game library
1+
# 🎮 KAPLAY.js — A JavaScript & TypeScript Game Library
22

3-
![#KAPLAY](/kaplay.webp)
3+
<div align="center">
4+
<img src="./kaplay.webp">
5+
</div>
46

5-
[**KAPLAY**](https://kaplayjs.com/) is a JavaScript library that helps you make
6-
games fast and fun!
7+
KAPLAY is the **fun-first**, 2D game library for **JavaScript** and
8+
**TypeScript**. It’s made to **feel like a game** while you're making games.
9+
Simple. Fast. Powerful.
710

8-
Start playing around with it in the [KAPLAYGROUND](https://play.kaplayjs.com/)
11+
✨ Whether you’re a beginner or an experienced dev, **KAPLAY** comes with its
12+
own **web-based editor** — the [KAPLAYGROUND](https://play.kaplayjs.com) — so
13+
you can try code instantly, and learn with more than **90 examples**!
914

10-
## Examples
15+
## 🎲 Quick Overview
1116

1217
```js
13-
// initialize context
14-
kaplay();
15-
16-
// define gravity
17-
setGravity(2400);
18+
// Start a game
19+
kaplay({
20+
background: "#6d80fa",
21+
});
1822

19-
// load a sprite called "bean"
20-
loadSprite("bean", "sprites/bean.png");
23+
// Load an image
24+
loadSprite("bean", "https://play.kaplayjs.com/bean.png");
2125

22-
// compose the player game object from multiple components and add it to the game
23-
const bean = add([
24-
sprite("bean"),
25-
pos(80, 40),
26-
area(),
27-
body(),
26+
// Add a sprite to the scene
27+
add([
28+
sprite("bean"), // it renders as a sprite
2829
]);
29-
30-
// press space to jump
31-
onKeyPress("space", () => {
32-
// this method is provided by the "body" component above
33-
bean.jump();
34-
});
3530
```
3631

37-
KAPLAY uses a powerful component system to compose game objects and behaviors.
32+
Game objects are composed from simple, powerful components:
3833

3934
```js
40-
// add a game obj to the scene from a list of component
35+
// Add a Game Obj to the scene from a list of component
4136
const player = add([
42-
// it renders as a sprite
43-
sprite("bean"),
44-
// it has a position
45-
pos(100, 200),
46-
// it has a collider
47-
area(),
48-
// it is a physical body which will respond to physics
49-
body(),
50-
// it has 8 of health
51-
health(8),
52-
// or give it tags for easier group behaviors
53-
"player",
37+
rect(40, 40), // it renders as a rectangle
38+
pos(100, 200), // it has a position (coordinates)
39+
area(), // it has a collider
40+
body(), // it is a physical body which will respond to physics
41+
health(8), // it has 8 health points
42+
// Give it tags for easier group behaviors
5443
"friendly",
55-
// plain objects fields are directly assigned to the game obj
44+
// Give plain objects fields for associated data
5645
{
5746
dir: vec2(-1, 0),
5847
dead: false,
@@ -74,18 +63,12 @@ player.onCollide("enemy", () => {
7463
player.onUpdate(() => {
7564
if (player.pos.y >= height()) {
7665
destroy(player);
77-
gameOver();
7866
}
7967
});
8068

81-
// if 'player' onCollide with any object with tag "enemy", run the callback
82-
player.onCollide("enemy", () => {
83-
player.hp -= 1;
84-
});
85-
86-
// all objects with tag "enemy" will move towards 'player' every frame
87-
onUpdate("enemy", (e) => {
88-
e.move(player.pos.sub(e.pos).unit().scale(e.speed));
69+
// All objects with tag "enemy" will move to the left
70+
onUpdate("enemy", (enemy) => {
71+
enemy.move(-400, 0);
8972
});
9073

9174
// move up 100 pixels per second every frame when "w" key is held down
@@ -94,97 +77,122 @@ onKeyDown("w", () => {
9477
});
9578
```
9679

97-
## Usage
80+
## 🖥️ Installation
9881

99-
### Start a Project With `create-kaplay`
82+
### 🚀 Using `create-kaplay`
10083

101-
The fastest way to start a KAPLAY game is with
102-
[`create-kaplay`](https://github.com/kaplayjs/create-kaplay)
84+
The fastest way to get started:
10385

10486
```sh
105-
$ npx create-kaplay mygame
87+
npx create-kaplay my-game
10688
```
10789

108-
This will create a directory called `mygame` for you, containing all the files
109-
we need
90+
Then open [http://localhost:5173](http://localhost:5173) and edit `src/game.js`.
91+
92+
### 📦 Install with package manager
11093

11194
```sh
112-
$ cd mygame
113-
$ npm run dev
95+
npm install kaplay
11496
```
11597

116-
Then open http://localhost:5173 and edit `src/game.js`
98+
```sh
99+
yarn add kaplay
100+
```
117101

118-
### Install as NPM Package
102+
```sh
103+
pnpm add kaplay
104+
```
119105

120106
```sh
121-
$ npm install kaplay
107+
bun add kaplay
122108
```
123109

124-
```js
125-
import kaplay from "kaplay";
110+
> You will need a bundler like [Vite](https://vitejs.dev/) or
111+
> [ESBuild](https://esbuild.github.io/) to use KAPLAY in your project. Learn how
112+
> to setup ESbuild
113+
> [here](https://kaplayjs.com/guides/install/#setup-your-own-nodejs-environment).
126114
127-
kaplay();
115+
### 🌐 Use in Browser
128116

129-
add([
130-
text("oh hi"),
131-
pos(80, 40),
132-
]);
117+
Include via CDN:
118+
119+
```html
120+
<script src="https://unpkg.com/kaplay@3001.0.12/dist/kaplay.js"></script>
133121
```
134122

135-
also works with CommonJS
123+
### 📜 TypeScript Global Types
136124

137-
```js
138-
const kaplay = require("kaplay");
139-
```
125+
If you're using **TypeScript**, you used `create-kaplay` or installed with a
126+
package manager and you want **global types**, you can load them using the
127+
following directive:
140128

141-
Note that you'll need to use a bundler like `esbuild` or `webpack` to use KAPLAY
142-
with NPM
129+
```ts
130+
import "kaplay/global";
143131

144-
### Browser CDN
132+
vec2(10, 10); // typed!
133+
```
145134

146-
This exports a global `kaplay` function
135+
But it's recommended to use `tsconfig.json` to include the types:
147136

148-
```html
149-
<script src="https://unpkg.com/kaplay@3001.0.9/dist/kaplay.js"></script>
150-
<script>
151-
kaplay()
152-
</script>
137+
```json
138+
{
139+
"compilerOptions": {
140+
"types": ["./node_modules/kaplay/dist/declaration/global.d.ts"]
141+
}
142+
}
153143
```
154144

155-
or use with es modules
145+
> If you are publishing a game (and not testing/learning) maybe you don't want
146+
> to use globals,
147+
> [see why](https://kaplayjs.com/guides/optimization/#avoid-global-namespace).
156148
157-
```html
158-
<script type="module">
159-
import kaplay from "https://unpkg.com/kaplay@3001.0.9/dist/kaplay.mjs"
160-
kaplay()
161-
</script>
149+
You can also use all **KAPLAY** source types importing them:
150+
151+
```js
152+
import type { TextCompOpt } from "kaplay"
153+
import type * as KA from "kaplay" // if you prefer a namespace-like import
154+
155+
interface MyTextCompOpt extends KA.TextCompOpt {
156+
fallback: string;
157+
}
162158
```
163159

164-
works all CDNs that supports NPM packages, e.g. jsdelivr, skypack
160+
## 📚 Resources
161+
162+
### 📖 Docs
165163

166-
## Documentation
164+
- [KAPLAY Official Docs](https://kaplayjs.com/docs/)
165+
- [KAPLAYGROUND](https://play.kaplayjs.com)
167166

168-
- **v4000**: https://v4000.kaplayjs.com/
169-
- **v3001**: https://kaplayjs.com/
167+
### 📺 Tutorials
170168

171-
## Community
169+
- 🎥
170+
[KAPLAY Library Crash Course by JSLegend ⚔️](https://www.youtube.com/watch?v=FdEYxGoy5_c)
171+
- 📖
172+
[Learn JavaScript basics and KAPLAY to make games quickly](https://jslegenddev.substack.com/p/learn-the-basics-of-javascript-and)
173+
174+
### 💬 Community
172175

173176
- [Discord Server](https://discord.gg/aQ6RuQm3TF)
174177
- [GitHub Discussions](https://github.com/kaplayjs/kaplay/discussions)
175-
- [Twitter](https://twitter.com/kaplayjs)
178+
- [Twitter](https://twitter.com/Kaboomjs)
176179

177-
### Games
180+
## 🎮 Games
178181

179-
Collections of games made with KAPLAY (and Kaboom), selected by KAPLAY:
182+
Collections of games made with KAPLAY, selected by KAPLAY:
180183

181184
- [Itch.io](https://itch.io/c/4494863/kag-collection)
182185
- [Newgrounds.com](https://www.newgrounds.com/playlist/379920/kaplay-games)
183186

184-
## Credits
187+
## 🙌 Credits
188+
189+
KAPLAY is an open-source project, maintained by the
190+
[KAPLAY Team and core contributors](https://github.com/kaplayjs/kaplay/wiki/Development-Team)
191+
and with the support of many
192+
[other amazing contributors](https://github.com/kaplayjs/kaplay/graphs/contributors).
193+
194+
### 🏆 Recognitions
185195

186-
- Thanks to [tga](https://space55.xyz) for all his work on the original
187-
Kaboom.js
188196
- Thanks to [mulfok](https://twitter.com/MulfoK) for the awesome
189197
[mulfok32](https://lospec.com/palette-list/mulfok32) color palette, used in
190198
KAPLAY sprites and art

0 commit comments

Comments
 (0)