parkm / oldbpm

A JavaScript game where you shoot at bubbles.
0 stars 1 forks source link

States #17

Closed dgpt closed 10 years ago

dgpt commented 10 years ago

I don't know if States even need prototypes, actually. Here's how I wanted to do them.

function State(init, update) { //yadayadayada }
var level1 = new State(function() {}, function() {});

Since we'd only be rewriting the init and update functions every time, it makes sense to just use callbacks instead.

parkm commented 10 years ago

There's also the onSwitch function (Which I should probably rename). I think it'll be more flexible as a prototype. especially because of all the reuse the state has to do. nevermind.

This also seems hard to read if we were to have a new state far away from the State function declaration, since there's no names on the functions you'd just have to remember the order. But we could just pass it as an object. { update: function(){}, init: function() {} }

dgpt commented 10 years ago

Hm, good point. It's definitely more flexible as a prototype. What do you mean by 'all the reuse the state has to do'?

We could do an object or we could name the functions new State(function init() {}, function update() {});

parkm commented 10 years ago

Oh yeah I suppose that would work to. But yeah I think leaving it would be best.