Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Gabe Rogan krabbypattified

🎯
Focusing
Block or report user

Report or block krabbypattified

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@krabbypattified
krabbypattified / cloudSettings
Created Mar 28, 2019
Visual Studio Code Settings Sync Gist
View cloudSettings
{"lastUpload":"2019-03-28T15:56:07.976Z","extensionVersion":"v3.2.7"}
@krabbypattified
krabbypattified / imagerepeat.js
Last active Feb 20, 2019
Repeated background image for canvas game engine
View imagerepeat.js
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 / collision.md
Last active Jan 18, 2019
Broad-phase Collision Detection O(n)
View collision.md

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
View Assets.js
// Assets
const assets = {
sword: {
short: import('./Sword/short.png'),
long: 'anythingSyncOrAsync',
}
}
// Renderable component
const Blade = new Renderable([
You can’t perform that action at this time.