コード例 #1
0
ファイル: bullet.c プロジェクト: Fittings/BulletHell3DS
void bullet_draw(Bullet self) {
	if (self->flag_is_player_bullet) {
	    sf2d_draw_rectangle(self->x - self->radius, self->y - self->radius, self->radius, self->radius, RGBA8(0x00, 0xF6, 0xFF, 0xFF));
	} else {
		sf2d_draw_rectangle(self->x - self->radius, self->y - self->radius, self->radius, self->radius, RGBA8(0xFF, 0xA5, 0xC4, 0xFF));
	}
}
コード例 #2
0
//ZZ  Quick function to check if drawing is working here.
void test_draw() {
	sf2d_start_frame(GFX_TOP, GFX_LEFT); //Left for Standard Vision
		sf2d_draw_rectangle(0, 0, 400, 240, RGBA8(0xFF, 0xFF, 0x89, 0xFF)); //Background
		
	sf2d_end_frame();
	sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);
		sf2d_draw_rectangle(0, 0, 400, 240, RGBA8(0xFF, 0xFF, 0x89, 0xFF)); //Background
	sf2d_end_frame();
	sf2d_swapbuffers();
}
コード例 #3
0
void Slider::draw()
{
    if (is_hidden()) return;

    sf2d_draw_rectangle(x, y, width, height, RGBA8(0x40, 0x40, 0x40, 255));
    int percent = value * width / (max - min);
    sf2d_draw_rectangle(x + percent - 2, y - 6 + height / 2, 5, 12, RGBA8(0x60, 0x60, 0x60, 255));
    sf2d_draw_rectangle(x + percent - 2 + 1, y - 6 + height / 2 + 1, 3, 10, !is_active() ? color.start() : color.color());
    if (style & LABELS)
        font->draw(value, x + width, y);
}
コード例 #4
0
ファイル: gfx.c プロジェクト: ctruLua/ctruLua
/***
Draw a filled rectangle on the current screen.
@function rectangle
@tparam integer x rectangle origin horizontal coordinate, in pixels
@tparam integer y rectangle origin vertical coordinate, in pixels
@tparam integer width rectangle width, in pixels
@tparam integer height rectangle height, in pixels
@tparam[opt=0] number angle rectangle rotation, in radians
@tparam[opt=default color] integer color drawing color
@tparam[opt] integer color2 Second drawing color ; if the argument is not nil, the rectangle will be filled with a gradient from color to color2
@tparam[opt] integer direction Gradient drawing direction (`gfx.TOP_TO_BOTTOM` or `gfx.LEFT_TO_RIGHT`). This argument is mandatory if a second color was specified.
*/
static int gfx_rectangle(lua_State *L) {
	int x = luaL_checkinteger(L, 1);
	int y = luaL_checkinteger(L, 2);
	int width = luaL_checkinteger(L, 3);
	int height = luaL_checkinteger(L, 4);

	float angle = luaL_optnumber(L, 5, 0);
	u32 color = luaL_optinteger(L, 6, color_default);

	// Not second color : fill with plain color.
	if (lua_isnoneornil(L, 7)) {
		if (angle == 0)
			sf2d_draw_rectangle(x, y, width, height, color);
		else
			sf2d_draw_rectangle_rotate(x, y, width, height, color, angle);
	// Two colors : fill with a gradient.
	} else {
		u32 color2 = luaL_checkinteger(L, 7);
		u8 direction = luaL_checkinteger(L, 8);

		if (angle == 0)
			sf2d_draw_rectangle_gradient(x, y, width, height, color, color2, direction);
		else
			sf2d_draw_rectangle_gradient_rotate(x, y, width, height, color, color2, direction, angle);
	}

	return 0;
}
コード例 #5
0
ファイル: gui.c プロジェクト: nop90/Vex3DS
/*
	Shows menu items 
*/
void ShowMenu(MENU *menu)
{
	int i;
	MENUITEM *mi = menu->m;
	
	int boxColor;
	
    boxColor = RGBA8(0x44,   0x44, 0xaa,   0xff);

	// show menu lines
	for(i = 0; i < menu->itemNum; i++, mi++) {
		int fg_color;
		sf2d_draw_rectangle(10, 35 + i*26, 125, 19, (menu->itemCur == i)?boxColor:COLOR_INACTIVE_ITEM_BG); 
		if(menu->itemCur == i) fg_color = COLOR_ACTIVE_ITEM; else fg_color = COLOR_INACTIVE_ITEM;
		ShowMenuItem(12, 38 + i*26, mi, fg_color,(menu == &gui_MainMenu)?0:1);
	}

	// show preview screen
//	ShowPreview(menu);

	// print info string

    sftd_draw_text(font, 7, 7, RGBA8(0x66,   0x66, 0x66,   0xff), 10, "Vex3ds");
    sftd_draw_text(font, 5, 5, RGBA8(0xff,   0xff, 0xff,   0xff), 10, "Vex3ds");

/*	if (menu == &gui_MainMenu) {
		guitextwidth = sftd_get_text_width(font, 10, Handy_3DS_String_list[HANDY_STR_Back_to_Game]);
		sftd_draw_text(font, (320 - guitextwidth) / 2, 225, COLOR_HELP_TEXT, 10, Handy_3DS_String_list[HANDY_STR_Back_to_Game]);
	} else {
		guitextwidth = sftd_get_text_width(font, 10, Handy_3DS_String_list[HANDY_STR_Back_to_Previous]);
		sftd_draw_text(font, (320 - guitextwidth) / 2, 225, COLOR_HELP_TEXT, 10, Handy_3DS_String_list[HANDY_STR_Back_to_Previous]);
	}
 */
 }
コード例 #6
0
ファイル: graphics.c プロジェクト: leoagomes/LovePotion
static int graphicsRectangle(lua_State *L) { // love.graphics.rectangle()

	if (sf2d_get_current_screen() == currentScreen) {

		char *mode = luaL_checkstring(L, 1);

		int x = luaL_checkinteger(L, 2);
		int y = luaL_checkinteger(L, 3);

		translateCoords(&x, &y);

		int w = luaL_checkinteger(L, 4);
		int h = luaL_checkinteger(L, 5);

		if (strcmp(mode, "fill") == 0) {
			sf2d_draw_rectangle(x, y, w, h, getCurrentColor());
		} else if (strcmp(mode, "line") == 0) {
			sf2d_draw_line(x, y, x, y + h, currentLineWidth, getCurrentColor());
			sf2d_draw_line(x, y, x + w, y, currentLineWidth, getCurrentColor());

			sf2d_draw_line(x + w, y, x + w, y + h, currentLineWidth, getCurrentColor());
			sf2d_draw_line(x, y + h, x + w, y + h, currentLineWidth, getCurrentColor());
		}

	}

	return 0;

}
コード例 #7
0
void game_controller_draw_bottom(GameController self) {
	sf2d_start_frame(GFX_BOTTOM, GFX_LEFT); 
		sf2d_draw_rectangle(0, 0, 400, 240, RGBA8(0xFF, 0x47, 0x53, 0xFF)); //Background
		
		if (self->flag_test) sf2d_draw_rectangle(30, 30, 30, 30, RGBA8(0xAA, 0xDD, 0x89, 0xFF));
		
		//Draw lives. 
		int i;
		for (i=0; i < self->player->lives; i++) {
			sf2d_draw_rectangle(15+(i*16), 0, 15, 15, RGBA8(0x47, 0x5F, 0xFF, 0xFF));
		}
		
		
		//sftd_font *font = sftd_load_font_mem(FreeSans_ttf, FreeSans_ttf_size);
		//sftd_draw_text(0, 10, 10, RGBA8(0, 255, 0, 255), 20, "Font drawing on the bot. screen!");
		
	sf2d_end_frame();
}
コード例 #8
0
ファイル: Slider.cpp プロジェクト: flarn2006/GraphCalc3DS
void Slider::Draw(int x, int y, int w, int h)
{
	width = w;
	int fillWidth = (int)Interpolate(value, min, max, 0.0, (double)(w - 2));
	sf2d_draw_rectangle_gradient(x+1, y+1, w-2, h-2, RGBA8(0xF0, 0xF0, 0xF0, 0xFF), RGBA8(0xFF, 0xFF, 0xFF, 0xFF), SF2D_TOP_TO_BOTTOM);
	sf2d_draw_rectangle(x+1, y+1, fillWidth, h-2, RGBA8(0x00, 0xCC, 0xFF, 0xFF));
    mainFont.drawStr(ssprintf("%.5f", value), x + 8, y + h/2 - mainFont.height()/2, RGBA8(0x00, 0x00, 0x00, 0xFF));
    sf2d_draw_rectangle_gradient(x+1, y+1, w-2, h/2-2, RGBA8(0xFF, 0xFF, 0xFF, 0x20), RGBA8(0xFF, 0xFF, 0xFF, 0x60), SF2D_TOP_TO_BOTTOM);
}
コード例 #9
0
ファイル: enemy.c プロジェクト: Fittings/BulletHell3DS
//Draws the enemy
void enemy_draw(Enemy self) {
	if (!self) return;
	
	if (self->enemy_texture == NULL) {
		sf2d_draw_rectangle(self->x - self->radius, self->y - self->radius, self->radius, self->radius, RGBA8(0xFF, 0x00, 0x08, 0xFF));
	} else {
		sf2d_draw_texture(self->enemy_texture, self->x + self->radius, self->y + self->radius);
	}
}
コード例 #10
0
void Button::draw()
{
    if (is_hidden()) return;

    image.draw(x, y);

    if (!is_active()) return;

    sf2d_draw_rectangle(x, y, width, height, blend_color.color());
}
コード例 #11
0
ファイル: gfx.c プロジェクト: ctruLua/ctruLua
/***
Draw a point, a single pixel, on the current screen.
@function point
@tparam integer x point horizontal coordinate, in pixels
@tparam integer y point vertical coordinate, in pixels
@tparam[opt=default color] integer color drawing color
*/
static int gfx_point(lua_State *L) {
	int x = luaL_checkinteger(L, 1);
	int y = luaL_checkinteger(L, 2);

	u32 color = luaL_optinteger(L, 3, color_default);

	sf2d_draw_rectangle(x, y, 1, 1, color); // well, it looks like a point

	return 0;
}
コード例 #12
0
//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();
}
コード例 #13
0
ファイル: cursor.cpp プロジェクト: RapdElzo/Flask
void Cursor::render(float translateValue)
{
	if (sf2d_get_current_screen() == getCurrentScreen()) 
	{
		setColor(41, 105, 176, 160 * this->sineValue);

		sf2d_draw_rectangle(this->x, ceil(this->y - translateValue), this->width, this->height, getCurrentColor());

		setColor(255, 255, 255, 255);
	}
}
コード例 #14
0
//ZZZ TODO Seperate this all out
void game_controller_draw_top(GameController self) {
	//Left Eye
	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 (self->enemy->health > 0) enemy_draw(self->enemy); /*ZZZ TESTING ZZZ */
		
		//bullet_draw(self->bullet);
		//bullet_draw(self->bullet_storage->bullet_array[0]);
		//bullet_draw(self->bullet_storage->bullet_array[self->bullet_storage->bullet_limit-1]);
		bullet_storage_draw_all(self->bullet_storage);
		
		player_draw(self->player); //Draw player ontop of all game objects.
		
		//Pause interface
		if (self->is_paused) sf2d_draw_rectangle(0, 0, 400, 240, RGBA8(0x7A, 0x7A, 0x7A, 0xCC));
	sf2d_end_frame();

	
}
コード例 #15
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));

        }
    }
}
コード例 #16
0
ファイル: main.c プロジェクト: kitling/undertale_techdemo
void render(void) {
    // Start frame on the top screen
    sf2d_start_frame(GFX_TOP, GFX_LEFT);

    // Draw the background (or in this case, the room)
    sf2d_draw_texture(rooms[room].bg.tex,
                      rooms[room].bg.pos.x - (int)camera_pos.x,
                      rooms[room].bg.pos.y - (int)camera_pos.y);

    // Draw the player's sprite
    sf2d_draw_texture(curr_tex,
                      (int)player_pos.x - (int)camera_pos.x,
                      (int)player_pos.y - (int)camera_pos.y);

    sf2d_draw_rectangle(0, 0, 800, 240, RGBA8(0x00, 0x00, 0x00, 0xFF - (int)roomTimer));

    // End frame
    sf2d_end_frame();

    // Start frame on the bottom screen
    sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);

    // If the easter egg variable is true, then activate it
    if (easterEgg) {
        // Draw the easter egg
        sftd_draw_text(font, 10, 140,  RGBA8(255, 0, 0, 255), 16, "* You IDIOT.");
        sftd_draw_text(font, 10, 170,  RGBA8(255, 255, 255, 255), 16, "* Nah, this is just");
        sftd_draw_text(font, 10, 200,  RGBA8(255, 255, 255, 255), 16, "   a simple test.");
        int y = -10;
        // Debug stuff
        switch (easterPage) {
            case 0:
                sftd_draw_textf(font, 10, y+=20, RGBA8(255, 0, 0, 255), 12, "FPS: %f", sf2d_get_fps());
                sftd_draw_textf(font, 10, y+=20, RGBA8(255, 0, 0, 255), 12, "Sprite Timer: %f", sprTimer);
                sftd_draw_textf(font, 10, y+=20, RGBA8(255, 255, 255, 255), 12, "Player X: %f, Y: %f", player_pos.x, player_pos.y);
                sftd_draw_textf(font, 10, y+=20, RGBA8(255, 255, 255, 255), 12, "Camera X: %f, Y: %f", camera_pos.x, camera_pos.y);
                break;
            case 1:
                sftd_draw_textf(font, 10, y+=20, RGBA8(255, 255, 255, 255), 12, "Block Position: %lu", home->block_pos);
                sftd_draw_textf(font, 10, y+=20, RGBA8(255, 255, 255, 255), 12, "Block: %u", home->block);
                sftd_draw_textf(font, 10, y+=20, RGBA8(255, 0, 0, 255), 12, "Status: %li", home->status);
                break;
        }
    };
    // End frame
    sf2d_end_frame();
}
コード例 #17
0
ファイル: Button.cpp プロジェクト: flarn2006/GraphCalc3DS
void Button::Draw(int x, int y, int w, int h)
{
	u32 c_on = altMode ? color_on_alt : color_on;
	u32 c_off = altMode ? color_off_alt : color_off;
	const char *str = (altMode ? text_alt : text).c_str();
	
    bool pressed = (GetTouchState() == TS_TOUCHING);
    if (!pressed) {
        sf2d_draw_rectangle(x+1, y+1, w-2, h-2, c_off);
        sf2d_draw_rectangle_gradient(x+1, y+1, w-2, h/2-2, RGBA8(0xFF, 0xFF, 0xFF, 0x20), RGBA8(0xFF, 0xFF, 0xFF, 0x60), SF2D_TOP_TO_BOTTOM);
    } else {
        sf2d_draw_rectangle_gradient(x+1, y+1, w-2, h-2, c_off, c_on, SF2D_TOP_TO_BOTTOM);
    }
	
	int textX = x + w/2;
	int textY = y + h/2 - btnFont.height() / 2;
    btnFont.align(ALIGN_CENTER).drawStr(str, textX, textY);
}
コード例 #18
0
ファイル: Render.c プロジェクト: DavidSM64/Minicraft3DS
void renderFrame(int x1, int y1, int x2, int y2, u32 bgColor) {
	int startX = x1;
	int startY = y1;
	sf2d_draw_rectangle((x1 << 4) + 4 - (offsetX << 1),
			(y1 << 4) + 4 - (offsetY << 1), ((x2 - x1) << 4) - 8,
			((y2 - y1) << 4) - 8, bgColor);
	while (x1 < x2) {
		y1 = startY;
		while (y1 < y2) {
			int xp = (x1 << 4) - (offsetX << 1);
			int yp = (y1 << 4) - (offsetY << 1);
			sf2d_draw_texture_part_scale(icons, xp, yp,
					getFrame(x1, x2, startX), 200 + getFrame(y1, y2, startY), 8,
					8, 2.0, 2.0);
			++y1;
		}
		++x1;
	}
}
コード例 #19
0
ファイル: gfx.c プロジェクト: ctruLua/ctruLua
/***
Draw a circle outline on the current screen.
@function linedCircle
@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=1] integer width line's thickness, in pixels
@tparam[opt=default color] integer color drawing color
*/
static int gfx_linedCircle(lua_State *L) {
	int x0 = luaL_checkinteger(L, 1);
	int y0 = luaL_checkinteger(L, 2);
	int radius = luaL_checkinteger(L, 3);
	float width = luaL_optnumber(L, 4, 1.0f);

	u32 color = luaL_optinteger(L, 5, color_default);

	for (int r = ceil(radius - width/2), maxr = ceil(radius + width/2)-1; r <= maxr; r++) {
		// Implementatin of the Andres circle algorithm.
		int x = 0;
		int y = r;
		int d = r - 1;
		while (y >= x) {
			// Best way to draw a lot of points, 10/10
			sf2d_draw_rectangle(x0 + x , y0 + y, 1, 1, color);
			sf2d_draw_rectangle(x0 + y , y0 + x, 1, 1, color);
			sf2d_draw_rectangle(x0 - x , y0 + y, 1, 1, color);
			sf2d_draw_rectangle(x0 - y , y0 + x, 1, 1, color);
			sf2d_draw_rectangle(x0 + x , y0 - y, 1, 1, color);
			sf2d_draw_rectangle(x0 + y , y0 - x, 1, 1, color);
			sf2d_draw_rectangle(x0 - x , y0 - y, 1, 1, color);
			sf2d_draw_rectangle(x0 - y , y0 - x, 1, 1, color);

			if (d >= 2*x) {
				d -= 2*x + 1;
				x++;
			} else if (d < 2*(r-y)) {
				d += 2*y - 1;
				y--;
			} else {
				d += 2*(y - x - 1);
				y--;
				x++;
			}
		}
	}

	return 0;
}
コード例 #20
0
ファイル: savexit_viewer.cpp プロジェクト: Elveman/PHBank
// --------------------------------------------------
Result SavexitViewer::drawTopScreen()
// --------------------------------------------------
{
	if (hasRegularChild()) { if (child->drawTopScreen() == PARENT_STEP); else return CHILD_STEP; }
	// Viewer::drawTopScreen(); // Not useful here!

	sf2d_draw_rectangle(79, 66, 240, 135, RGBA8(0x48, 0xA2, 0x3E, 0xE8));

	uint32_t x, y;

	x = 88;
	y = 67;
	sftd_draw_text_pkm(x, (y+=15), "You are about to exit PHBank");
	sftd_draw_text_pkm(x, (y+=15), "  A - Save and exit");
	sftd_draw_text_pkm(x, (y+=15), "  X - Exit without saving");
	sftd_draw_text_pkm(x, (y+=15), "  Y - Backup the save");
	sftd_draw_text_pkm(x, (y+=15), "  B - Return to PHBank");

	if (hasOverlayChild()) { child->drawTopScreen(); }
	return SUCCESS_STEP;
}
コード例 #21
0
ファイル: main.c プロジェクト: Hayleia/3ds_samples
int main()
{
	char* names[] = {
		"nul/20",
		"item1",
		"second item",
		"the third one",
		"item4",
		"item5",
		"item6",
		"item7",
		"item8",
		"item9",
		"item10",
		"item11",
		"item12",
		"item13",
		"item14",
		"item15",
		"item16",
		"item17",
		"item18",
		"item19",
		"item20",
		"item21",
		"item22",
		"item23",
		"item24",
		"item25",
		"item26",
		"item27",
		"item28",
		"item29"
	};

	int nbitems = 30;
	uint8_t owneditem[nbitems];
	for (int i=0; i<nbitems; i++) owneditem[i] = 0;

	sf2d_init();
	sf2d_set_clear_color(RGBA8(255, 255, 255, 255));
	sf2d_set_vblank_wait(0);

	// Font loading
	sftd_init();
	sftd_font* font = sftd_load_font_mem(FreeSans_ttf, FreeSans_ttf_size);

	int fontSize = 20;

	int row = 0;
	int nbrow = 10;
	int firstrow = 0;

#define LONG_TIMEOUT 500
#define SHORT_TIMEOUT_MAX 100
#define SHORT_TIMEOUT_MIN 20

	u64 oldTime = osGetTime();
	u64 timer = 0;
	u64 timeout = LONG_TIMEOUT;

	while (aptMainLoop()) {

		hidScanInput();
		if (hidKeysDown() & KEY_START) break;

		if ((hidKeysHeld() & KEY_UP) && timer == 0) row--;
		if (row == -1) {
			row++;
			firstrow--;
			if (firstrow == -1) {
				row = nbrow-1;
				firstrow = nbitems-nbrow;
			}
		}

		if ((hidKeysHeld() & KEY_DOWN) && timer == 0) row++;
		if (row == nbrow) {
			row--;
			firstrow++;
			if (firstrow+nbrow == nbitems+1) {
				firstrow = 0;
				row = 0;
			}
		}

		int index = firstrow+row;
		owneditem[index] += 100;
		if (hidKeysDown() & KEY_LEFT) owneditem[index]--;
		if (hidKeysDown() & KEY_RIGHT) owneditem[index]++;
		owneditem[index] %= 100;

		// use osGetTime to have key repetition
		u64 newTime = osGetTime();
		u64 delay = newTime-oldTime;
		oldTime = newTime;
		if (hidKeysHeld()) {
			timer += delay;
			if (timer>timeout) {
				timer = 0;
				if (timeout == LONG_TIMEOUT) {
					timeout = SHORT_TIMEOUT_MAX;
				} else {
					timeout = umax(timeout-2, SHORT_TIMEOUT_MIN);
				}
			}
		} else {
			timer = 0;
			timeout = LONG_TIMEOUT;
		}

		sf2d_start_frame(GFX_TOP, GFX_LEFT);
		{
			for (int i=0; i<nbrow; i++) {
				unsigned int color = RGBA8(0, 0, 0, 255);
				if (i == row) {
					sf2d_draw_rectangle(0, i*fontSize, 400, fontSize, RGBA8(0, 0, 0, 255));
					color = RGBA8(255, 255, 255, 255);
				}
				sftd_draw_textf(font, 010, i*fontSize, color, fontSize, names[firstrow+i]);
				sftd_draw_textf(font, 210, i*fontSize, color, fontSize, "%i", owneditem[firstrow+i]);
			}
		}
		sf2d_end_frame();

		sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);
		{
			sftd_draw_textf(font, 0, 20, RGBA8(0, 255, 0, 255), 20, "Press START to exit");
			sftd_draw_textf(font, 0, 40, RGBA8(0, 255, 0, 255), 20, "Timeout: %i", timeout);
		}
		sf2d_end_frame();

		sf2d_swapbuffers();
	}

	sftd_free_font(font);
	sftd_fini();

	sf2d_fini();
	return 0;
}
コード例 #22
0
void Lux_NATIVE_DrawRect( LuxRect dest_rect, ObjectEffect effects)
{
	Lux_NATIVE_SetFrame(dest_rect, false);
	sf2d_draw_rectangle(dest_rect.x, dest_rect.y, dest_rect.w, dest_rect.h, RGBA8(effects.primary_colour.r, effects.primary_colour.g, effects.primary_colour.b, effects.primary_colour.a)  );

}
コード例 #23
0
ファイル: main.c プロジェクト: DavidSM64/Minicraft3DS
int main() {
    cfguInit();
    CFGU_GetSystemModel(&MODEL_3DS);
	FILE * file;
	shouldRenderDebug = true;
	if ((file = fopen("settings.bin", "r"))) {
        fread(&shouldRenderDebug,sizeof(bool),1,file);
        fread(&shouldSpeedup,sizeof(bool),1,file);
        osSetSpeedupEnable(shouldSpeedup);
		fclose(file);
	}
    
	sf2d_init();
	csndInit();
	noItem = newItem(ITEM_NULL, 0);
	
	currentMenu = MENU_TITLE;
	currentSelection = 0;
	quitGame = false;

	icons = sfil_load_PNG_buffer(icons2_png, SF2D_PLACE_RAM);
	font = sfil_load_PNG_buffer(Font_png, SF2D_PLACE_RAM);
	bottombg = sfil_load_PNG_buffer(bottombg_png, SF2D_PLACE_RAM);
	
	dirtColor[0] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 0)); 
	dirtColor[1] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 1)); 
	dirtColor[2] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 2)); 
	dirtColor[3] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 3)); 
	dirtColor[4] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 4)); 

	loadSound(&snd_playerHurt, "resources/playerhurt.raw");
	loadSound(&snd_playerDeath, "resources/playerdeath.raw");
	loadSound(&snd_monsterHurt, "resources/monsterhurt.raw");
	loadSound(&snd_test, "resources/test.raw");
	loadSound(&snd_pickup, "resources/pickup.raw");
	loadSound(&snd_bossdeath, "resources/bossdeath.raw");
	loadSound(&snd_craft, "resources/craft.raw");
	
	bakeLights();
	
	int i;
	for (i = 0; i < 5; ++i) {
		minimap[i] = sf2d_create_texture(128, 128, TEXFMT_RGBA8,
				SF2D_PLACE_RAM);
		sf2d_texture_tile32(minimap[i]);
	}
	
	sf2d_set_vblank_wait(true);

	sf2d_set_clear_color(0xFF000000);

	k_up.input = KEY_DUP | KEY_CPAD_UP | KEY_CSTICK_UP;
	k_down.input = KEY_DDOWN | KEY_CPAD_DOWN | KEY_CSTICK_DOWN;
	k_left.input = KEY_DLEFT | KEY_CPAD_LEFT | KEY_CSTICK_LEFT;
	k_right.input = KEY_DRIGHT | KEY_CPAD_RIGHT | KEY_CSTICK_RIGHT;
	k_attack.input = KEY_A | KEY_B | KEY_L | KEY_ZR;
	k_menu.input = KEY_X | KEY_Y | KEY_R | KEY_ZL;
	k_pause.input = KEY_START;
	k_accept.input = KEY_A;
	k_decline.input = KEY_B;
	k_delete.input = KEY_X;
	k_menuNext.input = KEY_R;
	k_menuPrev.input = KEY_L;

	if ((file = fopen("btnSave.bin", "rb"))) {
		fread(&k_up.input, sizeof(int), 1, file);
		fread(&k_down.input, sizeof(int), 1, file);
		fread(&k_left.input, sizeof(int), 1, file);
		fread(&k_right.input, sizeof(int), 1, file);
		fread(&k_attack.input, sizeof(int), 1, file);
		fread(&k_menu.input, sizeof(int), 1, file);
		fread(&k_pause.input, sizeof(int), 1, file);
		fread(&k_accept.input, sizeof(int), 1, file);
		fread(&k_decline.input, sizeof(int), 1, file);
		fread(&k_delete.input, sizeof(int), 1, file);
		fread(&k_menuNext.input, sizeof(int), 1, file);
		fread(&k_menuPrev.input, sizeof(int), 1, file);
		fclose(file);
	}
	
	if ((file = fopen("lastTP.bin", "r"))) {
		char fnbuf[256];
		fgets(fnbuf, 256, file); // get directory to texturepack
		loadTexturePack(fnbuf);   
		fclose(file);
	}

	tickCount = 0;
	initRecipes();
	defineTables();
	while (aptMainLoop()) {
		++tickCount;
		hidScanInput();
		tickKeys(hidKeysHeld(), hidKeysDown());

		if (quitGame) break;

		if (initGame > 0) setupGame(initGame == 1 ? true : false);

		if (currentMenu == 0) {
			tick();
			sf2d_start_frame(GFX_TOP, GFX_LEFT);

			offsetX = xscr;
			offsetY = yscr;
			sf2d_draw_rectangle(0, 0, 400, 240, 0xFF0C0C0C); //RGBA8(12, 12, 12, 255)); //You might think "real" black would be better, but it actually looks better that way
			renderLightsToStencil();

			renderBackground(xscr, yscr);
			renderEntities(player.x, player.y, &eManager);
			renderPlayer();
			
			resetStencilStuff();
			offsetX = 0;
			offsetY = 0;
			
			if(shouldRenderDebug){
			    sprintf(fpsstr, " FPS: %.0f, X:%d, Y:%d, E:%d", sf2d_get_fps(), player.x, player.y, eManager.lastSlot[currentLevel]);
			    drawText(fpsstr, 2, 225);
            }
			
			sf2d_end_frame();

            sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);
                if(!shouldRenderMap){
                    sf2d_draw_texture(bottombg, 0, 0);
                    renderGui();
                } else {
                    renderZoomedMap();
                }
            sf2d_end_frame();
		} else {
			tickMenu(currentMenu);
			renderMenu(currentMenu, xscr, yscr);
		}

		sf2d_swapbuffers();
	}

	freeRecipes();

	freeLightBakes();
	sf2d_free_texture(icons);
	sf2d_free_texture(minimap[0]);
	sf2d_free_texture(minimap[1]);
	sf2d_free_texture(minimap[2]);
	sf2d_free_texture(minimap[3]);
	sf2d_free_texture(minimap[4]);
	freeSounds();
	csndExit();
    cfguExit();
	sf2d_fini();
	return 0;
}
コード例 #24
0
ファイル: main.c プロジェクト: shutterbug2000/Minicraft3DS
int main()
{
	sf2d_init();
	csndInit();
	noItem = newItem(ITEM_NULL,0);
	
	currentMenu = MENU_TITLE;
    currentSelection = 0;
	quitGame = false;

    icons = sfil_load_PNG_buffer(icons2_png, SF2D_PLACE_RAM);
    font = sfil_load_PNG_buffer(Font_png, SF2D_PLACE_RAM);
	
	//consoleInit(GFX_BOTTOM, NULL);
   // printf("Press 'Start' to exit.\n");

	loadSound(&snd_playerHurt, "resources/playerhurt.raw");
	loadSound(&snd_playerDeath, "resources/playerdeath.raw");
	loadSound(&snd_monsterHurt, "resources/monsterhurt.raw");
	loadSound(&snd_test, "resources/test.raw");
	loadSound(&snd_pickup, "resources/pickup.raw");
	loadSound(&snd_bossdeath, "resources/bossdeath.raw");
	loadSound(&snd_craft, "resources/craft.raw");
    
    int i;
    for(i = 0;i < 5;++i){
       minimap[i] = sf2d_create_texture(128,128,TEXFMT_RGBA8,SF2D_PLACE_RAM);
	   sf2d_texture_tile32(minimap[i]);
    }
    
    sf2d_set_vblank_wait(true);
	
	sf2d_set_clear_color(0xFF);
	
	/* Default inputs */
	k_up.input = KEY_DUP | KEY_CPAD_UP | KEY_CSTICK_UP;
	k_down.input = KEY_DDOWN | KEY_CPAD_DOWN | KEY_CSTICK_DOWN;
	k_left.input = KEY_DLEFT | KEY_CPAD_LEFT | KEY_CSTICK_LEFT;
	k_right.input = KEY_DRIGHT | KEY_CPAD_RIGHT | KEY_CSTICK_RIGHT;
	k_attack.input = KEY_A | KEY_B | KEY_L | KEY_ZR;
	k_menu.input = KEY_X | KEY_Y | KEY_R | KEY_ZL;
	k_pause.input = KEY_START;
    k_accept.input = KEY_A;
    k_decline.input = KEY_B;
    k_delete.input = KEY_X;
    FILE * file;
    
    /* If btnSave exists, then use that. */
    if ((file = fopen("btnSave.bin", "rb"))){
        fread(&k_up.input, sizeof(int), 1, file);
        fread(&k_down.input, sizeof(int), 1, file);
        fread(&k_left.input, sizeof(int), 1, file);
        fread(&k_right.input, sizeof(int), 1, file);
        fread(&k_attack.input, sizeof(int), 1, file);
        fread(&k_menu.input, sizeof(int), 1, file);
        fread(&k_pause.input, sizeof(int), 1, file);
        fread(&k_accept.input, sizeof(int), 1, file);
        fread(&k_decline.input, sizeof(int), 1, file);
        fread(&k_delete.input, sizeof(int), 1, file);
        fclose(file);
    }
	
	//screenShot = false;
	
    tickCount=0;
    initRecipes();
    defineTables();
	while (aptMainLoop()) {
		++tickCount;
		hidScanInput();
		tickKeys(hidKeysHeld(),hidKeysDown());

		//if (quitGame || hidKeysHeld() & KEY_SELECT) break;
		if (quitGame) break;
		//if (hidKeysDown() & (KEY_L | KEY_R)) screenShot = true;
	//	else screenShot = false;
        
        if(initGame > 0) setupGame(initGame == 1 ? true : false);
        
        if(currentMenu == 0){
            tick();
            sprintf(fpsstr, " FPS: %.0f, X:%d, Y:%d, E:%d", sf2d_get_fps(),player.x, player.y,eManager.lastSlot[currentLevel]);
		    sf2d_start_frame(GFX_TOP, GFX_LEFT);
                if(currentLevel == 0){ 
                    sf2d_draw_texture_part_scale(minimap[1],(-xscr/3)-256,(-yscr/3)-32,0,0,128,128,12.5,7.5);
                    sf2d_draw_rectangle(0,0,400,240, 0xDFDFDFAF);
                }
	            offsetX = xscr;offsetY = yscr;
		        renderBackground(xscr,yscr);
		        renderEntities(player.x, player.y, &eManager);
		        renderPlayer();
	            offsetX = 0;offsetY = 0;
		        renderItemWithText(player.p.activeItem, 10, 205);
		       // drawText(debugText,2,208);
		        drawText(fpsstr,2,225);
		    sf2d_end_frame();
		      
		    sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);	
		        if(currentLevel == 0 && airWizardHealthDisplay > 0){ 
                    sprintf(bossHealthText, "BOSS: %.0f%%", ((float)airWizardHealthDisplay/2000.0)*100);
                    drawText(bossHealthText,2,225);
                }
		        renderGui();
                sf2d_draw_texture(minimap[currentLevel], 192, 112);//y:56
            sf2d_end_frame();
        } else{ 
            tickMenu(currentMenu);
            renderMenu(currentMenu,xscr,yscr);
        }
        
		sf2d_swapbuffers();
	}
	
    freeRecipes();
	sf2d_free_texture(icons);
	sf2d_free_texture(minimap[0]);
	sf2d_free_texture(minimap[1]);
	sf2d_free_texture(minimap[2]);
	sf2d_free_texture(minimap[3]);
	sf2d_free_texture(minimap[4]);
    freeSounds();
    csndExit();
	sf2d_fini();
	return 0;
}
コード例 #25
0
ファイル: main.c プロジェクト: uschmann/sf2dlib
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;
}
コード例 #26
0
void Lux_NATIVE_DrawMessage( std::string message, uint8_t alignment )
{
	std::string::iterator object;
	LuxRect rect, area, draw;
	int16_t w = 400, h = 240;

	bool watch_for_color = false;
	bool is_whitspace = false;
	LuxColour font_color = { 255, 255,255, 255 };

	rect.x = rect.y = 0;

	Lux_Util_SetRectFromText( rect, message, 7, 10, 240 );

	area = rect;

	if ( alignment == 3 )
	{
		area.y = h - area.h;
	}
	else if ( alignment == 2 )
	{
		area.y = h - area.h;
		area.x = w - area.w;
	}
	else if ( alignment == 1 )
	{
		area.x = w - area.w;
	}


	draw = area;
	draw.w = draw.h = 8;

	for ( object = message.begin(); object != message.end(); object++ )
	{
		uint8_t utfchar = *object;
		uint32_t cchar = utfchar;

		is_whitspace = false;

		if (cchar == '\n' || cchar == '\r')
		{
			draw.y += 10;
			draw.x = area.x;
			cchar = 0;
			is_whitspace = true;
		}
		else if ( cchar <= 32 )
		{
			draw.x += 7;
			cchar = 0;
			is_whitspace = true;
		}
		else if ( cchar <= 128 )
		{

		}
		else if ( cchar < 224 )
		{
			object++;
			uint32_t next = *object;

			cchar = ((cchar << 6) & 0x7ff) + (next & 0x3f);
		}
		else if ( cchar < 240 )
		{
			uint32_t next;

			object++;
			next = (*object) & 0xff;
			cchar = ((cchar << 12) & 0xffff) + ((next << 6) & 0xfff);

			object++;
			next = (*object) & 0x3f;
			cchar += next;

		}
		else if ( cchar < 245 )
		{
			uint32_t next;

			object++;
			next = (*object) & 0xff;
			cchar = ((cchar << 18) & 0xffff) + ((next << 12) & 0x3ffff);

			object++;
			next = (*object) & 0xff;
			cchar += (next << 6) & 0xfff;

			object++;
			next = (*object) & 0x3f;
			cchar += next;
		}

		if ( cchar != 0 )
		{
			if ( !Lux_Util_CheckTextColour( cchar, font_color, watch_for_color ) )
			{
				sf2d_texture * texture = dsgraphics_bitfont->GetTexture(cchar);

				if ( texture )
				{
					sf2d_draw_texture_blend(texture, draw.x, draw.y, RGBA8(font_color.r, font_color.g, font_color.b, font_color.a) 	);
				}
				else
				{
					sf2d_draw_rectangle(draw.x, draw.y, draw.w, draw.h, RGBA8(font_color.r, font_color.g, font_color.b, font_color.a)  );
				}
				draw.x += 7;
			}
		}

		if ( is_whitspace )
		{
			/* Reset Colour if a whitespace occurs */
			font_color.r = font_color.g = font_color.b = 255;
		}
	}
}
コード例 #27
0
ファイル: Menu.c プロジェクト: RSDuck/Minicraft3DS
void renderMenu(int menu,int xscr,int yscr){
    int i = 0;
    switch(menu){
        case MENU_LOADGAME:
		sf2d_start_frame(GFX_TOP, GFX_LEFT);
        if(!enteringName){ // World select
            offsetX = 0;offsetY = (currentSelection * 32) - 48;
            drawText("Select a file",122,-16);
            for(i = 0; i < worldFileCount + 1; ++i){
                int color = 0x201092FF;
                char * text = fileNames[i];
                if(i == worldFileCount){
                    text = "Generate New World";
                    color = 0x109220FF;
                }
                if(i != currentSelection) color &= 0x7F7F7FFF; // Darken color.
                else {
                    if(areYouSure)color = 0xDF1010FF;
                }
                
                char scoreText[24];
                sprintf(scoreText,"Score: %d",fileScore[i]);
                
                renderFrame(1,i*4,24,(i*4)+4,color);
                if(i != worldFileCount){
                    drawText(text,(400-(strlen(text)*12))/2,i*64+12);
                    drawText(scoreText,(400-(strlen(scoreText)*12))/2,i*64+32);
                } else {
                    drawText(text,(400-(strlen(text)*12))/2,i*64+24);
                }
                if(fileWin[i] && i != worldFileCount) render16(18,i*32+8,24,208,0); // Render crown
            }
            offsetX = 0;offsetY = 0;
        } else { // Enter new world name.
            drawText("Enter a name",128,16);
            drawText(fileNames[worldFileCount],(400-(strlen(fileNames[worldFileCount])*12))/2, 48);
            
            if(errorFileName > 0){
                switch(errorFileName){// Error: Filename cannot already exist.
                    case 1: drawTextColor("ERROR: Length cannot be 0!",(400-26*12)/2,200,0xAF1010FF); break;    
                    case 2: drawTextColor("ERROR: You need Letters/Numbers!",(400-32*12)/2,200,0xAF1010FF); break;    
                    case 3: drawTextColor("ERROR: Filename already exists!",(400-31*12)/2,200,0xAF1010FF); break;    
                }    
            }
        }
		sf2d_end_frame();
		sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);
        if(!enteringName){ // World select
            if(!areYouSure){
                drawTextColor("Load World",100,12,0xFFFF3FFF);
                drawText("Press   or   to scroll", 28, 50);
                renderButtonIcon(k_up.input & -k_up.input, 98, 48, 1);
                renderButtonIcon(k_down.input & -k_down.input, 160, 48, 1);
                drawText("Press   to load world", (320-21*12)/2, 100);
                renderButtonIcon(k_accept.input & -k_accept.input, 104, 98, 1);
                drawText("Press   to return", 58, 150);
                renderButtonIcon(k_decline.input & -k_decline.input, 128, 148, 1);
                if(currentSelection != worldFileCount){
                    drawText("Press   to delete",(320-17*12)/2, 200);
                    renderButtonIcon(k_delete.input & -k_delete.input, 128, 198, 1);
                }
            } else {
                drawTextColor("Delete File?",88,12,0xFF3F3FFF);
                drawText("Press   to confirm", (320-18*12)/2, 100);
                renderButtonIcon(k_accept.input & -k_accept.input, 122, 98, 1);
                drawText("Press   to return", 58, 150);
                renderButtonIcon(k_decline.input & -k_decline.input, 128, 148, 1);
            }
            
        } else { // Draw the "keyboard"
            drawTextColor("Touch the keypad below",(320-22*12)/2,12,0xFFFF33FF);
            
            sf2d_draw_rectangle(0, 50, 320, 110, 0xBF7F7FFF);
            drawSizedText(guiText0,4, 60, 2);
            drawSizedText(guiText1,4, 80, 2);
            drawSizedText(guiText2,12, 100, 2);
            drawSizedText(guiText3,28, 120, 2);
            drawSizedText(guiText4,12, 140, 2);
            
            if(touchDelay > 0){
                sf2d_draw_rectangle(touchX, touchY, touchW, touchH, 0xAF);
            }
            
            drawText("Press   to confirm", (320-18*12)/2, 180);
            renderButtonIcon(k_accept.input & -k_accept.input, 122, 178, 1);
            drawText("Press   to return", 58, 210);
            renderButtonIcon(k_decline.input & -k_decline.input, 128, 208, 1);
        }
            
		sf2d_end_frame();
        break;
        case MENU_SETTINGS:
		    sf2d_start_frame(GFX_TOP, GFX_LEFT);
		        drawTextColor("Rebind Buttons",116,12,0xAFAF00FF);
                drawText("Button",16,32);
                drawText("Game",140,32);
                drawText("Menus",280,32);
		    
                char gameButText[34];
                char menuButText[34];
                    
                for(i = 0; i < 5; ++i){
                    if((currentSelection-2) + i > 21 || (currentSelection-2) + i < 0) continue;
                    renderButtonIcon(keys[(currentSelection-2) + i], 16, (i * 18) + 30, 2);
                    int ccol = 0x7F7F7FFF;
                    
                    sprintf(gameButText,"%s",getButtonFunctionGame(keys[(currentSelection-2) + i]));
                    sprintf(menuButText,"%s",getButtonFunctionMenu(keys[(currentSelection-2) + i]));
                    
                    if(i == 2){ 
                        if(!selBut)ccol = 0xFFFFFFFF;
                        else{ 
                            ccol = 0x00FF00FF;
                            if(left)sprintf(gameButText,"<%s>",getButtonFunctionGame(keys[(currentSelection-2) + i]));
                            else sprintf(menuButText,"<%s>",getButtonFunctionMenu(keys[(currentSelection-2) + i]));
                        }
                    }
                    if(left){
                        drawTextColor(gameButText, 112, (i * 33) + 80, ccol);
                        drawTextColor(menuButText, 280, (i * 33) + 80, 0x7F7F7FFF);
                    } else {
                        drawTextColor(gameButText, 112, (i * 33) + 80, 0x7F7F7FFF);
                        drawTextColor(menuButText, 280, (i * 33) + 80, ccol);
                    }
                }
                if(bindOpt){
                    renderFrame(1,1,24,14,0x1010BFFF);
                    drawTextColor("Save changes?",122,32,0xAFAF00FF);
                    for(i = 2; i >= 0; --i){
                        char* msg = keybOptions[i];
                        u32 color = 0x4F4F4FFF;
                        if(i == curSaveSel) color = 0xFFFFFFFF;
                        drawTextColor(msg,(400 - (strlen(msg) * 12))/2, (i * 24) + 92, color);    
                    }
                    drawText("Press   to return", 98, 190);
                    renderButtonIcon(k_decline.input & -k_decline.input, 168, 188, 1);
                    
                    if(errorBut >= 0 && errorBut < 9){
                        char errorText[30];
                        switch(errorBut){
                            case 0: sprintf(errorText, "Error: Missing 'Move up'"); break;
                            case 1: sprintf(errorText, "Error: Missing 'Move down'"); break;
                            case 2: sprintf(errorText, "Error: Missing 'Move right'"); break;
                            case 3: sprintf(errorText, "Error: Missing 'Move left'"); break;
                            case 4: sprintf(errorText, "Error: Missing 'Attack'"); break;
                            case 5: sprintf(errorText, "Error: Missing 'Toggle Menu'"); break;
                            case 6: sprintf(errorText, "Error: Missing 'Pause'"); break;
                            case 7: sprintf(errorText, "Error: Missing 'Accept'"); break;
                            case 8: sprintf(errorText, "Error: Missing 'Decline'"); break;
                            case 9: sprintf(errorText, "Error: Missing 'Delete'"); break;
                        }
                        drawTextColor(errorText,(400 - (strlen(errorText) * 12))/2,50,0xFF0000FF);
                    }
                    
                }
		    sf2d_end_frame();
		    sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);	
		    if(!selBut){
                drawText("Press   to select", 58, 80);
                renderButtonIcon(k_accept.input & -k_accept.input, 128, 78, 1);
                drawText("Press   to return", 58, 130);
                renderButtonIcon(k_decline.input & -k_decline.input, 128, 128, 1);
            } else {
                drawText("Press   or   to scroll", 28, 50);
                renderButtonIcon(k_left.input & -k_left.input, 98, 48, 1);
                renderButtonIcon(k_right.input & -k_right.input, 160, 48, 1);
                drawText("Press   to unselect", 46, 100);
                renderButtonIcon(k_accept.input & -k_accept.input, 118, 98, 1);
                drawText("Press   to return", 58, 150);
                renderButtonIcon(k_decline.input & -k_decline.input, 128, 148, 1);
            }
		    sf2d_end_frame();
        break;
        
        case MENU_PAUSED:
		    sf2d_start_frame(GFX_TOP, GFX_LEFT);
                if(currentLevel == 0){ 
                    sf2d_draw_texture_part_scale(minimap[1],(-xscr/3)-256,(-yscr/3)-32,0,0,128,128,12.5,7.5);
                    sf2d_draw_rectangle(0,0,400,240, 0xDFDFDFAF);
                }
	            offsetX = xscr;offsetY = yscr;
		            renderMenuBackground(xscr,yscr);
	            offsetX = 0;offsetY = 0;
                renderFrame(1,1,24,14,0xAF1010FF);
                drawText("Paused",164,32);
                for(i = 2; i >= 0; --i){
                    char* msg = pOptions[i];
                    u32 color = 0x7F7F7FFF;
                    if(i == currentSelection) color = 0xFFFFFFFF;
                    drawTextColor(msg,(400 - (strlen(msg) * 12))/2, (i * 24) + 100, color);    
                }
                
                if(pauseSaveDisplayTimer > 0) drawTextColor("Game Saved!", (400-(11*12))/2, 64,0x20FF20FF);
                
                if(areYouSure || areYouSureSave){
                    if(areYouSure)renderFrame(6,5,19,10,0x8F1010FF);
                    else renderFrame(6,5,19,10,0x108F10FF);
                    
                    drawText("Are you sure?",122,96);
                    drawText("   Yes", 164, 117);
                    renderButtonIcon(k_accept.input & -k_accept.input, 166, 114, 1);
                    drawText("   No", 170, 133);
                    renderButtonIcon(k_decline.input & -k_decline.input, 166, 130, 1);
                }
                
		    sf2d_end_frame();
        break;  
        case MENU_WIN:
		    sf2d_start_frame(GFX_TOP, GFX_LEFT);
                if(currentLevel == 0){ 
                    sf2d_draw_texture_part_scale(minimap[1],(-xscr/3)-256,(-yscr/3)-32,0,0,128,128,12.5,7.5);
                    sf2d_draw_rectangle(0,0,400,240, 0xDFDFDFAF);
                }
	            offsetX = xscr;offsetY = yscr;
		            renderMenuBackground(xscr,yscr);
	            offsetX = 0;offsetY = 0;
                renderFrame(5,3,21,12,0x1010FFFF);
                if(!rev){ opacity+=5; if(opacity == 255) rev = true; }
                else { opacity-=5; if(opacity == 100) rev = false; }
                sprintf(scoreText,"Score: %d", player.p.score);
                drawTextColor("You Win!",158,76,0xAFAF0000 + opacity);
                drawText(scoreText, 200-((strlen(scoreText)-1)*6), 100);
                drawText("Press   to continue", 96, 150);
                renderButtonIcon(k_attack.input & -k_attack.input, 166, 148, 1);
                
                //printf("0x%08X",k_attack.input & -k_attack.input);
		    sf2d_end_frame();
        break;  
        case MENU_LOSE:
		    sf2d_start_frame(GFX_TOP, GFX_LEFT);
                if(currentLevel == 0){ 
                    sf2d_draw_texture_part_scale(minimap[1],(-xscr/3)-256,(-yscr/3)-32,0,0,128,128,12.5,7.5);
                    sf2d_draw_rectangle(0,0,400,240, 0xDFDFDFAF);
                }
	            offsetX = xscr;offsetY = yscr;
		            renderMenuBackground(xscr,yscr);
	            offsetX = 0;offsetY = 0;
                renderFrame(5,3,21,12,0x1010FFFF);
                if(!rev){ opacity+=5; if(opacity == 255) rev = true; }
                else { opacity-=5; if(opacity == 100) rev = false; }
                sprintf(scoreText,"Score: %d", player.p.score);
                drawTextColor("You DIED!",158,76,0xAF000000 + opacity);
                drawText(scoreText, 200-((strlen(scoreText)-1)*6), 100);
                drawText("Press   to continue", 96, 150);
                renderButtonIcon(k_attack.input & -k_attack.input, 166, 148, 1);
                //printf("0x%08X",k_attack.input & -k_attack.input);
		    sf2d_end_frame();
        break;  
        case MENU_INVENTORY:
		    sf2d_start_frame(GFX_TOP, GFX_LEFT);
                if(currentLevel == 0){ 
                    sf2d_draw_texture_part_scale(minimap[1],(-xscr/3)-256,(-yscr/3)-32,0,0,128,128,12.5,7.5);
                    sf2d_draw_rectangle(0,0,400,240, 0xDFDFDFAF);
                }
	            offsetX = xscr;offsetY = yscr;
		            renderMenuBackground(xscr,yscr);
	            offsetX = 0;offsetY = 0;
                renderFrame(1,1,24,14,0x1010FFFF);
                renderItemList(player.p.inv, 1,1,24,14, curInvSel);
		    sf2d_end_frame();
        break;  
        case MENU_CRAFTING:
		    sf2d_start_frame(GFX_TOP, GFX_LEFT);
                if(currentLevel == 0){ 
                    sf2d_draw_texture_part_scale(minimap[1],(-xscr/3)-256,(-yscr/3)-32,0,0,128,128,12.5,7.5);
                    sf2d_draw_rectangle(0,0,400,240, 0xDFDFDFAF);
                }
	            offsetX = xscr;offsetY = yscr;
		            renderMenuBackground(xscr,yscr);
	            offsetX = 0;offsetY = 0;
	            
                renderFrame(15,1,24,4,0x1010FFFF);
                renderFrame(15,5,24,14,0x1010FFFF);
                renderFrame(1,1,14,14,0x1010FFFF);
                renderRecipes(currentRecipes, 1, 1, 14, 14, curInvSel);
                
                Recipe* rec = &currentRecipes->recipes[curInvSel];
                renderItemIcon(rec->itemResult,rec->itemAmountLevel,128,16);
                char craftText[12];
                sprintf(craftText,"%d",countItemInv(rec->itemResult,rec->itemAmountLevel, player.p.inv));
                drawText(craftText,274,34);
                
                if(rec->numOfCosts > 0){
                    int i;
                    for(i = 0; i < rec->numOfCosts; i++){
                        int amnt = countItemInv(rec->costs[i].costItem,0, player.p.inv);
                        int ttlCst = rec->costs[i].costAmount;
                        int col = 0xFFFFFFFF; if(amnt<ttlCst) col = 0x7F7F7FFF;
                        renderItemIcon(rec->costs[i].costItem,1,128,48+(i*8));
                        sprintf(craftText,"%d/%d",amnt,ttlCst);
                        drawTextColor(craftText,274,96+(i*18),col);
                    }
                }
                
		    sf2d_end_frame();
        break;  
        
        case MENU_CONTAINER:
		    sf2d_start_frame(GFX_TOP, GFX_LEFT);
                if(currentLevel == 0){ 
                    sf2d_draw_texture_part_scale(minimap[1],(-xscr/3)-256,(-yscr/3)-32,0,0,128,128,12.5,7.5);
                    sf2d_draw_rectangle(0,0,400,240, 0xDFDFDFAF);
                }
	            offsetX = xscr;offsetY = yscr;
		            renderMenuBackground(xscr,yscr);
		        if (curChestEntity->entityFurniture.r == 1){ offsetX = 48;offsetY = 0;}
		        else {offsetX = 0;offsetY = 0;}
		        
		        renderFrame(1,1,14,14,0x1010FFFF);
		        renderItemList(curChestEntity->entityFurniture.inv,1,1,14,14,
                curChestEntity->entityFurniture.r == 0 ? curInvSel : -curChestEntity->entityFurniture.oSel - 1);
		        renderFrame(15,1,28,14,0x1010FFFF);
		        renderItemList(player.p.inv,15,1,28,14,
                curChestEntity->entityFurniture.r == 1 ? curInvSel : -curChestEntity->entityFurniture.oSel - 1);
		        offsetX = 0;offsetY = 0;
		    sf2d_end_frame();
        break;
        case MENU_ABOUT:
		    sf2d_start_frame(GFX_TOP, GFX_LEFT);
		        drawText("About Minicraft",110,12);
		        drawSizedText("Minicraft was made by Markus Persson for the",24,36,1.0);
		        drawSizedText("22'nd ludum dare competition in december 2011.",16,48,1.0);
		        drawSizedText("it is dedicated to my father. <3",72,60,1.0);
		        drawSizedText("- Markus \"Notch\" Persson",104,76,1.0);
		        
		        drawTextColor("3DS Homebrew Edition",74,120,0x00FF00FF);
		        drawSizedTextColor("This port was made by David Benepe (Davideesk)",16,144,1.0,0x00FF00FF);
		        drawSizedTextColor("just for fun in September/October 2015.",44,156,1.0,0x00FF00FF);
		        drawSizedTextColor("TY Notch for creating a fun game to remake!",28,180,1.0,0x00FF00FF);
		    sf2d_end_frame();
		    sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);
		        drawTextColor("Special Thanks to:",52,12,0xFF7F7FFF);
		        drawTextColor("Smea",136,60,0xFF2020FF);
		        drawSizedTextColor("for ctrulib",116,80,1.0,0xFF2020FF);
		        drawTextColor("Xerpi",130,120,0x2020FFFF);
		        drawSizedTextColor("for sf2dlib",116,140,1.0,0x2020FFFF);
                drawText("Press   to return", 58, 220);
                renderButtonIcon(k_decline.input & -k_decline.input, 128, 218, 1);
		    sf2d_end_frame();
        break;
        case MENU_TITLE:
            /* Top Screen */
		    sf2d_start_frame(GFX_TOP, GFX_LEFT);
		        renderTitle(76,16);
		    
		        for(i = 4; i >= 0; --i){
                    char* msg = options[i];
                    u32 color = 0x7F7F7FFF;
                    if(i == currentSelection) color = 0xFFFFFFFF;
                    drawSizedTextColor(msg,(200 - (strlen(msg) * 8))/2, ((8 + i) * 20 - 50) >> 1,2.0, color);    
                }
		    
		        drawText(versionText,2,225);
		    sf2d_end_frame();
		    
            /* Bottom Screen */
		    sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);	
		      int startX = 0, startY = 0;// relative coordinates ftw
		        switch(currentSelection){
                    case 0: // "Start Game"
                        startX = 20;startY = 50;
                        render16(startX,startY+12,0,128,0);//Player(Carrying)
                        render16(startX,startY,128,128,0);//Workbench
                        startX = 120;startY = 20;
                        render16b(startX,startY,16,96,0,0x001DC1FF);// water pit
                        render16b(startX+16,startY,32,96,0,0x001DC1FF);
                        render16b(startX,startY+16,48,96,0,0x001DC1FF);
                        render16b(startX+16,startY+16,64,96,0,0x001DC1FF);
                        renderc  (startX+8,startY+12,48,160,16,8,0);//Waves
                        renderc  (startX+8,startY+8,0,112,16,8,0);//Player (Top-Half)
                        startX = 110;startY = 76;
                        render16 (startX,startY,48,112,0);//Player
                        renderc  (startX+12,startY,40,160,8,16,0);//Slash
                        render   (startX+14,startY+4,152,144,0);//Pickaxe
                        render16b(startX+18,startY,80,0,0,0xDCC6AEFF);//Iron ore
                        startX = 40;startY = 90;
                        render16b (startX,startY,128,112,0,0xADFFADFF);//Slime
                        render16 (startX+18,startY,48,112,1);//Player (Mirrored)
                        renderc  (startX+14,startY,32,160,8,16,0);//Slash
                        render   (startX+12,startY+4,104,144,1);//Sword
                        startX = 64;startY = 40;
                        render16b(startX,startY,16,80,0,0x69B569FF);// grass pit
                        render16b(startX+16,startY,32,80,0,0x69B569FF);
                        render16b(startX,startY+16,48,80,0,0x69B569FF);
                        render16b(startX+16,startY+16,64,80,0,0x69B569FF);
                        render16 (startX+8,startY+4,0,16,0);//Tree
                        render   (startX+1,startY+14,80,152,0);// Apple
                        render16 (startX+9,startY+18,16,112,0);//Player
                        renderc  (startX+9,startY+14,16,160,16,8,0);//Slash
                        drawTextColor("Play minicraft",24,24,0xFFFF7FFF);
                    break;
                    case 1: // "How To Play"
                        startX = 72;startY = 54;
                        render16(startX,startY,96,208,0);//C-PAD
                        startX = 72;startY = 37;
                        render16(startX,startY-16,16,112,0);//Player
                        render16(startX,startY,112,208,0);//C-PAD up
                        startX = 72;startY = 71;
                        render16(startX,startY+16,0,112,0);//Player
                        render16(startX,startY,144,208,0);//C-PAD down
                        startX = 39;startY = 54;
                        render16(startX,startY,48,112,1);//Player
                        render16(startX+16,startY,128,208,0);//C-PAD left
                        startX = 89;startY = 54;
                        render16(startX+16,startY,48,112,0);//Player
                        render16(startX,startY,160,208,0);//C-PAD right
                        
                        drawTextColor("Learn the basics",64,24,0xFFFF7FFF);
                    break;
                    case 2: // "Settings"
                    break;
                    case 3: // "About"
                    break;
                }
		    sf2d_end_frame();
            break;
        
        
    }
    
}
コード例 #28
0
ファイル: main.c プロジェクト: Hayleia/Undertone
int main()
{
	sf2d_init();
	sf2d_set_vblank_wait(0);

	// this will depend on the level
	uint8_t mapWidth = 4;
	uint8_t mapHeight = 3;
	uint16_t mapDim = mapWidth*mapHeight;
	uint8_t map_u[mapDim];
	uint16_t mapLength = generateLevel(map_u, mapWidth, mapHeight, 12);
	uint8_t map[mapDim];
	memcpy(map, map_u, mapDim);

	// get some drawing parameters
	uint16_t areaWidth = TWIDTH*2/3;
	uint16_t areaHeight = THEIGHT*2/3;
	uint16_t recWidth = areaWidth/mapWidth;
	uint16_t recHeight = areaHeight/mapHeight;
	uint16_t areaTop = (THEIGHT-mapHeight*recHeight)/2;
	uint16_t areaLeft = (TWIDTH-mapWidth*recWidth)/2;

	uint8_t curX = 0;
	uint8_t curY = 0;
	uint16_t playerLength = 0;
	float colorInterpolation = 0;

	u64 oldTime = 0;
	u64 keyTime = 0;

	while (aptMainLoop()) {
		// manage timer according to time passed since last frame
		u64 newTime = osGetTime();
		keyTime += newTime-oldTime;
		oldTime = newTime;

		hidScanInput();
		if (hidKeysDown() & KEY_START) break;

		// move cursor according to input
		uint16_t oldCurXY = curY*mapWidth+curX;
		curX += mapWidth;
		curY += mapHeight;
		if (hidKeysDown() & KEY_LEFT) curX--;
		if (hidKeysDown() & KEY_RIGHT) curX++;
		if (hidKeysDown() & KEY_UP) curY--;
		if (hidKeysDown() & KEY_DOWN) curY++;
		curX %= mapWidth;
		curY %= mapHeight;
		uint16_t newCurXY = curY*mapWidth+curX;

		if (newCurXY != oldCurXY) {
			map[newCurXY]--;
			playerLength++;
			keyTime=0; // force cursor display now
		}
		if (map[newCurXY] == 255) {
			// reset level
			curX = 0;
			curY = 0;
			playerLength = 0;
			memcpy(map, map_u, mapDim);
		}
		if (playerLength == mapLength) break; // TODO should be "you won"

		u32 targetColor = RGBA8(0x00,0xaa,0xaa,255);
		float targetInterpolation = (float)playerLength/(float)mapLength;
		if (newTime%256==0) colorInterpolation = (colorInterpolation*3+targetInterpolation*1)/4;
		u32 darkColor = interpolate(targetColor, greyed(targetColor), colorInterpolation);
		u32 liteColor = interpolate(darkColor, 0xffffffff, 1.0f/3.0f); // white is too clear
		u32 bgColor = interpolate(darkColor, 0, 0.5f);

		sf2d_set_clear_color(bgColor);

		sf2d_start_frame(GFX_TOP, GFX_LEFT);
		{
			// draw tiles
			for (uint8_t x=0; x<mapWidth; x++) for (uint8_t y=0; y<mapHeight; y++) {
				sf2d_draw_rectangle(x*recWidth+areaLeft, y*recHeight+areaTop, recWidth, recHeight, interpolate(darkColor, liteColor, ((float)map[y*mapWidth+x])/3));
			}

			// draw cursor
			float t = (float)(keyTime%2048)/2048.0f;
			uint8_t op = pow(fabs(t-0.5f)*2,4)*255;
			sf2d_draw_rectangle(curX*recWidth+areaLeft, curY*recHeight+areaTop, recWidth, recHeight, RGBA8(0,0,0,op));
		}
		sf2d_end_frame();

		sf2d_swapbuffers();
	}

	sf2d_fini();

	return 0;
}