From: "Oliver Batchelor" Newsgroups: comp.os.msdos.djgpp Subject: Random numbers, 'or ' and 'and' ; Date: 31 Oct 1998 21:22:33 GMT Organization: The Internet Group (Christchurch) Lines: 416 Message-ID: <01be0514$a99ee440$2e884fd1@default> NNTP-Posting-Host: newsch.ihug.co.nz X-Newsreader: Microsoft Internet News 4.70.1155 Cache-Post-Path: newsch.es.co.nz!unknown AT p46-max9 DOT chc DOT ihug DOT co DOT nz X-Cache: nntpcache 2.3.2.1 (see http://www.nntpcache.org/) To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com I am writing a rts game. full code below. I am going quite well despite having a few problems, i drew 106 different tiles for water, grass and dirt and joins between them, i use rotate sprite and use angles for units rather than directions. my problems are : 1: I cannot find out how to use and or or in an if statement i tried all of these but they dont work.. I would really appreciate it if someone told me what whas wrong if(a and b) blah; if((a) and (b)) blah; if(a & b) blah; if((a) & (b)) blah; if(a or b) blah; if((a) or (b)) blah; if(a || b) blah; if((a) || (b)) blah; 2: I cant seem to find a procedure that makes random numbers. Here is the code, it is a bit slopy with not many comments and is hard to follow and is very un optimised i think :< #include #include #include #include #include "audio.h" #include "allegro.h" #include "good.h" float pi; BITMAP *page1, *page2, *introbmp; BITMAP *active_page; char msg[50], ch; int i, a,b,x,y,c,scrolx,scroly, sector; int map[100][100]; DATAFILE *tiledata, *gooddata; int maxmapy, maxmapx; FILE *mapfile; AUDIOINFO info; LPAUDIOMODULE lpModule; BOOL stopped; unsigned char audioon, quit; float d1, d2; float fract, dx, dy, ang, fa, fb, fc; /*unit info*/ float uspeed[100]; float uturnspeed[100]; float ux[100]; float uy[100]; float udir[100]; float udestx[100]; float udesty[100]; float udestdir[100]; BOOL selected[100]; BOOL umoving[100]; BOOL uturning[100]; BOOL uimage[100]; BOOL ucanstop[100]; int unitno; /*mouse rectangle*/ int sx, sy, ex, ey; BOOL selecting; BOOL someselected; float calcang(float x1, float y1, float x2, float y2) /*Calculate the angle between the line x1, y1, x2, y2 and the line y = x1 (straight up)*/ { float ang; dx=x1- x2; dy=y1-y2; b=0; if((dx > -0.5) & (dx < 0.5)) { b=1; if(dy > 0) ang=0; else ang=128; } /*atan 0 or atan a huge number at the angels 0 and 64 dont work (out of 256) */ if((dy > -0.5)& (dy < 0.5)) { b=1; if(dx > 0) ang=192; else ang=64; } if(!b) { if(dx < 0) {if(dy > 0) sector=0; else sector=1;} else {if(dy>0)sector=3; else sector=2;} if(dx <0)dx=-dx; if(dy <0)dy=-dy; fract=dy/dx; if(fract <0) fract=-fract; if((sector==0)) fract = 1/fract; if((sector==2)) fract = 1/fract; ang=fixtof(fatan(ftofix(fract)))+sector*64; } return ang; } void calcangdist(float a1, float a2) /*return values in d1, d2 */ { if(a1 > a2) { d1=255-a1+a2; d2=a1-a2; } else if(a1 < a2) { d2=255-a2+a1; d1=a2-a1; } return; } int main() /*Start of main prog, set vars */ { maxmapy=100; maxmapx=100; scroly=0; audioon=1; scrolx=0; i=0; unitno=20; someselected=0; pi=3.14159; for (a=0; anTracks); APlayModule(lpModule); } allegro_init(); /* install_timer(); */ install_keyboard(); /*initialise keyboard mouse grahpics etc.. */ install_mouse(); mapfile=fopen("demo.dat", "rb"); fread(map, sizeof(map),1,mapfile); fclose(mapfile); set_color_depth(16); set_gfx_mode(GFX_AUTODETECT, 320, 240, 336, 512); tiledata = load_datafile("land.dat"); if (!tiledata) { allegro_exit(); printf("Error loading land.dat!\n\n"); quit=1; } gooddata = load_datafile("good.dat"); if (!tiledata) { allegro_exit(); printf("Error loading good.dat!\n\n"); quit=1; } page1 = create_sub_bitmap(screen, 0, 0, SCREEN_W, SCREEN_H); page2 = create_sub_bitmap(screen, 0, SCREEN_H, SCREEN_W, SCREEN_H); active_page = page1; while (!key[KEY_ESC]) /*Start of main loop !!! */ { if(audioon)AUpdateAudio(); clear(active_page); for (x=0+scrolx; x<10+scrolx; x++) { for (y=0+scroly; y<7+scroly; y++) { draw_compiled_sprite(active_page, tiledata[map[x][y]].dat, (x-scrolx)*32, (y-scroly)*32); }} for(a=0; a (scrolx-1)*32) if(ux[a] < (scrolx+11)*32) if(uy[a] > (scroly-1)*32) if(uy[a] < (scroly+8)*32) rotate_sprite(active_page, gooddata[uimage[a]].dat, ux[a]-scrolx*32, uy[a]-scroly*32, ftofix(udir[a]+i)); if(selected[a]) rect(active_page, ux[a]-scrolx*32, uy[a]-scroly*32, ux[a]+32-scrolx*32, uy[a]+32-scroly*32, 255); } for(a=0; a d2) udir[a]+=uturnspeed[a]; if(udir[a] > 255) udir[a]-=256; if(udir[a] < 0) udir[a]+=256; }} if(audioon)AUpdateAudio(); for(a=0; a ex) { a=ex; ex=sx; sx=a; } if(sy > ey) { a=ey; ey=sy; sy=a; } for(a=0; a < unitno; a++) { if(ux[a]+32 > sx+scrolx*32) if(ux[a] < ex+scrolx*32) if(uy[a]+32 > sy+scroly*32) if(uy[a] < ey+scroly*32) selected[a] = 1; someselected=1; } } if(mouse_b & 2) if(someselected) for(a=0;a maxmapy-7) scroly=maxmapy-7; } if(mouse_y == 0) { scroly--; if(scroly < 0 ) scroly=0; } if(mouse_x==319) { scrolx++; if(scrolx > maxmapx-10) scrolx=maxmapx-10; } if(mouse_x==0) { scrolx--; if(scrolx < 0 ) scrolx=0; }} if (active_page == page1) { scroll_screen(0, 0); active_page = page2; } else { scroll_screen(0, SCREEN_H); active_page = page1; } } /*END of main loop*/ clear_keybuf(); destroy_bitmap(page1); /*Clean up, close down of graphics sound etc.. */ destroy_bitmap(page2); unload_datafile(tiledata); mapfile=fopen("map.dat", "wb"); fwrite(map, sizeof(map),1,mapfile); fclose(mapfile); if(audioon) { AStopModule(); ACloseVoices(); /* release module file */ AFreeModuleFile(lpModule); /* close audio device */ ACloseAudio(); } return 0; }