Skip to content

Commit

Permalink
feat: add KAPLAY template
Browse files Browse the repository at this point in the history
  • Loading branch information
niceEli committed Sep 8, 2024
1 parent ed1c8a9 commit 9be1e08
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 0 deletions.
24 changes: 24 additions & 0 deletions kaplay/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
58 changes: 58 additions & 0 deletions kaplay/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# KAPLAY Starter

👋 Welcome to KAPLAY!

This README includes everything you need to start writing game quickly.

## Project Structure

```bash
.
├── src
│ ├── ...
│ ├── scenes
│ │ └── starter.ts # An Example Of A Simple Scene In KAPLAY
│ └── components # This Is Where Your Components Would Live To Be Accessed By Nodes
├── public
│ └── put images here
├── ...
├── theme.ts # Customize the theme of the tutorial
└── tsconfig.json # Typescript Config
```

## Getting Started

Make sure you have all dependencies installed and started the dev server:

```bash
pnpm install
pnpm run dev
```

## UI Structure

```markdown
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ ● ● ● │
├─────────────────────────────────────┬──────────────────────────────────────────────────────────┤
│ │ │
│ │ │
│ │ │
│ │ │
│ │ │
│ │ │
│ │ │
│ Your Code │ │
│ │ │
│ │ Game Preview │
│ │ │
│ │ │
│ │ │
│ │ │
│ │ │
├─────────────────────────────────────┤ │
│ │ │
│ Terminal │ │
│ │ │
└─────────────────────────────────────┴──────────────────────────────────────────────────────────┘
```
12 changes: 12 additions & 0 deletions kaplay/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>KAPLAY Game</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="./src/main.ts"></script>
</body>
</html>
16 changes: 16 additions & 0 deletions kaplay/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "kaplay-starter",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview"
},
"devDependencies": {
"typescript": "^5.5.3",
"vite": "^5.4.2",
"kaplay": "3001.0.0-beta.1"
}
}
11 changes: 11 additions & 0 deletions kaplay/src/components/spin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default function cmp_spin(){
let me: any
return {
add() {
me = this as any
},
update() {
me.angle -= 2.222222222
}
}
}
10 changes: 10 additions & 0 deletions kaplay/src/kaplay.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import kaplay from 'kaplay';

export const k = kaplay({
background: [0,0,0],
width: 1280,
height: 720,
letterbox: true,
});

export default k;
6 changes: 6 additions & 0 deletions kaplay/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import k from "./kaplay";
import scn_starter from "./scenes/starter";

k.scene("starter", scn_starter);

k.go("starter");
35 changes: 35 additions & 0 deletions kaplay/src/scenes/starter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import cmp_spin from "../components/spin";
import k from "../kaplay";

export default function scn_starter(){

k.add([
k.rect(k.width(), k.height()),
k.color(k.WHITE),
])

k.add([
k.pos(k.center()),
k.anchor("center"),
k.color(k.BLACK),
k.text("Hello, Kaplay!\nEdit The Files In The 'src' Folder To Get Started\nCheck Out https://kaplayjs.com For The Documentation", {
align: "center",
}),
]);

k.loadBean()

let bean = k.add([
k.sprite("bean"),
k.pos(k.width() / 2, k.height() / 2 + 200),
k.anchor("center"),
k.rotate(0),
cmp_spin(),
])

k.onFixedUpdate(() => {
bean.pos.x = Math.cos(k.time()) * 100 + k.width() / 2
bean.pos.y = Math.sin(k.time()) * 100 + k.height() / 2 + 200
})

}
23 changes: 23 additions & 0 deletions kaplay/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"isolatedModules": true,
"moduleDetection": "force",
"noEmit": true,

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"]
}

0 comments on commit 9be1e08

Please sign in to comment.