QuickBox2D Tetris Pieces

import com.actionsnippet.qbox.*;

[SWF(backgroundColor=0x000000, width=700, height=600, frameRate=60)]

var sim:QuickBox2D = new QuickBox2D(this);

sim.setDefault({fillColor:0x003366, lineColor:0x2B80D5, isBullet:true});
sim.createStageWalls();

var shapes:Array = [];
shapes[0] = [[1,1,1,1]];
shapes[1] = [[1, 0, 0], [1, 1, 1]];
shapes[2] = [[0, 0, 1], [1, 1, 1]];
shapes[3] = [[1, 1], [1, 1]];
shapes[4] = [[0, 1, 1], [1, 1, 0]];
shapes[5] = [[0, 1, 0], [1, 1, 1]];
shapes[6] = [[1, 1, 0], [0, 1, 1]];
var cols:Array = [0xFF0000,  0xFFFF00, 0xFF00FF, 0x0000FF, 0x00FF00,0x00FFFF, 0x00FF00,0xFAA703];
var angs:Array =  [0, Math.PI / 2, Math.PI, Math.PI + Math.PI / 2];
var bev:BevelFilter = new BevelFilter();
with (bev) blurX = 10, blurY = 10, strength = 0.5;

var inc:int = 9;
for (var i:int = 0; i<shapes.length; i++){
	sim.setDefault({fillColor:cols[inc % cols.length]});
	inc++
	makePiece(shapes[i], 3 + i * 3, 3);
	sim.setDefault({fillColor:cols[inc % cols.length]});
	inc++
	makePiece(shapes[i], 3 + i * 3, 8);
}

function makePiece(pattern:Array, xp:Number, yp:Number, scale:Number = 0.7):QuickObject{
	var parts:Array = [];
	for (var i:int = 0; i<pattern.length; i++){
		for (var j:int = 0; j<pattern[i].length; j++){
			if (pattern[i][j] == 1){
				parts.push(sim.addBox({x:j * scale, y:i * scale, width:scale, height:scale, restitution:0, friction:1, isBullet:true}));
			}
		}
	}
	var ang:Number = angs[int(Math.random()*angs.length)];
	var piece:QuickObject =  sim.addGroup({objects:parts, x:xp, y:yp, angle:ang});
	
	piece.userData.filters = [bev];
	return piece;
}

sim.start();
sim.mouseDrag();

This snippet uses the QuickBox2D library to create some Tetris pieces.


Have a look at the swf here…

3 comments

  1. Hi Zevon

    I have been getting the error

    Type was not found or was not a compile-time constant:QuickObject

    function makePiece(pattern:Array, xp:Number, yp:Number, scale:Number = 0.7):QuickObject{

Leave a Reply

Your email address will not be published. Required fields are marked *