Jump to content
  • Advertisement
Sign in to follow this  
Twinsen2

Trigering Events in OpenGL Tile Engine

This topic is 4828 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hey all. I have a bit of a problem here, i have created a tile engine and i have made a function which checks the id of an array"the map" for a value, and if true then it launches an event, the problem i have is that it launches the event on any tile even though the id of the tile isnt the right one: Here is the array:
char map[10][10] = {
// 0  1  2  3  4  5  6  7  8  9
  {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, //0 BOTTOM RIGHT
  {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //1
  {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //2
  {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //3
  {1, 0, 0, 0, 2, 0, 0, 0, 0, 1}, //4
  {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //5
  {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //6
  {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //7
  {1, 0, 0, 0, 0, 0, 0, 0, 3, 1}, //8
  {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, //9 TOP RIGHT
};
As you can see the number 3 in the array is the place where an event occurs.

  TextureImage[0] = LoadBMP("Data/Tile1_Grass.bmp");
  TextureImage[1] = LoadBMP("Data/Tile2_Block.bmp");
  TextureImage[2] = LoadBMP("Data/Tile3_Character.bmp");
  TextureImage[3] = LoadBMP("Data/Tile1_Grass.bmp");

here are my textures so far

Here is where i think the problem is:
if (keys['W'] && !wp)
{
  wp= TRUE;  // w is pressed?
     yCord -= 0.2f;  // move camera with character
				
	if(map[cordx + 1] [cordy] != 1)  // this is for going up W, and checks  
                                         // colliosn detection.
                                         // a is the texture value 4 wall
	   {
// basically what this does is it moves the character by going to the tile
// above and storing its value, providing its not one, it then passes the value
// to the trigger function, then it goes back to the original tile and loads
// the tile aboves value into it
// it then goes above again and gives the new tile the value 2
// therefore the character moves up correctly.
		cordx ++;                
		trigger(cordx,cordy);
	        cordx --;
		map[cordx] [cordy] = trigger(cordx,cordy);
		cordx ++;
		map[cordx] [cordy] = 2;	
	   }
				
} 

here is the trigger function:

int trigger(int xcord, int ycord)
{
	if(map [xcord][ycord] = 3)
	{
      ///////////////EVENTS GO HERE////////////////////////
	   map[xcord][ycord] = 2;


	}



return(1);
}

Okay what this should do if im right is go through the map until it reaches the top right corner where the number 3 is and then set that tile's value to 2. The prob is that it changes every tile's value to 2, but i dont understand as the if statement says only at 3. cheerz, and thankyou 4 ur help :) edit: added source tags -SiCrane [Edited by - SiCrane on July 28, 2005 10:45:39 AM]

Share this post


Link to post
Share on other sites
Advertisement
Change
if(map [xcord][ycord] = 3) 
to
if(map [xcord][ycord] == 3)

If you use = instead of == you'll asign the value, and that willl always be true.

Share this post


Link to post
Share on other sites
Quote:
Original post by Perost
Change
if(map [xcord][ycord] = 3) 
to
if(map [xcord][ycord] == 3)

If you use = instead of == you'll asign the value, and that willl always be true.


tsk...tsk....tsk.....so stupid. thankz man,
I just wrote a 2500 word uni essay b4 i did this so my brain was a bit dead, and the reason my textures being stores are inaffective is because this is the first game in 3d i have ever made so plz bare with me.

***UPDATE i tried == to but some reason it still wants to change the tile to the value of 2???
there must be something making it equal 3 mayble??
I think its my code for moving tiles maybe??

thankz very much for ur replys

Share this post


Link to post
Share on other sites
cordx ++;
trigger(cordx,cordy);
cordx --;
map[cordx] [cordy] = trigger(cordx,cordy);
cordx ++;
map[cordx] [cordy] = 2;

That would be what is assigning each tile a value of 2.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!