Message-ID: <20010413203035.45876.qmail@web13303.mail.yahoo.com> Date: Fri, 13 Apr 2001 13:30:35 -0700 (PDT) From: Rafael Frongillo Subject: Re: integer assignment error To: djgpp AT delorie DOT com In-Reply-To: <20010413154455.46911.qmail@web13302.mail.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Reply-To: djgpp AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk OK FINE, I'll post the code... I didn't think it would be worth it, however, as the error could be anywhere, if it is there. One of the most common mis-assigned variables is the integer 'lifting' in the class 'guy'. I apologize for the large amount of code, but here it is: -------------------- Main.cpp: #include #include #include #include #include #include "guys.cpp" #include "keys.cpp" void reset(); void game(); void setkeys(); void action(); void drawWalls(int); void makeWalls(); void loadIms(); void beginning(); int delay=0, backcolor = white, bufcolor = black; int score1, score2, keyset=0; guy guy1, guy2; MIDI *mid1,*mid2,*mid3; int main() { time_t sec; time(&sec); srandom((unsigned int)sec); PALLETE pall; allegro_init(); install_keyboard(); install_timer(); set_color_depth(16); set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0); set_color_conversion(COLORCONV_TOTAL); if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, "") != 0) { printf("Error initialising sound system\n%s\n", allegro_error); return 1; } data = load_datafile("main.dxt"); mid1 = (MIDI *)data[R1].dat; mid2 = (MIDI *)data[ESC].dat; mid3 = (MIDI *)data[R2].dat; buf = create_bitmap(width,height); rectfill(buf,0,0,width,height,bufcolor); rectfill(screen,0,0,640,480,backcolor); loadIms(); for (int i=0; i<5; i++) { masked_blit(mp1[i],screen,0,0,i*mp1[i]->w,20,mp1[i]->w,mp1[i]->h); } for (int i=0; i<3; i++) { masked_blit(mp2[i],screen,0,00,i*mp2[i]->w,60,mp2[i]->w,mp2[i]->h); } for (int i=0; i<4; i++) { masked_blit(mp3[i],screen,0,00,i*mp3[i]->w,100,mp3[i]->w,mp3[i]->h); } generate_332_palette(pall); readkey(); play_midi(mid3, TRUE); beginning(); int index=0, numoptions=3; while (1) { clear(screen); textout(screen,font,"NEW GAME",250,100+20*0,orange); textout(screen,font,"SET KEYS",250,100+20*1,orange); textout(screen,font,"QUIT",250,100+20*2,orange); int j=0; while (1) { clear_keybuf(); rectfill(screen,200,100,250,100+numoptions*20,black); if (j==KEY_UP) index--; if (j==KEY_DOWN) index++; if (index >= numoptions) index = 0; else if (index<0) index = numoptions-1; if (j==KEY_ENTER) { switch (index) { case 0 : game(); break; case 1 : setkeys(); break; default : allegro_exit(); cout << glift[1] << endl; return 0; } break; } masked_blit(mp1[0],screen,0,0,200,100+index*20,mp1[0]->w,mp1[0]->h); j = readkey() >> 8; } } allegro_exit(); return 0; } void game() { switch (random()%2) { case 0 : play_midi(mid1, TRUE); break; case 1 : play_midi(mid2, TRUE); break; } while (1) { clear(screen); textout(screen,font,"SCORE:",200,200,1000); textprintf(screen,font,200,250,1000,"PLAYER 1: %i",score1); textprintf(screen,font,200,270,1000,"PLAYER 2: %i",score2); if (score1==5) { textout(screen,font,"PLAYER 1 WINS THE GAME",200,300,1000); score1 = score2 = 0; break; } else if (score2==5) { textout(screen,font,"PLAYER 2 WINS THE GAME",200,300,1000); score1 = score2 = 0; break; } clear_keybuf(); int j = readkey() >> 8; if (j == KEY_ESC) { clear_keybuf(); break;} else action(); } play_midi(mid3, TRUE); } void action() { reset(); while (!key[KEY_ENTER]) { if (key[keys[12]]) { clear_keybuf(); while (!key[KEY_P]) rest(50); clear_keybuf(); } rest(delay); rectfill(buf,scrx1-50,scry1-50,scrx1+innerw+50,scry1+innerh+50,bufcolor); rectfill(buf,scrx2-50,scry2-50,scrx2+innerw+50,scry2+innerh+50,bufcolor); drawWalls(1); for (int i=0; i0) { textout(screen,font,"---PLAYER 2 WINS MATCH---",200,210,white); score2++; readkey(); break; } else if (guy2.hp<=0 && guy2.hp>0) { textout(screen,font,"---PLAYER 1 WINS MATCH---",200,210,white); score1++; readkey(); break; } else if (guy1.hp<=0 && guy2.hp>0) { textout(screen,font," ------ T I E ------ ",200,210,white); readkey(); break; } } } void reset() { guy1 = guy(1,100,100); guy1.setKeys(keys[0], keys[1], keys[2], keys[3], keys[4], keys[5]); guy2 = guy(2,400,100); guy2.setKeys(keys[6], keys[7], keys[8], keys[9], keys[10], keys[11]); rectfill(buf,0,0,width,height,bufcolor); rectfill(screen,0,0,640,480,backcolor); for (int i = 0; i #include "main.h" #include "guys.h" #include "guy.h" BITMAP *all, *right[6], *left[6], *jp[3], *stand, *ducp, *diep, *fallp, *up, *down, *check1, *check2, *mslall, *lgrab[4], *rgrab[4]; DATAFILE *data; SAMPLE *jumpsnd; guy::guy() { destroy(); } guy::guy(int n, int xx, int yy) { num = n; x = xx; y = yy; w = 40, h = 51; speed=2, maxspeed=6, canjump = weapon = 1, hp=100; checkpic = check1; temp = stand; for (int i=0; i0); if (key[KEY_1]) { weapon=1; } if (key[KEY_2]) weapon=2; if (key[KEY_3]) weapon=3; if (key[KEY_4]) weapon=4; if (key[KEY_5]) weapon=5; if (key[Ku]) { d = UP; if (!lifting && grabbing) lifting=1;} if (key[Kd]) { d = DN;} if (key[Kr]) { d = RT; running = 1; } if (key[Kl]) { d = LF; running = 1; } if (key[Kj]) { if (!grabbing && canjump) { jumping=1; picn=0; }} else if (jumping && jumpn<6) jumpn = 6; move(); checkPups(); if (key[Kf]) { if (!loading && !grabbing) fire(); } textprintf(screen,font,520,(innerh+10)*(num-1)+20,white,"AMMO: %i ", ammo[weapon]); rectfill(screen,520,(innerh+10)*(num-1)+30,520+ammo[weapon]/10,(innerh+10)*(num-1)+38,blue); textprintf(screen,font,520,(innerh+10)*(num-1)+50,white,"HEALTH: %i ", hp); rectfill(screen,520,(innerh+10)*(num-1)+60,640,(innerh+10)*(num-1)+68,white); if (hp>=0) rectfill(screen,520,(innerh+10)*(num-1)+60,520+hp/2,(innerh+10)*(num-1)+68,red); else vline(screen,520,(innerh+10)*(num-1)+60,(innerh+10)*(num-1)+68,red); } void guy::move() { px = x, py = y; picn++; if (lifting) lift(); else if (running) { if (checkGrab() && !jumping) { grabbing = 1; } else { speed += 1*(speed!=maxspeed); x += speed*d; grabbing=0; } textprintf(screen,font,600,430,white,"D%i ",d); switch (d) { case RT : if (grabbing) temp = rgrab[0]; else { if (picn > 4) picn = 1; temp = right[picn]; } break; // textout(screen,font,"R",600,440,white); case LF : if (grabbing) temp = lgrab[0]; else { if (picn > 4) picn = 1; temp = left[picn]; } break; // textout(screen,font,"L",600,440,white); } checkWalls(d); } else { speed=2; grabbing=0; switch (d) { case RT : temp = right[0]; picn = 0; break; case UP : temp = up; picn = 0; break; case DN : temp = down; picn = 0; break; case 0 : temp = stand; picn = 0; break; case LF : temp = left[0]; picn = 0; break; } } shoot(); if (!grabbing) { if (jumping) jump(); else fall(); } masked_blit(temp,buf,0,0,x-w/2,y,temp->w,temp->h); textout(buf,font,"GUY",x,y,white); // draw_sprite(buf,temp,x-w/2,y); running = 0; moveScreen(); } void guy::moveScreen() { int sx,sy; if (num==1) { sx = scrx1; sy = scry1; } else { sx = scrx2; sy = scry2; } if (x-sx < innerw/2 - 10) sx -= (innerw/2-10)-(x-sx); else if (x-sx > innerw/2 + 10) sx += (x-sx)-(innerw/2+10); if ((y+h/2)-sy < innerh/2 - 10) sy -= (innerh/2-10)-((y+h/2)-sy); else if ((y+h/2)-sy > innerh/2 + 10) sy += ((y+h/2)-sy)-(innerh/2+10); if (sx<0) sx = 0; else if (sx>width-innerw) sx = width-innerw; if (sy<0) sy = 0; else if (sy>height-innerh) sy = height-innerh; if (num==1) { scrx1 = sx; scry1 = sy; } else { scrx2 = sx; scry2 = sy; } } void guy::fire() { for (int i=0; i0) { ammo[weapon]--; switch (d) { case RT : msls[i] = MSL(weapon,x+10,y+20,d,num); break; case LF : msls[i] = MSL(weapon,x-10,y+20,d,num); break; case UP : msls[i] = MSL(weapon,x,y-5,d,num); break; case DN : msls[i] = MSL(weapon,x+5,y+20,d,num); break; } loading = msls[i].fdelay; break; } } } void guy::lift() { textprintf(screen,font,500,450,white,"G%i ",grabbing); textprintf(screen,font,500,460,white,"L%i ",lifting); grabbing=1; if (d==1) switch (lifting) { case 1 : y -= 15; x -= 5; temp = rgrab[1]; break; case 2 : y -= 13; x += 5; temp = rgrab[2]; break; case 3 : y -= 20; x += 3; temp = rgrab[3]; break; case 4 : y -= 15; x += 3; temp = rgrab[3]; grabbing = 0; lifting = -1; break; default : grabbing = 0; lifting = -1; break; } else switch (lifting) { case 1 : y -= 15; x += 5; temp = lgrab[1]; break; case 2 : y -= 13; x -= 5; temp = lgrab[2]; break; case 3 : y -= 20; x -= 3; temp = lgrab[3]; break; case 4 : y -= 15; x -= 3; temp = lgrab[3]; grabbing = 0; lifting = -1; break; default : grabbing = 0; lifting = -1; break; } checkWalls(d); checkWalls(UP); lifting++; } void guy::shoot() { for (int i=0; iw,pupp[0]->h); break; case 2 : weapon = 1; pups[i] = pup(); ammo[1] += 10; masked_blit(pupp[2],screen,0,0,520,(innerh+10)*(num-1),pupp[2]->w,pupp[2]->h); break; case 3 : weapon = 2; pups[i] = pup(); ammo[2] += 40; masked_blit(pupp[3],screen,0,0,520,(innerh+10)*(num-1),pupp[3]->w,pupp[3]->h); break; case 4 : weapon = 3; pups[i] = pup(); ammo[3] += 4; masked_blit(pupp[4],screen,0,0,520,(innerh+10)*(num-1),pupp[4]->w,pupp[4]->h); break; } } } int guy::checkGrab() { int b=0; for (int i=0; i15); temp = fallp; break; } falling = !checkWalls(DN); if (!falling) { jumpn=0; canjump=1; if (fallbefore) temp = jp[2]; } else canjump = 0; } void guy::duck() { checkpic = check2; } void guy::destroy() { speed = maxspeed = picn = jumpn = stopjump = running = jumping = falling = loading = canjump = grabbing = weapon = ammo[10] = d = dead = mslnum = hp = lifting = num = x = y = px = py = Kj = Kf = Ku = Kd = Kr = Kl = w = h = 0; } -------------------- Guys.h #ifndef GUYS_H #include "msls.cpp" #include "pups.cpp" class guy { public : guy(); guy(int num, int x, int y); void update(); void move(); void jump(); void fall(); void duck(); void lift(); void shoot(); void fire(); void die(); void moveScreen(); void setKeys(int kj, int kf, int ku, int kd, int kr, int kl); int checkWalls(int); int checkGrab(); void checkPups(); void destroy(); int speed, maxspeed, picn, jumpn, stopjump, running, jumping, falling, loading, canjump, grabbing, weapon, ammo[10], d, dead, mslnum, hp, lifting, num, x, y, px, py; int Kj, Kf, Ku, Kd, Kr, Kl; int w,h; MSL msls[MAXMSL]; BITMAP *checkpic, *temp; }; #define GUYS_H #endif ---------------------- That should be all that is needed, I hope. Thanks for your patience! -Rafael Frongillo __________________________________________________ Do You Yahoo!? Get email at your own domain with Yahoo! Mail. http://personal.mail.yahoo.com/