HICON _al_win_create_icon(HWND wnd, ALLEGRO_BITMAP *sprite, int xfocus, int yfocus, bool is_cursor, bool resize) { int x, y; int sys_sm_cx, sys_sm_cy; HDC h_dc; HDC h_and_dc; HDC h_xor_dc; ICONINFO iconinfo; HBITMAP and_mask; HBITMAP xor_mask; HBITMAP hOldAndMaskBitmap; HBITMAP hOldXorMaskBitmap; HICON icon; if (resize) { if (is_cursor) { /* Get allowed cursor size - Windows can't make cursors of arbitrary size */ sys_sm_cx = GetSystemMetrics(SM_CXCURSOR); sys_sm_cy = GetSystemMetrics(SM_CYCURSOR); } else { sys_sm_cx = GetSystemMetrics(SM_CXICON); sys_sm_cy = GetSystemMetrics(SM_CYICON); } if ((sprite->w > sys_sm_cx) || (sprite->h > sys_sm_cy)) { return NULL; } } else { sys_sm_cx = al_get_bitmap_width(sprite); sys_sm_cy = al_get_bitmap_height(sprite); } /* Create bitmap */ h_dc = GetDC(wnd); h_xor_dc = CreateCompatibleDC(h_dc); h_and_dc = CreateCompatibleDC(h_dc); /* Prepare AND (monochrome) and XOR (colour) mask */ and_mask = CreateBitmap(sys_sm_cx, sys_sm_cy, 1, 1, NULL); xor_mask = CreateCompatibleBitmap(h_dc, sys_sm_cx, sys_sm_cy); hOldAndMaskBitmap = (HBITMAP) SelectObject(h_and_dc, and_mask); hOldXorMaskBitmap = (HBITMAP) SelectObject(h_xor_dc, xor_mask); /* Create transparent cursor */ for (y = 0; y < sys_sm_cy; y++) { for (x = 0; x < sys_sm_cx; x++) { SetPixel(h_and_dc, x, y, WINDOWS_RGB(255, 255, 255)); SetPixel(h_xor_dc, x, y, WINDOWS_RGB(0, 0, 0)); } } local_draw_to_hdc(h_xor_dc, sprite, 0, 0); /* Make cursor background transparent */ for (y = 0; y < sprite->h; y++) { for (x = 0; x < sprite->w; x++) { ALLEGRO_COLOR c; unsigned char r, g, b, a; c = al_get_pixel(sprite, x, y); al_unmap_rgba(c, &r, &g, &b, &a); if (a != 0) { /* Don't touch XOR value */ SetPixel(h_and_dc, x, y, 0); } else { /* No need to touch AND value */ SetPixel(h_xor_dc, x, y, WINDOWS_RGB(0, 0, 0)); } } } SelectObject(h_and_dc, hOldAndMaskBitmap); SelectObject(h_xor_dc, hOldXorMaskBitmap); DeleteDC(h_and_dc); DeleteDC(h_xor_dc); ReleaseDC(wnd, h_dc); iconinfo.fIcon = is_cursor ? false : true; iconinfo.xHotspot = xfocus; iconinfo.yHotspot = yfocus; iconinfo.hbmMask = and_mask; iconinfo.hbmColor = xor_mask; icon = CreateIconIndirect(&iconinfo); DeleteObject(and_mask); DeleteObject(xor_mask); return icon; }
void Game::run () { bool to_paint; ALLEGRO_EVENT event; while (1) { do { al_wait_for_event(global.queue, &event); switch (event.type) { case ALLEGRO_EVENT_DISPLAY_CLOSE: Utils::terminate(); break; case ALLEGRO_EVENT_TIMER: to_paint = true; if (!paused) time_walk (); break; case ALLEGRO_EVENT_KEY_DOWN: case ALLEGRO_EVENT_KEY_REPEAT: if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) paused = !paused; }; } while (!al_event_queue_is_empty(global.queue)); if (to_paint) { al_clear_to_color(global.color_black); al_set_blender(ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA, al_map_rgba_f(1.0, 1.0, 1.0, 0.3)); al_draw_bitmap(global.bitmap_bga[0], GAME_X1, n_frame - al_get_bitmap_height(global.bitmap_bgd[0]) - al_get_bitmap_height(global.bitmap_bgc[0]) - al_get_bitmap_height(global.bitmap_bgb[0]) - al_get_bitmap_height(global.bitmap_bga[0]) + GAME_H, 0); al_draw_bitmap(global.bitmap_bgb[0], GAME_X1, n_frame - al_get_bitmap_height(global.bitmap_bgd[0]) - al_get_bitmap_height(global.bitmap_bgc[0]) - al_get_bitmap_height(global.bitmap_bgb[0]) + GAME_H, 0); al_draw_bitmap(global.bitmap_bgc[0], GAME_X1, n_frame - al_get_bitmap_height(global.bitmap_bgd[0]) - al_get_bitmap_height(global.bitmap_bgc[0]) + GAME_H, 0); al_draw_bitmap(global.bitmap_bgd[0], GAME_X1, n_frame - al_get_bitmap_height(global.bitmap_bgd[0]) + GAME_H, 0); if (gamedata.fl_invincible && n_frame % 6 < 3) { al_set_blender(ALLEGRO_ALPHA, ALLEGRO_ONE, al_map_rgba_f(0.0, 0.0, 1.0, 1.0)); al_draw_bitmap(GAME_POS_C(gamedata.cur_pos, global.bitmap_char[gamedata.character]), 0); al_draw_bitmap(GAME_POS_C(gamedata.cur_pos, global.bitmap_char[gamedata.character]), 0); al_draw_bitmap(GAME_POS_C(gamedata.cur_pos, global.bitmap_char[gamedata.character]), 0); } else { /* if (gamedata.character == CHAR_SILK) { al_set_blender(ALLEGRO_ALPHA, ALLEGRO_ONE, al_map_rgba_f(1.0, 1.0, 1.0, 1.0)); al_draw_bitmap(GAME_POS_C(gamedata.cur_pos, global.bitmap_char[gamedata.character]), 0); al_draw_bitmap(GAME_POS_C(gamedata.cur_pos, global.bitmap_char[gamedata.character]), 0); } else */ { al_set_blender(ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA, al_map_rgba_f(1.0, 1.0, 1.0, 1.0)); al_draw_bitmap(GAME_POS_C(gamedata.cur_pos, global.bitmap_char[gamedata.character]), 0); } } al_set_blender(ALLEGRO_ALPHA, ALLEGRO_ONE, al_map_rgba_f(1.0, 1.0, 1.0, 1.0)); al_draw_bitmap(GAME_POS_C(gamedata.cur_pos, global.bitmap_crd[gamedata.character]), 0); al_set_blender(ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA, al_map_rgba_f(1.0, 1.0, 1.0, 1.0)); for (int i = 0; i < gamedata.n_pbullet; i ++) gamedata.pbullet[i] -> draw (); for (int i = 0; i < gamedata.n_ebullet; i ++) gamedata.ebullet[i] -> draw (); for (int i = 0; i < gamedata.n_enemy; i ++) gamedata.enemy[i] -> draw (); al_set_blender(ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA, al_map_rgba_f(1.0, 1.0, 1.0, 1.0)); al_draw_bitmap(global.bitmap_game, 1, 1, 0); al_set_blender(ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA, al_map_rgba_f(0.7, 0.7, 1.0, 0.9)); al_draw_textf(global.font_game, GAME_X2 + 20, GAME_Y1 + 50, ALLEGRO_ALIGN_LEFT, "HISCORE"); al_draw_textf(global.font_game_score, SCREEN_W - 20, GAME_Y1 + 50, ALLEGRO_ALIGN_RIGHT, "0"); al_draw_textf(global.font_game, GAME_X2 + 20, GAME_Y1 + 75, ALLEGRO_ALIGN_LEFT, "SCORE"); al_draw_textf(global.font_game_score, SCREEN_W - 20, GAME_Y1 + 75, ALLEGRO_ALIGN_RIGHT, "0"); al_draw_textf(global.font_game, GAME_X2 + 20, GAME_Y1 + 110, ALLEGRO_ALIGN_LEFT, "Life"); { char buf[128]; int tmp = 0, bp = 0; while (tmp + HP_PER_LIFE <= gamedata.hp) { buf[bp ++] = '@'; tmp += HP_PER_LIFE; } while (tmp + 1 <= gamedata.hp) { buf[bp ++] = '.'; tmp += HP_PER_LIFE; } buf[bp] = 0; al_draw_textf(global.font_game_score, GAME_X2 + 90, GAME_Y1 + 110, ALLEGRO_ALIGN_LEFT, buf); } al_draw_textf(global.font_game, GAME_X2 + 20, GAME_Y1 + 135, ALLEGRO_ALIGN_LEFT, "Power"); al_draw_textf(global.font_game_score, GAME_X2 + 90, GAME_Y1 + 135, ALLEGRO_ALIGN_LEFT, "%d.%02d \\ 5.00", gamedata.power / 100, gamedata.power % 100); al_draw_textf(global.font_game, GAME_X2 + 20, GAME_Y1 + 160, ALLEGRO_ALIGN_LEFT, "Skill"); al_draw_textf(global.font_game_score, GAME_X2 + 90, GAME_Y1 + 160, ALLEGRO_ALIGN_LEFT, "17234 \\ 1500"); al_draw_textf(global.font_game, GAME_X2 + 20, GAME_Y1 + 195, ALLEGRO_ALIGN_LEFT, "Point"); al_draw_textf(global.font_game_score, GAME_X2 + 90, GAME_Y1 + 195, ALLEGRO_ALIGN_LEFT, "20000"); al_draw_textf(global.font_game, GAME_X2 + 20, GAME_Y1 + 220, ALLEGRO_ALIGN_LEFT, "Graze"); al_draw_textf(global.font_game_score, GAME_X2 + 90, GAME_Y1 + 220, ALLEGRO_ALIGN_LEFT, "%d", gamedata.graze); { char buf[128]; sprintf(buf, "%2.2lf", global.calculated_fps); al_draw_textf(global.font_game_score, SCREEN_W, SCREEN_H - 20, ALLEGRO_ALIGN_RIGHT, buf); } { double cur_time = al_current_time (); global.calculated_fps = FPS / (cur_time - global.time_previous[d_frame % FPS]); global.time_previous[d_frame % FPS] = cur_time; d_frame ++; } al_flip_display(); to_paint = false; } } }
void draw_sprite(TileSet * tileset, s_sprite sprite, s_map_block * block, float x, float y, int shrink, bool flip = 0, int offset = 0, bool shiftup = false) { if(offset < 0) return; int target_width = al_get_bitmap_width(al_get_target_bitmap()); int target_height = al_get_bitmap_height(al_get_target_bitmap()); if((x + sprite.origin_x > target_width) || (y + sprite.origin_y > target_height) || ((x + sprite.origin_x + sprite.width) < 0) || ((y + sprite.origin_y + (sprite.height - shrink)) < 0))return; int flags = 0; if(flip) flags = ALLEGRO_FLIP_HORIZONTAL; ALLEGRO_COLOR color; switch(sprite.color_by) { case COLOR_NONE: color = block->light; break; case COLOR_INI: color = mix_colors(sprite.color, block->light); break; case COLOR_BIOME: color = mix_colors(block->biome_color, block->light); break; case COLOR_COMBINED: color = mix_colors(block->combined_color, block->light); break; case COLOR_STRUCTURE: color = mix_colors(block->structure_color, block->light); break; case COLOR_TRADE: color = mix_colors(block->trade_color, block->light); break; case COLOR_PALETTE: switch(sprite.color_source) { case SOURCE_ELEV: color = mix_colors(tileset->get_palette_color(sprite.palette_number, block->height), block->light); break; case SOURCE_DEPTH: color = mix_colors(tileset->get_palette_color(sprite.palette_number,block->water_height-block->height), block->light); break; case SOURCE_TEMPERATURE: color = mix_colors(tileset->get_palette_color(sprite.palette_number,block->levels[SOURCE_TEMPERATURE]), block->light); break; case SOURCE_RAINFALL: color = mix_colors(tileset->get_palette_color(sprite.palette_number,block->levels[SOURCE_RAINFALL]), block->light); break; case SOURCE_DRAINAGE: color = mix_colors(tileset->get_palette_color(sprite.palette_number,block->levels[SOURCE_DRAINAGE]), block->light); break; case SOURCE_SAVAGERY: color = mix_colors(tileset->get_palette_color(sprite.palette_number,block->levels[SOURCE_SAVAGERY]), block->light); break; case SOURCE_VOLCANISM: color = mix_colors(tileset->get_palette_color(sprite.palette_number,block->levels[SOURCE_VOLCANISM]), block->light); break; case SOURCE_EVIL: color = mix_colors(tileset->get_palette_color(sprite.palette_number,block->levels[SOURCE_EVIL]), block->light); break; case SOURCE_SALINITY: color = mix_colors(tileset->get_palette_color(sprite.palette_number,block->levels[SOURCE_SALINITY]), block->light); break; default: color = block->light; } break; default: color = block->light; break; } al_draw_tinted_bitmap_region( imagelist.get_image(sprite.index), color, sprite.x + (sprite.width * offset), sprite.y + ((!shiftup)*shrink), sprite.width, sprite.height - shrink, x + sprite.origin_x, y + sprite.origin_y, flags); }
/* main game render function */ void dot_game_render(void * data) { APP_INSTANCE * app = (APP_INSTANCE *)data; char buf[16] = {0}; int i; ALLEGRO_COLOR text_color = t3f_color_white; float c = (float)app->game.player.ball.timer / (float)DOT_GAME_COMBO_TIME; float s, r, a; float cx, cy, ecx, ecy; float touch_effect_y = 0; float level_y = 8; float start_y = DOT_GAME_PLAYFIELD_HEIGHT / 2; char * touch_text = "Click"; if(!app->desktop_mode) { touch_effect_y = t3f_virtual_display_height - DOT_GAME_PLAYFIELD_HEIGHT; level_y = DOT_GAME_PLAYFIELD_HEIGHT / 2 - al_get_font_line_height(app->font[DOT_FONT_32]) / 2; start_y = t3f_virtual_display_height - DOT_GAME_PLAYFIELD_HEIGHT / 2; touch_text = "Touch"; } al_clear_to_color(app->game.bg_color); al_hold_bitmap_drawing(true); dot_bg_objects_render(data); al_draw_bitmap(app->bitmap[DOT_BITMAP_BG], 0, 0, 0); if(app->game.combo) { s = app->game.player.ball.r * 2.0 + 128.0 - c * 128.0; t3f_draw_scaled_bitmap(app->bitmap[DOT_BITMAP_COMBO], al_map_rgba_f(0.125, 0.125, 0.125, 0.125), app->game.player.ball.x - s / 2.0, app->game.player.ball.y - s / 2.0, app->game.player.ball.z, s, s, 0); } if(app->game.shield.active) { s = app->game.shield.r * 2.0; t3f_draw_scaled_bitmap(app->bitmap[DOT_BITMAP_COMBO], al_map_rgba_f(0.125, 0.125, 0.0625, 0.125), app->game.shield.x - s / 2.0, app->game.shield.y - s / 2.0, app->game.player.ball.z, s, s, 0); } for(i = 0; i < DOT_GAME_MAX_BALLS; i++) { if(app->game.ball[i].active) { t3f_draw_scaled_bitmap(app->bitmap[DOT_BITMAP_BALL_RED + app->game.ball[i].type], t3f_color_white, app->game.ball[i].x - app->game.ball[i].r, app->game.ball[i].y - app->game.ball[i].r, app->game.ball[i].z, app->game.ball[i].r * 2.0, app->game.ball[i].r * 2.0, 0); } } for(i = 0; i < DOT_GAME_MAX_BALLS; i++) { if(app->game.ball[i].active) { if(app->game.ball[i].type == app->game.player.ball.type) { r = 32.0 + app->game.ball[i].target_tick * 2; a = 1.0 - app->game.ball[i].target_tick / (float)DOT_GAME_TARGET_TICKS; t3f_draw_scaled_bitmap(app->bitmap[DOT_BITMAP_TARGET], al_map_rgba_f(a, a, a, a), app->game.ball[i].x - r, app->game.ball[i].y - r, app->game.ball[i].z, r * 2.0, r * 2.0, 0); } } } if(!app->desktop_mode) { dot_create_touch_dots_effect(data); t3f_draw_scaled_bitmap(app->bitmap[DOT_BITMAP_SCRATCH], al_map_rgba_f(0.0, 0.0, 0.0, 0.5), 0, t3f_virtual_display_height - DOT_GAME_PLAYFIELD_HEIGHT, 0.0, DOT_GAME_PLAYFIELD_WIDTH, al_get_bitmap_height(app->bitmap[DOT_BITMAP_SCRATCH]), 0); } if(app->game.player.ball.active) { cx = (float)(al_get_bitmap_width(app->bitmap[DOT_BITMAP_BALL_RED + app->game.player.ball.type]) / 2); cy = (float)(al_get_bitmap_height(app->bitmap[DOT_BITMAP_BALL_RED + app->game.player.ball.type]) / 2); ecx = (float)(al_get_bitmap_width(app->bitmap[DOT_BITMAP_BALL_EYES]) / 2); ecy = (float)(al_get_bitmap_height(app->bitmap[DOT_BITMAP_BALL_EYES]) / 2); if(app->game.state != DOT_GAME_STATE_START) { t3f_draw_scaled_rotated_bitmap(app->bitmap[DOT_BITMAP_BALL_RED + app->game.player.ball.type], t3f_color_white, cx, cy, app->game.player.ball.x, app->game.player.ball.y, app->game.player.ball.z, 0.0, app->game.player.ball.r / cx, app->game.player.ball.r / cy, 0); t3f_draw_scaled_rotated_bitmap(app->bitmap[DOT_BITMAP_BALL_EYES], t3f_color_white, 8.0, 8.0, app->game.player.ball.x, app->game.player.ball.y, app->game.player.ball.z, app->game.player.ball.a, app->game.player.ball.r / ecx, app->game.player.ball.r / ecy, 0); } if(app->game.combo) { sprintf(buf, "%d", app->game.ascore); dot_shadow_text(app->font[DOT_FONT_16], t3f_color_white, al_map_rgba_f(0.0, 0.0, 0.0, 0.5), app->game.player.ball.x, app->game.player.ball.y - app->game.player.ball.r - 16.0 - 8.0, DOT_SHADOW_OX, DOT_SHADOW_OY, ALLEGRO_ALIGN_CENTRE, buf); } } dot_game_render_hud(data); if((app->game.tick / 6) % 2) { text_color = al_map_rgba_f(1.0, 1.0, 0.0, 1.0); } al_hold_bitmap_drawing(false); if(app->game.state == DOT_GAME_STATE_PAUSE) { if(!app->desktop_mode) { al_draw_filled_rectangle(0.0, 0.0, t3f_virtual_display_width, t3f_virtual_display_height - DOT_GAME_PLAYFIELD_HEIGHT, al_map_rgba_f(0.0, 0.0, 0.0, 0.5)); } al_hold_bitmap_drawing(true); s = DOT_GAME_GRAB_SPOT_SIZE; dot_create_grab_spot_effect(data); if(app->desktop_mode) { t3f_set_clipping_rectangle(0, 0, DOT_GAME_PLAYFIELD_WIDTH, DOT_GAME_PLAYFIELD_HEIGHT); } t3f_draw_scaled_bitmap(app->bitmap[DOT_BITMAP_SCRATCH], al_map_rgba_f(0.0, 0.0, 0.0, 0.5), 0, touch_effect_y, 0.0, DOT_GAME_PLAYFIELD_WIDTH, al_get_bitmap_height(app->bitmap[DOT_BITMAP_SCRATCH]), 0); if(app->desktop_mode) { al_hold_bitmap_drawing(false); al_hold_bitmap_drawing(true); t3f_set_clipping_rectangle(0, 0, 0, 0); } dot_shadow_text(app->font[DOT_FONT_32], text_color, al_map_rgba_f(0.0, 0.0, 0.0, 0.5), t3f_virtual_display_width / 2, DOT_GAME_PLAYFIELD_HEIGHT / 2 - al_get_font_line_height(app->font[DOT_FONT_32]) / 2, DOT_SHADOW_OX, DOT_SHADOW_OY, ALLEGRO_ALIGN_CENTRE, "Paused"); } else if(app->game.state == DOT_GAME_STATE_START) { if(!app->desktop_mode) { al_draw_filled_rectangle(0.0, 0.0, t3f_virtual_display_width, DOT_GAME_PLAYFIELD_HEIGHT + 80, al_map_rgba_f(0.0, 0.0, 0.0, 0.5)); } al_hold_bitmap_drawing(true); dot_create_touch_start_effect(data); if(app->desktop_mode) { t3f_set_clipping_rectangle(0, 0, DOT_GAME_PLAYFIELD_WIDTH, DOT_GAME_PLAYFIELD_HEIGHT); } t3f_draw_scaled_bitmap(app->bitmap[DOT_BITMAP_SCRATCH], al_map_rgba_f(0.0, 0.0, 0.0, 0.5), 0, touch_effect_y, 0.0, DOT_GAME_PLAYFIELD_WIDTH, al_get_bitmap_height(app->bitmap[DOT_BITMAP_SCRATCH]), 0); if(app->desktop_mode) { al_hold_bitmap_drawing(false); al_hold_bitmap_drawing(true); t3f_set_clipping_rectangle(0, 0, 0, 0); } if(app->game.level_start) { sprintf(buf, "Level %d", app->game.level + 1); dot_shadow_text(app->font[DOT_FONT_32], text_color, al_map_rgba_f(0.0, 0.0, 0.0, 0.5), t3f_virtual_display_width / 2, level_y, DOT_SHADOW_OX * 2, DOT_SHADOW_OY * 2, ALLEGRO_ALIGN_CENTRE, buf); } dot_shadow_text(app->font[DOT_FONT_32], text_color, al_map_rgba_f(0.0, 0.0, 0.0, 0.5), t3f_virtual_display_width / 2, start_y - al_get_font_line_height(app->font[DOT_FONT_32]), DOT_SHADOW_OX * 2, DOT_SHADOW_OY * 2, ALLEGRO_ALIGN_CENTRE, touch_text); dot_shadow_text(app->font[DOT_FONT_32], text_color, al_map_rgba_f(0.0, 0.0, 0.0, 0.5), t3f_virtual_display_width / 2, start_y, DOT_SHADOW_OX * 2, DOT_SHADOW_OY * 2, ALLEGRO_ALIGN_CENTRE, "Here"); } al_hold_bitmap_drawing(false); }
void UIWidget::on_draw() { if (surface_area) { al_draw_rounded_rectangle(0, 0, surface_area->placement.size.x, surface_area->placement.size.y, 4, 4, color::color(color::aliceblue, 0.2), 2.0); ALLEGRO_BITMAP *widget_icon = UIStyleAssets::get_widget_icon(); al_draw_tinted_bitmap(widget_icon, color::color(color::white, 0.1), place.size.x/2-al_get_bitmap_width(widget_icon)/2, place.size.y/2-al_get_bitmap_height(widget_icon)/2, 0); } }
void Scenario::setImagem(ALLEGRO_BITMAP* _imagem) { imagem = _imagem; setWidth(al_get_bitmap_width(_imagem)); setHeight(al_get_bitmap_height(_imagem)); }
int image_sequence::get_height() const { assert(images.size() > 0); return al_get_bitmap_height(images[0].image); }
// Draw to screen void menu::draw(){ // Menu Background al_draw_bitmap( img_menu, 0, 0, 0); // Start button al_draw_bitmap( start, (animation_pos * 3.2) - al_get_bitmap_width(start), 400, 0); // Highscores button al_draw_bitmap( highscores_button, SCREEN_W - (animation_pos * 1.4), 30, 0); // Joystick Mode if( settings[SETTING_CONTROLMODE] != 1 && joystick_enabled){ al_draw_bitmap( xbox_start, (animation_pos * 3.2) - al_get_bitmap_width(start) + 220, 430, 0); } // Nice title image al_draw_bitmap( title, 20, (animation_pos * 1.2) - al_get_bitmap_height(title), 0); // Bottom Right Buttons al_draw_bitmap( ui_credits, 541, SCREEN_H - (animation_pos * al_get_bitmap_height(ui_credits))/100, 0); al_draw_bitmap( ui_controls, 645, SCREEN_H - (animation_pos * al_get_bitmap_height(ui_controls))/100, 0); al_draw_bitmap( ui_help, 697, SCREEN_H - (animation_pos * al_get_bitmap_height(ui_help))/100, 0); al_draw_bitmap( ui_options, 749, SCREEN_H - (animation_pos * al_get_bitmap_height(ui_options))/100, 0); //Draw scores if( mini_screen == MINISTATE_SCORES){ // Highscore background al_draw_bitmap( highscores_table, 200, 50, 0); // Title al_draw_text( orbitron_36, al_map_rgb(0,0,0), 400, 75, ALLEGRO_ALIGN_CENTRE , "Highscores"); // Read the top 10 scores for( int i = 0; i < 10; i++){ al_draw_text( orbitron_24, al_map_rgb(0,0,0), 225, (i * 40) + 130, ALLEGRO_ALIGN_LEFT, scores[i][0].c_str()); al_draw_text( orbitron_18, al_map_rgb(0,0,0), 575, (i * 40) + 132, ALLEGRO_ALIGN_RIGHT, scores[i][1].c_str()); } } // Tutorial screen else if( mini_screen == MINISTATE_TUTORIAL){ al_draw_bitmap( helpScreen, 0, 0, 0); } // Credits screen else if( mini_screen == MINISTATE_CREDITS){ al_draw_bitmap( credits, 0, 0, 0); } // Credits screen else if( mini_screen == MINISTATE_CONTROLS){ al_draw_bitmap( controls, 0, 0, 0); } // Option Menu drawing(page and ingame) else if( mini_screen == MINISTATE_OPTIONS){ // Background al_draw_bitmap( options, 0, 0, 0); // Buttons al_draw_bitmap( ui_particle[settings[SETTING_PARTICLE_TYPE]], 280, 407, 0); al_draw_bitmap( ui_sound[settings[SETTING_SOUND]], 120, 180, 0); al_draw_bitmap( ui_music[settings[SETTING_MUSIC]], 280, 180, 0); al_draw_bitmap( ui_window[settings[SETTING_FULLSCREEN]], 120, 407, 0); al_draw_bitmap( ui_screenshake[settings[SETTING_SCREENSHAKE]], 280, 295, 0); al_draw_bitmap( ui_control[settings[SETTING_CONTROLMODE]], 120, 295, 0); // Button Text al_draw_text( orbitron_24, al_map_rgb( 255, 250, 250), 110, 154, ALLEGRO_ALIGN_LEFT , "Sounds Music Exit"); al_draw_text( orbitron_24, al_map_rgb( 255, 250, 250), 126, 268, ALLEGRO_ALIGN_LEFT , "Input Screen Shake"); al_draw_text( orbitron_24, al_map_rgb( 255, 250, 250), 108, 382, ALLEGRO_ALIGN_LEFT , "Window Particles Back"); // Exit and back al_draw_bitmap( ui_exit, 540, 180, 0); al_draw_bitmap( ui_back, 540, 407, 0); } // Debug if( settings[SETTING_DEBUG]){ // Joystick testing if( joystick_enabled){ for( int i = 0; i < JOY_MAX_BUTTONS; i++){ al_draw_textf( orbitron_12, al_map_rgb( 255, 255, 255), 20, 10 * i + 20, ALLEGRO_ALIGN_LEFT , "Joystick B %i : %i", i, joystickListener::button[i]); } } // FPS al_draw_textf( orbitron_12, al_map_rgb( 255, 255, 255), SCREEN_W - 100, 20, ALLEGRO_ALIGN_LEFT , "FPS:%i", fps); } // Draw rocket if no particles if( settings[SETTING_PARTICLE_TYPE] == 3 && mouse_rocket_up) al_draw_bitmap( mouse_rocket, mouseListener::mouse_x - 10, mouseListener::mouse_y, 0); // Draw mouse particles for( unsigned int i = 0; i < mousePart.size(); i++) mousePart.at(i).draw(); al_draw_bitmap( mouse, mouseListener::mouse_x - 10, mouseListener::mouse_y, 0); }
int LevelGraphic::get_h() { return al_get_bitmap_height(bmp); }
void desenha_spaceship( SPACESHIP* spaceship ) { al_draw_scaled_bitmap(spaceship->bitmap, 0, 0, al_get_bitmap_width(spaceship->bitmap), al_get_bitmap_height(spaceship->bitmap), spaceship->posicao_x, spaceship->posicao_y, DISPLAY_WIDTH/19, DISPLAY_HEIGHT/8 , 0 ); }
// Update loop void menu::update(){ //Menu animations if( animation_pos < 100 && !startClicked) animation_pos += 4; if( animation_pos > 0 && startClicked) animation_pos -= 4; // Start the game if( startClicked && animation_pos <= 0) set_next_state( STATE_GAME); // Open submenu or start game if( mini_screen == MINISTATE_MENU){ // Start game with controller if( joystickListener::buttonPressed[JOY_XBOX_START] || joystickListener::buttonPressed[JOY_XBOX_A]){ startClicked = true; } // Buttons if( mouseListener::mouse_pressed & 1){ // Start game if( collision( mouseListener::mouse_x, mouseListener::mouse_x, 40, 40 + al_get_bitmap_width(start), mouseListener::mouse_y, mouseListener::mouse_y, 410, 410 + al_get_bitmap_height(start))){ startClicked = true; } // Scores else if( collision( mouseListener::mouse_x, mouseListener::mouse_x, 660, 660 + al_get_bitmap_width(highscores_button), mouseListener::mouse_y, mouseListener::mouse_y, 30, 30 + al_get_bitmap_height(highscores_button))){ updateScores( scores); mini_screen = MINISTATE_SCORES; } // Credits menu else if( collision( mouseListener::mouse_x, mouseListener::mouse_x, 542, 644, mouseListener::mouse_y, mouseListener::mouse_y, 548, 600)){ mini_screen = MINISTATE_CREDITS; } // Controls menu else if( collision( mouseListener::mouse_x, mouseListener::mouse_x, 644, 696, mouseListener::mouse_y, mouseListener::mouse_y, 548 ,600)){ mini_screen = MINISTATE_CONTROLS; } // Help screen else if( collision( mouseListener::mouse_x, mouseListener::mouse_x, 696, 749, mouseListener::mouse_y, mouseListener::mouse_y, 548, 600)){ mini_screen = MINISTATE_TUTORIAL; } // Options menu else if( collision( mouseListener::mouse_x, mouseListener::mouse_x, 749, 800, mouseListener::mouse_y, mouseListener::mouse_y, 548, 600)){ mini_screen = MINISTATE_OPTIONS; } } } // Exit menus else if( mini_screen == MINISTATE_TUTORIAL || mini_screen == MINISTATE_CREDITS || mini_screen == MINISTATE_CONTROLS || mini_screen == MINISTATE_SCORES ){ if( keyListener::lastKeyPressed != -1 || mouseListener::mouse_pressed & 1 || joystickListener::lastButtonPressed != -1){ mini_screen = MINISTATE_MENU; draw(); } } // Options else if( mini_screen == MINISTATE_OPTIONS && mouseListener::mouse_pressed & 1){ // Particles toggle if( collision( 280, 360, mouseListener::mouse_x, mouseListener::mouse_x, 400, 480, mouseListener::mouse_y, mouseListener::mouse_y)){ settings[SETTING_PARTICLE_TYPE] = (settings[SETTING_PARTICLE_TYPE] + 1) % 4; } // Sound button toggle else if( collision( 120, 200, mouseListener::mouse_x, mouseListener::mouse_x, 180, 260, mouseListener::mouse_y, mouseListener::mouse_y)){ settings[SETTING_SOUND] = (settings[SETTING_SOUND] + 1) % 2; } // Music button toggle else if( collision( 280, 360, mouseListener::mouse_x, mouseListener::mouse_x, 180, 260, mouseListener::mouse_y, mouseListener::mouse_y)){ settings[SETTING_MUSIC] = (settings[SETTING_MUSIC] + 1) % 2; if( settings[SETTING_MUSIC] == 0) al_stop_sample( ¤tMusic); else al_play_sample( music_mainmenu, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, ¤tMusic); } // Fullscreen toggle else if( collision( 120, 200, mouseListener::mouse_x, mouseListener::mouse_x, 400, 480, mouseListener::mouse_y, mouseListener::mouse_y)){ settings[SETTING_FULLSCREEN] = (settings[SETTING_FULLSCREEN] + 1) % 2; if( settings[SETTING_FULLSCREEN]){ // Fullscreen stuff al_destroy_display( display); al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW); display = al_create_display( SCREEN_W, SCREEN_H); ALLEGRO_DISPLAY_MODE disp_data; al_get_display_mode(al_get_num_display_modes() - 1, &disp_data); float sx = disp_data.width / (float)SCREEN_W; float sy = disp_data.height / (float)SCREEN_H; ALLEGRO_TRANSFORM trans; al_identity_transform(&trans); al_scale_transform(&trans, sx, sy); al_use_transform(&trans); al_hide_mouse_cursor( display); } else{ al_destroy_display( display); al_set_new_display_flags(ALLEGRO_WINDOWED); display = al_create_display( SCREEN_W, SCREEN_H); al_hide_mouse_cursor( display); } } //Screen shake else if( collision( 280, 360, mouseListener::mouse_x, mouseListener::mouse_x, 290, 370, mouseListener::mouse_y, mouseListener::mouse_y)){ settings[SETTING_SCREENSHAKE] = (settings[SETTING_SCREENSHAKE] + 1) % 4; } // Control Toggle else if( collision( 120, 200, mouseListener::mouse_x, mouseListener::mouse_x, 290, 370, mouseListener::mouse_y, mouseListener::mouse_y)){ settings[SETTING_CONTROLMODE] = ((settings[SETTING_CONTROLMODE] + 1) % 3); } // Power off else if( collision( 540, 620, mouseListener::mouse_x, mouseListener::mouse_x, 180, 260, mouseListener::mouse_y, mouseListener::mouse_y)){ write_settings(); set_next_state( STATE_EXIT); } // Exit menu else if( collision( 540, 620, mouseListener::mouse_x, mouseListener::mouse_x, 407, 487, mouseListener::mouse_y, mouseListener::mouse_y)){ mini_screen = MINISTATE_MENU; write_settings(); } } // Update mouse particles if( settings[SETTING_PARTICLE_TYPE] != 3 && mouse_rocket_up){ for( int i = 0; i < 500; i++){ if( random( 1, 10) == 1){ ALLEGRO_COLOR part_color = al_map_rgb( 255, random(0,255), 0); if( settings[SETTING_CHRISTMAS]){ int red_or_green = random( 0, 1) * 255; part_color = al_map_rgb( red_or_green, 255 - red_or_green, 0); } particle newParticle( mouseListener::mouse_x, mouseListener::mouse_y + 16, part_color, random( -2, 2), random( 8, 20), 1, settings[SETTING_PARTICLE_TYPE]); mousePart.push_back( newParticle); } } } for( unsigned int i = 0; i < mousePart.size(); i++){ mousePart.at(i).logic(); if( random( 0, 10) == 0) mousePart.erase( mousePart.begin() + i); } // Close game if( keyListener::key[ALLEGRO_KEY_ESCAPE]) set_next_state( STATE_EXIT); // Check if mouse is going up mouse_rocket_up = ( mouseListener::mouse_y < mouseMove); mouseMove = mouseListener::mouse_y; }
int main(int argc, char **argv) { ALLEGRO_DISPLAY *display; ALLEGRO_BITMAP *bmp, *tmp; ALLEGRO_SHADER *horz_shader; ALLEGRO_SHADER *vert_shader; al_init(); al_install_keyboard(); al_init_image_addon(); display = al_create_display(480, 320); bmp = al_load_bitmap("glow.png"); ALLEGRO_BITMAP *bg = al_load_bitmap("bg.png"); tmp = al_create_bitmap( al_get_bitmap_width(bmp), al_get_bitmap_height(bmp) ); horz_shader = al_create_shader(ALLEGRO_SHADER_GLSL); vert_shader = al_create_shader(ALLEGRO_SHADER_GLSL); al_attach_shader_source( horz_shader, ALLEGRO_VERTEX_SHADER, glsl_vertex_source ); al_attach_shader_source( horz_shader, ALLEGRO_PIXEL_SHADER, glsl_pixel_source_horz ); al_link_shader(horz_shader); al_attach_shader_source( vert_shader, ALLEGRO_VERTEX_SHADER, glsl_vertex_source ); al_attach_shader_source( vert_shader, ALLEGRO_PIXEL_SHADER, glsl_pixel_source_vert ); al_link_shader(vert_shader); ALLEGRO_COLOR white = al_map_rgb(255, 255, 255); al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA, white); ALLEGRO_VERTEX *v; v = new ALLEGRO_VERTEX[6*4]; v[0].x = 0; v[0].y = 320; v[0].z = 0; v[0].u = 0; v[0].v = 0; v[0].color = white; v[1].x = 0; v[1].y = 0; v[1].z = 0; v[1].u = 0; v[1].v = 1; v[1].color = white; v[2].x = 480; v[2].y = 0; v[2].z = 0; v[2].u = 1; v[2].v = 1; v[2].color = white; v[3].x = 0; v[3].y = 320; v[3].z = 0; v[3].u = 0; v[3].v = 0; v[3].color = white; v[4].x = 480; v[4].y = 0; v[4].z = 0; v[4].u = 1; v[4].v = 1; v[4].color = white; v[5].x = 480; v[5].y = 320; v[5].z = 0; v[5].u = 1; v[5].v = 0; v[5].color = white; al_set_shader_vertex_array(horz_shader, &v[0].x, sizeof(ALLEGRO_VERTEX)); al_set_shader_color_array(horz_shader, (unsigned char *)&v[0].color, sizeof(ALLEGRO_VERTEX)); al_set_shader_texcoord_array(horz_shader, &v[0].u, sizeof(ALLEGRO_VERTEX)); al_set_shader_vertex_array(vert_shader, &v[0].x, sizeof(ALLEGRO_VERTEX)); al_set_shader_color_array(vert_shader, (unsigned char *)&v[0].color, sizeof(ALLEGRO_VERTEX)); al_set_shader_texcoord_array(vert_shader, &v[0].u, sizeof(ALLEGRO_VERTEX)); float radius = 1; float rinc = 4; while (1) { al_set_target_bitmap(tmp); al_clear_to_color(al_map_rgba(0, 0, 0,0)); ALLEGRO_KEYBOARD_STATE s; al_get_keyboard_state(&s); if (al_key_down(&s, ALLEGRO_KEY_ESCAPE)) break; radius += rinc; if (rinc > 0 && radius >= 25) { rinc = -rinc; } else if (rinc < 0 && radius < 1) { rinc = -rinc; } al_set_shader_sampler(horz_shader, "t", bmp, 0); al_set_shader_float(horz_shader, "img_width", al_get_bitmap_width(bmp)); al_set_shader_float(horz_shader, "radius", radius); al_use_shader(horz_shader, true); al_draw_bitmap(bmp, 0, 0, 0); al_use_shader(horz_shader, false); al_set_target_bitmap(al_get_backbuffer()); al_draw_bitmap(bg, 0, 0, 0); al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE, white); al_set_shader_sampler(vert_shader, "t", tmp, 0); al_set_shader_float(vert_shader, "img_height", al_get_bitmap_height(bmp)); al_set_shader_float(vert_shader, "radius", radius); al_use_shader(vert_shader, true); al_draw_bitmap(tmp, 0, 0, 0); al_use_shader(vert_shader, false); al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA, white); al_draw_bitmap(bmp, 0, 0, 0); al_flip_display(); al_rest(0.016); } al_save_bitmap("bgxx.png", bg); al_save_bitmap("tmpxx.png", tmp); return 0; }
bool Map::loadMap(std::string mapDirectory) { GUI *guiPtr = Base::instance()->getGuiPtr(); std::ifstream fileStream; fileStream.open(mapDirectory); if(!fileStream.good()) return false; int linei = 0; bool error = false; while(!fileStream.eof()) { linei+=1; std::string line; std::vector<std::string> translatedLine; //line decryption std::getline(fileStream, line); if(line.size()==0) continue; std::string::iterator it; std::string temporaryCommandContainer; bool nameEnclosure = false; for(it=line.begin();it!=line.end();it++) { if(*it == '#') break; else if(*it == '\"') { nameEnclosure = !nameEnclosure; } else if(*it == ' ' && !nameEnclosure) { translatedLine.push_back(temporaryCommandContainer); temporaryCommandContainer = ""; } else { temporaryCommandContainer += *it; } } if(temporaryCommandContainer.size()>0) { translatedLine.push_back(temporaryCommandContainer); temporaryCommandContainer = ""; } if(translatedLine.size()==0) continue; //command decryption if(translatedLine[0]=="nazwa") { if(translatedLine.size()!=2) error=true; else setMapName(translatedLine[1]); } else if(translatedLine[0]=="mapa") { if(translatedLine.size()!=2) error=true; else { al_destroy_bitmap(mapaPtr); mapaPtr = al_load_bitmap(translatedLine[1].c_str()); al_clear_to_color(al_map_rgb(0, 0, 255)); mapaWidth = al_get_bitmap_width(mapaPtr); mapaHeight = al_get_bitmap_height(mapaPtr); } } else if(translatedLine[0]=="kraj") { if(translatedLine.size()!=6) error=true; else addRealm(translatedLine[1],al_map_rgb(std::stoi(translatedLine[2]), std::stoi(translatedLine[3]),std::stoi(translatedLine[4])), translatedLine[5]); } else if(translatedLine[0]=="koniec") { if(translatedLine.size()!=2) error=true; else if(translatedLine[1]=="krajow") fillDiplomaticStates(); else error=true; } else if(translatedLine[0]=="region") { if(translatedLine.size()!=7) error=true; else if(!addRegion(std::stoi(translatedLine[1]),std::stoi(translatedLine[2]), translatedLine[3],translatedLine[4],std::stoi(translatedLine[5]), std::stoi(translatedLine[6]))) error=true; } else if(translatedLine[0]=="droga") { if(translatedLine.size()!=3) error=true; else if(!addRegionsConnector(translatedLine[1], translatedLine[2])) error=true; } else if(translatedLine[0]=="wojna") { if(translatedLine.size()!=3) error=true; else if(!changeDiplomaticState(WAR, translatedLine[1], translatedLine[2])) error=true; } else if(translatedLine[0]=="handel") { if(translatedLine.size()!=3) error=true; else if(!changeDiplomaticState(TRADE_AGREEMENT, translatedLine[1], translatedLine[2])) error=true; } else if(translatedLine[0]=="sojusz") { if(translatedLine.size()!=3) error=true; else if(!changeDiplomaticState(ALLIANCE, translatedLine[1], translatedLine[2])) error=true; } if(error) { guiPtr->showNotification("Błąd w mapie w linii: " + std::to_string(linei)); return false; } } fillRealmsRegions(); return true; }
/* draw_to_hdc: * Draws an entire Allegro BITMAP to a Windows DC. Has a syntax similar to * draw_sprite(). */ static void local_draw_to_hdc(HDC dc, ALLEGRO_BITMAP *bitmap, int x, int y) { int w = al_get_bitmap_width(bitmap); int h = al_get_bitmap_height(bitmap); local_stretch_blit_to_hdc(bitmap, dc, 0, 0, w, h, x, y, w, h); }
virtual Skybox *load(const File &file, bool force = false) { // // A terminer // http://raptor.developpez.com/tutorial/opengl/skybox/ ALLEGRO_FS_ENTRY *fs; ALLEGRO_FS_ENTRY *content; ALLEGRO_BITMAP **bmps = new ALLEGRO_BITMAP*[6]; int fileCnt = 0; GLuint cube_map_texture_ID; GLenum cube_map_target[6] = { GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, GL_TEXTURE_CUBE_MAP_POSITIVE_Z }; std::map<std::string, ALLEGRO_LOCKED_REGION*> texture_image; fs = al_create_fs_entry(file.getFullName().c_str()); if (!fs) { throw LoadingFailed(file.getFullName(), "SkyboxLoader failed to find or open skybox folder."); } if (!al_open_directory(fs)) { throw LoadingFailed(file.getFullName(), "SkyboxLoader failed to open skybox folder."); } if (!al_fs_entry_exists(fs)) { throw LoadingFailed(file.getFullName(), "SkyboxLoader can't find folder."); } al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP); while ((content = al_read_directory(fs))) { const char *name = al_get_fs_entry_name(content); ALLEGRO_LOCKED_REGION *r; std::cout << name << std::endl; bmps[fileCnt] = al_load_bitmap(name); if (!bmps[fileCnt]) throw LoadingFailed(name, "SkyboxLoader can't load image."); r = al_lock_bitmap(bmps[fileCnt], ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READWRITE); if (!r) throw LoadingFailed(name, "SkyboxLoader can't lock bitmap."); texture_image.insert(std::pair<std::string, ALLEGRO_LOCKED_REGION*>(std::string(name), r)); al_destroy_fs_entry(content); ++fileCnt; } al_destroy_fs_entry(fs); al_set_new_bitmap_flags(~ALLEGRO_MEMORY_BITMAP); // Génération d'une texture CubeMap glGenTextures(1, &cube_map_texture_ID); if (cube_map_texture_ID == 0) throw LoadingFailed(file.getFullName(), "SkyboxLoader error generating a texture."); // Configuration de la texture glBindTexture(GL_TEXTURE_CUBE_MAP, cube_map_texture_ID); std::map<std::string, ALLEGRO_LOCKED_REGION*>::iterator it = texture_image.begin(); int i = 0; while (it != texture_image.end()) { glTexImage2D(cube_map_target[i], 0, it->second->pixel_size, al_get_bitmap_width(bmps[i]), al_get_bitmap_height(bmps[i]), 0, GL_BGRA, GL_UNSIGNED_BYTE, it->second->data); al_unlock_bitmap(bmps[i]); ++i; ++it; } glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP); return new Skybox(cube_map_texture_ID, bmps, file.getFileName(), force); }
/* ---------------------------------------------------------------------------- * Draws the button. It' just a rectangle with a fancy border; * the latter is drawn one line at a time. */ void button::draw_self() { unsigned int w = x2 - x1; unsigned int h = y2 - y1; ALLEGRO_COLOR top_color, bottom_color; if(mouse_clicking && mouse_in) { top_color = get_darker_bg_color(); bottom_color = get_lighter_bg_color(); } else { top_color = get_lighter_bg_color(); bottom_color = get_darker_bg_color(); } al_draw_filled_rectangle(x1, y1, x2, y2, get_bg_color()); //Top line, outermost. draw_line(this, DRAW_LINE_TOP, 0, 1, 0, top_color); //Top line, innermost. draw_line(this, DRAW_LINE_TOP, 0, 2, 1, top_color); //Left line, outermost. draw_line(this, DRAW_LINE_LEFT, 0, 1, 0, top_color); //Left line, innermost. draw_line(this, DRAW_LINE_LEFT, 0, 2, 1, top_color); //Bottom line, outermost. draw_line(this, DRAW_LINE_BOTTOM, 1, 0, 0, bottom_color); //Bottom line, innermost. draw_line(this, DRAW_LINE_BOTTOM, 2, 0, 1, bottom_color); //Right line, outermost. draw_line(this, DRAW_LINE_RIGHT, 1, 0, 0, bottom_color); //Right line, innermost. draw_line(this, DRAW_LINE_RIGHT, 2, 0, 1, bottom_color); //This is the center of the text, not top left. Also, relative coordinates. signed short final_text_y = 0; //Top left of the icon. signed short final_icon_y = 0; if(icon && text.size()) { //If there's an icon and text. unsigned short total_height = al_get_bitmap_height(icon) + al_get_font_line_height(style->text_font) + 2; //The icon goes to the top of the 2. final_icon_y = h / 2 - total_height / 2; //The text uses the same base y as the icon, except lowered, obviously. final_text_y = final_icon_y + al_get_bitmap_height(icon) + al_get_font_line_height(style->text_font) / 2 + 2; } else if(icon) { //Icon, but no text. final_icon_y = h / 2 - al_get_bitmap_height(icon) / 2; } else if(!icon && text.size()) { //Text, but no icon. final_text_y = h / 2; } if(icon) { al_draw_bitmap( icon, x1 + (w / 2 - al_get_bitmap_width(icon) / 2), y1 + final_icon_y, 0); } if(text.size()) { draw_text_lines( style->text_font, get_fg_color(), x1 + (w / 2), y1 + final_text_y, ALLEGRO_ALIGN_CENTRE, true, text); } }
void dot_intro_render(void * data) { APP_INSTANCE * app = (APP_INSTANCE *)data; al_clear_to_color(app->level_color[0]); al_hold_bitmap_drawing(true); dot_bg_objects_render(data); al_draw_bitmap(app->bitmap[DOT_BITMAP_BG], 0, 0, 0); if(!app->desktop_mode || !app->menu_showing) { al_draw_bitmap(app->bitmap[DOT_BITMAP_LOGO], DOT_GAME_PLAYFIELD_WIDTH / 2 - al_get_bitmap_width(app->bitmap[DOT_BITMAP_LOGO]) / 2 + app->logo_ox, DOT_GAME_PLAYFIELD_HEIGHT / 2 - al_get_bitmap_height(app->bitmap[DOT_BITMAP_LOGO]) / 2, 0); dot_credits_render(data, app->credits_ox); dot_shadow_text(app->font[DOT_FONT_16], t3f_color_white, al_map_rgba_f(0.0, 0.0, 0.0, 0.5), t3f_virtual_display_width / 2 + app->logo_ox, DOT_GAME_PLAYFIELD_HEIGHT - al_get_font_line_height(app->font[DOT_FONT_16]) * 2, DOT_SHADOW_OX, DOT_SHADOW_OY, ALLEGRO_ALIGN_CENTRE, "Copyright (c) 2016 T^3 Software."); } al_hold_bitmap_drawing(false); dot_intro_render_split(data); if(app->menu_showing) { al_hold_bitmap_drawing(true); t3f_render_gui(app->menu[app->current_menu]); if(app->entering_name) { if((app->tick / 15) % 2) { dot_shadow_text(app->font[DOT_FONT_32], t3f_color_white, al_map_rgba_f(0.0, 0.0, 0.0, 0.5), app->menu[DOT_MENU_PROFILE]->ox + app->menu[DOT_MENU_PROFILE]->element[1].ox + al_get_text_width(app->menu[DOT_MENU_PROFILE]->element[1].aux_data, app->menu[DOT_MENU_PROFILE]->element[1].data) / 2, app->menu[DOT_MENU_PROFILE]->oy + app->menu[DOT_MENU_PROFILE]->element[1].oy, DOT_SHADOW_OX, DOT_SHADOW_OY, 0, "_"); } } al_hold_bitmap_drawing(false); } }
void DrawPage(int p) { switch (p) { case 1: al_hold_bitmap_drawing(true); al_draw_bitmap(game->intro.table_bitmap, 0, 0, 0); al_hold_bitmap_drawing(true); draw_text(1, "Ever since Twilight Sparkle and her"); draw_text(1, "friends imprisoned Discord in stone,"); draw_text(1, "Equestria had been peaceful for"); draw_text(1, "a long time."); al_hold_bitmap_drawing(false); break; case 2: al_draw_bitmap_region(game->intro.table_bitmap, al_get_bitmap_width(game->intro.table_bitmap)/2, 0, al_get_bitmap_width(game->intro.table_bitmap)/2, al_get_bitmap_height(game->intro.table_bitmap), game->viewportWidth*0, 0, 0); al_draw_bitmap_region(game->intro.table_bitmap, al_get_bitmap_width(game->intro.table_bitmap)/2, 0, al_get_bitmap_width(game->intro.table_bitmap)/2, al_get_bitmap_height(game->intro.table_bitmap), game->viewportWidth*0.5, 0, 0); al_hold_bitmap_drawing(false); al_hold_bitmap_drawing(true); draw_text(2, "Until one day a reckless pony caused"); draw_text(2, "a tiny bit of chaos near Discord’s"); draw_text(2, "statue."); al_hold_bitmap_drawing(false); break; case 3: al_hold_bitmap_drawing(true); al_draw_bitmap_region(game->intro.table_bitmap, al_get_bitmap_width(game->intro.table_bitmap)/2, 0, al_get_bitmap_width(game->intro.table_bitmap)/2, al_get_bitmap_height(game->intro.table_bitmap), game->viewportWidth*0, 0, 0); al_draw_bitmap_region(game->intro.table_bitmap, al_get_bitmap_width(game->intro.table_bitmap)/2, 0, al_get_bitmap_width(game->intro.table_bitmap)/2, al_get_bitmap_height(game->intro.table_bitmap), game->viewportWidth*0.5, 0, 0); al_hold_bitmap_drawing(false); al_hold_bitmap_drawing(true); draw_text(3, "This small amount of chaos was not"); draw_text(3, "enough to free Discord, but enough"); draw_text(3, "to turn discarded muffins into"); draw_text(3, "vicious muffinzombies, with aim to"); draw_text(3, "destroy all harmony in Equestria."); al_hold_bitmap_drawing(false); break; case 4: al_hold_bitmap_drawing(true); al_draw_bitmap_region(game->intro.table_bitmap, al_get_bitmap_width(game->intro.table_bitmap)/2, 0, al_get_bitmap_width(game->intro.table_bitmap)/2, al_get_bitmap_height(game->intro.table_bitmap), game->viewportWidth*0, 0, 0); al_draw_bitmap_region(game->intro.table_bitmap, al_get_bitmap_width(game->intro.table_bitmap)/2, 0, al_get_bitmap_width(game->intro.table_bitmap)/2, al_get_bitmap_height(game->intro.table_bitmap), game->viewportWidth*0.5, 0, 0); al_hold_bitmap_drawing(false); al_hold_bitmap_drawing(true); draw_text(4, "Discord, learning from his last failure,"); draw_text(4, "turned his muffinzombies against Twilight"); draw_text(4, "and her friends, trapping them in their"); draw_text(4, "own homes. With the bearers of the"); draw_text(4, "Elements out of the way, he now waits"); draw_text(4, "until chaos takes hold of the world,"); draw_text(4, "so he can rule Equestria once again."); al_hold_bitmap_drawing(false); break; case 5: al_hold_bitmap_drawing(true); al_draw_bitmap_region(game->intro.table_bitmap, al_get_bitmap_width(game->intro.table_bitmap)/2, 0, al_get_bitmap_width(game->intro.table_bitmap)/2, al_get_bitmap_height(game->intro.table_bitmap), game->viewportWidth*0, 0, 0); al_draw_bitmap_region(game->intro.table_bitmap, al_get_bitmap_width(game->intro.table_bitmap)/2, 0, al_get_bitmap_width(game->intro.table_bitmap)/2, al_get_bitmap_height(game->intro.table_bitmap), game->viewportWidth*0.5, 0, 0); al_hold_bitmap_drawing(false); al_hold_bitmap_drawing(true); draw_text(5, "Who can defeat Discord without"); draw_text(5, "the Elements of Harmony?"); draw_text(5, ""); draw_text(5, "Well... There is somepony who knows"); draw_text(5, "all about muffins..."); al_hold_bitmap_drawing(false); break; } }
/* starting game UI */ void start_game (bool Fullscreen) { /* creating display */ ALLEGRO_DISPLAY * display; if (Fullscreen) { /* creating disp_data struct to store supported resolutions */ ALLEGRO_DISPLAY_MODE disp_data; /* making it fullscreen */ al_set_new_display_flags(ALLEGRO_FULLSCREEN); /* storing info */ al_get_display_mode(al_get_num_display_modes() - 1, &disp_data); CurrentScreenWidth = disp_data.width; CurrentScreenHeight = disp_data.height; /* creating display with different resolutions for different screens */ display = al_create_display(CurrentScreenWidth, CurrentScreenHeight); } else { al_set_new_display_flags(ALLEGRO_WINDOWED); display = al_create_display(CurrentScreenWidth, CurrentScreenHeight); } if (!display) { al_show_native_message_box(display, "Error", "Display Settings", "Couldn't create a display.", NULL, ALLEGRO_MESSAGEBOX_ERROR); exit(-1); } /* setting new window title */ al_set_window_title(display, "Snake"); // ----------------------- /* creating fonts */ ALLEGRO_FONT * font = al_load_font(MainFont, 36, ALLEGRO_ALIGN_CENTER); ALLEGRO_FONT * credits_font = al_load_font(CreditsFont, 20, NULL); if (!font) { al_show_native_message_box(display, "Error", "Could not load font file.", "Have you included the resources in the same directory of the program?", NULL, ALLEGRO_MESSAGEBOX_ERROR); exit(-1); } /* loading audio samples */ ALLEGRO_SAMPLE * over_button_sound = al_load_sample(OverButton); ALLEGRO_SAMPLE * pressed_button_sound = al_load_sample(PressedButton); ALLEGRO_SAMPLE * eating_apple_sound = al_load_sample(EatApple); ALLEGRO_SAMPLE * game_over_sound = al_load_sample(GameOverSound); if (!over_button_sound || !pressed_button_sound) { al_show_native_message_box(display, "Error", "Could not load one or more sound files.", "Your resources folder must be corrupt, please download it again.", NULL, ALLEGRO_MESSAGEBOX_ERROR); exit(-1); } al_reserve_samples(2); /* creating timer */ ALLEGRO_TIMER * timer = al_create_timer(1.0 / FPS); ALLEGRO_TIMER *frametimer = al_create_timer(1.0 / frameFPS); /* creating event queue */ ALLEGRO_EVENT_QUEUE * event_queue = al_create_event_queue(); 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_register_event_source(event_queue, al_get_timer_event_source(frametimer)); al_register_event_source(event_queue, al_get_mouse_event_source()); al_register_event_source(event_queue, al_get_keyboard_event_source()); ALLEGRO_KEYBOARD_STATE keystate; /* loading BITMAPS */ ALLEGRO_BITMAP * SmallWallpaperBitmap = al_load_bitmap(SmallWallpaper); ALLEGRO_BITMAP * BigWallpaperBitmap = al_load_bitmap(BigWallpaper); ALLEGRO_BITMAP * mouse = al_load_bitmap(MouseCursor); ALLEGRO_BITMAP * applepng = al_load_bitmap(Apple_png); if (!mouse) { al_show_native_message_box(display, "Error", "Could not load one or more resource file.", "Your resources folder must be corrupt, please download it again.", NULL, ALLEGRO_MESSAGEBOX_ERROR); exit(-1); } al_hide_mouse_cursor(display); /* ---- VARIABLES ---- */ bool done = false, change_resolution = false, draw = true; int mouse_x = CurrentScreenWidth, mouse_y = CurrentScreenHeight; /* mouse */ bool left_mouse_button_down = false; bool left_mouse_button_up = false; /* MAIN MENU */ int button_displacement; if (!Fullscreen) { button_displacement = 20; } else { button_displacement = 15; } Button play_button(50, 20, Blue, 0, -button_displacement); Button options_button(40, 15, Blue); Button exit_button(40, 15, Blue, 0, button_displacement); /* PLAY */ string score; Direction new_direction; int speed_up, speed_up_anim_frame = 0; bool speed_up_anim = false; Snake snake; Apple apple; /* starting timers */ al_start_timer(timer); al_start_timer(frametimer); while (!done) { /* actually defining our events */ ALLEGRO_EVENT events; al_wait_for_event(event_queue, &events); al_get_keyboard_state(&keystate); switch (gameState) { case MainMenu: { /* WINDOW */ if (events.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { done = true; } /* MOUSE */ if (events.type == ALLEGRO_EVENT_MOUSE_AXES) { mouse_x = events.mouse.x; mouse_y = events.mouse.y; draw = true; } if (events.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) { /* left button */ if (events.mouse.button & 1) { left_mouse_button_down = true; draw = true; } } if (events.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) { /* left button */ if (events.mouse.button & 1) { left_mouse_button_down = false; left_mouse_button_up = true; draw = true; } } /* button conditions */ if (play_button.MouseOverButton(mouse_x, mouse_y) && !play_button.StillOverButton) { play_button.play_over_button_sound = true; } if (options_button.MouseOverButton(mouse_x, mouse_y) && !options_button.StillOverButton) { options_button.play_over_button_sound = true; } if (exit_button.MouseOverButton(mouse_x, mouse_y) && !exit_button.StillOverButton) { exit_button.play_over_button_sound = true; } /* KEYBOARD */ if (events.type == ALLEGRO_EVENT_KEY_UP) { switch (events.keyboard.keycode) { case ALLEGRO_KEY_ESCAPE: { done = true; break; } case ALLEGRO_KEY_SPACE: case ALLEGRO_KEY_ENTER: { /* STARTING GAME NOW */ new_direction = RIGHT; speed_up = 0; snake.ResetSnakeDetails(); apple.NewApple(snake.GetSnakeCells()); gameState = PlayGame; } } break; } /* ------------ NOW DRAWING ------------ */ if (draw) { /* drawing wallpaper */ if (Fullscreen) { al_draw_scaled_bitmap(BigWallpaperBitmap, 0, 0, al_get_bitmap_width(BigWallpaperBitmap), al_get_bitmap_height(BigWallpaperBitmap), 0, 0, CurrentScreenWidth, CurrentScreenHeight, NULL); } else { al_draw_bitmap(SmallWallpaperBitmap, 0, 0, 0); } /* -- play button -- */ if (play_button.MouseOverButton(mouse_x, mouse_y)) { play_button.SetButtonColor(LightBlue); /* button pressed */ if (left_mouse_button_down) { play_button.pressed_button = true; play_button.SetButtonColor(DarkBlue); } /* button released */ else if (left_mouse_button_up) { play_button.pressed_button = false; play_button.StillPressingButton = false; play_button.SetButtonColor(Blue); /* STARTING GAME NOW */ new_direction = RIGHT; speed_up = 0; snake.ResetSnakeDetails(); apple.NewApple(snake.GetSnakeCells()); gameState = PlayGame; } play_button.DisplayButton(); } else { play_button.pressed_button = false; play_button.StillPressingButton = false; play_button.StillOverButton = false; play_button.SetButtonColor(Blue); play_button.DisplayButton(); } /* -- options button -- */ if (options_button.MouseOverButton(mouse_x, mouse_y)) { options_button.SetButtonColor(LightBlue); /* button pressed */ if (left_mouse_button_down) { options_button.pressed_button = true; options_button.SetButtonColor(DarkBlue); } /* button released */ else if (left_mouse_button_up) { options_button.pressed_button = false; options_button.StillPressingButton = false; options_button.SetButtonColor(Blue); switch (Fullscreen) { case 0: { Fullscreen = 1; done = true; change_resolution = true; break; } case 1: { Fullscreen = 0; done = true; change_resolution = true; break; } } } options_button.DisplayButton(); } else { options_button.pressed_button = false; options_button.StillPressingButton = false; options_button.StillOverButton = false; options_button.SetButtonColor(Blue); options_button.DisplayButton(); } /* -- exit button -- */ if (exit_button.MouseOverButton(mouse_x, mouse_y)) { exit_button.SetButtonColor(LightBlue); /* button pressed */ if (left_mouse_button_down) { exit_button.pressed_button = true; exit_button.SetButtonColor(DarkBlue); } /* button released */ else if (left_mouse_button_up) { exit_button.pressed_button = false; exit_button.StillPressingButton = false; exit_button.SetButtonColor(Blue); done = true; } exit_button.DisplayButton(); } else { exit_button.pressed_button = false; exit_button.StillPressingButton = false; exit_button.StillOverButton = false; exit_button.SetButtonColor(Blue); exit_button.DisplayButton(); } /* -- sound -- */ /* mouse over button */ if (play_button.MouseOverButton(mouse_x, mouse_y) && !play_button.StillOverButton) { play_button.StillOverButton = true; al_play_sample(over_button_sound, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, 0); } if (options_button.MouseOverButton(mouse_x, mouse_y) && !options_button.StillOverButton) { options_button.StillOverButton = true; al_play_sample(over_button_sound, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, 0); } if (exit_button.MouseOverButton(mouse_x, mouse_y) && !exit_button.StillOverButton) { exit_button.StillOverButton = true; al_play_sample(over_button_sound, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, 0); } /* button pressed */ if (play_button.pressed_button && !play_button.StillPressingButton) { play_button.StillPressingButton = true; al_play_sample(pressed_button_sound, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, 0); } else if (options_button.pressed_button && !options_button.StillPressingButton) { options_button.StillPressingButton = true; al_play_sample(pressed_button_sound, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, 0); } else if (exit_button.pressed_button && !exit_button.StillPressingButton) { exit_button.StillPressingButton = true; al_play_sample(pressed_button_sound, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, 0); } /* -- text -- */ string fullscreenmode_string; if (Fullscreen) { fullscreenmode_string = "Fullscreen: On"; } else { fullscreenmode_string = "Fullscreen: Off"; } al_draw_text(font, White, CurrentScreenWidth / 2, play_button.GetButtonHeightCenter() - 23, ALLEGRO_ALIGN_CENTER, "New Game"); al_draw_text(font, White, CurrentScreenWidth / 2, options_button.GetButtonHeightCenter() - 23, ALLEGRO_ALIGN_CENTER, fullscreenmode_string.c_str()); al_draw_text(font, White, CurrentScreenWidth / 2, exit_button.GetButtonHeightCenter() - 23, ALLEGRO_ALIGN_CENTER, "Exit"); al_draw_text(credits_font, White, 3, CurrentScreenHeight - 20, NULL, "FEUP 2013 - Henrique Ferrolho"); /* -- mouse cursor -- */ al_draw_bitmap(mouse, mouse_x, mouse_y, NULL); al_flip_display(); al_clear_to_color(al_map_rgb(0, 0, 0)); left_mouse_button_up = false; draw = false; } break; } case PlayGame: { if (events.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { done = true; } /* KEYBOARD */ if (events.type == ALLEGRO_EVENT_KEY_UP) { switch (events.keyboard.keycode) { case ALLEGRO_KEY_ESCAPE: { /* going back to MAIN MENU */ draw = true; gameState = MainMenu; break; } case ALLEGRO_KEY_ENTER: case ALLEGRO_KEY_SPACE: { /* pausing game */ draw = true; gameState = PauseGame; break; } } break; } if (events.type == ALLEGRO_EVENT_TIMER) { if (events.timer.source == timer) { draw = true; /* navigation keys */ if (al_key_down(&keystate, ALLEGRO_KEY_DOWN) || al_key_down(&keystate, ALLEGRO_KEY_S)) { new_direction = DOWN; } else if (al_key_down(&keystate, ALLEGRO_KEY_UP) || al_key_down(&keystate, ALLEGRO_KEY_W)) { new_direction = UP; } else if (al_key_down(&keystate, ALLEGRO_KEY_RIGHT) || al_key_down(&keystate, ALLEGRO_KEY_D)) { new_direction = RIGHT; } else if (al_key_down(&keystate, ALLEGRO_KEY_LEFT) || al_key_down(&keystate, ALLEGRO_KEY_A)) { new_direction = LEFT; } /* checking boundaries */ if (!snake.IsInScreenBoundaries() || snake.EatedItself()) { draw = true; al_play_sample(game_over_sound, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, 0); gameState = GameOver; break; } } else if (events.timer.source == frametimer) { /* moving snake */ snake.SetSnakeDirection(new_direction); snake.MoveSnake(); if (snake.EatedApple(apple.GetAppleX(), apple.GetAppleY())) { al_play_sample(eating_apple_sound, 0.5, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, 0); apple.NewApple(snake.GetSnakeCells()); snake.IncreaseSnakeLength(); draw = true; } } } /* ------------ NOW DRAWING ------------ */ if (draw) { /* game frame */ if (Fullscreen) { al_draw_rectangle(0, 0, CurrentScreenWidth, CurrentScreenHeight, DarkRed, 20); //al_draw_rectangle(0, 0, 1360, 760, DarkRed, 20); } else { al_draw_rectangle(0, 0, CurrentScreenWidth, CurrentScreenHeight, DarkRed, 20); } apple.DrawApple(applepng); snake.DrawSnake(); /* increasing speed */ if (snake.GetSnakeCells().size() < 5) { al_set_timer_speed(frametimer, 1.0 / frameFPS); } else if (snake.GetSnakeCells().size() < 10) { if (speed_up == 0) { speed_up++; speed_up_anim = true; } al_set_timer_speed(frametimer, 1.0 / 14); } else if (snake.GetSnakeCells().size() < 20) { if (speed_up == 1) { snake.SetColor(LightBlue); speed_up++; speed_up_anim = true; } al_set_timer_speed(frametimer, 1.0 / 16); } else if (snake.GetSnakeCells().size() < 30) { if (speed_up == 2) { speed_up++; speed_up_anim = true; } al_set_timer_speed(frametimer, 1.0 / 18); } else if (snake.GetSnakeCells().size() < 40) { if (speed_up == 3) { snake.SetColor(DarkRed); speed_up++; speed_up_anim = true; } al_set_timer_speed(frametimer, 1.0 / 20); } /* speed up animation */ if (speed_up_anim) { if (speed_up_anim_frame < 10) { al_draw_text(font, White, CurrentScreenWidth / 2, (CurrentScreenHeight / 2) - 30, ALLEGRO_ALIGN_CENTER, "SPEED UP!"); speed_up_anim_frame++; } else if (speed_up_anim_frame < 20) { al_draw_text(font, Yellow, CurrentScreenWidth / 2, (CurrentScreenHeight / 2) - 30, ALLEGRO_ALIGN_CENTER, "SPEED UP!"); speed_up_anim_frame++; } else if (speed_up_anim_frame < 30) { al_draw_text(font, White, CurrentScreenWidth / 2, (CurrentScreenHeight / 2) - 30, ALLEGRO_ALIGN_CENTER, "SPEED UP!"); speed_up_anim_frame++; } else if (speed_up_anim_frame < 40) { al_draw_text(font, Yellow, CurrentScreenWidth / 2, (CurrentScreenHeight / 2) - 30, ALLEGRO_ALIGN_CENTER, "SPEED UP!"); speed_up_anim_frame++; } else if (speed_up_anim_frame < 50) { al_draw_text(font, White, CurrentScreenWidth / 2, (CurrentScreenHeight / 2) - 30, ALLEGRO_ALIGN_CENTER, "SPEED UP!"); speed_up_anim_frame++; } else if (speed_up_anim_frame < 60) { speed_up_anim = false; speed_up_anim_frame = 0; } } /* printing score */ stringstream ss; ss << "Score: " << snake.GetSnakeCells().size(); score = ss.str(); al_draw_text(credits_font, Yellow, 60, 15, ALLEGRO_ALIGN_CENTER, score.c_str()); al_flip_display(); al_clear_to_color(al_map_rgb(0, 0, 0)); draw = false; } break; } case PauseGame: { if (events.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { done = true; } if (events.type == ALLEGRO_EVENT_KEY_UP) { switch (events.keyboard.keycode) { case ALLEGRO_KEY_SPACE: case ALLEGRO_KEY_ENTER: { /* resume game */ draw = true; gameState = PlayGame; break; } } break; } /* ------------ NOW DRAWING ------------ */ if (draw) { /* game frame */ if (Fullscreen) { al_draw_rectangle(0, 0, CurrentScreenWidth, CurrentScreenHeight, DarkRed, 20); //al_draw_rectangle(0, 0, 1360, 760, DarkRed, 20); } else { al_draw_rectangle(0, 0, CurrentScreenWidth, CurrentScreenHeight, DarkRed, 20); } apple.DrawApple(applepng); snake.DrawSnake(); /* printing score */ stringstream ss; ss << "Score: " << snake.GetSnakeCells().size(); score = ss.str(); al_draw_text(credits_font, Yellow, 60, 15, ALLEGRO_ALIGN_CENTER, score.c_str()); al_draw_text(font, Yellow, CurrentScreenWidth / 2, (CurrentScreenHeight / 2) - 30, ALLEGRO_ALIGN_CENTER, "GAME PAUSED"); al_flip_display(); draw = false; } break; } case GameOver: { if (events.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { done = true; } /* MOUSE */ if (events.type == ALLEGRO_EVENT_MOUSE_AXES) { mouse_x = events.mouse.x; mouse_y = events.mouse.y; draw = true; } if (events.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) { /* left button */ if (events.mouse.button & 1) { left_mouse_button_down = true; draw = true; } } if (events.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) { /* left button */ if (events.mouse.button & 1) { left_mouse_button_down = false; left_mouse_button_up = true; draw = true; } } /* going to MAIN MENU */ if (events.type == ALLEGRO_EVENT_KEY_UP) { switch (events.keyboard.keycode) { case ALLEGRO_KEY_SPACE: case ALLEGRO_KEY_ENTER: { draw = true; gameState = MainMenu; break; } } break; } if (left_mouse_button_up) { left_mouse_button_up = false; draw = true; gameState = MainMenu; break; } if (draw) { al_draw_filled_rectangle(0, 0, CurrentScreenWidth, CurrentScreenHeight, DarkRed); /* printing score */ stringstream ss; ss << "Score: " << snake.GetSnakeCells().size(); score = ss.str(); al_draw_text(font, Yellow, CurrentScreenWidth / 2, (CurrentScreenHeight / 2) - 80, ALLEGRO_ALIGN_CENTER, score.c_str()); al_draw_text(font, White, CurrentScreenWidth / 2, (CurrentScreenHeight / 2) - 30, ALLEGRO_ALIGN_CENTER, "Click to continue"); /* -- mouse cursor -- */ al_draw_bitmap(mouse, mouse_x, mouse_y, NULL); al_flip_display(); } break; } } } /* dealocating memory */ al_destroy_display(display); al_destroy_font(font); al_destroy_timer(timer); al_destroy_bitmap(mouse); al_destroy_sample(over_button_sound); al_destroy_sample(pressed_button_sound); al_destroy_event_queue(event_queue); if (change_resolution) { CurrentScreenWidth = DefaultScreenWidth; CurrentScreenHeight = DefaultScreenHeight; start_game(Fullscreen); } }
static void setup_state(const char* vtxs, const ALLEGRO_VERTEX_DECL* decl, ALLEGRO_BITMAP* texture) { if(decl) { ALLEGRO_VERTEX_ELEMENT* e; e = &decl->elements[ALLEGRO_PRIM_POSITION]; if(e->attribute) { int ncoord = 0; GLenum type = 0; bool normalized; glEnableClientState(GL_VERTEX_ARRAY); convert_storage(e->storage, &type, &ncoord, &normalized); glVertexPointer(ncoord, type, decl->stride, vtxs + e->offset); } else { glDisableClientState(GL_VERTEX_ARRAY); } e = &decl->elements[ALLEGRO_PRIM_TEX_COORD]; if(!e->attribute) e = &decl->elements[ALLEGRO_PRIM_TEX_COORD_PIXEL]; if(texture && e->attribute) { int ncoord = 0; GLenum type = 0; bool normalized; glEnableClientState(GL_TEXTURE_COORD_ARRAY); convert_storage(e->storage, &type, &ncoord, &normalized); glTexCoordPointer(ncoord, type, decl->stride, vtxs + e->offset); } else { glDisableClientState(GL_TEXTURE_COORD_ARRAY); } e = &decl->elements[ALLEGRO_PRIM_COLOR_ATTR]; if(e->attribute) { glEnableClientState(GL_COLOR_ARRAY); glColorPointer(4, GL_FLOAT, decl->stride, vtxs + e->offset); } else { glDisableClientState(GL_COLOR_ARRAY); glColor4f(1, 1, 1, 1); } } else { const ALLEGRO_VERTEX* vtx = (const ALLEGRO_VERTEX*)vtxs; glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glVertexPointer(3, GL_FLOAT, sizeof(ALLEGRO_VERTEX), &vtx[0].x); glColorPointer(4, GL_FLOAT, sizeof(ALLEGRO_VERTEX), &vtx[0].color.r); glTexCoordPointer(2, GL_FLOAT, sizeof(ALLEGRO_VERTEX), &vtx[0].u); } if (texture) { GLuint gl_texture = al_get_opengl_texture(texture); int true_w, true_h; int tex_x, tex_y; GLuint current_texture; float mat[4][4] = { {1, 0, 0, 0}, {0, -1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1} }; int height; if (texture->parent) height = texture->parent->h; else height = texture->h; al_get_opengl_texture_size(texture, &true_w, &true_h); al_get_opengl_texture_position(texture, &tex_x, &tex_y); mat[3][0] = (float)tex_x / true_w; mat[3][1] = (float)(height - tex_y) / true_h; if(decl) { if(decl->elements[ALLEGRO_PRIM_TEX_COORD_PIXEL].attribute) { mat[0][0] = 1.0f / true_w; mat[1][1] = -1.0f / true_h; } else { mat[0][0] = (float)al_get_bitmap_width(texture) / true_w; mat[1][1] = -(float)al_get_bitmap_height(texture) / true_h; } } else { mat[0][0] = 1.0f / true_w; mat[1][1] = -1.0f / true_h; } glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint*)¤t_texture); if (current_texture != gl_texture) { glBindTexture(GL_TEXTURE_2D, gl_texture); } glMatrixMode(GL_TEXTURE); glLoadMatrixf(mat[0]); glMatrixMode(GL_MODELVIEW); } else { glBindTexture(GL_TEXTURE_2D, 0); } }
bool initialize(int argc, char * argv[]) { const char * val; ALLEGRO_BITMAP * bp; process_arguments(argc, argv); if(!t3f_initialize(640, 480, 60.0, "The Devil", logic, render, T3F_DEFAULT | T3F_USE_MOUSE)) { return false; } t3f_3d_set_projection(&projection, 0, 0, 640, 480, 320, 240); t3f_3d_select_projection(&projection); animation[ANIMATION_PLAYER] = t3f_load_animation_from_bitmap("data/player.png"); if(!animation[ANIMATION_PLAYER]) { return false; } animation[ANIMATION_DEMON] = t3f_load_animation_from_bitmap("data/demon.png"); if(!animation[ANIMATION_DEMON]) { return false; } animation[ANIMATION_ARCHDEMON] = t3f_load_animation_from_bitmap("data/archdemon.png"); if(!animation[ANIMATION_ARCHDEMON]) { return false; } animation[ANIMATION_PLAYER_SHOT] = t3f_load_animation_from_bitmap("data/player_shot.png"); if(!animation[ANIMATION_PLAYER_SHOT]) { return false; } animation[ANIMATION_ENEMY_SHOT] = t3f_load_animation_from_bitmap("data/enemy_shot.png"); if(!animation[ANIMATION_ENEMY_SHOT]) { return false; } animation[ANIMATION_SPIRIT] = t3f_create_animation(); if(!animation[ANIMATION_SPIRIT]) { return false; } bp = al_load_bitmap("data/spirit0.png"); t3f_animation_add_bitmap(animation[ANIMATION_SPIRIT], bp); t3f_animation_add_frame(animation[ANIMATION_SPIRIT], 0, 0, 0, 0, al_get_bitmap_width(bp), al_get_bitmap_height(bp), 0, 5); bp = al_load_bitmap("data/spirit1.png"); t3f_animation_add_bitmap(animation[ANIMATION_SPIRIT], bp); t3f_animation_add_frame(animation[ANIMATION_SPIRIT], 1, 0, 0, 0, al_get_bitmap_width(bp), al_get_bitmap_height(bp), 0, 5); bp = al_load_bitmap("data/spirit2.png"); t3f_animation_add_bitmap(animation[ANIMATION_SPIRIT], bp); t3f_animation_add_frame(animation[ANIMATION_SPIRIT], 2, 0, 0, 0, al_get_bitmap_width(bp), al_get_bitmap_height(bp), 0, 5); animation[ANIMATION_LOGO] = t3f_load_animation_from_bitmap("data/logo.png"); if(!animation[ANIMATION_LOGO]) { return false; } animation[ANIMATION_TITLE] = t3f_load_animation_from_bitmap("data/title_logo.png"); if(!animation[ANIMATION_TITLE]) { return false; } sprite_sheet = al_create_bitmap(512, 512); if(!sprite_sheet) { return false; } t3f_start_sprite_sheet(sprite_sheet, T3F_SPRITE_SHEET_TYPE_SPRITES); t3f_add_animation_to_sprite_sheet(animation[ANIMATION_PLAYER]); t3f_add_animation_to_sprite_sheet(animation[ANIMATION_DEMON]); t3f_add_animation_to_sprite_sheet(animation[ANIMATION_ARCHDEMON]); t3f_add_animation_to_sprite_sheet(animation[ANIMATION_PLAYER_SHOT]); t3f_add_animation_to_sprite_sheet(animation[ANIMATION_ENEMY_SHOT]); t3f_add_animation_to_sprite_sheet(animation[ANIMATION_SPIRIT]); t3f_finish_sprite_sheet(); font[FONT_GAME] = al_load_bitmap_font("data/default_font.png"); if(!font[FONT_GAME]) { return false; } sample[SAMPLE_GAME_OVER] = al_load_sample("data/game_over.ogg"); if(!sample[SAMPLE_GAME_OVER]) { return false; } sample[SAMPLE_LEVEL_UP] = al_load_sample("data/level_up.ogg"); if(!sample[SAMPLE_LEVEL_UP]) { return false; } sample[SAMPLE_MAX_MULTIPLIER] = al_load_sample("data/max_multiplier.ogg"); if(!sample[SAMPLE_MAX_MULTIPLIER]) { return false; } sample[SAMPLE_HIGH_SCORE] = al_load_sample("data/high_score.ogg"); if(!sample[SAMPLE_HIGH_SCORE]) { return false; } sample[SAMPLE_TWIN_SHOT] = al_load_sample("data/twin_shot.ogg"); if(!sample[SAMPLE_TWIN_SHOT]) { return false; } sample[SAMPLE_TRIPLE_SHOT] = al_load_sample("data/triple_shot.ogg"); if(!sample[SAMPLE_TRIPLE_SHOT]) { return false; } sample[SAMPLE_POWERUP] = al_load_sample("data/powerup.ogg"); if(!sample[SAMPLE_POWERUP]) { return false; } sample[SAMPLE_SHOOT] = al_load_sample("data/shoot.ogg"); if(!sample[SAMPLE_SHOOT]) { return false; } sample[SAMPLE_HIT] = al_load_sample("data/hit.ogg"); if(!sample[SAMPLE_HIT]) { return false; } sample[SAMPLE_DIE] = al_load_sample("data/die.ogg"); if(!sample[SAMPLE_DIE]) { return false; } sample[SAMPLE_MULTIPLIER] = al_load_sample("data/multiplier.ogg"); if(!sample[SAMPLE_MULTIPLIER]) { return false; } cinema = load_cinema("data/intro.cin", 0); if(!cinema) { return false; } ending_cinema = load_cinema("data/ending.cin", 0); if(!ending_cinema) { return false; } level_color[0] = al_map_rgba(131, 0, 0, 255); level_color[1] = al_map_rgba(131, 22, 0, 255); level_color[2] = al_map_rgba(131, 46, 0, 255); level_color[3] = al_map_rgba(131, 68, 0, 255); level_color[4] = al_map_rgba(131, 99, 0, 255); level_color[5] = al_map_rgba(131, 126, 0, 255); level_color[6] = al_map_rgba(101, 131, 0, 255); level_color[7] = al_map_rgba(77, 131, 0, 255); level_color[8] = al_map_rgba(0, 131, 73, 255); level_color[9] = al_map_rgba(0, 105, 131, 255); level_color[10] = al_map_rgba(0, 135, 254, 255); hyperlink_set_driver(NULL); val = al_get_config_value(t3f_config, "Save Data", "High Score"); if(val) { high_score = atoi(val); } t3f_play_music("data/title.xm", 0.0, 0.0); state = STATE_LOGO; return true; }
void Tile::AssembleTile() { if(!visible) { return; } if((material.type == INORGANIC) && (material.index == -1)) { material.index = 0; } bool defaultSnow = 1; t_SpriteWithOffset sprite; c_sprite* spriteobject; int32_t drawx = x; int32_t drawy = y; int32_t drawz = z; ownerSegment->CorrectTileForSegmentOffset( drawx, drawy, drawz); ownerSegment->CorrectTileForSegmentRotation( drawx, drawy, drawz); pointToScreen((int*)&drawx, (int*)&drawy, drawz); drawx -= (TILEWIDTH>>1)*ssConfig.scale; //TODO the following check should get incorporated into segment beautification if(((drawx + TILEWIDTH*ssConfig.scale) < 0) || (drawx > ssState.ScreenW) || ((drawy + (TILETOPHEIGHT + FLOORHEIGHT)*ssConfig.scale) < 0) || (drawy - WALLHEIGHT*ssConfig.scale > ssState.ScreenH)) { return; } bool chopThisTile = 0; if(ssConfig.truncate_walls == 1) { chopThisTile = 1; } else if(ssConfig.truncate_walls == 2 && obscuringCreature == 1) { chopThisTile = 1; } else if(ssConfig.truncate_walls == 3 && (obscuringCreature == 1 || obscuringBuilding == 1)) { chopThisTile = 1; } else if(ssConfig.truncate_walls == 4 && obscuringBuilding == 1) { chopThisTile = 1; } if(building.type == BUILDINGTYPE_BLACKBOX) { AssembleSpriteFromSheet( SPRITEOBJECT_BLACK, IMGObjectSheet, al_map_rgb(255,255,255), drawx, drawy+FLOORHEIGHT*ssConfig.scale); AssembleSpriteFromSheet( SPRITEOBJECT_BLACK, IMGObjectSheet, al_map_rgb(255,255,255), drawx, drawy); return; } ALLEGRO_COLOR plateBorderColor = al_map_rgb(85,85,85); int rando = randomCube[x%RANDOM_CUBE][y%RANDOM_CUBE][z%RANDOM_CUBE]; //Draw Ramp Tops if(tileType == tiletype::RampTop){ Tile * b = this->ownerSegment->getTile(this->x, this->y, this->z-1); if(b && b->tileShapeBasic() == tiletype_shape_basic::Ramp) { spriteobject = GetTileSpriteMap(b->tileType, b->material, b->consForm); if (spriteobject->get_sheetindex() == UNCONFIGURED_INDEX) { spriteobject->set_sheetindex(0); spriteobject->set_fileindex(INVALID_INDEX); spriteobject->set_defaultsheet(IMGRampSheet); } if (spriteobject->get_sheetindex() != INVALID_INDEX) { spriteobject->set_size(SPRITEWIDTH, TILETOPHEIGHT); spriteobject->set_plate_layout(RAMPTOPPLATE); spriteobject->set_offset(0, WALLHEIGHT); spriteobject->assemble_world_offset(x, y, z, 0, b); spriteobject->set_offset(0, 0); } spriteobject->set_plate_layout(TILEPLATE); } } //Draw Floor if( tileShapeBasic()==tiletype_shape_basic::Floor || tileShapeBasic()==tiletype_shape_basic::Wall || tileShapeBasic()==tiletype_shape_basic::Ramp || tileShapeBasic()==tiletype_shape_basic::Stair) { //If plate has no floor, look for a Filler Floor from it's wall if (tileShapeBasic()==tiletype_shape_basic::Floor) { spriteobject = GetFloorSpriteMap(tileType, this->material, consForm); } else if (tileShapeBasic()==tiletype_shape_basic::Wall) { spriteobject = GetFloorSpriteMap(tileType, this->material, consForm); } else if (tileShapeBasic()==tiletype_shape_basic::Ramp) { spriteobject = GetFloorSpriteMap(tileType, this->material, consForm); } else if (tileShapeBasic()==tiletype_shape_basic::Stair) { spriteobject = GetFloorSpriteMap(tileType, this->material, consForm); } if(spriteobject->get_sheetindex() != INVALID_INDEX) { if (spriteobject->get_sheetindex() == UNCONFIGURED_INDEX) { spriteobject->set_sheetindex(SPRITEOBJECT_FLOOR_NA); spriteobject->set_fileindex(INVALID_INDEX); spriteobject->set_offset(0, WALLHEIGHT); spriteobject->assemble_world(x, y, z, this); } else { spriteobject->assemble_world(x, y, z, this); } } } //Floor Engravings if((tileShapeBasic()==tiletype_shape_basic::Floor) && engraving_character && engraving_flags.bits.floor) { AssembleSpriteFromSheet( engraving_character, IMGEngFloorSheet, al_map_rgba_f(1.0,1.0,1.0,((engraving_quality + 5.0f) / 10.0f)), drawx, drawy, this ); } //Draw Ramp if(tileShapeBasic()==tiletype_shape_basic::Ramp) { spriteobject = GetTileSpriteMap(tileType, material, consForm); if (spriteobject->get_sheetindex() == UNCONFIGURED_INDEX) { spriteobject->set_sheetindex(0); spriteobject->set_fileindex(INVALID_INDEX); spriteobject->set_defaultsheet(IMGRampSheet); } if (spriteobject->get_sheetindex() != INVALID_INDEX) { spriteobject->set_size(SPRITEWIDTH, SPRITEHEIGHT); spriteobject->set_plate_layout(RAMPBOTTOMPLATE); spriteobject->assemble_world_offset(x, y, z, 0, this, (chopThisTile && this->z == ownerSegment->pos.z + ownerSegment->size.z -2)); } spriteobject->set_plate_layout(TILEPLATE); } if(snowlevel <= bloodlevel) { AssembleFloorBlood ( drawx, drawy ); } //first part of snow if(tileShapeBasic()!=tiletype_shape_basic::Ramp && tileShapeBasic()!=tiletype_shape_basic::Wall && tileShapeBasic()!=tiletype_shape_basic::Stair && defaultSnow && snowlevel>bloodlevel) { if(snowlevel > 75) { AssembleSpriteFromSheet( 20, IMGObjectSheet, bloodcolor, drawx, drawy, this); } else if(snowlevel > 50) { AssembleSpriteFromSheet( 21, IMGObjectSheet, bloodcolor, drawx, drawy, this ); } else if(snowlevel > 25) { AssembleSpriteFromSheet( 22, IMGObjectSheet, bloodcolor, drawx, drawy, this ); } else if(snowlevel > 0) { AssembleSpriteFromSheet( 23, IMGObjectSheet, bloodcolor, drawx, drawy, this ); } } ////vegetation //if(tree.index > 0 || tree.type > 0){ // c_sprite * vegetationsprite = 0; // vegetationsprite = GetSpriteVegetation( (TileClass) getVegetationType( this->floorType ), tree.index ); // if(vegetationsprite) // vegetationsprite->assemble_world(x, y, z); //} //items if(Item.item.type >= 0) { if( contentLoader->itemConfigs[Item.item.type] && (Item.item.index < contentLoader->itemConfigs[Item.item.type]->subItems.size()) && contentLoader->itemConfigs[Item.item.type]->subItems[Item.item.index]) { contentLoader->itemConfigs[Item.item.type]->subItems[Item.item.index]->sprite.assemble_world(x, y, z, this); } else if ( contentLoader->itemConfigs[Item.item.type] && contentLoader->itemConfigs[Item.item.type]->configured) { contentLoader->itemConfigs[Item.item.type]->default_sprite.assemble_world(x, y, z, this); } else { AssembleSpriteFromSheet( 350, IMGObjectSheet, lookupMaterialColor(Item.matt, Item.dyematt), drawx, (tileShapeBasic()==tiletype_shape_basic::Ramp)?(drawy - ((WALLHEIGHT/2)*ssConfig.scale)):drawy , this); } } //shadow if (shadow > 0) { AssembleSpriteFromSheet( BASE_SHADOW_PLATE + shadow - 1, IMGObjectSheet, al_map_rgb(255,255,255), drawx, (tileShapeBasic()==tiletype_shape_basic::Ramp)?(drawy - ((WALLHEIGHT/2)*ssConfig.scale)):drawy , this); } //Building bool skipBuilding = (building.type == building_type::Civzone && !ssConfig.show_zones) || (building.type == building_type::Stockpile && !ssConfig.show_stockpiles); if(building.type != BUILDINGTYPE_NA && !skipBuilding) { for(uint32_t i=0; i < building.sprites.size(); i++) { spriteobject = &building.sprites[i]; if(building.parent) { spriteobject->assemble_world(x, y, z, building.parent); } else { spriteobject->assemble_world(x, y, z, this); } } } //Draw Stairs if(tileShapeBasic()==tiletype_shape_basic::Stair) { bool mirrored = false; if(findWallCloseTo(ownerSegment, this) == eSimpleW) { mirrored = true; } //down part spriteobject = GetFloorSpriteMap(tileType, material, consForm); if(spriteobject->get_sheetindex() != INVALID_INDEX && spriteobject->get_sheetindex() != UNCONFIGURED_INDEX) { if (mirrored) { spriteobject->assemble_world_offset(x, y, z, 1, this); } else { spriteobject->assemble_world(x, y, z, this); } } //up part spriteobject = GetTileSpriteMap(tileType, material, consForm); if(spriteobject->get_sheetindex() != INVALID_INDEX && spriteobject->get_sheetindex() != UNCONFIGURED_INDEX) { if (mirrored) { spriteobject->assemble_world_offset(x, y, z, 1, this); } else { spriteobject->assemble_world(x, y, z, this); } } } if(tileShapeBasic()==tiletype_shape_basic::Floor || tileShapeBasic()==tiletype_shape_basic::Wall) { //draw wall spriteobject = GetTileSpriteMap(tileType, material, consForm); int spriteOffset = 0; if (spriteobject->get_sheetindex() == UNCONFIGURED_INDEX) { if(tileShapeBasic()==tiletype_shape_basic::Wall){ spriteobject->set_sheetindex(SPRITEOBJECT_WALL_NA); spriteobject->set_fileindex(INVALID_INDEX); spriteobject->set_plate_layout(TILEPLATE); spriteobject->set_defaultsheet(IMGObjectSheet); } else { //unconfigured non-walls are not valid spriteobject->set_sheetindex(INVALID_INDEX); } } if (spriteobject->get_sheetindex() == INVALID_INDEX ) { //skip } else { spriteobject->assemble_world(x, y, z, this, (chopThisTile && this->z == ownerSegment->pos.z + ownerSegment->size.z -2)); } } //Wall Engravings if((tileShapeBasic()==tiletype_shape_basic::Wall) && engraving_character) { if(ownerSegment->segState.DisplayedRotation == 0) { if(engraving_flags.bits.east) { AssembleSpriteFromSheet( engraving_character, IMGEngRightSheet, al_map_rgba_f(1.0,1.0,1.0,((engraving_quality + 5.0f) / 10.0f)), drawx, drawy, this ); } if(engraving_flags.bits.south) { AssembleSpriteFromSheet( engraving_character, IMGEngLeftSheet, al_map_rgba_f(1.0,1.0,1.0,((engraving_quality + 5.0f) / 10.0f)), drawx, drawy, this ); } } if(ownerSegment->segState.DisplayedRotation == 1) { if(engraving_flags.bits.north) { AssembleSpriteFromSheet( engraving_character, IMGEngRightSheet, al_map_rgba_f(1.0,1.0,1.0,((engraving_quality + 5.0f) / 10.0f)), drawx, drawy, this ); } if(engraving_flags.bits.east) { AssembleSpriteFromSheet( engraving_character, IMGEngLeftSheet, al_map_rgba_f(1.0,1.0,1.0,((engraving_quality + 5.0f) / 10.0f)), drawx, drawy, this ); } } if(ownerSegment->segState.DisplayedRotation == 2) { if(engraving_flags.bits.west) { AssembleSpriteFromSheet( engraving_character, IMGEngRightSheet, al_map_rgba_f(1.0,1.0,1.0,((engraving_quality + 5.0f) / 10.0f)), drawx, drawy, this ); } if(engraving_flags.bits.north) { AssembleSpriteFromSheet( engraving_character, IMGEngLeftSheet, al_map_rgba_f(1.0,1.0,1.0,((engraving_quality + 5.0f) / 10.0f)), drawx, drawy, this ); } } if(ownerSegment->segState.DisplayedRotation == 3) { if(engraving_flags.bits.south) { AssembleSpriteFromSheet( engraving_character, IMGEngRightSheet, al_map_rgba_f(1.0,1.0,1.0,((engraving_quality + 5.0f) / 10.0f)), drawx, drawy, this ); } if(engraving_flags.bits.west) { AssembleSpriteFromSheet( engraving_character, IMGEngLeftSheet, al_map_rgba_f(1.0,1.0,1.0,((engraving_quality + 5.0f) / 10.0f)), drawx, drawy, this ); } } } if(designation.bits.flow_size > 0) { //if(waterlevel == 7) waterlevel--; uint32_t waterlevel = designation.bits.flow_size + (deepwater ? 1 : 0); if(designation.bits.liquid_type == 0) { contentLoader->water[waterlevel-1].sprite.assemble_world(x, y, z, this, (chopThisTile && this->z == ownerSegment->pos.z + ownerSegment->size.z -2)); } else { contentLoader->lava[waterlevel-1].sprite.assemble_world(x, y, z, this, (chopThisTile && this->z == ownerSegment->pos.z + ownerSegment->size.z -2)); } } // creature if(occ.bits.unit && creature && (ssConfig.show_hidden_tiles || !designation.bits.hidden)) { AssembleCreature(drawx, drawy, creature, this); } //second part of snow if(tileShapeBasic()!=tiletype_shape_basic::Wall && tileShapeBasic()!=tiletype_shape_basic::Stair && defaultSnow && snowlevel>bloodlevel) { if(snowlevel > 75) { AssembleSpriteFromSheet( 24, IMGObjectSheet, bloodcolor, drawx, drawy, this ); } else if(snowlevel > 50) { AssembleSpriteFromSheet( 25, IMGObjectSheet, bloodcolor, drawx, drawy, this ); } else if(snowlevel > 25) { AssembleSpriteFromSheet( 26, IMGObjectSheet, bloodcolor, drawx, drawy, this ); } } if(tileeffect.density>0) { ALLEGRO_COLOR tint = lookupMaterialColor(tileeffect.matt); int size = 0; switch(tileeffect.type){ case df::flow_type::Miasma: AssembleParticleCloud(tileeffect.density, drawx, drawy - (SPRITEHEIGHT/2), SPRITEWIDTH, SPRITEHEIGHT, sprite_miasma, tint); break; case df::flow_type::Steam: AssembleParticleCloud(tileeffect.density, drawx, drawy - (SPRITEHEIGHT/2), SPRITEWIDTH, SPRITEHEIGHT, sprite_water, tint); break; case df::flow_type::Mist: AssembleParticleCloud(tileeffect.density, drawx, drawy - (SPRITEHEIGHT/2), SPRITEWIDTH, SPRITEHEIGHT, sprite_water2, tint); break; case df::flow_type::MaterialDust: AssembleParticleCloud(tileeffect.density, drawx, drawy - (SPRITEHEIGHT/2), SPRITEWIDTH, SPRITEHEIGHT, sprite_dust, tint); break; case df::flow_type::MagmaMist: AssembleParticleCloud(tileeffect.density, drawx, drawy - (SPRITEHEIGHT/2), SPRITEWIDTH, SPRITEHEIGHT, sprite_magma, tint); break; case df::flow_type::Smoke: AssembleParticleCloud(tileeffect.density, drawx, drawy - (SPRITEHEIGHT/2), SPRITEWIDTH, SPRITEHEIGHT, sprite_smoke, tint); break; case df::flow_type::Dragonfire: tint.a*=tileeffect.density/100.0f; tint.g*=tileeffect.density/100.0f; tint.b*=tileeffect.density/100.0f; size = 3 - ((tileeffect.density-1)/25); AssembleSpriteFromSheet((((currentFrameLong+rando)%8)*20+size), sprite_dragonfire, tint, drawx, drawy, this, 2.0f); //ALLEGRO_COLOR tint = lookupMaterialColor(Eff_Dragonfire.matt.type, Eff_Dragonfire.matt.index); //draw_particle_cloud(Eff_Dragonfire.density, drawx, drawy - (SPRITEHEIGHT/2), SPRITEWIDTH, SPRITEHEIGHT, sprite_dragonfire, tint); break; case df::flow_type::Fire: tint.a*=tileeffect.density/100.0f; tint.g*=tileeffect.density/100.0f; tint.b*=tileeffect.density/100.0f; size = 3 - ((tileeffect.density-1)/25); AssembleSpriteFromSheet((((currentFrameLong+rando)%8)*20+size), sprite_dragonfire, tint, drawx, drawy, this, 2.0f); //ALLEGRO_COLOR tint = lookupMaterialColor(Eff_Fire.matt.type, Eff_Fire.matt.index); //draw_particle_cloud(Eff_Fire.density, drawx, drawy - (SPRITEHEIGHT/2), SPRITEWIDTH, SPRITEHEIGHT, sprite_fire, tint); break; case df::flow_type::Web: tint.a*=tileeffect.density/100.0f; AssembleSpriteFromSheet(rando%5, sprite_webing, tint, drawx, drawy, this, 4.0f); //al_draw_tinted_bitmap(sprite_webing,tint, drawx, drawy - (WALLHEIGHT), 0); break; case df::flow_type::MaterialGas: AssembleParticleCloud(tileeffect.density, drawx, drawy - (SPRITEHEIGHT/2), SPRITEWIDTH, SPRITEHEIGHT, sprite_boiling, tint); break; case df::flow_type::MaterialVapor: AssembleParticleCloud(tileeffect.density, drawx, drawy - (SPRITEHEIGHT/2), SPRITEWIDTH, SPRITEHEIGHT, sprite_boiling, tint); break; case df::flow_type::SeaFoam: tint.a*=tileeffect.density/100.0f; AssembleSprite(sprite_oceanwave, tint, 0, 0, al_get_bitmap_width(sprite_oceanwave), al_get_bitmap_height(sprite_oceanwave), drawx, drawy - (WALLHEIGHT)*ssConfig.scale, SPRITEWIDTH*ssConfig.scale, SPRITEHEIGHT*ssConfig.scale, 0); break; case df::flow_type::OceanWave: AssembleParticleCloud(tileeffect.density, drawx, drawy - (SPRITEHEIGHT/2), SPRITEWIDTH, SPRITEHEIGHT, sprite_water, tint); break; } } if(occ.bits.unit && creature && (ssConfig.show_hidden_tiles || !designation.bits.hidden)) { AssembleCreatureText(drawx, drawy, creature, ownerSegment); } }
static bool test(ALLEGRO_BITMAP *bitmap, ALLEGRO_FONT *font, char *message) { ALLEGRO_EVENT_QUEUE *queue; ALLEGRO_EVENT event; double start_time; long frames = 0; double fps = 0; char second_line[100]; bool quit = false; queue = al_create_event_queue(); al_register_event_source(queue, al_get_keyboard_event_source()); start_time = al_get_time(); for (;;) { if (al_get_next_event(queue, &event)) { if (event.type == ALLEGRO_EVENT_KEY_DOWN) { if (event.keyboard.keycode == ALLEGRO_KEY_SPACE) { break; } if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) { quit = true; break; } } } al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO); /* Clear the backbuffer with red so we can tell if the bitmap does not * cover the entire backbuffer. */ al_clear_to_color(al_map_rgb(255, 0, 0)); al_draw_scaled_bitmap(bitmap, 0, 0, al_get_bitmap_width(bitmap), al_get_bitmap_height(bitmap), 0, 0, al_get_bitmap_width(al_get_target_bitmap()), al_get_bitmap_height(al_get_target_bitmap()), 0); al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA); /* Note this makes the memory buffer case much slower due to repeated * locking of the backbuffer. Officially you can't use al_lock_bitmap * to solve the problem either. */ print(font, message, 0, 0); sprintf(second_line, "%.1f FPS", fps); print(font, second_line, 0, al_get_font_line_height(font)+5); al_flip_display(); frames++; fps = (double)frames / (al_get_time() - start_time); } al_destroy_event_queue(queue); return quit; }
void Gamestate_Draw(struct Game *game, struct dosowiskoResources* data) { al_draw_bitmap(data->bitmap, 0, 0, 0); if ((data->tick / 11) % 2 == 0) { al_draw_bitmap(data->icon, 320 / 2 - al_get_bitmap_width(data->icon) / 2, 180 / 2 - al_get_bitmap_height(data->icon) / 2 , 0); } }
/* Function: al_draw_soft_triangle */ void al_draw_soft_triangle( ALLEGRO_VERTEX* v1, ALLEGRO_VERTEX* v2, ALLEGRO_VERTEX* v3, uintptr_t state, void (*init)(uintptr_t, ALLEGRO_VERTEX*, ALLEGRO_VERTEX*, ALLEGRO_VERTEX*), void (*first)(uintptr_t, int, int, int, int), void (*step)(uintptr_t, int), void (*draw)(uintptr_t, int, int, int)) { /* ALLEGRO_VERTEX copy_v1, copy_v2; <- may be needed for clipping later on */ ALLEGRO_VERTEX* vtx1 = v1; ALLEGRO_VERTEX* vtx2 = v2; ALLEGRO_VERTEX* vtx3 = v3; ALLEGRO_BITMAP *target = al_get_target_bitmap(); int need_unlock = 0; ALLEGRO_LOCKED_REGION *lr; int min_x, max_x, min_y, max_y; int width = al_get_bitmap_width(target); int height = al_get_bitmap_height(target); /* TODO: Need to clip them first, make a copy of the vertices first then */ /* Lock the region we are drawing to. We are choosing the minimum and maximum possible pixels touched from the formula (easily verified by following the above algorithm. */ min_x = (int)floorf(MIN(vtx1->x, MIN(vtx2->x, vtx3->x))) - 1; min_y = (int)floorf(MIN(vtx1->y, MIN(vtx2->y, vtx3->y))) - 1; max_x = (int)ceilf(MAX(vtx1->x, MAX(vtx2->x, vtx3->x))) + 1; max_y = (int)ceilf(MAX(vtx1->y, MAX(vtx2->y, vtx3->y))) + 1; /* TODO: This bit is temporary, the min max's will be guaranteed to be within the bitmap once clipping is implemented */ if (max_x >= width) max_x = width; if (max_y >= height) max_y = height; if (min_x >= width) min_x = width; if (min_y >= height) min_y = height; if (max_x < 0) max_x = 0; if (max_y < 0) max_y = 0; if (min_x < 0) min_x = 0; if (min_y < 0) min_y = 0; if (al_is_bitmap_locked(target)) { if (!_al_bitmap_region_is_locked(target, min_x, min_y, max_x - min_x, max_y - min_y)) return; } else { if (!(lr = al_lock_bitmap_region(target, min_x, min_y, max_x - min_x, max_y - min_y, ALLEGRO_PIXEL_FORMAT_ANY, 0))) return; need_unlock = 1; } triangle_stepper(state, init, first, step, draw, v1, v2, v3); if (need_unlock) al_unlock_bitmap(target); }
static void render(void) { ALLEGRO_COLOR white = al_map_rgba_f(1, 1, 1, 1); ALLEGRO_COLOR black = al_map_rgba_f(0, 0, 0, 1); ALLEGRO_COLOR red = al_map_rgba_f(1, 0, 0, 1); ALLEGRO_COLOR green = al_map_rgba_f(0, 0.5, 0, 1); ALLEGRO_COLOR blue = al_map_rgba_f(0.1, 0.2, 1, 1); int x, y, w, h, as, de, xpos, ypos; int target_w, target_h; ALLEGRO_USTR_INFO info, sub_info; const ALLEGRO_USTR *u; al_clear_to_color(white); al_hold_bitmap_drawing(true); al_draw_textf(ex.f1, black, 50, 50, 0, "Tulip (kerning)"); al_draw_textf(ex.f2, black, 50, 100, 0, "Tulip (no kerning)"); al_draw_textf(ex.f3, black, 50, 200, 0, "This font has a size of 12 pixels, " "the one above has 48 pixels."); al_hold_bitmap_drawing(false); al_hold_bitmap_drawing(true); al_draw_textf(ex.f3, red, 50, 220, 0, "The color can simply be changed."); al_hold_bitmap_drawing(false); al_hold_bitmap_drawing(true); al_draw_textf(ex.f3, green, 50, 240, 0, "Some unicode symbols:"); al_draw_textf(ex.f3, green, 50, 260, 0, "%s", get_string("symbols1")); al_draw_textf(ex.f3, green, 50, 280, 0, "%s", get_string("symbols2")); al_draw_textf(ex.f3, green, 50, 300, 0, "%s", get_string("symbols3")); #define OFF(x) al_ustr_offset(u, x) #define SUB(x, y) al_ref_ustr(&sub_info, u, OFF(x), OFF(y)) u = al_ref_cstr(&info, get_string("substr1")); al_draw_ustr(ex.f3, green, 50, 320, 0, SUB(0, 6)); u = al_ref_cstr(&info, get_string("substr2")); al_draw_ustr(ex.f3, green, 50, 340, 0, SUB(7, 11)); u = al_ref_cstr(&info, get_string("substr3")); al_draw_ustr(ex.f3, green, 50, 360, 0, SUB(4, 11)); u = al_ref_cstr(&info, get_string("substr4")); al_draw_ustr(ex.f3, green, 50, 380, 0, SUB(0, 11)); al_draw_textf(ex.f5, black, 50, 420, 0, "forced monochrome"); al_hold_bitmap_drawing(false); target_w = al_get_bitmap_width(al_get_target_bitmap()); target_h = al_get_bitmap_height(al_get_target_bitmap()); xpos = target_w - 10; ypos = target_h - 10; al_get_text_dimensions(ex.f4, "Allegro", &x, &y, &w, &h); as = al_get_font_ascent(ex.f4); de = al_get_font_descent(ex.f4); xpos -= w; ypos -= h; x += xpos; y += ypos; al_draw_rectangle(x, y, x + w, y + h, black, 0); al_draw_line(x, y + as, x + w, y + as, black, 0); al_draw_line(x, y + as + de, x + w, y + as + de, black, 0); al_hold_bitmap_drawing(true); al_draw_textf(ex.f4, blue, xpos, ypos, 0, "Allegro"); al_hold_bitmap_drawing(false); al_hold_bitmap_drawing(true); al_draw_textf(ex.f3, black, target_w, 0, ALLEGRO_ALIGN_RIGHT, "%.1f FPS", ex.fps); al_hold_bitmap_drawing(false); }
static void draw(void) { float x, y; int iw = al_get_bitmap_width(ex.pattern); int ih = al_get_bitmap_height(ex.pattern); ALLEGRO_BITMAP *screen, *temp; ALLEGRO_LOCKED_REGION *lock; void *data; int size, i, format; al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO); al_clear_to_color(ex.background); screen = al_get_target_bitmap(); set_xy(8, 8); /* Test 1. */ /* Disabled: drawing to same bitmap is not supported. */ /* print("Screen -> Screen (%.1f fps)", get_fps(0)); get_xy(&x, &y); al_draw_bitmap(ex.pattern, x, y, 0); start_timer(0); al_draw_bitmap_region(screen, x, y, iw, ih, x + 8 + iw, y, 0); stop_timer(0); set_xy(x, y + ih); */ /* Test 2. */ print("Screen -> Bitmap -> Screen (%.1f fps)", get_fps(1)); get_xy(&x, &y); al_draw_bitmap(ex.pattern, x, y, 0); temp = al_create_bitmap(iw, ih); al_set_target_bitmap(temp); al_clear_to_color(al_map_rgba_f(1, 0, 0, 1)); start_timer(1); al_draw_bitmap_region(screen, x, y, iw, ih, 0, 0, 0); al_set_target_bitmap(screen); al_draw_bitmap(temp, x + 8 + iw, y, 0); stop_timer(1); set_xy(x, y + ih); al_destroy_bitmap(temp); /* Test 3. */ print("Screen -> Memory -> Screen (%.1f fps)", get_fps(2)); get_xy(&x, &y); al_draw_bitmap(ex.pattern, x, y, 0); al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP); temp = al_create_bitmap(iw, ih); al_set_target_bitmap(temp); al_clear_to_color(al_map_rgba_f(1, 0, 0, 1)); start_timer(2); al_draw_bitmap_region(screen, x, y, iw, ih, 0, 0, 0); al_set_target_bitmap(screen); al_draw_bitmap(temp, x + 8 + iw, y, 0); stop_timer(2); set_xy(x, y + ih); al_destroy_bitmap(temp); al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP); /* Test 4. */ print("Screen -> Locked -> Screen (%.1f fps)", get_fps(3)); get_xy(&x, &y); al_draw_bitmap(ex.pattern, x, y, 0); start_timer(3); lock = al_lock_bitmap_region(screen, x, y, iw, ih, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READONLY); format = lock->format; size = lock->pixel_size; data = malloc(size * iw * ih); for (i = 0; i < ih; i++) memcpy((char*)data + i * size * iw, (char*)lock->data + i * lock->pitch, size * iw); al_unlock_bitmap(screen); lock = al_lock_bitmap_region(screen, x + 8 + iw, y, iw, ih, format, ALLEGRO_LOCK_WRITEONLY); for (i = 0; i < ih; i++) memcpy((char*)lock->data + i * lock->pitch, (char*)data + i * size * iw, size * iw); al_unlock_bitmap(screen); free(data); stop_timer(3); set_xy(x, y + ih); }
draw_text("creatures may try to stop you. Don't let them!"); draw_text(""); x = 0.23; draw_text("Last but not least - You should be able to see the"); draw_text("constellation Orion in the sky tonight. Be sure to"); draw_text("take a moment to look for it if you have one to"); draw_text("spare. It's beautiful!"); draw_text(""); x = 0.25; draw_text("The fate of Equestria rests in your hooves."); draw_text("Be safe and good luck!"); draw_text(""); x = 0.26; draw_text("Yours,"); draw_text("Twilight Sparkle"); al_draw_text_with_shadow(game->menu.font, al_map_rgb(255,255,255), al_get_bitmap_width(game->level.letter)*0.5, al_get_bitmap_height(game->level.letter)*0.8, ALLEGRO_ALIGN_CENTRE, "Press enter to continue..."); al_set_target_bitmap(al_get_backbuffer(game->display)); PROGRESS; al_set_target_bitmap(game->level.welcome); al_clear_to_color(al_map_rgba(0,0,0,0)); al_draw_text_with_shadow(game->menu.font_title, al_map_rgb(255,255,255), game->viewportWidth*0.5, game->viewportHeight*0.1, ALLEGRO_ALIGN_CENTRE, "Level 1"); al_draw_text_with_shadow(game->menu.font_subtitle, al_map_rgb(255,255,255), game->viewportWidth*0.5, game->viewportHeight*0.275, ALLEGRO_ALIGN_CENTRE, "Fluttershy"); PROGRESS; al_set_target_bitmap(al_get_backbuffer(game->display)); Dodger_PreloadBitmaps(game, progress); } void Level1_Draw(struct Game *game) { Dodger_Draw(game);
int main() { const float FPS = 60.0; if(!al_init()) { al_show_native_message_box(NULL, "Fatal Error", NULL, "No se pudo inicializar Allegro", NULL, ALLEGRO_MESSAGEBOX_ERROR); return -1; } al_set_new_display_flags(ALLEGRO_WINDOWED); // Pone la ventana en modo Windowed ALLEGRO_DISPLAY *display = al_create_display(ScreenWidth, ScreenHeight); // Pone la posición en la que debe salir la ventana //al_set_window_position(display, 0, 30); // Pone el título de la ventana al_set_window_title(display, "Rabbit Kills Robots"); if(!display) // Si no se pudo crear la ventana, entonces pone un mensaje de error { al_show_native_message_box(NULL, "Error", NULL, "No se pudo crear la pantalla", NULL, ALLEGRO_MESSAGEBOX_ERROR); return -1; } al_install_keyboard(); al_install_mouse(); al_init_image_addon(); al_init_font_addon(); al_init_ttf_addon(); al_init_primitives_addon(); // ----------------------------------------------------------------- ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue(); ALLEGRO_TIMER *timer = al_create_timer(1.0/FPS); ALLEGRO_KEYBOARD_STATE keyState; // Utilizado para debugging ALLEGRO_FONT *font = al_load_font("sprites/DroidSans.ttf", 10, 0); ALLEGRO_BITMAP *fondo1 = al_load_bitmap("sprites/fondo1.png"); bool done = false; // ---------Estructuras del juego----------------------------------- //~ struct Player //~ { //~ ALLEGRO_BITMAP *image; //~ float x; //~ float y; //~ float moveSpeed; //~ float degrees; //~ int clip; //~ bool alive; //~ float xmouse; //~ float ymouse; //~ }player; struct Player player; player.image = al_load_bitmap("sprites/player.png"); al_convert_mask_to_alpha(player.image, al_map_rgb(255,255,255)); player.x = ScreenWidth / 2; player.y = ScreenHeight / 2; player.w = al_get_bitmap_width(player.image); player.h = al_get_bitmap_height(player.image); player.moveSpeed = 3; player.degrees = -ALLEGRO_PI/2; player.alive = true; player.clip = 6; //~ struct Bala //~ { //~ ALLEGRO_BITMAP *image; //~ float x; //~ float y; //~ float dx; //~ float dy; //~ bool shot; //~ void update(); //~ }bala; struct Bala bala; //~ void Bala::update() //~ { //~ bala.dx = cosf(player.xmouse - player.x); //~ bala.dy = senf(player.ymouse - player.y); //~ //~ if(bala.shot){ //~ //~ bala.x += bala.dx; //~ bala.y += bala.dy; //~ } //~ //~ } bala.image = al_load_bitmap("sprites/bullet.png"); bala.x = player.x+50; bala.y = player.y+25; bala.shot = false; //~ struct Enemigo //~ { //~ ALLEGRO_BITMAP *image; //~ float x; //~ float y; //~ float velocidad_x; //~ float velocidad_y; //~ //float degrees; //~ }robot; struct Enemigo robot; robot.image = al_load_bitmap("sprites/Robot_sprites.png"); //al_convert_mask_to_alpha(robot.image, al_map_rgb(255,255,255)); robot.x = 50; robot.y = 50; robot.w = al_get_bitmap_width(robot.image); robot.h = al_get_bitmap_height(robot.image); robot.velocidad_x = 0.23; robot.velocidad_y = 0.23; //~ void Weapon::recargar() //~ { //~ for(int i = 0; i < 6; i++) //~ { //~ bullets[i] = bala; //~ } //~ } //~ struct Weapon //~ { //~ struct Bala bullets[player.clip]; //~ void recargar(); //~ }arma; //~ //~ void Weapon::recargar() //~ { //~ for(int i = 0; i < player.clip; i++) //~ { //~ bullets[i] = bala; //~ } //~ } //~ // ----------------------------------------------------------------- // Esta variable guardará los eventos del mouse ALLEGRO_MOUSE_STATE mouseState; // Registro varias fuentes de eventos 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_register_event_source(event_queue, al_get_mouse_event_source()); // Inicializo el temporizador principal al_start_timer(timer); while(!done) { // La variable de los eventos ALLEGRO_EVENT ev; al_wait_for_event(event_queue, &ev); // Y aquí espero por los eventos if(ev.type == ALLEGRO_EVENT_TIMER) { // Dos funciones para pasar eventos del mouse y del teclado al_get_keyboard_state(&keyState); al_get_mouse_state(&mouseState); // Esto detecta la posición del mouse y lo guarda a un par de variables player.xmouse = al_get_mouse_state_axis(&mouseState, 0); player.ymouse = al_get_mouse_state_axis(&mouseState, 1); // Si presiono Esc entonces me saca del juego if(al_key_down(&keyState, ALLEGRO_KEY_ESCAPE)) { done = true; } // Si presiono A entonces el valor x se reduce, osea, se va a la izquierda if(al_key_down(&keyState, ALLEGRO_KEY_A)) { player.x -= player.moveSpeed; } // Si... meh, ya sabes lo que sigue if(al_key_down(&keyState, ALLEGRO_KEY_D)) { player.x += player.moveSpeed; } // ... if(al_key_down(&keyState, ALLEGRO_KEY_W)) { player.y -= player.moveSpeed; } // ... if(al_key_down(&keyState, ALLEGRO_KEY_S)) { player.y += player.moveSpeed; } } // Esto permite que el jugador se mueva con el mouse player.degrees = atan2((player.ymouse-player.y),(player.xmouse-player.x)); // La Inteligencia Artificial del enemigo if(robot.x < player.x-25) robot.x += robot.velocidad_x; if(robot.x > player.x-25) robot.x -= robot.velocidad_x; if(robot.y > player.y-25) robot.y -= robot.velocidad_y; if(robot.y < player.y-25) robot.y += robot.velocidad_y; // Uso de las funciones para las colisiones //if(Collision(player.x, player.y, 50, 50, robot.x, robot.y, 34, 34)) player.alive = false; if(PixelCol(player.image, robot.image, player.x-(player.w/2), player.y-(player.h/2), player.w, player.h, robot.x, robot.y, robot.w/7, robot.h)) player.alive = false; al_clear_to_color(al_map_rgb(255, 255, 255)); // Se pinta todo a negro al_draw_scaled_bitmap(fondo1,0, 0, 256, 256, 0, 0, ScreenWidth, ScreenHeight, 0); // Se dibuja el fondo if(player.alive){ // Si el jugador está vivo al_draw_rotated_bitmap(player.image, 25, 25, player.x, player.y, player.degrees, 0); // Dibujo el jugador al_draw_rotated_bitmap(bala.image, 0, 0, player.x+5, player.y+5, player.degrees, 0); // Dibujo la bala (esto hay que quitarlo) } al_draw_bitmap_region(robot.image, 0, 0, 60, 52, robot.x, robot.y, 0); // Dibujo el robot // Esto es para el debugging // Dibujo rectángulos para las colisiones al_draw_rectangle(player.x-(player.w/2), player.y-(player.h/2), (player.x+player.w)-(player.w/2), (player.y+player.h)-(player.h/2), al_map_rgb(0, 255, 0), 1.0); al_draw_rectangle(robot.x, robot.y, robot.x+(robot.w/7), robot.y+robot.h, al_map_rgb(0, 255, 0), 1.0); // Escribo en una esquina de la pantalla, información respecto al personaje al_draw_textf(font, al_map_rgb(255,255,255), ScreenWidth-10, 2, ALLEGRO_ALIGN_RIGHT, "Player x, y : %.1f %.1f", player.x, player.y); al_draw_textf(font, al_map_rgb(255,255,255), ScreenWidth-10, 12, ALLEGRO_ALIGN_RIGHT, "Rotation (rad): %.5f", player.degrees); al_draw_textf(font, al_map_rgb(255,255,255), ScreenWidth-10, 22, ALLEGRO_ALIGN_RIGHT, "Rotation (degrees): %.2f", (player.degrees*180)/ALLEGRO_PI); // Actualizo la pantalla (flip) al_flip_display(); } //-----After party (hay que limpiar)-------------------------------- // A destruirlo todo!! BAM BAM BAM, KABOOM!! al_destroy_font(font); al_destroy_bitmap(fondo1); al_destroy_bitmap(robot.image); al_destroy_display(display); al_destroy_event_queue(event_queue); al_destroy_bitmap(player.image); al_destroy_timer(timer); return 0; }
void Gamestate_Draw(struct Game *game, struct dosowiskoResources* data) { if (!data->fadeout) { char t[255] = ""; strcpy(t, data->text); if (data->underscore) { strncat(t, "_", 1); } else { strncat(t, " ", 1); } al_set_target_bitmap(data->bitmap); al_clear_to_color(al_map_rgba(0,0,0,0)); al_draw_text(data->font, al_map_rgba(255,255,255,10), game->viewport.width/2, game->viewport.height*0.4167, ALLEGRO_ALIGN_CENTRE, t); double tg = tan(-data->tan/384.0 * ALLEGRO_PI - ALLEGRO_PI/2); int fade = data->fadeout ? 255 : data->fade; al_set_target_bitmap(data->pixelator); al_clear_to_color(al_map_rgb(35, 31, 32)); al_draw_tinted_scaled_bitmap(data->bitmap, al_map_rgba(fade, fade, fade, fade), 0, 0, al_get_bitmap_width(data->bitmap), al_get_bitmap_height(data->bitmap), -tg*al_get_bitmap_width(data->bitmap)*0.05, -tg*al_get_bitmap_height(data->bitmap)*0.05, al_get_bitmap_width(data->bitmap)+tg*0.1*al_get_bitmap_width(data->bitmap), al_get_bitmap_height(data->bitmap)+tg*0.1*al_get_bitmap_height(data->bitmap), 0); al_draw_bitmap(data->checkerboard, 0, 0, 0); al_set_target_backbuffer(game->display); al_draw_bitmap(data->pixelator, 0, 0, 0); } }