Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Eemeli Kelokorpi committed Feb 15, 2014
2 parents 36bc042 + 55b3450 commit 62521e6
Show file tree
Hide file tree
Showing 8 changed files with 306 additions and 157 deletions.
10 changes: 2 additions & 8 deletions src/engine/build.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
var UglifyJS = require('uglify-js');
var fs = require('fs');
var i, file, size, result;
var i, file, size, result, totalSize = 0;

var outputFile = process.argv[2] || 'game.min.js';
var outputDir = process.argv[3] || './';
var header = '// Made with Panda.js - http://www.pandajs.net';
var totalSize = 0;
var include = ['engine/core.js', 'game/main.js'];
var exclude = ['engine/debug.js'];
var dir = process.cwd() + '/src/';

global['game'] = {};
Expand Down Expand Up @@ -36,10 +34,6 @@ for (i = 0; i < include.length; i++) {
require(dir + include[i]);
}

for (var i = game.modules.length - 1; i >= 0; i--) {
if(exclude.indexOf(game.modules[i]) !== -1) game.modules.splice(i, 1);
}

for (i = 0; i < game.modules.length; i++) {
file = game.modules[i];
game.modules[i] = dir + game.modules[i];
Expand All @@ -52,7 +46,7 @@ console.log('Total ' + totalSize + ' bytes');

result = UglifyJS.minify(game.modules);

result.code = header + '\n' + 'window.pandaMinified = true;' + '\n' + result.code;
result.code = header + '\n' + result.code;

fs.writeFile(outputDir + outputFile, result.code, function(err) {
if(err) console.log(err);
Expand Down
18 changes: 10 additions & 8 deletions src/engine/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ var core = {
@property {game.Storage} storage
**/
storage: null,
/**
Instance of {{#crossLink "game.Keyboard"}}{{/crossLink}}.
@property {game.Keyboard} keyboard
**/
keyboard: null,
/**
Device / browser detection.
Expand Down Expand Up @@ -119,7 +124,7 @@ var core = {
!object || typeof(object) !== 'object' ||
object instanceof HTMLElement ||
object instanceof game.Class ||
object instanceof game.Container
(game.Container && object instanceof game.Container)
) {
return object;
}
Expand Down Expand Up @@ -258,8 +263,6 @@ var core = {
});
**/
module: function(name, version) {
if(name === 'engine.debug' && window.pandaMinified) return this;

if(this._current) throw('Module ' + this._current.name + ' has no body');
if(this.modules[name] && this.modules[name].body) throw('Module ' + name + ' is already defined');

Expand All @@ -277,7 +280,6 @@ var core = {
require: function() {
var i, modules = Array.prototype.slice.call(arguments);
for (i = 0; i < modules.length; i++) {
if(modules[i] === 'engine.debug' && window.pandaMinified) continue;
if(modules[i]) this._current.requires.push(modules[i]);
}
return this;
Expand Down Expand Up @@ -308,12 +310,12 @@ var core = {
height = height || (game.System.orientation === game.System.PORTRAIT ? 927 : 672);

this.system = new game.System(width, height, canvasId);
this.sound = new game.SoundManager();
this.pool = new game.Pool();
if(game.SoundManager) this.sound = new game.SoundManager();
if(game.Pool) this.pool = new game.Pool();
if(game.Debug && game.Debug.enabled && !navigator.isCocoonJS) this.debug = new game.Debug();
if(game.DebugDraw && game.DebugDraw.enabled) this.debugDraw = new game.DebugDraw();
if(game.Storage.id) this.storage = new game.Storage(game.Storage.id);
if(game.Analytics.id) this.analytics = new game.Analytics(game.Analytics.id);
if(game.Storage && game.Storage.id) this.storage = new game.Storage(game.Storage.id);
if(game.Analytics && game.Analytics.id) this.analytics = new game.Analytics(game.Analytics.id);

this.ready = true;

Expand Down
5 changes: 4 additions & 1 deletion src/engine/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@ game.DebugDraw = game.Class.extend({
var sprite = new game.Graphics();
sprite.beginFill(game.DebugDraw.shapeColor);

// TODO add support for game.Circle and game.Line
if(body.shape instanceof game.Rectangle) {
sprite.drawRect(-body.shape.width/2, -body.shape.height/2, body.shape.width, body.shape.height);
}
if(body.shape instanceof game.Circle) {
sprite.drawCircle(0, 0, body.shape.radius);
}
// TODO add support for game.Line

sprite.target = body;
sprite.alpha = game.DebugDraw.shapeAlpha;
Expand Down
245 changes: 245 additions & 0 deletions src/engine/keyboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
/**
@module keyboard
@namespace game
**/
game.module(
'engine.keyboard'
)
.body(function() {

/**
Instance automatically created at {{#crossLink "game.Core"}}{{/crossLink}}
@class Keyboard
@extends game.Class
**/
game.Keyboard = game.Class.extend({
/**
List of keys.
BACKSPACE
TAB
ENTER
SHIFT
CTRL
ALT
PAUSE
CAPS_LOCK
ESC
SPACE
PAGE_UP
PAGE_DOWN
END
HOME
LEFT
UP
RIGHT
DOWN
PRINT_SCREEN
INSERT
DELETE
ZERO
ONE
TWO
THREE
FOUR
FIVE
SIX
SEVEN
EIGHT
NINE
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
NUM_ZERO
NUM_ONE
NUM_TWO
NUM_THREE
NUM_FOUR
NUM_FIVE
NUM_SIX
NUM_SEVEN
NUM_EIGHT
NUM_NINE
NUM_MULTIPLY
NUM_PLUS
NUM_MINUS
NUM_PERIOD
NUM_DIVISION
F1
F2
F3
F4
F5
F6
F7
F8
F9
F10
F11
F12
@property {Array} keys
**/
keys: [],
/**
List of keys, that are pressed down.
@property {Array} keysDown
**/
keysDown: [],

init: function() {
this.keys[8] = 'BACKSPACE';
this.keys[9] = 'TAB';
this.keys[13] = 'ENTER';
this.keys[16] = 'SHIFT';
this.keys[17] = 'CTRL';
this.keys[18] = 'ALT';
this.keys[19] = 'PAUSE';
this.keys[20] = 'CAPS_LOCK';
this.keys[27] = 'ESC';
this.keys[32] = 'SPACE';
this.keys[33] = 'PAGE_UP';
this.keys[34] = 'PAGE_DOWN';
this.keys[35] = 'END';
this.keys[36] = 'HOME';
this.keys[37] = 'LEFT';
this.keys[38] = 'UP';
this.keys[39] = 'RIGHT';
this.keys[40] = 'DOWN';
this.keys[44] = 'PRINT_SCREEN';
this.keys[45] = 'INSERT';
this.keys[46] = 'DELETE';
this.keys[48] = 'ZERO';
this.keys[49] = 'ONE';
this.keys[50] = 'TWO';
this.keys[51] = 'THREE';
this.keys[52] = 'FOUR';
this.keys[53] = 'FIVE';
this.keys[54] = 'SIX';
this.keys[55] = 'SEVEN';
this.keys[56] = 'EIGHT';
this.keys[57] = 'NINE';
this.keys[65] = 'A';
this.keys[66] = 'B';
this.keys[67] = 'C';
this.keys[68] = 'D';
this.keys[69] = 'E';
this.keys[70] = 'F';
this.keys[71] = 'G';
this.keys[72] = 'H';
this.keys[73] = 'I';
this.keys[74] = 'J';
this.keys[75] = 'K';
this.keys[76] = 'L';
this.keys[77] = 'M';
this.keys[78] = 'N';
this.keys[79] = 'O';
this.keys[80] = 'P';
this.keys[81] = 'Q';
this.keys[82] = 'R';
this.keys[83] = 'S';
this.keys[84] = 'T';
this.keys[85] = 'U';
this.keys[86] = 'V';
this.keys[87] = 'W';
this.keys[88] = 'X';
this.keys[89] = 'Y';
this.keys[90] = 'Z';
this.keys[96] = 'NUM_ZERO';
this.keys[97] = 'NUM_ONE';
this.keys[98] = 'NUM_TWO';
this.keys[99] = 'NUM_THREE';
this.keys[100] = 'NUM_FOUR';
this.keys[101] = 'NUM_FIVE';
this.keys[102] = 'NUM_SIX';
this.keys[103] = 'NUM_SEVEN';
this.keys[104] = 'NUM_EIGHT';
this.keys[105] = 'NUM_NINE';
this.keys[106] = 'NUM_MULTIPLY';
this.keys[107] = 'NUM_PLUS';
this.keys[109] = 'NUM_MINUS';
this.keys[110] = 'NUM_PERIOD';
this.keys[111] = 'NUM_DIVISION';
this.keys[112] = 'F1';
this.keys[113] = 'F2';
this.keys[114] = 'F3';
this.keys[115] = 'F4';
this.keys[116] = 'F5';
this.keys[117] = 'F6';
this.keys[118] = 'F7';
this.keys[119] = 'F8';
this.keys[120] = 'F9';
this.keys[121] = 'F10';
this.keys[122] = 'F11';
this.keys[123] = 'F12';

window.addEventListener('keydown', this.keydown.bind(this), false);
window.addEventListener('keyup', this.keyup.bind(this), false);
},

/**
@method keydown
**/
keydown: function(event) {
if(game.Keyboard.preventDefault) event.preventDefault();

if(!this.keys[event.keyCode]) return; // unkown key
if(this.keysDown[this.keys[event.keyCode]]) return; // key already down

this.keysDown[this.keys[event.keyCode]] = true;
if(game.scene) game.scene.keydown(this.keys[event.keyCode]);
},

/**
@method keyup
**/
keyup: function(event) {
if(game.Keyboard.preventDefault) event.preventDefault();

this.keysDown[this.keys[event.keyCode]] = false;
if(game.scene) game.scene.keyup(this.keys[event.keyCode]);
},

/**
Check if key is pressed down.
@method down
@return {Boolean}
**/
down: function(key) {
return (this.keysDown[key]);
}
});

/**
Prevent default keyboard action.
@attribute {Boolean} preventDefault
@default false
**/
game.Keyboard.preventDefault = false;

game.keyboard = new game.Keyboard();

});
16 changes: 9 additions & 7 deletions src/engine/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,21 @@ game.Loader = game.Class.extend({
game.system.stage.addChild(this.text);

var imageData = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJMAAACDCAMAAAC+7dm8AAAAolBMVEUAAAAjHyAjHyAjHyAjHyAjHyAjHyAjHyAjHyAmIiMjHyAjHyAjHyAjHyAjHyAjHyAjHyAjHyAjHyD////m5+grKCn8/Pz3+PgzMDH09PVKR0jw8fGenp7t7u6ko6SqqapTUVLLy8zY2Nnq6uvj4+Q5NjhkYmNcWltAPT+Qj5CBf4B6eXqXlpfe3t9zcnPEw8RsamyHhoe8vL22tbbS0tKvr7CGaULPAAAAEnRSTlMAg3FU0uK/ChX+QzIj8LGdkWTaWSIZAAALGUlEQVR42r1c2ZaiMBBFRXFfIiAqsijI5or6/782rSyBVAJRu+c+zDndQ8dL1U1tAYVfQHfQajYmY7E9QilGbXE8bbYGkvBfIQ37CZMRqkB73GgNhT+HNJg1xiJ6A71x8w95dVtTEX2EdmMg/AGGTSYfRdNcLYWCGBCb0i97rNVBAK4VBebNPjryD3br5XKxWG52snPc3s/xwwjCk+eXKE6Hv8ioSSpZsa6PrZxit16ocxZ2thl6ObNJ97cYkfY5PRw5A+ZTAXWr71Nejd/wYL9dttDlJufYLObcWMSnF612/2sjTcsmCo4ydpk6fw9Lw3/J6jtTDdslRrqDGS3nH0C9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1lXeJrgfdfNzi+Gyfz7ERRJe9tXKJ8ac4bra6UuazPsi7/Gj1sufuxgi1Pvp2nHZn2uxnOz4fVCBx9sVXKeW6ElOD9ZvTsdhGVRi1xc5k2pi1BkRubWerSML3EKEApC6GJGU/SZWf1km0/SvoJ0L4Gq1ZS/g9UmJX+C/4BxGsxy8xC3cVAAAAAElFTkSuQmCC';
if(game.ua.ie) imageData += '?' + Date.now();
if(game.device.ie) imageData += '?' + Date.now();
this.symbol = new game.Sprite(game.system.width/2 - 8, game.system.height/2 + 70, PIXI.Texture.fromImage(imageData, true), {
anchor: {x: 0.5, y: 1.0},
rotation: -0.1
});
game.system.stage.addChild(this.symbol);

var tween = new game.Tween(this.symbol, {rotation: 0.1}, 0.5, {
easing: game.Tween.Easing.Cubic.InOut,
loop: game.Tween.Loop.Reverse
});
this.tweens.push(tween);
tween.start();
if(game.Tween) {
var tween = new game.Tween(this.symbol, {rotation: 0.1}, 0.5, {
easing: game.Tween.Easing.Cubic.InOut,
loop: game.Tween.Loop.Reverse
});
this.tweens.push(tween);
tween.start();
}
},

getPath: function(path) {
Expand Down
Loading

0 comments on commit 62521e6

Please sign in to comment.