Created
July 12, 2019 03:28
-
-
Save LukeWood/71644f39b6fe49a5d03e98ea56d90df1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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