/*Updates map portion of screen*/ void update_map(screen_t* my_screen){ car_t* player = &my_screen->vw.player; car_t* cpu = my_screen->vw.cpu; int i; int xblit = cord2px(player->bound_box.x); int yblit = cord2px(player->bound_box.y); pthread_mutex_lock(&my_screen->sems.pcar_mux); blit(my_screen->map.background, screen, xblit -10, yblit-10, xblit-10, yblit-10, cord2px(player->bound_box.w)+20, cord2px(player->bound_box.h)+20); for(i = 0; i<CPUCARS; i++){ if(cpu[i].alive){ pthread_mutex_lock(&my_screen->sems.cpucar_mux[i]); xblit = cord2px(cpu[i].bound_box.x); yblit = cord2px(cpu[i].bound_box.y); blit(my_screen->map.background, screen, xblit-10, yblit-10, xblit-10, yblit-10, cord2px(cpu[i].bound_box.w)+20, cord2px(cpu[i].bound_box.h)+20); } } for(i=0;i<CPUCARS; i++) if(cpu[i].alive){ rotate_sprite(screen, cpu[i].sprite, carx2px(cpu[i].pos.x), cary2px(cpu[i].pos.y), ftofix(cpu[i].angle*256/360)); pthread_mutex_unlock(&my_screen->sems.cpucar_mux[i]); } rotate_sprite(screen, player->sprite, carx2px(player->pos.x), cary2px(player->pos.y), ftofix(player->angle*256/360)); pthread_mutex_unlock(&my_screen->sems.pcar_mux); }
/********************************************//** * \brief Affiche les obstacles - ATTENTION ILS TOURNENT TOUS * * \param page BITMAP* Buffer d'affichage * \param images BITMAP** Tableau de BITAMAP -> obstacles * \param scroll_x int * \param nbr_obstacle int Taille du tableau d'obstacles * \param obstacle t_obstacle* Info des obstacles * \return void * ***********************************************/ void afficher_obstacle(BITMAP* page,BITMAP** images,int scroll_x, int nbr_obstacle,t_obstacle* obstacle) { int i; for (i = 0 ; i < nbr_obstacle ; i ++ ) { if (obstacle[i].type != 2) rotate_sprite(page,images[obstacle[i].type],obstacle[i].coord.x-scroll_x,obstacle[i].coord.y,itofix(scroll_x)); else { draw_sprite(page,images[obstacle[i].type],obstacle[i].coord.x-scroll_x,obstacle[i].coord.y); rotate_sprite(page,images[obstacle[i].type],obstacle[i].coord2.x-scroll_x,obstacle[i].coord2.y,itofix(64*2)); } } }
void printaTabuleiro(JOGO_T *jogo){ rotate_sprite( jogo->bmpbuffer, jogo->tabuleiro.imagem, jogo->tabuleiro.bmpx0, jogo->tabuleiro.bmpy0, itofix(ANGULO_INT)); /*draw_sprite(jogo->bmpbuffer, jogo->tabuleiro.imagem, jogo->tabuleiro.bmpx0 , jogo->tabuleiro.bmpy0);*/ }
/********************************************//** * \brief Affiche les bonus sur le buffer * * \param page BITMAP* Buffer d'affichage * \param images BITMAP** Tableau d'images * \param scroll_x int Scroll de l'ecran * \param nbr_bonus int Nb de bonus (ie taille du tableau) * \param bonus t_bonus* Donnees des bonus * \return void * ***********************************************/ void afficher_bonus(BITMAP* page,BITMAP** images,int scroll_x,int nbr_bonus, t_bonus* bonus) { int i; for (i=0 ; i<nbr_bonus ; i ++ ) { if (bonus[i].vivant) rotate_sprite(page,images[bonus[i].type],bonus[i].coord.x-scroll_x,bonus[i].coord.y,itofix(scroll_x)); } }
void Animation::drawRotatedFrame(BITMAP *dest, int frame, int x, int y, int angle, bool vflip) { BITMAP *src = getFrame(frame); if (vflip) { rotate_sprite_v_flip(dest, src, x, y, itofix(angle)); } else { rotate_sprite(dest, src, x, y, itofix(angle)); } }
void draw_crusher(BITMAP *bmp) { static fixed angle = 0; int x, y, x1, y1, x2, y2; x = crusher.x+crusher.w/2-get_bitmap(BMP_CRUSHER)->w/2; y = crusher.y+crusher.h/2-get_bitmap(BMP_CRUSHER)->h/2+8; /* crusher body */ draw_sprite(bmp, get_bitmap(BMP_CRUSHER), x, y); /* crusher motor */ draw_sprite(bmp, get_bitmap(BMP_CRUSHER_MOTOR), x1 = x-get_bitmap(BMP_CRUSHER_MOTOR)->w+1+rand()%3-1, y1 = y+rand()%3-1); /* crusher pulley */ rotate_sprite(bmp, get_bitmap(BMP_CRUSHER_PULLEY), x2 = x+17-get_bitmap(BMP_CRUSHER_PULLEY)->w/2+rand()%3-1, y2 = y+13-get_bitmap(BMP_CRUSHER_PULLEY)->h/2+rand()%3-1, angle); /* strap */ do_line(bmp, x1+12, y1+8, x2+get_bitmap(BMP_CRUSHER_PULLEY)->w/2-1, y2, makecol(0, 0, 0), strap_proc); do_line(bmp, x1+12, y1+18, x2+get_bitmap(BMP_CRUSHER_PULLEY)->w/2-1, y2+get_bitmap(BMP_CRUSHER_PULLEY)->h-1, makecol(0, 0, 0), strap_proc); angle = fadd(angle, itofix(16)); if (angle > itofix(256)) angle = fsub(angle, itofix(256)); /* scorer */ draw_sprite(bmp, get_bitmap(BMP_SCORER), x+get_bitmap(BMP_CRUSHER)->w, y+get_bitmap(BMP_CRUSHER)->h-get_bitmap(BMP_SCORER)->h); /* alarm */ if (alarm_time_blue >= 0) { masked_blit(get_bitmap(BMP_SCORER_ALARM), bmp, 0, 0, x+get_bitmap(BMP_CRUSHER)->w+63, y+get_bitmap(BMP_CRUSHER)->h-get_bitmap(BMP_SCORER)->h+27, 8, 9); } if (alarm_time_red >= 0) { masked_blit(get_bitmap(BMP_SCORER_ALARM), bmp, get_bitmap(BMP_SCORER_ALARM)->w-8, 0, x+get_bitmap(BMP_CRUSHER)->w+75, y+get_bitmap(BMP_CRUSHER)->h-get_bitmap(BMP_SCORER)->h+27, 8, 9); } }
/*Updates User Interface portion of screen*/ void update_ui(screen_t* my_screen){ car_t *player = &my_screen->vw.player; double angle; int i; masked_blit(my_screen->ui.redspeedmeter, screen, 0, 0, 0, MAP_H, my_screen->ui.redspeedmeter->w, my_screen->ui.redspeedmeter->h); pthread_mutex_lock(&my_screen->sems.pcar_mux); angle = - 135 + player->vel * 3.6; rotate_sprite(screen, my_screen->ui.needle, 66, MAP_H, ftofix(angle*256/360)); pthread_mutex_unlock(&my_screen->sems.pcar_mux); for(i=0;i<CPUCARS; i++){ if(my_screen->vw.cpu[i].alive){ masked_blit(my_screen->ui.speedmeter, screen, 0, 0, UI_W -my_screen->ui.speedmeter->w *(1+i), MAP_H, my_screen->ui.speedmeter->w, my_screen->ui.speedmeter->h); pthread_mutex_lock(&my_screen->sems.cpucar_mux[i]); angle = - 135 + my_screen->vw.cpu[i].vel * 3.6; rotate_sprite(screen, my_screen->ui.little_needle, UI_W -my_screen->ui.speedmeter->w *(1+i) + 49, MAP_H, ftofix(angle*256/360)); pthread_mutex_unlock(&my_screen->sems.cpucar_mux[i]); } } }
Player::Player(int _bodyColor, int _faceColor, int _lengthX, int _lengthY, int _maxHealth): Object(_lengthX, _lengthY, 4), C(bodyColor), C(faceColor), dir(rand() % 4), C(maxHealth) { health = maxHealth; rectfill(sprites[0], 0, 0, lengthX, lengthY, bodyColor); rectfill(sprites[0], 7 * lengthX / 8, lengthY / 5, lengthX, 4 * lengthY / 5, faceColor); for(int i = 1; i < 4; i++) rotate_sprite(sprites[i], sprites[0], 0, 0, ftofix(i * 64)); }
void actualiser_bitmap_collision(float*mapx,t_listePerso* lp) { int i; clear_to_color(collision,makecol(255,0,255)); masked_blit(niveau,collision,*mapx,0,0,0,SCREEN_W,SCREEN_H); for (i=0; i<MAXI; i++) { if (lp->perso[i]!=NULL) { rotate_sprite(collision,lp->perso[i]->hitbox,lp->perso[i]->x,lp->perso[i]->y,ftofix(lp->perso[i]->angle)); } } }
void updateexplosion(int num) { int x, y,i; for(i=0;i<MAXBULLET;i++){ if (!explosions[num]->alive) continue ; //draw explosion (maxframe) times if (explosions[num]->curframe++ < explosions[num]->maxframe) { x = explosions[num]->x; y = explosions[num]->y; //draw explosion in enemy window rotate_sprite(buffer, explode_bmp, x + rand()%10 - 20, y + rand()%10 - 20, itofix(rand()%255)); //draw explosion in "my" window if enemy is visible x = scrollx[!num] + SCROLLW/2; y = scrolly[!num] + SCROLLH/2; if (inside(x, y, scrollx[num], scrolly[num], scrollx[num] + SCROLLW, scrolly[num] + SCROLLH)) { //but only draw if explosion is active if (explosions[num]->alive) rotate_sprite(buffer, explode_bmp, startx[num]+x-scrollx[num] + rand()%10 - 20, starty[num]+y-scrolly[num] + rand()%10 - 20, itofix(rand()%255)); } } else { explosions[num]->alive = 0; explosions[num]->curframe = 0; } } }
void player_bullets_draw(player_bullet *b, int liczba, BITMAP *bufor) { for (int i = 0; i < liczba; i++) { clear_to_color(b[i].obraz_rot, makecol(255, 0, 255)); rotate_sprite(b[i].obraz_rot, b[i].obraz, (b[i].obraz_rot->w - b[i].obraz->w) / 2, (b[i].obraz_rot->h - b[i].obraz->h) / 2, itofix((int) (256.0 * b[i].rot / (2.0 * pi)))); masked_blit(b[i].obraz_rot, bufor, 0, 0, ex(b[i].h * sin(b[i].a)) / 2 - b[i].obraz_rot->w / 2, ey(b[i].h * cos(b[i].a)) / 2 - b[i].obraz_rot->h / 2, b[i].obraz_rot->w, b[i].obraz_rot->h); } }
void pon_tortuga(int x1,int y1,int orientacion){ switch (orientacion){ case 0: draw_sprite(buffer2, im_tortuga, 0,0); break; //case 1: rotate_sprite(buffer2,im_tortuga,0,0,itofix(64)); // break; //case 2: rotate_sprite(buffer2,im_tortuga,0,0,itofix(128)); // break; //case 3: rotate_sprite(buffer2,im_tortuga,0,0,itofix(192)); // break; default:rotate_sprite(buffer2,im_tortuga,0,0,itofix(orientacion));break; } blit(buffer2, screen, 0,0,x1,y1,64,70); }
void affichage(float*mapx,t_listePerso* lp) { int i; blit(fond,page,*mapx/10,0,0,0,SCREEN_W,SCREEN_H); masked_blit(niveau,page,*mapx,0,0,0,SCREEN_W,SCREEN_H); for (i=0; i<MAXI; i++) { if (lp->perso[i]!=NULL) { rotate_sprite(page,oiseau[lp->perso[i]->imgcourante],lp->perso[i]->x,lp->perso[i]->y,ftofix(lp->perso[i]->angle)); } } // affichage sur le buffer blit(page,screen,0,0,0,0,SCREEN_W,SCREEN_H); }
void desenha_fumante(BITMAP *buffer, BITMAP *smoking, BITMAP *smoking_not, BITMAP *gear, int fumante, int passos, int passos_total, int offset) { if (estado_global[fumante] == Fazendo) { int x = 550; int y = offset; BITMAP *tmp = create_bitmap(SCREEN_W, SCREEN_H); blit(buffer, tmp, 0, 0, 0, 0, buffer->w, buffer->h); fixed ang; // Anda até o centro for (passos = 0; passos < passos_total; ++passos, x-=10) { blit(tmp, buffer, 0, 0, 0, 0, buffer->w, buffer->h); draw_sprite(buffer, smoking_not, x, y); blit(buffer, screen, 0, 0, 0, 0, buffer->w, buffer->h); rest_callback(75, callback); } // Faz o cigarro for (ang = 0, passos = 0; passos < passos_total*3; ang += 37, ++passos) { blit(tmp, buffer, 0, 0, 0, 0, buffer->w, buffer->h); draw_sprite(buffer, smoking_not, x, y); rotate_sprite(buffer, gear, x-50, y+50, itofix(ang)); blit(buffer, screen, 0, 0, 0, 0, buffer->w, buffer->h); rest_callback(40, callback); } // Volta a posicao for (passos = 0; passos < passos_total; ++passos, x+=10) { blit(tmp, buffer, 0, 0, 0, 0, buffer->w, buffer->h); draw_sprite(buffer, smoking_not, x, y); blit(buffer, screen, 0, 0, 0, 0, buffer->w, buffer->h); rest_callback(75, callback); } } }
/********************************************//** * \brief Affiche les eclats sur le buffer * * \param eclat_perso[ECLAT_PERSO_NB_MAX] t_eclat_perso * \param sprites t_sprite* * \param scroll int * \return void * ***********************************************/ void eclat_perso_blit(t_eclat_perso eclat_perso[ECLAT_PERSO_NB_MAX], t_sprite *sprites, int scroll) { int i; for (i = 0; i < ECLAT_PERSO_NB_PAR_PERSO; ++i) { if (eclat_perso[i].isActive) { BITMAP *ptr; if (eclat_perso[i].isActive == 1) ptr = sprites->eclat1; else ptr = sprites->eclat2; rotate_sprite(sprites->page, ptr, eclat_perso[i].pos.x-scroll, eclat_perso[i].pos.y, itofix((scroll/2)%256)); } } }
void Personnage::afficher(BITMAP* buffer) { BITMAP* aff; switch(pos) { case 0:case 2: aff = img[0]; break; case 1: aff = img[1]; break; case 3: aff = img[2]; } rotate_sprite(buffer,aff,(SCREEN_W-img[0]->w)/2,(SCREEN_H-img[0]->h)/2,itofix(a)); }
//draw with rotation void sprite::drawframe(BITMAP *dest, int angle) { if (!this->image) return; //create scratch frame if necessary if (!this->frame) { this->frame = create_bitmap(this->width, this->height); } //first, draw frame normally but send it to the scratch frame image int fx = this->animstartx + (this->curframe % this->animcolumns) * this->width; int fy = this->animstarty + (this->curframe / this->animcolumns) * this->height; blit(this->image, this->frame, fx, fy, 0, 0, this->width, this->height); //draw rotated image in scratch frame onto dest //adjust for Allegro's 16.16 fixed trig (256 / 360 = 0.7) then divide by 2 radians rotate_sprite(dest, this->frame, (int)this->x, (int)this->y, itofix((int)(angle / 0.7f / 2.0f))); }
void draw_all_stations(station *stacje, int n, BITMAP *bufor) { for (int i = 0; i < n; i++) { if (!stacje[i].zywa) continue; clear_to_color(stacje[i].budynek_rot, makecol(255, 0, 255)); rotate_sprite(stacje[i].budynek_rot, stacje[i].budynek, (stacje[i].budynek_rot->w - stacje[i].budynek->w) / 2, (stacje[i].budynek_rot->h - stacje[i].budynek->h) / 2, itofix((int) (256.0 * stacje[i].a / (2.0 * pi)))); masked_blit(stacje[i].budynek_rot, bufor, 0, 0, ex(stacje[i].h * sin(stacje[i].a)) / 2 - stacje[i].budynek_rot->w / 2, ey(stacje[i].h * cos(stacje[i].a)) / 2 - stacje[i].budynek_rot->h / 2, stacje[i].budynek_rot->w, stacje[i].budynek_rot->h); } }
Ship* get_ship(int x, int y) { SDL_Surface *fb = SDL_GetVideoSurface(); int bpp = fb->pitch / fb->w; Ship* ship = malloc(sizeof(Ship)); ship->pos = malloc(sizeof(Vector)); set_vector(ship->pos, x, y); ship->v = malloc(sizeof(Vector)); set_vector(ship->v, 0, 0); ship->dv = 2; ship->rot = 0; ship->vrot = 0; ship->arot = 0.5; ship->bullets = new_array(sizeof (Bullet)); ship->particles = new_array(sizeof(Particle)); if (!ship_sprite){ bmp_file *bmp = read_bmp("Sprites/ship.bmp"); ship_sprite = malloc(sizeof(Sprite)); ship_sprite->pixels = convert_bmp_to_pixels(bmp, 4); ship_sprite->w = get_bmp_width(bmp); ship_sprite->h = get_bmp_height(bmp); ship_sprite->bpp = 4;//get_bmp_bits_per_pixel(bmp); free_bmp(bmp); } ship->sprite = *ship_sprite; int rrad = ship->sprite.w/sin(45); //rotation buffer width and height Sprite rotBuffer = {malloc(sizeof(int) * rrad * rrad), rrad, rrad, bpp}; memset(rotBuffer.pixels, 0, sizeof(int) * rrad * rrad); rotate_sprite(ship->sprite, rotBuffer, 0); ship->rot_buffer = rotBuffer; ship->rainbow = SDL_CreateRGBSurface(SDL_SWSURFACE, fb->w, fb->h, 8*fb->pitch/fb->w, 0, 0, 0, 0); int bytes = fb->h * fb->pitch; memset(ship->rainbow->pixels, 0, bytes); reset_keys(); return ship; }
void tur_draw_turret(BITMAP *dest, turret_t *turret) { int x, y; float bx, by; int i; x = turret->x * 32; y = turret->y * 32; /* XXX/DEBUG: SHOW ANGLE */ bx = x + turret->bitmap->w/2; by = y + turret->bitmap->h/2; drawing_mode(DRAW_MODE_TRANS,NULL,0,0); set_trans_blender(0,0,0,100); for (i = 0; i < turret->range; i += 10) { float result; result = fixtof(fixcos(turret->angle)); by -= result * 10; result = fixtof(fixsin(turret->angle)); bx += result * 10; //putpixel(dest, bx, by, makecol(255,255,0)); //putpixel(dest, bx+1, by, makecol(255,255,0)); } solid_mode(); /* ---- */ /* range */ drawing_mode(DRAW_MODE_TRANS,NULL,0,0); set_trans_blender(0,0,0,60); //circle(dest, turret->x * 32 + 16, turret->y * 32 + 16, turret->range, makecol(200,200,200)); /*circlefill(dest, turret->x * 32 + 16, turret->y * 32 + 16, turret->range, makecol(200,200,200));*/ solid_mode(); /* turret */ rotate_sprite(dest, turret->bitmap, turret->x * 32, turret->y * 32, turret->angle); }
void update(){ draw_sprite( screen, buffer, 0, 0); draw_sprite( buffer, scene1, 0, 0); if(flip==0){draw_sprite(buffer,bobby, 600, 600); flip=1; loop=1;} if(flip==1 && loop==0){draw_sprite_h_flip(buffer,bobby, 600, 600); flip=0;} loop=0; angle=angle+5; rotate_sprite(buffer, bobby, 400, 600, itofix(angle)); stretch_sprite(buffer, bobby, 500, 600, w, h); stretch_sprite(buffer, bobby, 300, 600, w, 50); stretch_sprite(buffer, bobby, 200, 600, 50, h); w++; h++; if(w==75){w=25;} if(h==75){h=25;} rest(100); }
void cmd_run(Ttoken *t) { Tscript_object *o; int loops; static int i = 0; loops = atoi(t->word); cycle_count = 0; while(loops && !script_done) { while(cycle_count > 0 && loops && !script_done) { logic_count ++; poll_music(); // update objects o = objects; while(o != NULL) { if (!o->line) { o->x += o->vx; o->y += o->vy; } o = (Tscript_object *) o->next; } if (key[KEY_ESC]) script_done = -1; i ++; loops --; cycle_count --; } // let other processes play yield_timeslice(); // blit buffer to swap buffer blit(buffer, swap_buffer, 0, 0, 0, 0, 160, 120); // draw objects o = objects; while(o != NULL) { if (o->bmp[0] != NULL) { int frame = (o->frames ? logic_count % o->frames : 0); if (o->dir == 1) draw_sprite_h_flip(swap_buffer, o->bmp[frame], o->x, o->y); else if (o->dir == 0) draw_sprite(swap_buffer, o->bmp[frame], o->x, o->y); else // rotate rotate_sprite(swap_buffer, o->bmp[frame], o->x, o->y, itofix(-8*i)); } else if (o->line) { line(swap_buffer, ((Tscript_object *)o->line_from)->x + o->x, ((Tscript_object *)o->line_from)->y + o->y, ((Tscript_object *)o->line_to)->x + o->vx, ((Tscript_object *)o->line_to)->y + o->vy, 1); } o = (Tscript_object *) o->next; } // blit to screen blit_to_screen(swap_buffer); } }
void Bitmap::RotateBlt(Bitmap *src, int dst_x, int dst_y, fixed_t angle) { BITMAP *al_src_bmp = src->_alBitmap; rotate_sprite(_alBitmap, al_src_bmp, dst_x, dst_y, angle); }
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); }
void IAGSEngine::BlitSpriteRotated(int x, int y, BITMAP *bmp, int angle) { rotate_sprite(abuf, bmp, x, y, itofix(angle)); }
int init_vaisseau_data(struct vaisseau_data *v, struct vaisseau_gfx *gfx, float mass, float thrust_max, int anglestep, int max_fuel, int speed_fuel_down, int speed_fuel_up, int max_shield_force, int speed_shield_force_down, int speed_shield_force_up) { v->thrust_max = ftofix(thrust_max); v->mass = ftofix(mass); v->anglestep = anglestep; v->max_fuel = max_fuel; v->speed_fuel_down = speed_fuel_down; v->speed_fuel_up = speed_fuel_up; v->max_shield_force = max_shield_force; v->speed_shield_force_down = speed_shield_force_down; v->speed_shield_force_up = speed_shield_force_down; int i; for (i = 0; i < MAX_TIR; i++) { v->tir[i].x = 0; v->tir[i].y = 0; v->tir[i].xposprecise = itofix(0); v->tir[i].yposprecise = itofix(0); v->tir[i].dx = itofix(0); v->tir[i].dy = itofix(0); v->tir[i].free = true; } for (i = 0; i < MAX_TIR; i++) { v->backtir[i].x = 0; v->backtir[i].y = 0; v->backtir[i].xposprecise = itofix(0); v->backtir[i].yposprecise = itofix(0); v->backtir[i].dx = itofix(0); v->backtir[i].dy = itofix(0); v->backtir[i].free = true; } for (i = 0; i < 8; i++) { v->debris[i].x = 0; v->debris[i].y = 0; v->debris[i].xposprecise = itofix(0); v->debris[i].yposprecise = itofix(0); v->debris[i].ax = itofix(0); v->debris[i].ay = itofix(0); v->debris[i].vx = itofix(0); v->debris[i].vy = itofix(0); v->debris[i].impultion = itofix(0); v->debris[i].angle = 0; v->debris[i].active = false; } v->gfx = gfx; v->sprite_ptr = gfx->sprite; v->sprite_buffer_rota = al_create_bitmap(32, 32); // create ALLEGRO_BITMAP pour le sprite if (!v->sprite_buffer_rota) return -1; clear_bitmap(v->sprite_buffer_rota); // On nettoye int num_frames = (360 / anglestep) + 1; // Add one frame for handling rounding errors v->coll_map.init(32, 32, num_frames); for (int frame = 0; frame < num_frames; frame++) { double angle = v->anglestep * frame; clear_bitmap(v->sprite_buffer_rota); rotate_sprite(v->sprite_buffer_rota, v->sprite_ptr, 0, 0, angle); ALLEGRO_LOCKED_REGION *reg = al_lock_bitmap( v->sprite_buffer_rota, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READONLY); assert(reg); for (int y = 0; y < 32; y++) { for (int x = 0; x < 32; x++) { auto pixel = get_pixel(reg, x, y); v->coll_map.set_pixel(x, y, frame, is_nonblack_pixel(pixel)); } } al_unlock_bitmap(v->sprite_buffer_rota); } return 0; }
int demo_2() { static struct tmu_td tmu_badclouds, tmu_badfactory, tmu_clearscreen; static struct tmu_vertex badclouds_src_vtx[TMU_MESH_MAXSIZE][TMU_MESH_MAXSIZE]; static struct tmu_vertex badclouds_dst_vtx[TMU_MESH_MAXSIZE][TMU_MESH_MAXSIZE]; static struct tmu_vertex badfactory_src_vtx[TMU_MESH_MAXSIZE][TMU_MESH_MAXSIZE]; static struct tmu_vertex badfactory_dst_vtx[TMU_MESH_MAXSIZE][TMU_MESH_MAXSIZE]; static short int black = 0x0000; static struct tmu_vertex src_clr_vertices[TMU_MESH_MAXSIZE][TMU_MESH_MAXSIZE]; static struct tmu_vertex dst_clr_vertices[TMU_MESH_MAXSIZE][TMU_MESH_MAXSIZE]; int quit = 0 , x = 0; //unsigned int x , y ; //unsigned short int * vga_position; //Initialization sprites_init(); sprites_load(badclouds_raw,badclouds_raw_len,0x001F,138,100,0); sprites_load(badclouds_raw,badclouds_raw_len,0x001F,138,100,1); sprites_load(badclouds_raw,badclouds_raw_len,0x001F,138,100,2); sprites_load(badclouds_raw,badclouds_raw_len,0x001F,138,100,3); sprites_load(badclouds_raw,badclouds_raw_len,0x001F,138,100,4); sprites_load(badfactory_raw,badfactory_raw_len,0x001F,100,100,0); /* debug_sprite(&sprite_data[0]); debug_sprite(&sprite_data[1]); debug_sprite(&sprite_data[2]); debug_sprite(&sprite_data[3]); debug_sprite(&sprite_data[4]); */ init_sprite(&badclouds_src_vtx[0][0] , &badclouds_dst_vtx[0][0] , &sprite_data[0]); init_sprite(&badfactory_src_vtx[0][0] , &badfactory_dst_vtx[0][0] , &sprite_data[5]); /* for ( x = 0; x <= HMESHLAST; x++) { for ( y = 0; y <= VMESHLAST; y++) { badclouds_src_vtx[x][y].x = x * 138; badclouds_src_vtx[x][y].y = y * 100; badclouds_src_vtx[x][y].x = x * 138; badclouds_src_vtx[x][y].y = y * 100; } } */ src_clr_vertices[0][0].x = 0; src_clr_vertices[0][0].y = 0; src_clr_vertices[1][0].x = 640; src_clr_vertices[1][0].y = 0; src_clr_vertices[0][1].x = 0; src_clr_vertices[0][1].y = 480; src_clr_vertices[1][1].x = 640; src_clr_vertices[1][1].y = 480; dst_clr_vertices[0][0].x = 0 - 30; dst_clr_vertices[0][0].y = 0 - 23; dst_clr_vertices[1][0].x = 640 + 30 ; dst_clr_vertices[1][0].y = 0 - 23; dst_clr_vertices[0][1].x = 0 - 30; dst_clr_vertices[0][1].y = 480 + 23; dst_clr_vertices[1][1].x = 640 + 30; dst_clr_vertices[1][1].y = 480 + 23; //tmu_clearscreen.flags = 0; tmu_badclouds.flags = TMU_CTL_CHROMAKEY; tmu_clearscreen.hmeshlast = 1; tmu_clearscreen.vmeshlast = 1; tmu_clearscreen.brightness = 60; tmu_clearscreen.chromakey = 0; tmu_clearscreen.srcmesh = &src_clr_vertices[0][0]; tmu_clearscreen.srchres = vga_hres; tmu_clearscreen.srcvres = vga_vres; tmu_clearscreen.dstmesh = &dst_clr_vertices[0][0]; tmu_clearscreen.dsthres = vga_hres; tmu_clearscreen.dstvres = vga_vres; tmu_clearscreen.profile = 0; tmu_clearscreen.callback = tmu_complete; tmu_clearscreen.user = NULL; tmu_badclouds.flags = TMU_CTL_CHROMAKEY; tmu_badclouds.hmeshlast = HMESHLAST; tmu_badclouds.vmeshlast = VMESHLAST; tmu_badclouds.brightness = 62; tmu_badclouds.chromakey = CHROMAKEY; tmu_badclouds.srcmesh = &badclouds_src_vtx[0][0]; tmu_badclouds.srchres = 138; tmu_badclouds.srcvres = 100; tmu_badclouds.dstmesh = &badclouds_dst_vtx[0][0]; tmu_badclouds.dsthres = vga_hres; tmu_badclouds.dstvres = vga_vres; tmu_badclouds.profile = 0; tmu_badclouds.callback = tmu_complete; tmu_badclouds.user = NULL; tmu_badfactory.flags = TMU_CTL_CHROMAKEY; tmu_badfactory.hmeshlast = HMESHLAST; tmu_badfactory.vmeshlast = VMESHLAST; tmu_badfactory.brightness = 62; tmu_badfactory.chromakey = CHROMAKEY; tmu_badfactory.srcmesh = &badclouds_src_vtx[0][0]; tmu_badfactory.srchres = 100; tmu_badfactory.srcvres = 100; tmu_badfactory.dstmesh = &badclouds_dst_vtx[0][0]; tmu_badfactory.dsthres = vga_hres; tmu_badfactory.dstvres = vga_vres; tmu_badfactory.profile = 0; tmu_badfactory.callback = tmu_complete; tmu_badfactory.user = NULL; x = 0; frames = 0; while(quit < 10) { tmu_clearscreen.srcfbuf = vga_lastbuffer; tmu_clearscreen.dstfbuf = vga_backbuffer; tmu_wait = 0; tmu_submit_task(&tmu_clearscreen); while(!tmu_wait); //update_sprite(tmu_badclouds.dstmesh ,&sprite_data[x/20], 320 , 240 , frames); if (x/40 == 5) { init_sprite(tmu_badfactory.srcmesh,tmu_badclouds.dstmesh ,&sprite_data[x/40]); scale_sprite(tmu_badfactory.dstmesh , (100 + COS[frames])/10 , (100 + COS[frames])/10 ); rotate_sprite(tmu_badfactory.dstmesh , frames); move_sprite(tmu_badfactory.dstmesh , 320 , 240); tmu_badfactory.srcfbuf = sprite_data[x/40].data; tmu_badfactory.dstfbuf = vga_backbuffer; } else { init_sprite(tmu_badclouds.srcmesh,tmu_badclouds.dstmesh ,&sprite_data[x/40]); scale_sprite(tmu_badclouds.dstmesh , (100 + COS[frames])/10 , (100 + COS[frames])/10 ); rotate_sprite(tmu_badclouds.dstmesh , frames); move_sprite(tmu_badclouds.dstmesh , 320 , 240); tmu_badclouds.srcfbuf = sprite_data[x/40].data; tmu_badclouds.dstfbuf = vga_backbuffer; } /* tmu_clearscreen.srcfbuf = &black; tmu_clearscreen.dstfbuf = vga_backbuffer; tmu_wait = 0; tmu_submit_task(&tmu_clearscreen); while(!tmu_wait); */ tmu_wait = 0; tmu_submit_task(&tmu_badclouds); while(!tmu_wait); flush_bridge_cache(); vga_swap_buffers(); // demo_sleep(10); x += 1; frames+=5; if (frames > 360) frames = frames - 360; if (x == 240) {x = 0;quit++;} } return 0; }
void Stage::render(BITMAP *buffer) { clear_to_color(buffer, makecol(75, 75, 75)); if (bmpDrawOn) for (vector<Body*>::iterator it = world->bodyList.begin(); it != world->bodyList.end(); ++it) { Body *b = *it; BITMAP *bmp = b->bmp; if (!bmp) continue; Point p = b->getAllegPosition(); int x = p.x - (bmp->w / 2); int y = p.y - (bmp->h / 2); rotate_sprite(buffer, bmp, x, y, b->getAllegAngle()); } if (freeDraw->On) draw_sprite(buffer, freeDraw->bmp, 0, 0); if (customBox->On) draw_sprite(buffer, customBox->bmp, 0, 0); if (customCircle->On) draw_sprite(buffer, customCircle->bmp, 0, 0); if (customPolygon->On) draw_sprite(buffer, customPolygon->bmp, 0, 0); /*************************************************************************************************/ //Menu if (!cleanModeOn) { textprintf_centre_ex(buffer, font, SCREEN_W / 2, 40, GREEN, -1, "Hold TAB for menu"); textprintf_ex(buffer, font, 10, 15, GRAY, -1, "Body type:"); switch (bodyType) { case Random: textprintf_ex(buffer, font, 100, 15, BLUE, -1, "Random"); break; case Box: textprintf_ex(buffer, font, 100, 15, YELLOW, -1, "Box"); break; case Circle: textprintf_ex(buffer, font, 100, 15, YELLOW, -1, "Circle"); break; case Free_Draw: textprintf_ex(buffer, font, 100, 15, PURPLE, -1, "Free Draw"); break; case Custom_Box: textprintf_ex(buffer, font, 100, 15, PURPLE, -1, "Custom Box"); break; case Custom_Circle: textprintf_ex(buffer, font, 100, 15, PURPLE, -1, "Custom Circle"); break; case Custom_Polygon: textprintf_ex(buffer, font, 100, 15, PURPLE, -1, "Custom Polygon"); break; default: break; } textprintf_ex(buffer, font, 230, 15, GRAY, -1, "Static mode:"); if (world->staticModeOn) textprintf_ex(buffer, font, 340, 15, GREEN, -1, "On"); else textprintf_ex(buffer, font, 340, 15, RED, -1, "Off"); textprintf_ex(buffer, font, 400, 15, GRAY, -1, "Mouse lock:"); if (mouseLockOn) textprintf_ex(buffer, font, 500, 15, GREEN, -1, "On"); else textprintf_ex(buffer, font, 500, 15, RED, -1, "Off"); textprintf_ex(buffer, font, 600, 15, GRAY, -1, "Gravity: %.2f, %.2f", gravity.x, gravity.y); if (!world->simulateOn) textprintf_centre_ex(buffer, font, SCREEN_W / 2, 65, YELLOW, -1, "PAUSED"); textprintf_ex(buffer, font, 10, 40, GRAY, -1, "Bodies:"); textprintf_ex(buffer, font, 70, 40, world->bodyList.size() > 400 ? RED : GRAY, -1, "%d", world->bodyList.size()); dt = (int) (gtime - dt); if (dt == 0) dt = 1; int fps = 60 / dt; dt = gtime; textprintf_ex(buffer, font, 10, 65, GRAY, -1, "Approx. FPS:"); textprintf_ex(buffer, font, 110, 65, fps < 60 ? fps < (60 / 2) ? RED : YELLOW : GREEN, -1, "%d", fps); if (menuOn) { textprintf_ex(buffer, font, 10, 85, WHITE, -1, "Press keys 0-9 to choose options"); textprintf_ex(buffer, font, 10, 100, WHITE, -1, "0 : Reset"); textprintf_ex(buffer, font, 10, 110, WHITE, -1, "1 : Random bodies"); textprintf_ex(buffer, font, 10, 120, WHITE, -1, "2 : Box"); textprintf_ex(buffer, font, 10, 130, WHITE, -1, "3 : Circle"); textprintf_ex(buffer, font, 10, 140, WHITE, -1, "4 : Free draw"); textprintf_ex(buffer, font, 10, 150, WHITE, -1, "5 : Custom Box"); textprintf_ex(buffer, font, 10, 160, WHITE, -1, "6 : Destroy last body"); textprintf_ex(buffer, font, 10, 170, WHITE, -1, "7 : Toggle static mode"); textprintf_ex(buffer, font, 10, 180, WHITE, -1, "8 : Pause"); textprintf_ex(buffer, font, 10, 190, WHITE, -1, "9 : Toggle Mouse lock"); textprintf_ex(buffer, font, 10, 205, WHITE, -1, "MB1 : Make bodies"); textprintf_ex(buffer, font, 10, 215, WHITE, -1, "MB2 : Make bombs"); textprintf_ex(buffer, font, 10, 235, WHITE, -1, "H : Hide all text"); textprintf_ex(buffer, font, 10, 245, WHITE, -1, "C : Toggle cursor"); textprintf_ex(buffer, font, 10, 255, WHITE, -1, "A : Auto dump bodies"); textprintf_ex(buffer, font, 10, 265, WHITE, -1, "N : Destroy last non-static body"); textprintf_ex(buffer, font, 10, 275, WHITE, -1, "M : Destroy all non-static body"); textprintf_ex(buffer, font, 10, 285, WHITE, -1, "S : Toggle small bodies"); textprintf_ex(buffer, font, 10, 295, WHITE, -1, "V : Custom polygon"); textprintf_ex(buffer, font, 10, 305, WHITE, -1, "X : Custom circle"); textprintf_ex(buffer, font, 10, 315, WHITE, -1, "P : Pyramid show"); textprintf_ex(buffer, font, 10, 325, WHITE, -1, "Arrow keys : Adjust gravity"); } } /*************************************************************************************************/ if (cursorOn) draw_sprite(buffer, mouse_sprite, mouse_x, mouse_y); }
/////////////////////////////////////////////////////////////////// // // Function Name: refreshbmps // Description: Repaints the edges with new router coordinates. // /////////////////////////////////////////////////////////////////// void Edge::refreshbmps(bool useThread) { double dist, doubR1X, doubR1Y, doubR2X, doubR2Y; painted_usage = 0.0; painted_percent = -1; currX = 0; currY = 0; if (useThread) { r1x = threadZero->getRouterAt(sourceIndex) ->getXPixel(); // set coordinates of routers r1y = threadZero->getRouterAt(sourceIndex)->getYPixel(); r2x = threadZero->getRouterAt(destinationIndex)->getXPixel(); r2y = threadZero->getRouterAt(destinationIndex)->getYPixel(); } else { r1x = topoRouters[sourceIndex]->getXPixel(); // set coordinates of routers r1y = topoRouters[sourceIndex]->getYPixel(); r2x = topoRouters[destinationIndex]->getXPixel(); r2y = topoRouters[destinationIndex]->getYPixel(); } if (!useThread && r3x == r1x && r3y == r1y && r4x == r2x && r4y == r2y) return; else { r3x = r1x; r3y = r1y; r4x = r2x; r4y = r2y; if (r2x == r1x) { // straight up and down invunitX = 1.0; invunitY = 0.0; dist = abs(r2y - r1y); } else if (r2y == r1y) { // slope actually 0 invunitX = 0.0; invunitY = 1.0; dist = abs(r2x - r1x); } else { doubR1X = r1x; doubR1Y = r1y; doubR2X = r2x; doubR2Y = r2y; dist = sqrt((doubR2X - doubR1X) * (doubR2X - doubR1X) + (doubR2Y - doubR1Y) * (doubR2Y - doubR1Y)); // distance formula invunitX = -(r2y - r1y) / dist; // condense to inverse unit vector invunitY = (r2x - r1x) / dist; } double angle = atan((double)(r2y - r1y) / (double)(r2x - r1x)) * (256) / (2 * M_PI); if ((r1x == r2x || r1y == r2y) && sourceIndex > destinationIndex) { r1x -= 5 * invunitX; r1y -= 5 * invunitY; r2x -= 5 * invunitX; r2y -= 5 * invunitY; } else { r1x += 5 * invunitX; r1y += 5 * invunitY; r2x += 5 * invunitX; r2y += 5 * invunitY; } if (r2x < r1x) angle += 128.0; // for bitmap edges int distInt = ceil(dist); ALLEGRO_BITMAP *temp_bmp = al_create_bitmap(distInt, 13); ALLEGRO_BITMAP *temp_bmp2 = al_create_bitmap(distInt, distInt); if (r1x < r2x) putX = r1x; else putX = r2x; if (r1y < r2y) putY = r1y; else putY = r2y; int copyX = ((distInt - abs(r2x - r1x)) / 2) - 7; int copyY = ((distInt - abs(r2y - r1y)) / 2) - 7; if (copyX < 0) copyX = 0; if (copyY < 0) copyY = 0; for (int b = 0; b < 14; b++) { al_clear_to_color(temp_bmp, makecol(255, 0, 255)); stretch_blit(tailOriginals[b], temp_bmp, 0, 0, tailOriginals[b]->w, tailOriginals[b]->h, 15, 0, tailOriginals[b]->w, temp_bmp->h); stretch_blit(arrowOriginals[b], temp_bmp, 0, 0, arrowOriginals[b]->w, arrowOriginals[b]->h, distInt - 15 - arrowOriginals[b]->w, 0, arrowOriginals[b]->w, temp_bmp->h); stretch_blit(edgeOriginals[b], temp_bmp, 0, 0, edgeOriginals[b]->w, edgeOriginals[b]->h, 15 + tailOriginals[b]->w, 0, distInt - 30 - arrowOriginals[b]->w - tailOriginals[b]->w, temp_bmp->h); al_clear_to_color(temp_bmp2, makecol(255, 0, 255)); rotate_sprite(temp_bmp2, temp_bmp, 0, (temp_bmp2->h) / 2, itofix(angle)); al_destroy_bitmap(edgeBmps[b]); edgeBmps[b] = al_create_bitmap(abs(r2x - r1x) + 14, abs(r2y - r1y) + 14); al_clear_to_color(edgeBmps[b], makecol(255, 0, 255)); blit(temp_bmp2, edgeBmps[b], copyX, copyY, 0, 0, edgeBmps[0]->w, edgeBmps[0]->h); } al_destroy_bitmap(temp_bmp); al_destroy_bitmap(temp_bmp2); // end for bitmap edges } }
void alienrocket::drawTo(BITMAP* b, BITMAP* f[]){ if(color > 14){ color = 0; } if(fired){ rotate_sprite(b, f[color], fixtoi(x), fixtoi(y), angle); } color++; }