Skip to content

Instantly share code, notes, and snippets.

@Cogentx
Created May 17, 2019 02:58
Show Gist options
  • Save Cogentx/10e629067dd643885de96e2602567e69 to your computer and use it in GitHub Desktop.
Save Cogentx/10e629067dd643885de96e2602567e69 to your computer and use it in GitHub Desktop.
Bejeweled - default
<footer><div id=version></div></footer>
class Demo extends Phaser.Scene {
constructor() {
super({
key: 'examples'
})
}
preload() {}
create() {
this.bejeweled = new rexbejeweled(this, {
board: {
grid: {
gridType: 'quadGrid',
x: 30,
y: 30 - 600,
cellWidth: 60,
cellHeight: 60,
type: 'orthogonal' // 'orthogonal'|'isometric'|'staggered'
},
width: 10,
height: 20 // Prepared rows: upper 10 rows
},
chess: {
// pick random symbol from array, or a callback to return symbol
symbols: [0, 1, 2, 3, 4, 5],
// User-defined chess game object
create: function (board) {
var scene = board.scene;
var gameObject = scene.rexBoard.add.shape(board, 0, 0, 0, 0x0, 1, false)
.setScale(0.95)
.setData('symbol', undefined);
// Symbol is stored in gameObject's data manager (`gameObject.getData('symbol')`)
// Add data changed event to change the appearance of game object via new symbol value
gameObject.data.events.on('changedata_symbol', function (gameObject, value, previousValue) {
gameObject.setFillStyle(getColor(value));
});
return gameObject;
},
// moveTo behavior
moveTo: {
speed: 400
},
},
});
this.bejeweled.start();
}
update() {}
}
var colorArray = Phaser.Display.Color.HSVColorWheel(0.5, 1);
var getColor = function (symbol) {
// symbols: [0, 1, 2, 3, 4, 5]
return colorArray[symbol * 60].color;
}
var config = {
type: Phaser.AUTO,
parent: 'phaser-example',
width: 800,
height: 600,
scene: Demo
};
var game = new Phaser.Game(config);
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/phaser.min.js"></script>
<script src="https://rawgit.com/rexrainbow/phaser3-rex-notes/master/plugins/dist/rexbejeweled.min.js"></script>
html, body {
height: 100%;
}
body {
margin: 0;
padding: 0;
background: #222;
color: #eee;
font: caption;
}
#version {
position: absolute;
left: 5px;
top: 605px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment