Code edit (8 edits merged)
Please save this source code
User prompt
in up, in the last line of the dragTarget method call sortCellsByFilled on board
User prompt
add a new method to Board that sorts .children if they are instances of Cell. Such that cells with the value filled=true renders above cells with filled=false
User prompt
add a method to Board that sorts .children if they are instances of Cell. Such that cells with the value filled=true renders above cells with filled=false
User prompt
set background color to 80acc2
User prompt
When changing and using scores use the LK score methods
User prompt
move up board y by 30 px
User prompt
update brick y offsets to [2, -10, 2, 2, 2, -20]
Code edit (3 edits merged)
Please save this source code
User prompt
Instead of having the same array twice, create a top level variable of the brick y offset in cell
Code edit (1 edits merged)
Please save this source code
User prompt
set alpha on tileBackground to .5
User prompt
set tileBackground y to the height of the screen
User prompt
after gameBackground in game code, insert a new element wait the id tileBackground at. Make this be aligned at the bottom center of the screen
User prompt
set alpha on the background element to .5
Remix started
Copy Blockmas
===================================================================
--- original.js
+++ change.js
@@ -1,4 +1,7 @@
+/****
+* Classes
+****/
var Particle = Container.expand(function (tint) {
var self = Container.call(this);
self.tint = tint;
var particleGraphics = self.createAsset('particle', 'Particle Graphics', 0.5, 0.5);
@@ -11,9 +14,11 @@
self.tick = function () {
self.x += self.vx;
self.y += self.vy;
self.alpha -= 1 / self.lifetime;
- if (self.alpha <= 0) self.destroy();
+ if (self.alpha <= 0) {
+ self.destroy();
+ }
};
});
var Cell = Container.expand(function () {
var self = Container.call(this);
@@ -60,33 +65,33 @@
self.setFill(false);
});
var Block = Container.expand(function (board) {
var self = Container.call(this);
- var hsvToRgb = function (h, s, v) {
+ var hsvToRgb = function hsvToRgb(h, s, v) {
var r, g, b;
var i = Math.floor(h * 6);
var f = h * 6 - i;
var p = v * (1 - s);
var q = v * (1 - f * s);
var t = v * (1 - (1 - f) * s);
switch (i % 6) {
case 0:
- (r = v, g = t, b = p);
+ r = v, g = t, b = p;
break;
case 1:
- (r = q, g = v, b = p);
+ r = q, g = v, b = p;
break;
case 2:
- (r = p, g = v, b = t);
+ r = p, g = v, b = t;
break;
case 3:
- (r = p, g = q, b = v);
+ r = p, g = q, b = v;
break;
case 4:
- (r = t, g = p, b = v);
+ r = t, g = p, b = v;
break;
case 5:
- (r = v, g = p, b = q);
+ r = v, g = p, b = q;
break;
}
return (Math.round(r * 255) << 16) + (Math.round(g * 255) << 8) + Math.round(b * 255);
};
@@ -106,15 +111,19 @@
self.color = hsvToRgb(hue, 0.6, 1);
self.rotateShapeRandomly = function () {
var rotations = Math.floor(Math.random() * 4);
for (var r = 0; r < rotations; r++) {
- self.shape = self.shape[0].map((val, index) => self.shape.map(row => row[index]).reverse());
+ self.shape = self.shape[0].map(function (val, index) {
+ return self.shape.map(function (row) {
+ return row[index];
+ }).reverse();
+ });
}
};
self.rotateShapeRandomly();
self.blocks = [];
var background = self.createAsset('background', 'Background Graphics', .5, .5);
- background.alpha = 0;
+ background.alpha = 0.5;
var blockSize = 160;
background.width = 4 * blockSize;
background.height = 4 * blockSize;
self.addChild(background);
@@ -200,9 +209,13 @@
};
self.rotateShapeRandomly = function () {
var rotations = Math.floor(Math.random() * 4);
for (var r = 0; r < rotations; r++) {
- self.shape = self.shape[0].map((val, index) => self.shape.map(row => row[index]).reverse());
+ self.shape = self.shape[0].map(function (val, index) {
+ return self.shape.map(function (row) {
+ return row[index];
+ }).reverse();
+ });
}
};
});
var Board = Container.expand(function () {
@@ -216,9 +229,11 @@
this.particles.push(particle);
this.addChild(particle);
}
};
- self.grid = new Array(10).fill(null).map(() => new Array(10).fill(null));
+ self.grid = new Array(10).fill(null).map(function () {
+ return new Array(10).fill(null);
+ });
var size = 158;
var totalWidth = 10 * size;
var totalHeight = 10 * size;
for (var i = 0; i < 10; i++) {
@@ -244,10 +259,14 @@
for (var i = 0; i < 10; i++) {
var rowFilled = true;
var colFilled = true;
for (var j = 0; j < 10; j++) {
- if (!self.grid[i][j].filled) rowFilled = false;
- if (!self.grid[j][i].filled) colFilled = false;
+ if (!self.grid[i][j].filled) {
+ rowFilled = false;
+ }
+ if (!self.grid[j][i].filled) {
+ colFilled = false;
+ }
}
if (rowFilled || colFilled) {
rowsRemoved += (rowFilled ? 1 : 0) + (colFilled ? 1 : 0);
for (var j = 0; j < 10; j++) {
@@ -281,121 +300,137 @@
}
};
self.placeBlock = function () {};
});
-var Game = Container.expand(function () {
- var self = Container.call(this);
- var gameBackground = self.createAsset('gameBackground', 'Background Graphics', .5, .5);
- gameBackground.x = 2048 / 2;
- gameBackground.y = 2732 / 2 + 65;
- var blocks = [];
- var dragTarget;
- var board = self.addChild(new Board());
- board.x = 2048 / 2;
- board.y = 2732 / 2 - 250 + 30;
- var targetOffset;
- self.createBlock = function (index) {
- var block = new Block(board);
- block.x = 2048 / 2 + (index - 1) * (block.width + 30);
- block.y = 2732 + block.height;
- block.setStartPosition(block.x, 2732 - block.height / 2 - 30);
- blocks.push(block);
- self.addChild(block);
- block.on('down', function (obj) {
- dragTarget = this;
- var pos = obj.event.getLocalPosition(this);
- var targetPos = obj.event.getLocalPosition(self);
- this.targetX = pos.x;
- this.targetY = pos.y;
- dragTarget.move(targetPos.x, targetPos.y);
- });
- };
- stage.on('move', function (obj) {
- if (dragTarget) {
- board.removeTint();
- var pos = obj.event.getLocalPosition(self);
- dragTarget.move(pos.x, pos.y);
- dragTarget.showOverlap();
- }
+
+/****
+* Initialize Game
+****/
+var game = new LK.Game({
+ backgroundColor: 0x000000
+});
+
+/****
+* Game Code
+****/
+var gameBackground = game.createAsset('gameBackground', 'Background Graphics', .5, .5);
+gameBackground.x = 2048 / 2;
+gameBackground.y = 2732 / 2 + 65;
+var blocks = [];
+var dragTarget;
+var board = game.addChild(new Board());
+board.x = 2048 / 2;
+board.y = 2732 / 2 - 250 + 30;
+var targetOffset;
+game.createBlock = function (index) {
+ var block = new Block(board);
+ block.x = 2048 / 2 + (index - 1) * (block.width + 30);
+ block.y = 2732 + block.height;
+ block.setStartPosition(block.x, 2732 - block.height / 2 - 30);
+ blocks.push(block);
+ game.addChild(block);
+ block.on('down', function (obj) {
+ dragTarget = this;
+ var pos = obj.event.getLocalPosition(this);
+ var targetPos = obj.event.getLocalPosition(game);
+ this.targetX = pos.x;
+ this.targetY = pos.y;
+ dragTarget.move(targetPos.x, targetPos.y);
});
- stage.on('up', function (obj) {
- if (dragTarget) {
- var cells = dragTarget.getOverlappingCells();
- if (cells) {
- for (var a = 0; a < cells.length; a++) {
- cells[a].setFill(true, dragTarget.blocks[a], dragTarget.offset);
- cells[a].setTint(dragTarget.color);
- }
- blocks[blocks.indexOf(dragTarget)] = undefined;
- dragTarget.destroy();
- if (!blocks.some(block => block)) {
- self.createBlocks();
- }
- var pointsToAdd = board.checkLines();
- if (pointsToAdd) {
- score += Math.pow(pointsToAdd, 2) * 10;
- scoreTxt.setText(score);
- }
+};
+game.on('move', function (obj) {
+ if (dragTarget) {
+ board.removeTint();
+ var pos = obj.event.getLocalPosition(game);
+ dragTarget.move(pos.x, pos.y);
+ dragTarget.showOverlap();
+ }
+});
+game.on('up', function (obj) {
+ if (dragTarget) {
+ var cells = dragTarget.getOverlappingCells();
+ if (cells) {
+ for (var a = 0; a < cells.length; a++) {
+ cells[a].setFill(true, dragTarget.blocks[a], dragTarget.offset);
+ cells[a].setTint(dragTarget.color);
}
- board.removeTint();
- dragTarget = undefined;
+ blocks[blocks.indexOf(dragTarget)] = undefined;
+ dragTarget.destroy();
+ if (!blocks.some(function (block) {
+ return block;
+ })) {
+ game.createBlocks();
+ }
+ var pointsToAdd = board.checkLines();
+ if (pointsToAdd) {
+ score += Math.pow(pointsToAdd, 2) * 10;
+ scoreTxt.setText(score);
+ }
}
- });
- self.createBlocks = function () {
- for (var i = 0; i < 3; i++) {
- self.createBlock(i);
- }
- };
- var score = 0;
- self.createBlocks();
- var scoreTxt = new Text2('0', {
- size: 150,
- fill: "#ffffff",
- font: 'Impact',
- stroke: '#2a636e',
- strokeThickness: 16
- });
- scoreTxt.anchor.set(.5, 0);
- LK.gui.topCenter.addChild(scoreTxt);
- self.isMovePossible = function () {
- for (var a = 0; a < blocks.length; a++) {
- if (blocks[a]) {
- for (var i = 0; i < 10; i++) {
- for (var j = 0; j < 10; j++) {
- if (board.grid[i][j].filled) continue;
- var canPlace = true;
- for (var k = 0; k < blocks[a].shape.length; k++) {
- for (var l = 0; l < blocks[a].shape[k].length; l++) {
- if (blocks[a].shape[k][l] === 1) {
- if (i + k < 0 || i + k >= 10 || j + l < 0 || j + l >= 10 || board.grid[i + k][j + l].filled) {
- canPlace = false;
- break;
- }
+ board.removeTint();
+ dragTarget = undefined;
+ }
+});
+game.createBlocks = function () {
+ for (var i = 0; i < 3; i++) {
+ game.createBlock(i);
+ }
+};
+var score = 0;
+game.createBlocks();
+var scoreTxt = new Text2('0', {
+ size: 150,
+ fill: "#ffffff",
+ font: 'Impact',
+ stroke: '#2a636e',
+ strokeThickness: 16
+});
+scoreTxt.anchor.set(.5, 0);
+LK.gui.topCenter.addChild(scoreTxt);
+game.isMovePossible = function () {
+ for (var a = 0; a < blocks.length; a++) {
+ if (blocks[a]) {
+ for (var i = 0; i < 10; i++) {
+ for (var j = 0; j < 10; j++) {
+ if (board.grid[i][j].filled) {
+ continue;
+ }
+ var canPlace = true;
+ for (var k = 0; k < blocks[a].shape.length; k++) {
+ for (var l = 0; l < blocks[a].shape[k].length; l++) {
+ if (blocks[a].shape[k][l] === 1) {
+ if (i + k < 0 || i + k >= 10 || j + l < 0 || j + l >= 10 || board.grid[i + k][j + l].filled) {
+ canPlace = false;
+ break;
}
}
- if (!canPlace) break;
}
- if (canPlace) return true;
+ if (!canPlace) {
+ break;
+ }
}
+ if (canPlace) {
+ return true;
+ }
}
}
}
- return false;
- };
- var isGameOver = false;
- LK.on('tick', function () {
- board.tick();
- if (isGameOver || !self.isMovePossible()) {
- LK.effects.flashScreen(0xffffff, 1000);
- LK.showGameOver();
- }
- for (var a = blocks.length - 1; a >= 0; a--) {
- if (blocks[a]) {
- if (blocks[a] != dragTarget) {
- blocks[a].moveTowardsHomePosition();
- } else {
- blocks[a].moveToDragTarget();
- }
+ }
+ return false;
+};
+var isGameOver = false;
+LK.on('tick', function () {
+ board.tick();
+ if (isGameOver || !game.isMovePossible()) {
+ LK.effects.flashScreen(0xffffff, 1000);
+ LK.showGameOver();
+ }
+ for (var a = blocks.length - 1; a >= 0; a--) {
+ if (blocks[a]) {
+ if (blocks[a] != dragTarget) {
+ blocks[a].moveTowardsHomePosition();
+ } else {
+ blocks[a].moveToDragTarget();
}
}
- });
-});
+ }
+});
\ No newline at end of file
White square with tight round corners, flat shaded, hyper casual game. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
White particle cloud. Cartoon. Bright outline. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Perfectly square yellow Christmas decoration. Cartoon style. Cute art style. Simple vector style.
Perfectly square bright purple Christmas decoration with cute happyy face. Cartoon style. Cute art style. Simple vector style.
Perfectly square bright green game piece with cute happy face. Cartoon style. Cute art style. Simple vector style. No Shadows. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
No background
Perfectly square red game piece with cute happy face. Cartoon style. Cute art style. Simple vector style. No Shadows. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Perfectly square bright dark blue game piece with cute happy face. Cartoon style. Cute art style. Simple vector style. No Shadows. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows..