⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 blockdata.cpp

📁 用VC在BREW平台上开发的手机游戏Superball的源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			}
			else if((ballx->row >= -1) && (ballx->row <= ARRAY_ROW-2) &&    ////hit down block
			   (block_array[ballx->row+1][ballx->col] != 0) && 
			   (ballx->cy >= 24+ballx->row*8-ballx->specify))
			{
				if(ballx->picindex == 0)
					ballx->dir = NORTHEAST;
				if(block_array[ballx->row+1][ballx->col] <= 5)
					hitblock(ballx->row+1, ballx->col);
				ballshine = true;
			}
			////right
			if((ballx->col == ARRAY_COL-1) && (ballx->cx >= rightedge-ballx->specify))  ////hit rightedge
				ballx->dir = (ballx->dir == SOUTHEAST) ? SOUTHWEST : NORTHWEST;
			else if ((ballx->row >= 0) && (ballx->row < ARRAY_ROW) && (ballx->col != ARRAY_COL) && 
				(block_array[ballx->row][ballx->col+1] != 0) &&       ////hit right block 
			    (ballx->cx >= leftedge+ballx->col*15+15-ballx->specify))
			{
				if(ballx->picindex == 0)
					ballx->dir = (ballx->dir == SOUTHEAST) ? SOUTHWEST : NORTHWEST;
				if(block_array[ballx->row][ballx->col+1] <= 5)
					hitblock(ballx->row, ballx->col+1);
				ballshine = true;
			}
			break;

		case SOUTHWEST:
			////down
			if(loseball(ballx))
				return;
			if((ballx->cy >= board.cy-5) && (ballx->cy <= board.cy) && (ballx->cx >= board.cx-board.specify) && (ballx->cx <= board.cx+board.specify))        ////hit the board
			{
			    ballx->dir = NORTHWEST;
				if(ballx->cx-board.cx<=board.specify/3 && board.cx-ballx->cx<=board.specify/3)
					ballx->status = 1;
				else if(ballx->cx-board.cx>=board.specify*2/3 || board.cx-ballx->cx>=board.specify*2/3)
					ballx->status = 2;
				else
					ballx->status = 0;
				if(ballx->status != 0 && ballx->speed == 3)
					ballx->specify = 4;
				else
					ballx->specify = 3;
			}
			else if((ballx->row >= -1) && (ballx->row <= ARRAY_ROW-2) &&    ////hit down block
			   (block_array[ballx->row+1][ballx->col] != 0) && 
			   (ballx->cy >= 24+ballx->row*8-ballx->specify))
			{
				if(ballx->picindex == 0)
					ballx->dir = NORTHWEST;
				if(block_array[ballx->row+1][ballx->col] <= 5)
					hitblock(ballx->row+1, ballx->col);
				ballshine = true;
			}
			////left
			if((ballx->col == 0) && (ballx->cx <= leftedge+ballx->specify))    ////hit leftedge
				ballx->dir = (ballx->dir == SOUTHWEST) ? SOUTHEAST : NORTHEAST;
			else if ((ballx->row >= 0) && (ballx->row < ARRAY_ROW) && (ballx->col != 0) && 
				(block_array[ballx->row][ballx->col-1] != 0) &&    ////hit left block
				(ballx->cx <= leftedge+ballx->col*15+ballx->specify))
			{
				if(ballx->picindex == 0)
					ballx->dir = (ballx->dir == SOUTHWEST) ? SOUTHEAST : NORTHEAST;
				if(block_array[ballx->row][ballx->col-1] <= 5)
					hitblock(ballx->row, ballx->col-1);
				ballshine = true;
			}
			break;
	}
	moveball(ballx);
	if(ballshine)
		ballx->sm.ModifyStripIndex(ballx->picindex+2);
}

void BlockData::catchblock(uint8 type)
{
	switch(type)
	{
		case 1:    ////long board
			score += 50;
			if(board.status == 1)
				boardsizetime = 0;
			else if(board.status == 2)
			{
				board.status = 0;
				board.picindex = 1;
				board.specify = 12;
				board.sm.ModifyStripIndex(board.picindex);
			}
			else
			{
				board.status = 1;
				board.picindex = 2;
				board.specify = 16;
				board.sm.ModifyStripIndex(board.picindex);
				boardsizetime = 0;
			}
			break;
		case 2:    ////short board
			score += 100;
			if(board.status == 2)
				boardsizetime = 0;
			else if(board.status == 1)
			{
				board.status = 0;
				board.picindex = 1;
				board.specify = 12;
				board.sm.ModifyStripIndex(board.picindex);
			}
			else
			{
				board.status = 2;
				board.picindex = 0;
				board.specify = 8;
				board.sm.ModifyStripIndex(board.picindex);
				boardsizetime = 0;
			}
			break;
		case 3:    ////two balls
			score += 50;
			if(ballcount == 2)
				ballnumbertime = 0;
			else
			{
				ballcount++;
				ballnumbertime = 0;
				if(ball1.picindex == -1)
				{
					ball1.cx = board.cx;
					ball1.cy = board.cy-2;
					ball1.dir = NORTHEAST;
					ball1.picindex = ball2.picindex;
					ball1.speed = ball2.speed;
					ball1.status = 0;
					ball1.sm.MoveToPos(ball1.cx-ball1.specify, ball1.cy-ball1.specify);
					ball1.sm.ModifyStripIndex(ball1.picindex);
					ball1.sm.Reveal(3);
				}
				else
				{
					ball2.cx = board.cx;
					ball2.cy = board.cy-2;
					ball2.dir = NORTHEAST;
					ball2.picindex = ball1.picindex;
					ball2.speed = ball1.speed;
					ball2.status = 0;
					ball2.sm.MoveToPos(ball2.cx-ball2.specify, ball2.cy-ball2.specify);
					ball2.sm.ModifyStripIndex(ball2.picindex);
					ball2.sm.Reveal(3);
				}
			}
			break;
		case 4:    ////speed up
			score += 100;
			if(ball1.speed == 3)
				ballspeedtime = 0;
			else
			{
				ball1.speed = 3;
				ball2.speed = 3;
				ballspeedtime = 0;
			}
			break;
		case 5:    ////super ball
			score += 50;
			if(ball1.picindex == 1 || ball2.picindex == 1)
				superballtime = 0;
			else
			{
				superballtime = 0;
				if(ball1.picindex != -1)
				{
					ball1.picindex = 1;
					ball1.sm.ModifyStripIndex(ball1.picindex);
				}
				if(ball2.picindex != -1)
				{
					ball2.picindex = 1;
					ball2.sm.ModifyStripIndex(ball2.picindex);
				}
			}
			break;		
		default: break;
	}
}

void BlockData::hitblock(int8 row, int8 col)
{
	int i;
	uint8 temp;

	score += 20;
	block_array[row][col] = 0;
	if(--blockcount == 0)
	{
		blocks[row][col].sm.Hide();
		level++;
		upgrading = true;
		upgradetime = 0;
		newlevel = true;
		for(i = 0; i < 4; i++)    ////恭喜过关
		{
			lettersm[i].ModifyStripIndex(79+i);
			lettersm[i].MoveToPos(-16, -16);
		}
		return;
	}
	temp = randomblock();
	if(temp % 2 == 0 || temp == 1)
	{
		blocks[row][col].status = 2;
		blocks[row][col].sm.Hide();
	}
	else
	{
		blocks[row][col].specify = temp/2;
		blocks[row][col].status = 1;
		blocks[row][col].picindex = temp/2+73;
		blocks[row][col].sm.ModifyStripIndex(temp/2+73);    
		blocks[row][col].sm.MoveToLayer(2);
		blocks[row][col].speed = 4;
	}
}

boolean BlockData::loseball(item* ballx)
{
	int i;
	
	if(ballx->cy >= scrHeight+ballx->specify)	////out of screen, lose a life 
	{
		ballx->picindex = -1;
		if(!(--ballcount))
			if(!(--life))
			{
				upgrading = true;
				upgradetime = 0;
				ballx->sm.Hide();
				lifesm[life].Hide();
				for(i = 0; i < 4; i++)    ////游戏结束
				{
					lettersm[i].ModifyStripIndex(87+i);
					lettersm[i].MoveToPos(-16, -16);
					lettersm[i].Reveal(3);
				}
				return true;
			}
		if(ballcount == 0)	////no ball but still has life
		{
			upgrading = true;
			upgradetime = 0;
			newlife = true;
			lifesm[life].Hide();
			for(i = 0; i < 4; i++)    ////重新发球
			{
				lettersm[i].ModifyStripIndex(83+i);
				lettersm[i].MoveToPos(-16, -16);
				lettersm[i].Reveal(3);
			}
			board.dir = 0;
		}
		else
			ballx->sm.Hide();
		return true;
	}
	else
		return false;
}

void BlockData::levelup()
{
	int i, j, topy;

	if(upgradetime++%2 == 0)
		return;

	topy = scrHeight*upgradetime/40;
	for(i = 0; i < 4; i++)    ////letters		
		lettersm[i].MoveToPos(scrWidth/2-32+16*i, topy);
	lettersm[5].MoveToPos(scrWidth/2+20, topy);
	lettersm[6].MoveToPos(scrWidth/2+30, topy);	
	lettersm[(upgradetime/2)%4].Hide();
	lettersm[(upgradetime/2-1)%4].Reveal(3);

	mgr->RenderScene();
	
	rect.x = 0;
	rect.y = 0;
	rect.dx = scrWidth;
	rect.dy = topy;
	IGRAPHICS_SetFillColor(pg, 0, 0, 0, 0);
	IGRAPHICS_DrawRect(pg, &rect);
	IGRAPHICS_SetFillColor(pg, 255, 255, 255, 0);
	for(i = 0; i <= scrWidth; i += 8)
		for(j = 0; j < topy-6; j+= 8)
		{
			rect.x = i+2;
			rect.y = j+2;
			rect.dx = 4;
			rect.dy = 4;	
			IGRAPHICS_DrawRect(pg, &rect);
		}
	if(upgradetime == 40)
	{
		upgrading = false;
		newlevel = false;
		for(i = 0; i < 7; i++)
			lettersm[i].Hide();
		////refresh block array
		blockcount = 0;
		for(i = 0; i < ARRAY_ROW; i++)
			for(j = 0; j < ARRAY_COL; j++)
			{
				switch(level%MAPNUM)
				{
				case 1:     block_array[i][j] = BA1[i][j];    break;	
				case 2:     block_array[i][j] = BA2[i][j];    break;
				case 3:     block_array[i][j] = BA3[i][j];    break;
				case 4:     block_array[i][j] = BA4[i][j];    break;
				case 5:     block_array[i][j] = BA5[i][j];    break;
				case 6:     block_array[i][j] = BA6[i][j];    break;
				case 7:     block_array[i][j] = BA7[i][j];    break;
				case 8:     block_array[i][j] = BA8[i][j];    break;
				case 9:     block_array[i][j] = BA9[i][j];    break;
				case 10:    block_array[i][j] = BA10[i][j];   break;
				case 11:    block_array[i][j] = BA11[i][j];   break;
				case 0:     block_array[i][j] = BA12[i][j];   break;
				default:    block_array[i][j] = BA1[i][j];    break;
				}
				if(block_array[i][j] >= 1 && block_array[i][j] <= 5)
					blockcount++;
			}
		////refresh ball and board
		ball1.cx = scrWidth/2;
		ball1.cy = scrHeight - 15;	////****
		ball1.specify = 3;			////****
		ball1.speed = 2;				////****
		ball1.dir = NORTHEAST;
		ball1.picindex = -1;			////****
		ball1.status = 0;
		ball2.picindex = -1;
		ball2.sm.Hide();
		board.cx = scrWidth/2;
		board.cy = scrHeight - 10;	////****
		board.specify = 12;			
		board.speed = 4;
		board.dir = 0;				
		board.picindex = 1;			////****
		board.status = 0;
		ball1.sm.MoveToPos(ball1.cx-4, ball1.cy-4);
		ball1.sm.ModifyStripIndex(0);
		ball1.sm.Reveal(3);
		board.sm.MoveToPos(board.cx-16, board.cy-2);
		board.sm.ModifyStripIndex(1);
		////refresh block
		for(i = 0; i < ARRAY_ROW; i++)
			for(j = 0; j < ARRAY_COL; j++)
			{
				blocks[i][j].sm.ModifyStripIndex(block_array[i][j]%6);
				blocks[i][j].sm.MoveToPos(leftedge+j*15, i*8+8);
				blocks[i][j].sm.Reveal(1);
				if(block_array[i][j] != 0)
				{
					blocks[i][j].cx = j*15+7;
					blocks[i][j].cy = i*8+20;
					blocks[i][j].speed = 4;   
					blocks[i][j].picindex = block_array[i][j] % 6;  
					blocks[i][j].status = 0;	
				}
				else
					blocks[i][j].sm.Hide();
			}	
		////game parameters
		ballcount = 0;
	}
}

void BlockData::lifeup()
{
	int i, j, topy;
	
	if(upgradetime++%2 == 0)
		return;
	
	topy = 32*upgradetime/20;
	for(i = 0; i < 4; i++)    ////letters
		lettersm[i].MoveToPos(scrWidth/2-32+16*i, scrHeight-topy-16);
	lettersm[(upgradetime/2)%4].Hide();
	lettersm[(upgradetime/2-1)%4].Reveal(3);
	mgr->RenderScene();
	
	rect.x = 0;
	rect.y = scrHeight-topy;
	rect.dx = scrWidth;
	rect.dy = topy;
	IGRAPHICS_SetFillColor(pg, 0, 0, 0, 0);
	IGRAPHICS_DrawRect(pg, &rect);
	AEECircle circle;
	IGRAPHICS_SetFillColor(pg, 255, 255, 255, 0);
	for(i = 0; i <= scrWidth-16; i += 16)
		for(j = rect.y; j < scrHeight-8; j+= 16)
		{
			circle.cx = i+8;
			circle.cy = j+8;
			circle.r = 4;
			IGRAPHICS_DrawCircle(pg, &circle);
		}
	if(upgradetime == 20)
	{
		upgrading = false;
		newlife = false;
		for(i = 0; i < 8; i++)
			lettersm[i].Hide();
		ball1.cx = board.cx;
		ball1.cy = board.cy-5;
		ball1.picindex = -1;
		ball1.dir = NORTHEAST;
		ball1.speed = 2;
		ball1.status = 0;
		ball1.sm.ModifyStripIndex(0);
		ball1.sm.Reveal(3);	
	}
}

void BlockData::gameover()
{
	int i, j, topy;
	
	if(upgradetime++%2 == 0)
		return;

	topy = scrHeight*upgradetime/40;

	for(i = 0; i < 4; i++)
		lettersm[i].MoveToPos(scrWidth/2-32+16*i, topy);
	lettersm[(upgradetime/2)%4].Hide();
	lettersm[(upgradetime/2-1)%4].Reveal(3);
	mgr->RenderScene();

	rect.x = 0;
	rect.y = 0;
	rect.dx = scrWidth;
	rect.dy = topy;
	IGRAPHICS_SetFillColor(pg, 0, 0, 0, 0);
	IGRAPHICS_DrawRect(pg, &rect);
	IGRAPHICS_SetFillColor(pg, 255, 255, 255, 0);
	for(i = 0; i <= scrWidth; i += 8)
		for(j = 0; j < topy-6; j+= 8)
		{
			rect.x = i+2;
			rect.y = j+2;
			rect.dx = 4;
			rect.dy = 4;	
			IGRAPHICS_DrawRect(pg, &rect);
		}

	if(upgradetime == 40)
	{
		////if highscore, get username. else show score goto highscore
		if(score > ((ScoreListView*)m_arbiter->GetViewByID(IDW_SCORE))->GetScore())
			highscore = true;
		newuser = true;
		upgradetime = 0;
		namelen = 4;
		bottomindex = 3;
		for(i = 0; i < 8; i++)
			lettersm[i].Hide();
		ball1.sm.Hide();
		ball2.sm.Hide();
		board.sm.Hide();
		for(i = 0; i < ARRAY_ROW; i++)
			for(j = 0; j < ARRAY_COL; j++)
				blocks[i][j].sm.Hide();
		for(i = 0; i < 2; i++)    ////得分	
		{
			blocks[0][i].sm.ModifyStripIndex(91+i);
			blocks[0][i].sm.MoveToPos(scrWidth/2-20+24*i, scrHeight/2-48);
			blocks[0][i].sm.Reveal(3);
		}
		for(i = 0; i < 5; i++)    ////score
			scoresm[i].MoveToPos(scrWidth/2-25+10*i, scrHeight/2-28);
		for(i = 0; i < 3; i++)    ////用户名
		{
			blocks[1][i].sm.ModifyStripIndex(93+i);
			blocks[1][i].sm.MoveToPos(scrWidth/2-27+20*i, scrHeight/2+4);
			blocks[1][i].sm.Reveal(3);
		}
		////user name
		letterindex[0] = 62;
		letterindex[1] = 60;
		letterindex[2] = 46;
		letterindex[3] = 59;
		letterindex[4] = 68;
		letterindex[5] = 68;
		letterindex[6] = 68;
		letterindex[7] = 68;
		for(i = 0; i < 8; i++)   
		{
			lettersm[i].MoveToPos(scrWidth/2-20+10*i, scrHeight/2+24);
			lettersm[i].ModifyStripIndex(letterindex[i]);
			lettersm[i].Reveal(3);
		}
		////bottom line
		if(highscore)
		{
			blocks[2][0].sm.MoveToPos(scrWidth/2+10, scrHeight/2+34);
			blocks[2][0].sm.ModifyStripIndex(69);
			blocks[2][0].sm.Reveal(3);
		}
	}
}

void BlockData::username()
{
	int i;
	if(!highscore)
	{
		if(upgradetime++ == 30)
		{
			m_arbiter->Arbit(IDW_SCORE);
			return;
		}
	}
	else
	{
		if(upgradetime++%2 != 0)
			return;
		for(i = 0; i < 8; i++)
			lettersm[i].MoveToPos(scrWidth/2-namelen*5+10*i, scrHeight/2+24);
		blocks[2][0].sm.MoveToPos(scrWidth/2-namelen*5+10*bottomindex, scrHeight/2+34);
		if(namedir != 0)
		{
			if(namedir == 1 || namedir == 2)
				namedir++;
			if(namedir == -1 || namedir == -2)
				namedir--;
			if(namedir == 3)
			{
				letterindex[bottomindex] += 1;
				if(letterindex[bottomindex] == 69)
					letterindex[bottomindex] = 6;
			}
			if(namedir == -3)
			{
				letterindex[bottomindex] -= 1;
				if(letterindex[bottomindex] == 5)
					letterindex[bottomindex] = 68;
			}
			lettersm[bottomindex].ModifyStripIndex(letterindex[bottomindex]);
		}			
	}
	mgr->RenderScene();
}

void BlockData::newhighscore()
{
	int start, end, i, j;
	AECHAR username[9] = {0};

	j = 0;
	for(start = 0; letterindex[start] == 68; start++);
	for(end = 7; letterindex[end] == 68; end--);
	for(i = start; i <= end; i++)
	{
		if(letterindex[i] == 68)
			while(letterindex[i+1] == 68)
				i++;
		if(letterindex[i] >= 6 && letterindex[i] <= 15)
			username[j++] = letterindex[i] - 6 + '0';
		else if(letterindex[i] >= 16 && letterindex[i] <= 41)
			username[j++] = letterindex[i] - 16 + 'A';
		else if(letterindex[i] >= 42 && letterindex[i] <= 67)
			username[j++] = letterindex[i] - 42 + 'a';
		else
			username[j++] = ' ';
	}
	username[j] = 0;

	((ScoreListView*)m_arbiter->GetViewByID(IDW_SCORE))->InsertNewScore(username, score);
	m_arbiter->Arbit(IDW_SCORE);
}

uint8 BlockData::randomblock()
{
	byte Rand_i;
	GETRAND(&Rand_i, 1);
	return Rand_i%BLOCK_TYPE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -