Skip to content

Instantly share code, notes, and snippets.

@LukeWood
Created July 12, 2019 03:28
Show Gist options
  • Save LukeWood/71644f39b6fe49a5d03e98ea56d90df1 to your computer and use it in GitHub Desktop.
Save LukeWood/71644f39b6fe49a5d03e98ea56d90df1 to your computer and use it in GitHub Desktop.
import {subscribe} from "tiny-pubsub"
import {update_bullet} from './update_bullet'
let bullets = {};
subscribe("bullet", bullet => {
bullets[bullet.id] = bullet;
})
subscribe("tick", (current_time, world) => {
for(let id in bullets) {
bullets[id] = update_bullet(bullets[id], current_time, world);
if(bullets[id] == null) {
delete bullets[id];
}
}
})
subscribe("poll", ({ bullets: bullets_poll }) => {
let tmp_bullets = {};
bullets_poll.forEach(bullet => {
tmp_bullets[bullet.id] = bullet;
});
bullets = tmp_bullets;
})
subscribe("remove-bullet", (id) => {
delete bullets[id]
})
function get_bullets() {
return Object.keys(bullets).map((uuid) => bullets[uuid])
}
export {get_bullets}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment