Skip to content

Instantly share code, notes, and snippets.

View krabbypattified's full-sized avatar
🎯
Focusing

Gabe Rogan krabbypattified

🎯
Focusing
View GitHub Profile
@krabbypattified
krabbypattified / cloudSettings
Created March 28, 2019 15:56
Visual Studio Code Settings Sync Gist
{"lastUpload":"2019-03-28T15:56:07.976Z","extensionVersion":"v3.2.7"}
@krabbypattified
krabbypattified / imagerepeat.js
Last active February 20, 2019 13:57
Repeated background image for canvas game engine
const cameraXobject = new DOMMatrix().rotate(PI/8)
const inverse = cameraXobject.inverse()
const transformPoint = p => inverse.transformPoint(p)
const pat = ctx.createPattern(img, 'repeat')
ctx.fillStyle = pat
ctx.path = [
[0,0],
[ctx.canvas.width,0],
[0,ctx.canvas.height],
@krabbypattified
krabbypattified / Assets.js
Last active January 18, 2019 10:44
Engine Spec
// Assets
const assets = {
sword: {
short: import('./Sword/short.png'),
long: 'anythingSyncOrAsync',
}
}
// Renderable component
const Blade = new Renderable([
@krabbypattified
krabbypattified / collision.md
Last active January 18, 2019 09:32
Broad-phase Collision Detection O(n)

Preface

This describes a 2D broad-phase collision detection algorithm that runs in O(n) time where n is the number of entities. It easily extends to 3D. It holds no state except entity bounding box calculated during the previous frame in order to prevent phasing. The algorithm performs 4 steps every frame: Rectangle Creation, Rectangle Sorting, Chunk Creation, and Collision Detection.

Definitions

  • point = a point in 2D space
  • path = an open set of linearly connected points
  • polygon = a closed set of linearly connected points
  • entity = a point or path or polygon
  • space = the 2D space formed by two spatial dimensions
  • spacetime = the 3D space formed by two spatial dimensions and a time dimension