int main(void) { int i,j,k,x,y; //byte bi,bj; //byte cursize=1; //int cursorx=0,cursory=0; //byte spritecont=10,spritecont2=10+16; //byte sprconmeno,sprconpiu; //byte sprconmeno2,sprconpiu2; //byte terrancont=0,solidcont=0; //bool speed=false; //bool print=false,toggleprint=false; //bool moved=false,pushed=false; int nlevel; BITMAP *buffer; // Double-buffering BITMAP *textures; // Immagine globale delle texture BITMAP *sprites[256]; // Array degli sprite //RGB color[256]; //char nomefile[30],errmess[20]; //FILE *fp; T_Map mappa; strcpy(errmess,""); // inizializzo la stringa if(!mappa.InitLevel()){ strcpy(errmess,"Impossibile allocare la mappa"); exit(0); } /////////// INPUT NOME FILE DELLA MAPPA /////////////////////// printf("\n\t Inserta il nome del file della mappa(senza est.) : "); gets(nomefile); strcat(nomefile,".map"); ///////////////////////////////////////////////////////////////// if(!mappa.SetMapFile){ printf("\n\t File non trovato"); } nlevel=mappa.RetNLevel(); printf("\n\t Numero attuale di livelli: %d",nlevel); printf("\n\t Inserta il numero di livelli da creare nella mappa:"); printf("\n\t (0 per non aggiungerne)"); scanf("%d",&i); if(i>0){ nlevel+=i; mappa.SetNLevel(nlevel); mappa.AllocMap(); } GameInit(); textures=create_bitmap(128,128); mappa.SetTextureFile("D:\\DJGPP\\Game01\\IndexTxt.txt"); /////// Gestione delle texture... s�, lo so, lo so che sono tile for(y=0,i=0;y<16&&i<256;y++){ for(x=0;x<16&&i<256;x++,i++){ sprites[i]=create_sub_bitmap(textures,x*UNITX, y*UNITY,UNITX,UNITY); } } /////////// INIZIALIZZAZIONE MATRICE DELLA FINESTRELLA ///// for(i=0;i<WIMGY;i++){ for(j=0;j<WIMGX;j++){ miniwmask[i][j]=0; } } ////// INIZIALIZZAZIONE MATRICE DELLA LISTA DELLE TILE///////////// for(i=0;i<2;i++){ for(j=0;j<20;j++){ spritemask1[i][j]=0; spritemask2[i][j]=0; } } ///////////////// BUFFER PER IL DOUBLE BUFFERING ////////////// buffer=create_bitmap(SCREEN_W,SCREEN_H); //show_mouse(buffer); clear_to_color(buffer,DESK_COL); //clear_to_color(lvldis,BACKG_COL); ////////////////////////////////////////////////////////////////// /////////////////////////// PUTTAGGIO /////////////////////////// DrawMainWindow(); DrawMiniWindow(); DrawTileLists(); //show_mouse(buffer); blit(buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H); //rectfill(screen,0,0,100,100,5); ////////////////////////////////////////////////////////////////// ////////////////// INPUT E CONTROLLI //////////////////////////// while(!key[KEY_ESC]){ if(key[KEY_RSHIFT]||key[KEY_LSHIFT]){ speed=true; }else{ speed=false; } if(key[KEY_P]){ cursize=2; moved=true; } if(key[KEY_O]){ cursize=1; moved=true; } if(key[KEY_SPACE]&&!pushed){ print=true; pushed=true; moved=true; } if(key[KEY_T]&&!pushed){ pushed=true; moved=true; if(toggleprint){ toggleprint=false; }else{ toggleprint=true; } } if(key[KEY_LEFT]&&cursorx&&!pushed){ if(!speed) pushed=true; cursorx--; if(cursize==2&&cursorx) cursorx--; relx=cursorx*MUNITX; moved=true; } if(key[KEY_RIGHT]&&cursorx<NSPRITEX-cursize&&!pushed){ if(!speed) pushed=true; cursorx++; if(cursize==2&&cursorx<NSPRITEX-cursize) cursorx++; relx=cursorx*MUNITX; moved=true; } if(key[KEY_UP]&&cursory&&!pushed){ if(!speed) pushed=true; cursory--; if(cursize==2&&cursory) cursory--; rely=cursory*MUNITY; moved=true; } if(key[KEY_DOWN]&&cursory<NSPRITEY-cursize&&!pushed){ if(!speed) pushed=true; cursory++; if(cursize==2&&cursory<NSPRITEY-cursize) cursory++; rely=cursory*MUNITY; moved=true; } if(key[KEY_PLUS_PAD]&&!pushed){ //if(!button[KEY_PLUS_PAD]){ pushed=true; BACKG_COL++; moved=true; //button[KEY_PLUS_PAD]=true; //} //}else{ // button[KEY_PLUS_PAD]=false; } if(key[KEY_Z]&&!pushed){ if(!speed) pushed=true; //spritecont--; //spritecont2--; //relx=cursorx*MUNITX; moved=true; } if(key[KEY_X]&&!pushed){ if(!speed) pushed=true; //spritecont++; //spritecont2++; //relx=cursorx*MUNITX; moved=true; } if(key[KEY_A]&&!pushed){ if(!speed) pushed=true; if(terrancont>0) terrancont--; else terrancont=MAX_TERR; //spritecont2++; //relx=cursorx*MUNITX; moved=true; } if(key[KEY_S]&&!pushed){ if(!speed) pushed=true; terrancont++; if(terrancont>MAX_TERR) terrancont=0; //spritecont2++; //relx=cursorx*MUNITX; moved=true; } if(key[KEY_Q]&&!pushed){ if(!speed) pushed=true; if(solidcont>0) solidcont--; else solidcont=MAX_SOLID; //spritecont2++; //relx=cursorx*MUNITX; moved=true; } if(key[KEY_W]&&!pushed){ if(!speed) pushed=true; solidcont++; if(solidcont>MAX_SOLID) solidcont=0; //spritecont2++; //relx=cursorx*MUNITX; moved=true; } if(key[KEY_F3]&&!pushed){ pushed=true; fp=fopen(nomefile,"rb"); if(fp!=NULL){ if(!mappa.LoadLevel(fp)) strcpy(errmess,"Unable to load"); fclose(fp); for(i=0,k=0;i<NSPRITEY;i++){ for(j=0;j<NSPRITEX;j++,k++){ livello[i][j].solid=mappa.RetSolid(k); livello[i][j].terran=mappa.RetTerran(k); } } } moved=true; } if(key[KEY_F2]&&!pushed){ pushed=true; /* for(i=0,k=0;i<NSPRITEY;i++){ for(j=0;j<NSPRITEX;j++,k++){ mappa.SetSolid(k,livello[i][j].solid); mappa.SetTerran(k,livello[i][j].terran); } } for(i=OVER_SPACE,k=0;i<OVER_SPACE+NSPRITEY;i++){ for(j=LEFT_SPACE;j<LEFT_SPACE+NSPRITEX;j++,k++){ mappa.SetSprite(k,livello[i][j].sprite); } } */ fp=fopen(nomefile,"wb"); //mappa.SaveLevel(fp); fclose(fp); } if(key[KEY_F7]&&!pushed){ pushed=true; for(i=0,k=0;i<NSPRITEY;i++){ for(j=0;j<NSPRITEX;j++,k++){ //fwrite(&livello[i][j],sizeof(level),1,fp); livello[i][j].solid=mappa.RetSolid(k); livello[i][j].terran=mappa.RetTerran(k); } } moved=true; } if(key[KEY_F5]&&!pushed){ pushed=true; for(i=0,k=0;i<NSPRITEY;i++){ for(j=0;j<NSPRITEX;j++,k++){ mappa.SetSolid(k,livello[i][j].solid); mappa.SetTerran(k,livello[i][j].terran); } } } if(key[KEY_ENTER]){ clear_to_color(buffer,0); for(i=OVER_SPACE,y=0;i<NSPRITEY-BOTTOM_SPACE;i++,y+=UNITY){ for(j=LEFT_SPACE,x=0;j<NSPRITEX-RIGHT_SPACE;j++,x+=UNITX){ blit(sprites[livello[i][j].sprite],buffer,0,0, x,y,UNITX,UNITY); } } vsync(); blit(buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H); while(!key[KEY_BACKSPACE]); moved=true; } if(print||toggleprint){ livello[cursory][cursorx].sprite=spritecont; livello[cursory][cursorx].terran=terrancont; livello[cursory][cursorx].solid=solidcont; print=false; //stretch_blit(sprites[spritecont],lvldis,0,0,UNITX,UNITY, // cursorx*MUNITX,cursory*MUNITY,MUNITX,MUNITY); if(cursize>1){ livello[cursory][cursorx+1].sprite=spritecont+1; livello[cursory][cursorx+1].terran=terrancont; livello[cursory][cursorx+1].solid=solidcont; // stretch_blit(sprites[spritecont+1], // lvldis,0,0,UNITX,UNITY,(cursorx+1)*MUNITX, // cursory*MUNITY,MUNITX,MUNITY); livello[cursory+1][cursorx].sprite=spritecont2; livello[cursory+1][cursorx].terran=terrancont; livello[cursory+1][cursorx].solid=solidcont; // stretch_blit(sprites[spritecont2], // lvldis,0,0,UNITX,UNITY,cursorx*MUNITX, // (cursory+1)*MUNITY,MUNITX,MUNITY); livello[cursory+1][cursorx+1].sprite=spritecont2+1; livello[cursory+1][cursorx+1].terran=terrancont; livello[cursory+1][cursorx+1].solid=solidcont; // stretch_blit(sprites[spritecont2+1], // lvldis,0,0,UNITX,UNITY,(cursorx+1)*MUNITX, // (cursory+1)*MUNITY,MUNITX,MUNITY); } } if(moved){ clear_to_color(buffer,DESK_COL); // Puttaggio dello schema del livello : ex lvldis rectfill(buffer,0,0,XLAR,YLAR,BACKG_COL); //blit(lvldis,buffer,0,0,0,0,XLAR,YLAR); for(i=0,y=0;i<NSPRITEY;i++,y+=MUNITY){ for(j=0,x=0;j<NSPRITEX;j++,x+=MUNITX){ if(livello[i][j].sprite){ stretch_blit(sprites[livello[i][j].sprite], buffer,0,0,UNITX,UNITY,x,y,MUNITX,MUNITY); } } } // Rettangoli dello schema //rect(buffer,LEFT_SPACE*MUNITX,OVER_SPACE*MUNITY, // XLAR-(RIGHT_SPACE*MUNITX)-1,YLAR-(BOTTOM_SPACE*MUNITY)-1, // CONF_COL); rect(buffer,relx,rely,relx+(cursize*MUNITX-1), rely+(cursize*MUNITY-1),CURS_COL); // Disegno della finestra laterale // for(i=cursory-2,bi=0;i<cursory+3;i++,bi++){ for(j=cursorx-2,bj=0;j<cursorx+3;j++,bj++){ if(i<0||j<0){ windimg[bi][bj]=0; }else{ windimg[bi][bj]=livello[i][j].sprite; } } } for(i=0,y=0;i<WIMGY;i++,y+=UNITY){ for(j=0,x=SCREEN_W-(WIMGX*UNITX);j<WIMGX;j++,x+=UNITX){ //temp=; blit(sprites[windimg[i][j]],buffer,0,0,x,y,UNITX,UNITY); } } // Se � premuto 'toggleprint' ( che � un Pokemon? ) if(toggleprint){ rectfill(buffer,300,110,320,130,CURS_COL); }else{ rectfill(buffer,300,110,320,130,DESK_COL); } textprintf(buffer,font,250,60,255,"Sol : %d",solidcont); textprintf(buffer,font,250,70,255,"Terr: %d",terrancont); // Disegno elenco sprite if(spritecont>10){ sprconmeno=spritecont-10; }else{ sprconmeno=256-(10-spritecont); } if(spritecont<246){ sprconpiu=spritecont+10; }else{ sprconpiu=10-(256-spritecont); } if(spritecont2>10){ sprconmeno2=spritecont2-10; }else{ sprconmeno2=256-(10-spritecont2); } if(spritecont2<246){ sprconpiu2=spritecont2+10; }else{ sprconpiu2=10-(256-spritecont2); } for(bi=sprconmeno,bj=sprconmeno2,x=0;bi!=sprconpiu;bi++,bj++,x+=BIGUNITX){ stretch_blit(sprites[bi],buffer,0,0,UNITX,UNITY,x, 200,BIGUNITX,BIGUNITY); if(cursize>1){ stretch_blit(sprites[bj],buffer,0,0, UNITX,UNITY,x,216,BIGUNITX,BIGUNITY); } } rect(buffer,160,199,160+(cursize*BIGUNITX), 200+(cursize*BIGUNITY),CURS_COL); moved=false; } if(pushed){ pushed=false; for(i=0;i<128;i++){ if(key[i]){ pushed=true; break; } } } show_mouse(buffer); vsync(); blit(buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H); show_mouse(NULL); } /// Distruzione Bitmap for(i=0;i<256;i++){ destroy_bitmap(sprites[i]); //destroy_bitmap(texture[1][i]); } destroy_bitmap(textures); //destroy_bitmap(lvldis); destroy_bitmap(buffer); readkey(); GameExit(); printf("Programmed with DJGPP RHIDE Allegro"); puts(errmess); getch(); return 0; }
KaboHaze::KaboHaze(SpaceLocation *creator, Ship *ohost, double obasepower) : SpaceLocation(creator, Vector2(0.0, 0.0), 0.0) { STACKTRACE; prev = 0; next = 0; // update the list (insert at the start) if (KaboHazeFirst) KaboHazeFirst->prev = this; next = KaboHazeFirst; prev = 0; KaboHazeFirst = this; //mother = omother; host = ohost; basepower = obasepower; power = basepower; // decay_time = odecaytime; // in milliseconds newcrew = iround(host->getCrew()); oldcrew = newcrew; // this "haze" is passive, of course: collide_flag_anyone = 0; collide_flag_sameteam = 0; collide_flag_sameship = 0; // I'll make 64 rotated versions in total, if needed, which I'll store // in memory: for ( int i = 0; i < 64; ++i ) { shield_bmp[i] = 0; } sprite_index = 0; // no rotation. shield_sprite_index = 0; // this item cannot collide collide_flag_anyone = 0; // this is probably important ... otherwise a thing like a flipping wedge indicator // can avoid a shield from being drawn ?!?! layer = LAYER_SHIPS; set_depth(DEPTH_SHIPS + 0.1); // The +0.1 places this presence at a higher level, so that this routine is // always done after the ship was drawn! Thnx Orz, for telling. // Graphics init stuff for the shield ! // copy the ship sprite (yes, a COPY because we need to do some operations on it !) SpaceSprite *ship_spr; ship_spr = host->get_sprite(); if (!ship_spr) { state = 0; return; } //BITMAP *ship_bmp; int wship = ship_spr->width(); int hship = ship_spr->height(); BITMAP *ship_bmp = create_bitmap(wship, hship); clear_to_color(ship_bmp, 0); // important otherwise it contains artefacts int index = 0; ship_spr->draw(Vector2(0, 0), Vector2(wship, hship), index, ship_bmp); // this does a (masked?) blit // create a blurred image from this: int R = 3; blit_blur(ship_bmp, R); // a complex and costly funtion ! Inefficiently programmed as well of course (by me). // now, create a masked shield - only the area that covers the // blurred image of the ship: shield_bmp[sprite_index] = create_bitmap(wship, hship); // important otherwise it contains artefacts clear_to_color(shield_bmp[sprite_index], 0); // scale/draw a shield: /* // the raw shield image BITMAP *raw_bmp = this->sprite->get_bitmap_readonly(0); int wraw = raw_bmp->w; int hraw = raw_bmp->h; stretch_blit(raw_bmp, shield_bmp[sprite_index], 0, 0, wraw, hraw, 0, 0, wship, hship ); */ // a uniform green glow clear_to_color(shield_bmp[sprite_index], tw_makecol(0,255,0)); // mask out the areas outside the ship, so that the shield only covers // the ship. blit_singlecolor(ship_bmp, shield_bmp[sprite_index], tw_makecol(0,0,0)); destroy_bitmap(ship_bmp); // ok ! this is what we need - only things left are // resize // rotate // trans-draw. // which we've to do repeatedly. // we may also cache the rotated images ! // flashes can occur within the edges of the shield ... check where the // edges are !! (assuming here, it's a closed shape). edge_left = new int [hship]; edge_right = new int [hship]; for ( int j = 0; j < hship; ++j ) { edge_left[j] = -1; edge_right[j] = -1; for ( int i = 0; i < wship; ++i ) { int color = getpixel(shield_bmp[0], i, j); if ( color != 0 ) { if ( edge_left[j] == -1 ) edge_left[j] = i; edge_right[j] = i; } } } attributes &= ~ATTRIB_STANDARD_INDEX; }
int main() { int exit_flag = 0, i; VERTEX cube[8]; cube[0].local = (_3D) { -10.0, -10.0, 0.0 }; cube[1].local = (_3D) { 10.0, -10.0, 0.0 }; cube[2].local = (_3D) { 10.0, 10.0, 0.0 }; cube[3].local = (_3D) { -10.0, 10.0, -10.0 }; cube[4].local = (_3D) { -10.0, -10.0, 10.0 }; cube[5].local = (_3D) { 10.0, -10.0, 10.0 }; cube[6].local = (_3D) { 10.0, 10.0, 10.0 }; cube[7].local = (_3D) { -10.0, 10.0, 10.0 }; _3D world_pos = {0.0, 0.0, 100.0}; init(); printf("D1:=%f;\nD2:=%f;\nD3:=%f;\nD4:=%f;\n", dist_3d(cube[0].local, cube[1].local), dist_3d(cube[1].local, cube[2].local), dist_3d(cube[2].local, cube[3].local), dist_3d(cube[3].local, cube[0].local)); readkey(); int xang, yang, zang; while(!exit_flag) { rest(10); xang = 0; yang = 0; zang = 0; if(keypressed()) { if(key[KEY_ESC]) { exit_flag = 1; } if(key[KEY_A]) { world_pos.x -= 1.0; } if(key[KEY_D]) { world_pos.x += 1.0; } if(key[KEY_W]) { world_pos.z += 3.0; } if(key[KEY_S]) { world_pos.z -= 3.0; } if(key[KEY_UP]) { xang = 3; } if(key[KEY_DOWN]) { xang = -3; } if(key[KEY_RIGHT]) { yang = 3; } if(key[KEY_LEFT]) { yang = -3; } } clear_to_color(buffer, 0); for(i = 0; i < 8; i++) { rotate_vertex(&cube[i], xang, yang, zang); project_vertex(&cube[i], world_pos); } /* printf("%f, %f, %f\n", dist_3d(cube[0].local, cube[1].local), dist_3d(cube[1].local, cube[2].local), dist_3d(cube[2].local, cube[0].local)); */ printf("Sx1:=%f;\nSy1:=%f;\nSx2:=%f;\nSy2:=%f;\nSx3:=%f;\nSy3:=%f;\nSx4:=%f;\nSy4:=%f;\n", cube[0].screen[0].x, cube[0].screen[0].y, cube[1].screen[0].x, cube[1].screen[0].y, cube[2].screen[0].x, cube[2].screen[0].y, cube[3].screen[0].x, cube[3].screen[0].y); printf("t = %f\n\n\n\n\n\n", (cube[0].local.x + world_pos.x) / cube[0].screen[0].x); /*printf("{%f %f %f}\n", cube[0].local.x + world_pos.x, cube[0].local.y + world_pos.y, cube[0].local.z + world_pos.z); */ _2d_line(cube[0].screen[0], cube[1].screen[0], RED); _2d_line(cube[1].screen[0], cube[2].screen[0], RED); _2d_line(cube[2].screen[0], cube[3].screen[0], RED); _2d_line(cube[3].screen[0], cube[0].screen[0], RED); /* _2d_line(cube[4].screen[0], cube[5].screen[0], RED); _2d_line(cube[5].screen[0], cube[6].screen[0], RED); _2d_line(cube[6].screen[0], cube[7].screen[0], RED); _2d_line(cube[7].screen[0], cube[4].screen[0], RED); _2d_line(cube[0].screen[0], cube[4].screen[0], RED); _2d_line(cube[1].screen[0], cube[5].screen[0], RED); _2d_line(cube[2].screen[0], cube[6].screen[0], RED); _2d_line(cube[3].screen[0], cube[7].screen[0], RED); */ /* _2d_line(cube[0].screen[1], cube[1].screen[1], BLUE); _2d_line(cube[1].screen[1], cube[2].screen[1], BLUE); _2d_line(cube[2].screen[1], cube[3].screen[1], BLUE); _2d_line(cube[3].screen[1], cube[0].screen[1], BLUE); _2d_line(cube[4].screen[1], cube[5].screen[1], BLUE); _2d_line(cube[5].screen[1], cube[6].screen[1], BLUE); _2d_line(cube[6].screen[1], cube[7].screen[1], BLUE); _2d_line(cube[7].screen[1], cube[4].screen[1], BLUE); _2d_line(cube[0].screen[1], cube[4].screen[1], BLUE); _2d_line(cube[1].screen[1], cube[5].screen[1], BLUE); _2d_line(cube[2].screen[1], cube[6].screen[1], BLUE); _2d_line(cube[3].screen[1], cube[7].screen[1], BLUE); */ blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); } destroy_bitmap(buffer); return 0; }
bool Tabs::onProcessMessage(Message* msg) { SkinTheme* theme = static_cast<SkinTheme*>(this->getTheme()); switch (msg->type) { case JM_REQSIZE: msg->reqsize.w = 0; // msg->reqsize.h = 4 + jwidget_get_text_height(widget) + 5; msg->reqsize.h = theme->get_part(PART_TAB_FILLER)->h + theme->get_part(PART_TAB_BOTTOM_NORMAL)->h; return true; case JM_SETPOS: jrect_copy(this->rc, &msg->setpos.rect); setScrollX(m_scrollX); return true; case JM_DRAW: { BITMAP *doublebuffer = create_bitmap(jrect_w(&msg->draw.rect), jrect_h(&msg->draw.rect)); JRect rect = jwidget_get_rect(this); jrect_displace(rect, -msg->draw.rect.x1, -msg->draw.rect.y1); JRect box = jrect_new(rect->x1-m_scrollX, rect->y1, rect->x1-m_scrollX+2*jguiscale(), rect->y1+theme->get_part(PART_TAB_FILLER)->h); clear_to_color(doublebuffer, theme->get_window_face_color()); theme->draw_part_as_hline(doublebuffer, box->x1, box->y1, box->x2-1, box->y2-1, PART_TAB_FILLER); theme->draw_part_as_hline(doublebuffer, box->x1, box->y2, box->x2-1, rect->y2-1, PART_TAB_BOTTOM_NORMAL); box->x1 = box->x2; // For each tab... TabsListIterator it, end = m_list_of_tabs.end(); for (it = m_list_of_tabs.begin(); it != end; ++it) { Tab* tab = *it; box->x2 = box->x1 + tab->width; int x_delta = 0; int y_delta = 0; // Y-delta for animating tabs (intros and outros) if (m_ani == ANI_ADDING_TAB && m_selected == tab) { y_delta = (box->y2 - box->y1) * (ANI_ADDING_TAB_TICKS - m_ani_t) / ANI_ADDING_TAB_TICKS; } else if (m_ani == ANI_REMOVING_TAB && m_nextTabOfTheRemovedOne == tab) { x_delta += m_removedTab->width - m_removedTab->width*(1.0-std::exp(-10.0 * m_ani_t / (double)ANI_REMOVING_TAB_TICKS)); x_delta = MID(0, x_delta, m_removedTab->width); // Draw deleted tab if (m_removedTab) { JRect box2 = jrect_new(box->x1, box->y1, box->x1+x_delta, box->y2); drawTab(doublebuffer, box2, m_removedTab, 0, false); jrect_free(box2); } } box->x1 += x_delta; box->x2 += x_delta; drawTab(doublebuffer, box, tab, y_delta, (tab == m_selected)); box->x1 = box->x2; } if (m_ani == ANI_REMOVING_TAB && m_nextTabOfTheRemovedOne == NULL) { // Draw deleted tab if (m_removedTab) { int x_delta = m_removedTab->width - m_removedTab->width*(1.0-std::exp(-10.0 * m_ani_t / (double)ANI_REMOVING_TAB_TICKS)); x_delta = MID(0, x_delta, m_removedTab->width); JRect box2 = jrect_new(box->x1, box->y1, box->x1+x_delta, box->y2); drawTab(doublebuffer, box2, m_removedTab, 0, false); jrect_free(box2); box->x1 += x_delta; box->x2 = box->x1; } } /* fill the gap to the right-side */ if (box->x1 < rect->x2) { theme->draw_part_as_hline(doublebuffer, box->x1, box->y1, rect->x2-1, box->y2-1, PART_TAB_FILLER); theme->draw_part_as_hline(doublebuffer, box->x1, box->y2, rect->x2-1, rect->y2-1, PART_TAB_BOTTOM_NORMAL); } jrect_free(rect); jrect_free(box); blit(doublebuffer, ji_screen, 0, 0, msg->draw.rect.x1, msg->draw.rect.y1, doublebuffer->w, doublebuffer->h); destroy_bitmap(doublebuffer); return true; } case JM_MOUSEENTER: case JM_MOTION: calculateHot(); return true; case JM_MOUSELEAVE: if (m_hot != NULL) { m_hot = NULL; invalidate(); } return true; case JM_BUTTONPRESSED: if (m_hot != NULL) { if (m_selected != m_hot) { m_selected = m_hot; invalidate(); } if (m_selected && m_delegate) m_delegate->clickTab(this, m_selected->data, msg->mouse.flags); } return true; case JM_WHEEL: { int dx = (jmouse_z(1) - jmouse_z(0)) * jrect_w(this->rc)/6; // setScrollX(m_scrollX+dx); m_begScrollX = m_scrollX; if (m_ani != ANI_SMOOTH_SCROLL) m_endScrollX = m_scrollX + dx; else m_endScrollX += dx; // Limit endScrollX position (to improve animation ending to the correct position) { int max_x = getMaxScrollX(); m_endScrollX = MID(0, m_endScrollX, max_x); } startAni(ANI_SMOOTH_SCROLL); return true; } case JM_TIMER: { switch (m_ani) { case ANI_NONE: // Do nothing break; case ANI_SCROLL: { int dir = (getManager()->getCapture() == m_button_left ? -1: 1); setScrollX(m_scrollX + dir*8*msg->timer.count); break; } case ANI_SMOOTH_SCROLL: { if (m_ani_t == ANI_SMOOTH_SCROLL_TICKS) { stopAni(); setScrollX(m_endScrollX); } else { // Lineal //setScrollX(m_begScrollX + m_endScrollX - m_begScrollX) * m_ani_t / 10); // Exponential setScrollX(m_begScrollX + (m_endScrollX - m_begScrollX) * (1.0-std::exp(-10.0 * m_ani_t / (double)ANI_SMOOTH_SCROLL_TICKS))); } break; } case ANI_ADDING_TAB: { if (m_ani_t == ANI_ADDING_TAB_TICKS) stopAni(); invalidate(); break; } case ANI_REMOVING_TAB: { if (m_ani_t == ANI_REMOVING_TAB_TICKS) stopAni(); invalidate(); break; } } ++m_ani_t; break; } case JM_SIGNAL: if (msg->signal.num == JI_SIGNAL_INIT_THEME) { m_button_left->setBgColor(theme->get_tab_selected_face_color()); m_button_right->setBgColor(theme->get_tab_selected_face_color()); } else if (msg->signal.num == JI_SIGNAL_SET_FONT) { TabsListIterator it, end = m_list_of_tabs.end(); for (it = m_list_of_tabs.begin(); it != end; ++it) { Tab* tab = *it; tab->width = calcTabWidth(tab); } } else if (msg->signal.num == JI_SIGNAL_INIT_THEME) { /* setup the background color */ jwidget_set_bg_color(this, ji_color_face()); } break; } return Widget::onProcessMessage(msg); }
void Layer::draw(BITMAP * dest) { // default implementation: clear blue clear_to_color (dest, BLUE); }
int main() { int klaw = 0; allegro_init(); install_keyboard(); set_color_depth(16); set_gfx_mode(GFX_AUTODETECT,640,480,0,0); clear_to_color(screen,makecol(10,10,10)); while( !key[KEY_ESC]) { /* klaw = readkey(); clear_to_color(screen,makecol(10,10,10)); switch (klaw) { case 7217: textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : 1"); break; case 7474: textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : 2"); break; case 7731: textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : 3"); break; case 7988: textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : 4"); break; case 8245: textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : 5"); break; } if( key[KEY_LEFT]) textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : [KEY_LEFT]"); if( key[KEY_RIGHT]) textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : [KEY_RIGHT]"); if( key[KEY_UP]) textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : [KEY_UP]"); if( key[KEY_DOWN]) textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : [KEY_DOWN]"); if( key[KEY_0]) textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : [KEY_0]"); if( key[KEY_1]) textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : [KEY_1]"); if( key[KEY_2]) textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : [KEY_2]"); if( key[KEY_3]) textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : [KEY_3]"); if( key[KEY_4]) textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : [KEY_4]"); if( key[KEY_5]) textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : [KEY_5]"); if( key[KEY_6]) textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : [KEY_6]"); if( key[KEY_7]) textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : [KEY_7]"); if( key[KEY_8]) textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : [KEY_8]"); if( key[KEY_9]) textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : [KEY_9]"); if( key[KEY_SPACE]) textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : [KEY_SPACE]"); if( key[KEY_ENTER]) textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : [KEY_ENTER]"); */ BITMAP *plik = NULL; plik = load_bmp("bmp.bmp",default_palette); if (!plik) { set_gfx_mode(GFX_TEXT,0,0,0,0); allegro_message("nie mogê za³adowaæ obrazka Plik!"); allegro_exit(); return 0; } blit( plik, screen, 0,0, 100,100, plik->w, plik->h); readkey(); destroy_bitmap(plik); allegro_exit(); } allegro_exit(); return 0; }
int select_a_ship(void) { int ship_box [8] = {0,0,0,0,0,0,0,0}; int sbox2; int ship_chosen = 0; int level_chosen = 1; int max_level, wpixels; menu_counter = 0; counter2 = 0; int anykey = 0; int i, x, y, k; int holding_key = 1; while (TRUE) { menu_counter ++; clear_to_color(display, COL_BACK1); run_menu_background(); x = 30; y = 40; #define Y_INTERVAL 100 #define Y_BASE 45 // stages aabox(200, 50, 550, 250); TRANS_MODE rectfill(display, 375 - 80, 70, 375 + 80, 100, TRANS_BLUE2); rect(display, 375 - 80, 70 - 0, 375 + 80, 100, TRANS_BLUE3); rect(display, 375 - 81, 70 - 1, 375 + 81, 100 + 1, TRANS_BLUE2); END_TRANS textprintf_centre_ex(display, font, 375, 80, -1, -1, "select stage"); switch(arena.difficulty) { case 0: textprintf_centre_ex(display, font, 375, 115, -1, -1, "NORMAL"); break; case 1: textprintf_centre_ex(display, font, 375, 115, -1, -1, "HARD"); break; case 2: textprintf_centre_ex(display, font, 375, 115, -1, -1, "PUNISHMENT"); break; } for (i = 0; i < 3; i ++) { if (i == 0) { aabox(230 + i * 70, 140 + i * 25, 270 + i * 70, 180 + i * 25); textprintf_centre_ex(display, font, 250 + i * 70, 152 + i * 25, -1, -1, "%i", i + 1); rect(display, 276 + i * 70, 141 + i * 25, 302 + i * 70, 152 + i * 25, TRANS_BLUE3); } else if (options.stage_power [ship_chosen] [i - 1] [arena.difficulty] != 0 || options.stage_power_bar [ship_chosen] [i - 1] [arena.difficulty] != 0) { aabox(230 + i * 70, 140 + i * 25, 270 + i * 70, 180 + i * 25); if (options.stage_power [ship_chosen] [i - 1] [arena.difficulty] < 0 || options.stage_power [ship_chosen] [i - 1] [arena.difficulty] > 9) options.stage_power [ship_chosen] [i - 1] [arena.difficulty] = 0; // sanity check textprintf_centre_ex(display, font, 250 + i * 70, 152 + i * 25, -1, -1, "%i", i + 1); TRANS_MODE for (k = 0; k < options.stage_power [ship_chosen] [i - 1] [arena.difficulty]; k ++) { rectfill(display, 305 + i * 70 + k * 4, 143 + i * 25, 307 + i * 70 + k * 4, 150 + i * 25, TRANS_RED1); rect(display, 305 + i * 70 + k * 4, 143 + i * 25, 307 + i * 70 + k * 4, 150 + i * 25, TRANS_RED4); } // rect(display, 275 + i * 70, 143 + i * 25, 303 + i * 70, 152 + i * 25, COL_OUTLINE); // rect(display, 276 + i * 70, 144 + i * 25, 302 + i * 70, 151 + i * 25, COL_LGREY); rect(display, 276 + i * 70, 141 + i * 25, 302 + i * 70, 152 + i * 25, TRANS_BLUE3); #define LEVEL_CALC2 (3500 + (1100 * options.stage_power [ship_chosen] [i - 1] [arena.difficulty])) // duplicated in enemy.c and level.c wpixels = ((float) (options.stage_power_bar [ship_chosen] [i - 1] [arena.difficulty] * 20) / LEVEL_CALC2); if (wpixels >= 20 || wpixels < 0) wpixels = 19; if (wpixels > 0) { rectfill(display, 279 + i * 70, 143 + i * 25, 279 + i * 70 + wpixels, 150 + i * 25, TRANS_RED1); rect(display, 278 + i * 70, 143 + i * 25, 278 + wpixels + i * 70, 150 + i * 25, TRANS_RED5); } END_TRANS } TRANS_MODE if (level_chosen - 1 == i) rectfill(display, 230 + i * 70, 140 + i * 25, 270 + i * 70, 180 + i * 25, TRANS_BLUE2); END_TRANS } if (options.clear [ship_chosen] [arena.difficulty]) { TRANS_MODE rectfill(display, 207, 236, 214, 243, TRANS_BLUE4); END_TRANS textprintf_ex(display, font, 219, 231, -1, -1, "cleared"); } else if (options.finished [ship_chosen] [arena.difficulty]) { TRANS_MODE rectfill(display, 207, 236, 214, 243, TRANS_RED4); END_TRANS textprintf_ex(display, font, 219, 231, -1, -1, "finished"); } // ships draw_rle_sprite(display, eRLE_player [S_PLAYER1_1], x + 25 - 16, y + Y_BASE - 20 + 7); draw_rle_sprite(display, eRLE_player [S_PLAYER2_1], x + 25 - 19, y + Y_INTERVAL + Y_BASE - 8 - 5); draw_rle_sprite(display, eRLE_player [S_PLAYER3_1], x + 25 - 22, y + Y_INTERVAL * 2 + Y_BASE - 7 - 6); draw_rle_sprite(display, eRLE_player [S_PLAYER4_1], x + 25 - 16, y + Y_INTERVAL * 3 + Y_BASE - 9 - 4); draw_rle_sprite(display, eRLE_player [S_PLAYER4_1L], x + 25 - 16, y + Y_INTERVAL * 3 + Y_BASE - 4 + 3); draw_rle_sprite(display, eRLE_player [S_PLAYER5_1], x + 25 - 17, y + Y_INTERVAL * 4 + Y_BASE - 21); // draw_rle_sprite(display, eRLE_player [S_PLAYER6_1], x + 25 - 16, y + Y_INTERVAL * 5 + 25 - 16); /* textprintf_centre_ex(display, font, 100, 32, -1, -1, "g"); textprintf_centre_ex(display, font, 100, 44, -1, -1, "g"); textprintf_centre_ex(display, font, 100, 56, -1, -1, "g"); textprintf_centre_ex(display, font, 100, 68, -1, -1, "g"); textprintf_centre_ex(display, font, 100, 80, -1, -1, "g"); */ TRANS_MODE for (i = 0; i < 5; i ++) { rectfill(display, x, y - 25 + Y_BASE + i * Y_INTERVAL, x + 50, y + 25 + Y_BASE + i * Y_INTERVAL, TRANS_BLUE1); rect(display, x - 1, y - 25 + Y_BASE + i * Y_INTERVAL - 1, x + 50 + 1, y + 25 + Y_BASE + i * Y_INTERVAL + 1, TRANS_BLUE2); rect(display, x - 2, y - 25 + Y_BASE + i * Y_INTERVAL - 2, x + 50 + 2, y + 25 + Y_BASE + i * Y_INTERVAL + 2, TRANS_BLUE3); rect(display, x - 3, y - 25 + Y_BASE + i * Y_INTERVAL - 3, x + 50 + 3, y + 25 + Y_BASE + i * Y_INTERVAL + 3, TRANS_BLUE1); if (ship_chosen == i) { switch((menu_counter / 4) % 4) { case 0: default: rectfill(display, x - 1, y + i * Y_INTERVAL - 1 - 25 + Y_BASE, x + 50 + 1, y + 25 + Y_BASE + i * Y_INTERVAL + 1, TRANS_BLUE2); break; /* case 1: rectfill(display, x - 1, y + i * Y_INTERVAL - 1, x + 50 + 1, y + 50 + i * Y_INTERVAL + 1, TRANS_BLUE3); break; case 2: rectfill(display, x - 1, y + i * Y_INTERVAL - 1, x + 50 + 1, y + 50 + i * Y_INTERVAL + 1, TRANS_BLUE2); break; case 3: rectfill(display, x - 1, y + i * Y_INTERVAL - 1, x + 50 + 1, y + 50 + i * Y_INTERVAL + 1, TRANS_BLUE1); break;*/ } } if (ship_box [i] > 0) { sbox2 = ship_box [i]; // if (ship_box [ship_chosen] > 12 + xpart(menu_counter * 8, 5)) // sbox2 = 12 + xpart(menu_counter * 8, 5); rect(display, x - 3 - sbox2, y + i * Y_INTERVAL - 3 - sbox2 - 25 + Y_BASE, x + 50 + 3 + sbox2, y + 25 + Y_BASE + i * Y_INTERVAL + 3 + sbox2, TRANS_BLUE3); ship_box [i] --; } } END_TRANS ship_box [ship_chosen] += 2; if (ship_box [ship_chosen] > 15)// + xpart(menu_counter * 8, 5)) ship_box [ship_chosen] = 15; #define TITLE_X 375 #define TITLE_Y 320 #define LINE_X 220 #define LINE1_Y 350 #define LINE2_Y 365 #define LINE3_Y 380 #define LINE4_Y 395 TRANS_MODE rectfill(display, 200, 300, 550, 550, TRANS_BLUE1); rect(display, 200 - 1, 300 - 1, 550 + 1, 550 + 1, TRANS_BLUE2); rect(display, 200 - 2, 300 - 2, 550 + 2, 550 + 2, TRANS_BLUE3); rect(display, 200 - 3, 300 - 3, 550 + 3, 550 + 3, TRANS_BLUE2); rect(display, 200 - 4, 300 - 4, 550 + 4, 550 + 4, TRANS_BLUE1); sbox2 = ship_box [ship_chosen]; rect(display, 200 - sbox2 - 0, 300 - sbox2 - 0, 550 + sbox2 + 0, 550 + sbox2 + 0, TRANS_BLUE1); rect(display, 200 - sbox2 - 1, 300 - sbox2 - 1, 550 + sbox2 + 1, 550 + sbox2 + 1, TRANS_BLUE2); rect(display, 200 - sbox2 - 2, 300 - sbox2 - 2, 550 + sbox2 + 2, 550 + sbox2 + 2, TRANS_BLUE3); rect(display, 200 - sbox2 - 3, 300 - sbox2 - 3, 550 + sbox2 + 3, 550 + sbox2 + 3, TRANS_BLUE2); rect(display, 200 - sbox2 - 4, 300 - sbox2 - 4, 550 + sbox2 + 4, 550 + sbox2 + 4, TRANS_BLUE1); vline(display, TITLE_X, 550 + sbox2 + 2, 590, TRANS_BLUE3); hline(display, 5, 590, TITLE_X, TRANS_BLUE3); vline(display, 5, 40 + 25 + ship_chosen * Y_INTERVAL, 590, TRANS_BLUE3); hline(display, 5, 40 + 25 + ship_chosen * Y_INTERVAL, 30 - sbox2 - 3, TRANS_BLUE3); END_TRANS char ftext [8] [9] [150] = { { "white butterfly", "1 - autocannon", "2 - heavy cannon", "3 - seekers", "fire1 - autocannon", "fire2 - charge heavy cannon", "fire1 while charging - seekers", "" }, { "anemone", "1 - single cannon", "2 - strong, short-range blade", "3 - weak, long-range blade", "fire1 - single cannon", "fire2 - blade slash", "fire1 + fire2 - blade swing", " hold blade buttons for full circle", "" }, { "spinneret", "1 - orb beams", "2 - orb scatter fire", "3 - bomb launcher", "fire1 - orb beams", "fire1 + fire2 - orb fire", "fire2 - bomb launcher", "" }, { "hand of xom", "1 - multi-cannon", "2 - closed hand", "3 - open hand", "fire1 - multi-cannon", "fire2 - open up hand" "", "" } , { "chaos squid", "1 - chaos droplets", "2 - chaos swarm", "3 - orb field", "fire1 while orb docked - fire droplets", "fire1 while orb loose - fire swarm", "fire2 - control orb", "fire1 + fire2 - repel orb" } }; #define TEXT_X 230 TRANS_MODE rectfill(display, TITLE_X - 80, TITLE_Y - 0, TITLE_X + 80, TITLE_Y + 30, TRANS_BLUE2); rect(display, TITLE_X - 80, TITLE_Y - 0, TITLE_X + 80, TITLE_Y + 30, TRANS_BLUE3); rect(display, TITLE_X - 81, TITLE_Y - 1, TITLE_X + 81, TITLE_Y + 31, TRANS_BLUE2); textprintf_centre_ex(display, font, TITLE_X, TITLE_Y + 10, -1, -1, ftext [ship_chosen] [0]); if (ship_chosen == 4 && options.unlock [arena.difficulty] == 0) { textprintf_centre_ex(display, font, TITLE_X, TITLE_Y + 80, -1, -1, "finish stage 3 to unlock"); } else { hline(display, 198, LINE1_Y + 30, 320, TRANS_BLUE3); textprintf_ex(display, font, TEXT_X - 5, LINE1_Y + 20, -1, -1, "weapons"); textprintf_ex(display, font, TEXT_X, LINE1_Y + 40, -1, -1, ftext [ship_chosen] [1]); textprintf_ex(display, font, TEXT_X, LINE1_Y + 55, -1, -1, ftext [ship_chosen] [2]); textprintf_ex(display, font, TEXT_X, LINE1_Y + 70, -1, -1, ftext [ship_chosen] [3]); // textprintf_ex(display, font, TEXT_X, LINE1_Y + 60, -1, -1, ftext [ship_chosen] [4]); hline(display, 198, LINE1_Y + 110, 320, TRANS_BLUE3); textprintf_ex(display, font, TEXT_X - 5, LINE1_Y + 100, -1, -1, "controls"); textprintf_ex(display, font, TEXT_X, LINE1_Y + 120, -1, -1, ftext [ship_chosen] [4]); textprintf_ex(display, font, TEXT_X, LINE1_Y + 135, -1, -1, ftext [ship_chosen] [5]); textprintf_ex(display, font, TEXT_X, LINE1_Y + 150, -1, -1, ftext [ship_chosen] [6]); textprintf_ex(display, font, TEXT_X, LINE1_Y + 165, -1, -1, ftext [ship_chosen] [7]); } END_TRANS // ship_box [ship_chosen] = 15 + xpart(menu_counter * 8, 5); /* draw_rle_sprite(display, eRLE_player [S_PLAYER1_1], x + 25 - 16, y + 25 - 20 + 7); draw_rle_sprite(display, eRLE_player [S_PLAYER2_1], x + 90 + 25 - 19, y + 25 - 8 - 5); draw_rle_sprite(display, eRLE_player [S_PLAYER3_1], x + 25 - 22, y + Y_INTERVAL + 25 - 7 - 6); draw_rle_sprite(display, eRLE_player [S_PLAYER4_1], x + 90 + 25 - 16, y + Y_INTERVAL + 25 - 9 - 4); textprintf_centre_ex(display, font, 30, 102, -1, -1, "g"); textprintf_centre_ex(display, font, 30, 114, -1, -1, "g"); textprintf_centre_ex(display, font, 30, 126, -1, -1, "g"); textprintf_centre_ex(display, font, 30, 138, -1, -1, "g"); textprintf_centre_ex(display, font, 30, 150, -1, -1, "g"); TRANS_MODE for (i = 0; i < 4; i ++) { rectfill(display, x, y + i * Y_INTERVAL, x + 50, y + 50 + i * Y_INTERVAL, TRANS_BLUE1); rect(display, x - 1, y + i * Y_INTERVAL - 1, x + 50 + 1, y + 50 + i * Y_INTERVAL + 1, TRANS_BLUE2); rect(display, x - 2, y + i * Y_INTERVAL - 2, x + 50 + 2, y + 50 + i * Y_INTERVAL + 2, TRANS_BLUE3); rect(display, x - 3, y + i * Y_INTERVAL - 3, x + 50 + 3, y + 50 + i * Y_INTERVAL + 3, TRANS_BLUE1); rectfill(display, x + 90, y + i * Y_INTERVAL, x + 140, y + 50 + i * Y_INTERVAL, TRANS_BLUE1); rect(display, x + 90 - 1, y + i * Y_INTERVAL - 1, x + 140 + 1, y + 50 + i * Y_INTERVAL + 1, TRANS_BLUE2); rect(display, x + 90 - 2, y + i * Y_INTERVAL - 2, x + 140 + 2, y + 50 + i * Y_INTERVAL + 2, TRANS_BLUE3); rect(display, x + 90 - 3, y + i * Y_INTERVAL - 3, x + 140 + 3, y + 50 + i * Y_INTERVAL + 3, TRANS_BLUE1); } END_TRANS */ if (key [KEY_ESC]) return -1; anykey = 0; for (i = KEY_A; i < KEY_CAPSLOCK + 1; i ++) { if (key [i]) { anykey = 1; } } if (anykey == 0 && (options.joystick == 0 || any_joystick_input() == 0)) { key_wait = 0; holding_key = 0; } /* if (anykey == 0) { key_wait = 0; holding_key = 0; }*/ max_level = 1; if (options.stage_power [ship_chosen] [0] [arena.difficulty] > 0 || options.stage_power_bar [ship_chosen] [0] [arena.difficulty] > 0) max_level = 2; if (options.stage_power [ship_chosen] [1] [arena.difficulty] > 0 || options.stage_power_bar [ship_chosen] [1] [arena.difficulty] > 0) max_level = 3; // if (key_wait <= 0 && holding_key == 0) if (holding_key == 0) { if (key [player.key [CKEY_UP]] || menu_command(MC_UP)) { ship_chosen --; if (ship_chosen < 0) ship_chosen = 4; holding_key = 1; key_wait = 7; level_chosen = 1; } if (key [player.key [CKEY_DOWN]] || menu_command(MC_DOWN)) { ship_chosen ++; if (ship_chosen > 4) ship_chosen = 0; holding_key = 1; key_wait = 7; level_chosen = 1; } if (key [player.key [CKEY_LEFT]] || menu_command(MC_LEFT)) { level_chosen --; if (level_chosen < 1) level_chosen = max_level; holding_key = 1; key_wait = 7; } if (key [player.key [CKEY_RIGHT]] || menu_command(MC_RIGHT)) { level_chosen ++; if (level_chosen > max_level) level_chosen = 1; holding_key = 1; key_wait = 7; } if (key [player.key [CKEY_FIRE1]] || key [KEY_ENTER] || key [KEY_SPACE] || key [KEY_Z] || menu_command(MC_SELECT)) { if (ship_chosen != 4 || options.unlock [arena.difficulty] == 1) { arena.level = level_chosen; return ship_chosen; } } // if (key [KEY_UP] || key [KEY_8_PAD]) /* if (key [KEY_UP] || key [KEY_8_PAD]) { menu_select --; if (menu_select < 0) menu_select = MENU_EXIT; if (menu_select == MENU_CALIBRATE && options.joystick == 0) menu_select = MENU_KEYS; if (menu_select == MENU_JOY_OR_KEYS && options.joystick == 0) menu_select = MENU_JOY_OR_KEYS - 1; // key_wait = 7; holding_key = 1; } if (key [KEY_DOWN] || key [KEY_2_PAD]) { menu_select ++; if (menu_select > MENU_EXIT) menu_select = 0; if (menu_select == MENU_CALIBRATE && options.joystick == 0) menu_select = MENU_EXIT; if (menu_select == MENU_JOY_OR_KEYS && options.joystick == 0) menu_select = MENU_KEYS; // key_wait = 7; holding_key = 1; }*/ /* if (key [KEY_LEFT] || key [KEY_4_PAD]) { // if (menu_select == 2) // arena.starting_level = 1; key_wait = 7; holding_key = 1; }*/ } // } else key_wait --; do { thing ++; } while (ticked == 0); ticked = 0; if (arena.shift_palette > 0 && menu_counter % 12 == 0) { run_palette_shift(); build_new_palette(0, 0, 0, 0); set_palette(palet); if (arena.shift_palette == 1) arena.shift_palette = 0; } vsync(); blit(display, screen, 0, 0, 100, 0, 600, 600); };
/* moves a sprite along the spline path */ void walk(void) { #define MAX_POINTS 256 int points[8]; int x[MAX_POINTS], y[MAX_POINTS]; int n, i; int npoints; int ox, oy; acquire_screen(); clear_to_color(screen, makecol(255, 255, 255)); for (i=1; i<node_count-1; i++) draw_node(i); release_screen(); do { poll_mouse(); } while (mouse_b); clear_keybuf(); ox = -16; oy = -16; xor_mode(TRUE); for (n=1; n < node_count-2; n++) { npoints = (fixtoi(node_dist(nodes[n], nodes[n+1]))+3) / 4; if (npoints < 1) npoints = 1; else if (npoints > MAX_POINTS) npoints = MAX_POINTS; get_control_points(nodes[n], nodes[n+1], points); calc_spline(points, npoints, x, y); for (i=1; i<npoints; i++) { vsync(); acquire_screen(); circlefill(screen, ox, oy, 6, palette_color[2]); circlefill(screen, x[i], y[i], 6, palette_color[2]); release_screen(); ox = x[i]; oy = y[i]; poll_mouse(); if ((keypressed()) || (mouse_b)) goto getout; } } getout: xor_mode(FALSE); do { poll_mouse(); } while (mouse_b); clear_keybuf(); }
/*! \brief Main menu screen * * This is the main menu... just display the opening and then the menu and * then wait for input. Also handles loading a saved game, and the config menu. * * \param c zero if the splash (the bit with the staff and the eight heroes) * should be displayed. * \returns 1 if new game, 0 if continuing, 2 if exit */ int start_menu (int skip_splash) { int stop = 0, ptr = 0, redraw = 1, a, b; DATAFILE *bg; BITMAP *staff, *dudes, *tdudes; #ifdef DEBUGMODE if (debugging == 0) { #endif play_music ("oxford.s3m", 0); /* Play splash (with the staff and the heroes in circle */ if (skip_splash == 0) { bg = load_datafile_object (PCX_DATAFILE, "KQT_PCX"); staff = create_bitmap_ex (8, 72, 226); dudes = create_bitmap_ex (8, 112, 112); tdudes = create_bitmap_ex (8, 112, 112); blit ((BITMAP *) bg->dat, staff, 0, 7, 0, 0, 72, 226); blit ((BITMAP *) bg->dat, dudes, 80, 0, 0, 0, 112, 112); clear_bitmap (double_buffer); blit (staff, double_buffer, 0, 0, 124, 22, 72, 226); blit2screen (0, 0); kq_wait (1000); for (a = 0; a < 42; a++) { stretch_blit (staff, double_buffer, 0, 0, 72, 226, 124 - (a * 32), 22 - (a * 96), 72 + (a * 64), 226 + (a * 192)); blit2screen (0, 0); kq_wait (100); } for (a = 0; a < 5; a++) { color_scale (dudes, tdudes, 53 - a, 53 + a); draw_sprite (double_buffer, tdudes, 106, 64); blit2screen (0, 0); kq_wait (100); } draw_sprite (double_buffer, dudes, 106, 64); blit2screen (0, 0); kq_wait (1000); destroy_bitmap (staff); destroy_bitmap (dudes); destroy_bitmap (tdudes); unload_datafile_object(bg); /* TODO: this fade should actually be to white if (_color_depth == 8) fade_from (pal, whp, 1); else */ do_transition (TRANS_FADE_WHITE, 1); } clear_to_color (double_buffer, 15); blit2screen (0, 0); set_palette (pal); bg = load_datafile_object (PCX_DATAFILE, "TITLE_PCX"); for (a = 0; a < 16; a++) { clear_to_color (double_buffer, 15 - a); masked_blit ((BITMAP *) bg->dat, double_buffer, 0, 0, 0, 60 - (a * 4), 320, 124); blit2screen (0, 0); kq_wait (a == 0 ? 500 : 100); } if (skip_splash == 0) kq_wait (500); #ifdef DEBUGMODE } else { set_palette (pal); bg = load_datafile_object (PCX_DATAFILE, "TITLE_PCX"); } #endif reset_world (); /* Draw menu and handle menu selection */ while (!stop) { if (redraw) { clear_bitmap (double_buffer); masked_blit ((BITMAP *) bg->dat, double_buffer, 0, 0, 0, 0, 320, 124); menubox (double_buffer, 112, 116, 10, 4, BLUE); print_font (double_buffer, 128, 124, _("Continue"), FNORMAL); print_font (double_buffer, 128, 132, _("New Game"), FNORMAL); print_font (double_buffer, 136, 140, _("Config"), FNORMAL); print_font (double_buffer, 144, 148, _("Exit"), FNORMAL); draw_sprite (double_buffer, menuptr, 112, ptr * 8 + 124); redraw = 0; } display_credits (); blit2screen (0, 0); readcontrols (); if (bhelp) { unpress (); show_help (); redraw = 1; } if (up) { unpress (); if (ptr > 0) ptr--; else ptr = 3; play_effect (SND_CLICK, 128); redraw = 1; } if (down) { unpress (); if (ptr < 3) ptr++; else ptr = 0; play_effect (SND_CLICK, 128); redraw = 1; } if (balt) { unpress (); if (ptr == 0) { /* User selected "Continue" */ if (snc[0] == 0 && snc[1] == 0 && snc[2] == 0 && snc[3] == 0 && snc[4] == 0) stop = 2; else if (saveload (0) == 1) stop = 1; redraw = 1; } else if (ptr == 1) { /* User selected "New Game" */ stop = 2; } else if (ptr == 2) { /* Config */ clear (double_buffer); config_menu (); redraw = 1; /* TODO: Save Global Settings Here */ } else if (ptr == 3) { /* Exit */ unload_datafile_object (bg); klog (_("Then exit you shall!")); return 2; } } } unload_datafile_object (bg); if (stop == 2) { /* New game init */ for (a = 0; a < MAXCHRS; a++) memcpy (&party[a], &players[a].plr, sizeof (s_player)); init_players (); memset (progress, 0, SIZE_PROGRESS); memset (treasure, 0, SIZE_TREASURE); numchrs = 0; for (a = 0; a < NUMSHOPS; a++) { for (b = 0; b < SHOPITEMS; b++) shops[a].items_current[b] = shops[a].items_max[b]; } for (b = 0; b < 2; b++) { for (a = 0; a < MAX_INV; a++) g_inv[a][b] = 0; } } return stop - 1; }
int loadLvl(Label cellLabels[], Destination boxes[], BITMAP *&background, int levelNum){ int lbls; for (int i = 0; i < 20; i++){ cellLabels[i].x = screenw; cellLabels[i].y = screenh; cellLabels[i].h = 0; cellLabels[i].w = 0; cellLabels[i].clicked = false; cellLabels[i].visible = false; boxes[i].x = screenw + 1; boxes[i].y = screenh + 1; boxes[i].h = 0; boxes[i].w = 0; boxes[i].visible = false; } switch(levelNum){ case 1: lbls = 4; background = create_bitmap(screenw, screenh); clear_to_color(background, makecol(125, 38, 205)); for (int i = 0; i < lbls; i++){ cellLabels[i].y = i * 43; cellLabels[i].x = 735; cellLabels[i].h = 40; cellLabels[i].w = 100; cellLabels[i].clicked = false; cellLabels[i].visible = true; boxes[i].x = 0; boxes[i].y = 225; if(i >= 6) boxes[i].y = 500; boxes[i].h = 40; boxes[i].w = 100; boxes[i].visible = true; } /*for(int i = 0; i < lbls; i++){ std::swap(cellLabels[i].y, cellLabels[rand()%lbls].y); }*/ for(int i = 0; i < 4; i++) boxes[i].x = i * 105 + 4; for(int i = 6; i < 10; i++) boxes[i].x = i%6 * 105 + 4; boxes[4].x = 435; boxes[5].x = 590; boxes[10].x = 435; boxes[11].x = 590; strcpy(cellLabels[0].name, "A"); strcpy(cellLabels[1].name, "very"); strcpy(cellLabels[2].name, "clean"); strcpy(cellLabels[3].name, "animal"); break; case 2: lbls = 5; background = create_bitmap(screenw, screenh); clear_to_color(background, makecol(125, 38, 205)); for (int i = 0; i < lbls; i++){ cellLabels[i].y = i * 45 + 214; cellLabels[i].x = 735; cellLabels[i].h = 40; cellLabels[i].w = 100; cellLabels[i].clicked = false; cellLabels[i].visible = true; boxes[i].x = 0; boxes[i].y = 0; boxes[i].h = 40; boxes[i].w = 100; boxes[i].visible = true; } /*for(int i = 0; i < lbls; i++){ std::swap(cellLabels[i].y, cellLabels[rand()%lbls].y); }*/ boxes[0].x = 33; boxes[0].y = 362; boxes[1].x = 256; boxes[1].y = 440; boxes[2].x = 476; boxes[2].y = 315; strcpy(cellLabels[0].name, "But"); strcpy(cellLabels[1].name, "thought"); strcpy(cellLabels[2].name, "to"); strcpy(cellLabels[3].name, "be"); strcpy(cellLabels[4].name, "dirtiest"); break; case 3: lbls = 4; background = create_bitmap(screenw, screenh); clear_to_color(background, makecol(125, 38, 205)); for (int i = 0; i < lbls; i++){ cellLabels[i].y = i * 45 + 214; cellLabels[i].x = 735; cellLabels[i].h = 40; cellLabels[i].w = 100; cellLabels[i].clicked = false; cellLabels[i].visible = true; boxes[i].x = 0; boxes[i].y = 0; boxes[i].h = 40; boxes[i].w = 100; boxes[i].visible = true; } /*for(int i = 0; i < lbls; i++){ std::swap(cellLabels[i].y, cellLabels[rand()%lbls].y); }*/ boxes[0].x = 25; boxes[0].y = 458; boxes[1].x = 230; boxes[1].y = 467; boxes[2].x = 518; boxes[2].y = 279; strcpy(cellLabels[0].name, "Where"); strcpy(cellLabels[1].name, "does"); strcpy(cellLabels[2].name, "it"); strcpy(cellLabels[3].name, "sleep?"); break; case 4: lbls = 4; background = create_bitmap(screenw, screenh); clear_to_color(background, makecol(125, 38, 205)); for (int i = 0; i < lbls; i++){ cellLabels[i].y = i * 45 + 214; cellLabels[i].x = 735; cellLabels[i].h = 40; cellLabels[i].w = 100; cellLabels[i].clicked = false; cellLabels[i].visible = true; boxes[i].x = 0; boxes[i].y = 0; boxes[i].h = 40; boxes[i].w = 100; boxes[i].visible = true; } /*for(int i = 0; i < lbls; i++){ std::swap(cellLabels[i].y, cellLabels[rand()%lbls].y); }*/ boxes[0].x = 10; boxes[0].y = 473; boxes[1].x = 276; boxes[1].y = 444; boxes[2].x = 503; boxes[2].y = 437; strcpy(cellLabels[0].name, "Where"); strcpy(cellLabels[1].name, "utensils"); strcpy(cellLabels[2].name, "are"); strcpy(cellLabels[3].name, "inkiest"); break; /*case 5: lbls = 3; background = load_bitmap("bitmaps/anaphase2.bmp", NULL); if (!background) background = create_bitmap(screenw, screenh); for (int i = 0; i < lbls; i++){ cellLabels[i].y = i * 45 + 214; cellLabels[i].x = 735; cellLabels[i].h = 40; cellLabels[i].w = 100; cellLabels[i].clicked = false; cellLabels[i].visible = true; boxes[i].x = 0; boxes[i].y = 0; boxes[i].h = 40; boxes[i].w = 100; boxes[i].visible = true; } for(int i = 0; i < lbls; i++){ std::swap(cellLabels[i].y, cellLabels[rand()%lbls].y); } boxes[0].x = 163; boxes[0].y = 430; boxes[1].x = 353; boxes[1].y = 443; boxes[2].x = 578; boxes[2].y = 136; strcpy(cellLabels[0].name, "Daughter CellS"); strcpy(cellLabels[1].name, "Poles"); strcpy(cellLabels[2].name, "Spindle Fibre"); break; case 6: lbls = 2; background = load_bitmap("bitmaps/cytokinesis2.bmp", NULL); if (!background) background = create_bitmap(screenw, screenh); for (int i = 0; i < lbls; i++){ cellLabels[i].y = i * 45 + 214; cellLabels[i].x = 735; cellLabels[i].h = 40; cellLabels[i].w = 100; cellLabels[i].clicked = false; cellLabels[i].visible = true; boxes[i].x = 0; boxes[i].y = 0; boxes[i].h = 40; boxes[i].w = 100; boxes[i].visible = true; } for(int i = 0; i < lbls; i++){ std::swap(cellLabels[i].y, cellLabels[rand()%lbls].y); } boxes[0].x = 24; boxes[0].y = 282; boxes[1].x = 573; boxes[1].y = 313; strcpy(cellLabels[0].name, "Chromatin"); strcpy(cellLabels[1].name, "Haploid Cells"); break;*/ default: return 420; } return 1; }
void dos_video_init(void) { /* Change video settings if screen expansion is enabled */ if(option.expand) { option.video_driver = GFX_AUTODETECT; option.video_width = (IS_GG) ? 400 : 512; option.video_height = (IS_GG) ? 300 : 384; } /* Double requested height if scanlines are being used and screen expansion is disabled */ if((option.scanlines == 1) && (option.expand == 0)) { option.video_height *= 2; } /* Change video settings if tweaked display is enabled */ if(option.tweak) { option.video_driver = GFX_VGA; option.video_depth = 8; option.video_width = 320; option.video_height = 200; } /* Attempt to set graphics mode */ set_color_depth(option.video_depth); if(set_gfx_mode(option.video_driver, option.video_width, option.video_height, 0, 0) != 0) { printf("Error: %s\n", allegro_error); exit(1); } /* Clear palette and display */ memcpy(sms_pal, black_palette, sizeof(PALETTE)); sms_pal[0xFE].r = sms_pal[0xFE].g = sms_pal[0xFE].b = 0xFF; set_palette(sms_pal); clear(screen); /* Use vertical stretching if screen expansion is enabled, VGA expansion is disabled, and scanlines are disabled */ if((option.expand == 1) && (option.no_vga == 0) && (option.scanlines == 0)) { outp(0x3D4, 0x09); outp(0x3D5, (inp(0x3D5) & 0xE0) | 0x03); } /* Force overscan color to be black */ if(option.video_depth == 8) { inp(0x3DA); outp(0x3C0, 0x31); outp(0x3C0, 0xFF); clear_to_color(screen, 0xFF); } /* Tweak display accordingly */ if(option.tweak) { int i, j = IS_GG ? 1 : 0; /* Disable CRTC write protect */ outp(0x3D4, 0x11); outp(0x3D5, inp(0x3D5) & 0x7F); /* Load CRTC parameters */ for(i = 0; i <= 0x0D; i++) outpw(0x3D4, twktbl[j][i]); /* Enable CRTC write protect */ outp(0x3D4, 0x11); outp(0x3D5, inp(0x3D5) | 0x80); /* Set clocking mode register */ outp(0x3C2, twktbl[j][0x0E]); /* Set miscellaneous output register */ outpw(0x3C4, twktbl[j][0x0F]); } }
int main() { int exit_flag = 0, i, j; MAT16F tmat; int vnum, node_num; VERTEX *map_vertex; STATIC_BSP_NODE *tree; init(); load_static_bsp("map.bsp", &map_vertex, &vnum, &tree, &node_num); printf("Vertex Number: %d.\nNode Number: %d.\n", vnum, node_num); LOCK_VARIABLE(fps); LOCK_VARIABLE(frame_count); LOCK_FUNCTION(update_fps); install_int(update_fps, 1000); float frame = 0.0; VEC3F view_volume[5]; VEC3F cam_pos = vec3f(0.0, 3.0, 0.0), cam_dir, cam_dir_normal, cam_ang = vec3f(0.0, 0.0, 0.0); while(!exit_flag) { int mx, my; get_mouse_mickeys(&mx, &my); position_mouse(SCREEN_W / 2, SCREEN_H / 2); cam_ang.x += my * 0.001; cam_ang.y -= mx * 0.001; cam_dir.x = CAM_SPEED * cos(0.5 * M_PI + cam_ang.y); cam_dir.y = CAM_SPEED * cos(0.5 * M_PI + cam_ang.x); cam_dir.z = CAM_SPEED * sin(0.5 * M_PI + cam_ang.y); cam_dir_normal = vec3f(-cam_dir.z, 0.0, cam_dir.x); if(key[KEY_ESC]) { exit_flag = 1; } if(key[KEY_W]) { cam_pos = VEC3F_SUM(cam_pos, cam_dir); } if(key[KEY_S]) { cam_pos = VEC3F_DIFF(cam_pos, cam_dir); } if(key[KEY_A]) { cam_pos = VEC3F_SUM(cam_pos, cam_dir_normal); } if(key[KEY_D]) { cam_pos = VEC3F_DIFF(cam_pos, cam_dir_normal); } set_fov(90.0); if(mouse_b > 1) set_fov(30.0); build_view_volume(view_volume); reset_mat16f(tmat); rotate_x_mat16f(tmat, cam_ang.x); rotate_y_mat16f(tmat, cam_ang.y); rotate_z_mat16f(tmat, 0.0); translate_mat16f(tmat, cam_pos.x, cam_pos.y, cam_pos.z); for(i = 0; i < 5; i++) transform_vec3f(&view_volume[i], view_volume[i], tmat); reset_mat16f(tmat); translate_mat16f(tmat, -cam_pos.x, -cam_pos.y, -cam_pos.z); rotate_z_mat16f(tmat, 0.0); rotate_y_mat16f(tmat, -cam_ang.y); rotate_x_mat16f(tmat, -cam_ang.x); for(i = 0; i < vnum; i++) { transform_vec3f(&map_vertex[i].trans, map_vertex[i].object, tmat); project_vertex(&map_vertex[i]); } for(i = 0; i < node_num; i++) tree[i].flag = 0; int checks = 0; mark_nodes_inside_volume(tree, 0, map_vertex, view_volume, 5, &checks); int count = 0; for(i = 0; i < node_num; i++) if(tree[i].flag == 1) count++; clear_to_color(buffer, 0); clear_to_color(BASE_INT_z_buffer, BASE_INT_z_buffer_precision); traverse_tree(tree, 0, cam_pos, map_vertex, -1); textprintf_ex(buffer, font, 10, 10, makecol(255, 255, 255), 0, "FPS: %d", fps); textprintf_ex(buffer, font, 10, 10, makecol(255, 255, 255), 0, "FPS: %d", fps); textprintf_ex(buffer, font, 10, 20, makecol(255, 255, 255), 0, "Rendered: %d of nodes, %d of faces.", (int)((float)checks / (float)node_num * 100.0), (int)((float)count / (float)node_num * 100.0)); //textprintf_ex(buffer, font, 10, 20, makecol(255, 255, 255), 0, "%d", checks); blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); frame_count++; } deinit_engine(); for(i = 0; i < node_num; i++) free(tree[i].poly.vind); free(tree); free(map_vertex); return 0; }
int main(void) { int c; /* character from keyboard */ int i, j, k; /* number of tasks created */ double a; /* temporary variable */ int h; /* temporary variable */ int ntasks = 0; /* total number of created tasks*/ int last_proc = 0; /* last assigned processor */ int max_proc = ptask_getnumcores(); /* max number of procs */ init(); a = 2. * G * (float)TOP; for (i = 0; i < MAX_TASKS; i++) v0[i] = sqrt(a); i = 0; do { k = 0; if (keypressed()) { c = readkey(); k = c >> 8; } if ((ntasks == 0) && (k == KEY_SPACE)) { clear_to_color(screen, BGC); rect(screen, XMIN - L - 1, BASE - 1, XMAX + L + 1, TOP + BASE + L + 1, 14); } if ((ntasks < MAX_TASKS) && (k == KEY_SPACE)) { tpars params = TASK_SPEC_DFL; params.period = tspec_from(PER, MILLI); params.rdline = tspec_from(DREL, MILLI); params.priority = PRIO - i; params.measure_flag = 1; params.act_flag = NOW; /* a round robin assignment */ params.processor = last_proc++; if (last_proc >= max_proc) last_proc = 0; /** i = task_create(palla, PER, DREL, PRIO-i, NOW); */ i = ptask_create_param(palla, ¶ms); if (i != -1) { printf("Task %d created and activated\n", i); ntasks++; } else { allegro_exit(); printf("Error in creating task!\n"); exit(-1); } } if ((k >= KEY_0) && (k <= KEY_9)) { a = 2. * G * (float)TOP; pthread_mutex_lock(&mxv); v0[k - KEY_0] = sqrt(a); pthread_mutex_unlock(&mxv); } if ((k == KEY_O) && (ntasks > 9)) { for (j = 10; j < ntasks; j++) { h = rand() % (TOP - BASE); a = 2. * G * (float)h; pthread_mutex_lock(&mxv); v0[j] = sqrt(a); pthread_mutex_unlock(&mxv); } } if (k == KEY_A) { for (j = 0; j < ntasks; j++) { h = rand() % (TOP - BASE); a = 2. * G * (float)h; pthread_mutex_lock(&mxv); v0[j] = sqrt(a); pthread_mutex_unlock(&mxv); } } /* Printing deadline misses TO BE DONE for (j=0; j<ntasks; j++) { sprintf(s, "%d", task_dmiss(j)); textout_ex(screen, font, s, 50+j*48, 450, 7, 0); } */ } while (k != KEY_ESC); printf("Now printing the stats\n"); for (j = 0; j < ntasks; j++) { tspec wcet = ptask_get_wcet(j); tspec acet = ptask_get_avg(j); printf("TASK %d: WCET = %ld\t ACET = %ld\t NINST=%d\n", j, tspec_to(&wcet, MICRO), tspec_to(&acet, MICRO), ptask_get_numinstances(j)); } printf("End of statistics\n"); allegro_exit(); return 0; }
void print_grid(int policy, int prot) { int i, x, y, k; int lev; int at, dl; char buf[50]; /*------------------------------------------------------*/ /* Draw header */ /*------------------------------------------------------*/ clear_to_color(screen, BGC); rect(screen, XMIN+30, YMIN+1, XMAX-30, 40, 4); if (policy == SCHED_FIFO) sprintf(buf, "TASK schedule produced by SCHED_FIFO"); if (policy == SCHED_RR) sprintf(buf, "TASK schedule produced by SCHED_RR"); if (policy == SCHED_OTHER) sprintf(buf, "TASK schedule produced by SCHED_OTHER"); textout_centre_ex(screen, font, buf, 320, 10, 14, 0); if (prot == PIP) sprintf(buf, "+ PIP"); if (prot == PCP) sprintf(buf, "+ PCP"); if (prot != NOP) textout_centre_ex(screen, font, buf, 488, 10, 14, 0); textout_centre_ex(screen, font, "(ESC to exit)", 320, 30, 3, 0); sprintf(buf, "Time scale: %4.1f", scale); textout_ex(screen, font, buf, XMIN+40, 30, 7, 0); /*------------------------------------------------------*/ /* Draw grid */ /*------------------------------------------------------*/ for (x=OFFSET; x<XMAX; x+=DXGRID/scale) for (y=LEV0; y<LEV0+DLEV*(nt-1); y+=DYGRID) putpixel(screen, x, y, GRIDCOL); /*------------------------------------------------------*/ /* Draw task timelines */ /*------------------------------------------------------*/ textout_ex(screen, font, "MAIN", 10, LEV0+5, MAINCOL, 0); line(screen, OFFSET, LEV0, XMAX, LEV0, TLCOL); line(screen, OFFSET, LEV0, OFFSET, LEV0-10, TLCOL); for (i=1; i<nt; i++) { lev = LEV0 + DLEV*i; at = OFFSET; sprintf(buf, "T%d", i); textout_ex(screen, font, buf, 10, lev-8, TLCOL, 0); line(screen, OFFSET, lev, XMAX, lev, TLCOL); k = 0; do { at = k * period[i]; x = OFFSET + at/scale; if (x < XMAX) line(screen, x, lev, x, lev-20, TLCOL); dl = at + dline[i]; x = OFFSET + dl/scale; if (x < XMAX) { line(screen, x, lev-1, x, lev-15, DLCOL); line(screen, x, lev-1, x-1, lev-5, DLCOL); line(screen, x, lev-1, x+1, lev-5, DLCOL); } k++; } while (x < XMAX); } }
void InputDeviceSingleton::BeginJoystickCalibration() { int msgColor = makecol(255, 255, 255); int bgColor = makecol(0, 0, 255); // for each joystick, run a calibration sequence for (int index = 0; index < num_joysticks; index++) { // clear the screen clear_to_color(screen, bgColor); // while the jostick needs to be calibrated while (joy[index].flags & JOYFLAG_CALIBRATE) { // get the calibration message const char* message = calibrate_joystick_name(index); // show the message on the screen textprintf_centre_ex(screen, font, SCREEN_W / 2, SCREEN_H / 2, msgColor, -1, "%s, and press a key.", message); // read a key readkey(); // try to calibrate the joystick if (0 != calibrate_joystick(index)) { // show a message that we failed textprintf_centre_ex(screen, font, SCREEN_W / 2, 64 + (SCREEN_H / 2), msgColor, -1, "Could not calibrate the Joystick!"); // read a key readkey(); // and bail with a fatal error LogFatal("Could not calibrate the joystick!"); } } } // try to save the calibration data to a file if (0 != save_joystick_data("joysettings.dat")) { // clear the screen to red clear_to_color(screen, makecol(255, 0, 0)); // show a message on the screen textprintf_centre_ex(screen, font, SCREEN_W / 2, SCREEN_H / 2, makecol(255, 255, 0), -1, "Joystick Calibration data file could not be saved! Press a key to exit the program."); // read a key readkey(); LogFatal("Joystick Calibration data file could not be saved! Program will now exit!"); } // clear the screen clear_to_color(screen, bgColor); // show a message on the screen textprintf_centre_ex(screen, font, SCREEN_W / 2, SCREEN_H / 2, msgColor, -1, "Joysticks have been calibrated. Press a key to exit the program."); // read a key readkey(); // log a message that the joysticks were calibrated LogMessage("Joysticks calibrated! Program Exiting..."); exit(1); }
static void test_key_map(void) { int i, k, u; static int key_was_pressed[KEY_MAX + 1] = {0}; static int key_is_pressed[KEY_MAX + 1] = {0}; static char *welcome[] = { "Key that is pressed now is marked with red", "Key that was pressed is marked with yellow", "Press mouse button or Escape to exit test", 0 }; /* Clear screen and output prompt. */ clear_to_color(screen, white); for (i = 0; welcome[i] != 0; i++) textout_ex(screen, font, welcome[i], 8, i * 8 + 8, black, -1); clear_to_color(screen, white); for (i = 0; i < KEY_MAX; i++) textprintf_ex(screen, font, 32 + (i % 4) * 160, 32 + (i / 4) * 14, black, -1, "%s", scancode_to_name (i)); do { poll_keyboard(); poll_mouse(); } while ((key[KEY_ESC]) || (mouse_b)); do { while (keypressed()) { u = ureadkey (&k); textprintf_centre_ex (screen, font, SCREEN_W / 2, 8, red, white, "> %c <", u); } poll_keyboard(); poll_mouse(); for (i = 0; i < KEY_MAX; i++) { if (key[i]) key_was_pressed[i] = key_is_pressed[i] = 1; else key_is_pressed[i] = 0; } for (i = 0; i < KEY_MAX; i++) { int x = 16 + (i % 4) * 160; int y = 32 + (i / 4) * 14; if (key_is_pressed[i]) rectfill(screen, x, y, x + 7, y + 7, red); else if (key_was_pressed[i]) rectfill(screen, x, y, x + 7, y + 7, yellow); else rectfill(screen, x, y, x + 7, y + 7, white); } rest(1); } while ((!key[KEY_ESC]) && (!mouse_b)); do { poll_keyboard(); poll_mouse(); } while ((key[KEY_ESC]) || (mouse_b)); clear_keybuf(); }
int menu(char *kategoria, int *liczba_pytan) { BITMAP *tlo = prawko_load_bitmap("grafika/tlo.bmp"); BITMAP *kategoria_bmp = create_bitmap(1, 1); BITMAP *dodatek = create_bitmap(1, 1); BITMAP *pytania = create_bitmap(1, 1); BITMAP *pytania_statyczne = create_bitmap(1, 1); BITMAP *losowe = prawko_load_bitmap("grafika/losowe.bmp"); BITMAP *egzamin = prawko_load_bitmap("grafika/egzamin.bmp"); BITMAP *oprogramie = prawko_load_bitmap("grafika/oprogramie.bmp"); BITMAP *wyjscie = prawko_load_bitmap("grafika/wyjscie.bmp"); static int aktywny = 0; int wczytaj = 2; while(TRUE) { if(wczytaj == 1 || wczytaj == 2) { if(wczytaj == 1) { destroy_bitmap(kategoria_bmp); destroy_bitmap(dodatek); destroy_bitmap(pytania); destroy_bitmap(pytania_statyczne); } switch(*kategoria) { case 'a': kategoria_bmp = prawko_load_bitmap("grafika/A/kategoria.bmp"); dodatek = prawko_load_bitmap("grafika/A/dodatek.bmp"); pytania = prawko_load_bitmap("grafika/A/pytania.bmp"); pytania_statyczne = prawko_load_bitmap("grafika/A/pytania_statyczne.bmp"); wczytaj = 0; *liczba_pytan = 60; break; case 'b': kategoria_bmp = prawko_load_bitmap("grafika/B/kategoria.bmp"); dodatek = prawko_load_bitmap("grafika/B/dodatek.bmp"); pytania = prawko_load_bitmap("grafika/B/pytania.bmp"); pytania_statyczne = prawko_load_bitmap("grafika/B/pytania_statyczne.bmp"); wczytaj = 0; *liczba_pytan = 526; break; case 'c': kategoria_bmp = prawko_load_bitmap("grafika/C/kategoria.bmp"); dodatek = prawko_load_bitmap("grafika/C/dodatek.bmp"); pytania = prawko_load_bitmap("grafika/C/pytania.bmp"); pytania_statyczne = prawko_load_bitmap("grafika/C/pytania_statyczne.bmp"); wczytaj = 0; *liczba_pytan = 193; break; case 'd': kategoria_bmp = prawko_load_bitmap("grafika/D/kategoria.bmp"); dodatek = prawko_load_bitmap("grafika/D/dodatek.bmp"); pytania = prawko_load_bitmap("grafika/D/pytania.bmp"); pytania_statyczne = prawko_load_bitmap("grafika/D/pytania_statyczne.bmp"); wczytaj = 0; *liczba_pytan = 192; break; case 't': kategoria_bmp = prawko_load_bitmap("grafika/T/kategoria.bmp"); dodatek = prawko_load_bitmap("grafika/T/dodatek.bmp"); pytania = prawko_load_bitmap("grafika/T/pytania.bmp"); pytania_statyczne = prawko_load_bitmap("grafika/T/pytania_statyczne.bmp"); wczytaj = 0; *liczba_pytan = 61; break; } } clear_to_color(bufor_glowny, COLOR_TLA); blit(tlo, bufor_glowny, 0, 0, 0, 0, tlo->w, tlo->h); blit(kategoria_bmp, bufor_glowny, 0, 0, 52, 36, kategoria_bmp->w, kategoria_bmp->h); blit(dodatek, bufor_glowny, 0, 0, 300, 149, dodatek->w, dodatek->h); blit(pytania_statyczne, bufor_glowny, 0, 0, 288, 52, pytania_statyczne->w, pytania_statyczne->h); if(aktywny == 0) blit(pytania, bufor_glowny, 0, 0, 288, 52, pytania->w, pytania->h); else if(aktywny == 1) blit(losowe, bufor_glowny, 0, 0, 244, 91, losowe->w, losowe->h); else if(aktywny == 2) blit(egzamin, bufor_glowny, 0, 0, 197, 132, egzamin->w, egzamin->h); else if(aktywny == 3) blit(oprogramie, bufor_glowny, 0, 0, 148, 171, oprogramie->w, oprogramie->h); else if(aktywny == 4) blit(wyjscie, bufor_glowny, 0, 0, 106, 209, wyjscie->w, wyjscie->h); if(key[KEY_UP]) { if(aktywny-1 > -1) aktywny--; else aktywny = 4; } else if(key[KEY_DOWN]) { if(aktywny+1 < 5) aktywny++; else aktywny = 0; } else if(key[KEY_RIGHT]) { if((*kategoria)+1 < 'a'+4) { (*kategoria)++; wczytaj = 1; } else if(*kategoria == 'd') { *kategoria = 't'; wczytaj = 1; } } else if(key[KEY_LSHIFT]) { pomoc_menu(*liczba_pytan); } else if(key[KEY_LEFT]) { if(*kategoria == 't') { *kategoria = 'd'; wczytaj = 1; } else if((*kategoria)-1 > 'a'-1) { (*kategoria)--; wczytaj = 1; } } else if(key[KEY_SPACE] || key[KEY_ENTER]) { break; } blit(przycisk_ln, bufor_glowny, 0, 0, 10, 243, przycisk_ln->w, przycisk_ln->h); textprintf_ex(bufor_glowny, font, 10+przycisk_l->w, 249, makecol(255, 255, 255), -1, "Pomoc"); blit(bufor_glowny, screen, 0, 0, 0, 0, bufor_glowny->w, bufor_glowny->h); clear_key(); keypressed(); rest(60); } destroy_bitmap(tlo); destroy_bitmap(kategoria_bmp); destroy_bitmap(dodatek); destroy_bitmap(pytania); destroy_bitmap(pytania_statyczne); destroy_bitmap(losowe); destroy_bitmap(egzamin); destroy_bitmap(oprogramie); destroy_bitmap(wyjscie); return aktywny; }
int main() { int exit = 0, a_flag = -1;//, val = 0; int vnum, snum, i; VEC2F *map_vertex; WALL_SEGMENT *map_segment; NODE *head = NULL; VEC2F p = vec2f(0.0, 0.0), v; float alpha = 0.0; load_map("map.txt", &map_vertex, &map_segment, &vnum, &snum, 1.0); //realloc_bullshit(&map_vertex, 20); //map_vertex[16] = vec2f(20.0, 20.0); init(); head = (NODE *)malloc(sizeof(NODE)); head->val = val; head->a = map_segment[0].a; head->b = map_segment[0].b; head->n = NORMALIZED_NORMAL_VEC2F(map_vertex[map_segment[0].a], map_vertex[map_segment[0].b]); head->parent = NULL; head->left = NULL; head->right = NULL; val++; for(i = 1; i < snum; i++) { add_node(head, &val, map_segment[i].a, map_segment[i].b, &map_vertex, &vnum); val++; } //compile_map(head, map, snum); while(!exit) { if(key[KEY_ESC]) { exit = 1; } if(key[KEY_SPACE]) { printf("\n"); key[KEY_SPACE] = 0; } if(key[KEY_LEFT]) { alpha -= 0.03; } if(key[KEY_RIGHT]) { alpha += 0.03; } if(key[KEY_W]) { p.y -= SPEED; } if(key[KEY_S]) { p.y += SPEED; } if(key[KEY_A]) { p.x -= SPEED; } if(key[KEY_D]) { p.x += SPEED; } v = vec2f(20.0 * cos(alpha), 20.0 * sin(alpha)); clear_to_color(buffer, makecol(128, 128, 128)); //draw_tree(buffer, p, v, head, 320, 240, 10, makecol(128, 0, 0)); traverse_tree(buffer, head, p, v, map_vertex); printf("\n\n"); /* if(a_flag == 0) vec2f_line(buffer, a, b, makecol(0, 0, 128)); if(a_flag == 1) ve2f_line(buffer, a, vector(mouse_x, mouse_y), makecol(0, 0, 128)); circlefill(buffer, mouse_x, mouse_y, 2, 0); vec2f_point(buffer, p, 10, makecol(0, 128, 0)); */ vec2f_line(buffer, p, VEC2F_SUM(p, v), makecol(0, 0, 0)); vec2f_line(buffer, p, VEC2F_SUM(p, USCALE_VEC2F(VEC2F_NORMAL(v), 200.0)), makecol(0, 0, 0)); vec2f_line(buffer, p, VEC2F_SUM(p, USCALE_VEC2F(VEC2F_NORMAL(v), -200.0)), makecol(0, 0, 0)); blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); } free(map_vertex); free(map_segment); destroy_tree(head); destroy_bitmap(buffer); return 0; }
void CustomCircle::reset(void) { On = false; clear_to_color(bmp, TRANSPARENT); }
void S9xGraphicsMode () { if (in_text_mode) { if (mode < 0) { if (Settings.SixteenBit) { if (Settings.SupportHiRes || interpolate) mode = 10; else mode = 9; } else { if (Settings.SupportHiRes) mode = 3; else mode = 2; } } int ret; do { screen_width = modes [mode].width; screen_height = modes [mode].height; set_color_depth (Settings.SixteenBit ? 16: 8); if (modes [mode].mode == GFX_VGA) ret = set_gfx_mode (modes [mode].mode, 320, 200, 0, 0); else ret = set_gfx_mode (modes [mode].mode, modes [mode].width, modes [mode].height, 0, 0); } while (ret < 0 && ++mode < COUNT(modes)); planar = modes [mode].mode == GFX_MODEX; if (ret < 0) { fprintf (stderr, "Unable to switch to requested screen mode/resolution:\n%s\n", allegro_error); S9xExit (); } if (modes [mode].mode == GFX_VGA && screen_width == 256) { outRegArray (scr256x256, sizeof (scr256x256) / sizeof (Register)); screen->w = screen->cr = 256; screen->h = screen->cb = 256; for (int i = 1; i < 256; i++) screen->line[i] = screen->line[i - 1] + 256; } clear_to_color (screen, 0); if (install_keyboard ()) { set_gfx_mode (GFX_TEXT, 0, 0, 0, 0); fprintf (stdout, "Keyboard initialisation failed.\n"); S9xExit (); } if (!install_mouse ()) { mouse_installed = TRUE; set_mouse_range (0, 0, screen_width, screen_height); position_mouse (screen_width / 2, screen_height / 2); prev_mouse_x = mouse_x; prev_mouse_y = mouse_y; } else mouse_installed = FALSE; in_text_mode = FALSE; } }
void startup_menu(void) { reset_menu_palette(); menu_select = 0; key_wait = 30; // int counter; menu_counter = 0; counter2 = 0; arena.difficulty = 0; int y1 = 170; int y2 = 190 + menu_select * 30; int y3 = 218 + menu_select * 30; int y4 = 218 + menu_select * 30; int anykey = 0; int i; //#define TEST_MUSIC #ifdef TEST_MUSIC arena.level = 3; init_beat_new_level(); #endif init_menu_circles(); while (TRUE) { #ifdef TEST_MUSIC run_beat(); #endif clear_to_color(display, COL_BACK1); run_menu_background(); menu_counter += 4; if (menu_counter >= 40) menu_counter = 0; counter2 ++; if (counter2 >= 256) counter2 = 0; // textprintf_centre_ex(display, font, 300, 190, -1, -1, "W H I T E B U T T E R F L Y"); draw_rle_sprite(display, white_RLE, 150, 150); int my = 300; y1 = my - 23; y2 = my - 10 + menu_select * 30; y3 = my + 19 + menu_select * 30; y4 = my + 150; // rectfill(display, 370, y1, 600, y2, COL_COL1); TRANS_MODE rectfill(display, 370, y2 + 9, 640, y3 - 2, TRANS_BLUE3); rect(display, 368, y2 + 7, 641, y3 - 0, TRANS_BLUE3); END_TRANS // rectfill(display, 370, y3, 600, y4, TRANS_DGREEN); textprintf_ex(display, font, 400, my, -1, -1, "START GAME"); switch(arena.difficulty) { case 0: textprintf_ex(display, font, 400, my + 30, -1, -1, "DIFFICULTY - NORMAL"); break; case 1: textprintf_ex(display, font, 400, my + 30, -1, -1, "DIFFICULTY - HARD"); break; case 2: textprintf_ex(display, font, 400, my + 30, -1, -1, "DIFFICULTY - PUNISHMENT"); break; } // textprintf_ex(display [2], font, 400, 260, -1, -1, "STAGE - %i", arena.starting_level); textprintf_ex(display, font, 400, my + 90, -1, -1, "SET KEYS"); textprintf_ex(display, font, 400, my + 120, -1, -1, "OPTIONS"); textprintf_ex(display, font, 400, my + 150, -1, -1, "EXIT"); // textprintf_ex(display, font, 40, 10, -1, -1, "%i", joy[0].stick[options.joy_stick].axis[0].pos); // textprintf_ex(display, font, 40, 30, -1, -1, "%i", joy[0].stick[options.joy_stick].axis[1].pos); /* if (options.joystick) textprintf_ex(display, font, 400, my + 120, -1, -1, "CALIBRATE JOYSTICK"); else { textprintf_ex(display, font, 400, my + 120, -1, -1, "NO JOYSTICK"); drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); rectfill(display, 399, my + 110, 530, my + 135, CONVERT_WHITE_TO_GREY); drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0); } */ if (options.joystick) { if (options.key_or_joy == 1) textprintf_ex(display, font, 400, my + 60, -1, -1, "CONTROLS - JOYSTICK"); else textprintf_ex(display, font, 400, my + 60, -1, -1, "CONTROLS - KEYBOARD"); } else { textprintf_ex(display, font, 400, my + 60, -1, -1, "NO JOYSTICK"); drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); rectfill(display, 399, my + 50, 530, my + 75, CONVERT_WHITE_TO_GREY); drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0); } // textprintf_ex(display, font, 5, 5, -1, -1, "%i", any_joystick_input()); my = 330; y2 = my + 7 + arena.just_got_highscore * 30; y3 = my + 29 + arena.just_got_highscore * 30; if (arena.just_got_highscore > 0) { rectfill(display, 0, y2 - 5, 250, y3, COL_COL3); rect(display, -1, y2 - 5 - 2, 250 + 2, y3 + 2, COL_COL4); } // textprintf_right_ex(display, font, 137, my, -1, -1, "HIGH"); // textprintf_ex(display, font, 157, my, -1, -1, "SCORES"); textprintf_centre_ex(display, font, 147, my, -1, -1, "HIGHSCORES"); textprintf_right_ex(display, font, 137, my + 40, -1, -1, "NORMAL"); textprintf_ex(display, font, 157, my + 40, -1, -1, "%i", options.highscore [0]); textprintf_right_ex(display, font, 137, my + 70, -1, -1, "HARD"); textprintf_ex(display, font, 157, my + 70, -1, -1, "%i", options.highscore [1]); textprintf_right_ex(display, font, 137, my + 100, -1, -1, "PUNISHMENT"); textprintf_ex(display, font, 157, my + 100, -1, -1, "%i", options.highscore [2]); textprintf_right_ex(display, font, 600, 570, -1, -1, "COPYRIGHT 2009 LINLEY HENZELL"); // should print last score here... anykey = 0; for (i = KEY_A; i < KEY_CAPSLOCK + 1; i ++) { if (key [i]) { anykey = 1; } } if (anykey == 0 && (options.joystick == 0 || any_joystick_input() == 0)) key_wait = 0; if (key_wait == 0) { if (menu_command(MC_UP)) { menu_select --; if (menu_select < 0) menu_select = MENU_EXIT; if (menu_select == MENU_JOY_OR_KEYS && options.joystick == 0) menu_select = MENU_JOY_OR_KEYS - 1; key_wait = 7; } if (menu_command(MC_DOWN)) { menu_select ++; if (menu_select > MENU_EXIT) menu_select = 0; if (menu_select == MENU_JOY_OR_KEYS && options.joystick == 0) menu_select = MENU_KEYS; key_wait = 7; } if (menu_command(MC_LEFT)) { // if (menu_select == 2) // arena.starting_level = 1; if (menu_select == MENU_JOY_OR_KEYS) { if (options.key_or_joy == 0) options.key_or_joy = 1; else options.key_or_joy = 0; } if (menu_select == MENU_DIFFICULTY) { arena.difficulty --; if (arena.difficulty < 0) arena.difficulty = 0; } key_wait = 7; } if (menu_command(MC_RIGHT)) { // if (menu_select == 2) // arena.starting_level = 2; if (menu_select == MENU_JOY_OR_KEYS) { if (options.key_or_joy == 0) options.key_or_joy = 1; else options.key_or_joy = 0; } if (menu_select == MENU_DIFFICULTY) { arena.difficulty ++; if (arena.difficulty > 2) arena.difficulty = 2; } key_wait = 7; } // if (key [KEY_ESC]) // exit(0); if (menu_command(MC_SELECT)) { if (menu_select == MENU_EXIT) { goodbye_menu_circles(); return; } if (menu_select == MENU_KEYS) { key_wait = 10; define_keys(); key_wait = 10; } if (menu_select == MENU_OPTIONS) { key_wait = 10; set_options(); key_wait = 10; } /* if (menu_select == MENU_CALIBRATE) { jstick_calibrate(); key_wait = 20; ticked = 0; }*/ if (menu_select == MENU_START) { arena.level = 1;//arena.starting_level; ticked = 0; key_wait = 30; if (ship_select() == 1) { vsync(); // clear_bitmap(screen); // clear_bitmap(display); player.type = PTYPE_BASIC; // player.type = PTYPE_BOMBER; // player.type = PTYPE_ANENOME; // player.type = PTYPE_HAND; player.weapon_level = 0; int ship_select = select_a_ship(); if (ship_select != -1) { switch(ship_select) { default: case 0: player.type = PTYPE_BASIC; break; case 1: player.type = PTYPE_ANENOME; break; case 2: player.type = PTYPE_BOMBER; break; case 3: player.type = PTYPE_HAND; break; case 4: player.type = PTYPE_SQUID; break; } if (arena.level == 1) arena.from_start = 1; else arena.from_start = 0; arena.cleared = 0; arena.unlocked = 0; menu_counter = 0; goodbye_menu_circles(); new_game(); game_loop(); if (arena.level == 4) congratulations(); arena.target_palette = PAL_MENU; arena.shift_palette = 2; init_menu_circles(); // reset_menu_palette(); key_wait = 10; // was 1 // flower_dir *= -1; ticked = 0; } } else key_wait = 20; } else key_wait = 20; } } else key_wait --; do { thing ++; } while (ticked == 0); ticked = 0; if (arena.shift_palette > 0 && menu_counter % 12 == 0) { run_palette_shift(); build_new_palette(0, 0, 0, 0); set_palette(palet); if (arena.shift_palette == 1) arena.shift_palette = 0; } vsync(); blit(display, screen, 0, 0, 100, 0, 600, 600); }; }
int main() { init(); set_window_title("Team27, inc - Innocent Snake"); srand((unsigned)time(NULL)); //kondisi map awal int map[SIZE_Y][SIZE_X] = {-1,-1,-1,-1,-1,-1,-1, 0, 0, 0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 0, 0, 0,-1,-1,-1,-1, 0, 0, 0,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, -1, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, -1, 0, 0, 0,-1,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, -1, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, -1, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, -1, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1,-1,-1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0,-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0,-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0,-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1,-1,-1,-1,-1, 0, 0, 0,-1,-1,-1,-1,-1,-1, 0, 0,-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0,-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0,-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0,-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0,-1, -1, 0, 0, 0, 0, 0, 0,-1,-1,-1,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, -1,-1,-1,-1,-1,-1,-1, 0, 0, 0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 0, 0, 0,-1,-1,-1,-1, 0, 0, 0,-1,-1,-1,-1,-1,-1,-1,-1,-1 }; int counter = 0; int posX, posY; int loaded = 0; int x_his, y_his; int i, j, moveX = 1, moveY = 0; BITMAP *buffer = create_bitmap(SCREEN_W, SCREEN_H); BITMAP *path = create_bitmap(OBJECT_SIZE, OBJECT_SIZE); BITMAP *wall = load_bitmap("wall.bmp", NULL); BITMAP *head = load_bitmap("head.bmp", NULL); BITMAP *snake_body = load_bitmap("body.bmp", NULL); BITMAP *eat = create_bitmap(OBJECT_SIZE, OBJECT_SIZE); BITMAP *bg_map = create_bitmap(SCREEN_W, SCREEN_H); SNAKE *snake = NULL; SNAKE *pointer = NULL; clear_to_color(path, makecol(255, 255, 255)); //jalan berwarna putih clear_to_color(eat, makecol(255, 255, 255)); //makanan backgroundnya putih circlefill(eat, OBJECT_SIZE/2, OBJECT_SIZE/2, OBJECT_SIZE/2 - 4, makecol(255, 0, 0)); //makanan berwarna merah //membuat map snake di bitmap for(i=0; i<SIZE_Y; i++) { for(j=0; j<SIZE_X; j++) { switch(map[i][j]) { case PATH : draw_sprite(bg_map, path, j*OBJECT_SIZE, i*OBJECT_SIZE); break; case WALL : draw_sprite(bg_map, wall, j*OBJECT_SIZE, i*OBJECT_SIZE); break; } } } //inisialisasi awal posisi snake add_body(&snake, 3, 1, map); map[snake->y][snake->x] = HEAD; add_body(&snake, 2, 1, map); add_body(&snake, 1, 1, map); set_keyboard_rate(10, 10); while (!key[KEY_ESC]) { //deteksi apakah sudah ada makanan di map if(loaded==0) { do { posX = rand()%(SIZE_X-1) + 1; posY = rand()%(SIZE_Y-1) + 1; } while(map[posY][posX] != PATH); map[posY][posX] = EAT; loaded = 1; } //deteksi keyboard yang ditekan dan mengubah arah gerak snake if(counter==5) { if(key[KEY_UP] && moveY==0) { moveX=0; moveY=-1; clear_keybuf(); } else if(key[KEY_DOWN] && moveY==0) { moveX=0; moveY=1; clear_keybuf(); } else if(key[KEY_LEFT] && moveX==0) { moveX=-1; moveY=0; clear_keybuf(); } else if(key[KEY_RIGHT] && moveX==0) { moveX=1; moveY=0; clear_keybuf(); } x_his = snake->x; y_his = snake->y; //kalau menabrak sesuatu maka keluar if(!move_snake(snake, moveX, moveY, map)) break; //jika bertemu makanan maka tambah badan if(map[posY][posX] != EAT) { add_body(&snake, x_his, y_his, map); loaded = 0; } counter=0; } counter++; //tempelkan semua obyek ke buffer draw_sprite(buffer, bg_map, 0, 0); draw_sprite(buffer, eat, posX*OBJECT_SIZE, posY*OBJECT_SIZE); for(pointer = snake; pointer != NULL; pointer = pointer->next) { switch(map[pointer->y][pointer->x]) { case BODY : draw_sprite(buffer, snake_body, pointer->x*OBJECT_SIZE, pointer->y*OBJECT_SIZE); break; case HEAD : draw_sprite(buffer, head, pointer->x*OBJECT_SIZE, pointer->y*OBJECT_SIZE); break; } } //tampilkan buffer ke screen draw_sprite(screen, buffer, 0, 0); clear_bitmap(buffer); rest(10); } //destroy semua bitmap destroy_bitmap(head); destroy_bitmap(buffer); destroy_bitmap(path); destroy_bitmap(wall); destroy_bitmap(snake_body); destroy_bitmap(eat); deinit(); return 0; }
BITMAP *IAGSEngine::CreateBlankBitmap (int32 width, int32 height, int32 coldep) { BITMAP *tempb = create_bitmap_ex(coldep, width, height); clear_to_color(tempb, bitmap_mask_color(tempb)); return tempb; }
int main(int argc, char *argv[]) { int i, idx, color_depth = -1; if (argc >= 2) color_depth = atoi(argv[1]); if (color_depth != 16 && color_depth != 24 && color_depth != 32) { printf("Usage: test [color_depth]\n"); return -1; } allegro_init(); install_keyboard(); set_color_depth(color_depth); if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0) != 0) return -1; backbuffer = create_bitmap(SCREEN_W, SCREEN_H); BITMAP *backbuffer1 = create_bitmap(SCREEN_W, SCREEN_H); BITMAP *backbuffer2 = create_bitmap(SCREEN_W, SCREEN_H); // Load fire sprites (alpha transparency used) fire_ex = load_bitmap_alpha("fire.tga", true); for (int idx = 0; idx < SPRITE_COUNT; idx++) { i = idx % 8; fire_ex_bitmaps[idx] = create_sub_bitmap(fire_ex, (i % 4) * 33, (i / 4) * 41, 32, 40); fire_ex_rle_sprites[idx] = get_rle_sprite(fire_ex_bitmaps[i]); fire_ex_alpha_sprites[idx] = get_alpha_sprite(fire_ex_bitmaps[i]); } // Load fire sprites (no alpha transparency used) fire = load_bitmap_alpha("fire.tga", false); for (int idx = 0; idx < SPRITE_COUNT; idx++) { i = idx % 8; fire_bitmaps[idx] = create_sub_bitmap(fire, (i % 4) * 33, (i / 4) * 41, 32, 40); fire_rle_sprites[idx] = get_rle_sprite(fire_bitmaps[i]); fire_alpha_sprites[idx] = get_alpha_sprite(fire_bitmaps[i]); } // Load explosion sprites (alpha transparency used) explosion = load_bitmap_alpha("explosion.tga", true); for (i = 0; i < 10; i++) { explosion_bitmaps[i] = create_sub_bitmap(explosion, 0, 179 * i, 256, 178); explosion_rle_sprites[i] = get_rle_sprite(explosion_bitmaps[i]); explosion_alpha_sprites[i] = get_alpha_sprite(explosion_bitmaps[i]); } printf("---\n"); printf("explosion sprites per second (spritelib) = %.1lf\n", run_test(backbuffer1, test_explosion_spritelib)); printf("explosion sprites per second (allegro rle) = %.1lf\n", run_test(backbuffer2, test_explosion_allegro_rle)); printf("explosion sprites per second (allegro bitmap) = %.1lf\n", run_test(backbuffer2, test_explosion_allegro)); if (!compare_bitmaps(backbuffer1, backbuffer2)) printf("Error: results do not match!\n"); TESTS_COUNT = 500000; printf("---\n"); printf("normal fire sprites per second (spritelib) = %.1lf\n", run_test(backbuffer1, test_fire_spritelib)); printf("normal fire sprites per second (allegro rle) = %.1lf\n", run_test(backbuffer2, test_fire_allegro_rle)); if (!compare_bitmaps(backbuffer1, backbuffer2)) printf("Error: results do not match!\n"); printf("---\n"); printf("lit fire sprites per second (spritelib) = %.1lf\n", run_test(backbuffer1, test_fire_lit_spritelib)); printf("lit fire sprites per second (allegro rle) = %.1lf\n", run_test(backbuffer2, test_fire_lit_allegro_rle)); if (!compare_bitmaps(backbuffer1, backbuffer2)) printf("Error: results do not match!\n"); printf("---\n"); printf("alpha fire sprites per second (spritelib) = %.1lf\n", run_test(backbuffer1, test_fire_alpha_spritelib)); printf("alpha fire sprites per second (allegro rle) = %.1lf\n", run_test(backbuffer2, test_fire_alpha_allegro_rle)); if (!compare_bitmaps(backbuffer1, backbuffer2)) printf("Error: results do not match!\n"); i = 0; while (true) { if (keypressed()) { int scancode; ureadkey(&scancode); if (scancode == KEY_ESC) break; } clear_to_color(backbuffer, makecol(64, 64, 64)); int brightness = (i % 512) - 256; if (brightness < 0) brightness = -brightness; draw_alpha_sprite(backbuffer, explosion_alpha_sprites[i % 10], 0, 0, brightness); draw_alpha_sprite(backbuffer, fire_alpha_sprites[i % 4], 300, 0, brightness); draw_alpha_sprite(backbuffer, fire_alpha_sprites[(i % 4) + 4], 300, 50, 256 - brightness); draw_alpha_sprite(backbuffer, fire_alpha_sprites[i % 4], 300, 100, 250); draw_alpha_sprite(backbuffer, fire_alpha_sprites[(i % 4) + 4], 300, 150, 250); blit(backbuffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); rest(100); i++; } destroy_bitmap(backbuffer); destroy_bitmap(backbuffer1); destroy_bitmap(backbuffer2); for (idx = 0; idx < SPRITE_COUNT; idx++) { destroy_bitmap(fire_ex_bitmaps[idx]); destroy_rle_sprite(fire_ex_rle_sprites[idx]); destroy_alpha_sprite(fire_ex_alpha_sprites[idx]); destroy_bitmap(fire_bitmaps[idx]); destroy_rle_sprite(fire_rle_sprites[idx]); destroy_alpha_sprite(fire_alpha_sprites[idx]); } destroy_bitmap(fire_ex); destroy_bitmap(fire); // Load explosion sprites (alpha transparency used) for (i = 0; i < 10; i++) { destroy_bitmap(explosion_bitmaps[i]); destroy_rle_sprite(explosion_rle_sprites[i]); destroy_alpha_sprite(explosion_alpha_sprites[i]); } destroy_bitmap(explosion); allegro_exit(); return 0; }
void print_grid(int prot) { int i, x, y, k; int lev; int at, dl; char buf[100]; /*------------------------------------------------------*/ /* Draw header */ /*------------------------------------------------------*/ clear_to_color(screen, BGC); rect(screen, XMIN_GRID + 30, YMIN_GRID + 1, XMAX_GRID - 30, 40, 4); if (prot == PRIO_INHERITANCE) sprintf(buf, "Protocol: PRIO_INHERITANCE"); if (prot == PRIO_CEILING) { sprintf(buf, "Protocol: PRIO_CEILING"); } if (prot == NO_PROTOCOL) sprintf(buf, "Protocol: NO_PROTOCOL"); textout_centre_ex(screen, font, buf, 320, 10, 14, 0); textout_ex(screen, font, "Normal Exe", XMIN_GRID + 40, 30, COLOR_NORM_EXE, BGC); textout_ex(screen, font, "resource A", XMIN_GRID + 40 + 100, 30, COLOR_SEZ_A, BGC); textout_ex(screen, font, "resource B", XMIN_GRID + 40 + 200, 30, COLOR_SEZ_B, BGC); textout_centre_ex(screen, font, "(ESC to exit)", 320, YWIN - 20, 3, 0); sprintf(buf, "Time scale: %4.1f", scale); textout_ex(screen, font, buf, XMIN_GRID + 40, 10, 7, 0); /*------------------------------------------------------*/ /* Draw grid */ /*------------------------------------------------------*/ for (x = OFFSET; x < XMAX_GRID; x += DXGRID / scale) for (y = LEV0; y < LEV0 + DLEV * (num_tasks - 1); y += DYGRID) putpixel(screen, x, y, GRIDCOL); /*------------------------------------------------------*/ /* Draw task timelines */ /*------------------------------------------------------*/ for (i = 1; i < num_tasks; i++) { lev = LEV0 + DLEV * i; at = OFFSET; sprintf(buf, "T%d", i); textout_ex(screen, font, buf, 10, lev - 8, TLCOL, 0); line(screen, OFFSET, lev, XMAX_GRID, lev, TLCOL); k = 0; do { at = k * period[i]; x = OFFSET + at / scale; if (x < XMAX_GRID) line(screen, x, lev, x, lev - 20, TLCOL); dl = at + dline[i]; x = OFFSET + dl / scale; if (x < XMAX_GRID) { line(screen, x, lev - 1, x, lev - 15, DLCOL); line(screen, x, lev - 1, x - 1, lev - 5, DLCOL); line(screen, x, lev - 1, x + 1, lev - 5, DLCOL); } k++; } while (x < XMAX_GRID); } }
void AnimateLine::setBuffer(BITMAP* buffer1){ clear_to_color(tempBuffer,makecol(255,0,255)); draw_sprite(tempBuffer,buffer1,0,0); }
void KaboHaze::animate(Frame *space) { STACKTRACE; // IMPORTANT: physics must not be changed, that is, NON-LOCAL variable must not // be changed in this subroutine ! // Reason: the TimeWarp engine can decide to skip animations in case of low // frame-rate, thus, leading to a desynch between computers! /* Aaaaah, lots of work to do for a simple job, namely, create a transparent overlay of the shield onto the host: - Init (see constructor): Take the host-ship picture. Create a (blurred) mask image of it. Draw the shield and Overlay the mask. - Animate: Scale and draw the masked shield, Rotate and Draw transparent onto the screen. */ if (!host) return; //if ( state == 0 ) // return; // the host can die in-between calculate and animate, therefore I use this; it's // not allowed to change state of this presence though; that's done only in // calculate(). // Create a rotated copy of the shield sprite ... but only, if such a thing // does not exist, yet ! The purpose of this is, to spread the amount of // calculations over different frames, and to limit them to when they're // needed. int wshield = shield_bmp[0]->w; int hshield = shield_bmp[0]->h; if ( !shield_bmp[shield_sprite_index] ) { shield_bmp[shield_sprite_index] = create_bitmap(wshield, hshield); // important otherwise it contains artefacts clear_to_color(shield_bmp[shield_sprite_index], 0); rotate_sprite(shield_bmp[shield_sprite_index], shield_bmp[0], 0, 0, iround((1<<24)*(host->angle + 0.5*PI)/PI2) ); // result is in sprite_bmp[sprite_index] ( nice conventions, huh !) } //sprite_index = 0; // also needed - for collision detection?? // note, I've turned the collision of, since collide_flag_anyone = 0, but // otherwise, the collision detector would use this sprite_index to access // a ship sprite that doesnt exist !! // next, animate ... // first, reserve space for the target image, but ... how big should it be? // well, as big as the ship_bmp, but then, zoomed in space: int wfinal = int(wshield * space_zoom); int hfinal = int(hshield * space_zoom); BITMAP *final_bmp; final_bmp = create_bitmap(wfinal, hfinal); // scale/draw a shield: stretch_blit(shield_bmp[shield_sprite_index], final_bmp, 0, 0, wshield, hshield, 0, 0, wfinal, hfinal ); // result is in final_bmp // I need to calculate screen coordinates (using the original bmp size). // double xhost = host->normal_pos().x; // double yhost = host->normal_pos().y; Vector2 Vcorner; Vcorner = corner(host->normal_pos(), Vector2(wshield, hshield) ); //wcorner(xhost, wshield); int xplot = iround(Vcorner.x); //hcorner(yhost, hshield); int yplot = iround(Vcorner.y); // these routines are the standard way to calculate screen coordinates ! // local double power_scaled = power / 10.0; if ( power_scaled > 1.0 ) power_scaled = 1.0; // max brightness. // change the brightness of the shield: int brightness = int(255 * power_scaled); set_add_blender(0, 0, 0, brightness); draw_trans_sprite(space->surface, final_bmp, xplot, yplot); space->add_box(xplot, yplot, wshield, hshield); // also, draw a (few) flashes, at twice the brightness: brightness = 255; for ( int i = 0; i < int(power); ++i ) { int dx, dy; dx = wshield; dy = hshield; int icheck = 0; for (;;) { ++icheck; if (icheck > 100) break; // too bad !! //graphics dy = rand() % hshield; if (edge_left[dy] == -1) continue; if ( !(rand() % 2) ) //graphics dx = edge_left[dy]; else dx = edge_right[dy]; } dx -= wshield / 2; dy -= hshield / 2; double a = host->angle + 0.5*PI; // rotated around the center int dx2 = iround(wshield/2 + dx * cos(a) - dy * sin(a)); int dy2 = iround(hshield/2 + dy * cos(a) + dx * sin(a)); dx = iround( dx2 * space_zoom); dy = iround( dy2 * space_zoom); int x = xplot + dx; int y = yplot + dy; tw_putpixel(space->surface, x, y, tw_makecol(brightness,brightness,0) ); space->add_pixel(x, y); } // release the temporary bitmap: destroy_bitmap(final_bmp); }
int main( int argc, char** argv ){ //przygotowanie polaczenia int clientSocket; int sck; if(argv[1][0] == '1'){ clientSocket = server(); printf("Polaczono !\n"); } else{ sck = client(argv[2]); printf("Polaczono z serwerem ! \n"); } //inicjowanie funkcji zwiazanych z grafika BITMAP* buffer = NULL; allegro_init(); install_keyboard(); set_color_depth(16); set_gfx_mode( GFX_AUTODETECT_WINDOWED, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0 ); clear_to_color(screen, makecol( 0, 0, 0 ) ); buffer = create_bitmap(SCREEN_WIDTH, SCREEN_HEIGHT); BITMAP *okrazenie1 = NULL, *okrazenie2 = NULL, *okrazenie3 = NULL, *okrazenie4 = NULL; BITMAP *odliczanie3 = NULL, *odliczanie2 = NULL, *odliczanie1 = NULL, *odliczanieStart = NULL, *wygrana = NULL, *przegrana = NULL; polozenie player, player_temp; int licznikOkrazen=1; double x,y; bool zakonczenie = false; bool kolizja = false; bool lap_updown= false; bool zwyciestwo = true; //zaladowanie bitmap odliczanie3 = load_bmp("odliczanie3.bmp", NULL); odliczanie2 = load_bmp("odliczanie2.bmp", NULL); odliczanie1= load_bmp("odliczanie1.bmp", NULL); odliczanieStart = load_bmp("odliczanieStart.bmp", NULL); okrazenie1 = load_bmp("okrazenie1.bmp", NULL); okrazenie2 = load_bmp("okrazenie2.bmp", NULL); okrazenie3 = load_bmp("okrazenie3.bmp", NULL); okrazenie4 = load_bmp("okrazenie4.bmp", NULL); przegrana = load_bmp("przegrana.bmp", NULL); wygrana = load_bmp("Wygrana.bmp", NULL); //ustalenie pozycji poczatkowej if(argv[1][0] == '1'){ player.x = 535; player.y = 480; } else{ player.x = 535; player.y = 510; } int z = 4; //inicjalizacja wyscigu while(z>0){ if(z == 4) draw_sprite(buffer, odliczanie3, 0, 0); if(z == 3) draw_sprite(buffer, odliczanie2, 0, 0); if(z == 2) draw_sprite(buffer, odliczanie1, 0, 0); if(z == 1){ draw_sprite(buffer, odliczanieStart, 0, 0); circlefill(buffer, (int)player.x,(int)player.y, promien, makecol(128,0,0)); if(player.y == 480) circlefill(buffer, 535, 510, promien, makecol(0,128,0)); else circlefill(buffer, 535, 480, promien, makecol(0, 128, 0)); } draw_sprite(screen,buffer,0,0); sleep(1); z = z - 1; } while(zakonczenie == false && licznikOkrazen != 9){ // zakonczenie wyscigu jesli wcisniety zostal ESC if(key[ KEY_ESC ]){ printf("Gracz zamknal gre poprzez ESC. \n"); zakonczenie = true; } // wyswietlenie odpowiedniego tla planszy if(licznikOkrazen < 3) draw_sprite(buffer, okrazenie1, 0, 0); else if(licznikOkrazen < 5) draw_sprite(buffer, okrazenie2, 0, 0); else if(licznikOkrazen < 7) draw_sprite(buffer, okrazenie3, 0, 0); else if(licznikOkrazen < 9) draw_sprite(buffer, okrazenie4, 0, 0); // jesli nie ma kolizji... if(kolizja == false){ //zmieniamy predkosc i kat w zaleznosci od tego, czy wcisniety jest klawisz if( key[ KEY_LEFT ] ){ predkosc-=0.1; if(predkosc<1.0) predkosc=1.0; katSkretu+=0.1; if(katSkretu>2) katSkretu=2; kierunekPoruszania = zmianaKata(kierunekPoruszania,katSkretu); } else{ predkosc+=0.1; if(predkosc>3) predkosc=3; katSkretu-=0.1; if(katSkretu<1) katSkretu=1; } //i wyznaczamy nowa pozycje x = predkosc*cos(kierunekPoruszania*PI/180); player.x+=x; y = predkosc*sin(kierunekPoruszania*PI/180); player.y+=y; //sprawdzamy, czy okrazenie zostalo ukonczone przez gracza if(getpixel(buffer, (int)player.x, (int)player.y) == makecol(255,255,255)){ licznikOkrazen++; lap_updown = (!lap_updown); } //sprawdzamy, czy gracz nie znalazl sie poza torem if(getpixel(buffer, (int)player.x, (int)player.y) == makecol(0,0,0)) kolizja = true; circlefill(buffer, (int)player.x, (int)player.y, promien, makecol(128,0,0)); polozeniaGracza.push_front(player); while(polozeniaGracza.size()>50) polozeniaGracza.pop_back(); } //rysowanie sladu za graczem for(unsigned int i = 0; i<polozeniaGracza.size();i++){ player_temp = polozeniaGracza.front(); polozeniaGracza.pop_front(); circlefill(buffer, (int)player_temp.x, (int)player_temp.y, promien, makecol(128,0,0)); polozeniaGracza.push_back(player_temp); } //klient - komunikacja: przygotowanie i przeslanie informacji o kolizji/koncu wyscigu if(argv[1][0] == '2'){ if(kolizja == true){ player.x = 1; player.y = 1; } else if(licznikOkrazen == 9){ player.x = 2; player.y = 2; } char x[sizeof(player.x)]; char y[sizeof(player.y)]; sprintf(x, "%lf", player.x); sprintf(y, "%lf", player.y); write(sck,x,8); write(sck,y,8); oponentSock = sck; char rcvx[sizeof(double)]; char rcvy[sizeof(double)]; polozenie rcv; read(sck, &rcvx, 8); rcv.x = atof(rcvx); read(sck, &rcvy, 8); rcv.y = atof(rcvy); if(rcv.x == 1 && rcv.y == 1){ zakonczenie = true; zwyciestwo = true; } else if (rcv.x == 2 && rcv.y == 2) kolizja = true; else polozeniaPrzeciwnika.push_front(rcv); } // to samo dla serwera else{ char rcvx[sizeof(double)]; char rcvy[sizeof(double)]; polozenie rcv; read(clientSocket, &rcvx, 8); rcv.x = atof(rcvx); read(clientSocket, &rcvy, 8); rcv.y = atof(rcvy); if(rcv.x == 1 && rcv.y == 1) { zakonczenie = true; zwyciestwo = true; } else if (rcv.x == 2 && rcv.y == 2) kolizja = true; else polozeniaPrzeciwnika.push_front(rcv); if(kolizja == true){ player.x = 1; player.y = 1; } else if(licznikOkrazen == 9){ player.x = 2; player.y = 2; } char x[sizeof(player.x)]; char y[sizeof(player.y)]; sprintf(x ,"%lf",player.x); sprintf(y ,"%lf",player.y); write(clientSocket,x,8); write(clientSocket,y,8); } // zredukowanie sladu przeciwnika while(polozeniaPrzeciwnika.size()>50){ polozeniaPrzeciwnika.pop_back(); } // rysowanie sladu przeciwnika for(unsigned int i = 0; i<polozeniaPrzeciwnika.size();i++){ player_temp = polozeniaPrzeciwnika.front(); polozeniaPrzeciwnika.pop_front(); circlefill(buffer, (int)player_temp.x, (int)player_temp.y, promien, makecol(0,128,0)); polozeniaPrzeciwnika.push_back(player_temp); } draw_sprite(screen, buffer, 0, 0); if(kolizja == true){ zakonczenie = true; zwyciestwo = false; } } //gdy wygrana wyswietlamy wygrana if(zwyciestwo == true){ printf("wygrana\n"); draw_sprite(screen, wygrana, 0, 0); sleep(2); } //gdy przegrana wyswietlamy przegrana else{ draw_sprite(screen, przegrana, 0, 0); sleep(2); } //zamykanie gniazd if(argv[1][0] == '1'){ close(clientSocket); close(sck_in); } //czyszczenie listy polozen graczy while (!polozeniaGracza.empty()){ polozeniaGracza.pop_back(); } while (!polozeniaPrzeciwnika.empty()){ polozeniaPrzeciwnika.pop_back(); } //czyszczenie pamieci zajetej przez bitmapy destroy_bitmap(odliczanieStart); destroy_bitmap(odliczanie3); destroy_bitmap(odliczanie2); destroy_bitmap(odliczanie1); destroy_bitmap(okrazenie1); destroy_bitmap(okrazenie2); destroy_bitmap(okrazenie3); destroy_bitmap(okrazenie4); destroy_bitmap(wygrana); destroy_bitmap(przegrana); destroy_bitmap(buffer); allegro_exit(); return 0; }
void Bitmap::ClearTransparent() { clear_to_color(_alBitmap, bitmap_mask_color(_alBitmap)); }
int main() { FILE *dosya; char ch; int okunan=0,satirSayisi=0; int rMatrisi[100][100]; int i,j,giris,cikis,iterasyon; printf("\n\n ---Q-LEARNING ile LABIRENTTE YOL BULMA---\n\n"); printf("Baslangic odacik numarasini giriniz = "); scanf("%d",&giris); printf("\n"); printf("Hedef odacik numarasini giriniz = "); scanf("%d",&cikis); printf("\n"); printf("Iterasyon sayisini giriniz = "); scanf("%d",&iterasyon); printf("\n"); dosya=fopen("input44.txt" , "r"); while(!feof(dosya)) { ch=getc(dosya); if(ch=='\n') { satirSayisi++; } } fclose(dosya); for(i=0; i<satirSayisi; i++) { for(j=0; j<satirSayisi; j++) { rMatrisi[i][j]=-1; printf("%d ",rMatrisi[i][j]); } printf("\n"); } dosya=fopen("input44.txt" , "r"); int cevirme=0; int cevirsayac=0; int rEski=0; while(!feof(dosya)) { ch=getc(dosya); if(ch!=',' && ch!='\n') { cevirsayac++; if(cevirsayac==2) { //okunan=okunan-1 rMatrisi[okunan-1][cevirme]=rEski; cevirme=cevirme*10+ch-'0'; } else { cevirme = ch - '0'; } if(cevirme==cikis) { rEski= rMatrisi[okunan][cevirme]; rMatrisi[okunan][cevirme]=100; } else { rEski= rMatrisi[okunan][cevirme]; rMatrisi[okunan][cevirme]=0; } } else { cevirsayac=0; } if(ch=='\n') { okunan++; } } rMatrisi[cikis][cikis]=100; fclose(dosya); dosya=fopen("outR.txt","w"); for(i=0; i<okunan; i++) { for(j=0; j<okunan; j++) { printf("%d ",rMatrisi[i][j]); fprintf(dosya,"%d ",rMatrisi[i][j]); } printf("\n"); fprintf(dosya,"\n"); } fclose(dosya); float qMatrisi[satirSayisi][satirSayisi]; for(i=0; i<satirSayisi; i++) { for(j=0; j<satirSayisi; j++) { qMatrisi[i][j]=0; } } int enBuyuk=0; int enBuyukindis=0; int durum=giris; int aksiyon=0; int komsu=0; int itrSayac; int eskioda=giris; for(itrSayac=0; itrSayac<iterasyon; itrSayac++) { while(1) { aksiyon=rand()%satirSayisi; if(rMatrisi[giris][aksiyon]!=-1) break; } durum=giris; while(durum!=cikis) { eskioda=durum; komsu=0; enBuyuk=0; enBuyukindis=0; while(komsu<satirSayisi) { if(rMatrisi[aksiyon][komsu]!=-1) { if(qMatrisi[aksiyon][komsu]>=enBuyuk && aksiyon!=komsu && komsu!=eskioda ) { enBuyuk=qMatrisi[aksiyon][komsu]; enBuyukindis=komsu; } } komsu++; } qMatrisi[durum][aksiyon]=rMatrisi[durum][aksiyon] + 0.8* qMatrisi[aksiyon][enBuyukindis]; durum=aksiyon; aksiyon=enBuyukindis; } } int cikisYolu[satirSayisi]; int sayac=0; cikisYolu[0]=giris; printf("\n"); printf("\n"); printf("\n"); dosya=fopen("outQ.txt","w"); for(i=0; i<okunan; i++) { for(j=0; j<okunan; j++) { printf("%f ",qMatrisi[i][j]); fprintf(dosya,"%f ",qMatrisi[i][j]); } printf("\n"); fprintf(dosya,"\n"); } fclose(dosya); int enBuyuk2=0; int yol; int eklenecek=0; int s; for(s=0; s<satirSayisi; s++) { for(yol=0; yol<satirSayisi; yol++) { if(qMatrisi[giris][yol]>enBuyuk2) { eklenecek=yol; enBuyuk2=qMatrisi[giris][eklenecek]; } } cikisYolu[s+1]=eklenecek; sayac++; giris=eklenecek; enBuyuk2=0; if(eklenecek==cikis) { break; } } dosya=fopen("outPath.txt","w"); int a; for(a=0; a<sayac+1; a++) { printf(" %d ",cikisYolu[a]); fprintf(dosya,"%d ",cikisYolu[a]); } fclose(dosya); allegro_init(); install_keyboard(); set_color_depth(32); set_gfx_mode( GFX_AUTODETECT_WINDOWED, 600, 600, 0, 0); clear_to_color(screen,makecol(170,170,170) ); int odacik=sqrt(satirSayisi); int yatay=100,dikey=100,b; for(a=0; a<odacik; a++) { yatay=100; for(b=0; b<odacik; b++) { rect(screen,yatay,dikey,yatay+75,dikey+75,makecol(0,0,0)); yatay+=75; } dikey+=75; } int v,y,satir,sutun,yatay1,dikey1; for(v=0; v<satirSayisi; v++) { for(y=0; y<satirSayisi; y++) { yatay1=100,dikey1=100,satir=0,sutun=0; if( rMatrisi[v][y]!=-1) { if(((v<y)) && abs(v-y)<2 ) { satir+=(y/odacik); sutun+=(y%odacik); yatay1+=(sutun*75); dikey1+=(satir*75); vline(screen,yatay1,dikey1,dikey1+75,makecol(170,170,170)); } else if(((v<y)) && (!abs(v-y)<2) ) { satir+=(y/odacik); sutun+=(y%odacik); yatay1+=(sutun*75); dikey1+=(satir*75); hline(screen,yatay1,dikey1,yatay1+75,makecol(170,170,170)); } } } } /////////////////////////////////////////////// GIRIS-CIKIS ////////////////////////////////////////////////// satir=cikisYolu[0]/odacik; sutun=cikisYolu[0]%odacik; yatay1+=sutun*75; dikey1+=satir*75; if(cikisYolu[0]%odacik==0 || cikisYolu[0]%odacik==2) { vline(screen,yatay1,dikey1,dikey1+75,makecol(170,170,170)); }else { hline(screen,yatay1,dikey1,yatay1+75,makecol(170,170,170)); } ////////////////////////////////////////////////////////////////////////////////////// int cikisSatir,cikisSutun,cikisYatay=100,cikisDikey=100; cikisSatir=giris/odacik; cikisSutun=giris%odacik; cikisYatay+=cikisSutun*75; cikisDikey+=cikisSatir*75; if(giris%odacik==odacik-1) { vline(screen,cikisYatay+75,cikisDikey,cikisDikey+75,makecol(170,170,170)); hline(screen,cikisYatay+33,cikisDikey+33,cikisYatay+75,makecol(183,2,34)); } else if(giris%odacik==0) { vline(screen,cikisYatay,cikisDikey,cikisDikey+75,makecol(170,170,170)); hline(screen,cikisYatay+33,cikisDikey+33,cikisYatay,makecol(183,2,34)); } else { hline(screen,cikisYatay,cikisDikey+75,cikisYatay+75,makecol(170,170,170)); vline(screen,cikisYatay+33,cikisDikey+33,cikisDikey+75,makecol(183,2,34)); } /////////////////////////////////////////////// YOL ////////////////////////////////////////////////// int yoll=0,yolYatay=100,yolDikey=100,yollYatay=100,yollDikey=100,yolSatir,yolSutun,yolSatirr,yolSutunn; while(cikisYolu[yoll]!=cikis) { yolSatir=cikisYolu[yoll]/odacik; yolSutun=cikisYolu[yoll]%odacik; yolYatay=yolSutun*75+133; yolDikey=yolSatir*75+133; yolSatirr=cikisYolu[yoll+1]/odacik; yolSutunn=cikisYolu[yoll+1]%odacik; yollYatay=yolSutunn*75+133; yollDikey=yolSatirr*75+133; yoll++; line(screen,yolYatay,yolDikey,yollYatay,yollDikey,makecol(183,2,34)); } while(!key[KEY_ESC]) {} return 0; }