|
| 1 | +/** |
| 2 | +* @author Richard Davey <rich@photonstorm.com> |
| 3 | +* @copyright 2015 Photon Storm Ltd. |
| 4 | +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} |
| 5 | +*/ |
| 6 | + |
| 7 | +/** |
| 8 | +* |
| 9 | +* TODO: Gradient generator |
| 10 | +* TODO: Look at bsfxr for audio gen |
| 11 | +* TODO: Dither support |
| 12 | +* |
| 13 | +* @class Phaser.Create |
| 14 | +* @constructor |
| 15 | +* @param {Phaser.Game} game - Game reference to the currently running game. |
| 16 | + */ |
| 17 | +Phaser.Create = function (game) { |
| 18 | + |
| 19 | + /** |
| 20 | + * @property {Phaser.Game} game - A reference to the currently running Game. |
| 21 | + */ |
| 22 | + this.game = game; |
| 23 | + |
| 24 | + this.bmd = game.make.bitmapData(); |
| 25 | + |
| 26 | + this.canvas = this.bmd.canvas; |
| 27 | + this.ctx = this.bmd.context; |
| 28 | + |
| 29 | + // http://androidarts.com/palette/16pal.htm |
| 30 | + |
| 31 | + this.palettes = { |
| 32 | + 'arne': { 0: '#000000', 1: '#9D9D9D', 2: '#FFFFFF', 3: '#BE2633', 4: '#E06F8B', 5: '#493C2B', 6: '#A46422', 7: '#EB8931', 8: '#F7E26B', 9: '#2F484E', A: '#44891A', B: '#A3CE27', C: '#1B2632', D: '#005784', E: '#31A2F2', F: '#B2DCEF' }, |
| 33 | + 'jmp': { 0: '#000000', 1: '#191028', 2: '#46af45', 3: '#a1d685', 4: '#453e78', 5: '#7664fe', 6: '#833129', 7: '#9ec2e8', 8: '#dc534b', 9: '#e18d79', A: '#d6b97b', B: '#e9d8a1', C: '#216c4b', D: '#d365c8', E: '#afaab9', F: '#f5f4eb' }, |
| 34 | + 'cga': { 0: '#000000', 1: '#2234d1', 2: '#0c7e45', 3: '#44aacc', 4: '#8a3622', 5: '#5c2e78', 6: '#aa5c3d', 7: '#b5b5b5', 8: '#5e606e', 9: '#4c81fb', A: '#6cd947', B: '#7be2f9', C: '#eb8a60', D: '#e23d69', E: '#ffd93f', F: '#fffff' } |
| 35 | + }; |
| 36 | + |
| 37 | +}; |
| 38 | + |
| 39 | +Phaser.Create.prototype = { |
| 40 | + |
| 41 | + texture: function (key, data, pixelWidth, pixelHeight, palette) { |
| 42 | + |
| 43 | + if (typeof pixelWidth === 'undefined') { pixelWidth = 8; } |
| 44 | + if (typeof pixelHeight === 'undefined') { pixelHeight = 8; } |
| 45 | + if (typeof palette === 'undefined') { palette = 'arne'; } |
| 46 | + |
| 47 | + var w = data[0].length * pixelWidth; |
| 48 | + var h = data.length * pixelHeight; |
| 49 | + |
| 50 | + this.bmd.resize(w, h); |
| 51 | + |
| 52 | + // Draw it |
| 53 | + for (var y = 0; y < data.length; y++) |
| 54 | + { |
| 55 | + var row = data[y]; |
| 56 | + |
| 57 | + for (var x = 0; x < row.length; x++) |
| 58 | + { |
| 59 | + var d = row[x]; |
| 60 | + |
| 61 | + if (d !== '.' && d !== ' ') |
| 62 | + { |
| 63 | + this.ctx.fillStyle = this.palettes[palette][d]; |
| 64 | + this.ctx.fillRect(x * pixelWidth, y * pixelHeight, pixelWidth, pixelHeight); |
| 65 | + } |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + return this.bmd.generateTexture(key); |
| 70 | + |
| 71 | + }, |
| 72 | + |
| 73 | + grid: function (key, width, height, cellWidth, cellHeight, color) { |
| 74 | + |
| 75 | + this.bmd.resize(width, height); |
| 76 | + |
| 77 | + this.ctx.fillStyle = color; |
| 78 | + |
| 79 | + for (var y = 0; y < height; y += cellHeight) |
| 80 | + { |
| 81 | + this.ctx.fillRect(0, y, width, 1); |
| 82 | + } |
| 83 | + |
| 84 | + for (var x = 0; x < width; x += cellWidth) |
| 85 | + { |
| 86 | + this.ctx.fillRect(x, 0, 1, height); |
| 87 | + } |
| 88 | + |
| 89 | + return this.bmd.generateTexture(key); |
| 90 | + |
| 91 | + } |
| 92 | + |
| 93 | +}; |
| 94 | + |
| 95 | +Phaser.Create.prototype.constructor = Phaser.Create; |
0 commit comments