# TylerHum

Member

7

100 Neutral

• Rank
Newbie
1. ## Random Level Builder Help

[s] Ah I've discovered the source of the issue! My only issue now is that I don't know how to actually fix it. CollisionCheck snippet: for(int y=x1; y<y2; y++) { for(int x=x1; x<x2; x++) { if(LevelCurrent[x][y].walkable==1) return false; } } return true; The issue is that since the halls are 1 tile in width whenever it goes through y<y2 or x<x2 its equal to it so it just passes by without being checked. y=y1; x=x1; while(y<=y2) { while(x<=x2) { if(LevelCurrent[x][y].walkable==1) return false; x++; } y++; } return true; ^ I tried doing this so it wouldnt just pass on and the only thing it would do after that was build halls straight up for some odd reason. [/s]Ya know what disregard all of that I completely forgot about do while loops and it's now working perfectly. Thank you all for your help.
2. ## Random Level Builder Help

Ok I got the issues with the checking function (Thanks Lorenzo) and they now work fine with building the rooms but the hallways still build over everything as if nothing is there. Here's how it does hallways moving up. All the other hall builders are basically the same as this. if((LevelCurrent[x][y].flag_build==1||LevelCurrent[x][y].flag_build==2)&&type==0) { length=rand()%10; while(!cont||y-length<4||!CollisionCheck(LevelCurrent,x,y-length,x,y)) { length--; if(length<=4) cont=true; } if(length>4&&y>4&&LevelCurrent[x][y].direction!=2) { for(int i=0; i<length; i++) { LevelCurrent[x][y-i].walkable=1; } LevelCurrent[x][y].flag_build=0; LevelCurrent[x][y-length].flag_build=1; LevelCurrent[x][y-length].tries=5; LevelCurrent[x][y-length].direction=0; } else { if(LevelCurrent[x][y].tries>0) LevelCurrent[x][y].tries--; else if(LevelCurrent[x][y].tries==0) LevelCurrent[x][y].flag_build=0; } } I'm starting to think I'm doing halls all wrong to be honest. Any input would be great. Edit: Also if I set the compiler to Release instead of Debug (MS VC++ 2010) and set a break in the collision check function it claims it will never be hit.
3. ## Random Level Builder Help

Yea I've debugged if for a few hours now and I still cant find the issue.
4. ## Random Level Builder Help

Ok I'm trying to make a Level builder that'll build rooms and halls but its become rather hit and miss and I'm stuck on it. For one the checker that makes sure it wont build over itself only fires when it wants it seems and two it can go from putting completely random garbage all over to getting stuck in infinite loops. Build Level: #include "BL.h" bool CollisionCheck(Tile LevelCurrent[100][100],int x,int y,int width,int height) { int check=0; bool fin; for(y; y<height; y++) { for(x; x<width; x++) { if(LevelCurrent[x][y].walkable==1) check++; } } if(check>0) fin=false; else if(check==0) fin=true; return fin; } void BuildLevel(Tile LevelCurrent[100][100],int stair_x,int stair_y) { bool finish=false,cont=false; int x,y,x2,y2,type,length,roll,counter; type=4; for(y=0; y<100; y++) { for(x=0; x<100; x++) { LevelCurrent[x][y].walkable=0; LevelCurrent[x][y].flag_build=0; LevelCurrent[x][y].tries=0; } } LevelCurrent[stair_x][stair_y].flag_build=1; LevelCurrent[stair_x][stair_y].tries=5; while(!finish) { /* TYPES: Halls= 0-3 Standard Rooms= 4-24 Uncommon Rooms= 25-45 Rare Rooms= 46-66 */ type=rand()%5; for(y=0; y<100; y++) { for(x=0; x<100; x++) { //===========HALLS============================================================================================// //===UpHall============// if((LevelCurrent[x][y].flag_build==1||LevelCurrent[x][y].flag_build==2)&&type==0) { length=rand()%20; while(!CollisionCheck(LevelCurrent,x,y-length,1,length)&&y-length>4) { if(length<=4) break; length--; } if(length>4) { for(int i=0; i<length; i++) { LevelCurrent[x][y-i].walkable=1; } LevelCurrent[x][y].flag_build=0; LevelCurrent[x][y-length].flag_build=1; } else{ if(LevelCurrent[x][y].tries>0) LevelCurrent[x][y].tries++; else LevelCurrent[x][y].flag_build=0; } } //=====================// //===RightHall=========// if((LevelCurrent[x][y].flag_build==2)&&type==1) { length=rand()%20; while(!CollisionCheck(LevelCurrent,x,y,length,1)&&x+length<92) { if(length<=4) break; length--; } if(length>4) { for(int i=0; i<length; i++) { LevelCurrent[x+i][y].walkable=1; } LevelCurrent[x][y].flag_build=0; LevelCurrent[x+length][y].flag_build=1; } else{ if(LevelCurrent[x][y].tries>0) LevelCurrent[x][y].tries++; else LevelCurrent[x][y].flag_build=0; } } //=====================// //===DownHall==========// if((LevelCurrent[x][y].flag_build==2)&&type==2) { length=rand()%20; while(!CollisionCheck(LevelCurrent,x,y,1,length)&&y+length<92) { if(length<=4) break; length--; } if(length>4) { for(int i=0; i<length; i++) { LevelCurrent[x][y+i].walkable=1; } LevelCurrent[x][y].flag_build==0; LevelCurrent[x][y+length].flag_build=1; } else{ if(LevelCurrent[x][y].tries>0) LevelCurrent[x][y].tries++; else LevelCurrent[x][y].flag_build=0; } } //=====================// //===LeftHall==========// if((LevelCurrent[x][y].flag_build==2)&&type==3) { length=rand()%20; while(!CollisionCheck(LevelCurrent,x-length,y,length,1)&&x-length>4) { if(length<=4) break; length--; } if(length>4) { for(int i=0; i<length; i++) { LevelCurrent[x-1][y].walkable=1; } LevelCurrent[x][y].flag_build=0; LevelCurrent[x-length][y].flag_build=1; } else{ if(LevelCurrent[x][y].tries>0) LevelCurrent[x][y].tries++; else LevelCurrent[x][y].flag_build=0; } } //=====================// //============================================================================================================// //===========COMMON_ROOMS=====================================================================================// //Diamond - Medium - Type 4 if(LevelCurrent[x][y].flag_build==1&&type==4) { if(CollisionCheck(LevelCurrent,x-3,y-3,7,7)) { //=Y-3========================// LevelCurrent[x][y-3].walkable=1; //============================// //=Y-2========================// LevelCurrent[x-1][y-2].walkable=1; LevelCurrent[x][y-2].walkable=1; LevelCurrent[x+1][y-2].walkable=1; //============================// //=Y-1========================// LevelCurrent[x-2][y-1].walkable=1; LevelCurrent[x-1][y-1].walkable=1; LevelCurrent[x][y-1].walkable=1; LevelCurrent[x+1][y-1].walkable=1; LevelCurrent[x+2][y-1].walkable=1; //============================// //=Y+0========================// LevelCurrent[x-3][y].walkable=1; LevelCurrent[x-2][y].walkable=1; LevelCurrent[x-1][y].walkable=1; LevelCurrent[x][y].walkable=1; LevelCurrent[x+1][y].walkable=1; LevelCurrent[x+2][y].walkable=1; LevelCurrent[x+3][y].walkable=1; //============================// //=Y+1========================// LevelCurrent[x-2][y+1].walkable=1; LevelCurrent[x-1][y+1].walkable=1; LevelCurrent[x][y+1].walkable=1; LevelCurrent[x+1][y+1].walkable=1; LevelCurrent[x+2][y+1].walkable=1; //============================// //=Y+2========================// LevelCurrent[x-1][y+2].walkable=1; LevelCurrent[x][y+2].walkable=1; LevelCurrent[x+1][y+2].walkable=1; //============================// //=Y+3========================// LevelCurrent[x][y+3].walkable=1; //============================// //=Flags======================// if(LevelCurrent[x][y+4].walkable==0&&y+4<92) LevelCurrent[x][y+3].flag_build=2; if(LevelCurrent[x][y-4].walkable==0&&y-4>4) LevelCurrent[x][y-3].flag_build=2; if(LevelCurrent[x+4][y].walkable==0&&x+4<92) LevelCurrent[x+3][y].flag_build=2; if(LevelCurrent[x-4][y].walkable==0&&x-4>4) LevelCurrent[x-3][y].flag_build=2; //============================// //=Tries======================// if(LevelCurrent[x][y+4].walkable==0&&y+4<92) LevelCurrent[x][y+3].tries=5; if(LevelCurrent[x][y-4].walkable==0&&y-4>4) LevelCurrent[x][y-3].tries=5; if(LevelCurrent[x+4][y].walkable==0&&x+4<92) LevelCurrent[x+3][y].tries=5; if(LevelCurrent[x-4][y].walkable==0&&x-4>4) LevelCurrent[x-3][y].tries=5; //============================// LevelCurrent[x][y].tries=0; } /*else{ if(LevelCurrent[x][y].tries>0) LevelCurrent[x][y].tries++; else LevelCurrent[x][y].flag_build=0; }*/ } //============================================================================================================// //===========RARE_ROOMS=======================================================================================// //Hall Of Heroes - Type 46 if(type==46) { } //============================================================================================================// } } counter=0; for(y2=0; y2<100; y2++) { for(x2=0; x2<100; x2++) { if(LevelCurrent[x2][y2].flag_build!=0) counter++; } } if(counter==0) finish=true; counter=0; } return; } I'm at a complete lose at this point so any help would be greatly appreciated. Thanks.
5. ## 2d scrolling and collision

Awesome it finally works. Thank you for your help sir.

7. ## 2d scrolling and collision

Ok I've started a 2d game that's supposed to scroll and as it scrolls it'll load the new bits of map, the issue I'm having with that is it's jumping. Everytime the character moves 32 pixels he jumps another 32 and centers on the next tile. My second issue is that the collision I have setup doesnt register ,it thinks every tile is a wall until Im off the map completely. I only setup the collision on the UP movement to test it otherwise I wouldnt be able to move at all. Weirdest part is the drawing function still see's the floors and draws them properly. Here is the code I have. I'm using C++ and Allegro 5: Movement: //+++Key_UP++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// if(key[KEY_UP]) { if(levelCurrent[x/32][(y-2)/32].walkable==1 && levelCurrent[(x+(32-1))/32][(y-2)/32].walkable==1) { y--; } } //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// //+++Key_DOWN++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// if(key[KEY_DOWN]) { y++; } //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// //+++Key_LEFT++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// if(key[KEY_LEFT]) { x--; } //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// //+++Key_RIGHT+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// if(key[KEY_RIGHT]) { x++; } //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// //+++Mouse_buttons+++++++++++++++++++++++++++++++++++++++++++++++++++++++// if(key[MOUSE_1]&& mouse_x<120&& mouse_x>100&& mouse_y<25&& mouse_y>5) { buttons[CHARA]=true; view=4; } else buttons[CHARA]=false; } //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// Drawing: for(b=0;b<20;b++){ for(c=0;c<20;c++){ if(b+(y/32)<21&& b+(y/32)>-1&& c+(x/32)<21&& c+(x/32)>-1&& levelCurrent[c+(x/32)][b+(y/32)].walkable==1){ al_draw_bitmap(wall,(c*32)-x,(b*32)-y+32,0); } } } I'm pretty sure the issue is somewhere in there but I'm having a hard time finding a solution to it. Thanks for the help.
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!