Skip to content

Instantly share code, notes, and snippets.

@timetocode
timetocode / interp-sample.js
Created April 23, 2014 22:43
Entity interpolation
/* Entity Interpolation
this code occurs within the draw loop for an entity
this.x and this.y represent the most recently received server position of
the entity -- though i don't ever intend to use it for drawing
when an update is received (roughly every 50ms in my particular game) this.x and this.y get
pushed into previousState.x and previousState.y
i also continue sloppily onwards to previousPreviousState.x, but I've removed that code
@timetocode
timetocode / PlayerCharacter.js
Created June 1, 2019 06:14
babylon.js + nengi.js entity example. Note: one can write the same thing in more of an ECS style (instead of regular oop) if desired by moving all of the methods off of PlayerCharacter and into systems
import nengi from 'nengi'
import * as BABYLON from 'babylonjs'
class PlayerCharacter {
constructor(scene) {
this.name = 'anon'
this.mesh = new BABYLON.Mesh('dummy', scene)
this.mesh.entity = this // for collisions within babylon
this.hitpoints = 100
// velocity from own impulses
@timetocode
timetocode / AABB.js
Created May 24, 2015 22:47
Quadtree and AABB gists from nengi
//var BinarySerializer = require('./BinarySerializer')
//var BinaryType = require('./BinaryType')
// axis-aligned bounding box
/* PARAMS: (Point)center, (Point)half */
function AABB(x, y, halfWidth, halfHeight) {
this.initialize(x, y, halfWidth, halfHeight)
}
AABB.pool = []
@timetocode
timetocode / twitch-widget.html
Created September 25, 2014 01:25
JavaScript Widget, displays if a twitch.tv user is currently streaming.
<!-- jQuery, delete this line if you already have jQuery on your page -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- the twitch widget, place code in the <HEAD> -->
<script>
var twitchUserName = 'timetocode' // your name goes here
$(document).ready(function() {
$.getJSON("https://api.twitch.tv/kraken/streams/"+twitchUserName+"?callback=?",function(streamData) {
console.log('Stream Data:', streamData) // debug message, shows all available data
if(streamData && streamData.stream) {
@timetocode
timetocode / index.js
Created December 6, 2019 23:19
node & rust 500,000 entity iteration
const createEntity = (nid, x, y, name) => {
return {
nid,
x,
y,
hp: 100,
name
}
}
use std::time::Instant;
#[derive(Debug)]
struct Entity {
nid: u32,
x: f64,
y: f64,
hp: u8,
name: String
}
@timetocode
timetocode / childBot.js
Created August 4, 2019 22:18
nengi bot example using multiple cpus
const glue = require('./glue')
const nengi = glue.nengi.default
const nengiConfig = glue.nengiConfig.default
const PlayerInput = glue.PlayerInput.default
// bots need to all share the same protocols
const protocolMap = new nengi.ProtocolMap(nengiConfig, nengi.metaConfig)
//var address = 'ws://localhost:8001'
const address = null // put some url here
body {
background-color:#423b41;
}
.wrap {
display: flex;
}
.solo {
border: solid 4px #ebfff9;
@timetocode
timetocode / default.conf
Last active June 26, 2019 22:17
Nginx config and ubuntu systemd services for hosting multiple game instances on ports 8001 through 8005, proxied from urls like wss://subdomain.domain.io/1 through wss://subdomain.domain.io/5; can also remove the ssl and listen on port 80 instead. The service file is an example, but creating 5 called instance1.service through instance5.service a…
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 443 ssl;
ssl_certificate /srv/certs/fullchain.pem;
ssl_certificate_key /srv/certs/privkey.pem;
@timetocode
timetocode / nengi+TileMap-misc-examples.js
Last active June 15, 2019 19:32
Demonstration of representing 2D tile maps as 1D arrays and sending their data via nengi. Includes a tilemap which is a "2d array"(not really) of integers, and examples for a "2d array" of objects.
var TileEnum = {
EMPTY: 0,
GRASS: 1,
DIRT: 2,
STONEWALL: 3
}
class TileMap {
constructor(width, height) {