Skip to content

Instantly share code, notes, and snippets.

View pr00thmatic's full-sized avatar

pr00thmatic pr00thmatic

View GitHub Profile
@pr00thmatic
pr00thmatic / dog-definition.js
Last active August 29, 2015 14:15
execution context in module pattern
var dog = (function () {
var nombre = "dog";
var setName = function (newName) {
nombre = newName;
};
var speak = function () {
console.log('[' + nombre + ']: woof!');
};
@pr00thmatic
pr00thmatic / js-test.js
Last active August 29, 2015 14:15
js test
var a = (function () {
this.x = 100;
var a = 1;
var showX = function () {
console.log(this.x);
};
var setX = function () {
this.x = -100;
@pr00thmatic
pr00thmatic / .emacs part
Created January 27, 2015 22:10
.emacs for global keystrokes C-c C-c comment-region and C-c C-u uncomment-region
(defun comment-marked-region ()
"comments the marked region, just like M-x comment-region"
(interactive)
(comment-region (mark) (point)))
(defun uncomment-marked-region ()
"uncoments the marked region, just like M-x uncomment-region"
(interactive)
(uncomment-region-default (mark) (point)))
var Cat = { // this is actually an object: a "prototype" object
color: 'none',
size: 'none',
meow: function() {
console.log("meow");
}
};
var Garfield = Object.create(Cat); // this is a prototype object too
function update() {
game.physics.arcade.collide(uno, walls);
cursores = game.input.keyboard.createCursorKeys();
uno.animations.play('stand_' + lastDirection); // importante!! "uno" se queda quieto.
if(cursores.left.isDown) {
lastDirection = 'left';
uno.scale.x = -1;
uno.body.velocity.x = -1*velocity;
function move_x(alguien, dir) {
alguien.scale.x = dir;
alguien.body.velocity.x = dir*velocity;
lastDirection = 'right'; //right will be flipped if left
}
function move_y(alguien, dir) {
uno.body.velocity.y = dir*velocity;
if (dir > 0)
cursores = game.input.keyboard.createCursorKeys();
if(cursores.left.isDown) {
...
} else if (cursores.right.isDown) {
...
} else if (cursores.up.isDown) {
uno.body.velocity.y = -1;
uno.animations.play('front')
lastDirection = 'front';
cursores = game.input.keyboard.createCursorKeys();
if(cursores.left.isDown) {
lastDirection = 'left';
uno.scale.x = -1;
uno.body.velocity.x = -1*velocity;
uno.animations.play('right'); //uno.scale.x=-1 hace que right se voltee a left
} else if (cursores.right.isDown) {
lastDirection = 'right';
uno.scale.x = 1;
// Física
game.physics.arcade.enable(uno);
uno.collideWorldBounds = true;
//creando al personaje
uno = game.add.sprite(game.world.width/2-16,
game.world.height/2-16,
'uno');