void Ghost::render(int x_offset, int y_offset) { if (ghost_id < 4) { render_sprite(x - 4 + x_offset, y - 4 + y_offset, &sprite_clips[frame + direction * 2 + ghost_id * 8]); } else { if (ghost_id == 4) { render_blink_sprite(x - 4 + x_offset, y - 4 + y_offset, &blink_clips[frame]); } if (ghost_id == 5) { render_blink_sprite(x - 4 + x_offset, y - 4 + y_offset, &blink_clips[frame + 2]); } if (ghost_id == 6) { render_eyes_sprite(x - 4 + x_offset, y - 4 + y_offset, &eyes_clips[direction]); } } int timer_ticks = timer.ticks(); if (timer_ticks >= frame_interval) { for (int i = 0; i < timer_ticks / frame_interval; i++) { frame += 1; if (frame >= frame_count) frame = 0; } timer.restart(); } }
int main(){ init(); load_res(); SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); SDL_RenderClear(renderer); render_sprite(sprite_sheet, 0, 0, &sprite_sections[0]); render_sprite(sprite_sheet, WIDTH - 100, 0, &sprite_sections[1]); render_sprite(sprite_sheet, 0, HEIGHT - 100, &sprite_sections[2]); render_sprite(sprite_sheet, WIDTH - 100, HEIGHT - 100, &sprite_sections[3]); SDL_RenderPresent(renderer); SDL_Delay(3000); quit(); return 0; }
void WorldObjRenderer::process_object_with_surface(const FileReader& reader) { Vector3f pos; ResDescriptor desc; if (!(reader.read_vector("position", pos) && reader.read_desc("surface", desc))) { log_error("object (%1%) does not have 'position' and 'surface'", reader.get_name()); } else { if (reader.get_name() == "exit" || reader.get_name() == "hotspots") { render_sprite(desc, pos); } else if (reader.get_name() == "groundpiece") { std::string type; reader.read_string("type", type); if (type == "remove") { // FIXME: don't have blit_remove() render_surface(desc, pos); } else { render_surface(desc, pos); } } else { int repeat = 1; reader.read_int("repeat", repeat); render_surface(desc, pos, repeat); } } }
/** * \brief Draw a sprite on the gl_screen. * \param pos On gl_screen position of the sprite. * \param s The sprite to draw. */ void bear::visual::gl_screen::render ( const position_type& pos, const sprite& s ) { if ( s.has_transparency() ) { glEnable(GL_BLEND); VISUAL_GL_ERROR_THROW(); } glColor4f( s.get_red_intensity(), s.get_green_intensity(), s.get_blue_intensity(), s.get_opacity() ); const gl_image* impl = static_cast<const gl_image*>(s.get_image().get_impl()); glBindTexture( GL_TEXTURE_2D, impl->texture_id() ); VISUAL_GL_ERROR_THROW(); if ( s.get_angle() == 0 ) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); VISUAL_GL_ERROR_THROW(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); VISUAL_GL_ERROR_THROW(); } else { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); VISUAL_GL_ERROR_THROW(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); VISUAL_GL_ERROR_THROW(); } render_sprite( pos, s ); if ( s.has_transparency() ) { glDisable(GL_BLEND); VISUAL_GL_ERROR_THROW(); } } // gl_screen::render()
void GameTerrain::render(Canvas &canvas, const LightModel &light_model) { Rectf rect(0, 0, (float)size.width-1, (float)size.height-1); render_sprite(canvas, light_model, rect); }
void WorldObjRenderer::process(const FileReader& reader) { // FIXME: does not handle sprite alignment // FIXME: does not handle remove groundpieces // FIXME: does not handle liquid if (reader.get_name() == "surface-background" || reader.get_name() == "starfield-background" || reader.get_name() == "solidcolor-background" || reader.get_name() == "snow-generator" || reader.get_name() == "rain-generator") { // ignore } else if (reader.get_name() == "groundpiece" || reader.get_name() == "liquid" || reader.get_name() == "exit" || reader.get_name() == "hotspot") { process_object_with_surface(reader); } else if (reader.get_name() == "entrance") { Vector3f pos; reader.read_vector("position", pos); render_sprite(ResDescriptor("entrances/generic"), pos); } else if (reader.get_name() == "spike") { Vector3f pos; reader.read_vector("position", pos); render_surface(ResDescriptor("traps/spike_editor"), pos); } else if (reader.get_name() == "switchdoor-switch") { Vector3f pos; reader.read_vector("position", pos); render_surface(ResDescriptor("worldobjs/switchdoor_switch"), pos); } else if (reader.get_name() == "switchdoor-door") { Vector3f pos; reader.read_vector("position", pos); render_surface(ResDescriptor("worldobjs/switchdoor_box"), pos); } else if (reader.get_name() == "group") { FileReader objects = reader.read_section("objects"); process(objects.get_sections()); } else if (reader.get_name() == "prefab") { std::string name; if (!reader.read_string("name", name)) { log_error("'name' tag missing for prefab"); } else { PrefabFile prefab = PrefabFile::from_resource(name); Vector3f position; reader.read_vector("position", position); push_translate(static_cast<int>(position.x), static_cast<int>(position.y)); process(prefab.get_objects()); pop_translate(); } } else { log_error("unknown object type: %1%", reader.get_name()); } }
void vm_render_dorender(struct rpg_render *in, struct obj *omain) { struct var *cam_pos, *layer_opacity, *opacity, *f_rgb, *f_o, *tmp; struct r_sprite *rtmp; struct r_tmap *ttmp; int i, j, camx, camy; cam_pos = get_var_from_cstr(omain->vars, "cam_pos"); var_force_coord(cam_pos); camx = cam_pos->dat_list->dat_int; camy = cam_pos->dat_list->list_next->dat_int; for (i=0;i<8;i++) { layer_opacity = get_var_from_cstr(omain->vars, "tmap_layer_opacity"); opacity = lst_get_idx(layer_opacity, i); /* render tilemap layer if visible */ if (opacity->dat_int > 0) { clear_tmp(in->win); /*prefill*/ /*draw tilemaps to tmp*/ ttmp = in->tmaps[i]; while (ttmp != 0) { render_tmap(ttmp, in->win->t_surf, camx, camy); ttmp = ttmp->next; } /* blit t_surf to m_surf */ blit_surf(in->win->t_surf, in->win->m_surf, 0,0); } layer_opacity = get_var_from_cstr(omain->vars, "sprt_layer_opacity"); opacity = lst_get_idx(layer_opacity, i); /* render sprite layer if visible */ if (opacity->dat_int > 0) { clear_tmp(in->win); /*prefill*/ /* draw sprites of current layer to tmp*/ rtmp = in->sprites[i]; while (rtmp != 0) { render_sprite(rtmp, in->win->t_surf, camx, camy); rtmp = rtmp->next; } blit_surf(in->win->t_surf, in->win->m_surf,0,0); } } /* render fade overlay */ f_rgb = get_var_from_cstr(omain->vars, "fad_color"); f_o = get_var_from_cstr(omain->vars, "fad_opacity"); fill_surf_rgba( in->win->t_surf, lst_get_idx(f_rgb, 0)->dat_int, lst_get_idx(f_rgb, 1)->dat_int, lst_get_idx(f_rgb, 2)->dat_int, f_o->dat_int ); blit_surf(in->win->t_surf, in->win->m_surf,0,0); }
void render_world(void) { // posicion absoluta en el mundo de la izquierda de la pantalla t_pos left_absolute_x=world_get_left_absolute_x(); t_pos block_width=500.0; int iblock=(int)(left_absolute_x/block_width); int i; // int ibackblock=(int)((left_absolute_x/2.0)/(block_width*2.0)); //background render_background(); t_pos tile_x; float slow_factor=1/10.0; // 1 = foreground speed 0 = static background float level_factor=10.0; // 1 = foreground speed n = 1 background por cada n de foreground t_pos back_tile_x; t_pos back_tile_w=assets_tiles[4].out_bounds.w; back_tile_x= back_tile_w*(int)(world.player.x*slow_factor/back_tile_w) - world.player.x*slow_factor +(world.cam_x+200)*slow_factor -world.cam_x; back_tile_x= (int)((world.player.x+world.cam_x)/(back_tile_w*level_factor)) + (world.player.x+world.cam_x)/level_factor -world.player.x - world.cam_x; back_tile_x= back_tile_w*(int)((world.player.x+world.cam_x)/(back_tile_w*level_factor)) + (world.player.x+world.cam_x)*(1.0-1.0/level_factor) -world.player.x - world.cam_x; int back_i; back_i=(int)((world.player.x+world.cam_x)/(back_tile_w*level_factor)); back_tile_x=round(back_tile_x); // back_tile_x+=400; // glBlendColor(0.8,0.8,0.8,0.6); // glBlendFunc(GL_CONSTANT_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_FOG); glPushMatrix(); glTranslatef(0, 0, 0.4); int fondo_id_ant,fondo_id,fondo_id_sig,fondo_id_sigsig; fondo_id=((back_i/3)%2)==0?AST_TILE_FONDO:AST_TILE_FONDO2; fondo_id_ant=(((back_i-1)/3)%2)==0?AST_TILE_FONDO:AST_TILE_FONDO2; fondo_id_sig=(((back_i+1)/3)%2)==0?AST_TILE_FONDO:AST_TILE_FONDO2; fondo_id_sigsig=(((back_i+2)/3)%2)==0?AST_TILE_FONDO:AST_TILE_FONDO2; render_tile_num(back_tile_x-back_tile_w, c_floor_level-20.0, fondo_id_ant); render_tile_num(back_tile_x, c_floor_level-20.0, fondo_id); render_tile_num(back_tile_x+back_tile_w, c_floor_level-20.0, fondo_id_sig); if (fondo_id_ant==AST_TILE_FONDO && fondo_id==AST_TILE_FONDO2) { render_tile_num(back_tile_x-145, c_floor_level-20.0 -1 , AST_TILE_FONDO_TRANS12); } else if (fondo_id_ant==AST_TILE_FONDO2 && fondo_id==AST_TILE_FONDO) { render_tile_num(back_tile_x-134, c_floor_level-30.0 +9 , AST_TILE_FONDO_TRANS21); } if (fondo_id==AST_TILE_FONDO && fondo_id_sig==AST_TILE_FONDO2) { render_tile_num(back_tile_x+back_tile_w-145, c_floor_level-20.0 -1 , AST_TILE_FONDO_TRANS12); } else if (fondo_id==AST_TILE_FONDO2 && fondo_id_sig==AST_TILE_FONDO) { // glColor3f(1,1,1); // render_box(back_tile_x+back_tile_w-134+134-340 +340/2, c_floor_level-30.0 +9 +100 +390/2,340/2,390/2); render_tile_num(back_tile_x+back_tile_w-134, c_floor_level-30.0 +9 , AST_TILE_FONDO_TRANS21); } if (fondo_id_sig==AST_TILE_FONDO && fondo_id_sigsig==AST_TILE_FONDO2) { render_tile_num(back_tile_x+2*back_tile_w-145, c_floor_level-20.0 -1 , AST_TILE_FONDO_TRANS12); } else if (fondo_id_sig==AST_TILE_FONDO2 && fondo_id_sigsig==AST_TILE_FONDO) { // glColor3f(1,1,1); // render_box(back_tile_x+back_tile_w-134+134-340 +340/2, c_floor_level-30.0 +9 +100 +390/2,340/2,390/2); render_tile_num(back_tile_x+2*back_tile_w-134, c_floor_level-30.0 +9 , AST_TILE_FONDO_TRANS21); } glPopMatrix(); glDisable(GL_FOG); // glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); // solo provisional por ver tres planos // slow_factor=0.6; // back_tile_w=assets_tiles[1].out_bounds.w+100; // back_tile_x=-left_absolute_x*slow_factor+back_tile_w*(int)(left_absolute_x*slow_factor/back_tile_w); // render_tile_num(back_tile_x, c_floor_level, AST_TILE_CASAS1); // render_tile_num(back_tile_x+back_tile_w, c_floor_level, AST_TILE_CASAS1); glColor4f(1,0,0,1); render_back_zone(1,0); glColor4f(0,1,0,1); render_back_zone(1,1); glColor4f(0,0,1,1); render_back_zone(1,2); glColor4f(1,0,0,1); render_back_zone(0,0); glColor4f(0,1,0,1); render_back_zone(0,1); glColor4f(0,0,1,1); render_back_zone(0,2); // for (i=0;i<2;i++) { // tile_x=(ibackblock+i)*block_width*2.0-(world.player.x+world.cam_x)/2.0; // glColor4f(0,.3,0,1); // render_mountain(tile_x,c_floor_level+50,470,150); // } // for (i=0;i<3;i++) { // tile_x=(iblock+i)*block_width-world.player.x-world.cam_x - 100.0; // // render_tile_num(tile_x, c_floor_level-70, AST_TILE_SUELO); // // glColor4f(.5,.3,.3,1); // // render_tile(tile_x,c_floor_level-30,block_width-10,40); // // glColor4f(.3,.3,.3,1); // // render_tile(tile_x+110,c_floor_level,100,100); // // render_tile_num(tile_x+110,c_floor_level,AST_TILE_ARBOL2); // } // items t_item_iterator iter_i; item_iterate_init(&iter_i); t_itemPtr item; while ( NULL != (item=item_iterate_next(&world, &iter_i)) ) { render_item(item); } // cansados t_sprite_iterator iter; world_iterate_sprites(&iter); t_spritePtr sprite; while ( NULL != (sprite=world_iterate_next(&iter)) ) { if (sprite->sprite_class->id==SPRCLS_ID_CANSADO) { render_sprite(sprite); } } // walkers pero no bicis world_iterate_sprites(&iter); while ( NULL != (sprite=world_iterate_next(&iter)) ) { if (sprite->sprite_class->id==SPRCLS_ID_PEREGRINO || sprite->sprite_class->id==SPRCLS_ID_BORDONERO) { render_sprite(sprite); } } //player render_sprite(&world.player); // bicis aparte world_iterate_sprites(&iter); while ( NULL != (sprite=world_iterate_next(&iter)) ) { if (sprite->sprite_class->id==SPRCLS_ID_BICI) { render_sprite(sprite); } } for (i=0;i<3;i++) { tile_x=(iblock+i)*block_width-world.player.x-world.cam_x; glColor4f(0,1,0,1); // render_tile(tile_x,c_floor_level-40,block_width-10,40); render_tile_num(tile_x, c_floor_level-100.0, AST_TILE_SUELO); glColor4f(.3,.3,.3,1); // render_tile(tile_x+110,c_floor_level,100,100); // render_tile_num(tile_x+110,c_floor_level,AST_TILE_ARBOL2); } render_bocina(); int pading=30, hpading=10; render_tile_num(pading,pading-hpading*game_salto_pressed,AST_TILE_BTN_SALTAR); render_tile_num(160+pading,pading-hpading*game_esquivar_pressed,AST_TILE_BTN_ESQUIVAR); render_tile_num(810+pading,pading-hpading*game_hit_pressed,AST_TILE_BTN_PEGAR); render_tile_num(660+pading,pading-hpading*game_stop_pressed,AST_TILE_BTN_ANDAR); render_tile_num(860, 535, AST_TILE_BTN_PAUSE); if ( world.player.anim_state_id==STID_PLAYER_TIRED ) { //render_label_num(250, 300, 15); //render_tile(300, 300, &text_gameover_tile); render_tile_num(180,300,AST_TILE_GAMEOVER); } if (world.t<2.8) { render_tile_num(305,300,AST_TILE_READY); } else if (world.t<3.6) { render_tile_num(390/*-world.player.x+500.0*/,300,AST_TILE_GO); } }