//Draws the player sprite. void player_draw(Player self) { if (self->player_texture == NULL) { if (self->frame_invincibility > 0) { sf2d_draw_fill_circle(self->x, self->y, self->radius, RGBA8(0xFF, 0x00, 0x08, 0xFF)); } else { sf2d_draw_fill_circle(self->x, self->y, self->radius, RGBA8(0x5C, 0xFF, 0x71, 0xBB)); } } else { switch (self->player_direction) { //ZZZ Set this up for textures. case NORTH: case EAST: case SOUTH: case WEST: default: sf2d_draw_texture(self->player_texture, self->x, self->y); } } }
/*** Draw a filled circle on the current screen. @function circle @tparam integer x circle center horizontal coordinate, in pixels @tparam integer y circle center vertical coordinate, in pixels @tparam integer radius circle radius, in pixels @tparam[opt=default color] integer color drawing color */ static int gfx_circle(lua_State *L) { int x = luaL_checkinteger(L, 1); int y = luaL_checkinteger(L, 2); int radius = luaL_checkinteger(L, 3); u32 color = luaL_optinteger(L, 4, color_default); sf2d_draw_fill_circle(x, y, radius, color); return 0; }
//Goes through and draws all the circles. void circle_controller_draw_all_circles(CircleController self) { int i; for (i=0; i < MAX_SIZE; i++) { Circle circle = self->circle_array[i]; if (DO_SQUARE) { sf2d_draw_rectangle(circle->x - RADIUS, circle->y - RADIUS, RADIUS, RADIUS, RGBA8(0xFF, 0xA5, 0xC4, 0xFF)); } else { sf2d_draw_fill_circle(circle->x, circle->y, circle->radius, RGBA8(0xFF, 0xA5, 0xC4, 0xFF)); } } }
//Draw these lovely circles on the screen. void circle_controller_draw(CircleController self) { sf2d_start_frame(GFX_TOP, GFX_LEFT); //Left for Standard Vision sf2d_draw_rectangle(0, 0, 400, 240, RGBA8(0xFF, 0xFF, 0x89, 0xFF)); //Background if (DO_DRAW) circle_controller_draw_all_circles(self); sf2d_end_frame(); sf2d_start_frame(GFX_BOTTOM, GFX_LEFT); sf2d_draw_rectangle(0, 0, 400, 240, RGBA8(0xFF, 0xEE, 0x89, 0xFF)); //Background sf2d_draw_fill_circle(self->circle_timer->x, self->circle_timer->y, 4, RGBA8(0xFF, 0xA5, 0xC4, 0xFF)); float fps_percentage = sf2d_get_fps() / 60; sf2d_draw_rectangle(0, 200, fps_percentage * 320, 10, RGBA8(0x00, 0x00, 0x00, 0xFF)); sf2d_end_frame(); sf2d_swapbuffers(); }
static int gfx_target___index(lua_State *L) { target_userdata *target = luaL_checkudata(L, 1, "LTarget"); const char* name = luaL_checkstring(L, 2); if (strcmp(name, "texture") == 0) { texture_userdata *texture; texture = (texture_userdata*)lua_newuserdata(L, sizeof(*texture)); luaL_getmetatable(L, "LTexture"); lua_setmetatable(L, -2); texture->texture = &(target->target->texture); texture->scaleX = 1.0f; texture->scaleY = 1.0f; texture->blendColor = 0xffffffff; return 1; } else if (strcmp(name, "duck") == 0) { sf2d_rendertarget *target = sf2d_create_rendertarget(64, 64); for(int i=0;;i++) { sf2d_clear_target(target, 0xff000000); sf2d_start_frame_target(target); sf2d_draw_fill_circle(i%380, i%200, 10, 0xff0000ff); sf2d_end_frame(); //sf2d_texture_tile32(&target->texture); sf2d_start_frame(GFX_TOP, GFX_LEFT); sf2d_draw_texture(&target->texture, 10, 10); sf2d_end_frame(); sf2d_swapbuffers(); } } else { for (u8 i=0;target_methods[i].name;i++) { if (strcmp(target_methods[i].name, name) == 0) { lua_pushcfunction(L, target_methods[i].func); return 1; } } } lua_pushnil(L); return 1; }
static int graphicsCircle(lua_State *L) { // love.graphics.circle() if (sf2d_get_current_screen() == currentScreen) { int step = 15; char *mode = luaL_checkstring(L, 1); int x = luaL_checkinteger(L, 2); int y = luaL_checkinteger(L, 3); int r = luaL_checkinteger(L, 4); translateCoords(&x, &y); sf2d_draw_line(x, y, x, y, 1, getCurrentColor()); // Fixes weird circle bug. sf2d_draw_fill_circle(x, y, r, getCurrentColor()); } return 0; }
int main() { // Set the random seed based on the time srand(time(NULL)); sf2d_init(); sf2d_set_clear_color(RGBA8(0x40, 0x40, 0x40, 0xFF)); sf2d_texture *tex1 = sf2d_create_texture_mem_RGBA8(dice_img.pixel_data, dice_img.width, dice_img.height, TEXFMT_RGBA8, SF2D_PLACE_RAM); sf2d_texture *tex2 = sf2d_create_texture_mem_RGBA8(citra_img.pixel_data, citra_img.width, citra_img.height, TEXFMT_RGBA8, SF2D_PLACE_RAM); float rad = 0.0f; u16 touch_x = 320/2; u16 touch_y = 240/2; touchPosition touch; circlePosition circle; u32 held; while (aptMainLoop()) { hidScanInput(); hidCircleRead(&circle); held = hidKeysHeld(); if (held & KEY_START) { break; } else if (held & KEY_TOUCH) { hidTouchRead(&touch); touch_x = touch.px; touch_y = touch.py; } else if (held & (KEY_L | KEY_R)) { sf2d_set_clear_color(RGBA8(rand()%255, rand()%255, rand()%255, 255)); } sf2d_start_frame(GFX_TOP, GFX_LEFT); sf2d_draw_rectangle_rotate(260, 20, 40, 40, RGBA8(0xFF, 0xFF, 0x00, 0xFF), -2.0f*rad); sf2d_draw_rectangle(20, 60, 40, 40, RGBA8(0xFF, 0x00, 0x00, 0xFF)); sf2d_draw_rectangle(5, 5, 30, 30, RGBA8(0x00, 0xFF, 0xFF, 0xFF)); sf2d_draw_texture_rotate(tex1, 400/2 + circle.dx, 240/2 - circle.dy, rad); sf2d_end_frame(); sf2d_start_frame(GFX_BOTTOM, GFX_LEFT); sf2d_draw_rectangle_rotate(190, 160, 70, 60, RGBA8(0xFF, 0xFF, 0xFF, 0xFF), 3.0f*rad); sf2d_draw_rectangle(30, 100, 40, 60, RGBA8(0xFF, 0x00, 0xFF, 0xFF)); sf2d_draw_texture_rotate(tex2, touch_x, touch_y, -rad); sf2d_draw_rectangle(160-15 + cosf(rad)*50.0f, 120-15 + sinf(rad)*50.0f, 30, 30, RGBA8(0x00, 0xFF, 0xFF, 0xFF)); sf2d_draw_fill_circle(40, 40, 35, RGBA8(0x00, 0xFF, 0x00, 0xFF)); sf2d_end_frame(); rad += 0.2f; sf2d_swapbuffers(); } sf2d_free_texture(tex1); sf2d_free_texture(tex2); sf2d_fini(); return 0; }