git @ Cat's Eye Technologies noit-o-mnain-worb / 60c3202
Don't move Bobules more than once per step. Chris Pressey 7 years ago
1 changed file(s) with 28 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
4040
4141 Bobule = function() {
4242 this.pressure = 1;
43
44 this.move = function(pf, x, y) {
43 this.serial = 0;
44
45 this.move = function(serial, pf, x, y) {
46 if (this.serial > serial)
47 return;
48
4549 this.pressure++;
4650
4751 var newX = x + (Math.floor(Math.random() * 3) - 1);
6266 pf.put(x, y, undefined);
6367 this.pressure = 1;
6468 pf.put(newX, newY, this);
69 this.serial = serial + 1;
6570 };
6671
6772 this.draw = function(ctx, px, py, x, y, w, h) {
230235 * This function ensures a particular order.
231236 */
232237 this.foreach = function(fun) {
233 /* TODO have less knowledge of the innards of yoob.Playfield */
234 for (var y = this.worldPf.minY; y <= this.worldPf.maxY; y++) {
235 for (var x = this.worldPf.minX; x <= this.worldPf.maxX; x++) {
238 var lowerY = this.getLowerY();
239 var upperY = this.getUpperY();
240 var lowerX = this.getLowerX();
241 var upperX = this.getUpperX();
242 for (var y = lowerY; y <= upperY; y++) {
243 for (var x = lowerX; x <= upperX; x++) {
236244 var value = this.get(x, y);
237245 if (value === undefined)
238246 continue;
287295
288296 var proto = new yoob.Controller();
289297 WorbController = function() {
298 this.init = function(cfg) {
299 proto.init.apply(this, [cfg]);
300 this.pf = new WorbPlayfield().init({});
301 cfg.view.setPlayfield(this.pf);
302 this.view = cfg.view;
303 this.serial = 0;
304 return this;
305 };
306
290307 this.step = function() {
291308 var underLoad = false;
292309 var pf = this.pf;
293 this.view.draw();
294 pf.foreachBobule(function (x, y, elem) {
295 elem.move(pf, x, y);
310 var serial = this.serial;
311 pf.foreachBobule(function(x, y, elem) {
312 elem.move(serial, pf, x, y);
296313 });
297 pf.foreachWorld(function (x, y, elem) {
314 pf.foreachWorld(function(x, y, elem) {
298315 var b;
299316 if (elem instanceof Sink) {
300317 b = pf.get(x, y);
316333 if (this.onstep !== undefined) {
317334 this.onstep(underLoad);
318335 }
336 this.view.draw();
337 this.serial++;
319338 };
320339
321340 this.reset = function(text) {
323342 this.pf.load(0, 0, text);
324343 this.view.draw();
325344 };
326
327 this.init = function(cfg) {
328 proto.init.apply(this, [cfg]);
329 this.pf = new WorbPlayfield().init({});
330 cfg.view.setPlayfield(this.pf);
331 this.view = cfg.view;
332 return this;
333 };
334345 };
335346 WorbController.prototype = proto;