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

📄 playfield.cpp

📁 Source code (C++) of the Icebloxx game for Symbian OS UIQ3.x
💻 CPP
📖 第 1 页 / 共 4 页
字号:

    painter_pixmap.drawText(0, 68, max_x, 14, AlignHCenter | AlignBottom,
	"Actors and Objects");
    m_sprites->drawHappyPenguin(painter_pixmap, KLeftOffset, 90, (m_counter % 10) / 5);
    switch ((m_counter % 36) / 9) {
    case 0:
	m_sprites->drawPenguinDown(painter_pixmap, KLeftOffset+30, 90, (m_counter % 12) / 3);
	break;
    case 1:
	m_sprites->drawPenguinRight(painter_pixmap, KLeftOffset+30, 90, (m_counter % 12) / 3);
	break;
    case 2:
	m_sprites->drawPenguinUp(painter_pixmap, KLeftOffset+30, 90, (m_counter % 12) / 3);
	break;
    case 3:
	m_sprites->drawPenguinLeft(painter_pixmap, KLeftOffset+30, 90, (m_counter % 12) / 3);
	break;
    }
    painter_pixmap.drawText(KTextOffset, 90, max_x - 100, 30, AlignLeft | AlignVCenter,
	"Pixel Pete, the penguin");
    m_sprites->drawFlame(painter_pixmap, KLeftOffset, 124, 0);
    m_sprites->drawFlame(painter_pixmap, KLeftOffset+30, 124, (m_counter % 16) / 2);
    painter_pixmap.drawText(KTextOffset, 124, max_x - 100, 30, AlignLeft | AlignVCenter,
	"Evil flames, they kill");
    m_sprites->drawBlock(painter_pixmap, KLeftOffset, 158, 0);
    m_sprites->drawBlock(painter_pixmap, KLeftOffset+30, 158, (m_counter % 32) / 4);
    painter_pixmap.drawText(KTextOffset, 158, max_x - 100, 30, AlignLeft | AlignVCenter,
	"Ice cubes - push them");
    m_sprites->drawBlockCoin(painter_pixmap, KLeftOffset, 192, 0);
    m_sprites->drawBlockCoin(painter_pixmap, KLeftOffset+30, 192, (m_counter % 32) / 4);
    painter_pixmap.drawText(KTextOffset, 192, max_x - 100, 30, AlignLeft | AlignVCenter,
	"Frozen coins - get them all");
    m_sprites->drawWall(painter_pixmap, KLeftOffset, 226);
    painter_pixmap.drawText(KTextOffset, 226, max_x - 100, 30, AlignLeft | AlignVCenter,
	"Solid walls");
	 painter_pixmap.drawText(0, 226, max_x, max_y - 226, AlignHCenter | AlignVCenter,
	"Press space or tap to start game");

	iView->BlitImage(m_pixmap);
}

void PlayField::drawIntro_2(void)
{
    QPainter painter_pixmap(m_pixgc);
    QColor black(0, 0, 0);
    QColor white(255, 255, 255);
    int max_x = iView->Size().iWidth;
    int max_y = iView->Size().iHeight;

    painter_pixmap.fillRect(0, 0, max_x, max_y, black);
    painter_pixmap.setPen(white);

    m_sprites->drawIntro(painter_pixmap, (max_x - 208) / 2, 7);
    painter_pixmap.drawText(0, 68, max_x, 14, AlignHCenter | AlignBottom,
	"How to play the game");
    m_sprites->drawPenguinDown(painter_pixmap, KLeftOffset, 90, (m_counter % 12) / 3);
    painter_pixmap.drawText(KTextOffset, 90, max_x - 100, 15, AlignLeft | AlignVCenter,
	"Move up, down, left, right");
    painter_pixmap.drawText(KTextOffset, 105, max_x - 100, 15, AlignLeft | AlignVCenter,
	"with the directional keys");
    m_sprites->drawPenguinRight(painter_pixmap, KLeftOffset, 124, (m_counter % 12) / 3);
    m_sprites->drawBlock(painter_pixmap, KLeftOffset+30, 124, 0);
    painter_pixmap.drawText(KTextOffset, 124, max_x - 100, 15, AlignLeft | AlignVCenter,
	"Walk against ice cubes to");
    painter_pixmap.drawText(KTextOffset, 139, max_x - 100, 15, AlignLeft | AlignVCenter,
	"move them out of the way");
    m_sprites->drawPenguinRight(painter_pixmap, KLeftOffset, 158, (m_counter % 12) / 3);
    m_sprites->drawBlock(painter_pixmap, KLeftOffset, 158, (m_counter % 32) / 4);
    painter_pixmap.drawText(KTextOffset, 158, max_x - 100, 15, AlignLeft | AlignVCenter,
	"Walk against blocked ice");
    painter_pixmap.drawText(KTextOffset, 173, max_x - 100, 15, AlignLeft | AlignVCenter,
	"cubes to crack them");
    m_sprites->drawPenguinRight(painter_pixmap, KLeftOffset, 192, (m_counter % 12) / 3);
    m_sprites->drawBlockCoin(painter_pixmap, KLeftOffset+30, 192, (m_counter % 32) / 4);
    painter_pixmap.drawText(KTextOffset, 192, max_x - 100, 15, AlignLeft | AlignVCenter,
	"Free the gold coins by");
    painter_pixmap.drawText(KTextOffset, 207, max_x - 100, 15, AlignLeft | AlignVCenter,
	"crushing the ice around them");
    m_sprites->drawDead(painter_pixmap, KLeftOffset, 226, (m_counter % 16) / 2);
    m_sprites->drawFlame(painter_pixmap, KLeftOffset+30, 226, (m_counter % 16) / 2);
    painter_pixmap.drawText(KTextOffset, 226, max_x - 100, 15, AlignLeft | AlignVCenter,
	"And watch out");
    painter_pixmap.drawText(KTextOffset, 241, max_x - 100, 15, AlignLeft | AlignVCenter,
	"for the flames");
	
	painter_pixmap.drawText(0, 226, max_x, max_y - 226, AlignHCenter | AlignVCenter,
	"Press space or tap to start game");

	iView->BlitImage(m_pixmap);
}

void PlayField::drawIntro_3(void)
{
    QPainter painter_pixmap(m_pixgc);
    QColor black(0, 0, 0);
    QColor white(255, 255, 255);
    int max_x = iView->Size().iWidth;
    int max_y = iView->Size().iHeight;

    painter_pixmap.fillRect(0, 0, max_x, max_y, black);
    painter_pixmap.setPen(white);

    m_sprites->drawIntro(painter_pixmap, (max_x - 208) / 2, 7);
    painter_pixmap.drawText(0, 68, max_x, 14, AlignHCenter | AlignBottom,
	"How to score points");
    m_sprites->drawPenguinRight(painter_pixmap, KLeftOffset, 90, (m_counter % 12) / 3);
    m_sprites->drawBlock(painter_pixmap, KLeftOffset+30, 90, (m_counter % 32) / 4);
    painter_pixmap.drawText(KTextOffset, 90, max_x - 100, 15, AlignLeft | AlignVCenter,
	"Breaking ice:");
    painter_pixmap.drawText(KTextOffset, 105, max_x - 100, 15, AlignLeft | AlignVCenter,
	"5 points");
    m_sprites->drawFlame(painter_pixmap, KLeftOffset, 124, (m_counter % 16) / 2);
    painter_pixmap.drawText(KTextOffset, 124, max_x - 100, 15, AlignLeft | AlignVCenter,
	"Putting out flame with ice:");
    painter_pixmap.drawText(KTextOffset, 139, max_x - 100, 15, AlignLeft | AlignVCenter,
	"50 points");
    m_sprites->drawPenguinRight(painter_pixmap, KLeftOffset, 158, (m_counter % 12) / 3);
    m_sprites->drawBlockCoin(painter_pixmap, KLeftOffset+30, 158, (m_counter % 32) / 4);
    painter_pixmap.drawText(KTextOffset, 158, max_x - 100, 15, AlignLeft | AlignVCenter,
	"Freeing coin:");
    painter_pixmap.drawText(KTextOffset, 173, max_x - 100, 15, AlignLeft | AlignVCenter,
	"100 points");
    m_sprites->drawCoin(painter_pixmap, KLeftOffset, 192);
    painter_pixmap.drawText(KTextOffset, 192, max_x - 100, 15, AlignLeft | AlignVCenter,
	"Taking all coins:");
    painter_pixmap.drawText(KTextOffset, 207, max_x - 100, 15, AlignLeft | AlignVCenter,
	"1000 points");
    painter_pixmap.drawText(0, 226, max_x, max_y - 226, AlignHCenter | AlignVCenter,
	"Press space or tap to start game");

	iView->BlitImage(m_pixmap);
}

void PlayField::drawField(void)
{
    QPainter painter_pixmap(m_pixgc);
    QColor black(0, 0, 0);
    QColor white(255, 255, 255);
    int max_x = iView->Size().iWidth;
    int max_y = iView->Size().iHeight;
    int offs_y = (max_y - 240);
    int offs = (max_y - (243 + 28));
	int off_margin = offs/8;
	offs = offs+off_margin*2;
    int i;

    painter_pixmap.fillRect(0, offs, off_margin + max_lives * 15, 15, black);
    painter_pixmap.setPen(white);
    for (i = 0; i < m_lives; i++) {
	m_sprites->drawLive(painter_pixmap, off_margin + 15 * i, offs);
    }
    painter_pixmap.fillRect(max_x - 90 - off_margin, offs, 15, 15, black);
	char text[64];
	sprintf(text,"%d",m_levels_completed+1);
    painter_pixmap.drawText(max_x - 90 - off_margin, offs, 15, 15, AlignRight | AlignVCenter,
	text);
    painter_pixmap.fillRect(max_x - 35 - off_margin, offs, 35, 15, black);
	sprintf(text,"%d",m_score);
    painter_pixmap.drawText(max_x - 35 - off_margin, offs, 35, 15, AlignRight | AlignVCenter,
	text);

    for (i = 0; i < m_actors; i++) {
	switch (m_actor[i].m_type) {
	case Player:
	    if (m_state == Dying) {
		m_sprites->drawDead(painter_pixmap, m_actor[i].m_x, m_actor[i].m_y + offs_y,
		    m_actor[i].m_counter < 16 ? (m_actor[i].m_counter % 16) / 2 : 7);
	    } else if (m_state == HappyPenguin) {
		m_sprites->drawHappyPenguin(painter_pixmap, m_actor[i].m_x,
		    m_actor[i].m_y + offs_y, (m_actor[i].m_counter % 10) / 5);
	    } else if (m_actor[i].m_act_dir == Up) {
		m_sprites->drawPenguinUp(painter_pixmap, m_actor[i].m_x,
		    m_actor[i].m_y + offs_y, (m_actor[i].m_counter % 12) / 3);
	    } else if (m_actor[i].m_act_dir == Down) {
		m_sprites->drawPenguinDown(painter_pixmap, m_actor[i].m_x,
		    m_actor[i].m_y + offs_y, (m_actor[i].m_counter % 12) / 3);
	    } else if (m_actor[i].m_act_dir == Left) {
		m_sprites->drawPenguinLeft(painter_pixmap, m_actor[i].m_x,
		    m_actor[i].m_y + offs_y, (m_actor[i].m_counter % 12) / 3);
	    } else if (m_actor[i].m_act_dir == Right) {
		m_sprites->drawPenguinRight(painter_pixmap, m_actor[i].m_x,
		    m_actor[i].m_y + offs_y, (m_actor[i].m_counter % 12) / 3);
	    } else {
		m_sprites->drawPenguin(painter_pixmap, m_actor[i].m_x,
		    m_actor[i].m_y + offs_y);
	    }
	    break;
	case Block:
	    m_sprites->drawBlock(painter_pixmap, m_actor[i].m_x,
		m_actor[i].m_y + offs_y, m_actor[i].m_counter);
	    break;
	case BlockCoin:
	    m_sprites->drawBlockCoin(painter_pixmap, m_actor[i].m_x,
		m_actor[i].m_y + offs_y, m_actor[i].m_counter);
	    break;
	case Flame:
	    m_sprites->drawFlame(painter_pixmap, m_actor[i].m_x,
		m_actor[i].m_y + offs_y, (m_actor[i].m_counter % 16) / 2);
	    break;
	case Points:
	    m_sprites->drawPoints(painter_pixmap, m_actor[i].m_x,
		m_actor[i].m_y + offs_y, (m_actor[i].m_counter % 6) / 3);
	    break;
	case Wall:
	    m_sprites->drawWall(painter_pixmap, m_actor[i].m_x,
		m_actor[i].m_y + offs_y);
	    break;
	default:
	    break;
	}
    }
	iView->BlitImage(m_pixmap);
}

void PlayField::drawGameOver(void)
{
    QPainter painter_pixmap(m_pixgc);
    QColor black(0, 0, 0);
    QColor white(255, 255, 255);
    int max_x = iView->Size().iWidth;
    int max_y = iView->Size().iHeight;

    painter_pixmap.fillRect(0, 0, max_x, max_y, black);
    painter_pixmap.setPen(white);

    m_sprites->drawIntro(painter_pixmap, (max_x - 208) / 2, 7);
    painter_pixmap.drawText(0, 68, max_x, 14, AlignHCenter | AlignBottom,
	"Game over");
	char text[64];
    m_sprites->drawHappyPenguin(painter_pixmap, KLeftOffset, 90, (m_counter % 10) / 5);
	sprintf(text,"Levels completed: %d",m_levels_completed);
    painter_pixmap.drawText(KTextOffset, 90, max_x - 100, 30, AlignLeft | AlignVCenter,
	text);
    m_sprites->drawBlock(painter_pixmap, KLeftOffset, 124, (m_counter % 32) / 4);
	sprintf(text,"Blocks broken: %d",m_blocks_broken);
    painter_pixmap.drawText(KTextOffset, 124, max_x - 100, 30, AlignLeft | AlignVCenter,text);
	sprintf(text,"Coins collected: %d",m_coins_collected);
    m_sprites->drawBlockCoin(painter_pixmap, KLeftOffset , 158, (m_counter % 32) / 4);
    painter_pixmap.drawText(KTextOffset, 158, max_x - 100, 30, AlignLeft | AlignVCenter,
	text);
    m_sprites->drawFlame(painter_pixmap, KLeftOffset , 192, (m_counter % 16) / 2);
	sprintf(text,"Flames killed: %d",m_flames_killed);
    painter_pixmap.drawText(KTextOffset, 192, max_x - 100, 30, AlignLeft | AlignVCenter,
	text);
	sprintf(text,"Score: %d points",m_score);
    painter_pixmap.drawText(0, 226, max_x, max_y - 226, AlignHCenter | AlignVCenter,
	text);

	iView->BlitImage(m_pixmap);
}

void PlayField::drawHiScore()
{
	 QPainter painter_pixmap(m_pixgc);
    QColor black(0, 0, 0);
    QColor white(255, 255, 255);
    int max_x = iView->Size().iWidth;
    int max_y = iView->Size().iHeight;
    
	painter_pixmap.fillRect(0, 0, max_x, max_y, black);
    painter_pixmap.setPen(white);
    m_sprites->drawIntro(painter_pixmap, (max_x - 208) / 2, 7);

	 painter_pixmap.drawText(0, 68, max_x, 14, AlignHCenter | AlignBottom,
	"Hiscores");
	 for(TInt loop=0;loop<10;loop++)
	 {
		 TBuf8<20> name;
		 TBuf<20> nameAndPos;
		 nameAndPos.Format(_L("%02d. %S"),loop+1,&m_HiscoreNames[loop]);
		 name.Copy(nameAndPos);
		 char score[32];
		 sprintf(score,"%010d",this->m_Hiscores[loop]);
		 painter_pixmap.drawText(2, 92+loop*14, max_x, 14,0,(const char*)name.PtrZ());
		 painter_pixmap.drawText(0, 92+loop*14, max_x-2, 14,AlignRight,score);

	 }
   painter_pixmap.drawText(0, 226, max_x, max_y - 226, AlignHCenter | AlignVCenter,
	"Press space or tap to start game");

	iView->BlitImage(m_pixmap);
	
}

void PlayField::makeField(void)
{
    QPainter painter_pixmap(m_pixgc);
    QColor black(0, 0, 0);
    QColor white(255, 255, 255);
    int max_x = m_pixmap->width();
    int max_y = m_pixmap->height();
    int offs_y = (max_y - 240);
    int offs = (max_y - (243 + 28));
	int off_margin = offs/8;
	offs = offs+off_margin*2;

    int i;
    int j;

    painter_pixmap.fillRect(0, 0, max_x, max_y, black);

	if(offs_y >75)
	{
     m_sprites->drawIntro(painter_pixmap, (max_x - 208) / 2, 2);
	}

    painter_pixmap.setPen(white);
    painter_pixmap.drawLine(0, max_y - 241, max_x, max_y - 241);
    for (i = 0; i < m_lives; i++) {
	m_sprites->drawLive(painter_pixmap, off_margin + 15 * i, offs);
    }
   painter_pixmap.drawText(max_x - 120 - off_margin, offs, 30, 15, AlignLeft | AlignVCenter,
	"Level:");
	char text[64];
	sprintf(text,"%d",m_levels_completed+1);
    painter_pixmap.drawText(max_x - 90 - off_margin, offs, 15, 15, AlignRight | AlignVCenter,
	text);
    painter_pixmap.drawText(max_x - 70 - off_margin, offs, 35, 15, AlignLeft | AlignVCenter,
	"Score:");
	sprintf(text,"%d",m_score);
    painter_pixmap.drawText(max_x - 35 - off_margin, offs, 35, 15, AlignRight | AlignVCenter,
	text);

    /* reset all actors */
    memset(m_actor, 0, sizeof (m_actor));
    m_actors = 0;
    m_coins_in_level = 0;

    /* pixel pete, the penguin */
    m_actor[0].m_speed = m_speed;
    m_actor[0].m_type = Player;
    m_actors++;

    /* the ice blocks with and without coins */
    int level_blocks[max_config] = {17, 16, 15, 14, 13, 12};
    for (i = 0; i < level_blocks[m_levels_completed % max_config]; i++) {
	int nloops = 0;
	while (++nloops < 1000) {
	    int x = (rand() % max_cols) * 30;
	    int y = (rand() % max_rows) * 30;
	    for (j = 0; j < m_actors; j++) {
		if (m_actor[j].m_x == x && m_actor[j].m_y == y) {
		    break;
		}
	    }
	    if (j >= m_actors) {
		m_actor[m_actors].m_x = x; 
		m_actor[m_actors].m_y = y;
		m_actor[m_actors].m_speed = m_strength; // they move when pushed...
		m_actor[m_actors].m_type = Block;
		m_actors++;
		break;
	    }
	}
    }

    /* the evil flames */
    int level_flames[max_config] = {2, 3, 4, 2, 3, 4};
    int level_flames_speed[max_config] = {3, 3, 3, 5, 5, 5};
    for (i = 0; i < level_flames[m_levels_completed % max_config]; i++) {
	int nloops = 0;
	while (++nloops < 1000) {
	    int x = (rand() % max_cols) * 30;
	    int y = (rand() % max_rows) * 30;
	    if (x < (max_cols * 15) && y < (max_rows * 15)) {
		/* move the flame to make the distance to the penguin larger */
		x += max_cols * 15;
		y += max_rows * 15;
	    }
	    for (j = 0; j < m_actors; j++) {
		if (m_actor[j].m_x == x && m_actor[j].m_y == y) {
		    break;
		}
	    }
	    if (j >= m_actors) {
		m_actor[m_actors].m_x = x;
		m_actor[m_actors].m_y = y;
		m_actor[m_actors].m_speed
		    = level_flames_speed[m_levels_completed % max_config];
		m_actor[m_actors].m_type = Flame;
		m_actors++;
		break;
	    }
	}
    }

    /* the walls */
    int level_walls[max_config] = {5, 6, 7, 8, 9, 10};
    for (i = 0; i < level_walls[m_levels_completed % max_config]; i++) {
	int nloops = 0;
	while (++nloops < 1000) {
	    int x = (rand() % max_cols) * 30;
	    int y = (rand() % max_rows) * 30;
	    for (j = 0; j < m_actors; j++) {
		if (m_actor[j].m_x == x && m_actor[j].m_y == y) {
		    break;
		}
	    }
	    if (j >= m_actors) {
		m_actor[m_actors].m_x = x;
		m_actor[m_actors].m_y = y;
		m_actor[m_actors].m_type = Wall;
		m_actors++;
		/* draw the wall now, it will never move */
		m_sprites->drawWall(painter_pixmap, x, y + offs_y);
		break;
	    }
	}
    }

    /* the coins, always frozen inside an ice block */
    for (i = 0; i < m_coins; i++) {
	int nloops = 0;
	while (++nloops < 1000) {
	    int x = (rand() % max_cols) * 30;
	    int y = (rand() % max_rows) * 30;
	    for (j = 0; j < m_actors; j++) {
		if (m_actor[j].m_x == x && m_actor[j].m_y == y
		    && m_actor[j].m_type == Block) {
		    break;
		}
	    }
	    if (j < m_actors) {
		m_actor[j].m_type = BlockCoin;
		break;
	    }
	}
    }
    m_coins_in_level = m_coins;
}

void PlayField::check_field(enum Types map[max_rows][max_cols],
    bool visited[max_rows][max_cols], int row, int col) {
    visited[row][col] = true;
    if (row > 0 && map[row - 1][col] != Wall
	&& visited[row - 1][col] == false) {
	check_field(map, visited, row - 1, col);
    }
    if (row < (max_rows - 1) && map[row + 1][col] != Wall
	&& visited[row + 1][col] == false) {
	check_field(map, visited, row + 1, col);
    }
    if (col > 0 && map[row][col - 1] != Wall
	&& visited[row][col - 1] == false) {
	check_field(map, visited, row, col - 1);
    }
    if (col < (max_cols - 1) && map[row][col + 1] != Wall
	&& visited[row][col + 1] == false) {
	check_field(map, visited, row, col + 1);
    }
};
bool PlayField::isFieldOk(void)
{
    enum Types map[max_rows][max_cols];
    bool visited[max_rows][max_cols];
    int i;
    int j;

    /* first, set all fields to "unvisited" and build the map */
    for (i = 0; i < max_rows; i++) {

⌨️ 快捷键说明

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