Skip to content

Instantly share code, notes, and snippets.

View philldev's full-sized avatar
🏠
Working from home

Deddy Wolley philldev

🏠
Working from home
View GitHub Profile
@philldev
philldev / collision.ts
Created December 25, 2022 05:36
check collision between 2 rectangle
const collided = (r1: Rectangle, r2: Rectangle) => {
return (
r1.position.x + r1.size.width >= r2.position.x &&
r1.position.y + r1.size.height >= r2.position.y &&
r1.position.y <= r2.position.y + r2.size.height &&
r1.position.x <= r2.position.x + r2.size.height
)
}
@philldev
philldev / keyboard-input.ts
Last active December 25, 2022 04:49
Keyboard Input Typescript
type KeyboardState = 'pressed' | 'down' | 'released' | 'up'
class Keyboard {
private _keys: Record<string, KeyboardState> = {}
constructor(keys: string[]) {
for (const _key of keys) {
this._keys[_key] = 'up'
}
}