void Block::DrawPixel(int drawx, int drawy) { ALLEGRO_COLOR temp; if( tileShapeBasic==tiletype_shape_basic::Floor || tileShapeBasic==tiletype_shape_basic::Wall || tileShapeBasic==tiletype_shape_basic::Ramp || tileShapeBasic==tiletype_shape_basic::Stair ) { al_put_pixel(drawx, drawy, lookupMaterialColor(this->material.type, this->material.index)); } if(this->water.index) { if(this->water.type == 0) //water al_draw_pixel(drawx, drawy, al_map_rgba_f(0.6f, 0.85f, 0.92f, (float)water.index / 7.0f)); else al_draw_pixel(drawx, drawy, al_map_rgba_f(1.0f, 0.5f, 0.15f, (float)water.index / 7.0f)); } //Grass if(grasslevel > 0 && ( (tileMaterial == tiletype_material::GRASS_DARK) || (tileMaterial == tiletype_material::GRASS_DARK) || (tileMaterial == tiletype_material::GRASS_DRY) || (tileMaterial == tiletype_material::GRASS_DEAD))) { temp = lookupMaterialColor(WOOD, grassmat); al_draw_pixel(drawx, drawy, al_map_rgba_f(temp.r,temp.g, temp.b, (float)grasslevel/100.0f)); } }
void SpaceSim::DrawScreenNodes() { for(int y= 0 ; y<100; y++) { for(int x= 0 ; x<100; x++) { al_draw_pixel(x*200+1,y*200,al_map_rgb( 200,200,200)); al_draw_pixel(x*200-1,y*200,al_map_rgb( 200,200,200)); al_draw_pixel(x*200, y*200+1,al_map_rgb(200,200,200)); al_draw_pixel(x*200, y*200-1,al_map_rgb(200,200,200)); al_draw_pixel(x*200, y*200,al_map_rgb( 200,200,200)); } } };
void particle::render(double tx, double ty){ if(tracer){ al_draw_line( tx-x_vel, ty-y_vel, tx, ty, color, 0 ); }else{ al_draw_pixel( tx, ty, color); } }
void particle::render(){ if(tracer){ al_draw_line( x-x_vel, y-y_vel, x, y, color, 0 ); }else{ al_draw_pixel( x, y, color); } }
void Draw_body(b2Body* body, b2Vec2 camera) { float scale = 10; b2Vec2 position = scale*body->GetPosition() - camera; float32 angle = body->GetAngle(); al_draw_pixel(position.x, position.y, al_map_rgb_f(1, 0, 0)); for (b2Fixture* f = body->GetFixtureList(); f; f = f->GetNext()) { b2Shape* shape_base = f->GetShape(); if(shape_base->GetType() == b2Shape::e_polygon) { b2PolygonShape& shape = dynamic_cast<b2PolygonShape&>(*shape_base); int np = shape.GetVertexCount (); b2Vec2 pn = scale*shape.GetVertex(np-1); b2Vec2 ps, pe; ps.x = cos(angle)*pn.x - sin(angle)*pn.y; ps.y = sin(angle)*pn.x + cos(angle)*pn.y; for(int i=0; i<np; ++i) { pn = scale*shape.GetVertex(i); pe.x = cos(angle)*pn.x - sin(angle)*pn.y; pe.y = sin(angle)*pn.x + cos(angle)*pn.y; al_draw_line(position.x+ps.x, position.y+ps.y, position.x+pe.x, position.y+pe.y, al_map_rgb_f(1, 0, 0), 0); ps = pe; } } if(shape_base->GetType() == b2Shape::e_circle) { b2CircleShape& shape = dynamic_cast<b2CircleShape&>(*shape_base); al_draw_circle(position.x, position.y, shape.m_radius * scale, al_map_rgb_f(1, 0, 0), 0); } } }
void GameClass::DrawBlock (float x, float y, float xf, float yf) const { al_draw_filled_rectangle(x, y, xf, yf, cWhite); for (size_t i = 0; i < 20; i++) { float difX = cTileSize*(rand()%1001)/1000.0; float difY = cTileSize*(rand()%1001)/1000.0; al_draw_pixel(x + difX, y + difY, cBlack); } }
void draw_stars(){ // move the star fields al_clear_to_color(al_map_rgb(0,0,0)); al_draw_text(default_font, al_map_rgb(1,0,112), 0, 0, ALLEGRO_ALIGN_LEFT, "Press '+' or '-' to change speed."); al_draw_text(default_font, al_map_rgb(21,158,2), 320/2, 190, ALLEGRO_ALIGN_CENTRE, "Press 'Q' to exit."); for (int index=0; index<NUM_STARS; index++){ // erase the star al_draw_pixel(stars[index].x,stars[index].y,al_map_rgb(0,0,0)); // move the star and test for off screen condition // each star is in a different plane so test which plane star is // in so that proper velocity may be used switch(stars[index].plane) { case PLANE_1: // the slowest plane stars[index].x+=velocity_1; break; case PLANE_2: // the medium speed plane stars[index].x+=velocity_2; break; case PLANE_3: // the fastest plane (near) stars[index].x+=velocity_3; break; } // end switch // test if star went off screen if (stars[index].x > 319 ) // off right edge? stars[index].x=(stars[index].x-320); // wrap around else if (stars[index].x < 0) // off left edge? stars[index].x = (320+stars[index].x); // wrap around // draw the star at new position al_draw_pixel(stars[index].x,stars[index].y,stars[index].color); } // end for al_flip_display(); }
static mrb_value draw_pixel(mrb_state *mrb, mrb_value self) { mrb_float x; mrb_float y; ALLEGRO_COLOR *c; mrb_get_args(mrb, "ffd", &x, &y, &c, &mrbal_color_data_type); al_draw_pixel(x, y, *c); return mrb_nil_value(); }
static duk_ret_t js_Point(duk_context* ctx) { float x = duk_require_int(ctx, 0) + 0.5; float y = duk_require_int(ctx, 1) + 0.5; color_t color = duk_require_sphere_color(ctx, 2); if (!is_skipped_frame()) al_draw_pixel(x, y, nativecolor(color)); return 0; }
void Galaxy::draw() { al_draw_bitmap(background, 0, 0, 0); for (std::list<Star>::iterator star = stars.begin(); star != stars.end(); star++) { star->y += star->velocity; if (star->y > display_width) { star = stars.erase(star); } else { al_draw_pixel(star->x, star->y, star->color); } } createNewStar(); }
void draw_shoots(game *g) { ALLEGRO_TRANSFORM trans; al_identity_transform(&trans); al_use_transform(&trans); shoot *pt; pt = first_s; while(pt != NULL) { al_draw_pixel(pt->position->x, pt->position->y, SHOOT_COLOR); pt = pt->next; } }
void GameClass::DrawFloor (float x, float y, float xf, float yf) const { al_draw_filled_rectangle(x, y, xf, yf, cWhite); for (int i = 0; i < 5; i++) { float z = y + 2*i; al_draw_line(x, z, xf, z, cBlack, 0); } for (size_t i = 0; i < 20; i++) { float difX = 10 + (cTileSize-10)*(rand()%1001)/1000.0; float difY = 10 + (cTileSize-10)*(rand()%1001)/1000.0; al_draw_pixel(x + difX, y + difY, cBlack); } }
/*Desenha a imagem na janela @param ALLEGRO_DISPLAY *janela - janela onde ira desenhar a imagem unsigned char ** data - m atriz onde sera armazenado os bits int a - altura da imagem itn l - largura da imagem */ void desenha(ALLEGRO_DISPLAY *janela, unsigned char **data, int a, int l) { /*reajusta o tamanho da janela para a imagem aberta*/ resize(janela, a+50, l); int i, j; for (i=0; i<a; i++) { for(j=0; j<l; j++) { al_draw_pixel(j, i+50, al_map_rgb(data[i][j],data[i][j],data[i][j])); } } al_flip_display(); }
void drawPowerMeter(float px, float py, float width, float height, float value) { // Triangle float alpha = 0.7f; float heightNow = 1; float raiseHeightStep = height/width; int lightTheseBars = (width * value); int skipper=0; for (int ix = 0; ix < width; ix++) { if (skipper==4) { for (int iy = 0; iy < heightNow; iy++) { if (ix<lightTheseBars) al_draw_pixel(px+ix, py-iy,al_map_rgba_f(0.3*alpha, 0.3*alpha, 1.0*alpha, alpha)); //drawGlowDot(px+ix, py-iy,1.0f); else //darker //drawGlowDot(px+ix, py-iy,0.3f); al_draw_pixel(px+ix, py-iy,al_map_rgba_f(0.0*alpha, 0.0*alpha, 0.7*alpha, alpha)); } skipper=0; } skipper++; heightNow += raiseHeightStep; } }
void shal_draw_pixel(float x, float y, float color_r, float color_g, float color_b, float color_a) { ALLEGRO_COLOR color; color.r = color_r; color.g = color_g; color.b = color_b; color.a = color_a; return al_draw_pixel(x, y, color); }
void graphics::draw_at (const entity_c &obj, var zoom, var x, var y) { if (!display) { return; } if (obj.type == ENTITY) { al_draw_filled_circle (x, y, obj.radius * zoom, obj.color); al_draw_pixel (x, y, obj.color); al_draw_text (hud.font, hud.text_col, x, y, ALLEGRO_ALIGN_LEFT, obj.name.c_str()); } else if (obj.type == HAB) { hab_c &hab = (hab_c&)obj; al_draw_filled_circle (x, y, hab.radius * zoom, hab.color); ALLEGRO_COLOR engine_color = al_color_name ("red"); var engine_radius = (hab.radius / 4); var engine_angle = 0.7 * M_PI; al_draw_filled_circle ( x + zoom * (hab.radius + engine_radius) * cos (hab.ang_pos + engine_angle), y + zoom * (hab.radius + engine_radius) * sin (hab.ang_pos + engine_angle), engine_radius * zoom, engine_color); al_draw_filled_circle ( x + zoom * (hab.radius + engine_radius) * cos (hab.ang_pos - engine_angle), y + zoom * (hab.radius + engine_radius) * sin (hab.ang_pos - engine_angle), engine_radius * zoom, engine_color); al_draw_filled_circle ( x + zoom * (hab.radius - engine_radius) * cos (hab.ang_pos + M_PI), y + zoom * (hab.radius - engine_radius) * sin (hab.ang_pos + M_PI), engine_radius * zoom, engine_color); al_draw_pixel (x, y, hab.color); } }
int draw_function_line(double x1, double x1_value, double x2, double x2_value, ALLEGRO_COLOR line_color) { if(x1_value >= min_visible_value && x1_value <= max_visible_value && x2_value >= min_visible_value && x2_value <= max_visible_value) { x1 = Y_axis_coord + (x1 * (double)Xscale); x1_value = X_axis_coord - (x1_value * (double)Yscale); //printf("x=%f y=%f\n", x1, x1_value); al_draw_pixel(x1, x1_value, line_color); //al_draw_line(x1, x1_value, x2, x2_value, al_map_rgb(255, 200, 200), 1); if(!((int)x2 % 100)) al_flip_display(); } return 0; }
void bg_draw() { al_set_target_bitmap(bg); std::vector<std::pair<int, int>> newstack; h = h+2.5; if (h > 360) h = 0; v = v - 1.0 / 144.9; if (v <= 0) bg_clear(); for (unsigned int i = 0; i < stack.size(); ++i) { int x = stack[i].first; int y = stack[i].second; float r, g, b; al_color_hsv_to_rgb(h, s, v, &r, &g, &b); al_draw_pixel(x, y, al_map_rgb_f(r,g,b)); if (x != 0 && tab[x - 1][y] != 1) { float prob = 0.001*(rand() % 1000); if (prob > p) { newstack.push_back(std::make_pair(x - 1, y)); } tab[x - 1][y] = 1; } if (x != MAP_SIZE-1 && tab[x + 1][y] != 1) { float prob = 0.001*(rand() % 1000); if (prob > p) { newstack.push_back(std::make_pair(x + 1, y)); } tab[x + 1][y] = 1; } if (y != 0 && tab[x][y-1] != 1) { float prob = 0.001*(rand() % 1000); if (prob > p) { newstack.push_back(std::make_pair(x, y-1)); } tab[x][y-1] = 1; } if (y != MAP_SIZE-1 && tab[x][y+1] != 1) { float prob = 0.001*(rand() % 1000); if (prob > p) { newstack.push_back(std::make_pair(x, y+1)); } tab[x][y+1] = 1; } } stack = newstack; al_set_target_backbuffer(okno); }
/* Renders the next frame in a GIF animation to the given position. * You need to call this in order on the same destination for frames * [0..gif->frames_count - 1] to properly render all the frames in the GIF. * The current target bitmap should have the same height as the animation, * and blending should be set to fully copy RGBA. */ void algif_render_frame(ALGIF_ANIMATION *gif, int frame, int xpos, int ypos) { int x, y, w, h; ALGIF_FRAME *f = &gif->frames[frame]; ALGIF_PALETTE *pal; if (frame == 0) { al_draw_filled_rectangle(xpos, ypos, xpos + gif->width, ypos + gif->height, al_map_rgba_f(0, 0, 0, 0)); } else { ALGIF_FRAME *p = &gif->frames[frame - 1]; if (p->disposal_method == 2) { al_draw_filled_rectangle(xpos + p->xoff, ypos + p->yoff, xpos + p->xoff + p->bitmap_8_bit->w, ypos + p->yoff + p->bitmap_8_bit->h, al_map_rgba_f(0, 0, 0, 0)); } else if (p->disposal_method == 3 && gif->store) { al_draw_bitmap_region(gif->store, xpos + p->xoff, ypos + p->yoff, p->bitmap_8_bit->w, p->bitmap_8_bit->h, xpos + p->xoff, ypos + p->yoff, 0); al_destroy_bitmap(gif->store); gif->store = NULL; } } w = f->bitmap_8_bit->w; h = f->bitmap_8_bit->h; if (f->disposal_method == 3) { if (gif->store) al_destroy_bitmap(gif->store); gif->store = al_clone_bitmap(al_get_target_bitmap()); } pal = &gif->frames[frame].palette; if (pal->colors_count == 0) pal = &gif->palette; for (y = 0; y < h; y++) { for (x = 0; x < w; x++) { int c = f->bitmap_8_bit->data[x + y * f->bitmap_8_bit->w]; if (c != f->transparent_index) { al_draw_pixel(xpos + f->xoff + x, ypos + f->yoff + y, al_map_rgb(pal->colors[c].r, pal->colors[c].g, pal->colors[c].b)); } } } }
void rysuj_funkcje(double min,double max){ ALLEGRO_COLOR kolor; double skala; if (abs(max) < abs(min)) { max = min; } skala = 400/max; std::cout << skala; for (float i = 20; i <= 800; i+=dokladnosc) { if (i-400>= p && i-400<= k) { kolor = niebieski; } else { kolor = czerwony; } al_draw_pixel(i, (-f(i-400)+400) , kolor); // al_draw_line(i, -f(i-400)+400, i+1, f(i+1-400), czerwony, .1); } }
void al_draw_pixel_w(float x, float y, ALLEGRO_COLOR *color) { return al_draw_pixel(x, y, *color); }
int main (int argc, char *argv[]) { al_init(); ALLEGRO_DISPLAY *display = al_create_display(640, 480); al_init_primitives_addon(); al_init_image_addon(); al_init_font_addon(); al_init_ttf_addon(); srand(time(NULL)); char* disappointed[] = {" Razocharovana sum!", " Tolkova losho kontrolno ne sum vijdala!", "Golqm murzel vi e nalegnal...", " Potresavashto!!"}; ALLEGRO_BITMAP *image = al_load_bitmap("pic.bmp"); ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue(); ALLEGRO_TIMER *timer = al_create_timer(1/60.0); al_register_event_source(event_queue, al_get_timer_event_source(timer)); ALLEGRO_FONT *font = al_load_font("Arial.ttf", 20, 0); int done = 0; int render = 0; int x = 375; int y = 340; int traveled_y = 0; int delay = 120; int time_elapsed = 0; int dir = -1; int move_left = 0; int traveled_x = 0; int time_elapsed2 = 0; int draw_text = 0; int random = 0; int should_draw_text = 0; al_start_timer(timer); while(!done) { ALLEGRO_EVENT event; al_wait_for_event(event_queue, &event); if(event.type == ALLEGRO_EVENT_TIMER) { if(x < 50) done = 1; if(traveled_y >= 75) { if(!draw_text) { random = rand() % 4; if(y < 350) should_draw_text = 1; } draw_text = 1; if(++time_elapsed >= delay) { traveled_y = 0; time_elapsed = 0; if(y <= 60 || y >= 375) { if(!move_left) { if(y <= 60) { if(traveled_x >= 50) { if(++time_elapsed2 >= delay) { traveled_x = 0; time_elapsed2 = 0; move_left = 1; } } else { x -= 3; traveled_x += 3; } } else if(y >= 375) { should_draw_text = 0; if(traveled_x >= 140) { if(++time_elapsed2 >= delay) { traveled_x = 0; time_elapsed2 = 0; move_left = 1; } } else { x -= 3; traveled_x += 3; } } time_elapsed = 120; traveled_y = 75; } else { dir *= -1; move_left = 0; } } } } else { draw_text = 0; should_draw_text = 0; y += 3 * dir; traveled_y += 3; } render = 1; } if(render) { al_draw_bitmap(image, 0, 0, 0); al_draw_pixel(x, y, al_map_rgb(255, 0, 0)); if(should_draw_text) { al_draw_text(font, al_map_rgb(255, 255, 255), 10, 450, 0, disappointed[random]); } al_flip_display(); al_clear_to_color(al_map_rgb(0, 0, 0)); render = 0; } } al_destroy_display(display); al_destroy_bitmap(image); al_destroy_event_queue(event_queue); al_destroy_timer(timer); return 0; }
int main( void ) { ALLEGRO_DISPLAY *display; ALLEGRO_KEYBOARD_STATE key_state; Point stars[3][NUM_STARS/3]; float speeds[3] = { 0.0001f, 0.05f, 0.15f }; ALLEGRO_COLOR colors[3]; long start, now, elapsed, frame_count; int total_frames = 0; double program_start; double length; int layer, star; if (!al_init()) { abort_app("Could not init Allegro.\n"); return 1; } al_install_keyboard(); display = al_create_display(WIDTH, HEIGHT); if (!display) { abort_app("Could not create display.\n"); return 1; } colors[0] = al_map_rgba(255, 100, 255, 128); colors[1] = al_map_rgba(255, 100, 100, 255); colors[2] = al_map_rgba(100, 100, 255, 255); for (layer = 0; layer < 3; layer++) { for (star = 0; star < NUM_STARS/3; star++) { Point *p = &stars[layer][star]; p->x = rand() % WIDTH; p->y = rand() % HEIGHT; } } start = al_get_time() * 1000; now = start; elapsed = 0; frame_count = 0; program_start = al_get_time(); while (1) { if (frame_count < (1000/TARGET_FPS)) { frame_count += elapsed; } else { int X, Y; frame_count -= (1000/TARGET_FPS); al_clear_to_color(al_map_rgb(0, 0, 0)); for (star = 0; star < NUM_STARS/3; star++) { Point *p = &stars[0][star]; al_draw_pixel(p->x, p->y, colors[0]); } al_lock_bitmap(al_get_backbuffer(display), ALLEGRO_PIXEL_FORMAT_ANY, 0); for (layer = 1; layer < 3; layer++) { for (star = 0; star < NUM_STARS/3; star++) { Point *p = &stars[layer][star]; // put_pixel ignores blending al_put_pixel(p->x, p->y, colors[layer]); } } /* Check that dots appear at the window extremes. */ X = WIDTH - 1; Y = HEIGHT - 1; al_put_pixel(0, 0, al_map_rgb_f(1, 1, 1)); al_put_pixel(X, 0, al_map_rgb_f(1, 1, 1)); al_put_pixel(0, Y, al_map_rgb_f(1, 1, 1)); al_put_pixel(X, Y, al_map_rgb_f(1, 1, 1)); al_unlock_bitmap(al_get_backbuffer(display)); al_flip_display(); total_frames++; } now = al_get_time() * 1000; elapsed = now - start; start = now; for (layer = 0; layer < 3; layer++) { for (star = 0; star < NUM_STARS/3; star++) { Point *p = &stars[layer][star]; p->y -= speeds[layer] * elapsed; if (p->y < 0) { p->x = rand() % WIDTH; p->y = HEIGHT; } } } al_rest(0.001); al_get_keyboard_state(&key_state); if (al_key_down(&key_state, ALLEGRO_KEY_ESCAPE)) break; } length = al_get_time() - program_start; if (length != 0) { printf("%d FPS\n", (int)(total_frames / length)); } al_destroy_display(display); return 0; }
void RenderTarget::drawDot(float x, float y, const ALLEGRO_COLOR &color) { setAsCurrent(); convertCoords(x, y); al_draw_pixel(x, y, color); }
void drawGlowDot(float px, float py, float glowValue) { float alpha = 0.9f; al_draw_pixel(px, py, al_map_rgba_f(0.0*alpha*glowValue, 0.0*alpha*glowValue, 1.0*glowValue*alpha, alpha)); alpha = 0.2f; al_draw_pixel(px, py, al_map_rgba_f(0.3*alpha*glowValue, 0.3*alpha*glowValue, 1.0*alpha*glowValue, alpha)); alpha = 0.9f; al_draw_pixel(px-1, py, al_map_rgba_f(.0*alpha*glowValue, .0*alpha*glowValue, 1.0*glowValue*alpha, alpha)); al_draw_pixel(px+1, py, al_map_rgba_f(.0*alpha*glowValue, .0*alpha*glowValue, 1.0*glowValue*alpha, alpha)); al_draw_pixel(px, py-1, al_map_rgba_f(.0*alpha*glowValue, .0*alpha*glowValue, 1.0*glowValue*alpha, alpha)); al_draw_pixel(px, py+1, al_map_rgba_f(.0*alpha*glowValue, .0*alpha*glowValue, 1.0*glowValue*alpha, alpha)); alpha = 0.8f; al_draw_pixel(px-1, py-1, al_map_rgba_f(0.0*alpha, 0.0*alpha, 0.8*glowValue*alpha, alpha)); al_draw_pixel(px+1, py-1, al_map_rgba_f(0.0*alpha, 0.0*alpha, 0.8*glowValue*alpha, alpha)); al_draw_pixel(px-1, py+1, al_map_rgba_f(0.0*alpha, 0.0*alpha, 0.8*glowValue*alpha, alpha)); al_draw_pixel(px+1, py+1, al_map_rgba_f(0.0*alpha, 0.0*alpha, 0.8*glowValue*alpha, alpha)); alpha = 0.3f; al_draw_pixel(px-2, py, al_map_rgba_f(0.0*alpha, 0.0*alpha, 0.3*glowValue*alpha, alpha)); al_draw_pixel(px+2, py, al_map_rgba_f(0.0*alpha, 0.0*alpha, 0.3*glowValue*alpha, alpha)); al_draw_pixel(px, py-2, al_map_rgba_f(0.0*alpha, 0.0*alpha, 0.3*glowValue*alpha, alpha)); al_draw_pixel(px, py+2, al_map_rgba_f(0.0*alpha, 0.0*alpha, 0.3*glowValue*alpha, alpha)); }
static void mainloop(void) { ALLEGRO_EVENT_QUEUE *queue; ALLEGRO_TIMER *timer; float *buf; double pitch = 440; int i, si; int n = 0; bool redraw = false; for (i = 0; i < N; i++) { frequency[i] = 22050 * pow(2, i / (double)N); stream[i] = al_create_audio_stream(4, SAMPLES_PER_BUFFER, frequency[i], ALLEGRO_AUDIO_DEPTH_FLOAT32, ALLEGRO_CHANNEL_CONF_1); if (!stream[i]) { abort_example("Could not create stream.\n"); return; } if (!al_attach_audio_stream_to_mixer(stream[i], al_get_default_mixer())) { abort_example("Could not attach stream to mixer.\n"); return; } } queue = al_create_event_queue(); al_register_event_source(queue, al_get_keyboard_event_source()); for (i = 0; i < N; i++) { al_register_event_source(queue, al_get_audio_stream_event_source(stream[i])); } #ifdef ALLEGRO_POPUP_EXAMPLES if (textlog) { al_register_event_source(queue, al_get_native_text_log_event_source(textlog)); } #endif log_printf("Generating %d sine waves of different sampling quality\n", N); log_printf("If Allegro's resampling is correct there should be little variation\n", N); timer = al_create_timer(1.0 / 60); al_register_event_source(queue, al_get_timer_event_source(timer)); al_register_event_source(queue, al_get_display_event_source(display)); al_start_timer(timer); while (n < 60 * frequency[0] / SAMPLES_PER_BUFFER * N) { ALLEGRO_EVENT event; al_wait_for_event(queue, &event); if (event.type == ALLEGRO_EVENT_AUDIO_STREAM_FRAGMENT) { for (si = 0; si < N; si++) { buf = al_get_audio_stream_fragment(stream[si]); if (!buf) { continue; } for (i = 0; i < SAMPLES_PER_BUFFER; i++) { double t = samplepos[si]++ / (double)frequency[si]; buf[i] = sin(t * pitch * ALLEGRO_PI * 2) / N; } if (!al_set_audio_stream_fragment(stream[si], buf)) { log_printf("Error setting stream fragment.\n"); } n++; log_printf("%d", si); if ((n % 60) == 0) log_printf("\n"); } } if (event.type == ALLEGRO_EVENT_TIMER) { redraw = true; } if (event.type == ALLEGRO_EVENT_KEY_DOWN && event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) { break; } if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { break; } #ifdef ALLEGRO_POPUP_EXAMPLES if (event.type == ALLEGRO_EVENT_NATIVE_DIALOG_CLOSE) { break; } #endif if (redraw &&al_is_event_queue_empty(queue)) { ALLEGRO_COLOR c = al_map_rgb(0, 0, 0); int i; al_clear_to_color(al_map_rgb_f(1, 1, 1)); for (i = 0; i < 640; i++) { al_draw_pixel(i, 50 + waveform[i] * 50, c); } al_flip_display(); redraw = false; } } for (si = 0; si < N; si++) { al_drain_audio_stream(stream[si]); } log_printf("\n"); al_destroy_event_queue(queue); }
int main(int argc, char *argv[]) { int c; while((c = getopt(argc, argv, "hv")) != -1) { switch(c) { case 'h': puts(HELP); return 0; case 'v': printf("version %.1f\n", PROGRAM_VERSION); return 0; } } if(!al_init()) { fprintf(stderr, "failed to initialize allegro!\n"); return -1; } if(argc == 2 && !strcmp(argv[1], "-v")) { printf("version %.1f\n", PROGRAM_VERSION); return 0; } bool key[5] = {false, false, false, false, false}; bool doexit = false; bool redraw = true; timer = al_create_timer(1.0 / FPS); if(!timer) { fprintf(stderr, "couldn't initialize timer.\n"); return -1; } display = al_create_display(SCREEN_W, SCREEN_H); if(!display) { fprintf(stderr, "failed to create the display.\n"); al_destroy_timer(timer); return -1; } al_set_window_title(display, "blasteroids"); al_init_primitives_addon(); if(!al_install_keyboard()) { fprintf(stderr, "failed to initialize keyboard.\n"); al_destroy_display(display); al_destroy_timer(timer); return -1; } /* Making the sky look like sky */ colors[0] = al_map_rgba(255, 100, 255, 128); colors[1] = al_map_rgba(255, 100, 100, 255); colors[2] = al_map_rgba(100, 100, 255, 255); for (layer = 0; layer < 3; layer++) { for (star = 0; star < NUM_STARS/3; star++) { Point *p = &stars[layer][star]; p->x = rand() % SCREEN_W; p->y = rand() % SCREEN_H; } } start = al_get_time() * 1000; now = start; elapsed = 0; frame_count = 0; program_start = al_get_time(); /* done with the sky. Now making the ship. */ Spaceship *ship = init_ship(); List *a = (List *)summon_asteroids(NUMBER_ASTEROIDS); ListElmt *astElmt = list_head(a); if(!ship) { fprintf(stderr, "couldn't create bitmap.\n"); al_destroy_timer(timer); al_destroy_display(display); return -1; } Blast *blast = init_blast(ship->sx, ship->sy, ship->heading); event_queue = al_create_event_queue(); if(!event_queue) { fprintf(stderr, "failed to create event queue.\n"); al_destroy_display(display); al_destroy_timer(timer); return -1; } al_register_event_source(event_queue, al_get_keyboard_event_source()); al_register_event_source(event_queue, al_get_display_event_source(display)); al_register_event_source(event_queue, al_get_timer_event_source(timer)); al_start_timer(timer); while(!doexit) { /* animate the sky, just sky, starts, but NOT objects. */ ALLEGRO_EVENT ev; al_wait_for_event(event_queue, &ev); if(ev.type == ALLEGRO_EVENT_TIMER) { if(key[UP]) ship->speed += 0.04; if(key[RIGHT]) ship->heading += 1.0f; if(key[DOWN]) if(ship->speed > 0.05) ship->speed -= 0.04; if(key[LEFT]) ship->heading -= 1.0f; fly_ship(ship); // fire ze missile if(key[SPACE]) { blast->sx = ship->sx; blast->sy = ship->sy; blast->heading = ship->heading; blast->gone = 0; } float theta = head2theta(blast->heading); blast->sx += blast->speed * cos(theta); if(blast->sx <= 0 || blast->sx >= SCREEN_W) { blast->gone = 1; } blast->sy += blast->speed * sin(theta); if(blast->sy <= 0 || blast->sy >= SCREEN_H) { blast->gone = 1; } /* loop through the list of asteroids */ astElmt = (astElmt->next)?astElmt->next : list_head(a); Asteroid *aster = astElmt->aster; /* asteroid eternity */ if(aster->sx < 0 || aster->sx > SCREEN_W - 33) aster->sx = 0; if(aster->sy < 0 || aster->sy > SCREEN_H) aster->sy = 0; aster->twist += aster->rot_velocity; /* Fuzzy movement */ if((int)aster->sx % 3 == 0) aster->sx += aster->speed; aster->sx += 0.9; if((int)aster->sy % 5 == 3) aster->sy += aster->speed; aster->sy += 0.9; aster->twist += 0.4; /* detect alteroid collision, but only if 5 seconds have passed since the last Death */ Box s = {{ship->sx, ship->sy}, 16.0f, 20.0f}; Box a = {{aster->sx, aster->sy}, 45.0f, 40.0f}; if(ship->heading != -90.0f) { if(!aster->gone && !ship->gone && is_collision(&s, &a)) { ship->color = al_map_rgb(0, 0, 255); } } /* detect asteroid being shot */ Box b = {{blast->sx, blast->sy}, 120.0f, 3.0f}; if(!(blast->gone) && !(aster->gone) && is_collision(&b, &a)) { aster->gone = 1; } redraw = true; } else if(ev.type == ALLEGRO_EVENT_KEY_DOWN) { switch(ev.keyboard.keycode) { case ALLEGRO_KEY_UP: key[UP] = true; break; case ALLEGRO_KEY_RIGHT: key[RIGHT] = true; break; case ALLEGRO_KEY_DOWN: key[DOWN] = true; break; case ALLEGRO_KEY_LEFT: key[LEFT] = true; break; case ALLEGRO_KEY_SPACE: key[SPACE] = true; break; } } else if(ev.type == ALLEGRO_EVENT_KEY_UP) { switch(ev.keyboard.keycode) { case ALLEGRO_KEY_UP: key[UP] = false; break; case ALLEGRO_KEY_RIGHT: key[RIGHT] = false; break; case ALLEGRO_KEY_DOWN: key[DOWN] = false; break; case ALLEGRO_KEY_LEFT: key[LEFT] = false; break; case ALLEGRO_KEY_SPACE: key[SPACE] = false; break; case ALLEGRO_KEY_Q: case ALLEGRO_KEY_ESCAPE: doexit = true; break; } } if(redraw && al_is_event_queue_empty(event_queue)) { redraw = false; al_clear_to_color(al_map_rgb(0, 0, 0)); if (frame_count < (1000/TARGET_FPS)) { frame_count += elapsed; } else { int X, Y; frame_count -= (1000/TARGET_FPS); for (star = 0; star < NUM_STARS/3; star++) { Point *p = &stars[0][star]; al_draw_pixel(p->x, p->y, colors[0]); } /* al_lock_bitmap(al_get_backbuffer(display), ALLEGRO_PIXEL_FORMAT_ANY, 0); */ for (layer = 1; layer < 3; layer++) { for (star = 0; star < NUM_STARS/3; star++) { Point *p = &stars[layer][star]; // put_pixel ignores blending al_put_pixel(p->x, p->y, colors[layer]); } } /* Check that dots appear at the window extremes. */ X = SCREEN_W - 1; Y = SCREEN_H - 1; al_put_pixel(0, 0, al_map_rgb_f(1, 1, 1)); al_put_pixel(X, 0, al_map_rgb_f(1, 1, 1)); al_put_pixel(0, Y, al_map_rgb_f(1, 1, 1)); al_put_pixel(X, Y, al_map_rgb_f(1, 1, 1)); /* al_unlock_bitmap(al_get_backbuffer(display)); */ total_frames++; } now = al_get_time() * 1000; elapsed = now - start; start = now; for (layer = 0; layer < 3; layer++) { for (star = 0; star < NUM_STARS/3; star++) { Point *p = &stars[layer][star]; p->y -= speeds[layer] * elapsed; if (p->y < 0) { p->x = rand() % SCREEN_W; p->y = SCREEN_H; } } } draw_ship(ship); if(!blast->gone) { draw_blast(blast); } draw_asteroids(a); al_flip_display(); } } length = al_get_time() - program_start; /* printf("Length = %f\n", length); */ al_destroy_timer(timer); al_destroy_display(display); al_destroy_event_queue(event_queue); return 0; }
void Projectile::render() const { al_draw_pixel(pos.x, pos.y, WHITE); }
static ALLEGRO_COLOR test(ALLEGRO_COLOR src_col, ALLEGRO_COLOR dst_col, ALLEGRO_COLOR blend, int src_format, int dst_format, int src, int dst, int src_a, int dst_a, int operation, bool verbose) { ALLEGRO_COLOR result; ALLEGRO_BITMAP *dst_bmp; al_set_new_bitmap_format(dst_format); al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP); al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO, al_map_rgb_f(1, 1, 1)); dst_bmp = al_create_bitmap(1, 1); al_set_target_bitmap(dst_bmp); al_clear_to_color(dst_col); if (operation == 0) { ALLEGRO_BITMAP *src_bmp; al_set_new_bitmap_format(src_format); src_bmp = al_create_bitmap(1, 1); al_set_target_bitmap(src_bmp); al_clear_to_color(src_col); al_set_target_bitmap(dst_bmp); al_set_separate_blender(ALLEGRO_ADD, src, dst, ALLEGRO_ADD, src_a, dst_a, blend); al_draw_bitmap(src_bmp, 0, 0, 0); al_destroy_bitmap(src_bmp); } else if (operation == 1) { al_set_separate_blender(ALLEGRO_ADD, src, dst, ALLEGRO_ADD, src_a, dst_a, blend); al_draw_pixel(0, 0, src_col); } else if (operation == 2) { al_set_separate_blender(ALLEGRO_ADD, src, dst, ALLEGRO_ADD, src_a, dst_a, blend); al_draw_line(0, 0, 1, 1, src_col, 0); } result = al_get_pixel(dst_bmp, 0, 0); if (test_display) { al_set_target_bitmap(al_get_backbuffer()); al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO, al_map_rgb_f(1, 1, 1)); al_draw_bitmap(dst_bmp, 0, 0, 0); } al_destroy_bitmap(dst_bmp); if (!verbose) return result; printf("---\n"); printf("test id: %d\n", test_index); printf("source : "); print_color(src_col); printf(" %s format=%d mode=%d alpha=%d\n", operation == 0 ? "bitmap" : operation == 1 ? "pixel" : "prim", src_format, src, src_a); printf("destination: "); print_color(dst_col); printf(" format=%d mode=%d alpha=%d\n", dst_format, dst, dst_a); printf("blender : "); print_color(blend); printf("\n"); printf("result : "); print_color(result); printf("\n"); return result; }