void Castle::draw() { //Dibuja el castillo en el frame actual al_draw_scaled_rotated_bitmap(image[frame], xcenter, ycenter, hitbox->x, hitbox->y,hitbox->scale,hitbox->scale,0, 0); // al_draw_filled_rectangle(hitbox->x, hitbox->y,hitbox->x+hitbox->width, hitbox->y + hitbox->height,al_map_rgb(150,0,0)); }
static int mallegro_Poll(void) { #if _ANDROID_ if(al_is_bitmap_locked(scrmem)){ al_unlock_bitmap(scrmem); al_set_target_bitmap(al_get_backbuffer(display)); //al_draw_bitmap(scrmem, 0, 0, 0); al_draw_scaled_rotated_bitmap(scrmem, 0, 0, 0, 0, zoomfactor, zoomfactor, 0, 0); //al_draw_scaled_rotated_bitmap(scrmem, 0, al_get_bitmap_height(al_get_backbuffer(display)), 0, 0, 2, 2, ALLEGRO_PI/2, 0); //al_draw_scaled_rotated_bitmap(scrmem, 0, 500, 0, 0, 3, 3, ALLEGRO_PI/2, 0); //would have to recalculate mouse al_flip_display(); } #else if(al_is_bitmap_locked(display_bitmap)) { al_unlock_bitmap(display_bitmap); al_flip_display(); } #endif if (!al_is_mouse_installed()) return 0; if (al_peek_next_event(a_event_queue_m, &a_event)) return 1; //read event in read function return 0; }
void obj_AI_Bubble::Draw() { //al_draw_scaled_rotated_bitmap(image, 104, 104, (x-_camX)*(1/_zoom), (y-_camY)*(1/_zoom), (1.0f/96.0f) * radius, (1.0f/96.0f) * radius,0, 0); //al_draw_scaled_bitmap(image, 0, 0, 208, 208, x-(104*(1/96.f)*radius*(1/_zoom)), y-(104*(1/96.f)*radius*(1/_zoom)),208*(1/96.f)*radius*(1/_zoom),208*(1/96.f)*radius*(1/_zoom),0); al_draw_tinted_scaled_rotated_bitmap(imageRed,al_map_rgba(r,r,r,r),104,104,x,y,(1/96.f)*radius,(1/96.f)*radius,0,0); al_draw_tinted_scaled_rotated_bitmap(imageGreen,al_map_rgba(g,g,g,g),104,104,x,y,(1/96.f)*radius,(1/96.f)*radius,0,0); al_draw_scaled_rotated_bitmap(image,104,104,x,y,(1.0/96.f)*radius,(1.0/96.f)*radius,0,0); }
void Image::draw_in_another_target() { const Type_pos size_in_axe_x=(_V_size_x*_V_scale_x); const Type_pos size_in_axe_y=(_V_size_y*_V_scale_y); al_draw_scaled_rotated_bitmap(_V_bitmap,_V_size_x/2,_V_size_y/2, _V_pos_x+(!_V_centering_option_x*(size_in_axe_x/2)), _V_pos_y+(!_V_centering_option_y*(size_in_axe_y/2)), _V_scale_x,_V_scale_y,_V_angle,_V_flag); }
void PhysicsBody::draw() { if (bodyBitMap != nullptr) { b2Vec2 bodyPos = body->GetPosition(); int y = -(bodyPos.y - worldManager->getMeterWorldY()) * B2D_SCALE; al_draw_scaled_rotated_bitmap(bodyBitMap, (bitmapW / 2.0), (bitmapH / 2.0), (bodyPos.x - worldManager->getMeterWorldX()) * B2D_SCALE, y, (w * B2D_SCALE) / bitmapW, (h * B2D_SCALE) / bitmapH, -body->GetAngle(), NULL); } }
void SubBitmap::draw() { const Type_pos size_in_axe_x=(_V_size_x*bitmap_scale_x*_V_scale_x); const Type_pos size_in_axe_y=(_V_size_y*bitmap_scale_y*_V_scale_y); al_draw_scaled_rotated_bitmap(_V_bitmap,_V_size_x/2,_V_size_y/2, _V_pos_x+(!_V_centering_option_x*(size_in_axe_x/2)), _V_pos_y+(!_V_centering_option_y*(size_in_axe_y/2)), bitmap_scale_x*_V_scale_x,bitmap_scale_y*_V_scale_y,_V_angle,_V_flag); }
void DrawInput(const Input* const input) { float bar_bitmap_height = al_get_bitmap_height(input->bar_bitmap); al_draw_scaled_bitmap(input->bar_bitmap, 0, 0, input->strength.value * input->strength_scale1, bar_bitmap_height, input->bar_pos.x, input->bar_pos.y, input->strength.value * input->strength_scale2, BAR_HEIGHT, 0); float cx = 0; float cy = al_get_bitmap_height(input->arrow_bitmap) / 2; al_draw_scaled_rotated_bitmap(input->arrow_bitmap, cx, cy, input->arrow_pos.x, input->arrow_pos.y, input->arrow_scale.x, input->arrow_scale.y, DegToRad(input->angle), 1); }
void ship_draw(const ship *s) { // draw the bullets bullet_draw(s->bullets); // draw the ship const uint32_t bitmap_width = al_get_bitmap_width(s->bitmap); const uint32_t bitmap_height = al_get_bitmap_height(s->bitmap); if (s->attr.is_immune) { const double time_passed = al_get_time() - s->attr.time_stamp; if (time_passed - floor(time_passed) < 0.5) { al_draw_tinted_scaled_rotated_bitmap(s->bitmap, color_gray(), bitmap_width / 2, bitmap_height / 2, s->center.x, s->center.y, SHIP_SIZE / bitmap_width, SHIP_SIZE / bitmap_height, s->direction, 0); } else { al_draw_scaled_rotated_bitmap(s->bitmap, bitmap_width / 2, bitmap_height / 2, s->center.x, s->center.y, SHIP_SIZE / bitmap_width, SHIP_SIZE / bitmap_height, s->direction, 0); } } else { al_draw_scaled_rotated_bitmap(s->bitmap, bitmap_width / 2, bitmap_height / 2, s->center.x, s->center.y, SHIP_SIZE / bitmap_width, SHIP_SIZE / bitmap_height, s->direction, 0); } #ifdef DEBUG al_draw_circle(s->center.x, s->center.y, 5, al_map_rgb(255, 0, 0), 3); #endif }
static int allua_Bitmap_draw_scaled_rotated(lua_State * L) { ALLUA_bitmap bitmap = allua_check_bitmap(L, 1); float cx = luaL_checknumber(L, 2); float cy = luaL_checknumber(L, 3); float dx = luaL_checknumber(L, 4); float dy = luaL_checknumber(L, 5); float scalex = luaL_checknumber(L, 6); float scaley = luaL_checknumber(L, 7); float angle = luaL_checknumber(L, 8); int flags = luaL_checkint(L, 9); al_draw_scaled_rotated_bitmap(bitmap, cx, cy, dx, dy, scalex, scaley, angle, flags); return 0; }
static void step(enum Mode mode, ALLEGRO_BITMAP *b2) { switch (mode) { case ALL: break; case PLAIN_BLIT: al_draw_bitmap(b2, 0, 0, 0); break; case SCALED_BLIT: al_draw_scaled_bitmap(b2, 0, 0, 320, 200, 0, 0, 640, 480, 0); break; case ROTATE_BLIT: al_draw_scaled_rotated_bitmap(b2, 10, 10, 10, 10, 2.0, 2.0, ALLEGRO_PI/30, 0); break; } }
/* Draw our example scene. */ static void draw(void) { float xs, ys, a; double dt = 0; double t = al_get_time(); if (last_time > 0) { dt = t - last_time; } last_time = t; al_set_target_bitmap(target); al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA); al_draw_filled_rectangle(x, y, x + RW, y + RH, al_map_rgba_f(1, 0, 0, 1)); al_draw_filled_rectangle(0, 0, W, H, al_map_rgba_f(1, 1, 0, 0.1)); x += dx * dt; if (x < 0) { x = 0; dx = -dx; } if (x + RW > W) { x = W - RW; dx = -dx; } y += dy * dt; if (y < 0) { y = 0; dy = -dy; } if (y + RH > H) { y = H - RH; dy = -dy; } al_set_target_backbuffer(display); al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO); al_clear_to_color(al_map_rgba_f(0, 0, 1, 1)); xs = 1 + 0.2 * sin(t * ALLEGRO_PI * 2); ys = 1 + 0.2 * sin(t * ALLEGRO_PI * 2); a = t * ALLEGRO_PI * 2 / 3; al_draw_scaled_rotated_bitmap(target, W / 2, H / 2, 320, 240, xs, ys, a, 0); }
//Offsets are the map offset void CharacterSpawn::DrawObjectRotate(int xOffset, int yOffset) { //0.8 if (hasImage_ && hasColor_) { al_draw_tinted_scaled_rotated_bitmap( image_->GetImage(), chosenColor_, image_->GetImageWidth() / 2.0, image_->GetImageHeight() / 2.0, (currentPositionY_ + width_ / 2)*Constants::TileSize() + xOffset, (currentPositionY_ + height_ / 2)*Constants::TileSize() + yOffset, width_*Constants::TileSize() / (image_->GetImageWidth()*1.0), height_*Constants::TileSize() / (image_->GetImageHeight()*1.0), currentRotation_, 0 ); } else if (hasImage_) { al_draw_scaled_rotated_bitmap( image_->GetImage(), image_->GetImageWidth() / 2.0, image_->GetImageHeight() / 2.0, (currentPositionY_ + width_ / 2)*Constants::TileSize() + xOffset, (currentPositionY_ + height_ / 2)*Constants::TileSize() + yOffset, width_*Constants::TileSize() / (image_->GetImageWidth()*1.0), height_*Constants::TileSize() / (image_->GetImageHeight()*1.0), currentRotation_, 0 ); } };
static mrb_value bitmap_draw_scaled_rotated(mrb_state *mrb, mrb_value self) { ALLEGRO_BITMAP *b; mrb_float cx; mrb_float cy; mrb_float dx; mrb_float dy; mrb_float xscale; mrb_float yscale; mrb_float angle; mrb_sym flag1; mrb_sym flag2; int argc; int flags; Check_Destroyed(mrb, self, bitmap, b); argc = mrb_get_args(mrb, "fffffff|nn", &cx, &cy, &dx, &dy, &xscale, &yscale, &angle, &flag1, &flag2); flags = argc > 7 ? mrbal_bitmap_get_flags(mrb, argc, flag1, flag2) : 0; al_draw_scaled_rotated_bitmap(b, cx, cy, dx, dy, xscale, yscale, angle, flags); return mrb_nil_value(); }
void Peacemaker::render(Renderer *renderer, Gamestate *state) { std::string mainsprite; double dir = aimdirection; Mccree *c = state->get<Mccree>(state->get<Player>(owner)->character); if (firinganim.active()) { mainsprite = firinganim.getframepath(); } else if (reloadanim.active()) { mainsprite = reloadanim.getframepath(); dir = 3.1415*c->isflipped; } else if (fthanim.active()) { mainsprite = fthanim.getframepath(); } else { mainsprite = c->getcharacterfolder()+"arm/1"; } ALLEGRO_BITMAP *sprite = renderer->spriteloader.requestsprite(mainsprite); int spriteoffset_x = renderer->spriteloader.get_spriteoffset_x(mainsprite); int spriteoffset_y = renderer->spriteloader.get_spriteoffset_y(mainsprite); Rect spritedimensions = renderer->spriteloader.get_rect(mainsprite); al_set_target_bitmap(renderer->midground); if (c->weaponvisible(state)) { if (c->isflipped) { al_draw_scaled_rotated_bitmap(sprite, getattachpoint_x()+spriteoffset_x, getattachpoint_y()+spriteoffset_y, x - renderer->cam_x, y - renderer->cam_y, 1, -1, dir, 0); } else { al_draw_rotated_bitmap(sprite, getattachpoint_x()+spriteoffset_x, getattachpoint_y()+spriteoffset_y, x - renderer->cam_x, y - renderer->cam_y, dir, 0); } } }
void Character::DrawObjectRotate(float mapXOffset, float mapYOffset) { //0.8 if (hasImage_ && hasColor_) { al_draw_tinted_scaled_rotated_bitmap( imageBundle_[0].GetImageStateGroupDictionary()[0]->GetImageDictionary()[0]->GetImage(), chosenColor_, imageBundle_[0].GetImageStateGroupDictionary()[0]->GetImageDictionary()[0]->GetImageWidth() / 2.0, imageBundle_[0].GetImageStateGroupDictionary()[0]->GetImageDictionary()[0]->GetImageHeight() / 2.0, (currentPositionX_ + width_ / 2)*Constants::TileSize() + mapXOffset, (currentPositionY_ + height_ / 2)*Constants::TileSize() + mapYOffset, width_*Constants::TileSize() / (imageBundle_[0].GetImageStateGroupDictionary()[0]->GetImageDictionary()[0]->GetImageWidth()*1.0), height_*Constants::TileSize() / (imageBundle_[0].GetImageStateGroupDictionary()[0]->GetImageDictionary()[0]->GetImageHeight()*1.0), currentRotation_, 0 ); } else if (hasImage_) { al_draw_scaled_rotated_bitmap( imageBundle_[0].GetImageStateGroupDictionary()[0]->GetImageDictionary()[0]->GetImage(), imageBundle_[0].GetImageStateGroupDictionary()[0]->GetImageDictionary()[0]->GetImageWidth() / 2.0, imageBundle_[0].GetImageStateGroupDictionary()[0]->GetImageDictionary()[0]->GetImageHeight() / 2.0, (currentPositionX_ + width_ / 2)*Constants::TileSize() + mapXOffset, (currentPositionY_ + height_ / 2)*Constants::TileSize() + mapYOffset, width_*Constants::TileSize() / (imageBundle_[0].GetImageStateGroupDictionary()[0]->GetImageDictionary()[0]->GetImageWidth()*1.0), height_*Constants::TileSize() / (imageBundle_[0].GetImageStateGroupDictionary()[0]->GetImageDictionary()[0]->GetImageHeight()*1.0), currentRotation_, 0 ); } };
int main(int argc, char *argv[]) { ALLEGRO_DISPLAY *display = NULL; ALLEGRO_EVENT_QUEUE *evqueue = NULL; ALLEGRO_TIMER *timer = NULL; ALLEGRO_KEYBOARD_STATE keyboard_state; ALLEGRO_EVENT event; ALLEGRO_FONT *font; ALLEGRO_BITMAP *clock_hand, *clock_quadrant, *bow, *sword; float clock_ray = 0, clock_angle = 0; int clock_ray_alpha; float soul_interval = SOUL_TIME_INTERVAL; FuzzyPlayer *player, *cpu; FuzzyGame * game; bool running = true; bool redraw = true; int map_x = 13*16, map_y = 5*16; int screen_width = WINDOW_WIDTH; int screen_height = WINDOW_HEIGHT; double curtime; /* Initialization */ fuzzy_iz_error(al_init(), "Failed to initialize allegro"); fuzzy_load_addon("image", al_init_image_addon()); fuzzy_load_addon("primitives", al_init_primitives_addon()); fuzzy_load_addon("keyboard", al_install_keyboard()); fuzzy_load_addon("mouse", al_install_mouse()); al_init_font_addon(); fuzzy_iz_error(timer = al_create_timer(1.0 / FPS), "Cannot create FPS timer"); fuzzy_iz_error(evqueue = al_create_event_queue(), "Cannot create event queue"); fuzzy_iz_error(display = al_create_display(screen_width, screen_height), "Cannot initialize display"); al_set_window_title(display, WINDOW_TITLE); fuzzy_iz_error(font = al_load_font(fuzzy_res(FONT_FOLDER, "fixed_font.tga"), 0, 0), "Cannot load 'fixed_font.tga'"); clock_hand = al_load_bitmap(fuzzy_res(PICTURE_FOLDER, "clock_hand.png")); fuzzy_iz_error(clock_hand, "Cannot load clock handle"); clock_quadrant = al_load_bitmap(fuzzy_res(PICTURE_FOLDER, "clock_quadrant.png")); fuzzy_iz_error(clock_hand, "Cannot load clock quadrant"); bow = al_load_bitmap(fuzzy_res(PICTURE_FOLDER, "bow.png")); fuzzy_iz_error(clock_hand, "Cannot load bow image"); sword = al_load_bitmap(fuzzy_res(PICTURE_FOLDER, "sword.png")); fuzzy_iz_error(clock_hand, "Cannot load sword image"); /* Queue setup */ al_register_event_source(evqueue, al_get_display_event_source(display)); al_register_event_source(evqueue, al_get_timer_event_source(timer)); al_register_event_source(evqueue, al_get_keyboard_event_source()); al_register_event_source(evqueue, al_get_mouse_event_source()); /* Game setup */ game = fuzzy_game_new("level000.tmx"); player = fuzzy_player_new(game, FUZZY_PLAYER_LOCAL, "Dolly"); cpu = fuzzy_player_new(game, FUZZY_PLAYER_CPU, "CPU_0"); fuzzy_chess_add(game, player, FUZZY_FOO_LINK, 34, 30); fuzzy_chess_add(game, player, FUZZY_FOO_LINK, 33, 30); fuzzy_chess_add(game, cpu, FUZZY_FOO_LINK, 40, 30); bool showing_area = false; FuzzyChess *chess, *focus = NULL; al_clear_to_color(al_map_rgb(0, 0, 0)); al_draw_bitmap(game->map->bitmap, -map_x, -map_y, 0); al_flip_display(); #if DEBUG ALLEGRO_BITMAP *icon; int fps, fps_accum; double fps_time; icon = al_load_bitmap(fuzzy_res(PICTURE_FOLDER, "icon.tga")); if (icon) al_set_display_icon(display, icon); fps_accum = fps_time = 0; fps = FPS; #endif /* Server connection */ int svsock; //~ FuzzyMessage * sendmsg = fuzzy_message_new(); svsock = fuzzy_server_connect(FUZZY_DEFAULT_SERVER_ADDRESS, FUZZY_DEFAULT_SERVER_PORT); _aaa_menu(game, svsock); /* MAIN loop */ player->soul_time = al_get_time(); al_start_timer(timer); while (running) { /* wait until an event happens */ al_wait_for_event(evqueue, &event); switch (event.type) { case ALLEGRO_EVENT_TIMER: /* check soul ticks */ curtime = al_get_time(); while (curtime - player->soul_time >= soul_interval) { //~ fuzzy_debug("Soul tick!"); player->soul_time += soul_interval; player->soul_points += SOUL_POINTS_BOOST; clock_ray = 1; } clock_angle = (curtime - player->soul_time)/soul_interval * FUZZY_2PI; if (clock_ray) { clock_ray = (curtime - player->soul_time)/RAY_TIME_INTERVAL * 50 + 40; clock_ray_alpha = (curtime - player->soul_time)/RAY_TIME_INTERVAL*(55) + 200; if (clock_ray >= 90) clock_ray = 0; } al_get_keyboard_state(&keyboard_state); if (al_key_down(&keyboard_state, ALLEGRO_KEY_RIGHT)) { map_x += 5; if (map_x > (game->map->tot_width - screen_width)) map_x = game->map->tot_width - screen_width; } else if (al_key_down(&keyboard_state, ALLEGRO_KEY_LEFT)) { map_x -= 5; if (map_x < 0) map_x = 0; } else if (al_key_down(&keyboard_state, ALLEGRO_KEY_UP)) { map_y -= 5; if (map_y < 0) map_y = 0; } else if (al_key_down(&keyboard_state, ALLEGRO_KEY_DOWN)) { map_y += 5; if (map_y > (game->map->tot_height - screen_height)) map_y = game->map->tot_height - screen_height; } else if (al_key_down(&keyboard_state, ALLEGRO_KEY_O)) { soul_interval = fuzzy_max(0.1, soul_interval - 0.05); } else if (al_key_down(&keyboard_state, ALLEGRO_KEY_P)) { soul_interval += 0.05; } redraw = true; break; case ALLEGRO_EVENT_KEY_DOWN: if(! focus) break; _attack_area_off(); switch(event.keyboard.keycode) { case ALLEGRO_KEY_W: _chess_move(game, player, focus, focus->x, focus->y-1); break; case ALLEGRO_KEY_A: _chess_move(game, player, focus, focus->x-1, focus->y); break; case ALLEGRO_KEY_S: _chess_move(game, player, focus, focus->x, focus->y+1); break; case ALLEGRO_KEY_D: _chess_move(game, player, focus, focus->x+1, focus->y); break; case ALLEGRO_KEY_K: _attack_area_on(); break; case ALLEGRO_KEY_SPACE: /* switch attack type */ if (! focus) break; if (focus->atkarea == &FuzzyMeleeMan) focus->atkarea = &FuzzyRangedMan; else focus->atkarea = &FuzzyMeleeMan; break; } break; case ALLEGRO_EVENT_DISPLAY_CLOSE: running = false; break; case ALLEGRO_EVENT_KEY_UP: break; case ALLEGRO_EVENT_KEY_CHAR: break; case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN: if(event.mouse.button == RIGHT_BUTTON) { _attack_area_on(); } else if(event.mouse.button == LEFT_BUTTON) { /* world to tile coords */ int tx = (event.mouse.x+map_x) / game->map->tile_width; int ty = (event.mouse.y+map_y) / game->map->tile_height; #ifdef DEBUG printf("SELECT %d %d\n", tx, ty); #endif if(showing_area && fuzzy_chess_inside_target_area(game, focus, tx, ty)) { /* select attack target */ if (fuzzy_map_spy(game->map, FUZZY_LAYER_SPRITES, tx, ty) == FUZZY_CELL_SPRITE) { if (fuzzy_chess_local_attack(game, player, focus, tx, ty)) _attack_area_off(); } } else { /* select chess */ chess = fuzzy_chess_at(game, player, tx, ty); if (chess && focus != chess) { _attack_area_off(); if (focus != NULL) { // already has a focus effect, just move it fuzzy_sprite_move(game->map, FUZZY_LAYER_BELOW, focus->x, focus->y, tx, ty); } else { fuzzy_sprite_create(game->map, FUZZY_LAYER_BELOW, GID_TARGET, tx, ty); } focus = chess; } else if (! chess) { if (showing_area) { // just hide the attack area _attack_area_off(); } else if(focus) { // remove the focus fuzzy_sprite_destroy(game->map, FUZZY_LAYER_BELOW, focus->x, focus->y); focus = NULL; } } } } break; default: #ifdef DEBUG //~ fprintf(stderr, "Unknown event received: %d\n", event.type); #endif break; } if (redraw && al_is_event_queue_empty(evqueue)) { curtime = al_get_time(); fuzzy_map_update(game->map, curtime); // Clear the screen al_clear_to_color(al_map_rgb(0, 0, 0)); al_draw_bitmap(game->map->bitmap, -map_x, -map_y, 0); #ifdef GRID_ON /* Draw the grid */ int tw = game->map->tile_width; int ty = game->map->tile_height; int x, y; for (x=(tw-map_x)%tw; x<screen_width; x+=tw) al_draw_line(x, 0, x, screen_height, al_map_rgba(7,7,7,100), 1); for (y=(ty-map_y)%ty; y<screen_height; y+=ty) al_draw_line(0, y, screen_width, y, al_map_rgba(7,7,7,100), 1); #endif #if DEBUG al_draw_filled_rounded_rectangle(screen_width-100, 4, screen_width, 30, 8, 8, al_map_rgba(0, 0, 0, 200)); al_draw_textf(font, al_map_rgb(255, 255, 255), screen_width-50, 8, ALLEGRO_ALIGN_CENTRE, "FPS: %d", fps); #endif /* draw SP count */ al_draw_filled_rounded_rectangle(4, screen_height-170, 175, screen_height-4, 8, 8, al_map_rgba(0, 0, 0, 200)); al_draw_textf(font, al_map_rgb(255, 255, 255), 15, screen_height-163, ALLEGRO_ALIGN_LEFT, "SP: %d", player->soul_points); /* draw Soul Clock */ al_draw_scaled_bitmap(clock_quadrant, 0, 0, 301, 301, 20, screen_height-80-139/2, 139, 139, 0); al_draw_scaled_rotated_bitmap(clock_hand, 160, 607, 90, screen_height-80, 0.11, 0.11, clock_angle, 0); al_draw_circle(90, screen_height-80, clock_ray, al_map_rgb(80, clock_ray_alpha, 80), 2.0); /* draw weapon */ if (focus) { ALLEGRO_BITMAP * weapon; if (focus->atkarea == &FuzzyMeleeMan) weapon = sword; else weapon = bow; al_draw_scaled_bitmap(weapon, 0, 0, 90, 90, 20, 20, 60, 60, 0); } al_flip_display(); #if DEBUG fps_accum++; if (curtime - fps_time >= 1) { fps = fps_accum; fps_accum = 0; fps_time = curtime; } #endif redraw = false; } } /* Cleanup */ //~ void * retval; //~ char srvkey[FUZZY_SERVERKEY_LEN]; //~ fuzzy_protocol_server_shutdown(svsock, sendmsg, srvkey); //~ fuzzy_message_del(sendmsg); fuzzy_game_free(game); al_destroy_event_queue(evqueue); al_destroy_display(display); al_destroy_timer(timer); return 0; }
int main(int argc, const char *argv[]) { const char *filename; ALLEGRO_DISPLAY *display; ALLEGRO_BITMAP *bitmap; ALLEGRO_TIMER *timer; ALLEGRO_EVENT_QUEUE *queue; bool redraw = true; double zoom = 1; double t0; double t1; if (argc > 1) { filename = argv[1]; } else { filename = "data/mysha.pcx"; } if (!al_init()) { abort_example("Could not init Allegro.\n"); } if (argc > 2) { al_set_new_display_adapter(atoi(argv[2])); } al_install_mouse(); al_install_keyboard(); al_init_image_addon(); display = al_create_display(640, 480); if (!display) { abort_example("Error creating display\n"); } al_set_window_title(display, filename); t0 = al_get_time(); bitmap = al_load_bitmap(filename); t1 = al_get_time(); if (!bitmap) { abort_example("%s not found or failed to load\n", filename); } printf("Loading took %.4f seconds\n", t1 - t0); timer = al_create_timer(1.0 / 30); queue = al_create_event_queue(); al_register_event_source(queue, al_get_keyboard_event_source()); al_register_event_source(queue, al_get_display_event_source(display)); al_register_event_source(queue, al_get_timer_event_source(timer)); al_start_timer(timer); while (1) { ALLEGRO_EVENT event; al_wait_for_event(queue, &event); if (event.type == ALLEGRO_EVENT_DISPLAY_ORIENTATION) { int o = event.display.orientation; if (o == ALLEGRO_DISPLAY_ORIENTATION_0_DEGREES) { printf("0 degrees\n"); } else if (o == ALLEGRO_DISPLAY_ORIENTATION_90_DEGREES) { printf("90 degrees\n"); } else if (o == ALLEGRO_DISPLAY_ORIENTATION_180_DEGREES) { printf("180 degrees\n"); } else if (o == ALLEGRO_DISPLAY_ORIENTATION_270_DEGREES) { printf("270 degrees\n"); } else if (o == ALLEGRO_DISPLAY_ORIENTATION_FACE_UP) { printf("Face up\n"); } else if (o == ALLEGRO_DISPLAY_ORIENTATION_FACE_DOWN) { printf("Face down\n"); } } if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) break; if (event.type == ALLEGRO_EVENT_KEY_CHAR) { if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) break; if (event.keyboard.unichar == '1') zoom = 1; if (event.keyboard.unichar == '+') zoom *= 1.1; if (event.keyboard.unichar == '-') zoom /= 1.1; if (event.keyboard.unichar == 'f') zoom = (double)al_get_display_width(display) / al_get_bitmap_width(bitmap); } if (event.type == ALLEGRO_EVENT_TIMER) redraw = true; if (redraw && al_is_event_queue_empty(queue)) { redraw = false; al_clear_to_color(al_map_rgb_f(0, 0, 0)); if (zoom == 1) al_draw_bitmap(bitmap, 0, 0, 0); else al_draw_scaled_rotated_bitmap( bitmap, 0, 0, 0, 0, zoom, zoom, 0, 0); al_flip_display(); } } al_destroy_bitmap(bitmap); return 0; }
int main(int argc, char **argv) { ALLEGRO_DISPLAY *display; ALLEGRO_TIMER *timer; ALLEGRO_EVENT_QUEUE *queue; bool redraw = true; ALLEGRO_FONT *font; ALLEGRO_BITMAP *spin, *spin2; int current_bitmap = 0; int loaded_bitmap = 0; ALLEGRO_THREAD *thread; (void)argc; (void)argv; if (!al_init()) { abort_example("Could not init Allegro.\n"); } al_init_image_addon(); al_init_font_addon(); al_init_primitives_addon(); init_platform_specific(); open_log(); al_install_mouse(); al_install_keyboard(); spin = al_load_bitmap("data/cursor.tga"); log_printf("default bitmap without display: %p\n", spin); al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP); spin2 = al_load_bitmap("data/cursor.tga"); log_printf("video bitmap without display: %p\n", spin2); log_printf("%p before create_display: ", spin); print_bitmap_flags(spin); log_printf("\n"); display = al_create_display(64, 64); if (!display) { abort_example("Error creating display\n"); } spin2 = al_load_bitmap("data/cursor.tga"); log_printf("video bitmap with display: %p\n", spin2); log_printf("%p after create_display: ", spin); print_bitmap_flags(spin); log_printf("\n"); log_printf("%p after create_display: ", spin2); print_bitmap_flags(spin2); log_printf("\n"); al_destroy_display(display); log_printf("%p after destroy_display: ", spin); print_bitmap_flags(spin); log_printf("\n"); log_printf("%p after destroy_display: ", spin2); print_bitmap_flags(spin2); log_printf("\n"); display = al_create_display(640, 480); log_printf("%p after create_display: ", spin); print_bitmap_flags(spin); log_printf("\n"); log_printf("%p after create_display: ", spin2); print_bitmap_flags(spin2); log_printf("\n"); font = al_load_font("data/fixed_font.tga", 0, 0); mutex = al_create_mutex(); thread = al_create_thread(loading_thread, NULL); al_start_thread(thread); timer = al_create_timer(1.0 / 30); queue = al_create_event_queue(); al_register_event_source(queue, al_get_keyboard_event_source()); al_register_event_source(queue, al_get_display_event_source(display)); al_register_event_source(queue, al_get_timer_event_source(timer)); al_start_timer(timer); while (1) { ALLEGRO_EVENT event; al_wait_for_event(queue, &event); if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) break; if (event.type == ALLEGRO_EVENT_KEY_DOWN) { if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) break; } if (event.type == ALLEGRO_EVENT_TIMER) redraw = true; if (redraw && al_is_event_queue_empty(queue)) { float x = 20, y = 320; int i; ALLEGRO_COLOR color = al_map_rgb_f(0, 0, 0); float t = al_current_time(); redraw = false; al_clear_to_color(al_map_rgb_f(0.5, 0.6, 1)); al_draw_textf(font, color, x + 40, y, 0, "Loading %d%%", 100 * load_count / load_total); al_lock_mutex(mutex); if (loaded_bitmap < load_count) { /* This will convert any video bitmaps without a display * (all the bitmaps being loaded in the loading_thread) to * video bitmaps we can use in the main thread. */ al_convert_bitmap(bitmaps[loaded_bitmap]); loaded_bitmap++; } al_unlock_mutex(mutex); if (current_bitmap < loaded_bitmap) { int bw; al_draw_bitmap(bitmaps[current_bitmap], 0, 0, 0); if (current_bitmap + 1 < loaded_bitmap) current_bitmap++; for (i = 0; i <= current_bitmap; i++) { bw = al_get_bitmap_width(bitmaps[i]); al_draw_scaled_rotated_bitmap(bitmaps[i], 0, 0, (i % 20) * 640 / 20, 360 + (i / 20) * 24, 32.0 / bw, 32.0 / bw, 0, 0); } } if (loaded_bitmap < load_total) { al_draw_scaled_rotated_bitmap(spin, 16, 16, x, y, 1.0, 1.0, t * ALLEGRO_PI * 2, 0); } al_flip_display(); } } al_join_thread(thread, NULL); al_destroy_mutex(mutex); al_destroy_font(font); al_destroy_display(display); close_log(true); return 0; }
int main(int argc, char **argv) { ALLEGRO_DISPLAY *display; ALLEGRO_BITMAP *bitmap[2]; ALLEGRO_TIMER *timer; ALLEGRO_EVENT_QUEUE *queue; bool redraw = true; ALLEGRO_SHADER *shader; int t = 0; const char* pixel_file = NULL; (void)argc; (void)argv; if (!al_init()) { abort_example("Could not init Allegro.\n"); } al_install_mouse(); al_install_keyboard(); al_init_image_addon(); init_platform_specific(); al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR | ALLEGRO_MAG_LINEAR | ALLEGRO_MIPMAP); al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_SUGGEST); al_set_new_display_option(ALLEGRO_SAMPLES, 4, ALLEGRO_SUGGEST); al_set_new_display_flags(ALLEGRO_PROGRAMMABLE_PIPELINE); display = al_create_display(640, 480); if (!display) { abort_example("Error creating display\n"); } bitmap[0]= load_bitmap("data/mysha.pcx"); bitmap[1]= load_bitmap("data/obp.jpg"); shader = al_create_shader(ALLEGRO_SHADER_AUTO); if (!shader) abort_example("Error creating shader.\n"); if (al_get_shader_platform(shader) == ALLEGRO_SHADER_GLSL) { #ifdef ALLEGRO_CFG_SHADER_GLSL pixel_file = "data/ex_shader_multitex_pixel.glsl"; #endif } else { #ifdef ALLEGRO_CFG_SHADER_HLSL pixel_file = "data/ex_shader_multitex_pixel.hlsl"; #endif } if (!pixel_file) { abort_example("No shader source\n"); } if (!al_attach_shader_source(shader, ALLEGRO_VERTEX_SHADER, al_get_default_shader_source(ALLEGRO_SHADER_AUTO, ALLEGRO_VERTEX_SHADER))) { abort_example("al_attach_shader_source for vertex shader failed: %s\n", al_get_shader_log(shader)); } if (!al_attach_shader_source_file(shader, ALLEGRO_PIXEL_SHADER, pixel_file)) abort_example("al_attach_shader_source_file for pixel shader failed: %s\n", al_get_shader_log(shader)); if (!al_build_shader(shader)) abort_example("al_build_shader failed: %s\n", al_get_shader_log(shader)); al_use_shader(shader); timer = al_create_timer(1.0 / 60); queue = al_create_event_queue(); al_register_event_source(queue, al_get_keyboard_event_source()); al_register_event_source(queue, al_get_display_event_source(display)); al_register_event_source(queue, al_get_timer_event_source(timer)); al_start_timer(timer); while (1) { ALLEGRO_EVENT event; al_wait_for_event(queue, &event); if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) break; if (event.type == ALLEGRO_EVENT_KEY_CHAR) { if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) break; } if (event.type == ALLEGRO_EVENT_TIMER) { redraw = true; t++; } if (redraw && al_is_event_queue_empty(queue)) { int dw, dh; double scale = 1 + 100 * (1 + sin(t * ALLEGRO_PI * 2 / 60 / 10)); double angle = ALLEGRO_PI * 2 * t / 60 / 15; double x = 120 - 20 * cos(ALLEGRO_PI * 2 * t / 60 / 25); double y = 120 - 20 * sin(ALLEGRO_PI * 2 * t / 60 / 25); dw = al_get_display_width(display); dh = al_get_display_height(display); redraw = false; al_clear_to_color(al_map_rgb_f(0, 0, 0)); /* We set a second bitmap for texture unit 1. Unit 0 will have * the normal texture which al_draw_*_bitmap will set up for us. * We then draw the bitmap like normal, except it will use the * custom shader. */ al_set_shader_sampler("tex2", bitmap[1], 1); al_draw_scaled_rotated_bitmap(bitmap[0], x, y, dw / 2, dh / 2, scale, scale, angle, 0); al_flip_display(); } } al_use_shader(NULL); al_destroy_bitmap(bitmap[0]); al_destroy_bitmap(bitmap[1]); al_destroy_shader(shader); return 0; }
/** Draws a scaled and rotated bitmap. @param cx center x. @param cy center y. @param dx target horizontal position. @param dy target vertical position. @param xscale scale along the x axis. @param yscale scale along the y axis. @param angle angle in radians; clockwise. @param flags flags. */ void drawScaledRotated(float cx, float cy, float dx, float dy, float xscale, float yscale, float angle, int flags = 0) { al_draw_scaled_rotated_bitmap(get(), cx, cy, dx, dy, xscale, yscale, angle, flags); }
void Render::theme() { al_clear_to_color(al_map_rgb(0, 65, 34)); mapbg(); if((int)gamedata->player.aim_x > 0) al_draw_scaled_rotated_bitmap(bitmaps[PLAYER], 23, 2, GAME_WIDTH/2, GAME_HEIGHT/2, -1, 1, 0, 0); if((int)gamedata->player.aim_x <= 0) al_draw_scaled_rotated_bitmap(bitmaps[PLAYER], 13, 2, GAME_WIDTH/2, GAME_HEIGHT/2, 1, 1, 0, 0); double angle = atan2(-gamedata->player.aim_y, gamedata->player.aim_x); if((int)gamedata->player.aim_x > 0) al_draw_scaled_rotated_bitmap(bitmaps[GUN], 21, 19, GAME_WIDTH/2 + 2, GAME_HEIGHT/2 + 17, -1, 1, -angle, 0); if((int)gamedata->player.aim_x <= 0) al_draw_scaled_rotated_bitmap(bitmaps[GUN], 21, 19, GAME_WIDTH/2 + 8, GAME_HEIGHT/2 + 17, 1, 1, -angle + 3.14159, 0); // draw bullets for(unsigned int i = 0; i < gamedata->player.bullets.size(); i++) { al_draw_scaled_rotated_bitmap(bitmaps[BULLET], 0, 0, - gamedata->player.x+GAME_WIDTH/2+gamedata->player.bullets[i].x, floor(-gamedata->player.y)+GAME_HEIGHT/2+gamedata->player.bullets[i].y, 1, 1, gamedata->player.bullets[i].angle + 3.14159, 0); } // for i // draw bunnies for(unsigned int i = 0; i < gamedata->bunnies.size(); i++) if(gamedata->bunnies[i].is_alive != false) { if(gamedata->bunnies[i].direction >= 0) al_draw_scaled_rotated_bitmap(bitmaps[BUNNY], 0, 0, - gamedata->player.x+GAME_WIDTH/2+gamedata->bunnies[i].x-1, floor(-gamedata->player.y)+GAME_HEIGHT/2+gamedata->bunnies[i].y-1, 1, 1, 0, 0); else al_draw_scaled_rotated_bitmap(bitmaps[BUNNY], 10, 0, - gamedata->player.x+GAME_WIDTH/2+gamedata->bunnies[i].x-1, floor(-gamedata->player.y)+GAME_HEIGHT/2+gamedata->bunnies[i].y-1, -1, 1, 0, 0); } // if bunny alive if(gamedata->player.grenade->is_alive) al_draw_scaled_rotated_bitmap(bitmaps[GRENADE], 4, 6, - gamedata->player.x+GAME_WIDTH/2+gamedata->player.grenade->x+4, floor(-gamedata->player.y)+GAME_HEIGHT/2+gamedata->player.grenade->y+4, 1, 1, 0, 0); //font sprintf(string1, "%d", gamedata->player.health); al_draw_text(font24, al_map_rgb(10, 10, 0), 50, 525, 0, string1); unsigned int tempy = gamedata->bunnies.size(); unsigned int tempy2 = gamedata->numBunnies; sprintf(string1, "%d yet to feel thy wrath. %d shall commeth.", tempy, tempy2); al_draw_text(font16, al_map_rgb(10, 10, 0), 50, 25, 0, string1); tempy = gamedata->player.killed; sprintf(string1, "%d snuffed.", tempy); al_draw_text(font24, al_map_rgb(10, 10, 0), 75, 50, 0, string1); if(gamedata->player.has_grenade) al_draw_text(font24, al_map_rgb(10, 10, 0), 325, 525, 0, "You have only 1 Holy Hand Grenades."); else al_draw_text(font24, al_map_rgb(10, 10, 0), 325, 525, 0, "You have 0 Holy Hand Grenades."); // whiteout if(gamedata->player.grenade->is_alive) { double temp = 1.0 - gamedata->player.grenade->death_timer/300.0; al_draw_tinted_bitmap(bitmaps[WHITE], al_map_rgba_f(temp, temp, temp, 0), 0, 0, 0); } al_flip_display(); } // theme()