// Essa funcao eh executada a cada ciclo de desenho, devendo ser usada para // imprimir os objetos na tela void draw() { sprite_draw(*dots, dots_x, -1); sprite_draw(*stars, stars_x, 0); sprite_draw(*enterprise, x, y); }
static int lmatrix_multi_draw(lua_State *L) { struct sprite *s = self(L); int cnt = (int)luaL_checkinteger(L,3); if (cnt == 0) return 0; luaL_checktype(L,4,LUA_TTABLE); luaL_checktype(L,5,LUA_TTABLE); if (lua_rawlen(L, 4) < cnt) { return luaL_error(L, "matrix length must less then particle count"); } if (lua_rawlen(L, 5) < cnt) { return luaL_error(L, "color length must less then particle count"); } struct matrix *mat = (struct matrix *)lua_touserdata(L, 2); if (s->t.mat == NULL) { s->t.mat = &s->mat; matrix_identity(&s->mat); } struct matrix *parent_mat = s->t.mat; uint32_t parent_color = s->t.color; int i; if (mat) { struct matrix tmp; for (i = 0; i < cnt; i++) { lua_rawgeti(L, 4, i+1); lua_rawgeti(L, 5, i+1); struct matrix *m = (struct matrix *)lua_touserdata(L, -2); matrix_mul(&tmp, m, mat); s->t.mat = &tmp; s->t.color = (uint32_t)lua_tounsigned(L, -1); lua_pop(L, 2); sprite_draw(s, NULL); } } else { for (i = 0; i < cnt; i++) { lua_rawgeti(L, 4, i+1); lua_rawgeti(L, 5, i+1); struct matrix *m = (struct matrix *)lua_touserdata(L, -2); s->t.mat = m; s->t.color = (uint32_t)lua_tounsigned(L, -1); lua_pop(L, 2); sprite_draw(s, NULL); } } s->t.mat = parent_mat; s->t.color = parent_color; return 0; }
void player_draw_equip(){ if(PlayerEquip.feet){ sprite_draw(getArmorAnim(animCurrent, PlayerEquip.feet), player->frame_horizontal, player->frame_vertical,__gt_graphics_renderer,player->position.x,player->position.y); } if(PlayerEquip.hands){ sprite_draw(getArmorAnim(animCurrent, PlayerEquip.hands), player->frame_horizontal, player->frame_vertical,__gt_graphics_renderer,player->position.x,player->position.y); } if(PlayerEquip.head){ sprite_draw(getArmorAnim(animCurrent, PlayerEquip.head), player->frame_horizontal, player->frame_vertical,__gt_graphics_renderer,player->position.x,player->position.y); } if(PlayerEquip.torso){ sprite_draw(getArmorAnim(animCurrent, PlayerEquip.torso), player->frame_horizontal, player->frame_vertical,__gt_graphics_renderer,player->position.x,player->position.y); } if(PlayerEquip.chest){ sprite_draw(getArmorAnim(animCurrent, PlayerEquip.chest), player->frame_horizontal, player->frame_vertical,__gt_graphics_renderer,player->position.x,player->position.y); } if(PlayerEquip.shoulders){ sprite_draw(getArmorAnim(animCurrent, PlayerEquip.shoulders), player->frame_horizontal, player->frame_vertical,__gt_graphics_renderer,player->position.x,player->position.y); } if(PlayerEquip.weapon && PlayerEquip.weapon->active && animCurrent == SLASH ){ //sword sprites are 192x192 pixels, need offset if(PlayerEquip.weapon->type == WEAP_SWORD){ sprite_draw(PlayerEquip.weapon->image, player->frame_horizontal, player->frame_vertical,__gt_graphics_renderer,player->position.x - PLAYER_FRAMEW,player->position.y - PLAYER_FRAMEH); } else{ //draw on player instead sprite_draw(PlayerEquip.weapon->image, player->frame_horizontal, player->frame_vertical,__gt_graphics_renderer,player->position.x,player->position.y); } } }
void cave_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh) { int pri; int layers_ctrl = -1; int glob_flipx = READ_WORD(&cave_videoregs[0]) & 0x8000; int glob_flipy = READ_WORD(&cave_videoregs[2]) & 0x8000; tilemap_set_flip(ALL_TILEMAPS, (glob_flipx ? TILEMAP_FLIPX : 0) | (glob_flipy ? TILEMAP_FLIPY : 0) ); tilemap_set_enable( tilemap_0, READ_WORD(&cave_vctrl_0[4]) & 1 ); tilemap_set_scrollx(tilemap_0, 0, READ_WORD(&cave_vctrl_0[0]) ); tilemap_set_scrolly(tilemap_0, 0, READ_WORD(&cave_vctrl_0[2]) ); if (tilemap_1) { tilemap_set_enable( tilemap_1, READ_WORD(&cave_vctrl_1[4]) & 1 ); tilemap_set_scrollx(tilemap_1, 0, READ_WORD(&cave_vctrl_1[0]) ); tilemap_set_scrolly(tilemap_1, 0, READ_WORD(&cave_vctrl_1[2]) ); } if (tilemap_2) { tilemap_set_enable( tilemap_2, READ_WORD(&cave_vctrl_2[4]) & 1 ); tilemap_set_scrollx(tilemap_2, 0, READ_WORD(&cave_vctrl_2[0]) ); tilemap_set_scrolly(tilemap_2, 0, READ_WORD(&cave_vctrl_2[2]) ); } tilemap_update(ALL_TILEMAPS); palette_init_used_colors(); get_sprite_info(); sprite_update(); if (palette_recalc()) tilemap_mark_all_pixels_dirty(ALL_TILEMAPS); tilemap_render(ALL_TILEMAPS); /* Clear the background if at least one of layer 0's tile priorities is lacking */ if ((layers_ctrl & 0xf) != 0xf) osd_clearbitmap(Machine->scrbitmap); /* Pen 0 of layer 0's tiles (any priority) goes below anything else */ for ( pri = 0; pri < 4; pri++ ) if ((layers_ctrl&(1<<(pri+0)))&&tilemap_0) tilemap_draw(bitmap, tilemap_0, TILEMAP_IGNORE_TRANSPARENCY | pri); /* Draw the rest with transparency */ for ( pri = 0; pri < 4; pri++ ) { if ((layers_ctrl&(1<<(pri+12)))) sprite_draw(sprite_list, pri); if ((layers_ctrl&(1<<(pri+0)))&&tilemap_0) tilemap_draw(bitmap, tilemap_0, pri); if ((layers_ctrl&(1<<(pri+4)))&&tilemap_1) tilemap_draw(bitmap, tilemap_1, pri); if ((layers_ctrl&(1<<(pri+8)))&&tilemap_2) tilemap_draw(bitmap, tilemap_2, pri); } }
static int lmulti_draw(lua_State *L) { struct sprite *s = self(L); int cnt = (int)luaL_checkinteger(L,3); if (cnt == 0) return 0; luaL_checktype(L,4,LUA_TTABLE); luaL_checktype(L,5,LUA_TTABLE); if (lua_rawlen(L, 4) < cnt) { return luaL_error(L, "matrix length less then particle count"); } struct srt srt; fill_srt(L, &srt, 2); int i; for (i = 0; i < cnt; i++) { lua_rawgeti(L, 4, i+1); lua_rawgeti(L, 5, i+1); struct matrix * mat = (struct matrix *)lua_touserdata(L, -2); s->t.mat = mat; s->t.color = (uint32_t)lua_tounsigned(L, -1); lua_pop(L, 2); sprite_draw(s, &srt); } s->t.mat = NULL; return 0; }
void mouse_draw() { if (__mouse.showHide <= 0)return; sprite_draw(__mouse.sprite, __mouse.frame, __mouse.x, __mouse.y); }
/* userdata sprite table { .x .y .sx .sy .rot } */ static int ldraw(lua_State *L) { struct sprite *s = self(L); struct srt srt; fill_srt(L,&srt,2); sprite_draw(s, &srt); return 0; }
void entity_draw(entity *ent, int x, int y){ //SDL Main Camera src rect SDL_Rect entRect = {ent->position.x + ent->boundBox.x, ent->position.y + ent->boundBox.h, ent->boundBox.w, ent->boundBox.h}; sprite_draw(ent->sprite, ent->frame_horizontal, ent->frame_vertical, __gt_graphics_renderer, ent->position.x, ent->position.y); if(!ent->player) { draw_health_bar(ent); } }
/* userdata sprite table { .x .y .sx .sy .rot } */ static int ldraw(lua_State *L) { struct sprite *s = self(L); struct srt srt; fill_srt(L,&srt,2); struct program_param pp; fill_pp(L,&pp,3); sprite_draw(s, &srt, &pp); return 0; }
void component_button_draw(Component *component) { RectFloat r; ComponentButton *button = NULL; Sprite *img = NULL; int x,y; Uint32 ofx = 0, ofy = 0; button = component_get_button_data(component); if (button == NULL)return; x = component->bounds.x; y = component->bounds.y; r = font_get_bounds( button->buttonText, button->fontSize ); if ((component->state >= 0) && (component->state < ButtonStateMax)) { img = button->button[component->state]; if (img != NULL) { sprite_draw(img, 0, x, y); x = x + (img->frameWidth/2); y = y + (img->frameHeight/2) - (r.h*0.5); ofx = __component_button_offset_x; ofy = __component_button_offset_y; } r.x = x + ofx; r.y = y + ofy; font_draw_text_justify( button->buttonText, r.x, r.y, button->textColor[component->state], button->alpha, button->fontSize, button->justify ); if ((button->buttonType == ButtonText) && (component->state == ButtonHighlight) && (__component_button_text_outline)) { draw_rect(component->bounds,__component_button_color[component->state],button->alpha); } } }
static void updateFast(Layer *layer, GContext *ctx) { update_state(); graphics_context_set_compositing_mode(ctx, GCompOpAssign); graphics_draw_bitmap_in_rect(ctx, s_bmap_bg, GRect(0,0,144, 168)); graphics_context_set_compositing_mode(ctx, GCompOpAssign); sprite_draw( RESOURCE_ID_IMAGE_ROCKET, layer,ctx ); if( s_enableParticles ) { graphics_context_set_stroke_color(ctx,GColorWhite); // ugh, fixme. update_particles(layer,ctx); } }
void engine_draw() { SDL_RenderClear(ren); // draw stuff list_t* it = entities; entity* e; while (it) { e = (entity*)(it->value); if (e->t == SPRITE) sprite_draw((sprite*)e); if (e->t == TEXTFIELD) textfield_draw((textfield*)e); it = it->next; } SDL_RenderPresent(ren); }
void entity_draw(Entity e) { if (e->sprite) { sprite_draw(e->sprite, e->x, e->y); } }
int main(void) { //*uart_chan0_interruptenable |= INTERRUPTENABLE_ERBFI; //uint16_t* blip = _binary_blip_start; //for (int i = 0; i < sizeof(_binary_blip_start) / 2; i++) { // *(sound_bank_0 + i) = *blip++; //} //*sound_channel_0_samplelength = sizeof(_binary_blip_start); //*sound_channel_master_config = 0xFFFF; //*sound_channel_master_volume = 0xFF99; //*sound_channel_0_volume = 0xFF22; //*sound_channel_0_config = 0xF9FF; FATFS fs; FRESULT result; result = pf_mount(&fs); util_printffresult(result); util_printfat(&fs); result = pf_open("test.txt"); util_printffresult(result); char buf[64]; uint16_t len; pf_read(buf, 63, &len); printf("read from file: %s\n", buf); image_loadimagefromfile(&fs, &pai, "pai.bz", true); image_loadimagefromfile(&fs, &ballimage, "ball.be", false); newball(&ball1, 0, 0, &ballimage); newball(&ball2, 50, 0, &ballimage); initvideo(); machine_setinterruptmask(0); while (1) { if (fbready) continue; static uint16_t lastframe = 0; static uint16_t thisframe; uint16_t vidflags = video_register_flags; uint8_t port0 = input_port0; thisframe = video_register_frame; updateball(&ball1, thisframe, lastframe); updateball(&ball2, thisframe, lastframe); ballcollision(&ball1, &ball2); video_begin(); video_clear(0xFFFF); video_blitimage_nocopy(pai.width, pai.height, 30, 30, pai.data); sprite_draw(ball1.sprite); sprite_draw(ball2.sprite); video_drawline(&vect); video_gputs("Hello World!", _binary_fontrom_start, 1, 1); lastframe = thisframe; video_commit(); //video_flip(); fbready = true; } printf("Shouldn't have got here!"); while (1) { } return 0; }
void mouse_draw() { sprite_draw(mouse->sprite, mouse->frameNumber, mouse->position); }
void game_loop (GAME *game) { if (!game) return; ALLEGRO_KEYBOARD_STATE keyboard_state; ALLEGRO_EVENT event; ALLEGRO_FONT *font = al_load_font ("data/fixed_font.tga", 0, 0); SCENE *scene; SPRITE_ACTOR *actor; LIST_ITEM *item; AABB_COLLISIONS collisions; aabb_init_collisions (&collisions); AABB_COLLISIONS portal_collisions; aabb_init_collisions (&portal_collisions); AABB_COLLISIONS npc_collisions; aabb_init_collisions (&npc_collisions); int i = 0; bool redraw = true; float times[NTIMES] = {0}; double frame_time, current_time, new_time, mean_frame_time; double fixed_dt = 1.0 / FPS, dt; double curfps = 0.0; current_time = al_get_time (); al_start_timer (game->timer); float fadeout_duration = 0; float fadein_duration = 0; SCENE_PORTAL *dest_portal = NULL; char *arrow_path = get_resource_path_str ("data/ui/smallarrow_down.png"); ALLEGRO_BITMAP *sel_arrow = al_load_bitmap (arrow_path); while (game->running) { scene = game->current_scene; actor = game->current_actor; if (redraw) { al_clear_depth_buffer (0); tiled_draw_map_back (scene->map, game->screen.tint, game->screen.position.x, game->screen.position.y, game->screen.width, game->screen.height, 0, 0, 0); al_draw_textf (font, al_map_rgba_f (0.9, 0, 0, 1), 5, 5, 0, "FPS: %.2f", curfps); al_set_render_state (ALLEGRO_ALPHA_TEST, true); al_set_render_state (ALLEGRO_DEPTH_TEST, true); al_set_render_state (ALLEGRO_DEPTH_FUNCTION, ALLEGRO_RENDER_GREATER); al_hold_bitmap_drawing (true); sprite_draw (actor, &game->screen); item = _al_list_front (scene->npcs); while (item) { SPRITE_ACTOR *npc_actor = (SPRITE_ACTOR *)_al_list_item_data (item); sprite_draw (npc_actor, &game->screen); item = _al_list_next (scene->npcs, item); } al_hold_bitmap_drawing (false); al_set_render_state (ALLEGRO_DEPTH_TEST, false); al_set_render_state (ALLEGRO_ALPHA_TEST, false); if (false) { item = _al_list_front (portal_collisions.boxes); while (item) { BOX *box = _al_list_item_data (item); box_draw (*box, game->screen.position, al_map_rgb_f (1, 0, 0)); item = _al_list_next (portal_collisions.boxes, item); } aabb_draw (scene->portal_tree, &game->screen, al_map_rgb_f (0, 0, 1)); } tiled_draw_map_fore (scene->map, game->screen.tint, game->screen.position.x, game->screen.position.y, game->screen.width, game->screen.height, 0, 0, 0); if (game->current_npc) { float dx = game->current_npc->actor.box.center.x - game->screen.position.x; float dy = game->current_npc->actor.box.center.y - game->screen.position.y; dx -= al_get_bitmap_width (sel_arrow) * 0.5f; dy -= game->current_npc->actor.box.extent.y * 3.0f; al_draw_bitmap (sel_arrow, dx, dy, 0); } ui_draw (game->ui, &game->screen); if (game->force_vsync) al_wait_for_vsync (); al_flip_display (); redraw = false; } al_wait_for_event (game->event_queue, &event); switch (event.type) { case ALLEGRO_EVENT_TIMER: new_time = al_get_time (); frame_time = new_time - current_time; current_time = new_time; times[i] = frame_time; i = (i + 1) % NTIMES; mean_frame_time = 0.0; for (int j = 0; j < NTIMES; j++) mean_frame_time += times[j]; mean_frame_time /= NTIMES; curfps = 1.0 / mean_frame_time; dt = mean_frame_time / fixed_dt; if (fadeout_duration > 0.0f) { float fadef = fadeout_duration / TRANS_TIME; game->screen.tint = al_map_rgba_f (fadef, fadef, fadef, 1.0); fadeout_duration -= mean_frame_time; if (fadeout_duration <= 0.0f) { fadein_duration = TRANS_TIME; fadeout_duration = 0.0f; game_enter_portal (game, dest_portal); } } if (fadein_duration > 0.0f) { float fadef = 1.0 - fadein_duration / TRANS_TIME; game->screen.tint = al_map_rgba_f (fadef, fadef, fadef, 1.0); fadein_duration -= mean_frame_time; if (fadein_duration <= 0.0f) { game->paused = false; fadein_duration = 0.0f; } } if (game->paused) { redraw = true; break; } al_get_keyboard_state (&keyboard_state); if (al_key_down (&keyboard_state, ALLEGRO_KEY_ESCAPE)) { game->running = false; continue; } if (al_key_down (&keyboard_state, ALLEGRO_KEY_ENTER)) { ui_show_dialog (game->ui, NULL, NULL); } if (al_key_down (&keyboard_state, ALLEGRO_KEY_RIGHT)) { actor->event->move_right (actor, dt); } if (al_key_down (&keyboard_state, ALLEGRO_KEY_LEFT)) { actor->event->move_left (actor, dt); } if (al_key_down (&keyboard_state, ALLEGRO_KEY_UP)) { actor->event->move_up (actor, dt); } if (al_key_down (&keyboard_state, ALLEGRO_KEY_DOWN)) { actor->event->move_down (actor, dt); } BOX box = actor->box; box.center.x += actor->movement.x * dt; box.center.y += actor->movement.y * dt; aabb_collide_fill_cache (scene->collision_tree, &box, &collisions); if (scene->collision_tree->num_collisions > 0) { item = _al_list_front (collisions.boxes); while (item) { if (box_lateral (*(BOX *)_al_list_item_data (item), actor->box)) actor->movement.x = 0; else actor->movement.y = 0; item = _al_list_next (collisions.boxes, item); } } aabb_collide_fill_cache (scene->portal_tree, &box, &portal_collisions); if (scene->portal_tree->num_collisions > 0) { item = _al_list_front (portal_collisions.boxes); while (item) { BOX *colbox = _al_list_item_data (item); TILED_OBJECT *obj = colbox->data; SCENE_PORTAL *portal = scene_get_portal (game->scenes, obj->name); if (portal && portal->destiny_portal) { dest_portal = scene_get_portal (game->scenes, portal->destiny_portal); if (dest_portal) { fadeout_duration = TRANS_TIME; game->paused = true; actor->movement = (VECTOR2D){0, 0}; ui_show_dialog_cstr (game->ui, "Speaker:", "Entering portal."); break; } } item = _al_list_next (portal_collisions.boxes, item); } } box = screen_box (&game->screen); game->current_npc = NULL; item = _al_list_front (scene->npcs); float max_dist = 0; while (item) { SPRITE_NPC *npc = _al_list_item_data (item); float dist = vsqdistance (npc->actor.box.center, game->current_actor->box.center); if (dist < 128.0f * 128.0f && dist > max_dist) { game->current_npc = npc; max_dist = dist; } item = _al_list_next (scene->npcs, item); } //aabb_collide_fill_cache (scene->npc_tree, &box, &npc_collisions); //if (scene->npc_tree->num_collisions > 0) { // item = _al_list_front (npc_collisions.boxes); // float max_dist = 0; // while (item) { // BOX *colbox = _al_list_item_data (item); // SPRITE_NPC *npc = colbox->data; // float dist = vsqdistance (npc->actor.box.center, game->current_actor->box.center); // if (dist < 128.0f * 128.0f && dist > max_dist) { // game->current_npc = npc; // max_dist = dist; // } // item = _al_list_next (npc_collisions.boxes, item); // } //} screen_update (&game->screen, actor->position, scene->map, dt); sprite_update (actor, dt, mean_frame_time); item = _al_list_front (scene->npcs); while (item) { SPRITE_ACTOR *npc_actor = (SPRITE_ACTOR *)_al_list_item_data (item); sprite_update (npc_actor, dt, mean_frame_time); item = _al_list_next (scene->npcs, item); } redraw = true; break; case ALLEGRO_EVENT_DISPLAY_CLOSE: game->running = false; break; default: fprintf (stderr, "Unsupported event received: %d\n", event.type); break; } } aabb_free_collisions (&collisions); aabb_free_collisions (&portal_collisions); aabb_free_collisions (&npc_collisions); }