[原创]html5_PC游戏_图片俄罗斯方块
PC游戏_图片俄罗斯方块
以前的了,快一年了。。。
使用了离线canvas复制的方法,启动预览效果需要服务器支持
另外,AC娘图片可以自己做加载功能,这样游戏图片显示更顺畅
效果:
---
代码:
html:
<!DOCTYPE html>
<head>
<title>CGM001</title>
<script src="js/libs/jquery-1.11.0.js"></script>
<script src="js/libs/requestNextAnimationFrame.js"></script>
<script src="js/data/blockTypeData.js"></script>
<style>
body {
font-size:13px;
}
</style>
</head>
<body>
<h1 id="LoadH1" style="margin:auto;">加载图片中......</h1>
<div style="margin-top:20px;">
[方向键 <span style="color:blue;font-weight:bold;">左</span>:<span style="color:red;font-weight:bold;">左移</span>方块 <span style="color:blue;font-weight:bold;">右</span>:<span style="color:red;font-weight:bold;">右移</span>方块 <span style="color:blue;font-weight:bold;">上</span>:<span style="color:red;font-weight:bold;">旋转</span>方块 <span style="color:blue;font-weight:bold;">下</span>:<span style="color:red;font-weight:bold;">下移</span>方块]
<br />
<span style="color:red;font-weight:bold">当下落位置不正确时,会重新下落该方块。</span>
</div>
<div style="position:absolute;left:10px;bottom:10px; text-align:center">
<br />
版权所有©王欣盛
<a href="mailTo:wangxsh42@126.com">wangxsh42@126.com</a>
制作时间:2014/04/14 ~ 2014/04/18
</div>
</body>
<script src="js/entity/canvas_Entity.js"></script>
<script src="js/entity/block_Entity.js"></script>
<script src="js/entity/blocks_Entity.js"></script>
<script src="js/action/CGM001_Action.js"></script>
</html>
js:
Action:
//score
var maxFail = 200;
var maxMsg = "无解了?还是你没好好玩?";
var stsId = "stsId";
var countId = "countId";
var failCountId = "failCountId";
var fixCountId = "fixCountId"; var countB = 0;
var currB = 0;
var failB = 0;
var fixB = 0; //acNiang
var acSrc = "";
var acNiangId = "acNiangId";
var goodSize = 9;
var failSize = 24;
var nomalSize = 19;
var acRootPath = "imgs/acNiang/";
var goodPath = "good";
var failPath = "fail";
var nomalPath = "nomal";
var defaultPath = "imgs/acNiang/nomal0.png"; // background image
var goMax = 27;
var image;
var imageBG;
var bgColor;
var bgColorLst = [
"#E0FFFF",
"#FFC0CB",
"#9932CC",
"#90EE90",
"#7B68EE",
"#4169E1",
"#C0C0C0",
"#7CFC00"
];
var bgId = "bgDiv";
//canvas
var abs = "absolute";
var width = 400;
var height = 600;
var x = 10;
var y = 10;
var idC = "CGM001Canvas";
var idCOff = "CGM001OffCanvas";
var idCOffBG = "CGM001OffBGCanvas";
var idCOffAnimation = "CGM001OffCanvasAnimation";
var CGM001canvasObj = null;
var CGM001canvasOffObj = null;
var CGM001canvasOffBGObj = null;
var CGM001canvasOffObjAnimation = null;
var CGM001canvasParent = "body";
var border = "1px red solid";
border = "none";
//picture
var picWidth = width;
var picHeight = height;
//block
var blockCol = 10;
var blockRow = 15;
var blockWidth = picWidth / blockCol;
var blockHeight = picHeight / blockRow;
var blockSize = blockWidth < blockHeight ? blockWidth : blockHeight;
//blockLst
var blockLst = [];
var blockBoxLst = []; // to judge weather blockPos Right and isempty
var cuttedBlocksLst = [];
//blocks order
var blocksOrderRow = [];
var blocksOrderCol = []; $(function () {
CGM001canvasObj = createCanvas(abs,x,y,width,height,idC,CGM001canvasParent,border,false,CGM001canvasObj);
CGM001canvasOffObj = createCanvas(abs, x + width + 20, y, width, height, idCOff, CGM001canvasParent, border, false, CGM001canvasOffObj);
CGM001canvasOffBGObj = createCanvas(abs, x, y, width, height, idCOffBG, CGM001canvasParent, border, true, CGM001canvasOffBGObj);
CGM001canvasOffObjAnimation = createCanvas(abs, x + width * 2 + 20, y, width, height, idCOffAnimation, CGM001canvasParent, border, true, CGM001canvasOffObjAnimation); /* imageBG = new Image();
imageBG.src = 'imgs/bg.jpg';
imageBG.onload = function (e) {
CGM001canvasOffObjAnimation.context.drawImage(imageBG, 0, 0, picWidth, picHeight);
drawPic();
calcBlockLst();
}*/ drawPic();
calcBlockLst();
}); function createBgColor(abs, x, y, width, height, bgId, hideFlg) {
var bgStr = "<div id='" + bgId + "' width='" + width + "' height='" + height + "' style='position:" + abs + ";left:" + x + "px;top:" + y + "px;background:" + bgColor + ";'></div>";
var bgOgj = $(bgStr);
$(CGM001canvasParent).append(bgOgj.width(width).height(height).css('opacity', '0.2'));
} function createScoreDiv(abs, x, y, width, height, bgId, hideFlg) {
var tmpLeft = parseInt(x) + parseInt(width) - 75;
var tmpTop = parseInt(y) + 40;
var imgDivStr = "<div id='scoreId' style='position:" + abs + ";left:" + tmpLeft + "px;top:" + tmpTop + "px;text-align:left;'></div>"
var imgStr = "<img width='75' height='65' src='" + defaultPath + "' id='" + acNiangId + "' />";
var tmpStsWidth = 100;
var stsStr = "<div width='" + tmpStsWidth + "' height='65' style='font-weight:bold; position:relative;right:" + 0 + "px;top:-50px;' id='" + stsId + "' >" +
"方块:<span id='" + countId + "' style='color:red;'>第 " + currB + " 块/共 " + countB + " 块</span>" +
"<br />失败次数:<span id='" + failCountId + "' style='color:red;'>" + failB + "</span> 块" +
"<br />已固定:<span id='" + fixCountId + "' style='color:red;'>" + fixB + "</span> 块" +
"</div>";
var tmpObj = $(imgDivStr).append($(imgStr));
tmpObj.append($(stsStr));
$(CGM001canvasParent).append(tmpObj);
$("#" + stsId).css({ 'left': ($("#" + stsId).width() + 100) * -1 });
}; function createCanvas(abs,x,y,width,height,idC,CGM001canvasParent,border,hideFlg,canvasObj){
canvasObj = new CGM001_canvas(abs,x,y,width,height,idC,CGM001canvasParent,border,hideFlg);
canvasObj.create();
canvasObj.init();
return canvasObj;
}
function clearCanvas(){
CGM001canvasObj.context.clearRect(0,0,CGM001canvasObj.width,CGM001canvasObj.height);
}
function drawPic() {
image = new Image();
image.src = 'imgs/goImg/go'+parseInt(Math.random()*goMax)+'.jpg';
image.onload = function(e) {
$("#LoadH1").hide(); bgColor = bgColorLst[parseInt(Math.random() * bgColorLst.length - 1)];
createBgColor(abs, x, y, width, height, bgId, false);
createScoreDiv(abs, x, y, width, height, bgId, false); CGM001canvasObj.context.drawImage(image, 0, 0, picWidth, picHeight);
CGM001canvasOffObj.context.putImageData(CGM001canvasObj.context.getImageData(0,0,CGM001canvasObj.width,CGM001canvasObj.height),0,0);
CGM001canvasOffBGObj.context.putImageData(CGM001canvasObj.context.getImageData(0,0,CGM001canvasObj.width,CGM001canvasObj.height),0,0);
cutPic(); countB = cuttedBlocksLst.length;
$("#" + countId).html("第 " + currB + " 块/共 " + countB + " 块");
$("#" + stsId).css({ 'left': ($("#" + stsId).width() + 10) * -1 }); if(cuttedBlocksLst.length>0){
initList();
clearCanvas();
$(document).keydown(function (event) { onKeyUp(event); });
animate();
}
/*for(var i = 0 ;i < blockLst.length; i ++){
blockLst[i].draw();
}*/
};
} function calcBlockLst(){
var w = blockSize * blockCol;
var wc = picWidth - w;
var h = blockSize * blockRow;
var hc = picHeight - h;
var s = blockSize;
var r = blockRow;
var c = blockCol; blockLst = [];
for(i = r - 1; i >= 0; i--){
for(j = c - 1; j >= 0; j--){
blockLst.push(new CGM001_block(s, (s * j) + wc, (s * i) + hc, "rgba(255,0,0,0.2)", "blue", CGM001canvasObj.context, i, j, CGM001canvasOffObj.context));
blockBoxLst.push({x: (s * j) + wc,y:(s * i) + hc,empty:true});
}
}
} function cutPic(){
var colorLst = [
"rgba(255,0,0,0.1)",
"rgba(0,255,0,0.1)",
"rgba(0,0,255,0.1)",
"rgba(197,144,144,0.1)",
"rgba(209,207,66,0.1)",
"rgba(150,209,66,0.1)",
"rgba(66,209,147,0.1)",
"rgba(66,194,209,0.1)",
"rgba(157,66,209,0.1)",
"rgba(209,66,187,0.1)",
"rgba(176,133,141,0.1)"
];
var time = 0;
var picCutfinish = false;
while(time<200){ for(var i = 0 ;i < blockLst.length; i ++){
blockLst[i].cutted = false;
} //console.log(time);
cuttedBlocksLst = [];
var cutOverNum = 0;
var r = blockRow - 1;
var c = blockCol - 1;
var maxR = r;
var maxC = c;
var goOn = true;
var blocks = null;
var stop = 1;
var rx = maxR - r;
var cx = maxC - c;
var goR = rx;
var goC = cx;
var randomBlockLst = [];
while(goOn){
//stop ++;
var randomLst = []; if(null == blocks){
blocks = new CGM001_blocks(CGM001canvasObj.context);
} var colorIndex = cuttedBlocksLst.length % colorLst.length; var blockTmp = blockLst[rx*blockCol+cx];
if(!blockTmp.cutted){
blocks.blockLst.push(blockTmp);
//console.log("blockTmp",blockTmp.x1,blockTmp.x2);
blockTmp.cutted = true;
blockTmp.setFillColor(colorLst[colorIndex]);
cutOverNum++;
if(blocks.blockLst.length % 4 == 0){
cuttedBlocksLst.push(blocks);
blocks = null;
while(blockLst[goR*blockCol+goC].cutted){
//console.log("go",goC,maxC,goR);
goR = goC >= maxC ? goR + 1 : goR;
goC = goC >= maxC ? 0 : goC +1;
if(goC == maxC && goR == maxR){break;}
}
rx = goR;
cx = goC;
randomBlockLst = [];
//console.log("goEnd",rx,cx);
continue;
//break;
} // T
//if(blocks.blockLst.length % 4 != 0){
if(Math.random()>0.3){
randomBlockLst.push({r:rx,c:cx});
var randomBlockLstTmp = [];
for(checkIndex = 0; checkIndex < randomBlockLst.length; checkIndex++){
var rTmp = randomBlockLst[checkIndex].r;
var cTmp = randomBlockLst[checkIndex].c;
var canMoveFlg = false; if(rTmp != maxR && !blockLst[(rTmp+1)*blockCol+cTmp].cutted) // up
canMoveFlg = true;
if(rTmp != 0 && !blockLst[(rTmp-1)*blockCol+cTmp].cutted) // down
canMoveFlg = true;
if(cTmp != maxC && !blockLst[(rTmp)*blockCol+cTmp+1].cutted){ // left
var leftGo = true;
if(cTmp == maxC - 1 && rTmp!=0 && blocks.blockLst.length % 3 == 0){
if(!blockLst[(rTmp-1)*blockCol+cTmp+1].cutted)
leftGo = false;
}
if(leftGo)
canMoveFlg = true;
}
if(cTmp != 0 && !blockLst[(rTmp)*blockCol+cTmp-1].cutted) // right
canMoveFlg = true;
if(canMoveFlg){
randomBlockLstTmp.push(randomBlockLst[checkIndex]);
}
}
randomBlockLst = randomBlockLstTmp;
//console.log(randomBlockLst);
if(randomBlockLst.length==1){
rx = randomBlockLst[0].r;
cx = randomBlockLst[0].c;
}else if(randomBlockLst.length>1){
var blockI = parseInt(Math.random() * (randomBlockLst.length-1));
rx = randomBlockLst[blockI].r;
cx = randomBlockLst[blockI].c;
}
}else{
//randomBlockLst = [];
} }
if(rx != maxR && !blockLst[(rx+1)*blockCol+cx].cutted) // up
//if(rx+1>=maxR || blockLst[(rx+2)*blockCol+cx].cutted || (cx < maxC && !blockLst[(rx+2)*blockCol+cx+1].cutted) || (cx>0 && !blockLst[(rx+2)*blockCol+cx-1].cutted))
randomLst.push({r:1,c:0});
if(rx != 0 && !blockLst[(rx-1)*blockCol+cx].cutted) // down
//if(rx-1<=0 || blockLst[(rx-2)*blockCol+cx].cutted || (cx < maxC && !blockLst[(rx-2)*blockCol+cx+1].cutted) || (cx>0 && !blockLst[(rx-2)*blockCol+cx-1].cutted))
randomLst.push({r:-1,c:0});
if(cx != maxC && !blockLst[(rx)*blockCol+cx+1].cutted){ // left
var leftGo = true;
if(cx == maxC - 1 && rx!=0 && blocks.blockLst.length % 3 == 0){
if(!blockLst[(rx-1)*blockCol+cx+1].cutted)
leftGo = false;
}
if(leftGo)
//if(cx+1>=maxC || blockLst[(rx)*blockCol+cx+2].cutted || (rx < maxC && !blockLst[(rx+1)*blockCol+cx+2].cutted) || (rx>0 && !blockLst[(rx-1)*blockCol+cx+2].cutted))
randomLst.push({r:0,c:1});
}
if(cx != 0 && !blockLst[(rx)*blockCol+cx-1].cutted) // right
//if(cx-1<=0 || blockLst[(rx)*blockCol+cx-2].cutted || (rx < maxC && !blockLst[(rx+1)*blockCol+cx-2].cutted) || (rx>0 && !blockLst[(rx-1)*blockCol+cx-2].cutted))
randomLst.push({r:0,c:-1});
if(randomLst.length == 1)
{
rx += randomLst[0].r;
cx += randomLst[0].c;
}else if(randomLst.length > 1){
var i = parseInt(Math.random() * randomLst.length);
rx += randomLst[i].r;
cx += randomLst[i].c;
}else if(randomLst.length == 0){
goOn = false;
} if(cutOverNum >= blockLst.length){
goOn = false;
picCutfinish = true;
}
//if(stop >= 101){goOn = false;}
}
//console.log(cuttedBlocksLst);
//test to draw all blocks
for(i=0;i<cuttedBlocksLst.length;i++){
for (j=0; j<cuttedBlocksLst[i].blockLst.length; j++)
{
cuttedBlocksLst[i].blockLst[j].draw();
}
}
// big while to finish all loop
if(picCutfinish){
console.log(time);
break;
}else{
CGM001canvasObj.context.clearRect(0,0,CGM001canvasObj.width,CGM001canvasObj.height);
CGM001canvasObj.context.putImageData(CGM001canvasOffBGObj.context.getImageData(0, 0, CGM001canvasOffBGObj.width, CGM001canvasOffBGObj.height), 0, 0);
time++;
//console.log(time);
}
}
} function initList(){
var cuttedBlocksLstTmp;
for(cbli = 0; cbli < cuttedBlocksLst.length; cbli++){
cuttedBlocksLstTmp = null;
cuttedBlocksLstTmp = cuttedBlocksLst[cbli];
cuttedBlocksLstTmp.calcMinXY();
cuttedBlocksLstTmp.calcType();
//console.log((cbli+1)+"/"+cuttedBlocksLst.length);
} for(i=0;i<cuttedBlocksLst[0].type.length;i++){
//for(j=0;j<cuttedBlocksLst[0].type[i].length;j++){
//console.log(cuttedBlocksLst[0].type[i][0],cuttedBlocksLst[0].type[i][1],cuttedBlocksLst[0].type[i][2],cuttedBlocksLst[0].type[i][3]);
//}
}
//console.log(cuttedBlocksLst[0].blockLst[0].tag,cuttedBlocksLst[0].blockLst[1].tag,cuttedBlocksLst[0].blockLst[2].tag,cuttedBlocksLst[0].blockLst[3].tag,'index:',cuttedBlocksLst[0].typeNo,cuttedBlocksLst[0].typeRoateNo); /*cuttedBlocksLst[0].rotateBlocks(5); for(i=0;i<cuttedBlocksLst[0].type.length;i++){
//for(j=0;j<cuttedBlocksLst[0].type[i].length;j++){
console.log(cuttedBlocksLst[0].type[i][0],cuttedBlocksLst[0].type[i][1],cuttedBlocksLst[0].type[i][2],cuttedBlocksLst[0].type[i][3]);
//}
}
console.log('rotate:', cuttedBlocksLst[0].rotate);*/
// sort the down order
//blocksOrder
var sortCuttedBlocksTmp = [[],[]];
var maxYTmp = cuttedBlocksLst[0].maxY;
var sortj = 0,sorti=0;
for(sortiTmp=0;sortiTmp<cuttedBlocksLst.length;sortiTmp++){
if(maxYTmp != cuttedBlocksLst[sortiTmp].maxY){sortj++;sorti=0;sortCuttedBlocksTmp.push([]);maxYTmp = cuttedBlocksLst[sortiTmp].maxY;}
sortCuttedBlocksTmp[sortj].push([]);
sortCuttedBlocksTmp[sortj][sorti] = {no:sortiTmp,typeFirst:cuttedBlocksLst[sortiTmp].typeFirst};
sorti++;
}
/*console.log(sortCuttedBlocksTmp);*/ var blocksOrderColTmp = [[], []]; for (x = 0; x < sortCuttedBlocksTmp.length; x++) {
blocksOrderRow.push([[],[],[]]);
}
var addX = 0;
for(x=0;x<sortCuttedBlocksTmp.length;x++){
for(y=0;y<sortCuttedBlocksTmp[x].length;y++){
//
if (sortCuttedBlocksTmp[x][y].typeFirst == 3) {
if (blocksOrderRow.length - 1 > x + 2) {
addX = x + 2;
} else if (blocksOrderRow.length - 1 > x + 1) {
addX = x + 2;
} else { addX = x;}
blocksOrderRow[addX][sortCuttedBlocksTmp[x][y].typeFirst - 3].push(sortCuttedBlocksTmp[x][y].no);
} else {
blocksOrderRow[x][sortCuttedBlocksTmp[x][y].typeFirst].push(sortCuttedBlocksTmp[x][y].no);
}
}
/*console.log("blocksOrderColTmp",blocksOrderColTmp);*/
//blocksOrderRow[x]=blocksOrderColTmp;
}
for(xx=0;xx<blocksOrderRow.length;xx++){
//for(yy=0;yy<blocksOrderRow[xx].length;yy++)
//console.log(xx,yy,":",xx,blocksOrderRow[xx][yy]);
}
//gameOverFlg = true;
} // Animation.....................................................
// select the block
var drawBlocks = null;
var drawBlocksRow = 0;
var drawBlocksCol = 0;
var drawBlocksFirst = 0;
var paused = false;
var gameOverFlg = false;
var initDownBlockOverFlg = false;
var calTmpCol123 = [];
var calTmpCol123Tmp = []; // move and change the block
var operationLst = [];
var moveRotate = 0;
var moveX = 0;
var moveY = 0;
var getNew = true; // fps -> time var lastFpsUpdateTime = 0; function animate(time) {
if (!paused) {
/*context.clearRect(0,0,canvas.width,canvas.height);
drawBackground();
update();
draw();*/
updateCanvas();
drawCanvas();
if (!gameOverFlg) {
window.requestNextAnimationFrame(animate);
//console.log(drawBlocksRow,blocksOrderRow.length-1,"goon",gameOverFlg);
}else{
console.log(drawBlocksRow,blocksOrderRow.length-1,"stop",gameOverFlg);
}
}
} function initDownBlocks(){
drawBlocks = null;
while(drawBlocks==null && !initDownBlockOverFlg){
if(drawBlocksRow < blocksOrderRow.length-1){
if(drawBlocksCol < 3){
if(blocksOrderRow[drawBlocksRow][drawBlocksCol].length > drawBlocksFirst){
//decide which one!
var calTmpColOrg = blocksOrderRow[drawBlocksRow][drawBlocksCol];
var selectIndex = 0;
var selectedNo = 0;
//tmp init
if(calTmpCol123.length == 0){
for(i123 = 0;i123<calTmpColOrg.length;i123++){
calTmpCol123.push(calTmpColOrg[i123]);
calTmpCol123Tmp.push(calTmpColOrg[i123]);
}
}
//console.log("in:",calTmpCol123);
switch(drawBlocksCol){
case 1:
//select
selectIndex = calTmpCol123.length-1;
break;
case 0:
case 2:
default:
//select
selectIndex = parseInt(Math.random() * (calTmpCol123.length-1));
break;
}
selectedNo = calTmpCol123[selectIndex];
//delete tmp
calTmpCol123 = [];
for(i123=0;i123<calTmpCol123Tmp.length;i123++){
if(selectIndex != i123){
calTmpCol123.push(calTmpCol123Tmp[i123]);
}
}
//copy to tmp
calTmpCol123Tmp = [];
for(i123=0;i123<calTmpCol123.length;i123++){
calTmpCol123Tmp.push(calTmpCol123[i123]);
}
drawBlocks = cuttedBlocksLst[selectedNo]; //console.log("aa",drawBlocks.typeNo,drawBlocks.typeRoateNo,drawBlocks.rotate );
var initRotateTime = parseInt(Math.random() * 3);
// initRotateTime = 0; test
if(initRotateTime>=1){
//console.log('step1',drawBlocks.typeNo ,drawBlocks.typeRoateNo ,drawBlocks.rotate,drawBlocks.gorotate);
//drawBlocks.typeRoateNo = (drawBlocks.typeRoateNo + initRotateTime) % 4;
drawBlocks.gorotate = (initRotateTime * 90) % 360;
//console.log('step2',drawBlocks.typeNo ,drawBlocks.typeRoateNo ,drawBlocks.rotate,drawBlocks.gorotate);
//drawBlocks.gorotate = (initRotateTime * 90) % 360;
}
//drawBlocks.gorotate = drawBlocks.rotate;
//console.log("aa",drawBlocks.typeNo,drawBlocks.typeRoateNo,drawBlocks.rotate ); //console.log("out:",calTmpCol123,selectIndex);
//console.log("selectNo",selectedNo);
drawBlocksFirst++;
// crash check(gameOver)
drawBlocks.godisY = 0;
drawBlocks.godisX = 0;
drawBlocks.gorotate = drawBlocks.gorotate;
if(drawBlocks.testCrash(blockBoxLst)){
gameOverFlg = true;
}
//console.log('step3',drawBlocks.typeNo ,drawBlocks.typeRoateNo ,drawBlocks.rotate,drawBlocks.gorotate);
drawBlocks.godisY = 0;
drawBlocks.godisX = 0;
drawBlocks.gorotate = drawBlocks.gorotate;
if(drawBlocks.testCrash(blockBoxLst)){
gameOverFlg = true;
}
//console.log('step4',drawBlocks.typeNo ,drawBlocks.typeRoateNo ,drawBlocks.rotate,drawBlocks.gorotate);
drawBlocks.draw();
//gameOverFlg = true;
CGM001canvasOffObj.context.clearRect(0, 0, CGM001canvasOffObj.width, CGM001canvasOffObj.height);
CGM001canvasOffObj.context.drawImage(image, 0, 0, picWidth, picHeight);
drawBlocks.drawToOff(); }else{
drawBlocksFirst = 0;
drawBlocksCol++;
calTmpCol123 = [];
calTmpCol123Tmp = [];
}
}else{
drawBlocksCol = 0;
drawBlocksRow++;
}
}else{
initDownBlockOverFlg = true;
//console.log("over");
}
}
}
function updateCanvas(){ var now = (+new Date); if (now - lastFpsUpdateTime > 800) {
lastFpsUpdateTime = now;
// action in one second
if (getNew) {
acSrc = acRootPath + failPath + parseInt(Math.random() * failSize) + ".png";
initDownBlocks();
if (initDownBlockOverFlg) {
clearCanvas();
console.log("you Win!"); acSrc = acRootPath + goodPath + parseInt(Math.random() * goodSize) + ".png";
$("#" + acNiangId).attr("src", acSrc); var overStr = "<div style='width:" + width + "px;position:absolute;left:10px;top:150px; text-align:center;'><span style='color:red;font-size:50px;font-weight:bold;'>恭喜,你赢啦!</span><br /><input type='button' value='再来一次' onclick='javascript: location.reload();' /></div>" $("body").append($(overStr));
$("#" + bgId).hide();
$("#" + idC).hide();
$("#" + stsId).hide();
gameOverFlg = true;
return;
}
moveX = 0;
moveY = 0;
moveRotate = drawBlocks.rotate;
getNew = false;
currB++;
$("#" + countId).html("第 " + currB + " 块/共 " + countB + " 块");
$("#" + stsId).css({ 'left': ($("#" + stsId).width() + 10) * -1 });
} else {
acSrc = acRootPath + nomalPath + parseInt(Math.random() * nomalSize) + ".png";
}
$("#" + acNiangId).attr("src",acSrc);
if(!gameOverFlg){
if(initDownBlockOverFlg || drawBlocks==null){
gameOverFlg = true;
moveX = 0;
moveY = 0;
moveRotate = 0;
return;
}
moveY += drawBlocks.blockSize;
drawBlocks.godisX = moveX;
drawBlocks.godisY = moveY;
drawBlocks.gorotate = moveRotate;
//peng zhuang
drawBlocks.crash(blockBoxLst);
//console.log(drawBlocks.crashFlg,drawBlocks.doneFlg);
//mei you peng zhuang // peng zhuang
saveClearCanvas();
//drawBlocks.draw();
//drawBlocks.blockAgainFlg=false;
if (drawBlocks.blockAgainFlg) {
acSrc = acRootPath + failPath + parseInt(Math.random() * failSize) + ".png";
$("#" + acNiangId).attr("src", acSrc);
drawBlocks.disX = 0;
drawBlocks.disY = 0;
drawBlocks.godisX = 0;
drawBlocks.godisY = 0;
moveX = 0;
moveY = 0;
drawBlocks.doneFlg = false;
drawBlocks.crashFlg = false;
drawBlocks.blockAgainFlg = false;
failB++;
$("#" + failCountId).html(failB > maxFail ? maxMsg : failB);
$("#" + stsId).css({ 'left': ($("#" + stsId).width() + 10) * -1 });
} else if (drawBlocks.doneFlg || drawBlocks.crashFlg) {
getNew = true;
acSrc = acRootPath + goodPath + parseInt(Math.random() * goodSize) + ".png";
$("#" + acNiangId).attr("src", acSrc);
fixB++;
$("#" + fixCountId).html(fixB);
$("#" + stsId).css({ 'left': ($("#" + stsId).width() + 10) * -1 });
} else {
drawBlocks.draw();
}
} else {drawBlocks.draw();} }
} function drawCanvas(){} function onKeyUp(e){
if(drawBlocks!=null){
var gomoveX;
var gomoveY;
var gomoveRotate;
var currKey = 0,e=e||e.event;
currKey = e.keyCode || e.which || e.charCode;
var keyName = String.fromCharCode(currKey);
gomoveRotate = drawBlocks.rotate;
gomoveX = drawBlocks.disX;
gomoveY = drawBlocks.disY;
switch(currKey){
case 38:
//up
gomoveRotate =(drawBlocks.rotate + 90);
break;
case 40:
//down
gomoveY = drawBlocks.disY + blockSize;
break;
case 39:
//right
gomoveX =drawBlocks.disX + blockSize;
break;
case 37:
//left
gomoveX =drawBlocks.disX - blockSize;
break;
default:
break;
}
drawBlocks.godisY = gomoveY;
drawBlocks.godisX = gomoveX;
drawBlocks.gorotate = gomoveRotate;
//console.log("inp",drawBlocks.rotate,gomoveRotate);
if(drawBlocks.testCrash(blockBoxLst)){ } else {
acSrc = acRootPath + goodPath + parseInt(Math.random() * goodSize) + ".png";
$("#" + acNiangId).attr("src", acSrc);
moveX = gomoveX;
moveY = gomoveY;
moveRotate = gomoveRotate;
drawBlocks.crash(blockBoxLst);
saveClearCanvas();
drawBlocks.draw();
}
}
} function saveClearCanvas(){
CGM001canvasObj.context.clearRect(0,0,CGM001canvasObj.width,CGM001canvasObj.height);
CGM001canvasObj.context.putImageData(CGM001canvasOffObjAnimation.context.getImageData(0,0,CGM001canvasOffObjAnimation.width,CGM001canvasOffObjAnimation.height),0,0);
};
blockTypeData:
// blocks type
// 1 zi
var type1_1 = [
[1,0,0,0],
[1,0,0,0],
[1,0,0,0],
[1,0,0,0]];
var type1_2 = [
[1,1,1,1],
[0,0,0,0],
[0,0,0,0],
[0,0,0,0]];
var type1 = [type1_1,type1_2];
var typeRoate1_1 = [
[1,0,0,0],
[2,0,0,0],
[3,0,0,0],
[4,0,0,0]];
var typeRoateXY1_1 = [
{r:0,c:0},
{r:0,c:0},
{r:1,c:0},
{r:2,c:0},
{r:3,c:0}
];
var typeFirst1_1 = 0;
var typeRoate1_2 = [
[4,3,2,1],
[0,0,0,0],
[0,0,0,0],
[0,0,0,0]];
var typeRoateXY1_2 = [
{r:0,c:0},
{r:0,c:3},
{r:0,c:2},
{r:0,c:1},
{r:0,c:0}
];
var typeFirst1_2 = 0;
var typeRoate1_3 = [
[4,0,0,0],
[3,0,0,0],
[2,0,0,0],
[1,0,0,0]];
var typeRoateXY1_3 = [
{r:0,c:0},
{r:3,c:0},
{r:2,c:0},
{r:1,c:0},
{r:0,c:0}
];
var typeFirst1_3 = 0;
var typeRoate1_4 = [
[1,2,3,4],
[0,0,0,0],
[0,0,0,0],
[0,0,0,0]];
var typeRoateXY1_4 = [
{r:0,c:0},
{r:0,c:0},
{r:0,c:1},
{r:0,c:2},
{r:0,c:3}
];
var typeFirst1_4 = 0;
var typeRoate1 = [typeRoate1_1,typeRoate1_2,typeRoate1_3,typeRoate1_4];
var typeRoateXY1 = [typeRoateXY1_1,typeRoateXY1_2,typeRoateXY1_3,typeRoateXY1_4];
var typeFirst1 = [typeFirst1_1,typeFirst1_2,typeFirst1_3,typeFirst1_4];
// tian zi
var type2_1 = [
[1,1,0,0],
[1,1,0,0],
[0,0,0,0],
[0,0,0,0]];
var type2 = [type2_1];
var typeRoate2_1 = [
[1,2,0,0],
[4,3,0,0],
[0,0,0,0],
[0,0,0,0]];
var typeRoateXY2_1 = [
{r:0,c:0},
{r:0,c:0},
{r:0,c:1},
{r:1,c:1},
{r:1,c:0}
];
var typeFirst2_1 = 0;
var typeRoate2_2 = [
[4,1,0,0],
[3,2,0,0],
[0,0,0,0],
[0,0,0,0]];
var typeRoateXY2_2 = [
{r:0,c:0},
{r:0,c:1},
{r:1,c:1},
{r:1,c:0},
{r:0,c:0}
];
var typeFirst2_2 = 0;
var typeRoate2_3 = [
[3,4,0,0],
[2,1,0,0],
[0,0,0,0],
[0,0,0,0]];
var typeRoateXY2_3 = [
{r:0,c:0},
{r:1,c:1},
{r:1,c:0},
{r:0,c:0},
{r:0,c:1}
];
var typeFirst2_3 = 0;
var typeRoate2_4 = [
[2,3,0,0],
[1,4,0,0],
[0,0,0,0],
[0,0,0,0]];
var typeRoateXY2_4 = [
{r:0,c:0},
{r:1,c:0},
{r:0,c:0},
{r:0,c:1},
{r:1,c:1}
];
var typeFirst2_4 = 0;
var typeRoate2 = [typeRoate2_1,typeRoate2_2,typeRoate2_3,typeRoate2_4];
var typeRoateXY2 = [typeRoateXY2_1,typeRoateXY2_2,typeRoateXY2_3,typeRoateXY2_4];
var typeFirst2 = [typeFirst2_1,typeFirst2_2,typeFirst2_3,typeFirst2_4];
// L zi
var type3_1 = [
[1,0,0,0],
[1,0,0,0],
[1,1,0,0],
[0,0,0,0]];
var type3_2 = [
[1,1,1,0],
[1,0,0,0],
[0,0,0,0],
[0,0,0,0]];
var type3_3 = [
[1,1,0,0],
[0,1,0,0],
[0,1,0,0],
[0,0,0,0]];
var type3_4 = [
[0,0,1,0],
[1,1,1,0],
[0,0,0,0],
[0,0,0,0]];
var type3 = [type3_1,type3_2,type3_3,type3_4];
var typeRoate3_1 = [
[1,0,0,0],
[2,0,0,0],
[3,4,0,0],
[0,0,0,0]];
var typeRoateXY3_1 = [
{r:0,c:0},
{r:0,c:0},
{r:1,c:0},
{r:2,c:0},
{r:2,c:1}
];
var typeFirst3_1 = 0;
var typeRoate3_2 = [
[3,2,1,0],
[4,0,0,0],
[0,0,0,0],
[0,0,0,0]];
var typeRoateXY3_2 = [
{r:0,c:0},
{r:0,c:2},
{r:0,c:1},
{r:0,c:0},
{r:1,c:0}
];
var typeFirst3_2 = 2;
var typeRoate3_3 = [
[4,3,0,0],
[0,2,0,0],
[0,1,0,0],
[0,0,0,0]];
var typeRoateXY3_3 = [
{r:0,c:0},
{r:2,c:1},
{r:1,c:1},
{r:0,c:1},
{r:0,c:0}
];
var typeFirst3_3 = 3;
var typeRoate3_4 = [
[0,0,4,0],
[1,2,3,0],
[0,0,0,0],
[0,0,0,0]];
var typeRoateXY3_4 = [
{r:0,c:0},
{r:1,c:0},
{r:1,c:1},
{r:1,c:2},
{r:0,c:2}
];
var typeFirst3_4 = 0;
var typeRoate3 = [typeRoate3_1,typeRoate3_2,typeRoate3_3,typeRoate3_4];
var typeRoateXY3 = [typeRoateXY3_1,typeRoateXY3_2,typeRoateXY3_3,typeRoateXY3_4];
var typeFirst3 = [typeFirst3_1,typeFirst3_2,typeFirst3_3,typeFirst3_4];
// ~L zi
var type4_1 = [
[0,1,0,0],
[0,1,0,0],
[1,1,0,0],
[0,0,0,0]];
var type4_2 = [
[1,0,0,0],
[1,1,1,0],
[0,0,0,0],
[0,0,0,0]];
var type4_3 = [
[1,1,0,0],
[1,0,0,0],
[1,0,0,0],
[0,0,0,0]];
var type4_4 = [
[1,1,1,0],
[0,0,1,0],
[0,0,0,0],
[0,0,0,0]];
var type4 = [type4_1,type4_2,type4_3,type4_4];
var typeRoate4_1 = [
[0,1,0,0],
[0,2,0,0],
[4,3,0,0],
[0,0,0,0]];
var typeRoateXY4_1 = [
{r:0,c:0},
{r:0,c:1},
{r:1,c:1},
{r:2,c:1},
{r:2,c:0}
];
var typeFirst4_1 = 0;
var typeRoate4_2 = [
[4,0,0,0],
[3,2,1,0],
[0,0,0,0],
[0,0,0,0]];
var typeRoateXY4_2 = [
{r:0,c:0},
{r:1,c:2},
{r:1,c:1},
{r:1,c:0},
{r:0,c:0}
];
var typeFirst4_2 = 0;
var typeRoate4_3 = [
[3,4,0,0],
[2,0,0,0],
[1,0,0,0],
[0,0,0,0]];
var typeRoateXY4_3 = [
{r:0,c:0},
{r:2,c:0},
{r:1,c:0},
{r:0,c:0},
{r:0,c:1}
];
var typeFirst4_3 = 3;
var typeRoate4_4 = [
[1,2,3,0],
[0,0,4,0],
[0,0,0,0],
[0,0,0,0]];
var typeRoateXY4_4 = [
{r:0,c:0},
{r:0,c:0},
{r:0,c:1},
{r:0,c:2},
{r:1,c:2}
];
var typeFirst4_4 = 2;
var typeRoate4 = [typeRoate4_1,typeRoate4_2,typeRoate4_3,typeRoate4_4];
var typeRoateXY4 = [typeRoateXY4_1,typeRoateXY4_2,typeRoateXY4_3,typeRoateXY4_4];
var typeFirst4 = [typeFirst4_1,typeFirst4_2,typeFirst4_3,typeFirst4_4];
// Z zi
var type5_1 = [
[1,1,0,0],
[0,1,1,0],
[0,0,0,0],
[0,0,0,0]];
var type5_2 = [
[0,1,0,0],
[1,1,0,0],
[1,0,0,0],
[0,0,0,0]];
var type5 = [type5_1,type5_2];
var typeRoate5_1 = [
[1,2,0,0],
[0,3,4,0],
[0,0,0,0],
[0,0,0,0]];
var typeRoateXY5_1 = [
{r:0,c:0},
{r:0,c:0},
{r:0,c:1},
{r:1,c:1},
{r:1,c:2}
];
var typeFirst5_1 = 1;
var typeRoate5_2 = [
[0,1,0,0],
[3,2,0,0],
[4,0,0,0],
[0,0,0,0]];
var typeRoateXY5_2 = [
{r:0,c:0},
{r:0,c:1},
{r:1,c:1},
{r:1,c:0},
{r:2,c:0}
];
var typeFirst5_2 = 1;
var typeRoate5_3 = [
[4,3,0,0],
[0,2,1,0],
[0,0,0,0],
[0,0,0,0]];
var typeRoateXY5_3 = [
{r:0,c:0},
{r:1,c:2},
{r:1,c:1},
{r:0,c:1},
{r:0,c:0}
];
var typeFirst5_3 = 1;
var typeRoate5_4 = [
[0,4,0,0],
[2,3,0,0],
[1,0,0,0],
[0,0,0,0]];
var typeRoateXY5_4 = [
{r:0,c:0},
{r:2,c:0},
{r:1,c:0},
{r:1,c:1},
{r:0,c:1}
];
var typeFirst5_4 = 1;
var typeRoate5 = [typeRoate5_1,typeRoate5_2,typeRoate5_3,typeRoate5_4];
var typeRoateXY5 = [typeRoateXY5_1,typeRoateXY5_2,typeRoateXY5_3,typeRoateXY5_4];
var typeFirst5 = [typeFirst5_1,typeFirst5_2,typeFirst5_3,typeFirst5_4];
// ~Z zi
var type6_1 = [
[0,1,1,0],
[1,1,0,0],
[0,0,0,0],
[0,0,0,0]];
var type6_2 = [
[1,0,0,0],
[1,1,0,0],
[0,1,0,0],
[0,0,0,0]];
var type6 = [type6_1,type6_2];
var typeRoate6_1 = [
[0,3,4,0],
[1,2,0,0],
[0,0,0,0],
[0,0,0,0]];
var typeRoateXY6_1 = [
{r:0,c:0},
{r:1,c:0},
{r:1,c:1},
{r:0,c:1},
{r:0,c:2}
];
var typeFirst6_1 = 1;
var typeRoate6_2 = [
[1,0,0,0],
[2,3,0,0],
[0,4,0,0],
[0,0,0,0]];
var typeRoateXY6_2 = [
{r:0,c:0},
{r:0,c:0},
{r:1,c:0},
{r:1,c:1},
{r:2,c:1}
];
var typeFirst6_2 = 1;
var typeRoate6_3 = [
[0,2,1,0],
[4,3,0,0],
[0,0,0,0],
[0,0,0,0]];
var typeRoateXY6_3 = [
{r:0,c:0},
{r:0,c:2},
{r:0,c:1},
{r:1,c:1},
{r:1,c:0}
];
var typeFirst6_3 = 1;
var typeRoate6_4 = [
[4,0,0,0],
[3,2,0,0],
[0,1,0,0],
[0,0,0,0]];
var typeRoateXY6_4 = [
{r:0,c:0},
{r:2,c:1},
{r:1,c:1},
{r:1,c:0},
{r:0,c:0}
];
var typeFirst6_4 = 1;
var typeRoate6 = [typeRoate6_1,typeRoate6_2,typeRoate6_3,typeRoate6_4];
var typeRoateXY6 = [typeRoateXY6_1,typeRoateXY6_2,typeRoateXY6_3,typeRoateXY6_4];
var typeFirst6 = [typeFirst6_1,typeFirst6_2,typeFirst6_3,typeFirst6_4];
// T zi
var type7_1 = [
[1,1,1,0],
[0,1,0,0],
[0,0,0,0],
[0,0,0,0]];
var type7_2 = [
[0,1,0,0],
[1,1,0,0],
[0,1,0,0],
[0,0,0,0]];
var type7_3 = [
[0,1,0,0],
[1,1,1,0],
[0,0,0,0],
[0,0,0,0]];
var type7_4 = [
[1,0,0,0],
[1,1,0,0],
[1,0,0,0],
[0,0,0,0]];
var type7 = [type7_1,type7_2,type7_3,type7_4];
var typeRoate7_1 = [
[1,2,3,0],
[0,4,0,0],
[0,0,0,0],
[0,0,0,0]];
var typeRoateXY7_1 = [
{r:0,c:0},
{r:0,c:0},
{r:0,c:1},
{r:0,c:2},
{r:1,c:1}
];
var typeFirst7_1 = 2;
var typeRoate7_2 = [
[0,1,0,0],
[4,2,0,0],
[0,3,0,0],
[0,0,0,0]];
var typeRoateXY7_2 = [
{r:0,c:0},
{r:0,c:1},
{r:1,c:1},
{r:2,c:1},
{r:1,c:0}
];
var typeFirst7_2 = 2;
var typeRoate7_3 = [
[0,4,0,0],
[3,2,1,0],
[0,0,0,0],
[0,0,0,0]];
var typeRoateXY7_3 = [
{r:0,c:0},
{r:1,c:2},
{r:1,c:1},
{r:1,c:0},
{r:0,c:1}
];
var typeFirst7_3 = 0;
var typeRoate7_4 = [
[3,0,0,0],
[2,4,0,0],
[1,0,0,0],
[0,0,0,0]];
var typeRoateXY7_4 = [
{r:0,c:0},
{r:2,c:0},
{r:1,c:0},
{r:0,c:0},
{r:1,c:1}
];
var typeFirst7_4 = 2;
var typeRoate7 = [typeRoate7_1,typeRoate7_2,typeRoate7_3,typeRoate7_4];
var typeRoateXY7 = [typeRoateXY7_1,typeRoateXY7_2,typeRoateXY7_3,typeRoateXY7_4];
var typeFirst7 = [typeFirst7_1,typeFirst7_2,typeFirst7_3,typeFirst7_4]; var typeLst = [type1,type2,type3,type4,type5,type6,type7];
var typeRoateLst = [typeRoate1,typeRoate2,typeRoate3,typeRoate4,typeRoate5,typeRoate6,typeRoate7];
var typeRoateXYLst = [typeRoateXY1,typeRoateXY2,typeRoateXY3,typeRoateXY4,typeRoateXY5,typeRoateXY6,typeRoateXY7];
var typeFirst = [typeFirst1,typeFirst2,typeFirst3,typeFirst4,typeFirst5,typeFirst6,typeFirst7];
XXXEntity等,懒得贴了。。。
---
CSDN下载:
http://download.csdn.net/detail/wangxsh42/8391881
[原创]html5_PC游戏_图片俄罗斯方块的更多相关文章
- [原创]html5游戏_贪吃蛇
代码随便写写,尚有许多不足,PC与手机端皆可运行 手机端滑屏操作,PC端方向键操作 疑问: 生成食物,与判断是否可以移动方面 有两种实现方式, 1.使用js内存,数组循环判断 2.使用dom的quer ...
- [原创]html5游戏_五线谱打音符
html5手机游戏—五线谱打音符 1.[用五线谱打唱名] 2.[用唱名打五线谱] 3.[无限练习模式] 用来熟悉五线谱上音符的位置 代码不难,这回注释还是有认真写的[只是废代码没有全部删除...] 效 ...
- .Net Core ORM选择之路,哪个才适合你 通用查询类封装之Mongodb篇 Snowflake(雪花算法)的JavaScript实现 【开发记录】如何在B/S项目中使用中国天气的实时天气功能 【开发记录】微信小游戏开发入门——俄罗斯方块
.Net Core ORM选择之路,哪个才适合你 因为老板的一句话公司项目需要迁移到.Net Core ,但是以前同事用的ORM不支持.Net Core 开发过程也遇到了各种坑,插入条数多了也特别 ...
- WPF_界面_图片/界面/文字模糊解决之道整理
原文:WPF_界面_图片/界面/文字模糊解决之道整理 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/u010265681/article/detai ...
- java画图程序_图片用字母画出来_源码发布_版本二
在上一个版本:java画图程序_图片用字母画出来_源码发布 基础上,增加了图片同比例缩放,使得大像素图片可以很好地显示画在Notepad++中. 项目结构: 运行效果1: 原图:http://imag ...
- java画图程序_图片用字母画出来_源码发布
在之前写了一篇blog:java画图程序_图片用字母画出来 主要是把一些调试的截图发布出来,现在程序调试我认为可以了(当然,你如果还想调试的话,也可以下载源码自己调试). 就把源码发布出来. 项目结构 ...
- java画图程序_图片用字母画出来
最近在研究怎样将图片用字母在文本编辑工具中“画”出来. 你看了这个可能还不知道我想说什么? 我想直接上图,大家一定就知道了 第一张:小猫 原图:http://www.cnblogs.com/hongt ...
- 分享一组Rpg Marker人物行走,游戏素材图片,共20张图片
分享一组Rpg Marker人物行走,游戏素材图片,共20张图片 上面的下载地址链接是图片,无法直接复制哦!下载请直接点击: 游戏素材下载 或者复制以下链接:http://***/view/13.h ...
- BZOJ_4554_[Tjoi2016&Heoi2016]游戏_二分图匹配
BZOJ_4554_[Tjoi2016&Heoi2016]游戏_二分图匹配 Description 在2016年,佳缘姐姐喜欢上了一款游戏,叫做泡泡堂.简单的说,这个游戏就是在一张地图上放上若 ...
随机推荐
- 使用Highcharts实现图表展示
本篇随笔记录的是本人2011年做广州地铁协同办公项目时,图表需求的解决方案.(Demo中只是虚拟的测试数据) 关键技术点: 使用Highcharts实现图表展示: 另外使用Highslide弹窗.使用 ...
- Android之layout_alignBottom失效问题
外面是一层RelativeLayout,前面的text和后面按钮都是设置centerParent_vertical,第二个hello是需要与第一个底部对齐,虽然设置alginBottom指向第一个he ...
- POJ 2083 Fractal
Fractal Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6646 Accepted: 3297 Descripti ...
- 2 个UserControl 的传值问题
问题描述:有2个UserControl:UserControl1 里有一个Button,UserControl2 里面有一个TextBox,这2个控件都加载到了主窗体Form1 上.要求的是,点击 U ...
- windbg入门
1.下载安装windbg Windows 10 调试工具 (WinDbg) 如果你仅需要 Windows 10 调试工具,而不需要 WDK 10 或 Visual Studio 2015,你可以将调试 ...
- nginx url自动加斜杠的问题
nginx url自动加斜杠问题及301重定向 时间:2016-02-04 15:14:28来源:网络 导读:nginx url自动加斜杠问题及301重定向,URL指向一个目录并且在最后没有包含斜杠, ...
- jdbc根据实例名 连接 sql server
jdbc:sqlserver://PC;instanceName=sql2012;databaseName=xxxxx
- C# 解析百度天气数据,Rss解析百度新闻以及根据IP获取所在城市
百度天气 接口地址:http://api.map.baidu.com/telematics/v3/weather?location=上海&output=json&ak=hXWAgbsC ...
- HTML5 is Canvas
var cvs = document.getElementById("cvs"); // // 获取上下文环境 var con = cvs.getContext("2d& ...
- facebook-开发
https://developers.facebook.com/docs/ios/getting-started?locale=zh_CN#prerequisites