Jump to content

My shapes do not appear on the map (Tetris game)

- - - - -

  • Please log in to reply
6 replies to this topic

#1
ketybrown

ketybrown

    Newbie

  • Members
  • Pip
  • 3 posts
Hello everyone. I'm a newbie and I was given a project in school to develop a tetris-like clone. I have no compile and build errors but my shapes wont appear on the grid(game board). I'm thinking its logic error. I've worked my way through it but to no avail.

Please help. Its kind of urgent!

This is my map(grid/gameBoard) codes:

#include<ctime>

#include "map1.h"

#include "block1.h"

#include "Shuffle1.h"

#include "gwin.h"


extern Block4 bl, bl2, bl3;		//play, next, save

int lines[4];


Map::Map(){

}


void Map::initialize(){

	for(int x=0; x<17; x++){

		for(int y=0; y<21; y++){

			map[x][y] = EMPTY;

			}

		}

	

	for(int i=0; i<4; i++)

		lines[i]=0;

}



void Map::destroy(int x, int y, int w, int h){

	for(int i=0; i<=h; i++){

		for(int j=0; j<=w; j++){

			map[x+j][y+i] = EMPTY;

		}

	}

}


void Map::draw(){

	Block4 block;

	int temp_type, temp_type1, temp_type2;

	bl2.type = rand()%7, bl3.type = rand()%7;

		 

	//draw shape falling down

	for(int x=0; x<10; x++){

		for(int y=0; y<20; y++){

			/*if(map[x][y] >=0){

				Gwin.moveTo(x*32, y*32);

				temp_type = bl.type;

				Block4 block(x, y, temp_type);*/

			if (map[x][y] == ACTIVE){

//				Gwin.moveTo(x*32, y*32);

				temp_type = bl.type;

				bl.draw(x*32, y*32, temp_type);

			}

		}

	}

	

	

	//draw next shape coming down

	for(int x=11; x<16; x++){

		for(int y=5; y<7; y++){

			if(map[x][y] != EMPTY){

				Gwin.moveTo(x*32, y*32);

				temp_type1 = bl2.type;

				bl2.draw(x, y, temp_type1);

			}

		}

	}

	

	//for shape on hold, user can change to

	for(int x=11; x<16; x++){

		for(int y=9; y<11; y++){

			if(map[x][y] != EMPTY){

			Gwin.moveTo(x*32, y*32);

			temp_type2 = bl3.type;

			bl3.draw(x, y, temp_type2);

			}

		}

	}

}



void Map::checkForLines(){

	int sum=1;

	for(int y=19; y>=0 && sum!=0 ;y--){

		sum=0;

		for(int x=0; x<10; x++){

			if(map[x][y] != EMPTY)

				sum++;

		}

		if(sum == 10){

			lines[count_line] = y;

			count_line++;

			total_lines++;

		}

	}

}


void Map::colorLines(){

	for(int i=0; i<4 && lines[i]!=0; i++){

		for(int x=0; x<10; x++){

			map[x][lines[i]] = CYAN;

		}			

	}

}


void Map::removeLines(){

	//move top part down

	for(int y=lines[0]; y - count_line >= 0; y--){

		for(int x=0; x<10; x++){

			map[x][y] = map[x][y-count_line];

		}

	}

	

	//fill up lines moved down

	for(int y= count_line-1; y>= 0; y--){

		for(int x=0; x<10; x++){

			map[x][y] = EMPTY;

		}

	}

	for(int i=0; i<4 && lines[i]!=0; i++){

		lines[i]=0;

	}

}


This is my main function:

#include<iostream>

#include<string>

#include<cstdlib>

#include<ctime>

#include<cmath>


#include "Shuffle1.h"

#include "block1.h"

#include "map1.h"

#include "gwin.h"


using namespace GwinKeyNames;

using namespace std;


Block4 bl, bl2, bl3;		//play, next, save

extern Map mapM;


#define SCORE (19 - bl.b[0].y) + count_line*15 + pow(5.0,count_line) + 5*level

#define TICKSPEED (int)(TIMEINTERVAL/10+TIMEINTERVAL/level)

#define LEVELUP start % (int)(TIMEINTERVAL*20)



void generate_block();

void restart();

void tick();

void draw();

void play();

void help();

void setup();

void highscore();



Image gameback("gameback.jpg");

//srand((unsigned)time(NULL)); 

DWORD start = 0, start1 = 0;

Key keyvalue = ' ' ;						//for keys presed in game loop




int main(){


	int menuSelect = 0;						//initialize the menu selection to zero

	bool required = true;					//menu loop

	bool screenMenu = true;					//main default diaplay menu

	bool skill = false;

	bool help = false;						//help menu

	bool highScore = false;					//high score menu

	bool setup = false;						//setup menu 

	bool menuExit = false;

	bool resume = false;					//pause or resumed


	bool control = false;


	Key keyvalue1 = ' ';						// for menu keys pressed



	//Load images

	Image menu0("startgame1.jpg");

	Image menu1("skill1.jpg");

	Image menu2("highscore1.jpg");

	Image menu3("setup1.jpg");

	Image menu4("help1.jpg");

	Image menu5("exit1.jpg");


	Gwin.showConsole();						//To show console window

	Gwin.resize(560,700);

	Gwin.show();

	//Gwin.resize(BOX_W, BOX_H);				//resizes the gwindow to a new size

	Gwin.setTitle("My Tetris Game");		//Sets the gwindow to a new title


	do{

		Gwin.drawImage(menu0, 0, 0);

		Gwin.refresh();

		//keyvalue = Keyboard.getch();

		while(required){		//menu loop

			keyvalue = Keyboard.getch();

			switch(keyvalue){

				case ESCAPE:

					Gwin.clear();

					menuSelect = 0;

					Gwin.drawImage(menu0,0,0);

					required=false;

					break;

				case CURSOR_UP:

					//if ( (menuSelect > 0) && (screenMenu == true) )

					//{

					menuSelect--;

					Gwin.clear();


					if (menuSelect == 0 ) 

					{

						Gwin.drawImage(menu0,0,0);

					}

					if (menuSelect == 1 )

					{

						Gwin.drawImage(menu1,0,0);

					}

					else if (menuSelect == 2)

					{

						Gwin.drawImage(menu2,0,0);

					}

					else if (menuSelect == 3)

					{

						Gwin.drawImage(menu3,0,0);

					}

					else if (menuSelect == 4)

					{

						Gwin.drawImage(menu4,0,0);

					}

					else if (menuSelect == 5 || menuSelect==-1)

					{

						Gwin.drawImage(menu5,0,0);

						if(menuSelect==-1)

							menuSelect=5;

					}

					//}


					break;


				case CURSOR_DOWN:	 //move through menu by means of changing pictures 0 to 5 i.e 6 pictures in total

					//if ( (menuSelect <= 4) && (screenMenu == true) )

					//{

					menuSelect++;

					Gwin.clear();

					if (menuSelect == 0 || menuSelect==6) 

					{

						Gwin.drawImage(menu0,0,0);

						//if(menuSelect==6)

							menuSelect=0;

					}

					if (menuSelect == 1 )

					{

						Gwin.drawImage(menu1,0,0);


					}

					else if (menuSelect == 2)

					{

						Gwin.drawImage(menu2,0,0);

					}

					else if (menuSelect == 3)

					{

						Gwin.drawImage(menu3,0,0);

					}

					else if (menuSelect == 4)

					{

						Gwin.drawImage(menu4,0,0);

					}

					else if (menuSelect == 5)

					{

						Gwin.drawImage(menu5,0,0);


					}

					//}

					break;


				case RETURN:		//enter key to go in to the selected menu item


					if (menuSelect == 0) //play game

					{

						Gwin.refresh();

						Gwin.clear(BLACK);

					//	Gwin.setFillColour(YELLOW);

					//	Gwin.drawImage(gameback, 0,0);

						start = GetTickCount();


						bl2.type = rand()%7;

						generate_block();

//						bl2.mapM.draw();

					//	ready = true;

						play();


					}

					else if (menuSelect == 1)	//set skill level

					{

						cout << "Code not yet written " << endl;


					}

					else if (menuSelect == 2) //display high score

					{

						/*Gwin.clear();

						screenMenu = false;

						displayHighScores();*/

						cout << "Code not yet written " << endl;


					}

					else if (menuSelect == 3)	//set up

					{

						cout << "Code not yet written " << endl;


					}

					else if (menuSelect == 4)	//help

					{

						/*Gwin.clear();

						screenMenu = false;

						Gwin.drawImage(helpMenu,0,0);*/

						cout << "Code not yet written " << endl;


					}

					else if (menuSelect == 5)	//exit

					{

						control = true;

						required = false;

						menuExit = true;

						cout << "Now exiting... " << endl;

						Sleep(1000);

						exit(0);

						//required1 = false;


						break;

					}


					break;


				case CURSOR_RIGHT:	

					break;


			}

			//	Gwin.refresh();


			/**********************************************************END_OF_MENU**********************************************************/		


		}

	}	while(keyvalue!=ESCAPE);

	//end of while loop

}


void tick(){

	if((start % TICKSPEED == 0 && !CURSOR_DOWN)

		|| free_fall){

			bl.down();

	} 

}


void draw(){	//still incomplete. To draw the score and level layer

	Gwin.moveTo(380, 20);

}


//void update(){

//	Key key = ' ' ;

//	if(game_over)

//		return;

//

//	if(Keyboard.kbhit())

//		key = Keyboard.getch();

//	if(key = GwinKeyNames::F9)

//}


void generate_block(){

	if(!first_block){

		if(!F3)

			score += SCORE;

		for(int y=0; y<20; y++){

			for(int x=0; x<10; x++){

				if(map[x][y] = ACTIVE)

					map[x][y] = bl.type;

			}

		}

	}

	else {

		first_block =false;

	}


	prev_pos_x = bl.b[0].x;

	prev_pos_y = bl.b[0].y;

	bottom_reached = false;

	new_block = true;

	holded = false;

	ready_for_new_block = false;

	free_fall = false;

	count_line = 0;

	Block4 next_block;

	//Block4 next_block(3, 0, bl2.type);

	bl = next_block;

	next_block.b[0].x = 3;

	next_block.b[0].y = 0;

	next_block.type = bl2.type;


	//	Block4 next_block(3, 0, bl2.type);


	next_block.draw(next_block.b[0].x, next_block.b[0].y, next_block.type);


	//	next_block = bl.draw(3, 0, bl2.type);			//next_block

	int random_number = rand() % 7;

	//new_block

	//Block4 new_block(11, 5, random_number);

	//bl2 = new_block;

	Block4 new_block;

	new_block.b[0].x = 11;

	new_block.b[0].y = 5;

	new_block.type = random_number;

	//	Block4 new_block(11, 5, random_number);

	new_block.draw(new_block.b[0].x, new_block.b[0].y, new_block.type);


	//	new_block = bl2.draw(11, 5, random_number);			//new_block

}


//void play(){

//	

//}


void bottom(){

	static int count = 0;

	bool temp = bottom_reached;

	bottom_reached = false;

	for(int i=0; i<4; i++){

		if(bl.b[i].y == 19 || map[bl.b[i].x][bl.b[i].y+1] >= 0){

			bottom_reached = true;

		}

	}


	if(bottom_reached){

		count++;

		if(count > (int)(TIMEINTERVAL/2)){

			ready_for_new_block = true;

			count = 0;

		}

		else if((CURSOR_RIGHT || CURSOR_LEFT || CURSOR_UP) && moved)

			count = 0;

	}

	else

		count = 0;

}



void restart(){

	mapM.initialize();

	score = 0;

	total_lines = 0;

	level = 1;

	start = 0;

	start1 = 0;

	for(int i=0; i<4; i++)

		counter[i] = 0;

	count_line = 0;

	level_up_count = 0;

	for(int i=0; i<4; i++)

		t[i] = 1;

	for(int i=0; i<7; i++)

		bottom_reached = false;

	game_over = false;

	first_block = true;

	new_block = true;

	ready_for_new_block = false;

	block_number = 0;

	level_up = true;

	quit = false;

	moved = false;

	free_fall = false;

	prev_pos_x=0;

	prev_pos_y=0;

	holded = false;

	pause=false;

	first_hold = true;

	generate_block();


}


void play(){

	int temp_type;

	while(!ESCAPE && !quit){

		if(!game_over){

			start++;

		}

		if(LEVELUP == 0){

			level++;

			level_up = true;

		}

	

	for(int x=0; x<10; x++){

		for(int y=0; y<20; y++){

			/*if(map[x][y] >=0){

				Gwin.moveTo(x*32, y*32);

				temp_type = bl.type;

				Block4 block(x, y, temp_type);*/

			if (map[x][y] == ACTIVE){

				bl.type = temp_type;

				bl.draw(x*32, y*32, temp_type);

			}

		}

	}

		/*if(!lines[0] && !pause)

		tick();*/

		if(!lines[0] && !free_fall && !pause){

			if (Keyboard.kbhit()){

				Keyboard.getch();

				keyvalue = Keyboard.getch();

				switch(keyvalue){

					case CURSOR_LEFT:{

						counter[CURSOR_LEFT]++;

						bl.left();

									 }break;


					case CURSOR_RIGHT:{

						counter[CURSOR_RIGHT]++;

						bl.right();

									  }break;


					case CURSOR_DOWN:{

						counter[CURSOR_DOWN]++;

						bl.down();

									 }break;


					case SPACE:{	//free-fall key

						counter[SPACE]++;

						free_fall = true;

							   }break;


					case CURSOR_UP:{	//rotates the shape

						counter[CURSOR_UP]++;

						bl.up();

								   }break;


					case F3:{	//for user to change type of shape falling down

						if(!holded){

							bl3.type = rand()%7;

							int temp_type = bl3.type;

							bl.destroy();

							/*Block4 draw(3, 0, temp_type);

							bl = new_block;*/

							Block4 new_block;

							//new_block.b[0].x = 11;

							//new_block.b[0].y = 5;

							//new_block.type = temp_type;

							new_block.draw(11, 5, temp_type);

							//	new_block.draw(new_block.b[0].x, new_block.b[0].y, new_block.type);

						}

						else{

							first_hold = false;

							generate_block();

						}

						holded = true;

							}break;


					case F2:{	//F2 to restart game

						if(holded){

							restart();

						}

							}break;


					case 'p':		//pause game

					case 'P':

						pause = true;

						resume = false;

						while(resume = false){

							pause = true;

						}break;


					case 'c':		//resume game after pause

					case 'C':

						resume = true;

						pause = false;


				}

			}

			if(!lines[0] && !pause)

				tick();

		}


		if(bottom_reached){

			mapM.checkForLines();

		}

		if((!lines[0] && ready_for_new_block) || (!lines[0] && bottom_reached && free_fall))

			generate_block();


		draw();

		while(start >= start1) {}

	}



}


Edited by dargueta, 11 April 2011 - 01:42 PM.


#2
gregwarner

gregwarner

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 853 posts
  • Location:Arkansas
Please use CODE tags to surround your code and use proper indenting. It's very difficult to read without them.
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.

– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#3
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,718 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
Dude, this is incredibly intimidating to read. Can you tell us specifically where/what you think the problem is?
sudo rm -rf /

#4
Zer033

Zer033

    Learning Programmer

  • Members
  • PipPipPip
  • 79 posts
Where is shuffle1.h, map1.h block1.h and gwin.h? I'll help you out, but would like to see those as well so I can compile this and work on it. I'll look it over when I got time there's a lot of code there to digest though.

#5
ketybrown

ketybrown

    Newbie

  • Members
  • Pip
  • 3 posts

//Block1.h


#ifndef BLOCK_H

#define BLOCK_H


struct Block{

	int x, y;

	Block();

	//~Block();


	void destroy();

	int set(int x, int y);

};


struct Block4{

	Block b[4];

//	Block4 bl, bl2, bl3;		//play, next, save


	int type;


	Block4();

	Block4(const Block4 &block);


	int set(int dx, int dy);

	int draw(int, int, int type);

//	int draw();

	void destroy();

	void right();

	bool down();

	void left();

	void up();


};


#endif		//BLOCK_H



//Block1.cpp


#include<ctime>

#include "block1.h"

#include "map1.h"

#include "Shuffle1.h"

#include "gwin.h"


using namespace GwinColourNames;

using namespace std;;


enum type{ SQUARE, EL1, ZIGZAG1, ZIGZAG2, TE, EL2, BAR };


//Block4 bl, bl2, bl3;		//play, next, save

Map mapM;

Block::Block(){

}


void Block::destroy(){

	for(int x=0; x<17; x++){

		for(int y=0; y<21; y++){

			map[x][y] = EMPTY;

		}

	}

}


int Block::set(int x, int y){

	if(!(x<0) || (y<0)){

		if(new_block && map[x][y] >=0){

			game_over = true;

		}

		map[x][y] = ACTIVE;

	}

	this->x = x;

	this->y =y;


	return 0;	

}



Block4::Block4(const Block4& block){

	type = block.type;

	for(int i=0; i<4; i++){

		b[i].x = block.b[i].x;

		b[i].y = block.b[i].y;

	}

}




Block4::Block4(){

	srand( (unsigned)time( NULL ) );

	type = (rand()%7)+1;

}



int Block4::set(int dx, int dy){

	for(int i=0; i<4; i++){

		b[i].set((b[i].x + dx), (b[i].y + dy));

		moved = true;

	}

	return 0;

}



int Block4::draw(int x, int y, int type){		//draw function

//int Block4::draw(){

//	int x, y, type;


	this->type = type;

	if(x>10)

		mapM.destroy(10, y, 4,2);

		

		switch(type){

			case SQUARE:{

				Gwin.setFillColour(BLUE);

				Gwin.rectangle(b[0].set(x+1, y+1), b[1].set(x+1, y), b[2].set(x+2, y), b[3].set(x+2, y+1));

						}break;

/*			case EL1:{

				Gwin.setFillColour(RED);

				Gwin.rectangle((b[0].set(x+1, y)), (b[1].set(x, y)), (b[2].set(x+2, y)), (b[3].set(x, y+1)));

			}break;

			case EL2:{

				Gwin.setFillColour(YELLOW);

				Gwin.rectangle((b[0].set(x+1, y)), (b[1].set(x,y)), (b[2].set(x+2, y)), (b[3].set(x+2, y+1)));

			}break;

			case ZIGZAG1:{

				Gwin.setFillColour(GREEN);

				Gwin.rectangle((b[0].set(x+1, y)), (b[1].set(x+2, y)), (b[2].set(x, y+1)), (b[3].set(x+1, y+1)));

			}break;

			case ZIGZAG2:{

				Gwin.setFillColour(PINK);

				Gwin.rectangle((b[0].set(x+1, y)), (b[1].set(x, y)), (b[2].set(x+2, y+1)), (b[3].set(x+1, y+1)));

			}break;

			case TE:{

				Gwin.setFillColour(ORANGE);

				Gwin.rectangle((b[0].set(x+1, y)), (b[1].set(x, y)), (b[2].set(x+2, y)), (b[3].set(x+1, y+1)));

			}break;

			case BAR:{

				Gwin.setFillColour(WHITE);

				Gwin.rectangle((b[2].set(x, y)), (b[1].set(x+1, y)), (b[0].set(x+2, y)), (b[3].set(x+3, y)));

			}break;

//			default:{

//				cerr << "Error! " << endl;

//			}break;

		}*/


		return type;

		}

}


void Block4::destroy(){

	for(int i=0; i<4; i++)

		b[i].destroy();

}



void Block4::up(){

	Block t[4];	//test blocks

	for(int i=0; i<4; i++){

		t[i].x = b[i].x;

		t[i].y = b[i].y;

		

		//rotate

		t[i].x = - (b[i].y - b[0].y) + b[0].x;

		t[i].y = (b[i].x - b[0].x) + b[0].y;

		

		//check for collision

		if( (t[i].x > 9) || (t[i].y > 19) || (map[t[i].x][t[i].y] >= 0)){

			moved = false;

			return;

		}

	}

	

	if(type == SQUARE) 

	return;

	destroy();		//equivalent to erase

	for(int i=0; i<4; i++){

		b[i].set(t[i].x, t[i].y);

	}

}


void Block4::right(){

	for(int i=0; i<4; i++){

		if(b[i].x == 9 || map[b[i].x+1][b[i].y] >= 0){

			moved = false;

			return;

		}

	}

	destroy();		//equivalent to erase

	set(1, 0);		//coordinates to moveRight 

}



bool Block4::down(){

	for(int i=0; i<4; i++){

		if(b[i].y == 19 || map[b[i].x][b[i].y+1] >= 0){

			return false;

		}

	}

	bottom_reached = false;

	destroy();		//equivalent to erase

	set(0, 1);		//coordinates to moveLeft

	return true;

}


void Block4::left(){

	for(int i=0; i<4; i++){

		if(b[i].x == 0 || map[b[i].x-1][b[i].y] >= 0) {

			moved = false;

			return;

		}

	}

	destroy();		//equivalent to erase

	set(-1, 0); 	//coordinates to moveLeft

}


//map1.h


#ifndef MAP_H

#define MAP_H


#define ACTIVE 			-1

#define EMPTY 			-2


/*Colors

#define BLUE	0

#define RED		1 

#define	YELLOW	2

#define GREEN	3

#define	PINK	4

#define ORANGE	5

#define WHITE	6

#define CYAN	7*/



struct Map{

	Map();

	void initialize();

	void destroy(int x, int y, int w, int h);

	void draw();

	void checkForLines();

	void colorLines();

	void removeLines();

};


//extern int map[17][21];



#endif 	//MAP_H



//map1.cpp



#include<ctime>

#include "map1.h"

#include "block1.h"

#include "Shuffle1.h"

#include "gwin.h"


extern Block4 bl, bl2, bl3;		//play, next, save

int lines[4];


Map::Map(){

}


void Map::initialize(){

	for(int x=0; x<17; x++){

		for(int y=0; y<21; y++){

			map[x][y] = EMPTY;

			}

		}

	

	for(int i=0; i<4; i++)

		lines[i]=0;

}



void Map::destroy(int x, int y, int w, int h){

	for(int i=0; i<=h; i++){

		for(int j=0; j<=w; j++){

			map[x+j][y+i] = EMPTY;

		}

	}

}


void Map::draw(){

	Block4 block;

	int temp_type, temp_type1, temp_type2;

	bl2.type = rand()%7, bl3.type = rand()%7;

		 

	//draw shape falling down

	for(int x=0; x<10; x++){

		for(int y=0; y<20; y++){

			/*if(map[x][y] >=0){

				Gwin.moveTo(x*32, y*32);

				temp_type = bl.type;

				Block4 block(x, y, temp_type);*/

			if (map[x][y] == ACTIVE){

//				Gwin.moveTo(x*32, y*32);

				temp_type = bl.type;

				bl.draw(x*32, y*32, temp_type);

			}

		}

	}

	

	

	//draw next shape coming down

	for(int x=11; x<16; x++){

		for(int y=5; y<7; y++){

			if(map[x][y] != EMPTY){

				Gwin.moveTo(x*32, y*32);

				temp_type1 = bl2.type;

				bl2.draw(x, y, temp_type1);

			}

		}

	}

	

	//for shape on hold, user can change to

	for(int x=11; x<16; x++){

		for(int y=9; y<11; y++){

			if(map[x][y] != EMPTY){

			Gwin.moveTo(x*32, y*32);

			temp_type2 = bl3.type;

			bl3.draw(x, y, temp_type2);

			}

		}

	}

}



void Map::checkForLines(){

	int sum=1;

	for(int y=19; y>=0 && sum!=0 ;y--){

		sum=0;

		for(int x=0; x<10; x++){

			if(map[x][y] != EMPTY)

				sum++;

		}

		if(sum == 10){

			lines[count_line] = y;

			count_line++;

			total_lines++;

		}

	}

}


void Map::colorLines(){

	for(int i=0; i<4 && lines[i]!=0; i++){

		for(int x=0; x<10; x++){

			map[x][lines[i]] = CYAN;

		}			

	}

}


void Map::removeLines(){

	//move top part down

	for(int y=lines[0]; y - count_line >= 0; y--){

		for(int x=0; x<10; x++){

			map[x][y] = map[x][y-count_line];

		}

	}

	

	//fill up lines moved down

	for(int y= count_line-1; y>= 0; y--){

		for(int x=0; x<10; x++){

			map[x][y] = EMPTY;

		}

	}

	for(int i=0; i<4 && lines[i]!=0; i++){

		lines[i]=0;

	}

}



//Shuffle1.h


 #ifndef SHUFFLE_H

#define SHUFFLE_H


#define BOX_W			320		//new graphical window width

#define BOX_H			640		//new graphical window height

#define TIMEINTERVAL	100		//time to speed up the game


//game elements

//extern 

extern int map[17][21];

extern int total_lines;

extern int level;

extern int score;


//counters

extern int counter[4];

extern int level_up_count;

extern int count_line;


//states

extern int t[4];

extern bool game_over;

extern bool free_fall;

extern bool moved;

extern bool bottom_reached;

extern bool first_block;

extern bool new_block;

extern bool ready_for_new_block;

extern int block_number;

extern bool level_up;

extern int prev_pos_x;

extern int prev_pos_y;

extern int lines[4];

extern int quit;

extern bool holded;

extern bool pause;

extern bool resume;

extern bool first_hold;



#endif 	//SHUFFLE_H



//Shuffle1.cpp


#include "Shuffle1.h"



//elements of game

//Block4 bl, bl2, bl3;	//play, next, save

int map[17][21];

int score = 0;

int total_lines = 0;

int level = 1;


//counters

int counter[4] = {0,0,0,0};

int count_line = 0;

int level_up_count = 0;

 

 //states

int t[4] = {1,1,1,1};

bool game_over = false;

bool free_fall = false;

bool moved = false;

bool bottom_reached = false;

bool first_block = true;

bool new_block = true;

bool ready_for_new_block = false;

extern int block_number = 0;

extern bool level_up = false;

extern int prev_pos_x = 0;

extern int prev_pos_y = 0;

//extern int lines[4];

extern int quit = false;

extern bool holded = false;

extern bool pause = pause;

extern bool resume = false;

extern bool first_hold = true;


The "gwin.h" is the library I was told to use at school to draw my shapes. We were strictly told to use this. Its like allegro, open gui, sdl etc. but its a lame library. Apparently, just my school uses this.

I'm guessing my draw function is the problem here...

Thanks.

Edited by dargueta, 12 April 2011 - 09:48 AM.
Please use [code][/code] tags next time.


#6
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,718 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
Please use the code tags next time. It makes it really hard to read without them, so I edited your post and did it for you just now. Highlight your code and press the # button, and it'll make it nice and pretty when you post it.

As far as your problem:



int Block4::set(int dx, int dy){

	for(int i=0; i<4; i++){

		b[i].set((b[i].x + dx), (b[i].y + dy));

		moved = true;

	}

	[COLOR="RED"][B]return 0;[/B][/COLOR]

}



int Block4::draw(int x, int y, int type){		//draw function

...

Gwin.rectangle([COLOR="RED"][B]b[0].set(x+1, y+1), b[1].set(x+1, y), b[2].set(x+2, y), b[3].set(x+2, y+1)[/B][/COLOR]);


You're passing in 0 for every parameter.
sudo rm -rf /

#7
ketybrown

ketybrown

    Newbie

  • Members
  • Pip
  • 3 posts

dargueta said:

Please use the code tags next time. It makes it really hard to read without them, so I edited your post and did it for you just now. Highlight your code and press the # button, and it'll make it nice and pretty when you post it.

As far as your problem:


int Block4::set(int dx, int dy){

	for(int i=0; i<4; i++){

		b[i].set((b[i].x + dx), (b[i].y + dy));

		moved = true;

	}

	[COLOR="RED"][B]return 0;[/B][/COLOR]

}



int Block4::draw(int x, int y, int type){		//draw function

...

Gwin.rectangle([COLOR="RED"][B]b[0].set(x+1, y+1), b[1].set(x+1, y), b[2].set(x+2, y), b[3].set(x+2, y+1)[/B][/COLOR]);


You're passing in 0 for every parameter.


Thanks, I get it now.

But how can I access the functions of a class from another class?
Say, 'Block' is a struct and 'Blah' is another struct, and i created an array object of Blah in the Block struct like this:

Blah b[4];

and then created an object of Block in my main function like this:

Block block;

is this legal? --->


for(int m=0; m<4; m++){

   b[m].block.draw();

}


draw() is a function in the Block struct.

Thanks.
:)

Edited by dargueta, 15 April 2011 - 08:56 PM.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users