crazy2be / buildblast

Build a base, shoot intruders
MIT License
5 stars 1 forks source link

Add controls.on(...) #119

Open crazy2be opened 11 years ago

crazy2be commented 11 years ago

I noticed a fair bit of code that does things like:

var fireWasDown = false;
self.update = function (controlState) {
    if (controlState.fire && !fireWaseDown) {
        doSomething()
    }
    fireWasDown = controlState.fire;
}

We could allow this code to be rewritten as

controls.on('fire', doSomething);

And move the bookkeeping to controls.js.

I've been thinking about this for a bit now, I think the API should be something like:

It might even be nice to have some sort of controls.every(1000 /*ms*/, 'fire', fireGun) timer-integrated API, but I'm not totally sure how to do that properly.

Thoughts?

kieve commented 11 years ago

Could be useful, but for the controls.every, in the case of shooting, we must keep it serverside validated. That would just be fore animation / sound repeating.

yeerkkiller1 commented 11 years ago

We might think of applying this paradigm to the server code, as in not sending Controls, but just sending data when the state changes. Then the server could hook into specific messages.