Skip to content

Instantly share code, notes, and snippets.

@micmath
Created November 21, 2011 11:19
Show Gist options
  • Save micmath/1382354 to your computer and use it in GitHub Desktop.
Save micmath/1382354 to your computer and use it in GitHub Desktop.
/**
* Classic Atari PONG!
* @author Rob Taylor <[email protected]>
* @date 15/11/2011
*/
define([
'jquery-1'
], function ($) {
var Pong = function () {
};
Pong.prototype = {
_ticker: null,
_container: null,
_options: {
// gameSpeed: 20, // 50 FPS
// gameSpeed: 17, // 60 FPS
gameSpeed: 14, // 70 FPS
sounds: {
start: false,
score: false,
paddleImpact: false,
wallImpact: false,
win: false,
loose: false
}
},
_soundFx: {
_muted: false,
_store: {
start: function () {
return this._soundFx._store.start = new Audio(this._options.sounds.start);
}
// start: (this._options.sounds.start ? new Audio(this._options.sounds.start) : false),
// score: (this._options.sounds.score ? new Audio(this._options.sounds.score) : false),
// paddleImpact: (this._options.sounds.paddleImpact ? new Audio(this._options.sounds.paddleImpact) : false),
// wallImpact: (this._options.sounds.wallImpact ? new Audio(this._options.sounds.wallImpact) : false),
// win: (this._options.sounds.win ? new Audio(this._options.sounds.win) : false),
// loose: (this._options.sounds.loose ? new Audio(this._options.sounds.loose) : false)
},
mute: function () {
this._soundFx._muted = !this._soundFx._isMuted;
},
play: function (sound) {
if (!this._soundFx._muted && this._soundFx._store[sound] && this._soundFx._store[sound].canPlayType) {
this._soundFx._store[sound].play();
}
}
},
_update: function () {
window.console.count('tick');
},
_moveBall: function () {
},
_movePlayer1: function () {
},
_movePlayer2: function () {
},
_updateScore: function () {
},
attachTo: function (container) {
this._container = $(container);
},
start: function () {
this._ticker = window.setInterval(this._update, this._options.gameSpeed);
},
stop: function () {
window.clearInterval(this._ticker);
},
togglePause: function () {
if (this._ticker) {
window.clearInterval(this._ticker);
} else {
this._ticker = window.setInterval(this._update, this._options.gameSpeed);
}
}
};
return Pong;
});
@micmath
Copy link
Author

micmath commented Nov 21, 2011

var pong = new Pong();
pong._soundFX._store.start(); // <-- in here, what's "this"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment